2013-07-20 01:17:08 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["View"];
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
Components.utils.import("resource:///modules/colorUtils.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2013-10-31 21:00:28 +00:00
|
|
|
Components.utils.import("resource://gre/modules/Task.jsm");
|
2013-07-20 01:17:08 +00:00
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// module helpers
|
|
|
|
//
|
|
|
|
|
|
|
|
function makeURI(aURL, aOriginCharset, aBaseURI) {
|
|
|
|
return Services.io.newURI(aURL, aOriginCharset, aBaseURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// View prototype for shared functionality
|
|
|
|
|
2013-09-24 20:16:11 +00:00
|
|
|
function View(aSet) {
|
|
|
|
this._set = aSet;
|
|
|
|
this._set.controller = this;
|
2013-12-09 18:41:58 +00:00
|
|
|
this._window = aSet.ownerDocument.defaultView;
|
|
|
|
|
|
|
|
this.onResize = () => this._adjustDOMforViewState();
|
|
|
|
this._window.addEventListener("resize", this.onResize);
|
2013-09-24 20:16:11 +00:00
|
|
|
|
2013-10-31 21:00:28 +00:00
|
|
|
ColorUtils.init();
|
2013-09-24 20:16:11 +00:00
|
|
|
this._adjustDOMforViewState();
|
2013-07-20 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
View.prototype = {
|
2013-09-24 20:16:11 +00:00
|
|
|
destruct: function () {
|
2013-12-09 18:41:58 +00:00
|
|
|
this._window.removeEventListener("resize", this.onResize);
|
2013-09-24 20:16:11 +00:00
|
|
|
},
|
|
|
|
|
2013-08-16 23:56:50 +00:00
|
|
|
_adjustDOMforViewState: function _adjustDOMforViewState(aState) {
|
2013-10-22 23:32:42 +00:00
|
|
|
let grid = this._set;
|
|
|
|
if (!grid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!aState) {
|
|
|
|
aState = grid.getAttribute("viewstate");
|
|
|
|
}
|
|
|
|
switch (aState) {
|
|
|
|
case "snapped":
|
|
|
|
grid.setAttribute("nocontext", true);
|
|
|
|
grid.selectNone();
|
2014-01-09 22:46:19 +00:00
|
|
|
grid.disableCrossSlide();
|
2013-10-22 23:32:42 +00:00
|
|
|
break;
|
|
|
|
case "portrait":
|
|
|
|
grid.removeAttribute("nocontext");
|
|
|
|
grid.setAttribute("vertical", true);
|
2014-01-09 22:46:19 +00:00
|
|
|
grid.enableCrossSlide();
|
2013-10-22 23:32:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
grid.removeAttribute("nocontext");
|
|
|
|
grid.removeAttribute("vertical");
|
2014-01-09 22:46:19 +00:00
|
|
|
grid.enableCrossSlide();
|
2013-10-22 23:32:42 +00:00
|
|
|
}
|
|
|
|
if ("arrangeItems" in grid) {
|
|
|
|
grid.arrangeItems();
|
2013-07-29 22:03:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-20 01:17:08 +00:00
|
|
|
_updateFavicon: function pv__updateFavicon(aItem, aUri) {
|
|
|
|
if ("string" == typeof aUri) {
|
|
|
|
aUri = makeURI(aUri);
|
|
|
|
}
|
|
|
|
PlacesUtils.favicons.getFaviconURLForPage(aUri, this._gotIcon.bind(this, aItem));
|
|
|
|
},
|
|
|
|
|
|
|
|
_gotIcon: function pv__gotIcon(aItem, aIconUri) {
|
|
|
|
if (!aIconUri) {
|
|
|
|
aItem.removeAttribute("iconURI");
|
|
|
|
if (aItem.refresh) {
|
|
|
|
aItem.refresh();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ("string" == typeof aIconUri) {
|
|
|
|
aIconUri = makeURI(aIconUri);
|
|
|
|
}
|
|
|
|
let faviconURL = (PlacesUtils.favicons.getFaviconLinkForIcon(aIconUri)).spec;
|
2013-12-16 17:22:24 +00:00
|
|
|
aItem.iconSrc = faviconURL;
|
2013-10-31 21:00:28 +00:00
|
|
|
|
2013-12-16 17:22:24 +00:00
|
|
|
let xpFaviconURI = makeURI(faviconURL.replace("moz-anno:favicon:",""));
|
2013-10-31 21:00:28 +00:00
|
|
|
Task.spawn(function() {
|
|
|
|
let colorInfo = yield ColorUtils.getForegroundAndBackgroundIconColors(xpFaviconURI);
|
|
|
|
if (!(colorInfo && colorInfo.background && colorInfo.foreground)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let { background, foreground } = colorInfo;
|
2013-07-20 01:17:08 +00:00
|
|
|
aItem.style.color = foreground; //color text
|
|
|
|
aItem.setAttribute("customColor", background);
|
2013-08-10 08:29:22 +00:00
|
|
|
let matteColor = 0xffffff; // white
|
|
|
|
let alpha = 0.04; // the tint weight
|
|
|
|
let [,r,g,b] = background.match(/rgb\((\d+),(\d+),(\d+)/);
|
|
|
|
// get the rgb value that represents this color at given opacity over a white matte
|
|
|
|
let tintColor = ColorUtils.addRgbColors(matteColor, ColorUtils.createDecimalColorWord(r,g,b,alpha));
|
|
|
|
aItem.setAttribute("tintColor", ColorUtils.convertDecimalToRgbColor(tintColor));
|
2013-10-17 22:47:22 +00:00
|
|
|
// when bound, use the setter to propogate the color change through the tile
|
|
|
|
if ('color' in aItem) {
|
|
|
|
aItem.color = background;
|
2013-07-20 01:17:08 +00:00
|
|
|
}
|
2013-10-31 21:00:28 +00:00
|
|
|
});
|
2013-07-20 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|