2 * (C) Copyright 2009 Shawn Betts
3 * (C) Copyright 2009 John J. Foerch <jjfoerch@earthlink.net>
5 * Use, modification, and distribution are subject to the terms specified in the
10 define_variable("headings_xpath", "//h1 | //h2 | //h3 | //h4 | //h5 | //h6",
11 "The xpath expression used by next-heading and previous-heading to find "+
12 "headings. Users will rarely need to change the value of this, but it "+
13 "exists especially for page-modes to override with a site-specific "+
17 define_variable("scroll_to_heading_wrap", true,
18 "If true, will wrap to the topmost heading when the viewport is at the"+
19 "bottom of the document and the user tries to access the next heading."+
20 " Does the equivalent thing for \"previous heading\" as well.");
23 define_browser_object_class(
24 "next-heading", null, null,
26 let xpr = I.buffer.document.evaluate(
27 I.buffer.get('headings_xpath'), I.buffer.document, null,
28 Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null),
29 heading, found = null, foundtop = null,
30 first = null, firsttop = null;
31 while ((heading = xpr.iterateNext())) {
32 let rect = heading.getBoundingClientRect();
33 if (rect.bottom - rect.top < 2)
35 if (! first || rect.top < firsttop) {
39 if (rect.top > 2 && (! found || rect.top < foundtop)) {
44 // scrollY can exceed scrollMaxY
45 let eod = I.buffer.scrollY - I.buffer.scrollMaxY >= 0;
46 if ((!found || eod) && scroll_to_heading_wrap)
48 yield co_return(found);
52 define_browser_object_class(
53 "previous-heading", null, null,
55 let xpr = I.buffer.document.evaluate(
56 I.buffer.get('headings_xpath'), I.buffer.document, null,
57 Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null),
58 heading, found = null, foundtop = null,
59 last = null, lasttop = null;
60 while ((heading = xpr.iterateNext())) {
61 let rect = heading.getBoundingClientRect();
62 if (rect.bottom - rect.top < 2)
64 if (rect.top < -1 && (! found || rect.top > foundtop)) {
68 if (! last || rect.top > lasttop) {
73 if (! found && scroll_to_heading_wrap)
75 yield co_return(found);
80 var element = yield read_browser_object(I);
81 // no scrolling and no error if we failed to get an object.
84 element.scrollIntoView();
85 I.window.minibuffer.message(element.textContent);
90 "Generalized scroll command. The amount of scrolling is determined by "+
91 "the object passed to the command as a browser-object. If the object "+
92 "is a DOM node, that node will be scrolled to the top of the viewport "+