Bug 639945 - tooltips are not displayed on inline svg elements. r=dao,bzbarsky

This commit is contained in:
Robert Longson 2011-06-30 21:58:21 +01:00
parent bf018509ad
commit 782a97703a
4 changed files with 20 additions and 12 deletions

View File

@ -2981,9 +2981,8 @@ function FillInHTMLTooltip(tipElement)
XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title"); XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
} }
if (lookingForSVGTitle && if (lookingForSVGTitle &&
!(tipElement instanceof SVGElement && (!(tipElement instanceof SVGElement) ||
tipElement.parentNode instanceof SVGElement && tipElement.parentNode.nodeType == Node.DOCUMENT_NODE)) {
!(tipElement.parentNode instanceof SVGForeignObjectElement))) {
lookingForSVGTitle = false; lookingForSVGTitle = false;
} }
if (lookingForSVGTitle) { if (lookingForSVGTitle) {

View File

@ -6,6 +6,10 @@ function test () {
let doc = gBrowser.contentDocument; let doc = gBrowser.contentDocument;
let tooltip = document.getElementById("aHTMLTooltip"); 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")); ok(FillInHTMLTooltip(doc.getElementById("text1"), "should get title"));
is(tooltip.getAttribute("label"), " This is a title "); is(tooltip.getAttribute("label"), " This is a title ");

View File

@ -1,5 +1,14 @@
<svg width="640px" height="480px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0"> <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> <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"> <text id="text1" x="10px" y="32px" font-size="24px">
This contains only &lt;title&gt; This contains only &lt;title&gt;
<title> <title>

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -70,7 +70,6 @@
#include "Link.h" #include "Link.h"
#include "nsIDOMSVGElement.h" #include "nsIDOMSVGElement.h"
#include "nsIDOMSVGTitleElement.h" #include "nsIDOMSVGTitleElement.h"
#include "nsIDOMSVGForeignObjectElem.h"
#include "nsIDOMEvent.h" #include "nsIDOMEvent.h"
#include "nsIDOMMouseEvent.h" #include "nsIDOMMouseEvent.h"
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
@ -1059,9 +1058,8 @@ DefaultTooltipTextProvider::DefaultTooltipTextProvider()
// UseSVGTitle // UseSVGTitle
// //
// A helper routine that determines whether we're still interested // A helper routine that determines whether we're still interested
// in SVG titles. We need to stop at the SVG root element; that // 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 // has a document node parent
// parent.
// //
static PRBool static PRBool
UseSVGTitle(nsIDOMElement *currElement) UseSVGTitle(nsIDOMElement *currElement)
@ -1075,12 +1073,10 @@ UseSVGTitle(nsIDOMElement *currElement)
if (!parent) if (!parent)
return PR_FALSE; return PR_FALSE;
nsCOMPtr<nsIDOMSVGForeignObjectElement> parentFOContent(do_QueryInterface(parent)); PRUint16 nodeType;
if (parentFOContent) nsresult rv = parent->GetNodeType(&nodeType);
return PR_FALSE;
nsCOMPtr<nsIDOMSVGElement> parentSVGContent(do_QueryInterface(parent)); return NS_SUCCEEDED(rv) && nodeType != nsIDOMNode::DOCUMENT_NODE;
return (parentSVGContent != nsnull);
} }
/* void getNodeText (in nsIDOMNode aNode, out wstring aText); */ /* void getNodeText (in nsIDOMNode aNode, out wstring aText); */