Bug 639945 - tooltips are not displayed on inline svg elements. r=dao,bzbarsky
authorRobert Longson <longsonr@gmail.com>
Thu, 30 Jun 2011 21:58:21 +0100
changeset 72723 74635b831e9e3fb2e3f5c15cb52e47625f2adfb4
parent 72722 4a7f8e181dd0d150a12b35b5fc7c0f760b1ec357
child 72724 6ef387126d0f1e1dfcaa041729734ded1f47005e
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, bzbarsky
bugs639945
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 639945 - tooltips are not displayed on inline svg elements. r=dao,bzbarsky
browser/base/content/browser.js
browser/base/content/test/browser_bug329212.js
browser/base/content/test/title_test.svg
embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2976,19 +2976,18 @@ function FillInHTMLTooltip(tipElement)
       titleText = tipElement.getAttribute("title");
       if ((tipElement instanceof HTMLAnchorElement && tipElement.href) ||
           (tipElement instanceof HTMLAreaElement && tipElement.href) ||
           (tipElement instanceof HTMLLinkElement && tipElement.href) ||
           (tipElement instanceof SVGAElement && tipElement.hasAttributeNS(XLinkNS, "href"))) {
         XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
       }
       if (lookingForSVGTitle &&
-          !(tipElement instanceof SVGElement &&
-            tipElement.parentNode instanceof SVGElement &&
-            !(tipElement.parentNode instanceof SVGForeignObjectElement))) {
+          (!(tipElement instanceof SVGElement) ||
+           tipElement.parentNode.nodeType == Node.DOCUMENT_NODE)) {
         lookingForSVGTitle = false;
       }
       if (lookingForSVGTitle) {
         let length = tipElement.childNodes.length;
         for (let i = 0; i < length; i++) {
           let childNode = tipElement.childNodes[i];
           if (childNode instanceof SVGTitleElement) {
             SVGTitleText = childNode.textContent;
--- a/browser/base/content/test/browser_bug329212.js
+++ b/browser/base/content/test/browser_bug329212.js
@@ -1,16 +1,20 @@
 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(FillInHTMLTooltip(doc.getElementById("svg1"), "should get title"));
+    is(tooltip.getAttribute("label"), "This is a non-root SVG element title");
+
     ok(FillInHTMLTooltip(doc.getElementById("text1"), "should get title"));
     is(tooltip.getAttribute("label"), "    This            is a title    ");
 
     ok(!FillInHTMLTooltip(doc.getElementById("text2"), "should not get title"));
 
     ok(!FillInHTMLTooltip(doc.getElementById("text3"), "should not get title"));
 
     ok(FillInHTMLTooltip(doc.getElementById("link1"), "should get title"));
--- a/browser/base/content/test/title_test.svg
+++ b/browser/base/content/test/title_test.svg
@@ -1,10 +1,19 @@
 <svg width="640px" height="480px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0">
   <title>This is a root SVG element's title</title>
+  <foreignObject>
+    <html xmlns="http://www.w3.org/1999/xhtml">
+      <body>
+        <svg xmlns="http://www.w3.org/2000/svg" id="svg1">
+          <title>This is a non-root SVG element title</title>
+        </svg>
+      </body>
+    </html>
+  </foreignObject>
   <text id="text1" x="10px" y="32px" font-size="24px">
     This contains only &lt;title&gt;
     <title>
 
 
     This            is a title
 
     </title>
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -65,17 +65,16 @@
 #include "nsIDOMNode.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentType.h"
 #include "nsIDOMElement.h"
 #include "Link.h"
 #include "nsIDOMSVGElement.h"
 #include "nsIDOMSVGTitleElement.h"
-#include "nsIDOMSVGForeignObjectElem.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsIDOMNSUIEvent.h"
 #include "nsIDOMNamedNodeMap.h"
 #include "nsIFormControl.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsIDOMHTMLHtmlElement.h"
@@ -1054,38 +1053,35 @@ DefaultTooltipTextProvider::DefaultToolt
     mTag_dialogheader = do_GetAtom("dialogheader");
     mTag_window       = do_GetAtom("window");   
 }
 
 //
 // UseSVGTitle
 //
 // A helper routine that determines whether we're still interested
-// in SVG titles. We need to stop at the SVG root element; that
-// either has no parent, has a non-SVG parent or has an SVG ForeignObject 
-// parent.
+// in SVG titles. We need to stop at the SVG root element that
+// has a document node parent
 //
 static PRBool
 UseSVGTitle(nsIDOMElement *currElement)
 {
   nsCOMPtr<nsIDOMSVGElement> svgContent(do_QueryInterface(currElement));
   if (!svgContent)
     return PR_FALSE;
 
   nsCOMPtr<nsIDOMNode> parent;
   currElement->GetParentNode(getter_AddRefs(parent));
   if (!parent)
     return PR_FALSE;
 
-  nsCOMPtr<nsIDOMSVGForeignObjectElement> parentFOContent(do_QueryInterface(parent));
-  if (parentFOContent)
-    return PR_FALSE;
+  PRUint16 nodeType;
+  nsresult rv = parent->GetNodeType(&nodeType);
 
-  nsCOMPtr<nsIDOMSVGElement> parentSVGContent(do_QueryInterface(parent));
-  return (parentSVGContent != nsnull);
+  return NS_SUCCEEDED(rv) && nodeType != nsIDOMNode::DOCUMENT_NODE;
 }
 
 /* void getNodeText (in nsIDOMNode aNode, out wstring aText); */
 NS_IMETHODIMP
 DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, PRUnichar **aText,
                                         PRBool *_retval)
 {
   NS_ENSURE_ARG_POINTER(aNode);