From 9d9fa3edc81bddfb62564d0345db10779caa613d Mon Sep 17 00:00:00 2001 From: Magnus Melin Date: Wed, 18 Dec 2013 22:44:34 +0200 Subject: [PATCH] Bug 331772 - tooltiptext fails on XUL button in HTML page. r=enndeakin --- browser/base/content/test/general/browser.ini | 2 ++ ...owser_bug331772_xul_tooltiptext_in_html.js | 23 +++++++++++++++++++ .../test/general/xul_tooltiptext.xhtml | 14 +++++++++++ toolkit/content/widgets/popup.xml | 19 ++++++++++----- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 browser/base/content/test/general/browser_bug331772_xul_tooltiptext_in_html.js create mode 100644 browser/base/content/test/general/xul_tooltiptext.xhtml diff --git a/browser/base/content/test/general/browser.ini b/browser/base/content/test/general/browser.ini index 27bee0949ff7..34a8fa84ca4b 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -100,6 +100,7 @@ support-files = test_no_mcb_on_http_site_font.css test_no_mcb_on_http_site_font2.html test_no_mcb_on_http_site_font2.css + xul_tooltiptext.xhtml [browser_CTP_context_menu.js] skip-if = toolkit == "gtk2" || toolkit == "gtk3" # browser_CTP_context_menu.js fails intermittently on Linux (bug 909342) @@ -129,6 +130,7 @@ skip-if = toolkit == "windows" # Disabled on Windows due to frequent failures (b [browser_bug321000.js] skip-if = true # browser_bug321000.js is disabled because newline handling is shaky (bug 592528) [browser_bug329212.js] +[browser_bug331772_xul_tooltiptext_in_html.js] [browser_bug356571.js] [browser_bug380960.js] [browser_bug386835.js] diff --git a/browser/base/content/test/general/browser_bug331772_xul_tooltiptext_in_html.js b/browser/base/content/test/general/browser_bug331772_xul_tooltiptext_in_html.js new file mode 100644 index 000000000000..c88f049af3c3 --- /dev/null +++ b/browser/base/content/test/general/browser_bug331772_xul_tooltiptext_in_html.js @@ -0,0 +1,23 @@ +/** + * Tests that the tooltiptext attribute is used for XUL elements in an HTML doc. + */ +function test () { + waitForExplicitFinish(); + gBrowser.selectedTab = gBrowser.addTab(); + gBrowser.selectedBrowser.addEventListener("load", function () { + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); + + let doc = gBrowser.contentDocument; + let tooltip = document.getElementById("aHTMLTooltip"); + + ok(tooltip.fillInPageTooltip(doc.getElementById("xulToolbarButton")), "should get tooltiptext"); + is(tooltip.getAttribute("label"), "XUL tooltiptext"); + + gBrowser.removeCurrentTab(); + finish(); + }, true); + + content.location = + "http://mochi.test:8888/browser/browser/base/content/test/general/xul_tooltiptext.xhtml"; +} + diff --git a/browser/base/content/test/general/xul_tooltiptext.xhtml b/browser/base/content/test/general/xul_tooltiptext.xhtml new file mode 100644 index 000000000000..4a80864ddc24 --- /dev/null +++ b/browser/base/content/test/general/xul_tooltiptext.xhtml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/toolkit/content/widgets/popup.xml b/toolkit/content/widgets/popup.xml index 7671ef2cfbd4..da106803027a 100644 --- a/toolkit/content/widgets/popup.xml +++ b/toolkit/content/widgets/popup.xml @@ -517,6 +517,7 @@ var titleText = null; var XLinkTitleText = null; var SVGTitleText = null; + var XULtooltiptextText = null; var lookingForSVGTitle = true; var direction = tipElement.ownerDocument.dir; @@ -575,11 +576,17 @@ } catch(e) {} } - while ((titleText == null) && (XLinkTitleText == null) && - (SVGTitleText == null) && tipElement) { - if (tipElement.nodeType == Node.ELEMENT_NODE && - tipElement.namespaceURI != XULNS) { - titleText = tipElement.getAttribute("title"); + // Check texts against null so that title="" can be used to undefine a + // title on a child element. + while (tipElement && + (titleText == null) && (XLinkTitleText == null) && + (SVGTitleText == null) && (XULtooltiptextText == null)) { + + if (tipElement.nodeType == Node.ELEMENT_NODE) { + if (tipElement.namespaceURI == XULNS) + XULtooltiptextText = tipElement.getAttribute("tooltiptext"); + else + titleText = tipElement.getAttribute("title"); if ((tipElement instanceof HTMLAnchorElement || tipElement instanceof HTMLAreaElement || @@ -610,7 +617,7 @@ this.style.direction = direction; - return [titleText, XLinkTitleText, SVGTitleText].some(function (t) { + return [titleText, XLinkTitleText, SVGTitleText, XULtooltiptextText].some(function (t) { if (t && /\S/.test(t)) { // Make CRLF and CR render one line break each. this.label = t.replace(/\r\n?/g, '\n');