31 var
Cc = Components.classes;
32 var
Ci = Components.interfaces;
33 var
Cr = Components.results;
34 var
Cu = Components.utils;
36 Cu.import(
"resource://app/jsmodules/DebugUtils.jsm");
37 Cu.import(
"resource://app/jsmodules/DOMUtils.jsm");
38 Cu.import(
"resource://app/jsmodules/SBDataRemoteUtils.jsm");
39 Cu.import(
"resource://app/jsmodules/SBUtils.jsm");
45 TRACE: DebugUtils.generateLogFunction(
"sbVideoWindow", 5),
46 LOG: DebugUtils.generateLogFunction(
"sbVideoWindow", 3),
52 _mediacoreManager:
null,
53 _shouldDismissSelf:
false,
54 _playbackStopped:
false,
57 _actualSizeDataRemote:
null,
58 _lastActualSize:
null,
59 _windowNeedsResize:
false,
60 _windowNeedsFocus:
false,
63 _contextMenuListener:
null,
65 _keydownListener:
null,
68 _resizeListener:
null,
74 _videoFullscreenDataRemote:
null,
84 get ACTUAL_SIZE_DR_KEY() {
85 const dataRemoteKey =
"videowindow.actualsize";
89 get VIDEO_FULLSCREEN_DR_KEY() {
90 const dataRemoteKey =
"video.fullscreen";
94 get TRACK_TITLE_DR_KEY() {
95 const dataRemoteKey =
"metadata.title";
103 onMediacoreEvent:
function vwc_onMediacoreEvent(aEvent) {
104 switch(aEvent.type) {
105 case Ci.sbIMediacoreEvent.BEFORE_TRACK_CHANGE: {
106 this._handleBeforeTrackChange(aEvent);
110 case Ci.sbIMediacoreEvent.TRACK_CHANGE: {
111 this._handleTrackChange(aEvent);
115 case Ci.sbIMediacoreEvent.SEQUENCE_END: {
116 this._handleSequenceEnd(aEvent);
120 case Ci.sbIMediacoreEvent.VIDEO_SIZE_CHANGED: {
121 this._handleVideoSizeChanged(aEvent);
125 case Ci.sbIMediacoreEvent.EXPLICIT_TRACK_CHANGE: {
126 this._handleExplicitTrackChange(aEvent);
136 observe:
function vwc_observe(aSubject, aTopic,
aData) {
137 if(aTopic == this.ACTUAL_SIZE_DR_KEY &&
138 this._actualSizeDataRemote.boolValue ==
true &&
140 this._resizeFromVideoBox(this._videoBox);
142 else if(aTopic == this.VIDEO_FULLSCREEN_DR_KEY &&
143 !this._ignoreResize) {
144 this._onFullScreen();
146 else if(aTopic == this.TRACK_TITLE_DR_KEY) {
156 _initialize:
function vwc__initialize() {
157 this._mediacoreManager =
158 Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
159 .getService(
Ci.sbIMediacoreManager);
162 this._osdService =
Cc[
"@songbirdnest.com/mediacore/osd-control-service;1"]
163 .getService(
Ci.sbIOSDControlService);
164 this._osdService.onVideoWindowOpened(
window);
166 this._mediacoreManager.addListener(
this);
169 this._ssp =
Cc[
"@songbirdnest.com/Songbird/ScreenSaverSuppressor;1"]
170 .getService(
Ci.sbIScreenSaverSuppressor);
180 this._ssp.suppress(
true);
191 if(this._actualSizeDataRemote.stringValue ==
null ||
192 this._actualSizeDataRemote.stringValue ==
"") {
193 this._actualSizeDataRemote.boolValue =
true;
195 this._lastActualSize = this._actualSizeDataRemote.boolValue;
197 this._actualSizeDataRemote.bindObserver(
this);
199 this._videoFullscreenDataRemote =
201 this._videoFullscreenDataRemote.boolValue =
false;
202 this._videoFullscreenDataRemote.bindObserver(
this);
206 this._titleDataRemote.bindObserver(
this,
false);
210 this._ignoreResize =
true;
215 this._resizeListener =
function(aEvent) {
216 self._onResize(aEvent);
218 window.addEventListener(
"resize", this._resizeListener,
false);
221 this._mouseListener =
function(aEvent) {
222 self._onMouseMoved(aEvent);
224 window.addEventListener(
"mousemove", this._mouseListener,
false);
227 this._contextMenuListener =
function(aEvent) {
228 return self._onContextMenu(aEvent);
230 window.addEventListener(
"contextmenu", this._contextMenuListener,
false);
233 this._keydownListener =
function(aEvent) {
234 return self._onKeyDown(aEvent);
236 window.addEventListener(
"keypress", this._keydownListener,
false);
238 this._contextMenu = document.getElementById(
"video-context-menu");
239 this._videoElement = document.getElementById(
"video-box");
245 _shutdown:
function vwc__shutdown() {
248 if (!this._playbackStopped)
249 this._mediacoreManager.sequencer.stop();
251 window.removeEventListener(
"resize", this._resizeListener,
false);
252 this._resizeListener =
null;
254 window.removeEventListener(
"contextmenu", this._contextMenuListener,
false);
255 this._contextMenuListener =
null;
257 window.removeEventListener(
"keypress", this._keydownListener,
false);
258 this._keydownListener =
null;
260 this._titleDataRemote.unbind();
261 this._actualSizeDataRemote.unbind();
262 this._videoFullscreenDataRemote.unbind();
264 this._titleDataRemote =
null;
265 this._actualSizeDataRemote =
null;
266 this._videoFullscreenDataRemote =
null;
268 this._osdService.onVideoWindowWillClose();
269 this._osdService =
null;
271 this._mediacoreManager.removeListener(
this);
272 this._mediacoreManager =
null;
274 this._actualSizeDataRemote =
null;
275 this._videoBox =
null;
276 this._videoElement =
null;
282 _resizeFromVideoBox:
function vwc__resizeFromVideoBox(aVideoBox) {
284 var actualHeight = aVideoBox.height;
285 var actualWidth = aVideoBox.width * aVideoBox.parNumerator /
286 aVideoBox.parDenominator;
288 this._resizeFromWidthAndHeight(actualWidth,
290 aVideoBox.parNumerator,
291 aVideoBox.parDenominator);
294 _resizeFromWidthAndHeight:
function vwc__resizeFromWidthAndHeight(
aWidth,
299 videoWindowController.TRACE(
"_resizeFromWidthAndHeight: " +
str);
305 var screen =
window.screen;
306 var availHeight = screen.availHeight;
307 var availWidth = screen.availWidth;
309 log(
"Screen: " + screen);
310 log(
"Available Width: " + availWidth);
311 log(
"Available Height: " + availHeight);
314 log(
"Window width: " +
window.outerWidth);
315 log(
"Window height: " +
window.outerHeight);
317 var fullWidth =
false;
320 var fullHeight =
false;
323 var boxObject = this._videoElement.boxObject;
326 log(
"Video Orientation: " + orient);
328 log(
"Video Element Width: " + boxObject.width);
329 log(
"Video Element Height: " + boxObject.height);
331 var decorationsWidth =
window.outerWidth - boxObject.width;
332 var decorationsHeight =
window.outerHeight - boxObject.height;
334 log(
"Decorations Width: " + decorationsWidth);
335 log(
"Decorations Height: " + decorationsHeight);
338 if(
aWidth > boxObject.width) {
339 let delta =
aWidth - boxObject.width;
341 log(
"Initial Delta Width: " + delta);
345 let available = availWidth -
window.outerWidth -
window.screenX;
347 log(
"Current Available Width: " + available);
349 if(available > delta) {
356 deltaWidth = available;
362 deltaWidth =
aWidth - boxObject.width;
368 if(
aHeight > boxObject.height) {
369 let delta =
aHeight - boxObject.height;
371 log(
"Initial Delta Height: " + delta);
375 let available = availHeight -
window.outerHeight -
window.screenY;
377 log(
"Current Available Height: " + available);
379 if(available >= delta) {
386 deltaHeight = available;
391 deltaHeight =
aHeight - boxObject.height;
395 log(
"Final Delta Width: " + deltaWidth);
396 log(
"Final Delta Height: " + deltaHeight);
397 log(
"Full Width: " + fullWidth);
398 log(
"Full Height: " + fullHeight);
401 if(orient ==
"landscape" && deltaHeight > deltaWidth && !fullWidth) {
402 let mul = aPARDen / aPARNum;
403 if((aPARDen / aPARNum) == 1) {
406 deltaHeight = Math.round(deltaWidth * mul);
408 else if(orient ==
"portrait" && deltaWidth > deltaHeight && !fullHeight) {
409 let mul = aPARNum / aPARDen;
410 if((aPARNum / aPARDen) == 1) {
413 deltaWidth = Math.round(deltaHeight * mul);
416 log(
"Final Delta Width (With aspect ratio compensation): " + deltaWidth);
417 log(
"Final Delta Height (With aspect ratio compensation): " + deltaHeight);
419 if (deltaWidth || deltaHeight)
424 this._ignoreResize =
true;
427 window.resizeBy(deltaWidth, deltaHeight);
430 log(
"New Video Element Width: " + boxObject.width);
431 log(
"New Video Element Height: " + boxObject.height);
434 _moveToCenter:
function vwc__moveToCenter() {
435 var posX = (
window.screen.availWidth -
window.outerWidth) / 2;
436 var posY = (
window.screen.availHeight -
window.outerHeight) / 2;
438 window.moveTo(posX, posY);
441 _onFullScreen:
function vwc__onFullScreen() {
442 var full = this._videoFullscreenDataRemote.boolValue
443 if (
window.fullScreen != full) {
449 this._ignoreResize =
true;
454 document.documentElement.setAttribute(
"fullscreen", full);
457 document.documentElement.removeAttribute(
"fullscreen");
459 this._osdService.onVideoWindowFullscreenChanged(full);
462 this._lastActualSize = this._actualSizeDataRemote.boolValue;
463 this._actualSizeDataRemote.boolValue =
false;
466 this._actualSizeDataRemote.boolValue = this._lastActualSize;
473 _setFullScreen:
function vwc__setFullScreen(aFullScreen) {
474 this._videoFullscreenDataRemote.boolValue = aFullScreen;
477 _toggleFullScreen:
function vwc__toggleFullScreen() {
478 this._setFullScreen(!this._videoFullscreenDataRemote.boolValue);
481 _setActualSize:
function vwc__setActualSize() {
482 this._setFullScreen(
false);
483 this._actualSizeDataRemote.boolValue =
true;
490 _handleBeforeTrackChange:
function vwc__handleBeforeTrackChange(aEvent) {
491 var mediaItem = aEvent.data.QueryInterface(
Ci.sbIMediaItem);
495 if(mediaItem.contentType !=
"video") {
500 this._videoBox =
null;
503 _handleTrackChange:
function vwc__handleTrackChange(aEvent) {
504 if(this._shouldDismiss) {
506 this._shouldDismiss =
false;
509 if(this._windowNeedsFocus) {
511 this._windowNeedsFocus =
false;
515 _handleSequenceEnd:
function vwc__handleSequenceEnd(aEvent) {
519 _handleVideoSizeChanged:
function vwc__handleVideoSizeChanged(aEvent) {
520 if(!(aEvent.data instanceof
Ci.sbIVideoBox))
523 var videoBox = aEvent.data;
527 if(this._actualSizeDataRemote.boolValue ==
true && !
window.fullScreen) {
529 this._resizeFromVideoBox(videoBox);
532 if(this._needsMove) {
533 this._moveToCenter();
534 this._needsMove =
false;
540 this._videoBox = videoBox;
543 _handleExplicitTrackChange:
function vwc__handleExplicitTrackChange(aEvent) {
544 this._windowNeedsFocus =
true;
551 _onContextMenu:
function vwc__onContextMenu(aEvent) {
552 if(this._contextMenu.state ==
"open")
553 this._contextMenu.hidePopup();
555 this._setChecked(document.getElementById(
"actualsize"),
556 this._actualSizeDataRemote.boolValue);
557 this._setChecked(document.getElementById(
"fullscreen"),
558 this._videoFullscreenDataRemote.boolValue);
560 this._contextMenu.openPopupAtScreen(aEvent.screenX, aEvent.screenY,
true);
565 _setChecked:
function(
node, state)
568 node.setAttribute(
"checked",
"true");
570 node.removeAttribute(
"checked");
573 _onResize:
function vwc__onResize(aEvent) {
575 this._osdService.onVideoWindowResized();
580 if(this._ignoreResize) {
581 this._ignoreResize =
false;
586 this._needsMove =
true;
587 this._showing =
true;
594 this._actualSizeDataRemote.boolValue =
false;
597 _onMouseMoved:
function vwc__onMouseMoved(aEvent) {
599 if (this._contextMenu.state !=
"closed")
604 var
target = aEvent.target;
605 if (target instanceof XULElement && target != this._videoElement)
608 this._osdService.showOSDControls(
Ci.sbIOSDControlService.TRANSITION_NONE);
611 _onKeyDown:
function vwc__onKeyDown(aEvent) {
612 this._osdService.showOSDControls(
Ci.sbIOSDControlService.TRANSITION_NONE);
618 keyCode = aEvent.charCode;
622 if(keyCode == KeyEvent.DOM_VK_ESCAPE) {
623 this._setFullScreen(
false);
628 if(keyCode == KeyEvent.DOM_VK_SPACE) {
629 let state = this._mediacoreManager.status.state;
630 if((state ==
Ci.sbIMediacoreStatus.STATUS_BUFFERING) ||
631 (state ==
Ci.sbIMediacoreStatus.STATUS_PLAYING)) {
632 this._mediacoreManager.playbackControl.pause();
634 else if(this._mediacoreManager.primaryCore) {
635 this._mediacoreManager.playbackControl.play();
641 if(aEvent.ctrlKey && keyCode == KeyEvent.DOM_VK_RIGHT) {
642 this._mediacoreManager.sequencer.next();
647 if(aEvent.ctrlKey && keyCode == KeyEvent.DOM_VK_LEFT) {
648 this._mediacoreManager.sequencer.previous();
652 if(!aEvent.altKey && aEvent.ctrlKey && keyCode == KeyEvent.DOM_VK_UP) {
653 let vol = this._mediacoreManager.volumeControl.volume;
661 this._mediacoreManager.volumeControl.volume = vol;
667 if(!aEvent.altKey && aEvent.ctrlKey && keyCode == KeyEvent.DOM_VK_DOWN) {
668 let vol = this._mediacoreManager.volumeControl.volume;
676 this._mediacoreManager.volumeControl.volume = vol;
682 if(aEvent.ctrlKey && aEvent.altKey &&
683 (keyCode == KeyEvent.DOM_VK_UP ||
684 keyCode == KeyEvent.DOM_VK_DOWN)) {
685 let mute = this._mediacoreManager.volumeControl.mute;
686 this._mediacoreManager.volumeControl.mute = !mute;
692 if(this._platform ==
"Windows_NT") {
693 if((aEvent.altKey && (keyCode == KeyEvent.DOM_VK_F4)) ||
694 (aEvent.ctrlKey && (keyCode == KeyEvent.DOM_VK_W))) {
695 this._mediacoreManager.sequencer.stop();
702 _dismissSelf:
function vwc__dismissSelf() {
704 this._ssp.suppress(
false);
706 this._playbackStopped =
true;
function getPlatformString()
Get the name of the platform we are running on.
restoreDimensions aHeight
function SBNewDataRemote(aKey, aRoot)
Create a new data remote object.
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
var videoWindowController
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe