[Pkg-mozext-commits] [nosquint] 08/47: Import of 1.93.0 release into git
David Prévot
taffit at moszumanska.debian.org
Tue Apr 28 01:41:16 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 2.1.6
in repository nosquint.
commit 86192cc221d8ac74a93390e3946ee2c757b347ec
Author: Jason Tackaberry <tack at urandom.ca>
Date: Fri Jan 13 19:41:13 2012 -0500
Import of 1.93.0 release into git
---
src/content/init.js | 30 +----
src/content/nosquint.js | 333 +++++++++++++++++++++++++++++++-----------------
src/install.rdf | 2 +-
3 files changed, 224 insertions(+), 141 deletions(-)
diff --git a/src/content/init.js b/src/content/init.js
index b54a412..52099ce 100644
--- a/src/content/init.js
+++ b/src/content/init.js
@@ -1,6 +1,9 @@
window.addEventListener("load", NoSquint.init, false);
window.addEventListener("unload", NoSquint.destroy, false);
+// Hook ZoomManager in order to override Firefox's internal per-site
+// zoom memory feature.
+
ZoomManager._nosquintPendingZoom = null;
ZoomManager._nosquintOrigZoomGetter = ZoomManager.__lookupGetter__('zoom');
ZoomManager._nosquintOrigZoomSetter = ZoomManager.__lookupSetter__('zoom');
@@ -38,27 +41,6 @@ ZoomManager.__defineGetter__('zoom', function() {
return ZoomManager._nosquintOrigZoomGetter();
});
-ZoomManager.enlarge = function() {
- // FIXME: do we want to update any other tabs of pages in this site?
- getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom += (NoSquint.zoomIncrement / 100.0);
- NoSquint.saveCurrentZoom();
- NoSquint.updateStatus();
-}
-
-ZoomManager.reduce = function() {
- getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom -= (NoSquint.zoomIncrement / 100.0);
- NoSquint.saveCurrentZoom();
- NoSquint.updateStatus();
-}
-
-ZoomManager.reset = function() {
- var viewer = getBrowser().mCurrentBrowser.markupDocumentViewer;
- var page_zoom_default = NoSquint.getZoomDefaults()[1];
- if (Math.round(viewer.fullZoom * 100.0) == page_zoom_default)
- // Page zoom is already at default.
- return false;
- viewer.fullZoom = page_zoom_default / 100.0;
- NoSquint.saveCurrentZoom();
- NoSquint.updateStatus();
- return true;
-}
+ZoomManager.enlarge = NoSquint.cmdEnlargePrimary;
+ZoomManager.reduce = NoSquint.cmdReducePrimary;
+ZoomManager.reset = NoSquint.cmdReset;
diff --git a/src/content/nosquint.js b/src/content/nosquint.js
index bf6df2c..49d2e9a 100644
--- a/src/content/nosquint.js
+++ b/src/content/nosquint.js
@@ -1,5 +1,9 @@
// chrome://browser/content/browser.xul
// open dialogs will raise if already open
+
+/* Returns a list of lines from a URL (such as chrome://). This function
+ * is a WTF; how more obsure could it possibly be to read a damn file?
+ */
function readLines(aURL) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
@@ -15,6 +19,7 @@ function readLines(aURL) {
return str.split("\n");
}
+/* Generate eddies in the space-time continuum. */
function debug(msg) {
dump("[nosquint] " + msg + "\n");
}
@@ -23,31 +28,30 @@ var NoSquint = {
TLDs: null, // Hash of multi-level TLDs; shared between windows
prefs: null, // Prefs service rooted at extensions.nosquint.
- mousePrefs: null, // Prefers service rooted at mousewheel.withcontrolkey.
- initialized: false, // True when init() was called
+ mousePrefs: null, // Prefs service rooted at mousewheel.withcontrolkey
+ initialized: false, // True if init() was called
prefsRecursion: 0, // Recursion level in observe()
saveTimer: null, // Timer for saveSiteList()
zoomAllTimer: null, // Timer for zoomAll()
pruneTimer: null, // Timer for pruneSites()
sitesDirty: false, // True when sites list needs saving
- ignoreNextSitesChange: false,
- zoomManagerTimeout: null,
- globalDialog: null,
- siteDialog: null,
+ ignoreNextSitesChange: false, // ignores next update to sites pref
+ zoomManagerTimeout: null, // timeout for ZoomManager.zoom setter
+ globalDialog: null, // NoSquintPrefs object if global prefs dialog open
+ siteDialog: null, // NoSquintSitePrefs object if site prefs dialog open
/* Prefs */
-
// Sites hash is keyed on site name, with value being [level, timestamp, visits]
- sites: {},
- exceptions: [],
- defaultZoomLevel: 120,
- saveDelay: 5000,
- zoomIncrement: 10,
- rememberSites: true,
- wheelZoomEnabled: false,
- hideStatus: false,
- forgetMonths: 6,
- fullZoomPrimary: false,
+ sites: {}, // extensions.nosquint.sites
+ exceptions: [], // extensions.nosquint.exceptions
+ defaultZoomLevel: 120, // extensions.nosquint.zoomlevel
+ saveDelay: 5000, // extensions.nosquint.sitesSaveDelay
+ zoomIncrement: 10, // extensions.nosquint.zoomIncrement
+ rememberSites: true, // extensions.nosquint.rememberSites
+ wheelZoomEnabled: false, // extensions.nosquint.wheelZoomEnabled
+ hideStatus: false, // extensions.nosquint.hideStatus
+ forgetMonths: 6, // extensions.nosquint.forgetMonths
+ fullZoomPrimary: false, // extensions.nosquint.fullZoomPrimary
init: function() {
@@ -103,7 +107,7 @@ var NoSquint = {
NoSquint.mousePrefs.removeObserver("", NoSquint);
if (NoSquint.sitesDirty) {
- NoSquint._saveSiteListTimer();
+ NoSquint._realSaveSiteList();
}
/* Even though we've removed the pref observers, they lamely still get
@@ -120,6 +124,12 @@ var NoSquint = {
gBrowser.tabContainer.removeEventListener("TabSelect", NoSquint.handleTabChanged, false);
},
+
+ /* Updates View | Zoom menu to replace the default Zoom In/Out menu
+ * items with Primary Zoom In/Out and Secondary Zoom In/Out. Also the
+ * "Zoom Text Only" menuitem is replaced with an option to open the NS
+ * Global prefs.
+ */
updateZoomMenu: function() {
var bundle = document.getElementById("nosquint-overlay-bundle");
var popup = document.getElementById('viewFullZoomMenu').childNodes[0];
@@ -143,7 +153,8 @@ var NoSquint = {
item.setAttribute("key", "key_" + suffix);
item.style.listStyleImage = icon;
popup.insertBefore(item, popup.childNodes[i + 2]);
- if (0 && icon) {
+ /*
+ if (icon) {
// Override toolbar icon to use platform-native enlarge icon
var button = document.getElementById("nosquint-button-" + (enlarge ? "enlarge" : "reduce"));
if (button)
@@ -152,6 +163,7 @@ var NoSquint = {
document.getElementById('nosquint-status').src = icon.replace(/url\((.*)\)/, "$1");
}
}
+ */
}
var item = document.createElement('menuitem');
item.setAttribute('command', 'cmd_noSquintPrefs');
@@ -180,6 +192,16 @@ var NoSquint = {
}
},
+
+ /* Handlers for toolar buttons */
+ buttonEnlarge: function(event) {
+ event.shiftKey ? NoSquint.cmdEnlargeSecondary() : NoSquint.cmdEnlargePrimary();
+ },
+ buttonReduce: function(event) {
+ event.shiftKey ? NoSquint.cmdReduceSecondary() : NoSquint.cmdReducePrimary();
+ },
+
+ /* Handlers for commands defined in overlay.xul */
cmdEnlargePrimary: function() {
NoSquint.fullZoomPrimary ? NoSquint.enlargeFullZoom() : NoSquint.enlargeTextZoom();
},
@@ -193,22 +215,24 @@ var NoSquint = {
NoSquint.fullZoomPrimary ? NoSquint.reduceTextZoom() : NoSquint.reduceFullZoom();
},
cmdReset: function() {
- var text_zoom_default = NoSquint.getZoomDefaults()[0];
+ var [text, full] = NoSquint.getZoomDefaults();
var viewer = getBrowser().mCurrentBrowser.markupDocumentViewer;
- if (Math.round(viewer.textZoom * 100.0) != text_zoom_default)
- viewer.textZoom = text_zoom_default / 100.0;
- if (!ZoomManager.reset()) {
+ var updated = false;
+
+ if (Math.round(viewer.textZoom * 100.0) != text)
+ updated = viewer.textZoom = text / 100.0;
+ if (Math.round(viewer.fullZoom * 100.0) != full)
+ updated = viewer.fullZoom = full / 100.0;
+
+ if (updated != false) {
+ debug("Reset: save")
NoSquint.saveCurrentZoom();
NoSquint.updateStatus();
}
},
- buttonEnlarge: function(event) {
- event.shiftKey ? NoSquint.cmdEnlargeSecondary() : NoSquint.cmdEnlargePrimary();
- },
- buttonReduce: function(event) {
- event.shiftKey ? NoSquint.cmdReduceSecondary() : NoSquint.cmdReducePrimary();
- },
+
enlargeTextZoom: function() {
+ // FIXME: do we want to update any other tabs of pages in this site?
getBrowser().mCurrentBrowser.markupDocumentViewer.textZoom += (NoSquint.zoomIncrement / 100.0);
NoSquint.saveCurrentZoom();
NoSquint.updateStatus();
@@ -219,16 +243,25 @@ var NoSquint = {
NoSquint.updateStatus();
},
enlargeFullZoom: function() {
- ZoomManager.enlarge();
+ getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom += (NoSquint.zoomIncrement / 100.0);
+ NoSquint.saveCurrentZoom();
+ NoSquint.updateStatus();
},
reduceFullZoom: function() {
- ZoomManager.reduce();
+ getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom -= (NoSquint.zoomIncrement / 100.0);
+ NoSquint.saveCurrentZoom();
+ NoSquint.updateStatus();
},
+ /* Called when a menuitem from the status panel context menu is selected. */
popupItemSelect: function(event) {
var item = event.target;
var label = item.label;
if (label.search(/%$/) != -1) {
+ /* One of the radio menuitems for zoom level was selected (label
+ * ends in %). Set the zoom level based on the radio's group
+ * name.
+ */
var level = parseInt(label.replace(/%/, ''));
var browser = gBrowser.selectedBrowser;
if (item.getAttribute('name') == 'text')
@@ -239,10 +272,16 @@ var NoSquint = {
}
},
+ /* Left or right click on the status panel. */
statusPanelClick: function(event) {
if (event.button == 0)
+ // Left click, open site prefs.
return NoSquint.openSitePrefsDialog();
+ /* Right click. Setup the context menu according to the current
+ * browser tab: the site name is set, and the appropriate radio
+ * menuitems get selected.
+ */
var popup = document.getElementById("nosquint-status-popup");
var browser = gBrowser.selectedBrowser;
@@ -270,6 +309,11 @@ var NoSquint = {
popup.openPopupAtScreen(event.screenX, event.screenY, true);
},
+
+ /* Opens the site prefs dialog, or focuses it if it's already open.
+ * In either case, the values of the dialog are updated to reflect the
+ * current browser tab.
+ */
openSitePrefsDialog: function() {
var browser = gBrowser.selectedBrowser;
var site = NoSquint.getSiteFromURI(browser.currentURI);
@@ -279,19 +323,16 @@ var NoSquint = {
NoSquint.siteDialog.setValues(browser, site);
return NoSquint.siteDialog.dialog.focus();
}
- if (NoSquint.sitesDirty)
- NoSquint._saveSiteListTimer();
window.openDialog("chrome://nosquint/content/siteprefs.xul", "NoSquint Site Settings", "chrome",
NoSquint, browser, site);
},
+ /* Opens global prefs dialog or focuses it if it's already open. */
openGlobalPrefsDialog: function() {
if (NoSquint.globalDialog)
return NoSquint.globalDialog.dialog.focus();
- if (NoSquint.sitesDirty)
- NoSquint._saveSiteListTimer();
var browser = gBrowser.selectedBrowser;
var site = NoSquint.getSiteFromURI(browser.currentURI);
var level = NoSquint.getLevelForSite(site)[0] || "default";
@@ -300,17 +341,19 @@ var NoSquint = {
site, level, url, NoSquint);
},
-
+ /* Apply increase/decrease for ctrl-mousewheel */
handleScrollWheel: function(event) {
if (!event.ctrlKey || !NoSquint.wheelZoomEnabled)
return;
var browser = gBrowser.selectedBrowser;
var text = full = false;
var increment = NoSquint.zoomIncrement * (event.detail < 0 ? 1 : -1);
+
if (NoSquint.fullZoomPrimary && !event.shiftKey || !NoSquint.fullZoomPrimary && event.shiftKey)
full = (browser.markupDocumentViewer.fullZoom * 100) + increment;
else
text = (browser.markupDocumentViewer.textZoom * 100) + increment;
+
var current = Math.round(browser.markupDocumentViewer.textZoom * 100);
NoSquint.zoom(browser, text, full);
NoSquint.saveCurrentZoom();
@@ -319,10 +362,9 @@ var NoSquint = {
event.preventDefault();
},
-
handleTabChanged: function(event) {
if (gBrowser.selectedBrowser._noSquintified) {
- // ZoomManager.fullZoom was set somewhere internally in FF. Abort
+ // ZoomManager.zoom was set somewhere internally in FF. Abort
// the pending zoom.
NoSquint.abortPendingZoomManager();
NoSquint.updateStatus();
@@ -343,18 +385,27 @@ var NoSquint = {
* gives handleTabChanged() above and our custom ProgressListener an
* opportunity to abort the pending zoom, in order to fully bypass
* FF's new internal per-site zoom mechanism.
+ *
+ * If no ZoomManager zoom is pending, then the next zoom via the
+ * ZoomManager will be eaten.
*/
abortPendingZoomManager: function() {
- debug("aborting pending ZoomManager zoom");
- if (NoSquint.zoomManagerTimeout != null) {
+ if (NoSquint.zoomManagerTimeout != null && NoSquint.zoomManagerTimeout != false) {
+ debug("aborting queued ZoomManager zoom");
clearTimeout(NoSquint.zoomManagerTimeout);
NoSquint.zoomManagerTimeout = null;
ZoomManager._nosquintPendingZoom = null;
- } else
+ } else {
+ debug("aborting next ZoomManager zoom");
NoSquint.zoomManagerTimeout = false;
+ }
},
+ /* Given a FQDN, returns only the base domain, and honors two-level TLDs.
+ * So for example, www.foo.bar.com returns bar.com, or www.foo.bar.co.uk
+ * returns bar.co.uk.
+ */
getBaseDomainFromHost: function(host) {
if (host.match(/^[\d.]+$/) != null)
// IP address.
@@ -371,13 +422,30 @@ var NoSquint = {
},
+ /* Takes an array of exceptions
+ */
processExceptions: function(exlist) {
- // My eyes! The googles do nothing!
+ /* My eyes! The googles do nothing!
+ * This hideous function takes an exception, with our custom
+ * grammar, and converts it to a regular expression that we can
+ * match later. Hostname and path components are processed in
+ * separate calls; re_star and re_dblstar define the regexp syntax
+ * for * and ** wildcards for this pattern. (This is because
+ * wildcards have different semantics for hos vs path.)
+ *
+ * Function returns a list of [length, pattern, sub] where length
+ * is the number of literal (non-wildcard) characters, pattern is
+ * the regexp that will be used to match against the URI, and sub is
+ * used (via regexp.replace) to create the site name based on the
+ * URI.
+ */
function regexpify(pattern, re_star, re_dblstar) {
var parts = pattern.split(/(\[\*+\]|\*+)/);
var pattern = [];
var sub = [];
var length = 0;
+
+ // Maps wildcards in custom grammar to regexp equivalent.
var wildcards = {
'*': '(' + re_star + ')',
'**': '(' + re_dblstar + ')',
@@ -400,7 +468,6 @@ var NoSquint = {
sub.push(part.slice(1, -1));
else
sub.push('$' + n++);
-
}
return [ length, pattern.join(''), sub.join('') ];
}
@@ -412,16 +479,22 @@ var NoSquint = {
continue;
// Escape metacharacters except *
exc = exc.replace(/([^\w*\[\]])/g, '\\$1');
- // Split into host,path parts.
+ // Split into host and path parts, and regexpify separately.
var [_, exc_host, exc_path] = exc.match(/([^\/]+)(\\\/.*|$)/);
var [ len_host, re_host, sub_host] = regexpify(exc_host, '[^.:/]+', '.*');
var [ len_path, re_path, sub_path] = regexpify(exc_path, '[^/]+', '.*');
- exceptions.push([len_host, re_host, sub_host, len_path, re_path, sub_path]);
+ exceptions.push([len_host * 1000 + len_path, re_host, sub_host, re_path, sub_path]);
}
+ // Sort the exceptions such that the ones with the highest weights
+ // (that is, the longest literal lengths) appear first.
+ exceptions.sort(function(a, b) { return b[0] - a[0]; });
return exceptions;
},
-
+ /* Given a URI, returns the site name, as computed based on user-defined
+ * exceptions. If no exception matches the URI, we fall back to the base
+ * domain name.
+ */
getSiteFromURI: function(URI) {
var t0 = new Date().getTime();
if (!URI)
@@ -430,12 +503,14 @@ var NoSquint = {
var uri_host = URI.asciiHost;
var uri_path = URI.path;
var base = NoSquint.getBaseDomainFromHost(uri_host);
-
var match = null;
- var match_weight = 0;
-
+
+ /* Iterate over each exception, trying to match it with the URI.
+ * We break the loop on the first match, because exceptions are
+ * sorted with highest weights first.
+ */
for (var i in NoSquint.exceptions) {
- var [len_host, re_host, sub_host, len_path, re_path, sub_path] = NoSquint.exceptions[i];
+ var [weight, re_host, sub_host, re_path, sub_path] = NoSquint.exceptions[i];
if (re_host != '([^.:/]+)')
var m1 = uri_host.match(new RegExp('(' + re_host + ')$'));
else
@@ -445,55 +520,42 @@ var NoSquint = {
var m2 = uri_path.match(new RegExp('^(' + re_path + ')'));
if (!m1 || !m2)
- continue;
-
- var cur_weight = len_host * 1000 + len_path;
- if (cur_weight < match_weight)
+ // No match
continue;
var site_host = m1[1].replace(new RegExp(re_host), sub_host);
var site_path = m2[1].replace(new RegExp(re_path), sub_path);
match = site_host + site_path;
- match_weight = cur_weight;
+ break;
}
var t1 = new Date().getTime();
debug("getSiteFromURI took " + (t1-t0) + " ms");
- if (match)
- return match;
- return base;
+ return match ? match : base;
},
+ /* Attaches our custom ProgressListener to the given browser. */
attach: function(browser) {
var listener = new ProgressListener(browser);
browser.addProgressListener(listener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
browser._noSquintListener = listener;
+ // Zoom browser to the appropriate levels for the current URI.
NoSquint.zoom(browser, null, null);
- //alert("Create new listener");
-
- /* Sometimes the onLocationChange handler of the ProgressListener will
- * get fired, and sometimes it won't. My best guess is this is a
- * race condition, and the location sometimes gets changed before we
- * attach the ProgressListener. So we call NoSquint.zoom() on this
- * browser explicitly for this initial page, rather than rely on the
- * progress handler.
- */
- // XXX: is this still needed (for iframes)?
- //setTimeout(function() { NoSquint.zoom(browser, null); }, 1);
},
+ /* Updates the status panel and tooltip to reflect current site name
+ * and zoom levels.
+ */
updateStatus: function() {
if (NoSquint.hideStatus)
+ // Pref indicates we're hiding status panel, no sense in updating.
return;
var browser = gBrowser.selectedBrowser;
var text = Math.round(browser.markupDocumentViewer.textZoom * 100);
var full = Math.round(browser.markupDocumentViewer.fullZoom * 100);
var [ text_default, full_default ] = NoSquint.getZoomDefaults();
- //text += (text == text_default) ? "% (default)" : "%";
- //full += (full == full_default) ? "% (default)" : "%";
-
var e = document.getElementById('nosquint-status')
if (NoSquint.fullZoomPrimary)
e.label = full + "%" + (text == text_default ? "" : (" / " + text + "%"));
@@ -506,21 +568,28 @@ var NoSquint = {
document.getElementById("nosquint-status-tooltip-text").value = text + "%";
},
- // Returns array [text_size, full_size]
+ /* Gets the levels for the given site name. (Note, this is the site name
+ * as gotten from getSiteFromURI(), not the URI itself.) Returns a
+ * 2-tuple [text_size, full_size], or [null, null] if the site is not
+ * found. (This means we should use the default zoom.)
+ */
getLevelForSite: function(site) {
- if (!site)
- return [null, null];
-
- if (NoSquint.sites[site])
+ if (site && NoSquint.sites[site])
return [NoSquint.sites[site][0], NoSquint.sites[site][3]];
return [null, null];
},
+ /* Returns a 2-tuple [text_default, full_default] representing the default
+ * zoom levels.
+ */
getZoomDefaults: function() {
return [ NoSquint.fullZoomPrimary ? 100 : NoSquint.defaultZoomLevel,
NoSquint.fullZoomPrimary ? NoSquint.defaultZoomLevel : 100 ];
},
+ /* Returns a 2-tuple [text_default, full_default] zoom levels for the
+ * current browser.
+ */
getLevelForBrowser: function(browser) {
if (!browser._noSquintSite)
browser._noSquintSite = NoSquint.getSiteFromURI(browser.currentURI);
@@ -563,6 +632,12 @@ var NoSquint = {
NoSquint.updateStatus();
},
+ /* Updates the zoom levels for all tabs; each tab is set to the levels
+ * for the current URIs of each browser. If 'attach' is true, then
+ * ProgressListeners are attached to each browser as well. This is
+ * useful on initialization, where we can hook into any tabs that may
+ * have been open prior to initialization.
+ */
zoomAll: function(attach) {
debug("zooming all tabs; attach listeners = " + attach);
for (var i = 0; i < gBrowser.browsers.length; i++) {
@@ -574,29 +649,38 @@ var NoSquint = {
NoSquint.attach(browser);
}
NoSquint.updateStatus();
+ clearTimeout(NoSquint.zoomAllTimer);
+ NoSquint.zoomAllTimer = null;
},
+ /* Queues a zoomAll. Useful when we might otherwise call zoomAll()
+ * multiple times.
+ */
queueZoomAll: function() {
- if (NoSquint.zoomAllTimer != null)
- clearTimeout(NoSquint.zoomAllTimer);
- NoSquint.zoomAllTimer = setTimeout(function() { NoSquint.zoomAll(false); }, 1);
+ if (!NoSquint.zoomAllTimer)
+ NoSquint.zoomAllTimer = setTimeout(function() { NoSquint.zoomAll(false); }, 1);
},
+ /* Callback from custom ProgressListener when the given browser's URI
+ * has changed.
+ */
locationChanged: function(browser, uri) {
var site = NoSquint.getSiteFromURI(uri);
if (site != browser._noSquintSite)
- // Site changed; update timestamp on new site.
+ // Site accessed; update timestamp on new site.
NoSquint.updateSiteList(site, null, true);
+
browser._noSquintSite = site;
var [ text, full ] = NoSquint.getLevelForBrowser(browser);
NoSquint.zoom(browser, text, full);
if (NoSquint.siteDialog && NoSquint.siteDialog.browser == browser)
NoSquint.siteDialog.setValues(browser, site);
- // XXX: is this still needed (for iframes) in ff3?
- //setTimeout(function() { NoSquint.zoom(browser, NoSquint.getLevelForBrowser(browser)); }, 1);
},
+ /* Called periodically (on startup, and once a day after that) in order to
+ * remove remembered values for sites we haven't visited in forgetMonths.
+ */
pruneSites: function() {
if (!NoSquint.rememberSites || NoSquint.forgetMonths == 0)
return;
@@ -639,6 +723,13 @@ var NoSquint = {
NoSquint.updateSiteList(browser, [text, full]);
},
+ /* Updates the site list for the given site name (or browser, from which
+ * we'll grab the site name) to set the given levels (2-tuple of
+ * [text, full]) and update_timestamp is a bool which, if true, will
+ * cause the site's timestamp to be updated to the current time.
+ *
+ * Once updated, the site list is then queued for save in the prefs.
+ */
updateSiteList: function(site_or_browser, levels, update_timestamp) {
var site = site_or_browser;
if (typeof(site_or_browser) != "string")
@@ -657,6 +748,7 @@ var NoSquint = {
if (levels) {
var [ text_default, full_default ] = NoSquint.getZoomDefaults();
var [ text, full ] = levels;
+ // Default zoom levels are stored as 0.
[ text, full ] = [ text == text_default ? 0 : text, full == full_default ? 0 : full ];
if (!text && !full) {
@@ -667,6 +759,7 @@ var NoSquint = {
delete NoSquint.sites[site];
} else {
if (!NoSquint.sites[site])
+ // New site record
NoSquint.sites[site] = [text, new Date().getTime(), 1, full];
else {
NoSquint.sites[site][0] = text;
@@ -674,12 +767,14 @@ var NoSquint = {
}
// TODO: go through current tabs and resize tabs for this site
}
+
+ // Queue site list save.
NoSquint.saveSiteList();
}
return true;
},
- /* Stores the site list in the prefs service.
+ /* Queues a save of the site list in the prefs service.
*
* NOTE: This must only be called when the list has actually changed, or
* else the next time a change is made in the Settings dialog, it will
@@ -687,16 +782,19 @@ var NoSquint = {
*/
saveSiteList: function() {
if (NoSquint.saveTimer != null)
+ // Restart timer
clearTimeout(NoSquint.saveTimer);
NoSquint.sitesDirty = true;
- // The list is actually saved (by default) 5s later, so if the user
- // changes the zoom several times in a short period of time, we aren't
- // needlessly iterating over the sites array.
- NoSquint.saveTimer = setTimeout(function() { NoSquint._saveSiteListTimer(); }, NoSquint.saveDelay);
+ /* The list is actually saved (by default) 5s later, so if the user
+ * changes the zoom several times in a short period of time, we aren't
+ * needlessly iterating over the sites array.
+ */
+ NoSquint.saveTimer = setTimeout(function() { NoSquint._realSaveSiteList(); }, NoSquint.saveDelay);
},
- _saveSiteListTimer: function() {
+ /* Actually store the sites list. */
+ _realSaveSiteList: function() {
/* XXX: this can take up to 20ms (!!!) even with a smallish sites list
* (about 50). If it scales linearly, this could be a problem. Need
* to do some more serious benchmarking here. Looks like setCharPref
@@ -716,6 +814,12 @@ var NoSquint = {
* the pref it will fire a notification that we'll handle in
* prefsChanged() which is not necessary here. So set a flag that causes
* the next prefs notification for sites change to be ignored.
+ *
+ * TODO: this might not actually be relevant anymore, since the global
+ * prefs dialog no longer modifies the sites list. Think on this, and
+ * if it's Think on this, and if that's the case, remove this obsolete
+ * comments and NoSquint.ignoreNextSitesChange.
+ *
*/
NoSquint.ignoreNextSitesChange = true;
NoSquint.prefs.setCharPref("sites", siteList);
@@ -725,8 +829,13 @@ var NoSquint = {
NoSquint.sitesDirty = false;
},
+ /* Attach observers on extensions.nosquint and mousewheel.withcontrolkey
+ * branches, and simulate a change to each of our prefs so that we can
+ * load them.
+ */
initPrefs: function() {
if (NoSquint.prefs)
+ // Prefs already initialized.
return;
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(
@@ -754,25 +863,31 @@ var NoSquint = {
"sitesSaveDelay", "rememberSites", "exceptions", "sites", "forgetMonths", "fullZoomPrimary"
];
for (var i in prefs)
+ // Simulate a change
NoSquint.observe(null, "nsPref:changed", prefs[i]);
-
-
+ // Attach observers to both branches.
NoSquint.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
NoSquint.prefs.addObserver("", NoSquint, false);
NoSquint.mousePrefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
NoSquint.mousePrefs.addObserver("", NoSquint, false);
},
+ /* Callback from prefs observer when a pref has changed in one of the
+ * branches we are watching.
+ */
observe: function(subject, topic, data) {
if (topic != "nsPref:changed" || typeof(NoSquint) == 'undefined' || !NoSquint.prefs)
+ // Either not a pref change, or we are in the process of shutting down.
return;
+ // Used for mousewheel.withcontrolkey.action
NoSquint.prefsRecursion++;
switch (data) {
case "action":
if (NoSquint.prefsRecursion > 1)
+ // This update comes from us, ignore it.
break;
/* If mousewheel.withcontrolkey.action has changed (perhaps via another
* extension or edited manually by the user) try to do something
@@ -784,10 +899,10 @@ var NoSquint = {
var action = NoSquint.mousePrefs.getIntPref("action");
if (action == 3 || action == 5) {
NoSquint.prefs.setBoolPref("wheelZoomEnabled", true);
- //alert("Setting wheelZoomEnabled=true, action=0 because action == 3");
+ debug("setting wheelZoomEnabled=true, action=0 because action == " + action);
NoSquint.mousePrefs.setIntPref("action", 0);
} else if (action != 0) {
- //alert("Setting wheelZoomEnabled=false because action != 3 == " + action);
+ debug("setting wheelZoomEnabled=false because action != 3 == " + action);
NoSquint.prefs.setBoolPref("wheelZoomEnabled", false);
}
break;
@@ -799,7 +914,6 @@ var NoSquint = {
case "wheelZoomEnabled":
NoSquint.wheelZoomEnabled = NoSquint.prefs.getBoolPref("wheelZoomEnabled");
- //alert("Pref wheelZoomEnabled changed to " + NoSquint.wheelZoomEnabled);
if (NoSquint.wheelZoomEnabled)
NoSquint.mousePrefs.setIntPref("action", 0);
break;
@@ -824,15 +938,6 @@ var NoSquint = {
document.getElementById("nosquint-status").hidden = NoSquint.hideStatus;
if (!NoSquint.hideStatus)
NoSquint.handleTabChanged();
-
- /*
- if (NoSquint.hideStatus)
- gBrowser.tabContainer.removeEventListener("TabSelect", NoSquint.handleTabChanged, false);
- else {
- gBrowser.tabContainer.addEventListener("TabSelect", NoSquint.handleTabChanged, false);
- NoSquint.handleTabChanged();
- }
- */
break;
case "rememberSites":
@@ -847,18 +952,18 @@ var NoSquint = {
case "exceptions":
// Parse exceptions list from prefs
var exlist = NoSquint.prefs.getCharPref("exceptions").replace(/(^\s+|\s+$)/g, "").split(" ");
- //var list = NoSquint.parseExceptions(NoSquint.prefs.getCharPref("exceptions"));
NoSquint.exceptions = NoSquint.processExceptions(exlist);
NoSquint.queueZoomAll();
break;
case "sites":
- /* Parse site list from prefs. The prefs string a list of site specs,
- * delimited by a space, in the form sitename=level,timestamp,visits.
- * Spaces are not allowed in any value. Level, timestamp, and visits
- * are all integers. The parsing code tries to be robust and handle
- * malformed entries gracefully (in case the user edits them manually
- * and screws up).
+ /* Parse site list from prefs. The prefs string a list of site
+ * specs, delimited by a space, in the form
+ * "sitename=text_level,timestamp,visits,full_level". Spaces
+ * are not allowed in any value; sitename is a string, all
+ * other values are integers. The parsing code tries to be
+ * robust and handle malformed entries gracefully (in case the
+ * user edits them manually and screws up).
*/
// TODO: look at nsIContentPrefService
if (NoSquint.ignoreNextSitesChange) {
@@ -931,13 +1036,9 @@ ProgressListener.prototype.onLocationChange = function(progress, request, uri) {
}
ProgressListener.prototype.onStateChange = function(progress, request, state, status) {
- /*
- if (this.update) {
- this.update = false;
- NoSquint.locationChanged(this.browser, this.browser.currentURI);
- }
- */
if (!progress.isLoadingDocument) {
+ // Document load is fone; queue a save of the site list if it has been
+ // changed.
if (NoSquint.sitesDirty)
NoSquint.saveSiteList();
} else if (NoSquint.saveTimer) {
diff --git a/src/install.rdf b/src/install.rdf
index e29e2fb..3633bcc 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -6,7 +6,7 @@
<em:id>nosquint at urandom.ca</em:id>
<em:name>No Squint</em:name>
- <em:version>1.92.0</em:version>
+ <em:version>1.93.0</em:version>
<em:description>Manage site-specific full page and text zoom levels</em:description>
<em:creator>Jason Tackaberry</em:creator>
<!-- optional items -->
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/nosquint.git
More information about the Pkg-mozext-commits
mailing list