Bug 551838 - Adding empty href attribute doesn't add link styling

r=bz
This commit is contained in:
Shawn Wilsher 2010-06-16 09:59:26 -07:00
parent 4e43c7eae6
commit f1d155f2bc
6 changed files with 39 additions and 8 deletions

View File

@ -50,8 +50,8 @@ namespace mozilla {
namespace dom {
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
{ 0x2be8af0, 0x32a5, 0x41dd, \
{ 0xa7, 0x68, 0x12, 0x55, 0xc4, 0x9a, 0xd4, 0xc5 } }
{ 0xa687a99c, 0x3893, 0x45c0, \
{0x8e, 0xab, 0xb8, 0xf7, 0xd7, 0x9e, 0x9e, 0x7b } }
class Link : public nsISupports
{
@ -108,6 +108,8 @@ public:
protected:
virtual ~Link();
bool HasCachedURI() const { return !!mCachedURI; }
private:
/**
* Unregisters from History so this node no longer gets notifications about

View File

@ -12,6 +12,9 @@
#link4::before {
content:"Test link 2";
}
#link6::before {
content:"Test link 3";
}
</style>
</head>
<body>
@ -20,6 +23,8 @@
<link id="link2"/>
<a href="http://example.com/1">Test anchor 2</a>
<link id="link4" href="http://example.com/1"/>
<a href="">Test anchor 3</a>
<link id="link6" href=""/>
</p>
</body>
</html>

View File

@ -12,6 +12,9 @@
#link4::before {
content:"Test link 2";
}
#link6::before {
content:"Test link 3";
}
</style>
</head>
<body onload="run_test();">
@ -26,6 +29,8 @@ function run_test()
// Add the href attribute to the links so they should be restyled as links.
document.getElementById("link3").href = "http://example.com/1";
document.getElementById("link4").href = "http://example.com/1";
document.getElementById("link5").setAttribute("href", "");
document.getElementById("link6").setAttribute("href", "");
}
</script>
<p>
@ -33,6 +38,8 @@ function run_test()
<link id="link2" href="http://example.com/1"/>
<a id="link3">Test anchor 2</a>
<link id="link4"/>
<a id="link5">Test anchor 3</a>
<link id="link6"/>
</p>
</body>
</html>

View File

@ -439,11 +439,19 @@ nsHTMLAnchorElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
bool reset = false;
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
nsAutoString val;
GetHref(val);
if (!val.Equals(aValue)) {
// If we do not have a cached URI, we have some value here so we must reset
// our link state after calling the parent.
if (!Link::HasCachedURI()) {
reset = true;
}
// However, if we have a cached URI, we'll want to see if the value changed.
else {
nsAutoString val;
GetHref(val);
if (!val.Equals(aValue)) {
reset = true;
}
}
}
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,

View File

@ -19,7 +19,11 @@ a:link {
</a>
<a xlink:href="http://example.com/1">
<text x="10" y="100">Test anchor 2</text>
<text x="10" y="200">Test anchor 2</text>
</a>
<a xlink:href="">
<text x="10" y="300">Test anchor 3</text>
</a>
</svg>

Before

Width:  |  Height:  |  Size: 482 B

After

Width:  |  Height:  |  Size: 560 B

View File

@ -1,7 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
onload="document.getElementById('link1').removeAttribute('xlink:href');
document.getElementById('link2').setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'http://example.com/1');">
document.getElementById('link2').setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'http://example.com/1');
document.getElementById('link3').setAttributeNS('http://www.w3.org/1999/xlink', 'href', '');">
<title>Test for bug 549797 - Removing href attribute doesn't remove link styling</title>
@ -21,7 +22,11 @@ a:link {
</a>
<a id="link2">
<text x="10" y="100">Test anchor 2</text>
<text x="10" y="200">Test anchor 2</text>
</a>
<a id="link3">
<text x="10" y="300">Test anchor 3</text>
</a>
</svg>

Before

Width:  |  Height:  |  Size: 710 B

After

Width:  |  Height:  |  Size: 892 B