diff --git a/common/content/bindings.xml b/common/content/bindings.xml index eca6f65d..3f9d2c11 100644 --- a/common/content/bindings.xml +++ b/common/content/bindings.xml @@ -13,9 +13,14 @@ - + + + + document.getAnonymousElementByAttribute(this, "anonid", "hints"); + + - + diff --git a/common/content/hints.js b/common/content/hints.js index 069b7275..8d098728 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -287,49 +287,50 @@ const Hints = Module("hints", { return true; } - let baseNodeAbsolute = util.xmlToDom(, doc); - - let mode = this._hintMode; - let res = util.evaluateXPath(mode.xpath, doc, null, true); - if (mode.filter) - res = let (orig = res) (e for (e in orig) if (mode.filter(e))); - - let fragment = util.xmlToDom(
, doc); - let start = this._pageHints.length; - for (let elem in res) { - let hint = { elem: elem, showText: false }; - - if (!isVisible(elem)) - continue; - - if (elem.hasAttributeNS(NS, "hint")) - [hint.text, hint.showText] = [elem.getAttributeNS(NS, "hint"), true]; - else if (isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement])) - [hint.text, hint.showText] = this._getInputHint(elem, doc); - else if (elem.firstElementChild instanceof HTMLImageElement && /^\s*$/.test(elem.textContent)) - [hint.text, hint.showText] = [elem.firstElementChild.alt || elem.firstElementChild.title, true]; - else - hint.text = elem.textContent.toLowerCase(); - - hint.span = baseNodeAbsolute.cloneNode(true); - - let rect = elem.getClientRects()[0] || elem.getBoundingClientRect(); - let leftPos = Math.max((rect.left + offsetX), offsetX); - let topPos = Math.max((rect.top + offsetY), offsetY); - - if (elem instanceof HTMLAreaElement) - [leftPos, topPos] = this._getAreaOffset(elem, leftPos, topPos); - - hint.span.style.left = leftPos + "px"; - hint.span.style.top = topPos + "px"; - fragment.appendChild(hint.span); - - this._pageHints.push(hint); - } - let body = doc.body || util.evaluateXPath(["body"], doc).snapshotItem(0); if (body) { + let fragment = util.xmlToDom(
, doc); body.appendChild(fragment); + + let baseNodeAbsolute = util.xmlToDom(, doc); + + let mode = this._hintMode; + let res = util.evaluateXPath(mode.xpath, doc, null, true); + if (mode.filter) + res = let (orig = res) (e for (e in orig) if (mode.filter(e))); + + let start = this._pageHints.length; + for (let elem in res) { + let hint = { elem: elem, showText: false }; + + if (!isVisible(elem)) + continue; + + if (elem.hasAttributeNS(NS, "hint")) + [hint.text, hint.showText] = [elem.getAttributeNS(NS, "hint"), true]; + else if (isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement])) + [hint.text, hint.showText] = this._getInputHint(elem, doc); + else if (elem.firstElementChild instanceof HTMLImageElement && /^\s*$/.test(elem.textContent)) + [hint.text, hint.showText] = [elem.firstElementChild.alt || elem.firstElementChild.title, true]; + else + hint.text = elem.textContent.toLowerCase(); + + hint.span = baseNodeAbsolute.cloneNode(true); + + let rect = elem.getClientRects()[0] || elem.getBoundingClientRect(); + let leftPos = Math.max((rect.left + offsetX), offsetX); + let topPos = Math.max((rect.top + offsetY), offsetY); + + if (elem instanceof HTMLAreaElement) + [leftPos, topPos] = this._getAreaOffset(elem, leftPos, topPos); + + hint.span.style.left = leftPos + "px"; + hint.span.style.top = topPos + "px"; + fragment.wrappedJSObject.hints.appendChild(hint.span); + + this._pageHints.push(hint); + } + this._docs.push({ doc: doc, start: start, end: this._pageHints.length - 1 }); } @@ -420,7 +421,7 @@ const Hints = Module("hints", { if (!rect) continue; - hint.imgSpan = util.xmlToDom(, doc); + hint.imgSpan = util.xmlToDom(, doc); hint.imgSpan.style.left = (rect.left + offsetX) + "px"; hint.imgSpan.style.top = (rect.top + offsetY) + "px"; hint.imgSpan.style.width = (rect.right - rect.left) + "px"; @@ -453,12 +454,12 @@ const Hints = Module("hints", { if (options["usermode"]) { let css = []; - // FIXME: Broken for imgspans. - for (let { doc } in values(this._docs)) { - for (let elem in util.evaluateXPath("//*[@dactyl:highlight and @number]", doc)) { - let group = elem.getAttributeNS(NS, "highlight"); - css.push(highlight.selector(group) + "[number=" + elem.getAttribute("number").quote() + "] { " + elem.style.cssText + " }"); - } + for (let hint in values(this._pageHints)) { + let selector = highlight.selector("Hint") + "[number=" + hint.span.getAttribute("number").quote() + "]"; + let imgSpan = "[dactyl|hl=HintImage]"; + css.push(selector + ":not(" + imgSpan + ") { " + hint.span.style.cssText + " }"); + if (hint.imgSpan) + css.push(selector + imgSpan + " { " + hint.span.style.cssText + " }"); } styles.addSheet(true, "hint-positions", "*", css.join("\n")); } diff --git a/common/skin/dactyl.css b/common/skin/dactyl.css index 06451a82..e2dd4fb7 100644 --- a/common/skin/dactyl.css +++ b/common/skin/dactyl.css @@ -7,26 +7,15 @@ -moz-binding: url(chrome://dactyl/content/bindings.xml#frame) !important; } -[dactyl|class~=magic] > [dactyl|highlight=Hint] { - visibility: visible !important; -} -[dactyl|class~=magic] { - -moz-binding: url(chrome://dactyl/content/bindings.xml#magic) !important; - visibility: hidden !important; - position: absolute !important; - top: 0 !important; - left: 0 !important; - width: 4000px !important; +[dactyl|highlight~=hints] { + -moz-binding: url(chrome://dactyl/content/bindings.xml#hints) !important; } [dactyl|highlight~=HintImage], [dactyl|highlight~=Hint] { - z-index: 5000; + z-index: 50000; position: absolute !important; } -[dactyl|highlight~=Search] { - display: inline !important; -} /* Applied only to completion buffer and MOW */ @-moz-document