summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/libeditor/EditorBase.cpp14
-rw-r--r--editor/libeditor/HTMLEditRules.cpp51
-rw-r--r--editor/libeditor/HTMLEditor.cpp5
-rw-r--r--editor/libeditor/HTMLEditorObjectResizer.cpp29
-rw-r--r--editor/libeditor/HTMLStyleEditor.cpp8
-rw-r--r--editor/libeditor/TextEditRules.cpp4
-rw-r--r--editor/libeditor/TextEditor.cpp4
7 files changed, 51 insertions, 64 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp
index 7212e7c93..60df3571e 100644
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2330,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);
}
}
@@ -2346,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);
}
}
}
diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index 14f6cfe11..fe5e6c2bf 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -3302,15 +3302,15 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
}
}
NS_ENSURE_STATE(mHTMLEditor);
- nsCOMPtr<nsIDOMElement> curElement = do_QueryInterface(curNode);
- NS_NAMED_LITERAL_STRING(typestr, "type");
+ nsCOMPtr<Element> curElement = do_QueryInterface(curNode);
if (aBulletType && !aBulletType->IsEmpty()) {
- rv = mHTMLEditor->SetAttribute(curElement, typestr, *aBulletType);
+ rv = mHTMLEditor->SetAttribute(curElement, nsGkAtoms::type,
+ *aBulletType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
- rv = mHTMLEditor->RemoveAttribute(curElement, typestr);
+ rv = mHTMLEditor->RemoveAttribute(curElement, nsGkAtoms::type);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -4836,7 +4836,6 @@ HTMLEditRules::AlignBlockContents(nsIDOMNode* aNode,
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node && alignType, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIContent> firstChild, lastChild;
- nsCOMPtr<Element> divNode;
bool useCSS = mHTMLEditor->IsCSSEnabled();
@@ -4844,24 +4843,25 @@ HTMLEditRules::AlignBlockContents(nsIDOMNode* aNode,
firstChild = mHTMLEditor->GetFirstEditableChild(*node);
NS_ENSURE_STATE(mHTMLEditor);
lastChild = mHTMLEditor->GetLastEditableChild(*node);
- NS_NAMED_LITERAL_STRING(attr, "align");
if (!firstChild) {
// this cell has no content, nothing to align
} else if (firstChild == lastChild &&
firstChild->IsHTMLElement(nsGkAtoms::div)) {
// the cell already has a div containing all of its content: just
// act on this div.
- nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(firstChild);
+ RefPtr<Element> divElem = firstChild->AsElement();
if (useCSS) {
NS_ENSURE_STATE(mHTMLEditor);
- nsresult rv = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr,
+ nsresult rv = mHTMLEditor->SetAttributeOrEquivalent(divElem,
+ nsGkAtoms::align,
*alignType, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
NS_ENSURE_STATE(mHTMLEditor);
- nsresult rv = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
+ nsresult rv = mHTMLEditor->SetAttribute(divElem, nsGkAtoms::align,
+ *alignType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -4869,28 +4869,29 @@ HTMLEditRules::AlignBlockContents(nsIDOMNode* aNode,
} else {
// else we need to put in a div, set the alignment, and toss in all the children
NS_ENSURE_STATE(mHTMLEditor);
- divNode = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0);
- NS_ENSURE_STATE(divNode);
+ RefPtr<Element> divElem = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0);
+ NS_ENSURE_STATE(divElem);
// set up the alignment on the div
- nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(divNode);
if (useCSS) {
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
- mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false);
+ mHTMLEditor->SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
+ *alignType, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
NS_ENSURE_STATE(mHTMLEditor);
- nsresult rv = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
+ nsresult rv =
+ mHTMLEditor->SetAttribute(divElem, nsGkAtoms::align, *alignType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// tuck the children into the end of the active div
- while (lastChild && (lastChild != divNode)) {
+ while (lastChild && (lastChild != divElem)) {
NS_ENSURE_STATE(mHTMLEditor);
- nsresult rv = mHTMLEditor->MoveNode(lastChild, divNode, 0);
+ nsresult rv = mHTMLEditor->MoveNode(lastChild, divElem, 0);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_STATE(mHTMLEditor);
lastChild = mHTMLEditor->GetLastEditableChild(*node);
@@ -6510,9 +6511,9 @@ HTMLEditRules::SplitParagraph(nsIDOMNode *aPara,
}
// remove ID attribute on the paragraph we just created
- nsCOMPtr<nsIDOMElement> rightElt = do_QueryInterface(rightPara);
+ RefPtr<Element> rightElt = rightPara->AsElement();
NS_ENSURE_STATE(mHTMLEditor);
- rv = mHTMLEditor->RemoveAttribute(rightElt, NS_LITERAL_STRING("id"));
+ rv = mHTMLEditor->RemoveAttribute(rightElt, nsGkAtoms::id);
NS_ENSURE_SUCCESS(rv, rv);
// check both halves of para to see if we need mozBR
@@ -8387,18 +8388,18 @@ HTMLEditRules::RemoveAlignment(nsIDOMNode* aNode,
NS_ENSURE_SUCCESS(rv, rv);
} else if (isBlock || HTMLEditUtils::IsHR(child)) {
// the current node is a block element
- nsCOMPtr<nsIDOMElement> curElem = do_QueryInterface(child);
+ nsCOMPtr<Element> curElem = do_QueryInterface(child);
if (HTMLEditUtils::SupportsAlignAttr(child)) {
// remove the ALIGN attribute if this element can have it
NS_ENSURE_STATE(mHTMLEditor);
- rv = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align"));
+ rv = mHTMLEditor->RemoveAttribute(curElem, nsGkAtoms::align);
NS_ENSURE_SUCCESS(rv, rv);
}
if (useCSS) {
if (HTMLEditUtils::IsTable(child) || HTMLEditUtils::IsHR(child)) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->SetAttributeOrEquivalent(curElem,
- NS_LITERAL_STRING("align"),
+ nsGkAtoms::align,
aAlignType, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@@ -8518,21 +8519,17 @@ HTMLEditRules::AlignBlock(Element& aElement,
nsresult rv = RemoveAlignment(aElement.AsDOMNode(), aAlignType,
aContentsOnly == ContentsOnly::yes);
NS_ENSURE_SUCCESS(rv, rv);
- NS_NAMED_LITERAL_STRING(attr, "align");
if (htmlEditor->IsCSSEnabled()) {
// Let's use CSS alignment; we use margin-left and margin-right for tables
// and text-align for other block-level elements
rv = htmlEditor->SetAttributeOrEquivalent(
- static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
- attr, aAlignType, false);
+ &aElement, nsGkAtoms::align, aAlignType, false);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// HTML case; this code is supposed to be called ONLY if the element
// supports the align attribute but we'll never know...
if (HTMLEditUtils::SupportsAlignAttr(aElement.AsDOMNode())) {
- rv = htmlEditor->SetAttribute(
- static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
- attr, aAlignType);
+ rv = htmlEditor->SetAttribute(&aElement, nsGkAtoms::align, aAlignType);
NS_ENSURE_SUCCESS(rv, rv);
}
}
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 4cda49ab5..6a630cb1c 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2529,7 +2529,7 @@ HTMLEditor::CreateElementWithDefaults(const nsAString& aTagName)
// New call to use instead to get proper HTML element, bug 39919
nsCOMPtr<nsIAtom> realTagAtom = NS_Atomize(realTagName);
- nsCOMPtr<Element> newElement = CreateHTMLContent(realTagAtom);
+ RefPtr<Element> newElement = CreateHTMLContent(realTagAtom);
if (!newElement) {
return nullptr;
}
@@ -2561,8 +2561,7 @@ HTMLEditor::CreateElementWithDefaults(const nsAString& aTagName)
} else if (tagName.EqualsLiteral("td")) {
nsresult rv =
SetAttributeOrEquivalent(
- static_cast<nsIDOMElement*>(newElement->AsDOMNode()),
- NS_LITERAL_STRING("valign"), NS_LITERAL_STRING("top"), true);
+ newElement, nsGkAtoms::valign, NS_LITERAL_STRING("top"), true);
NS_ENSURE_SUCCESS(rv, nullptr);
}
// ADD OTHER TAGS HERE
diff --git a/editor/libeditor/HTMLEditorObjectResizer.cpp b/editor/libeditor/HTMLEditorObjectResizer.cpp
index 111a3f975..8ed5b6e4d 100644
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -926,35 +926,30 @@ HTMLEditor::SetFinalSize(int32_t aX,
// we want one transaction only from a user's point of view
AutoEditBatch batchIt(this);
- NS_NAMED_LITERAL_STRING(widthStr, "width");
- NS_NAMED_LITERAL_STRING(heightStr, "height");
-
- nsCOMPtr<Element> resizedObject = do_QueryInterface(mResizedObject);
- NS_ENSURE_TRUE(resizedObject, );
if (mResizedObjectIsAbsolutelyPositioned) {
if (setHeight) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::top, y);
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::top, y);
}
if (setWidth) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::left, x);
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::left, x);
}
}
if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) {
if (setWidth && mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) {
- RemoveAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), widthStr);
+ RemoveAttribute(mResizedObject, nsGkAtoms::width);
}
if (setHeight && mResizedObject->HasAttr(kNameSpaceID_None,
nsGkAtoms::height)) {
- RemoveAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), heightStr);
+ RemoveAttribute(mResizedObject, nsGkAtoms::height);
}
if (setWidth) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width,
width);
}
if (setHeight) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height,
height);
}
} else {
@@ -964,30 +959,30 @@ HTMLEditor::SetFinalSize(int32_t aX,
// triggering an immediate reflow; otherwise, we have problems
// with asynchronous reflow
if (setWidth) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width,
width);
}
if (setHeight) {
- mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height,
height);
}
if (setWidth) {
nsAutoString w;
w.AppendInt(width);
- SetAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), widthStr, w);
+ SetAttribute(mResizedObject, nsGkAtoms::width, w);
}
if (setHeight) {
nsAutoString h;
h.AppendInt(height);
- SetAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), heightStr, h);
+ SetAttribute(mResizedObject, nsGkAtoms::height, h);
}
if (setWidth) {
- mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::width,
EmptyString());
}
if (setHeight) {
- mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::height,
EmptyString());
}
}
diff --git a/editor/libeditor/HTMLStyleEditor.cpp b/editor/libeditor/HTMLStyleEditor.cpp
index d3eabba1d..c41f0a05c 100644
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -744,8 +744,6 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
// if we weren't passed an attribute, then we want to
// remove any matching inlinestyles entirely
if (!aAttribute || aAttribute->IsEmpty()) {
- NS_NAMED_LITERAL_STRING(styleAttr, "style");
- NS_NAMED_LITERAL_STRING(classAttr, "class");
bool hasStyleAttr = aNode.HasAttr(kNameSpaceID_None, nsGkAtoms::style);
bool hasClassAttr = aNode.HasAttr(kNameSpaceID_None, nsGkAtoms::_class);
@@ -754,14 +752,14 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
// just remove the element... We need to create above the element
// a span that will carry those styles or class, then we can delete
// the node.
- nsCOMPtr<Element> spanNode =
+ RefPtr<Element> spanNode =
InsertContainerAbove(&aNode, nsGkAtoms::span);
NS_ENSURE_STATE(spanNode);
nsresult rv =
- CloneAttribute(styleAttr, spanNode->AsDOMNode(), aNode.AsDOMNode());
+ CloneAttribute(nsGkAtoms::style, spanNode, aNode.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
rv =
- CloneAttribute(classAttr, spanNode->AsDOMNode(), aNode.AsDOMNode());
+ CloneAttribute(nsGkAtoms::_class, spanNode, aNode.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
}
nsresult rv = RemoveContainer(&aNode);
diff --git a/editor/libeditor/TextEditRules.cpp b/editor/libeditor/TextEditRules.cpp
index 4ecaff722..e98d36dd3 100644
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1422,9 +1422,9 @@ TextEditRules::CreateMozBR(nsIDOMNode* inParent,
NS_ENSURE_SUCCESS(rv, rv);
// give it special moz attr
- nsCOMPtr<nsIDOMElement> brElem = do_QueryInterface(brNode);
+ nsCOMPtr<Element> brElem = do_QueryInterface(brNode);
if (brElem) {
- rv = mTextEditor->SetAttribute(brElem, NS_LITERAL_STRING("type"),
+ rv = mTextEditor->SetAttribute(brElem, nsGkAtoms::type,
NS_LITERAL_STRING("_moz"));
NS_ENSURE_SUCCESS(rv, rv);
}
diff --git a/editor/libeditor/TextEditor.cpp b/editor/libeditor/TextEditor.cpp
index 545e3a3d1..3bee7843c 100644
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -311,9 +311,9 @@ TextEditor::UpdateMetaCharset(nsIDOMDocument* aDocument,
}
// set attribute to <original prefix> charset=text/html
- nsCOMPtr<nsIDOMElement> metaElement = do_QueryInterface(metaNode);
+ RefPtr<Element> metaElement = metaNode->AsElement();
MOZ_ASSERT(metaElement);
- rv = EditorBase::SetAttribute(metaElement, NS_LITERAL_STRING("content"),
+ rv = EditorBase::SetAttribute(metaElement, nsGkAtoms::content,
Substring(originalStart, start) +
charsetEquals +
NS_ConvertASCIItoUTF16(aCharacterSet));