1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 22:47:59 +01:00
This commit is contained in:
Kris Maglione
2010-12-26 23:45:28 -05:00
parent 8a5eb69492
commit c7c7ab68ee
2 changed files with 16 additions and 64 deletions

View File

@@ -148,39 +148,12 @@ var Buffer = Module("buffer", {
buffer.viewSource([elem.getAttribute("href"), Number(elem.getAttribute("line"))]) buffer.viewSource([elem.getAttribute("href"), Number(elem.getAttribute("line"))])
}; };
this.replaceProgressListener(this.progressListener); this.cleanupProgressListener = util.overlayObject(window.XULBrowserWindow,
this.progressListener);
}, },
cleanup: function () { cleanup: function () {
for (let prop in properties(this.progressListener)) this.cleanupProgressListener();
if (!this.progressListener.__lookupGetter__(prop) &&
!callable(this.progressListener[prop]))
this.origProgressListener[prop] = this.progressListener[prop]
this.replaceProgressListener(this.origProgressListener);
},
replaceProgressListener: function (newListener) {
// I hate this whole hack. --Kris
let obj = window.XULBrowserWindow, getter;
for (let prop in properties(obj))
if ((getter = obj.__lookupGetter__(prop)) && !obj.__lookupSetter__(prop)) {
newListener.__defineGetter__(prop, getter);
delete obj[prop];
}
this.origProgressListener = window.XULBrowserWindow;
try {
config.browser.removeProgressListener(window.XULBrowserWindow);
}
catch (e) {} // Why? --djk
config.browser.addProgressListener(newListener, Ci.nsIWebProgress.NOTIFY_ALL);
window.XULBrowserWindow = newListener;
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = newListener;
}, },
destroy: function () { destroy: function () {
@@ -237,11 +210,6 @@ var Buffer = Module("buffer", {
dactyl.initHelp(); dactyl.initHelp();
config.styleHelp(); config.styleHelp();
} }
// mark the buffer as loaded, we can't use buffer.loaded
// since that always refers to the current buffer, while doc can be
// any buffer, even in a background tab
doc.pageIsFullyLoaded = 1;
} }
if (doc instanceof HTMLDocument) { if (doc instanceof HTMLDocument) {
@@ -266,10 +234,8 @@ var Buffer = Module("buffer", {
/** /**
* @property {Object} The document loading progress listener. * @property {Object} The document loading progress listener.
*/ */
progressListener: update(Object.create(window.XULBrowserWindow), { progressListener: {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIWebProgressListener]), dactylLoadCount: 0,
loadCount: 0,
// XXX: function may later be needed to detect a canceled synchronous openURL() // XXX: function may later be needed to detect a canceled synchronous openURL()
onStateChange: function onStateChange(webProgress, request, flags, status) { onStateChange: function onStateChange(webProgress, request, flags, status) {
@@ -280,12 +246,11 @@ var Buffer = Module("buffer", {
// This fires when the load event is initiated // This fires when the load event is initiated
// only thrown for the current tab, not when another tab changes // only thrown for the current tab, not when another tab changes
if (flags & Ci.nsIWebProgressListener.STATE_START) { if (flags & Ci.nsIWebProgressListener.STATE_START) {
webProgress.DOMWindow.document.pageIsFullyLoaded = 0;
statusline.updateProgress(0); statusline.updateProgress(0);
buffer._triggerLoadAutocmd("PageLoadPre", webProgress.DOMWindow.document); buffer._triggerLoadAutocmd("PageLoadPre", webProgress.DOMWindow.document);
if (document.commandDispatcher.focusedWindow == webProgress.DOMWindow && this.loadCount++) if (document.commandDispatcher.focusedWindow == webProgress.DOMWindow && this.dactylLoadCount++)
util.timeout(function () { modes.reset(false); }, util.timeout(function () { modes.reset(false); },
dactyl.mode == modes.HINTS ? 500 : 0); dactyl.mode == modes.HINTS ? 500 : 0);
} }
@@ -294,8 +259,6 @@ var Buffer = Module("buffer", {
config.browser.mCurrentBrowser.collapsed = false; config.browser.mCurrentBrowser.collapsed = false;
if (!dactyl.focusedElement) if (!dactyl.focusedElement)
dactyl.focusContent(); dactyl.focusContent();
webProgress.DOMWindow.document.pageIsFullyLoaded = (status == 0 ? 1 : 2);
statusline.updateUrl(); statusline.updateUrl();
} }
} }
@@ -366,7 +329,7 @@ var Buffer = Module("buffer", {
break; break;
} }
}, },
}), },
/** /**
* @property {Array} The alternative style sheets for the current * @property {Array} The alternative style sheets for the current
@@ -387,19 +350,12 @@ var Buffer = Module("buffer", {
pageInfo: null, pageInfo: null,
/** /**
* @property {number} A value indicating whether the buffer is loaded. * @property {number} True when the buffer is fully loaded.
* Values may be:
* 0 - Loading.
* 1 - Fully loaded.
* 2 - Load failed.
*/ */
get loaded() get loaded() Math.min.apply(null,
Math.min.apply(Math, buffer.allFrames()
buffer.allFrames().map(function (frame) .map(function (frame) ["loading", "interactive", "complete"]
frame.document.pageIsFullyLoaded || 0)), .indexOf(frame.document.readyState))),
set loaded(val)
buffer.allFrames().forEach(function (frame)
frame.document.pageIsFullyLoaded = val),
/** /**
* @property {Object} The local state store for the currently selected * @property {Object} The local state store for the currently selected

View File

@@ -192,7 +192,6 @@ var Events = Module("events", {
} }
catch (e) {} catch (e) {}
buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro
modes.replaying = true; modes.replaying = true;
res = events.feedkeys(this._macros.get(this._lastMacro).keys, { noremap: true }); res = events.feedkeys(this._macros.get(this._lastMacro).keys, { noremap: true });
modes.replaying = false; modes.replaying = false;
@@ -643,15 +642,14 @@ var Events = Module("events", {
commandline.clear(); commandline.clear();
// TODO: allow macros to be continued when page does not fully load with an option // TODO: allow macros to be continued when page does not fully load with an option
let ret = (buffer.loaded == 1); if (!buffer.loaded)
if (!ret)
dactyl.echoerr("Page did not load completely in " + maxWaitTime + " seconds. Macro stopped."); dactyl.echoerr("Page did not load completely in " + maxWaitTime + " seconds. Macro stopped.");
// sometimes the input widget had focus when replaying a macro // sometimes the input widget had focus when replaying a macro
// maybe this call should be moved somewhere else? // maybe this call should be moved somewhere else?
// dactyl.focusContent(true); // dactyl.focusContent(true);
return ret; return buffer.loaded;
}, },
onDOMMenuBarActive: function () { onDOMMenuBarActive: function () {
@@ -1092,8 +1090,7 @@ var Events = Module("events", {
else if (this.pendingArgMap) { else if (this.pendingArgMap) {
let map = this.pendingArgMap; let map = this.pendingArgMap;
if (!Events.isEscape(key)) if (!Events.isEscape(key))
if (!modes.replaying || this.waitForPageLoad()) execute(map, null, this.count, key);
execute(map, null, this.count, key);
return true; return true;
} }
else if (map && !event.skipmap && candidates.length == 0) { else if (map && !event.skipmap && candidates.length == 0) {
@@ -1122,8 +1119,7 @@ var Events = Module("events", {
if (modes.replaying && !this.waitForPageLoad()) if (modes.replaying && !this.waitForPageLoad())
return true; return true;
let ret = execute(map, null, this.count); return !execute(map, null, this.count) || !map.route
return !(map.route && ret);
} }
} }
else if (mappings.getCandidates(this.main, candidateCommand).length > 0 && !event.skipmap) { else if (mappings.getCandidates(this.main, candidateCommand).length > 0 && !event.skipmap) {