summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dom/base/Element.cpp36
-rw-r--r--dom/base/Element.h2
-rw-r--r--dom/webidl/Element.webidl2
-rw-r--r--toolkit/modules/LightweightThemeConsumer.jsm10
4 files changed, 48 insertions, 2 deletions
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index 52d06b0f8..79b36a314 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1230,6 +1230,42 @@ Element::GetAttribute(const nsAString& aName, DOMString& aReturn)
}
}
+bool
+Element::ToggleAttribute(const nsAString& aName,
+ const Optional<bool>& aForce,
+ ErrorResult& aError)
+{
+ aError = nsContentUtils::CheckQName(aName, false);
+ if (aError.Failed()) {
+ return false;
+ }
+
+ nsAutoString nameToUse;
+ const nsAttrName* name = InternalGetAttrNameFromQName(aName, &nameToUse);
+ if (!name) {
+ if (aForce.WasPassed() && !aForce.Value()) {
+ return false;
+ }
+ nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(nameToUse);
+ if (!nameAtom) {
+ aError.Throw(NS_ERROR_OUT_OF_MEMORY);
+ return false;
+ }
+ aError = SetAttr(kNameSpaceID_None, nameAtom, EmptyString(), true);
+ return true;
+ }
+ if (aForce.WasPassed() && aForce.Value()) {
+ return true;
+ }
+ // Hold a strong reference here so that the atom or nodeinfo doesn't go
+ // away during UnsetAttr. If it did UnsetAttr would be left with a
+ // dangling pointer as argument without knowing it.
+ nsAttrName tmp(*name);
+
+ aError = UnsetAttr(name->NamespaceID(), name->LocalName(), true);
+ return false;
+}
+
void
Element::SetAttribute(const nsAString& aName,
const nsAString& aValue,
diff --git a/dom/base/Element.h b/dom/base/Element.h
index 049984d1b..c269ab14a 100644
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -686,6 +686,8 @@ public:
void GetAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsAString& aReturn);
+ bool ToggleAttribute(const nsAString& aName, const Optional<bool>& aForce,
+ ErrorResult& aError);
void SetAttribute(const nsAString& aName, const nsAString& aValue,
ErrorResult& aError);
void SetAttributeNS(const nsAString& aNamespaceURI,
diff --git a/dom/webidl/Element.webidl b/dom/webidl/Element.webidl
index ca5f1b35c..97eb4ffe0 100644
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -41,6 +41,8 @@ interface Element : Node {
[Pure]
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[Throws]
+ boolean toggleAttribute(DOMString name, optional boolean force);
+ [Throws]
void setAttribute(DOMString name, DOMString value);
[Throws]
void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
diff --git a/toolkit/modules/LightweightThemeConsumer.jsm b/toolkit/modules/LightweightThemeConsumer.jsm
index 1dd4c976a..cd456eac2 100644
--- a/toolkit/modules/LightweightThemeConsumer.jsm
+++ b/toolkit/modules/LightweightThemeConsumer.jsm
@@ -22,10 +22,12 @@ this.LightweightThemeConsumer =
this._win = aDocument.defaultView;
this._footerId = aDocument.documentElement.getAttribute("lightweightthemesfooter");
+/* XXX: If we want to disable LWTs for PB mode, this would be needed.
+ * Perhaps make this pref-controlled in the future if people want it?
if (PrivateBrowsingUtils.isWindowPrivate(this._win) &&
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
return;
- }
+ } */
let screen = this._win.screen;
this._lastScreenWidth = screen.width;
@@ -87,12 +89,16 @@ LightweightThemeConsumer.prototype = {
},
destroy: function () {
+/* XXX: If we want to disable LWTs for PB mode, this would be needed.
if (!PrivateBrowsingUtils.isWindowPrivate(this._win) ||
PrivateBrowsingUtils.permanentPrivateBrowsing) {
Services.obs.removeObserver(this, "lightweight-theme-styling-update");
this._win.removeEventListener("resize", this);
- }
+ } */
+
+ Services.obs.removeObserver(this, "lightweight-theme-styling-update");
+ this._win.removeEventListener("resize", this);
this._win = this._doc = null;
},