summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/EditorBase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/libeditor/EditorBase.cpp')
-rw-r--r--editor/libeditor/EditorBase.cpp75
1 files changed, 55 insertions, 20 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp
index f7988cd1a..fd970390f 100644
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1229,12 +1229,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);
}
@@ -1263,12 +1274,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);
}
@@ -2208,25 +2229,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);
}
/**
@@ -4618,21 +4642,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