From acf1c055490dc36b814152dc2bd99931bfcb1cb1 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 10 Jun 2012 15:39:21 +0300 Subject: [PATCH] Bug 763283 part 2 - Use nsINode::AsContent() in editor/; r=ehsan --- editor/libeditor/base/nsEditor.cpp | 9 +- editor/libeditor/html/nsHTMLEditRules.cpp | 8 +- editor/libeditor/html/nsHTMLEditor.cpp | 9 +- editor/libeditor/html/nsHTMLEditorStyle.cpp | 108 ++++++++++--------- editor/txtsvc/src/nsTextServicesDocument.cpp | 42 ++++---- 5 files changed, 94 insertions(+), 82 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 037c94074b8f..cbfe6fde1e40 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -327,7 +327,7 @@ nsEditor::InstallEventListeners() NS_ERROR_NOT_INITIALIZED); // Initialize the event target. - nsCOMPtr rootContent = do_QueryInterface(GetRoot()); + nsCOMPtr rootContent = GetRoot(); NS_ENSURE_TRUE(rootContent, NS_ERROR_NOT_AVAILABLE); mEventTarget = do_QueryInterface(rootContent->GetParent()); NS_ENSURE_TRUE(mEventTarget, NS_ERROR_NOT_AVAILABLE); @@ -1938,8 +1938,9 @@ NS_IMETHODIMP nsEditor::DumpContentTree() { #ifdef DEBUG - nsCOMPtr root = do_QueryInterface(mRootElement); - if (root) root->List(stdout); + if (mRootElement) { + mRootElement->List(stdout); + } #endif return NS_OK; } @@ -2139,7 +2140,7 @@ nsEditor::GetPreferredIMEState(IMEState *aState) return NS_OK; } - nsCOMPtr content = do_QueryInterface(GetRoot()); + nsCOMPtr content = GetRoot(); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); nsIFrame* frame = content->GetPrimaryFrame(); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 4fd3af1edd53..4ce15ac01dfd 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -2382,10 +2382,12 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection, // If something visible is deleted, no need to join. // Visible means all nodes except non-visible textnodes and breaks. if (join && origCollapsed) { - nsCOMPtr content = do_QueryInterface(somenode); - if (!content) { + if (!somenode->IsContent()) { join = false; - } else if (content->NodeType() == nsIDOMNode::TEXT_NODE) { + continue; + } + nsCOMPtr content = somenode->AsContent(); + if (content->NodeType() == nsIDOMNode::TEXT_NODE) { mHTMLEditor->IsVisTextNode(content, &join, true); } else { join = content->IsHTML(nsGkAtoms::br) && diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index df10fc3f7c64..a1c348484ff8 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -361,16 +361,17 @@ nsHTMLEditor::FindSelectionRoot(nsINode *aNode) aNode->IsNodeOfType(nsINode::eCONTENT), "aNode must be content or document node"); - nsCOMPtr content = do_QueryInterface(aNode); nsCOMPtr doc = aNode->GetCurrentDoc(); if (!doc) { return nsnull; } - if (doc->HasFlag(NODE_IS_EDITABLE) || !content) { + nsCOMPtr content; + if (doc->HasFlag(NODE_IS_EDITABLE) || !aNode->IsContent()) { content = doc->GetRootElement(); return content.forget(); } + content = aNode->AsContent(); // XXX If we have readonly flag, shouldn't return the element which has // contenteditable="true"? However, such case isn't there without chrome @@ -3396,8 +3397,8 @@ nsHTMLEditor::DeleteSelectionImpl(EDirection aAction, NS_ENSURE_STATE(selection->GetAnchorFocusRange()); NS_ENSURE_STATE(selection->GetAnchorFocusRange()->Collapsed()); - nsCOMPtr content = do_QueryInterface(selection->GetAnchorNode()); - NS_ENSURE_STATE(content); + NS_ENSURE_STATE(selection->GetAnchorNode()->IsContent()); + nsCOMPtr content = selection->GetAnchorNode()->AsContent(); // Don't strip wrappers if this is the only wrapper in the block. Then we'll // add a
later, so it won't be an empty wrapper in the end. diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index 30629013f05e..c45b9ee3a722 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -1177,10 +1177,13 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, NS_ENSURE_SUCCESS(result, result); for (iter->Init(range); !iter->IsDone(); iter->Next()) { - nsCOMPtr content = do_QueryInterface(iter->GetCurrentNode()); - nsCOMPtr node = do_QueryInterface(content); + if (!iter->GetCurrentNode()->IsContent()) { + continue; + } + nsCOMPtr content = iter->GetCurrentNode()->AsContent(); + nsCOMPtr node = content->AsDOMNode(); - if (node && nsTextEditUtils::IsBody(node)) { + if (nsTextEditUtils::IsBody(node)) { break; } @@ -1208,61 +1211,60 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, // handle non-text leaf nodes here continue; } - if (node) { - bool isSet = false; - if (first) { - if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, - aAttribute) && - // Bug 747889: we don't support CSS for fontSize values - (aProperty != nsEditProperty::font || - !aAttribute->EqualsLiteral("size"))) { - // the HTML styles defined by aProperty/aAttribute has a CSS - // equivalence in this implementation for node; let's check if it - // carries those css styles - if (aValue) { - firstValue.Assign(*aValue); - } - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, - isSet, firstValue, - COMPUTED_STYLE_TYPE); - } else { - IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, - &firstValue); - } - *aFirst = isSet; - first = false; - if (outValue) { - *outValue = firstValue; + + bool isSet = false; + if (first) { + if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, + aAttribute) && + // Bug 747889: we don't support CSS for fontSize values + (aProperty != nsEditProperty::font || + !aAttribute->EqualsLiteral("size"))) { + // the HTML styles defined by aProperty/aAttribute has a CSS + // equivalence in this implementation for node; let's check if it + // carries those css styles + if (aValue) { + firstValue.Assign(*aValue); } + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, + isSet, firstValue, + COMPUTED_STYLE_TYPE); } else { - if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, - aAttribute) && - // Bug 747889: we don't support CSS for fontSize values - (aProperty != nsEditProperty::font || - !aAttribute->EqualsLiteral("size"))) { - // the HTML styles defined by aProperty/aAttribute has a CSS equivalence - // in this implementation for node; let's check if it carries those css styles - if (aValue) { - theValue.Assign(*aValue); - } - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, - isSet, theValue, - COMPUTED_STYLE_TYPE); - } else { - IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, - &theValue); - } - if (firstValue != theValue) { - *aAll = false; - } + IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, + &firstValue); } - - if (isSet) { - *aAny = true; + *aFirst = isSet; + first = false; + if (outValue) { + *outValue = firstValue; + } + } else { + if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, + aAttribute) && + // Bug 747889: we don't support CSS for fontSize values + (aProperty != nsEditProperty::font || + !aAttribute->EqualsLiteral("size"))) { + // the HTML styles defined by aProperty/aAttribute has a CSS equivalence + // in this implementation for node; let's check if it carries those css styles + if (aValue) { + theValue.Assign(*aValue); + } + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, + isSet, theValue, + COMPUTED_STYLE_TYPE); } else { + IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, + &theValue); + } + if (firstValue != theValue) { *aAll = false; } } + + if (isSet) { + *aAny = true; + } else { + *aAll = false; + } } } if (!*aAny) { @@ -1621,8 +1623,8 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) if (NS_SUCCEEDED(res)) { nsCOMArray arrayOfNodes; while (!iter->IsDone()) { - nsCOMPtr node = do_QueryInterface(iter->GetCurrentNode()); - NS_ENSURE_TRUE(node, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(iter->GetCurrentNode()->IsContent(), NS_ERROR_FAILURE); + nsCOMPtr node = iter->GetCurrentNode()->AsContent(); if (IsEditable(node)) { arrayOfNodes.AppendObject(node); diff --git a/editor/txtsvc/src/nsTextServicesDocument.cpp b/editor/txtsvc/src/nsTextServicesDocument.cpp index 16bc1e53795b..40bfc23b2a26 100644 --- a/editor/txtsvc/src/nsTextServicesDocument.cpp +++ b/editor/txtsvc/src/nsTextServicesDocument.cpp @@ -785,13 +785,11 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, while (!iter->IsDone()) { - nsCOMPtr content = do_QueryInterface(iter->GetCurrentNode()); - - if (IsTextNode(content)) - { + if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) { // We found a text node, so position the document's // iterator at the beginning of the block, then get // the selection in terms of the string offset. + nsCOMPtr content = iter->GetCurrentNode()->AsContent(); result = mIterator->PositionAt(content); @@ -910,12 +908,10 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, while (!iter->IsDone()) { - nsCOMPtr content = do_QueryInterface(iter->GetCurrentNode()); - - if (IsTextNode(content)) - { + if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) { // We found a text node! Adjust the document's iterator to point // to the beginning of its text block, then get the current selection. + nsCOMPtr content = iter->GetCurrentNode()->AsContent(); result = mIterator->PositionAt(content); @@ -1377,13 +1373,13 @@ nsTextServicesDocument::DeleteSelection() nsCOMPtr curContent; - if (mIteratorStatus != nsTextServicesDocument::eIsDone) - { + if (mIteratorStatus != nsTextServicesDocument::eIsDone && + mIterator->GetCurrentNode()->IsContent()) { // The old iterator is still pointing to something valid, // so get its current node so we can restore it after we // create the new iterator! - curContent = do_QueryInterface(mIterator->GetCurrentNode()); + curContent = mIterator->GetCurrentNode()->AsContent(); } // Create the new iterator. @@ -2674,8 +2670,8 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS } else { // The parent has no children, so position the iterator // on the parent. - nsCOMPtr content = do_QueryInterface(parent); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(parent->IsContent(), NS_ERROR_FAILURE); + nsCOMPtr content = parent->AsContent(); result = iter->PositionAt(content); NS_ENSURE_SUCCESS(result, result); @@ -3160,7 +3156,9 @@ nsTextServicesDocument::FirstTextNodeInCurrentBlock(nsIContentIterator *iter) while (!iter->IsDone()) { - nsCOMPtr content = do_QueryInterface(iter->GetCurrentNode()); + nsCOMPtr content = iter->GetCurrentNode()->IsContent() + ? iter->GetCurrentNode()->AsContent() + : nsnull; if (IsTextNode(content)) { @@ -3231,7 +3229,9 @@ nsTextServicesDocument::FirstTextNodeInNextBlock(nsIContentIterator *aIterator) while (!aIterator->IsDone()) { - nsCOMPtr content = do_QueryInterface(aIterator->GetCurrentNode()); + nsCOMPtr content = aIterator->GetCurrentNode()->IsContent() + ? aIterator->GetCurrentNode()->AsContent() + : nsnull; if (IsTextNode(content)) { @@ -3277,7 +3277,9 @@ nsTextServicesDocument::GetFirstTextNodeInPrevBlock(nsIContent **aContent) if (!mIterator->IsDone()) { - nsCOMPtr current = do_QueryInterface(mIterator->GetCurrentNode()); + nsCOMPtr current = mIterator->GetCurrentNode()->IsContent() + ? mIterator->GetCurrentNode()->AsContent() + : nsnull; current.forget(aContent); } @@ -3311,7 +3313,9 @@ nsTextServicesDocument::GetFirstTextNodeInNextBlock(nsIContent **aContent) if (!mIterator->IsDone()) { - nsCOMPtr current = do_QueryInterface(mIterator->GetCurrentNode()); + nsCOMPtr current = mIterator->GetCurrentNode()->IsContent() + ? mIterator->GetCurrentNode()->AsContent() + : nsnull; current.forget(aContent); } @@ -3371,7 +3375,9 @@ nsTextServicesDocument::CreateOffsetTable(nsTArray *aOffsetTable, while (!aIterator->IsDone()) { - nsCOMPtr content = do_QueryInterface(aIterator->GetCurrentNode()); + nsCOMPtr content = aIterator->GetCurrentNode()->IsContent() + ? aIterator->GetCurrentNode()->AsContent() + : nsnull; if (IsTextNode(content)) {