1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 11:48:00 +01:00

Defer some initialization until the first window is visible.

This commit is contained in:
Kris Maglione
2011-08-21 11:52:55 -04:00
parent 5f42595f65
commit f830771283
4 changed files with 49 additions and 15 deletions

View File

@@ -26,6 +26,10 @@
<binding id="tab" display="xul:hbox"
extends="chrome://browser/content/tabbrowser.xml#tabbrowser-tab">
<implementation>
<property name="dactylOrdinal" onget="parseInt(this.getAttribute('dactylOrdinal'))"
onset="this.setAttribute('dactylOrdinal', val)"/>
</implementation>
<content closetabtext="Close Tab">
<xul:stack class="tab-icon dactyl-tab-stack">
<xul:image xbl:inherits="validate,src=image" role="presentation" class="tab-icon-image"/>
@@ -45,6 +49,10 @@
<binding id="tab-mac"
extends="chrome://browser/content/tabbrowser.xml#tabbrowser-tab">
<implementation>
<property name="dactylOrdinal" onget="parseInt(this.getAttribute('dactylOrdinal'))"
onset="this.setAttribute('dactylOrdinal', val)"/>
</implementation>
<content chromedir="ltr" closetabtext="Close Tab">
<xul:hbox class="tab-image-left" xbl:inherits="selected"/>
<xul:hbox class="tab-image-middle" flex="1" align="center" xbl:inherits="selected">

View File

@@ -56,6 +56,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
delete window.dactyl;
delete window.liberator;
// Prevents box ordering bugs after our stylesheet is removed.
styles.system.add("cleanup-sheet", config.styleableChrome, <![CDATA[
#TabsToolbar tab { display: none; }
]]>);

View File

@@ -72,6 +72,9 @@ var Tabs = Module("tabs", {
for (let elem in values(["dactyl-tab-icon-number", "dactyl-tab-number"].map(node)))
if (elem)
elem.parentNode.parentNode.removeChild(elem.parentNode);
delete tab.dactylOrdinal;
tab.removeAttribute("dactylOrdinal");
}
},
@@ -82,16 +85,21 @@ var Tabs = Module("tabs", {
if (!node("dactyl-tab-number")) {
let img = node("tab-icon-image");
if (img) {
let dom = DOM(<xul xmlns:xul={XUL} xmlns:html={XHTML}
><xul:hbox highlight="tab-number"><xul:label key="icon" align="center" highlight="TabIconNumber" class="dactyl-tab-icon-number"/></xul:hbox
><xul:hbox highlight="tab-number"><html:div key="label" highlight="TabNumber" class="dactyl-tab-number"/></xul:hbox
></xul>.*, document).appendTo(img.parentNode);
tab.__defineGetter__("dactylOrdinal", function () Number(dom.nodes.icon.value));
tab.__defineSetter__("dactylOrdinal", function (i) dom.nodes.icon.value = dom.nodes.label.textContent = i);
let dom = DOM(<xul xmlns:xul={XUL} xmlns:html={XHTML}>
<xul:hbox highlight="tab-number"><xul:label key="icon" align="center" highlight="TabIconNumber" class="dactyl-tab-icon-number"/></xul:hbox>
<xul:hbox highlight="tab-number"><html:div key="label" highlight="TabNumber" class="dactyl-tab-number"/></xul:hbox>
</xul>.elements(), document).appendTo(img.parentNode);
update(tab, {
get dactylOrdinal() Number(dom.nodes.icon.value),
set dactylOrdinal(i) {
dom.nodes.icon.value = dom.nodes.label.textContent = i;
this.setAttribute("dactylOrdinal", i);
}
});
}
}
}
tab.setAttribute("dactylOrdinal", i + 1);
tab.dactylOrdinal = i + 1;
}
statusline.updateTabCount(true);

View File

@@ -41,6 +41,8 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
util.addObserver(this);
this.overlays = {};
this.onWindowVisible = [];
config.loadStyles();
this.timeout(this.initialize);
@@ -287,13 +289,20 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
});
});
// Module.list.forEach(load);
frob("load");
modules.times = update({}, defineModule.times);
function finish() {
// Module.list.forEach(load);
frob("load");
modules.times = update({}, defineModule.times);
defineModule.loadLog.push("Loaded in " + (Date.now() - start) + "ms");
defineModule.loadLog.push("Loaded in " + (Date.now() - start) + "ms");
overlay.windows = array.uniq(overlay.windows.concat(window), true);
overlay.windows = array.uniq(overlay.windows.concat(window), true);
}
if (overlay.onWindowVisible)
overlay.onWindowVisible.push(finish);
else
finish();
modules.events.listen(window, "unload", function onUnload() {
window.removeEventListener("unload", onUnload.wrapped, false);
@@ -337,7 +346,13 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
}), true);
},
"chrome-document-global-created": function (window, uri) { this.observe(window, "toplevel-window-ready", null); },
"content-document-global-created": function (window, uri) { this.observe(window, "toplevel-window-ready", null); }
"content-document-global-created": function (window, uri) { this.observe(window, "toplevel-window-ready", null); },
"xul-window-visible": function () {
if (this.onWindowVisible) {
this.onWindowVisible.forEach(function (f) f.call(this), this);
this.onWindowVisible = null;
}
}
},
overlayWindow: function (url, fn) {
@@ -351,8 +366,10 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
}, this);
for (let doc in util.iterDocuments())
if (["interactive", "complete"].indexOf(doc.readyState) >= 0)
if (~["interactive", "complete"].indexOf(doc.readyState)) {
this.onWindowVisible = null;
this._loadOverlays(doc.defaultView);
}
else
this.observe(doc.defaultView, "toplevel-window-ready");
}
@@ -363,7 +380,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
window.dactylOverlays = [];
for each (let obj in overlay.overlays[window.document.documentURI] || []) {
if (window.dactylOverlays.indexOf(obj) >= 0)
if (~window.dactylOverlays.indexOf(obj))
continue;
window.dactylOverlays.push(obj);
this._loadOverlay(window, obj(window));