79 const Cc = Components.classes;
80 const Ci = Components.interfaces;
81 const Cu = Components.utils;
83 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
84 Cu.import(
"resource://gre/modules/NetUtil.jsm");
97 XPCOMUtils.defineLazyServiceGetter(
this,
"ioSvc",
98 "@mozilla.org/network/io-service;1",
100 XPCOMUtils.defineLazyServiceGetter(
this,
"imgTools",
101 "@mozilla.org/image/tools;1",
103 XPCOMUtils.defineLazyServiceGetter(
this,
"faviconSvc",
104 "@mozilla.org/browser/favicon-service;1",
105 "nsIFaviconService");
109 let channel = ioSvc.newChannelFromURI(
uri);
110 NetUtil.asyncFetch(channel,
function(inputStream, resultCode) {
111 if (!Components.isSuccessCode(resultCode))
115 imgTools.decodeImageData(inputStream, channel.contentType, out_img);
120 let defaultURI = faviconSvc.defaultFavicon;
121 if (!defaultURI.equals(
uri))
154 this.linkedBrowser =
tab.linkedBrowser;
156 this.linkedBrowser.addEventListener(
"MozAfterPaint",
this,
false);
157 this.linkedBrowser.addEventListener(
"DOMTitleChanged",
this,
false);
159 this.linkedBrowser.addEventListener(
"pageshow",
this,
false);
162 XPCOMUtils.defineLazyGetter(
this,
"preview",
function () this.
win.previewFromTab(
this.tab));
164 XPCOMUtils.defineLazyGetter(
this,
"canvasPreview",
function ()
165 this.
win.win.document.createElementNS(
"http://www.w3.org/1999/xhtml",
"canvas"));
167 XPCOMUtils.defineLazyGetter(
this,
"dirtyRegion",
169 let dirtyRegion =
Cc[
"@mozilla.org/gfx/region;1"]
170 .createInstance(
Ci.nsIScriptableRegion);
178 Ci.nsIDOMEventListener]),
179 destroy:
function () {
180 this.linkedBrowser.removeEventListener(
"pageshow",
this,
false);
181 this.linkedBrowser.removeEventListener(
"DOMTitleChanged",
this,
false);
182 this.linkedBrowser.removeEventListener(
"MozAfterPaint",
this,
false);
184 get wrappedJSObject() {
189 let rectstream = this.dirtyRegion.getRects();
193 for (let
i = 0;
i < rectstream.length;
i+= 4) {
194 let r = {x: rectstream[
i],
206 resetCanvasPreview:
function () {
207 this.canvasPreview.width = 0;
208 this.canvasPreview.height = 0;
213 updateCanvasPreview:
function () {
214 let
win = this.linkedBrowser.contentWindow;
215 let bx = this.linkedBrowser.boxObject;
217 if (bx.width !=
this.canvasPreview.width ||
218 bx.height !=
this.canvasPreview.height) {
221 this.canvasPreview.width = bx.width;
222 this.canvasPreview.height = bx.height;
226 let ctx = this.canvasPreview.getContext(
"2d");
227 let
flags = this.canvasPreviewFlags;
230 this.dirtyRegion.intersectRect(0, 0, bx.width, bx.height);
231 this.dirtyRects.forEach(
function (r) {
238 ctx.drawWindow(win, x, y, width, height,
"white", flags);
241 this.dirtyRegion.setToRect(0,0,0,0);
245 AeroPeek.resetCacheTimer();
248 onTabPaint:
function (
rect) {
253 let r = { x: Math.floor(
rect.left),
254 y: Math.floor(
rect.top),
258 this.dirtyRegion.unionRect(r.x, r.y, r.width, r.height);
265 return this.
win.width;
269 return this.
win.height;
272 get thumbnailAspectRatio() {
273 let boxObject = this.
tab.linkedBrowser.boxObject;
275 let tabWidth = boxObject.width || 1;
277 let tabHeight = boxObject.height || 1;
278 return tabWidth / tabHeight;
281 drawPreview:
function (ctx) {
283 this.
win.tabbrowser.previewTab(this.
tab,
function ()
self.previewTabCallback(ctx));
289 previewTabCallback:
function (ctx) {
293 ctx.drawWindow(this.
win.win, 0, 0, width, height,
"transparent");
297 this.updateCanvasPreview();
299 let boxObject = this.linkedBrowser.boxObject;
300 ctx.translate(boxObject.x, boxObject.y);
301 ctx.drawImage(this.canvasPreview, 0, 0);
305 this.updateCanvasPreview();
307 let scale = width/this.linkedBrowser.boxObject.width;
308 ctx.scale(scale, scale);
309 ctx.drawImage(this.canvasPreview, 0, 0);
316 this.
win.tabbrowser.removeTab(this.
tab);
319 onActivate:
function () {
320 this.
win.tabbrowser.selectedTab = this.
tab;
328 handleEvent:
function (evt) {
330 case "MozAfterPaint":
331 if (evt.originalTarget ===
this.linkedBrowser.contentWindow) {
332 let clientRects = evt.clientRects;
333 let length = clientRects.length;
334 for (let
i = 0;
i < length;
i++) {
335 let r = clientRects.item(
i);
339 let preview = this.preview;
341 preview.invalidate();
344 case "DOMTitleChanged":
347 this.
win.tabbrowser.setTabTitle(this.
tab);
348 let title = this.
tab.label;
349 this.preview.title = title;
350 this.preview.tooltip = title;
357 function () { let canvasInterface =
Ci.nsIDOMCanvasRenderingContext2D;
358 return canvasInterface.DRAWWINDOW_DRAW_VIEW
359 | canvasInterface.DRAWWINDOW_DRAW_CARET
360 | canvasInterface.DRAWWINDOW_DO_NOT_FLUSH;
378 for (let
i = 0;
i < this.
events.length;
i++)
379 this.
tabbrowser.tabContainer.addEventListener(
this.events[
i],
this,
false);
380 this.
tabbrowser.addTabsProgressListener(
this);
383 AeroPeek.windows.push(
this);
385 for (let
i = 0;
i < tabs.length;
i++)
386 this.newTab(tabs[
i]);
388 this.updateTabOrdering();
389 AeroPeek.checkPreviewCount();
394 events: [
"TabOpen",
"TabClose",
"TabSelect",
"TabMove"],
396 destroy:
function () {
397 this._destroying =
true;
401 for (let
i = 0;
i < this.
events.length;
i++)
402 this.
tabbrowser.tabContainer.removeEventListener(
this.events[
i],
this,
false);
404 for (let
i = 0;
i < tabs.length;
i++)
405 this.removeTab(tabs[
i]);
407 let idx = AeroPeek.windows.indexOf(this.
win.gTaskbarTabGroup);
408 AeroPeek.windows.splice(idx, 1);
409 AeroPeek.checkPreviewCount();
413 return this.
win.innerWidth;
416 return this.
win.innerHeight;
420 newTab:
function (
tab) {
422 let preview = AeroPeek.taskbar.createTaskbarTabPreview(this.
tabbrowser.docShell, controller);
423 preview.title =
tab.label;
424 preview.tooltip =
tab.label;
425 preview.visible = AeroPeek.enabled;
436 this.previews.splice(
tab._tPos, 0, preview);
437 AeroPeek.addPreview(preview);
441 removeTab:
function (
tab) {
442 let preview = this.previewFromTab(
tab);
443 preview.active =
false;
444 preview.visible =
false;
446 preview.controller.wrappedJSObject.destroy();
450 if (!this._destroying)
451 this.previews.splice(
tab._tPos, 1);
452 AeroPeek.removePreview(preview);
456 return this._enabled;
459 set enabled (enable) {
460 this._enabled = enable;
464 this.previews.forEach(
function (preview) {
466 preview.visible = enable;
468 this.updateTabOrdering();
471 previewFromTab:
function (
tab) {
472 return this.previews[
tab._tPos];
475 updateTabOrdering:
function () {
476 for (let i = 0; i < this.previews.length; i++) {
477 let
p = this.previews[
i];
478 let
next = i == this.previews.length - 1 ?
null : this.previews[i+1];
484 handleEvent:
function (evt) {
485 let
tab = evt.originalTarget;
489 this.updateTabOrdering();
493 this.updateTabOrdering();
496 this.previewFromTab(tab).active =
true;
499 let oldPos = evt.detail;
500 let newPos = tab._tPos;
501 let preview = this.previews[oldPos];
502 this.previews.splice(oldPos, 1);
503 this.previews.splice(newPos, 0, preview);
504 this.updateTabOrdering();
510 onLocationChange:
function () {
512 onProgressChange:
function () {
514 onSecurityChange:
function () {
518 onStatusChange:
function () {
520 onLinkIconAvailable:
function (
aBrowser) {
523 let index =
self.tabbrowser.browsers.indexOf(
aBrowser);
526 self.previews[index].icon = img;
564 this.available = this.taskbar.available;
580 return this._enabled;
583 set enabled(enable) {
584 if (this._enabled == enable)
587 this._enabled = enable;
590 win.enabled = enable;
594 addPreview:
function (preview) {
595 this.previews.push(preview);
596 this.checkPreviewCount();
599 removePreview:
function (preview) {
600 let idx = this.previews.indexOf(preview);
601 this.previews.splice(idx, 1);
602 this.checkPreviewCount();
605 checkPreviewCount:
function () {
606 if (this.previews.length >
this.maxpreviews)
607 this.enabled =
false;
609 this.enabled = this._prefenabled;
612 onOpenWindow:
function (
win) {
620 onCloseWindow:
function (
win) {
625 win.gTaskbarTabGroup.destroy();
629 resetCacheTimer:
function () {
630 this.cacheTimer.cancel();
631 this.cacheTimer.init(
this, 1000*this.cacheLifespan,
Ci.nsITimer.TYPE_ONE_SHOT);
637 case "nsPref:changed":
646 this.checkPreviewCount();
648 case "timer-callback":
649 this.previews.forEach(
function (preview) {
650 let controller = preview.controller.wrappedJSObject;
651 controller.resetCanvasPreview();
658 XPCOMUtils.defineLazyGetter(AeroPeek,
"cacheTimer",
function ()
662 XPCOMUtils.defineLazyServiceGetter(AeroPeek,
"prefs",
663 "@mozilla.org/preferences-service;1",
666 AeroPeek.initialize();
const WINTASKBAR_CONTRACTID
sbDeviceFirmwareAutoCheckForUpdate prototype flags
sbOSDControlService prototype QueryInterface
function PreviewController(win, tab)
function getFaviconAsImage(iconurl, callback)
_updateTextAndScrollDataForTab aBrowser
ContinuingWebProgressListener prototype onStateChange
const DISABLE_THRESHOLD_PREF_NAME
const CACHE_EXPIRATION_TIME_PREF_NAME
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe
function _imageFromURI(uri, callback)