mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 07:18:39 +09:00
Issue #1621 - Part 2: Implement nsIAtom version of SetAttribute/RemoveAttribute/CloneAttirubte.
Add nsIAtom version of the following. - CloneAttribute - RemoveAttribute - RemoveAttributeOrEquivalent - SetAttribute - SetAttributeOrEquivalent Ref: Bug 1324996
This commit is contained in:
parent
5260565a09
commit
b6b2792a35
6 changed files with 143 additions and 100 deletions
|
|
@ -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);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode);
|
||||
nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode);
|
||||
NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE);
|
||||
|
||||
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 (NS_WARN_IF(aAttribute.IsEmpty())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
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;
|
||||
if (aSourceElement->GetAttr(kNameSpaceID_None, aAttribute, attrValue)) {
|
||||
return SetAttribute(aDestElement, aAttribute, attrValue);
|
||||
}
|
||||
return RemoveAttribute(aDestElement, aAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -4678,21 +4702,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue