1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 09:27:58 +01:00

Document some more crap.

This commit is contained in:
Kris Maglione
2008-12-19 13:27:01 -05:00
parent 669043da71
commit 057d66ce65
17 changed files with 285 additions and 85 deletions

View File

@@ -26,8 +26,16 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
const Point = new Struct("x", "y");
/**
* A class to manage the primary web content buffer. The name comes
* from vim's term, 'buffer', which signifies instances of open
* files.
* @instance buffer
*/
function Buffer() //{{{
{
////////////////////////////////////////////////////////////////////////////////
@@ -809,6 +817,10 @@ function Buffer() //{{{
return {
/**
* The alternative stylesheets for the current buffer. Only
* returns stylesheets for the 'screen' media type.
*/
get alternateStyleSheets()
{
let stylesheets = window.getAllStyleSheets(window.content);
@@ -818,9 +830,18 @@ function Buffer() //{{{
);
},
/**
* @property {Object} A map of page info sections to their
* content generating functions.
*/
get pageInfo() pageInfo,
// 0 if loading, 1 if loaded or 2 if load failed
/**
* Returns whether the buffer is loaded. Values may be:
* 0 - Loading.
* 1 - Fully loaded.
* 2 - Load failed.
*/
get loaded()
{
if (window.content.document.pageIsFullyLoaded !== undefined)
@@ -833,7 +854,10 @@ function Buffer() //{{{
window.content.document.pageIsFullyLoaded = value;
},
// used to keep track of the right field for "gi"
/**
* The last focused input field in the buffer. Used by the
* "gi" key binding.
*/
get lastInputField()
{
if (window.content.document.lastInputField)
@@ -846,6 +870,9 @@ function Buffer() //{{{
window.content.document.lastInputField = value;
},
/**
* The current top-level document's URL.
*/
get URL()
{
return window.content.document.location.href;
@@ -856,6 +883,10 @@ function Buffer() //{{{
return window.content.innerHeight;
},
/**
* The current browser's text zoom level, as a percentage with
* 100 as 'normal'. Only affects text size.
*/
get textZoom()
{
return getBrowser().markupDocumentViewer.textZoom * 100;
@@ -865,6 +896,11 @@ function Buffer() //{{{
setZoom(value, false);
},
/**
* The current browser's text zoom level, as a percentage with
* 100 as 'normal'. Affects text size, as well as image size
* and block size.
*/
get fullZoom()
{
return getBrowser().markupDocumentViewer.fullZoom * 100;
@@ -874,14 +910,37 @@ function Buffer() //{{{
setZoom(value, true);
},
/**
* The current document's title.
*/
get title()
{
return window.content.document.title;
},
/**
*
* @param {string} option The section's value in 'pageinfo'.
* @param {string} title The heading for this section's
* output.
* @param {function} fn The function to generate this
* section's output.
*/
addPageInfoSection: addPageInfoSection,
// returns an XPathResult object
/**
* Evaluates an XPath expression in the current or provided
* document. It provides the xhtml and liberator XML
* namespaces. The result may be used as an iterator.
*
* @param {string} expression The XPath expression to evaluate.
* @param {Document} doc The document to evaluate the expression in.
* @default The current document.
* @param {Node} elem The context element.
* @default <b>doc</b>
* @param {boolean} asIterator Whether to return the results as an XPath
* iterator.
*/
evaluateXPath: function (expression, doc, elem, asIterator)
{
if (!doc)
@@ -892,15 +951,10 @@ function Buffer() //{{{
let result = doc.evaluate(expression, elem,
function lookupNamespaceURI(prefix)
{
switch (prefix)
{
case "xhtml":
return "http://www.w3.org/1999/xhtml";
case "liberator":
return NS.uri;
default:
return null;
}
return {
xhtml: "http://www.w3.org/1999/xhtml",
liberator: NS.uri
}[prefix] || null;
},
asIterator ? XPathResult.ORDERED_NODE_ITERATOR_TYPE : XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
@@ -913,9 +967,13 @@ function Buffer() //{{{
return result;
},
// in contrast to vim, returns the selection if one is made,
// otherwise tries to guess the current word under the text cursor
// NOTE: might change the selection
/**
* Returns the currently selected word. If the selection is
* null, it tries to guess the word that the caret is
* positioned in.
*
* NOTE: might change the selection
*/
// FIXME: getSelection() doesn't always preserve line endings, see:
// https://www.mozdev.org/bugs/show_bug.cgi?id=19303
getCurrentWord: function ()
@@ -937,8 +995,13 @@ function Buffer() //{{{
return String(selection);
},
// more advanced than a simple elem.focus() as it also works for iframes
// and image maps
/**
* Focuses the given element. In contrast to a simple
* elem.focus() call, this function works for iframes and
* image maps.
*
* @param {Node} elem The element to focus.
*/
// TODO: merge with followLink()?
focusElement: function (elem)
{
@@ -963,6 +1026,17 @@ function Buffer() //{{{
elem.dispatchEvent(evt);
},
/**
* Try to guess links the like of "next" and "prev". Though it
* has a singularly horrendous name, it turns out to be quite
* useful.
*
* @param {string} rel The relationship to look for. Looks for
* links with matching @rel or @rev attributes, and,
* failing that, looks for an option named rel +
* "pattern", and finds the last link matching that
* RegExp.
*/
followDocumentRelationship: function (rel)
{
let regexps = options.get(rel + "pattern").values
@@ -1019,7 +1093,13 @@ function Buffer() //{{{
liberator.beep();
},
// artificially "clicks" a link in order to open it
/**
* Fakes a click on a link.
*
* @param {Node} elem The element to click.
* @param {number} where Where to open the link. See
* {@link liberator.open}.
*/
followLink: function (elem, where)
{
let doc = elem.ownerDocument;
@@ -1067,6 +1147,9 @@ function Buffer() //{{{
});
},
/**
* The current document's selection controller.
*/
get selectionController() getBrowser().docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISelectionDisplay)
@@ -1091,11 +1174,19 @@ function Buffer() //{{{
}
},
/**
* Scrolls to the bottom of the current buffer.
*/
scrollBottom: function ()
{
scrollToPercentiles(-1, 100);
},
/**
* Scrolls the window laterally <b>cols</b> columns.
*
* @param {number} cols The number of columns to scroll.
*/
scrollColumns: function (cols)
{
let win = findScrollableWindow();
@@ -1107,11 +1198,19 @@ function Buffer() //{{{
win.scrollBy(COL_WIDTH * cols, 0);
},
/**
* Scrolls the buffer to its rightmost position.
*/
scrollEnd: function ()
{
scrollToPercentiles(100, -1);
},
/**
* Scrolls the buffer vertically <b>lines</b> rows.
*
* @param {number} lines The number of lines to scroll.
*/
scrollLines: function (lines)
{
let win = findScrollableWindow();
@@ -1119,6 +1218,11 @@ function Buffer() //{{{
win.scrollByLines(lines);
},
/**
* Scrolls the buffer vertically <b>pages</b> pages.
*
* @param {number} pages The number of pages to scroll.
*/
scrollPages: function (pages)
{
let win = findScrollableWindow();
@@ -1140,6 +1244,9 @@ function Buffer() //{{{
win.scrollBy(0, win.innerHeight / 2 * direction);
},
/**
* Scrolls the current buffer vertically to <b>percentage</b>
*/
scrollToPercentile: function (percentage)
{
scrollToPercentiles(-1, percentage);
@@ -1156,11 +1263,17 @@ function Buffer() //{{{
content.scrollTo(x, y);
},
/**
* Scrolls the current buffer laterally to its leftmost.
*/
scrollStart: function ()
{
scrollToPercentiles(0, -1);
},
/**
* Scrolls the current buffer vertically to its top.
*/
scrollTop: function ()
{
scrollToPercentiles(-1, 0);
@@ -1322,6 +1435,9 @@ function Buffer() //{{{
//}}}
}; //}}}
/**
* @instance marks
*/
function Marks() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// Do NOT create instances of this class yourself, use the helper method
// commands.add() instead
function Command(specs, description, action, extraInfo) //{{{
@@ -147,6 +149,9 @@ Command.prototype = {
}; //}}}
/**
* @instance commands
*/
function Commands() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
/**
* Creates a new completion context.
*
@@ -647,6 +649,9 @@ CompletionContext.prototype = {
}
}; //}}}
/**
* @instance completion
*/
function Completion() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,9 +26,14 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// command names taken from:
// http://developer.mozilla.org/en/docs/Editor_Embedding_Guide
/**
* @instance editor
*/
function Editor() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,11 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
/**
* @instance autocommands
*/
function AutoCommands() //{{{
{
////////////////////////////////////////////////////////////////////////////////
@@ -277,6 +282,9 @@ function AutoCommands() //{{{
//}}}
}; //}}}
/**
* @instance events
*/
function Events() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// TODO: proper backwards search - implement our own component?
// : implement our own highlighter?
// : frameset pages
@@ -37,6 +39,9 @@ the terms of any one of the MPL, the GPL or the LGPL.
// : incremental searches shouldn't permanently update search modifiers
// make sure you only create this object when the "liberator" object is ready
/**
* @instance search
*/
function Search() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,11 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
/**
* @instance hints
*/
function Hints() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -27,6 +27,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
plugins.contexts = {};
function Script(file)
{
@@ -52,6 +54,9 @@ function Script(file)
Script.prototype = plugins;
// TODO: why are we passing around strings rather than file objects?
/**
* @instance io
*/
function IO() //{{{
{
////////////////////////////////////////////////////////////////////////////////
@@ -838,7 +843,7 @@ lookup:
}
else if (/\.css$/.test(filename))
{
storage.styles.registerSheet(uri.spec, !silent, true);
storage.styles.registerSheet(uri.spec, true);
}
else
{

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// Do NOT create instances of this class yourself, use the helper method
// mappings.add() instead
function Map(modes, cmds, description, action, extraInfo) //{{{
@@ -76,6 +78,9 @@ Map.prototype = {
}; //}}}
/**
* @instance mappings
*/
function Mappings() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
const modes = (function () //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// do NOT create instances of this class yourself, use the helper method
// options.add() instead
function Option(names, description, type, defaultValue, extraInfo) //{{{
@@ -293,6 +295,9 @@ Option.validateCompleter = function (values)
function (value) res.some(function (item) item[0] == value));
}; //}}}
/**
* @instance options
*/
function Options() //{{{
{
////////////////////////////////////////////////////////////////////////////////

View File

@@ -6,6 +6,19 @@
it under any or all of those licenseses.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
/**
* @constant
* @property {string} The default highlighting rules. They have the
* form:
* rule ::= selector space css
* selector ::= group
* | group "," css-selector
* | group "," css-selector "," scope
* group ::= groupname
* | groupname css-selector
*/
// <css>
Highlights.prototype.CSS = <![CDATA[
Boolean color: red;
@@ -114,6 +127,12 @@ Highlights.prototype.CSS = <![CDATA[
}
]]>.toString();
/**
* A class to manage highlighting rules. The parameters are the
* standard paramaters for any {@link Storage} object.
*
* @author Kris Maglione <maglione.k@gmail.com>
*/
function Highlights(name, store, serial)
{
var self = this;
@@ -161,25 +180,35 @@ function Highlights(name, store, serial)
.replace(";!important;", ";", "g"); // Seeming Spidermonkey bug
css = style.selector + " { " + css + " }";
let error = styles.addSheet(style.selector, style.filter, css, true, force);
let error = styles.addSheet(style.selector, style.filter, css, true);
if (error)
return error;
style.value = newStyle;
highlight[style.class] = style;
};
/**
* Gets a CSS selector given a highlight group.
*/
this.selector = function (class)
{
let [, hl, rest] = class.match(/^(\w*)(.*)/);
return "[liberator|highlight~=" + hl + "]" + rest
};
/**
* Clears all highlighting rules. Rules with default values are
* reset.
*/
this.clear = function ()
{
for (let [k, v] in Iterator(highlight))
this.set(k, null, true);
};
/**
* Reloads the values in {@link #CSS}.
*/
this.reload = function ()
{
this.CSS.replace(/\{((?:.|\n)*?)\}/g, function (_, _1) _1.replace(/\n\s*/g, " "))
@@ -203,6 +232,13 @@ function Highlights(name, store, serial)
};
}
/**
* Manages named and unnamed user stylesheets, which apply to both
* chrome and content pages. The parameters are the standard
* paramaters for any {@link Storage} object.
*
* @author Kris Maglione <maglione.k@gmail.com>
*/
function Styles(name, store, serial)
{
/* Can't reference liberator or Components inside Styles --
@@ -233,7 +269,20 @@ function Styles(name, store, serial)
this.__defineGetter__("systemNames", function () Iterator(systemNames));
this.__defineGetter__("userNames", function () Iterator(userNames));
this.addSheet = function (name, filter, css, system, force)
/**
* Add a new stylesheet.
*
* @param {string} name The name given to the stylesheet by
* which it may be later referenced.
* @param {string} filter The sites to which this sheet will
* apply. Can be a domain name or a URL. Any URL ending in
* "*" is matched as a prefix.
* @param {string} css The CSS to be applied.
* @param {boolean} system Declares whether this is a system or
* user sheet. System sheets are used internally by
* @liberator.
*/
this.addSheet = function (name, filter, css, system)
{
let sheets = system ? systemSheets : userSheets;
let names = system ? systemNames : userNames;
@@ -249,7 +298,7 @@ function Styles(name, store, serial)
sheet.ref = [];
try
{
this.registerSheet(cssUri(wrapCSS(sheet)), !force);
this.registerSheet(cssUri(wrapCSS(sheet)));
this.registerAgentSheet(cssUri(wrapCSS(sheet)))
}
catch (e)
@@ -266,6 +315,10 @@ function Styles(name, store, serial)
return null;
};
/**
* Find sheets matching the parameters. See {@link #addSheet}
* for parameters.
*/
this.findSheets = function (name, filter, css, index, system)
{
let sheets = system ? systemSheets : userSheets;
@@ -284,6 +337,12 @@ function Styles(name, store, serial)
return matches.map(function (i) sheets[i]);
};
/**
* Remove a stylesheet. See {@link #addSheet} for parameters.
* In cases where <b>filter</b> is supplied, the given filters
* are removed from matching sheets. If any remain, the sheet is
* left in place.
*/
this.removeSheet = function (name, filter, css, index, system)
{
let self = this;
@@ -326,11 +385,15 @@ function Styles(name, store, serial)
return matches.length;
};
this.registerSheet = function (uri, doCheckSyntax, reload)
/**
* Register a user stylesheet at the given URI.
*
* @param {string} uri The UrI of the sheet to register.
* @param {boolean} reload Whether to reload any sheets that are
* already registered.
*/
this.registerSheet = function (uri, reload)
{
//dump (uri + "\n\n");
if (doCheckSyntax)
checkSyntax(uri);
if (reload)
this.unregisterSheet(uri);
uri = ios.newURI(uri, null, null);
@@ -338,6 +401,9 @@ function Styles(name, store, serial)
sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
};
/**
* Unregister a sheet at the given URI.
*/
this.unregisterSheet = function (uri)
{
uri = ios.newURI(uri, null, null);
@@ -346,6 +412,10 @@ function Styles(name, store, serial)
};
// FIXME
/**
* Register an agent stylesheet.
* @deprecated
*/
this.registerAgentSheet = function (uri)
{
this.unregisterAgentSheet(uri);
@@ -353,6 +423,10 @@ function Styles(name, store, serial)
sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
};
/**
* Unregister an agent stylesheet.
* @deprecated
*/
this.unregisterAgentSheet = function (uri)
{
uri = ios.newURI(uri, null, null);
@@ -373,65 +447,6 @@ function Styles(name, store, serial)
.join(", ");
return namespace + "@-moz-document " + selectors + "{\n" + css + "\n}\n";
}
let queryinterface = XPCOMUtils.generateQI([Ci.nsIConsoleListener]);
/* What happens if more than one thread tries to use this? */
let testDoc = document.implementation.createDocument(XHTML, "doc", null);
function checkSyntax(uri)
{
let errors = [];
let listener = {
QueryInterface: queryinterface,
observe: function (message)
{
try
{
message = message.QueryInterface(Ci.nsIScriptError);
if (message.sourceName == uri)
errors.push(message);
}
catch (e) {}
}
};
try
{
consoleService.registerListener(listener);
if (testDoc.documentElement.firstChild)
testDoc.documentElement.removeChild(testDoc.documentElement.firstChild);
testDoc.documentElement.appendChild(util.xmlToDom(
<html><head><link type="text/css" rel="stylesheet" href={uri}/></head></html>, testDoc));
while (true)
{
try
{
// Throws NS_ERROR_DOM_INVALID_ACCESS_ERR if not finished loading
testDoc.styleSheets[0].cssRules.length;
break;
}
catch (e)
{
if (e.name != "NS_ERROR_DOM_INVALID_ACCESS_ERR")
return [e.toString()];
sleep(10);
}
}
}
finally
{
consoleService.unregisterListener(listener);
}
if (errors.length)
{
let err = new Error("", errors[0].sourceName.replace(/^(chrome-data:text\/css,).*/, "$1..."), errors[0].lineNumber);
err.name = "CSSError";
err.message = errors.reduce(function (msg, e) msg + "; " + e.lineNumber + ": " + e.errorMessage,
errors.shift().errorMessage);
err.echoerr = err.fileName + ":" + err.lineNumber + ": " + err.message;
throw err;
}
}
}
let (array = util.Array)
{
@@ -440,8 +455,16 @@ let (array = util.Array)
};
}
/**
* @property {Styles}
*/
const styles = storage.newObject("styles", Styles, false);
/**
* @property {Highlights}
*/
const highlight = storage.newObject("highlight", Highlights, false);
highlight.CSS = Highlights.prototype.CSS;
highlight.reload();

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
// TODO: many methods do not work with Thunderbird correctly yet
function Tabs() //{{{

View File

@@ -1,3 +1,6 @@
/** @scope modules */
const template = {
add: function add(a, b) a + b,
join: function join(c) function (a, b) a + c + b,

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
/*
* This class is used for prompting of user input and echoing of messages
*

View File

@@ -26,6 +26,8 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
/** @scope modules */
const XHTML = "http://www.w3.org/1999/xhtml";
const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;