Bug 1347818 - Part 1. Clean up documentCharacterSet not to use nsIDOM*. r?masayuki
I want to remove nsIDOMNodeList usages from editor excepting old debug code.
(BTW, we might have to change to <meta charset> instead of <meta http-equive>, but it should handle by another issue)
MozReview-Commit-ID: ArAVOHigKNW
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -18,17 +18,16 @@
#include "HTMLEditUtils.h"
#include "HTMLURIRefObject.h"
#include "StyleSheetTransactions.h"
#include "TextEditUtils.h"
#include "TypeInState.h"
#include "nsIDOMText.h"
#include "nsIDOMMozNamedAttrMap.h"
-#include "nsIDOMNodeList.h"
#include "nsIDOMDocument.h"
#include "nsIDOMAttr.h"
#include "nsIDocumentInlines.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsISelectionController.h"
#include "nsIDOMHTMLDocument.h"
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -25,17 +25,16 @@
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIContent.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeFilter.h"
#include "nsIDOMNodeIterator.h"
-#include "nsIDOMNodeList.h"
#include "nsIDOMText.h"
#include "nsNameSpaceManager.h"
#include "nsINode.h"
#include "nsIPlaintextEditor.h"
#include "nsISupportsBase.h"
#include "nsLiteralString.h"
#include "nsUnicharUtils.h"
#include "nsIHTMLCollection.h"
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -32,17 +32,16 @@
#include "nsGkAtoms.h"
#include "nsIClipboard.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMNode.h"
-#include "nsIDOMNodeList.h"
#include "nsIDocumentEncoder.h"
#include "nsIEditRules.h"
#include "nsINode.h"
#include "nsIPresShell.h"
#include "nsISelectionController.h"
#include "nsISupportsPrimitives.h"
#include "nsITransferable.h"
#include "nsIWeakReferenceUtils.h"
@@ -227,74 +226,69 @@ TextEditor::EndEditorInit()
NS_IMETHODIMP
TextEditor::SetDocumentCharacterSet(const nsACString& characterSet)
{
nsresult rv = EditorBase::SetDocumentCharacterSet(characterSet);
NS_ENSURE_SUCCESS(rv, rv);
// Update META charset element.
- nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
- NS_ENSURE_TRUE(domdoc, NS_ERROR_NOT_INITIALIZED);
+ nsCOMPtr<nsIDocument> doc = GetDocument();
+ if (NS_WARN_IF(!doc)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
- if (UpdateMetaCharset(domdoc, characterSet)) {
+ if (UpdateMetaCharset(*doc, characterSet)) {
return NS_OK;
}
- nsCOMPtr<nsIDOMNodeList> headList;
- rv = domdoc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(headList));
- NS_ENSURE_SUCCESS(rv, rv);
- NS_ENSURE_TRUE(headList, NS_OK);
+ RefPtr<nsContentList> headList =
+ doc->GetElementsByTagName(NS_LITERAL_STRING("head"));
+ if (NS_WARN_IF(!headList)) {
+ return NS_OK;
+ }
- nsCOMPtr<nsIDOMNode> headNode;
- headList->Item(0, getter_AddRefs(headNode));
- NS_ENSURE_TRUE(headNode, NS_OK);
+ nsCOMPtr<nsIContent> headNode = headList->Item(0);
+ if (NS_WARN_IF(!headNode)) {
+ return NS_OK;
+ }
// Create a new meta charset tag
- nsCOMPtr<nsIDOMNode> resultNode;
- rv = CreateNode(NS_LITERAL_STRING("meta"), headNode, 0, getter_AddRefs(resultNode));
- NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
- NS_ENSURE_TRUE(resultNode, NS_OK);
+ RefPtr<Element> metaElement = CreateNode(nsGkAtoms::meta, headNode, 0);
+ if (NS_WARN_IF(!metaElement)) {
+ return NS_OK;
+ }
// Set attributes to the created element
if (characterSet.IsEmpty()) {
return NS_OK;
}
- nsCOMPtr<dom::Element> metaElement = do_QueryInterface(resultNode);
- if (!metaElement) {
- return NS_OK;
- }
-
// not undoable, undo should undo CreateNode
metaElement->SetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv,
NS_LITERAL_STRING("Content-Type"), true);
metaElement->SetAttr(kNameSpaceID_None, nsGkAtoms::content,
NS_LITERAL_STRING("text/html;charset=") +
NS_ConvertASCIItoUTF16(characterSet),
true);
return NS_OK;
}
bool
-TextEditor::UpdateMetaCharset(nsIDOMDocument* aDocument,
+TextEditor::UpdateMetaCharset(nsIDocument& aDocument,
const nsACString& aCharacterSet)
{
- MOZ_ASSERT(aDocument);
// get a list of META tags
- nsCOMPtr<nsIDOMNodeList> list;
- nsresult rv = aDocument->GetElementsByTagName(NS_LITERAL_STRING("meta"),
- getter_AddRefs(list));
- NS_ENSURE_SUCCESS(rv, false);
- NS_ENSURE_TRUE(list, false);
+ RefPtr<nsContentList> metaList =
+ aDocument.GetElementsByTagName(NS_LITERAL_STRING("meta"));
+ if (!metaList) {
+ return false;
+ }
- nsCOMPtr<nsINodeList> metaList = do_QueryInterface(list);
-
- uint32_t listLength = 0;
- metaList->GetLength(&listLength);
+ uint32_t listLength = metaList->Length(true);
for (uint32_t i = 0; i < listLength; ++i) {
nsCOMPtr<nsIContent> metaNode = metaList->Item(i);
MOZ_ASSERT(metaNode);
if (!metaNode->IsElement()) {
continue;
}
@@ -317,20 +311,21 @@ TextEditor::UpdateMetaCharset(nsIDOMDocu
if (!FindInReadable(charsetEquals, start, end,
nsCaseInsensitiveStringComparator())) {
continue;
}
// set attribute to <original prefix> charset=text/html
RefPtr<Element> metaElement = metaNode->AsElement();
MOZ_ASSERT(metaElement);
- rv = EditorBase::SetAttribute(metaElement, nsGkAtoms::content,
- Substring(originalStart, start) +
- charsetEquals +
- NS_ConvertASCIItoUTF16(aCharacterSet));
+ nsresult rv =
+ EditorBase::SetAttribute(metaElement, nsGkAtoms::content,
+ Substring(originalStart, start) +
+ charsetEquals +
+ NS_ConvertASCIItoUTF16(aCharacterSet));
return NS_SUCCEEDED(rv);
}
return false;
}
NS_IMETHODIMP
TextEditor::InitRules()
{
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -222,17 +222,17 @@ protected:
ePasswordFieldAllowed,
ePasswordFieldNotAllowed
};
bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
bool FireClipboardEvent(EventMessage aEventMessage,
int32_t aSelectionType,
bool* aActionTaken = nullptr);
- bool UpdateMetaCharset(nsIDOMDocument* aDocument,
+ bool UpdateMetaCharset(nsIDocument& aDocument,
const nsACString& aCharacterSet);
protected:
nsCOMPtr<nsIEditRules> mRules;
int32_t mWrapColumn;
int32_t mMaxTextLength;
int32_t mInitTriggerCounter;
int32_t mNewlineHandling;