From b196e84ca2a1edb02a85debf55c431482dd59285 Mon Sep 17 00:00:00 2001 From: John Foerch Date: Tue, 28 Aug 2012 18:57:54 -0400 Subject: [PATCH] point-per-window design started --- content/conkeror.xul | 1 + modules/buffer.js | 101 ++++++++++++++++++++++++++++------------ modules/conkeror.js | 1 + modules/content-buffer.js | 4 +- modules/point-commands.js | 19 ++++++++ modules/window.js | 2 + style/default/buffer--point.css | 2 +- 7 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 modules/point-commands.js diff --git a/content/conkeror.xul b/content/conkeror.xul index 21fa58c..0be54ce 100644 --- a/content/conkeror.xul +++ b/content/conkeror.xul @@ -50,5 +50,6 @@ COPYING file. + diff --git a/modules/buffer.js b/modules/buffer.js index 3cfe719..ad409b0 100644 --- a/modules/buffer.js +++ b/modules/buffer.js @@ -118,6 +118,17 @@ function buffer_creator (type) { }; } +function point_state () { +} +point_state.prototype = { + constructor: point_state, + toString: function () "#", + top: 0, + left: 0, + width: 30, + height: 30 +}; + function buffer_modality (buffer) { buffer.keymaps.push(default_global_keymap); } @@ -141,24 +152,6 @@ function buffer (window) { this.browser = element.firstChild; this.element.conkeror_buffer_object = this; - var point = create_XUL(window, "box"); - point.setAttribute("class", "point"); - point.setAttribute("top", "0"); - point.setAttribute("left", "0"); - window.buffers.container.parentNode.appendChild(point); - this.point = point; - if (window.buffers.count == 1) - point.focus(); - else - point.setAttribute("hidden", "true"); - /* - * Test stuff - */ - function point_debug_keydown (e) { - dumpln("point keydown: "+format_key_combo(e)); - } - point.addEventListener("keydown", point_debug_keydown, true); - this.local = { __proto__: conkeror }; this.page = null; this.enabled_modes = []; @@ -206,6 +199,12 @@ function buffer (window) { buffer.set_input_mode(); }, true); + // point init + // + this.web_navigation.sessionHistory.addSHistoryListener(this); + this.point_history = []; + this.point_history.index = -1; + this.modalities = [buffer_modality]; // When create_buffer_early_hook runs, basic buffer properties @@ -217,6 +216,7 @@ function buffer (window) { buffer.prototype = { constructor: buffer, toString: function () "#", + QueryInterface: generate_QI(Ci.nsISHistoryListener, Ci.nsISupportsWeakReference), // default_position is the default value for the $position keyword to // the buffer constructor. This property can be set on the prototype @@ -232,8 +232,6 @@ buffer.prototype = { // get name () [must be defined by subclasses] dead: false, /* This is set when the buffer is killed */ - point: null, - keymaps: null, mark_active: false, @@ -279,14 +277,14 @@ buffer.prototype = { destroy: function () { this.dead = true; + this.web_navigation.sessionHistory.removeSHistoryListener(this); + this.point_history = null; this.browser = null; this.element = null; this.saved_focused_frame = null; this.saved_focused_element = null; // prevent modalities from accessing dead browser this.modalities = []; - this.point.parentNode.removeChild(this.point); - this.point = null; }, set_input_mode: function () { @@ -380,6 +378,54 @@ buffer.prototype = { break; win = win.parent; } + }, + + // nsISHistoryListener interface + // + point_history: null, + get point () this.point_history[this.point_history.index] || null, + point_update: function () { + var p = this.point_history[this.point_history.index]; + this.window.point.setAttribute("top", p.top); + this.window.point.setAttribute("left", p.left); + this.window.point.style.width = p.width + "px"; + this.window.point.style.height = p.height + "px"; + }, + OnHistoryNewEntry: function (uri) { + dumpln("point_history_listener OnHistoryNewEntry"); + this.point_history.push(new point_state()); + this.point_history.index++; + this.point_update(); + }, + OnHistoryGoBack: function (uri) { + dumpln("point_history_listener OnHistoryGoBack"); + this.point_history.index--; + this.point_update(); + return true; + }, + OnHistoryGoForward: function (uri) { + dumpln("point_history_listener OnHistoryGoForward"); + this.point_history.index++; + this.point_update(); + return true; + }, + OnHistoryReload: function (uri, reload_flags) { + dumpln("point_history_listener OnHistoryReload"); + // perhaps save the xpath of any currently selected node so that + // we can attempt to reselect the same node after reload. + return true; + }, + OnHistoryGotoIndex: function (index, uri) { + dumpln("point_history_listener OnHistoryGotoIndex"); + this.point_history.index = index; + this.point_update(); + return true; + }, + OnHistoryPurge: function (num_entries) { + dumpln("point_history_listener OnHistoryPurge"); + this.point_history.splice(0, num_entries); + this.point_history.index -= num_entries; + return true; } }; @@ -472,9 +518,6 @@ buffer_container.prototype = { old_value.saved_focused_frame = old_value.focused_frame; old_value.saved_focused_element = old_value.focused_element; - old_value.point.blur(); - old_value.point.setAttribute("hidden", "true"); - if ('isActive' in old_value.browser.docShell) old_value.browser.docShell.isActive = false; old_value.browser.setAttribute("type", "content"); @@ -484,8 +527,6 @@ buffer_container.prototype = { // Select new buffer in the XUL deck this.container.selectedPanel = buffer.element; - buffer.point.setAttribute("hidden", "false"); - buffer.browser.setAttribute("type", "content-primary"); if ('isActive' in buffer.browser.docShell) buffer.browser.docShell.isActive = true; @@ -504,12 +545,12 @@ buffer_container.prototype = { else if (buffer.saved_focused_frame) set_focus_no_scroll(this.window, buffer.saved_focused_frame); - if (! buffer.saved_focused_element) - buffer.point.focus(); - buffer.saved_focused_element = null; buffer.saved_focused_frame = null; + if (buffer.point) + buffer.point_update(); + buffer.set_input_mode(); this.window.minibuffer.set_default_message(buffer.default_message); diff --git a/modules/conkeror.js b/modules/conkeror.js index a778f17..edfd21d 100644 --- a/modules/conkeror.js +++ b/modules/conkeror.js @@ -58,6 +58,7 @@ require("commands.js"); require("webjump.js"); require("history.js"); require("scroll.js"); +require("point-commands.js"); require("save.js"); diff --git a/modules/content-buffer.js b/modules/content-buffer.js index 8423525..3e0e685 100644 --- a/modules/content-buffer.js +++ b/modules/content-buffer.js @@ -157,6 +157,9 @@ function content_buffer (window) { content_buffer.prototype = { constructor: content_buffer, toString: function () "#", + QueryInterface: generate_QI(Ci.nsISHistoryListener, + Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference), destroy: function () { this.browser.removeProgressListener(this); @@ -196,7 +199,6 @@ content_buffer.prototype = { // nsIWebProgressListener interface // - QueryInterface: generate_QI(Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference), // This method is called to indicate state changes. onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) { diff --git a/modules/point-commands.js b/modules/point-commands.js new file mode 100644 index 0000000..6954310 --- /dev/null +++ b/modules/point-commands.js @@ -0,0 +1,19 @@ + + +interactive( + "point-select", + "", + function (I) { + var elem = yield read_browser_object(I); + var rect = elem.getBoundingClientRect(); + var point = I.buffer.point; + point.top = rect.top; + point.left = rect.left; + point.width = rect.width; + point.height = rect.height; + I.buffer.point_update(); + }, + $browser_object = browser_object_dom_node); + + +provide("point-commands"); diff --git a/modules/window.js b/modules/window.js index d96ab27..74d12cd 100644 --- a/modules/window.js +++ b/modules/window.js @@ -174,6 +174,8 @@ function window_initialize (window) { tag = window.args.tag; window.tag = generate_new_window_tag(tag); + window.point = window.document.getElementById("point"); + // Add a getBrowser() function to help certain extensions designed // for Firefox work with conkeror window.getBrowser = window_get_this_browser; diff --git a/style/default/buffer--point.css b/style/default/buffer--point.css index 874fa42..8acb2db 100644 --- a/style/default/buffer--point.css +++ b/style/default/buffer--point.css @@ -1,7 +1,7 @@ @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); -.point { +#point { width: 30px; height: 30px; background-color: none; -- 2.11.4.GIT