25 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
27 if (typeof(
Cc) ==
"undefined")
28 var
Cc = Components.classes;
29 if (typeof(
Ci) ==
"undefined")
30 var
Ci = Components.interfaces;
31 if (typeof(
Cu) ==
"undefined")
32 var
Cu = Components.utils;
33 if (typeof(
Cr) ==
"undefined")
34 var
Cr = Components.results;
55 this._cloakService = Cc[
"@songbirdnest.com/Songbird/WindowCloak;1"]
56 .getService(Ci.sbIWindowCloak);
57 this.
_timer = Cc[
"@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
61 this._useTransparentGraphics =
true;
62 if (
"@songbirdnest.com/Songbird/WindowChromeService;1" in Cc) {
63 var winChromeService =
64 Cc[
"@songbirdnest.com/Songbird/WindowChromeService;1"]
65 .getService(Ci.sbIWindowChromeService);
66 this._useTransparentGraphics = winChromeService.isCompositionEnabled;
76 _osdControlsShowing:
false,
77 _useTransparentGraphics:
false,
79 _videoWinHasFocus:
false,
80 _osdWinHasFocus:
false,
81 _mouseDownOnOSD:
false,
84 _fadeContinuation:
null,
87 _recalcOSDPosition:
function() {
90 var osdY = this._videoWindow.screenY +
91 (this._videoWindow.outerHeight * 0.95 - this._osdWindow.outerHeight);
94 var newOSDWidth = this._osdWindow.innerWidth;
99 newOSDWidth = this._videoWindow.innerWidth -
OSD_PADDING;
103 var osdX = this._videoWindow.screenX +
104 (this._videoWindow.innerWidth / 2) - (newOSDWidth / 2);
107 this._osdWindow.moveTo(osdX, osdY);
110 this._osdWindow.resizeTo(newOSDWidth,
OSD_HEIGHT);
116 onVideoWindowOpened:
function(aVideoWindow) {
118 this._videoWindow = aVideoWindow.QueryInterface(Ci.nsIDOMWindowInternal);
121 this._osdWindow = this._videoWindow.openDialog(
122 "chrome://songbird/content/xul/videoWindowControls.xul",
123 "Songbird OSD Control Window",
124 "chrome,dependent,modal=no,titlebar=no",
126 this._osdWindow.QueryInterface(Ci.nsIDOMWindowInternal);
129 this._cloakService.cloak(this._osdWindow);
134 Cc[
"@songbirdnest.com/integration/window-move-resize-service;1"]
135 .getService(Ci.sbIWindowMoveService);
137 winMoveService.startWatchingWindow(this._videoWindow,
this);
146 this._osdWinBlurListener =
function(aEvent) {
147 self._onOSDWinBlur(aEvent);
149 this._videoWinBlurListener =
function(aEvent) {
150 self._onVideoWinBlur(aEvent);
152 this._osdWinFocusListener =
function(aEvent) {
153 self._onOSDWinFocus(aEvent);
155 this._videoWinFocusListener =
function(aEvent) {
156 self._onVideoWinFocus(aEvent);
158 this._osdWinMousemoveListener =
function(aEvent) {
159 self._onOSDWinMousemove(aEvent);
161 this._osdWinMousedownListener =
function(aEvent) {
162 self._onOSDWinMousedown(aEvent);
164 this._osdWinMouseupListener =
function(aEvent) {
165 self._onOSDWinMouseup(aEvent);
167 this._osdWinKeypressListener =
function(aEvent) {
168 self._onOSDWinKeypress(aEvent);
170 this._osdWindow.addEventListener(
"blur",
171 this._osdWinBlurListener,
173 this._osdWindow.addEventListener(
"focus",
174 this._osdWinFocusListener,
176 this._osdWindow.addEventListener(
"mousemove",
177 this._osdWinMousemoveListener,
179 this._videoWindow.addEventListener(
"mousemove",
180 this._osdWinMousemoveListener,
182 this._osdWindow.addEventListener(
"mousedown",
183 this._osdWinMousedownListener,
185 this._osdWindow.addEventListener(
"mouseup",
186 this._osdWinMouseupListener,
188 this._osdWindow.addEventListener(
"keypress",
189 this._osdWinKeypressListener,
191 this._videoWindow.addEventListener(
"blur",
192 this._videoWinBlurListener,
194 this._videoWindow.addEventListener(
"focus",
195 this._videoWinFocusListener,
199 onVideoWindowWillClose:
function() {
203 Cc[
"@songbirdnest.com/integration/window-move-resize-service;1"]
204 .getService(Ci.sbIWindowMoveService);
206 winMoveService.stopWatchingWindow(this._videoWindow,
this);
213 this._osdWindow.removeEventListener(
"blur",
214 this._osdWinBlurListener,
216 this._osdWindow.removeEventListener(
"focus",
217 this._osdWinFocusListener,
219 this._osdWindow.removeEventListener(
"mousemove",
220 this._osdWinMousemoveListener,
222 this._osdWindow.removeEventListener(
"mousedown",
223 this._osdWinMousedownListener,
225 this._osdWindow.removeEventListener(
"mouseup",
226 this._osdWinMouseupListener,
228 this._osdWindow.removeEventListener(
"keypress",
229 this._osdWinKeypressListener,
231 this._videoWindow.removeEventListener(
"blur",
232 this._videoWinBlurListener,
234 this._videoWindow.removeEventListener(
"focus",
235 this._videoWinFocusListener,
237 this._osdWindow.close();
238 this._osdWindow =
null;
239 this._videoWindow =
null;
242 onVideoWindowResized:
function() {
243 this._recalcOSDPosition();
246 onVideoWindowFullscreenChanged:
function(aFullscreen) {
248 this._osdWindow.document.getElementById(
"osd_wrapper_hbox");
249 var fullscreenButton =
250 this._osdWindow.document.getElementById(
"full_screen_button");
254 outterBox.setAttribute(
"fullscreen",
true);
255 fullscreenButton.setAttribute(
"fullscreen",
true);
258 outterBox.removeAttribute(
"fullscreen");
259 fullscreenButton.removeAttribute(
"fullscreen");
264 hideOSDControls:
function(aTransitionType) {
267 if (this._mouseDownOnOSD)
273 switch (aTransitionType) {
274 case Ci.sbIOSDControlService.TRANSITION_FADE:
275 transition = this._fadeOut;
278 case Ci.sbIOSDControlService.TRANSITION_NONE:
279 transition = this._hideInstantly;
283 Components.utils.reportError(
284 "Invalid transition type passed into hideOSDControls()!");
287 transition = this._hideInstantly;
290 if (!this._useTransparentGraphics) {
291 transition = this._hideInstantly;
294 transition.call(
this,
function() {
298 self._osdControlsShowing =
false;
300 if (!
self._cloakService.isCloaked(
self._osdWindow)) {
301 if (
self._osdWinHasFocus) {
302 self._videoWindow.focus();
304 self._cloakService.cloak(
self._osdWindow);
309 showOSDControls:
function(aTransitionType) {
310 if (!this._videoWinHasFocus &&
311 !this._osdWinHasFocus)
319 if (this._osdSurpressed)
323 this.
_timer.initWithCallback(
this,
325 Ci.nsITimer.TYPE_ONE_SHOT);
329 if (this._osdControlsShowing) {
330 this._osdWindow.focus();
335 this._osdControlsShowing =
true;
336 this._recalcOSDPosition();
339 if (this._cloakService.isCloaked(
this._osdWindow)) {
340 this._cloakService.uncloak(this._osdWindow);
344 switch (aTransitionType) {
345 case Ci.sbIOSDControlService.TRANSITION_FADE:
346 transition = this._fadeIn;
349 case Ci.sbIOSDControlService.TRANSITION_NONE:
350 transition = this._showInstantly;
354 Components.utils.reportError(
355 "Invalid transition type passed into showOSDControls()!");
358 transition = this._showInstantly;
361 if (!this._useTransparentGraphics) {
362 transition = this._showInstantly;
365 transition.call(
this);
368 _fade:
function(
start, end, func) {
371 this._fadeContinuation = func;
372 var
node = this._osdWindow.document.getElementById(
"osd_wrapper_hbox");
374 var delta = (end -
start) / 10;
377 self._fadeInterval =
self._osdWindow.setInterval(
function() {
388 _fadeCancel:
function() {
389 this._osdWindow.clearInterval(this._fadeInterval);
390 if (this._fadeContinuation) {
391 this._fadeContinuation();
393 this._fadeContinuation =
null;
396 _showInstantly:
function(func) {
398 var
node = this._osdWindow.document.getElementById(
"osd_wrapper_hbox");
400 node.style.opacity = 1;
407 _hideInstantly:
function(func) {
415 _fadeOut:
function(func) {
416 this._fade(1, 0, func);
420 _fadeIn:
function(func) {
421 this._fade(0, 1, func);
424 _onOSDWinBlur:
function(aEvent) {
425 this._osdWinHasFocus =
false;
428 _onOSDWinFocus:
function(aEvent) {
429 this._osdWinHasFocus =
true;
432 _onVideoWinBlur:
function(aEvent) {
433 this._videoWinHasFocus =
false;
436 _onVideoWinFocus:
function(aEvent) {
437 this._videoWinHasFocus =
true;
440 _onOSDWinMousemove:
function(aEvent) {
443 this.showOSDControls(Ci.sbIOSDControlService.TRANSITION_NONE);
446 _onOSDWinMousedown:
function(aEvent) {
447 if (aEvent.button == 0) {
448 this._mouseDownOnOSD =
true;
452 _onOSDWinMouseup:
function(aEvent) {
453 if (aEvent.button == 0) {
455 this._mouseDownOnOSD =
false;
456 this.showOSDControls(Ci.sbIOSDControlService.TRANSITION_NONE);
460 _onOSDWinKeypress:
function(aEvent) {
461 if (!aEvent.getPreventDefault())
463 let
event = this._videoWindow.document.createEvent(
"KeyboardEvent");
464 event.initKeyEvent(aEvent.type, aEvent.bubbles, aEvent.cancelable,
465 this._videoWindow, aEvent.ctrlKey, aEvent.altKey,
466 aEvent.shiftKey, aEvent.metaKey, aEvent.keyCode,
468 this._videoWindow.dispatchEvent(
event);
475 onMoveStarted:
function() {
476 this._osdSurpressed =
true;
477 this._showOSDControlsOnStop = this._osdControlsShowing;
478 this.hideOSDControls(Ci.sbIOSDControlService.TRANSITION_NONE);
481 onMoveStopped:
function() {
482 this._osdSurpressed =
false;
483 if (this._showOSDControlsOnStop) {
484 this.showOSDControls(Ci.sbIOSDControlService.TRANSITION_NONE);
486 this._showOSDControlsOnStop =
false;
492 notify:
function(aTimer) {
493 if (aTimer == this.
_timer) {
494 this.hideOSDControls(Ci.sbIOSDControlService.TRANSITION_FADE);
503 "Songbird OSD Control Service";
505 "sbOSDControlService";
507 Components.ID(
"{03F78779-FCB7-4442-9A0C-E8547B4F1368}");
509 "@songbirdnest.com/mediacore/osd-control-service;1";
511 XPCOMUtils.generateQI([Ci.sbIOSDControlService,
512 Ci.sbIWindowMoveListener,
513 Ci.nsITimerCallback]);
function sbOSDControlService()
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
TimerLoop prototype notify