diff options
author | Moonchild <moonchild@palemoon.org> | 2020-08-13 12:10:54 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-08-13 12:10:54 +0000 |
commit | 11285cd0d6ef7de80d22187b99376602ed547214 (patch) | |
tree | 034c72eea2e7838b08abd00f37acf8e3c9e97949 /editor/libeditor/EditorBase.cpp | |
parent | e1e535c1c6372f95b4a14b6a00b6d6e7be400c3b (diff) | |
parent | d3383327a749ddb5c0626146c6f83bdfa3ea9936 (diff) | |
download | UXP-11285cd0d6ef7de80d22187b99376602ed547214.tar UXP-11285cd0d6ef7de80d22187b99376602ed547214.tar.gz UXP-11285cd0d6ef7de80d22187b99376602ed547214.tar.lz UXP-11285cd0d6ef7de80d22187b99376602ed547214.tar.xz UXP-11285cd0d6ef7de80d22187b99376602ed547214.zip |
Merge branch 'master' into es-modules-work
Diffstat (limited to 'editor/libeditor/EditorBase.cpp')
-rw-r--r-- | editor/libeditor/EditorBase.cpp | 89 |
1 files changed, 61 insertions, 28 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index 3f419a74e..60df3571e 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -1235,12 +1235,23 @@ EditorBase::SetAttribute(nsIDOMElement* aElement, const nsAString& aAttribute, const nsAString& aValue) { + if (NS_WARN_IF(aAttribute.IsEmpty())) { + return NS_ERROR_FAILURE; + } nsCOMPtr<Element> element = do_QueryInterface(aElement); NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute); + return SetAttribute(element, attribute, aValue); +} + +nsresult +EditorBase::SetAttribute(Element* aElement, + nsIAtom* aAttribute, + const nsAString& aValue) +{ RefPtr<ChangeAttributeTransaction> transaction = - CreateTxnForSetAttribute(*element, *attribute, aValue); + CreateTxnForSetAttribute(*aElement, *aAttribute, aValue); return DoTransaction(transaction); } @@ -1269,12 +1280,22 @@ NS_IMETHODIMP EditorBase::RemoveAttribute(nsIDOMElement* aElement, const nsAString& aAttribute) { + if (NS_WARN_IF(aAttribute.IsEmpty())) { + return NS_ERROR_FAILURE; + } nsCOMPtr<Element> element = do_QueryInterface(aElement); NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute); + return RemoveAttribute(element, attribute); +} + +nsresult +EditorBase::RemoveAttribute(Element* aElement, + nsIAtom* aAttribute) +{ RefPtr<ChangeAttributeTransaction> transaction = - CreateTxnForRemoveAttribute(*element, *attribute); + CreateTxnForRemoveAttribute(*aElement, *aAttribute); return DoTransaction(transaction); } @@ -2249,25 +2270,28 @@ EditorBase::CloneAttribute(const nsAString& aAttribute, nsIDOMNode* aSourceNode) { NS_ENSURE_TRUE(aDestNode && aSourceNode, NS_ERROR_NULL_POINTER); + if (NS_WARN_IF(aAttribute.IsEmpty())) { + return NS_ERROR_FAILURE; + } - nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode); - nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode); + nsCOMPtr<Element> destElement = do_QueryInterface(aDestNode); + nsCOMPtr<Element> sourceElement = do_QueryInterface(aSourceNode); NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE); + nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute); + return CloneAttribute(attribute, destElement, sourceElement); +} + +nsresult +EditorBase::CloneAttribute(nsIAtom* aAttribute, + Element* aDestElement, + Element* aSourceElement) +{ nsAutoString attrValue; - bool isAttrSet; - nsresult rv = GetAttributeValue(sourceElement, - aAttribute, - attrValue, - &isAttrSet); - NS_ENSURE_SUCCESS(rv, rv); - if (isAttrSet) { - rv = SetAttribute(destElement, aAttribute, attrValue); - } else { - rv = RemoveAttribute(destElement, aAttribute); + if (aSourceElement->GetAttr(kNameSpaceID_None, aAttribute, attrValue)) { + return SetAttribute(aDestElement, aAttribute, attrValue); } - - return rv; + return RemoveAttribute(aDestElement, aAttribute); } /** @@ -2306,11 +2330,9 @@ EditorBase::CloneAttributes(Element* aDest, RefPtr<nsDOMAttributeMap> destAttributes = aDest->Attributes(); while (RefPtr<Attr> attr = destAttributes->Item(0)) { if (destInBody) { - RemoveAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(aDest)), - attr->NodeName()); + RemoveAttribute(aDest, attr->NodeInfo()->NameAtom()); } else { - ErrorResult ignored; - aDest->RemoveAttribute(attr->NodeName(), ignored); + aDest->UnsetAttr(kNameSpaceID_None, attr->NodeInfo()->NameAtom(), true); } } @@ -2322,13 +2344,13 @@ EditorBase::CloneAttributes(Element* aDest, nsAutoString value; attr->GetValue(value); if (destInBody) { - SetAttributeOrEquivalent(static_cast<nsIDOMElement*>(GetAsDOMNode(aDest)), - attr->NodeName(), value, false); + SetAttributeOrEquivalent(aDest, attr->NodeInfo()->NameAtom(), value, + false); } else { // The element is not inserted in the document yet, we don't want to put // a transaction on the UndoStack - SetAttributeOrEquivalent(static_cast<nsIDOMElement*>(GetAsDOMNode(aDest)), - attr->NodeName(), value, true); + SetAttributeOrEquivalent(aDest, attr->NodeInfo()->NameAtom(), value, + true); } } } @@ -4678,21 +4700,32 @@ EditorBase::CreateHTMLContent(nsIAtom* aTag) kNameSpaceID_XHTML); } -nsresult +NS_IMETHODIMP EditorBase::SetAttributeOrEquivalent(nsIDOMElement* aElement, const nsAString& aAttribute, const nsAString& aValue, bool aSuppressTransaction) { - return SetAttribute(aElement, aAttribute, aValue); + nsCOMPtr<Element> element = do_QueryInterface(aElement); + if (NS_WARN_IF(!element)) { + return NS_ERROR_NULL_POINTER; + } + nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute); + return SetAttributeOrEquivalent(element, attribute, aValue, + aSuppressTransaction); } -nsresult +NS_IMETHODIMP EditorBase::RemoveAttributeOrEquivalent(nsIDOMElement* aElement, const nsAString& aAttribute, bool aSuppressTransaction) { - return RemoveAttribute(aElement, aAttribute); + nsCOMPtr<Element> element = do_QueryInterface(aElement); + if (NS_WARN_IF(!element)) { + return NS_ERROR_NULL_POINTER; + } + nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute); + return RemoveAttributeOrEquivalent(element, attribute, aSuppressTransaction); } nsresult |