summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-10-13 21:26:13 +0200
committerPale Moon <git-repo@palemoon.org>2016-10-13 21:26:13 +0200
commite0c45ce5af7371ba77490039b298870be55c9f99 (patch)
tree7eba915c32fb6e21fd2b197b760b73b1b922f59a
parent252ed1b4b7c2164cd2bcfd001baa624f7fb54c9b (diff)
downloadpalemoon-gre-e0c45ce5af7371ba77490039b298870be55c9f99.tar.gz
Fix link and style elements to handle onload events.
Move LinkElement/StyleElement::SetAttr to AfterSetAttr. This resolves #595.
-rw-r--r--dom/html/HTMLLinkElement.cpp90
-rw-r--r--dom/html/HTMLLinkElement.h11
-rw-r--r--dom/html/HTMLStyleElement.cpp15
-rw-r--r--dom/html/HTMLStyleElement.h11
4 files changed, 67 insertions, 60 deletions
diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp
index 95442e803..b26fd5231 100644
--- a/dom/html/HTMLLinkElement.cpp
+++ b/dom/html/HTMLLinkElement.cpp
@@ -293,54 +293,72 @@ HTMLLinkElement::UpdateImport()
}
nsresult
-HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- nsIAtom* aPrefix, const nsAString& aValue,
- bool aNotify)
+HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
+ const nsAttrValue* aValue, bool aNotify)
{
- nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
- aValue, aNotify);
-
- // The ordering of the parent class's SetAttr call and Link::ResetLinkState
- // is important here! The attribute is not set until SetAttr returns, and
- // we will need the updated attribute value because notifying the document
- // that content states have changed will call IntrinsicState, which will try
- // to get updated information about the visitedness from Link.
+ // It's safe to call ResetLinkState here because our new attr value has
+ // already been set or unset. ResetLinkState needs the updated attribute
+ // value because notifying the document that content states have changed will
+ // call IntrinsicState, which will try to get updated information about the
+ // visited state from Link.
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
- Link::ResetLinkState(!!aNotify, true);
+ bool hasHref = aValue;
+ Link::ResetLinkState(!!aNotify, hasHref);
if (IsInUncomposedDoc()) {
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
}
}
- if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None &&
- (aName == nsGkAtoms::href ||
- aName == nsGkAtoms::rel ||
- aName == nsGkAtoms::title ||
- aName == nsGkAtoms::media ||
- aName == nsGkAtoms::type)) {
- bool dropSheet = false;
- if (aName == nsGkAtoms::rel) {
- uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue,
- NodePrincipal());
- if (GetSheet()) {
- dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
- } else if (linkTypes & eHTMLIMPORT) {
+ if (aValue) {
+ if (aNameSpaceID == kNameSpaceID_None &&
+ (aName == nsGkAtoms::href ||
+ aName == nsGkAtoms::rel ||
+ aName == nsGkAtoms::title ||
+ aName == nsGkAtoms::media ||
+ aName == nsGkAtoms::type)) {
+ bool dropSheet = false;
+ if (aName == nsGkAtoms::rel) {
+ nsAutoString value;
+ aValue->ToString(value);
+ uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(value,
+ NodePrincipal());
+ if (GetSheet()) {
+ dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
+ } else if (linkTypes & eHTMLIMPORT) {
+ UpdateImport();
+ }
+ }
+
+ if (aName == nsGkAtoms::href) {
UpdateImport();
}
+
+ UpdateStyleSheetInternal(nullptr, nullptr,
+ dropSheet ||
+ (aName == nsGkAtoms::title ||
+ aName == nsGkAtoms::media ||
+ aName == nsGkAtoms::type));
}
-
- if (aName == nsGkAtoms::href) {
- UpdateImport();
+ } else {
+ // Since removing href or rel makes us no longer link to a
+ // stylesheet, force updates for those too.
+ if (aNameSpaceID == kNameSpaceID_None) {
+ if (aName == nsGkAtoms::href ||
+ aName == nsGkAtoms::rel ||
+ aName == nsGkAtoms::title ||
+ aName == nsGkAtoms::media ||
+ aName == nsGkAtoms::type) {
+ UpdateStyleSheetInternal(nullptr, nullptr, true);
+ }
+ if (aName == nsGkAtoms::href ||
+ aName == nsGkAtoms::rel) {
+ UpdateImport();
+ }
}
-
- UpdateStyleSheetInternal(nullptr, nullptr,
- dropSheet ||
- (aName == nsGkAtoms::title ||
- aName == nsGkAtoms::media ||
- aName == nsGkAtoms::type));
}
-
- return rv;
+
+ return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
+ aNotify);
}
nsresult
diff --git a/dom/html/HTMLLinkElement.h b/dom/html/HTMLLinkElement.h
index e636ab79d..c69df08dc 100644
--- a/dom/html/HTMLLinkElement.h
+++ b/dom/html/HTMLLinkElement.h
@@ -59,16 +59,11 @@ public:
bool aCompileEventHandlers) override;
virtual void UnbindFromTree(bool aDeep = true,
bool aNullParent = true) override;
- nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- const nsAString& aValue, bool aNotify)
- {
- return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
- }
- virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- nsIAtom* aPrefix, const nsAString& aValue,
- bool aNotify) override;
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify) override;
+ virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
+ const nsAttrValue* aValue,
+ bool aNotify) override;
virtual bool IsLink(nsIURI** aURI) const override;
virtual already_AddRefed<nsIURI> GetHrefURI() const override;
diff --git a/dom/html/HTMLStyleElement.cpp b/dom/html/HTMLStyleElement.cpp
index 605d3896d..df9e17abf 100644
--- a/dom/html/HTMLStyleElement.cpp
+++ b/dom/html/HTMLStyleElement.cpp
@@ -172,23 +172,22 @@ HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
}
nsresult
-HTMLStyleElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- nsIAtom* aPrefix, const nsAString& aValue,
- bool aNotify)
+HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
+ const nsAttrValue* aValue, bool aNotify)
{
- nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
- aValue, aNotify);
- if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
+ if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
} else if (aName == nsGkAtoms::scoped) {
- UpdateStyleSheetScopedness(true);
+ bool isScoped = aValue;
+ UpdateStyleSheetScopedness(isScoped);
}
}
- return rv;
+ return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
+ aNotify);
}
nsresult
diff --git a/dom/html/HTMLStyleElement.h b/dom/html/HTMLStyleElement.h
index d67231a2f..3eb148bc8 100644
--- a/dom/html/HTMLStyleElement.h
+++ b/dom/html/HTMLStyleElement.h
@@ -45,16 +45,11 @@ public:
bool aCompileEventHandlers) override;
virtual void UnbindFromTree(bool aDeep = true,
bool aNullParent = true) override;
- nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- const nsAString& aValue, bool aNotify)
- {
- return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
- }
- virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
- nsIAtom* aPrefix, const nsAString& aValue,
- bool aNotify) override;
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
bool aNotify) override;
+ virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
+ const nsAttrValue* aValue,
+ bool aNotify) override;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;