зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1469592 - Add support for Element.toggleAttribute. r=bzbarsky,smaug!
MozReview-Commit-ID: KkDLMlQgESs Differential Revision: https://phabricator.services.mozilla.com/D1710 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8745339529
Коммит
59b20406b3
|
@ -1321,6 +1321,43 @@ Element::GetAttribute(const nsAString& aName, DOMString& aReturn)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Element::ToggleAttribute(const nsAString& aName,
|
||||
const Optional<bool>& aForce,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
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;
|
||||
}
|
||||
RefPtr<nsAtom> nameAtom = NS_AtomizeMainThread(nameToUse);
|
||||
if (!nameAtom) {
|
||||
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return false;
|
||||
}
|
||||
aError = SetAttr(kNameSpaceID_None, nameAtom, EmptyString(), aTriggeringPrincipal, 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,
|
||||
|
|
|
@ -1101,6 +1101,8 @@ public:
|
|||
void GetAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aLocalName,
|
||||
nsAString& aReturn);
|
||||
bool ToggleAttribute(const nsAString& aName, const Optional<bool>& aForce,
|
||||
nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError);
|
||||
void SetAttribute(const nsAString& aName, const nsAString& aValue,
|
||||
nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError);
|
||||
void SetAttributeNS(const nsAString& aNamespaceURI,
|
||||
|
|
|
@ -41,6 +41,8 @@ interface Element : Node {
|
|||
[Pure]
|
||||
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
|
||||
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
|
||||
boolean toggleAttribute(DOMString name, optional boolean force);
|
||||
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
|
||||
void setAttribute(DOMString name, DOMString value);
|
||||
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
|
||||
void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
|
||||
|
|
|
@ -360,6 +360,7 @@ interface Element : Node {
|
|||
void setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
|
||||
void removeAttribute(DOMString qualifiedName);
|
||||
void removeAttributeNS(DOMString? namespace, DOMString localName);
|
||||
boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
|
||||
boolean hasAttribute(DOMString qualifiedName);
|
||||
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче