mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 05:47:58 +01:00
Liberate Buffer from the tyrany of the current window. Add DOM#contextmenu event. Provide sensible screenX/screenY for mouse events.
--HG-- rename : common/content/buffer.js => common/modules/buffer.jsm
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
"use strict";
|
||||
|
||||
var DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
|
||||
|
||||
// also includes methods for dealing with keywords and search engines
|
||||
var Bookmarks = Module("bookmarks", {
|
||||
init: function () {
|
||||
|
||||
@@ -19,9 +19,8 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
|
||||
this.forceOpen = opts.forceOpen || dactyl.forceOpen;
|
||||
|
||||
// Hack.
|
||||
if (!opts.window && modes.main == modes.OUTPUT_MULTILINE)
|
||||
opts.window = commandline.widgets.multilineOutput.contentWindow;
|
||||
if (!opts.window)
|
||||
opts.window = modes.getStack(0).params.window;
|
||||
|
||||
this.hintMode = hints.modes[mode];
|
||||
dactyl.assert(this.hintMode);
|
||||
@@ -760,7 +759,7 @@ var Hints = Module("hints", {
|
||||
this.addMode("V", "View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true));
|
||||
this.addMode("y", "Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true));
|
||||
this.addMode("Y", "Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true));
|
||||
this.addMode("c", "Open context menu", function (elem) buffer.openContextMenu(elem));
|
||||
this.addMode("c", "Open context menu", function (elem) DOM(elem).contextmenu());
|
||||
this.addMode("i", "Show image", function (elem) dactyl.open(elem.src));
|
||||
this.addMode("I", "Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB));
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ var History = Module("history", {
|
||||
let root = services.history.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
try {
|
||||
let items = iter(util.range(0, root.childCount)).map(function (i) {
|
||||
var items = iter(util.range(0, root.childCount)).map(function (i) {
|
||||
let node = root.getChild(i);
|
||||
return {
|
||||
url: node.uri,
|
||||
title: node.title,
|
||||
icon: node.icon ? node.icon : DEFAULT_FAVICON
|
||||
icon: node.icon ? node.icon : BookmarkCache.DEFAULT_FAVICON
|
||||
};
|
||||
}).toArray();
|
||||
}
|
||||
|
||||
@@ -227,6 +227,8 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
||||
}
|
||||
}
|
||||
}, {
|
||||
DEFAULT_FAVICON: "chrome://mozapps/skin/places/defaultFavicon.png",
|
||||
|
||||
getAnnotation: function getAnnotation(item, anno)
|
||||
services.annotation.itemHasAnnotation(item, anno) ?
|
||||
services.annotation.getItemAnnotation(item, anno) : null,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -107,6 +107,7 @@ var ConfigBase = Class("ConfigBase", {
|
||||
global: ["addons",
|
||||
"base",
|
||||
"io",
|
||||
"buffer",
|
||||
"cache",
|
||||
"commands",
|
||||
"completion",
|
||||
@@ -136,7 +137,6 @@ var ConfigBase = Class("ConfigBase", {
|
||||
"commandline",
|
||||
"abbreviations",
|
||||
"autocommands",
|
||||
"buffer",
|
||||
"editor",
|
||||
"events",
|
||||
"hints",
|
||||
|
||||
@@ -318,7 +318,7 @@ var DOM = Class("DOM", {
|
||||
}),
|
||||
}),
|
||||
|
||||
get rect() this[0].getBoundingClientRect(),
|
||||
get rect() this[0] ? this[0].getBoundingClientRect() : {},
|
||||
|
||||
get viewport() {
|
||||
let r = this.rect;
|
||||
@@ -760,7 +760,7 @@ var DOM = Class("DOM", {
|
||||
dispatch: function dispatch(event, params, extraProps) {
|
||||
this.canceled = false;
|
||||
return this.each(function (elem) {
|
||||
let evt = DOM.Event(this.document, event, params);
|
||||
let evt = DOM.Event(this.document, event, params, elem);
|
||||
if (!DOM.Event.dispatch(elem, evt, extraProps))
|
||||
this.canceled = true;
|
||||
}, this);
|
||||
@@ -825,7 +825,7 @@ var DOM = Class("DOM", {
|
||||
* @param {Object} opts The pseudo-event. @optional
|
||||
*/
|
||||
Event: Class("Event", {
|
||||
init: function Event(doc, type, opts) {
|
||||
init: function Event(doc, type, opts, target) {
|
||||
const DEFAULTS = {
|
||||
HTML: {
|
||||
type: type, bubbles: true, cancelable: false
|
||||
@@ -842,8 +842,12 @@ var DOM = Class("DOM", {
|
||||
bubbles: true, cancelable: true,
|
||||
view: doc.defaultView,
|
||||
detail: 1,
|
||||
screenX: 0, screenY: 0,
|
||||
clientX: 0, clientY: 0,
|
||||
get screenX() this.view.mozInnerScreenX
|
||||
+ Math.max(0, this.clientX + (DOM(target || opts.target).rect.left || 0)),
|
||||
get screenY() this.view.mozInnerScreenY
|
||||
+ Math.max(0, this.clientY + (DOM(target || opts.target).rect.top || 0)),
|
||||
clientX: 0,
|
||||
clientY: 0,
|
||||
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
||||
button: 0,
|
||||
relatedTarget: null
|
||||
@@ -854,13 +858,12 @@ var DOM = Class("DOM", {
|
||||
var t = this.constructor.types[type] || "";
|
||||
var evt = doc.createEvent(t + "Events");
|
||||
|
||||
let defaults = DEFAULTS[t || "HTML"];
|
||||
update(defaults, this.constructor.defaults[type]);
|
||||
let params = DEFAULTS[t || "HTML"];
|
||||
let args = Object.keys(params);
|
||||
update(params, this.constructor.defaults[type],
|
||||
iter.toObject([k, opts[k]] for (k in opts) if (k in params)));
|
||||
|
||||
let args = Object.keys(defaults)
|
||||
.map(function (k) k in opts ? opts[k] : defaults[k])
|
||||
|
||||
evt["init" + t + "Event"].apply(evt, args);
|
||||
evt["init" + t + "Event"].apply(evt, args.map(function (k) params[k]));
|
||||
return evt;
|
||||
}
|
||||
}, {
|
||||
@@ -1203,7 +1206,8 @@ var DOM = Class("DOM", {
|
||||
types: Class.Memoize(function () iter(
|
||||
{
|
||||
Mouse: "click mousedown mouseout mouseover mouseup " +
|
||||
"popupshowing popupshown popuphiding popuphidden",
|
||||
"popupshowing popupshown popuphiding popuphidden " +
|
||||
"contextmenu",
|
||||
Key: "keydown keypress keyup",
|
||||
"": "change command dactyl-input input submit " +
|
||||
"load unload pageshow pagehide DOMContentLoaded"
|
||||
|
||||
@@ -741,8 +741,7 @@ var RangeFind = Class("RangeFind", {
|
||||
this.range = range;
|
||||
this.document = range.startContainer.ownerDocument;
|
||||
this.window = this.document.defaultView;
|
||||
this.docShell = this.window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell);
|
||||
this.docShell = util.docShell(this.window);
|
||||
|
||||
if (this.selection == null)
|
||||
return false;
|
||||
|
||||
@@ -215,7 +215,7 @@ var Help = Module("Help", {
|
||||
},
|
||||
|
||||
flush: function flush(entries, time) {
|
||||
cache.flushEntry("help", time);
|
||||
cache.flushEntry("help.json", time);
|
||||
|
||||
for (let entry in values(Array.concat(entries || [])))
|
||||
cache.flushEntry(entry, time);
|
||||
|
||||
@@ -36,6 +36,7 @@ var Services = Module("Services", {
|
||||
this.add("clipboardHelper", "@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper");
|
||||
this.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl");
|
||||
this.add("console", "@mozilla.org/consoleservice;1", "nsIConsoleService");
|
||||
this.add("contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService");
|
||||
this.add("dactyl", "@dactyl.googlecode.com/extra/utils", "dactylIUtils");
|
||||
this.add("dactyl:", this.PROTOCOL + "dactyl");
|
||||
this.add("debugger", "@mozilla.org/js/jsd/debugger-service;1", "jsdIDebuggerService");
|
||||
@@ -63,6 +64,7 @@ var Services = Module("Services", {
|
||||
this.add("resource:", this.PROTOCOL + "resource", ["nsIProtocolHandler", "nsIResProtocolHandler"]);
|
||||
this.add("runtime", "@mozilla.org/xre/runtime;1", ["nsIXULAppInfo", "nsIXULRuntime"]);
|
||||
this.add("rdf", "@mozilla.org/rdf/rdf-service;1", "nsIRDFService");
|
||||
this.add("security", "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager");
|
||||
this.add("sessionStore", "@mozilla.org/browser/sessionstore;1", "nsISessionStore");
|
||||
this.add("spell", "@mozilla.org/spellchecker/engine;1", "mozISpellCheckingEngine");
|
||||
this.add("stringBundle", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService");
|
||||
|
||||
@@ -505,6 +505,17 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
dequote: function dequote(pattern, chars)
|
||||
pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0),
|
||||
|
||||
/**
|
||||
* Returns the nsIDocShell for the given window.
|
||||
*
|
||||
* @param {Window} win The window for which to get the docShell.
|
||||
* @returns {nsIDocShell}
|
||||
*/
|
||||
|
||||
docShell: function docShell(win)
|
||||
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell),
|
||||
|
||||
/**
|
||||
* Prints a message to the console. If *msg* is an object it is pretty
|
||||
* printed.
|
||||
|
||||
Reference in New Issue
Block a user