Bug 329212 - display the title element contents as a tooltip in SVG. r=dao,sr=bzbarsky

This commit is contained in:
Robert Longson 2010-02-06 11:03:10 +00:00
Родитель acdcd42b19
Коммит a5d2ab7340
5 изменённых файлов: 123 добавлений и 2 удалений

Просмотреть файл

@ -2636,12 +2636,23 @@ function FillInHTMLTooltip(tipElement)
var titleText = null;
var XLinkTitleText = null;
var SVGTitleText = null;
var direction = tipElement.ownerDocument.dir;
while (!titleText && !XLinkTitleText && tipElement) {
while (!titleText && !XLinkTitleText && !SVGTitleText && tipElement) {
if (tipElement.nodeType == Node.ELEMENT_NODE) {
titleText = tipElement.getAttribute("title");
XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
if (tipElement instanceof SVGElement) {
let length = tipElement.childNodes.length;
for (let i = 0; i < length; i++) {
let childNode = tipElement.childNodes[i];
if (childNode instanceof SVGTitleElement) {
SVGTitleText = childNode.textContent;
break;
}
}
}
var defView = tipElement.ownerDocument.defaultView;
// XXX Work around bug 350679:
// "Tooltips can be fired in documents with no view".
@ -2656,7 +2667,7 @@ function FillInHTMLTooltip(tipElement)
var tipNode = document.getElementById("aHTMLTooltip");
tipNode.style.direction = direction;
[titleText, XLinkTitleText].forEach(function (t) {
[titleText, XLinkTitleText, SVGTitleText].forEach(function (t) {
if (t && /\S/.test(t)) {
// Per HTML 4.01 6.2 (CDATA section), literal CRs and tabs should be

Просмотреть файл

@ -85,6 +85,8 @@ _BROWSER_FILES = \
browser_alltabslistener.js \
browser_bug304198.js \
browser_bug321000.js \
title_test.svg \
browser_bug329212.js \
browser_bug356571.js \
browser_bug386835.js \
browser_bug405137.js \

Просмотреть файл

@ -0,0 +1,36 @@
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("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"));
is(tooltip.getAttribute("label"), " This is a title ");
ok(FillInHTMLTooltip(doc.getElementById("text4"), "should get title"));
is(tooltip.getAttribute("label"), " This is a title ");
ok(!FillInHTMLTooltip(doc.getElementById("link2"), "should not get title"));
ok(FillInHTMLTooltip(doc.getElementById("link3"), "should get title"));
ok(tooltip.getAttribute("label") != "");
ok(FillInHTMLTooltip(doc.getElementById("link4"), "should get title"));
is(tooltip.getAttribute("label"), "This is an xlink:title attribute");
gBrowser.removeCurrentTab();
finish();
}, true);
content.location =
"http://localhost:8888/browser/browser/base/content/test/title_test.svg";
}

Просмотреть файл

@ -0,0 +1,45 @@
<svg width="640px" height="480px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0">
<text id="text1" x="10px" y="32px" font-size="24px">
This contains only &lt;title&gt;
<title>
This is a title
</title>
</text>
<text id="text2" x="10px" y="96px" font-size="24px">
This contains only &lt;desc&gt;
<desc>This is a desc</desc>
</text>
<text id="text3" x="10px" y="128px" font-size="24px">
This contains nothing.
</text>
<a id="link1" xlink:href="#">
This link contains &lt;title&gt;
<title>
This is a title
</title>
<text id="text4" x="10px" y="192px" font-size="24px">
</text>
</a>
<a id="link2" xlink:href="#">
<text x="10px" y="192px" font-size="24px">
This text contains &lt;title&gt;
<title>
This is a title
</title>
</text>
</a>
<a id="link3" xlink:href="#" xlink:title="This is an xlink:title attribute">
<text x="10px" y="224px" font-size="24px">
This link contains &lt;title&gt; &amp; xlink:title attr.
<title>This is a title</title>
</text>
</a>
<a id="link4" xlink:href="#" xlink:title="This is an xlink:title attribute">
<text x="10px" y="256px" font-size="24px">
This link contains xlink:title attr.
</text>
</a>
</svg>

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Просмотреть файл

@ -68,6 +68,10 @@
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMElement.h"
#ifdef MOZ_SVG
#include "nsIDOMSVGElement.h"
#include "nsIDOMSVGTitleElement.h"
#endif
#include "nsIDOMEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSUIEvent.h"
@ -1010,6 +1014,29 @@ DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, PRUnichar **aText,
currElement->GetAttributeNS(NS_LITERAL_STRING("http://www.w3.org/1999/xlink"), NS_LITERAL_STRING("title"), outText);
if ( outText.Length() )
found = PR_TRUE;
#ifdef MOZ_SVG
else {
nsCOMPtr<nsIDOMSVGElement> svgContent(do_QueryInterface(currElement));
if (svgContent) {
nsCOMPtr<nsIDOMNodeList>childNodes;
aNode->GetChildNodes(getter_AddRefs(childNodes));
PRUint32 childNodeCount;
childNodes->GetLength(&childNodeCount);
for (PRUint32 i = 0; i < childNodeCount; i++) {
nsCOMPtr<nsIDOMNode>childNode;
childNodes->Item(i, getter_AddRefs(childNode));
nsCOMPtr<nsIDOMSVGTitleElement> titleElement(do_QueryInterface(childNode));
if (titleElement) {
nsCOMPtr<nsIDOM3Node> titleContent(do_QueryInterface(titleElement));
titleContent->GetTextContent(outText);
if ( outText.Length() )
found = PR_TRUE;
break;
}
}
}
}
#endif
}
}
}