Bug 1190172 part 2 - Clean up nsHTMLEditor::ClearStyle; r=ehsan
☠☠ backed out by 6b1fc61b9be2 ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Sat, 23 Apr 2016 19:25:29 +0900
changeset 332521 643bf6006fea9dd538675a8b3e3c0617e84f3d29
parent 332520 7207f05dd558cd5cde2d354a51f7d04cc800decf
child 332522 ac6a27516edb47b4505aeb7d9b28a6607a3ca1b2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1190172
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190172 part 2 - Clean up nsHTMLEditor::ClearStyle; r=ehsan
editor/libeditor/nsHTMLDataTransfer.cpp
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/nsHTMLDataTransfer.cpp
@@ -339,18 +339,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
 
   if (!cellSelectionMode)
   {
     rv = DeleteSelectionAndPrepareToCreateNode();
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (aClearStyle) {
       // pasting does not inherit local inline styles
-      nsCOMPtr<nsIDOMNode> tmpNode =
-        do_QueryInterface(selection->GetAnchorNode());
+      nsCOMPtr<nsINode> tmpNode = selection->GetAnchorNode();
       int32_t tmpOffset = static_cast<int32_t>(selection->AnchorOffset());
       rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   else
   {
     // delete whole cells: we will replace with new table content
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -4420,24 +4420,21 @@ nsHTMLEditRules::ConvertListType(Element
 //
 //
 nsresult
 nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
                                           nsIDOMDocument *aDoc)
 {
   MOZ_ASSERT(aSelection && aDoc && mHTMLEditor->mTypeInState);
 
+  nsresult res;
   bool weDidSomething = false;
-  nsCOMPtr<nsIDOMNode> node, tmp;
-  int32_t offset;
-  NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection,
-                                                    getter_AddRefs(node),
-                                                    &offset);
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_STATE(aSelection->GetRangeAt(0));
+  nsCOMPtr<nsINode> node = aSelection->GetRangeAt(0)->GetStartParent();
+  int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
 
   // next examine our present style and make sure default styles are either
   // present or explicitly overridden.  If neither, add the default style to
   // the TypeInState
   int32_t length = mHTMLEditor->mDefaultStyles.Length();
   for (int32_t j = 0; j < length; j++) {
     PropItem* propItem = mHTMLEditor->mDefaultStyles[j];
     MOZ_ASSERT(propItem);
@@ -4466,53 +4463,50 @@ nsHTMLEditRules::CreateStyleForInsertTex
   }
 
   nsCOMPtr<nsIDOMElement> rootElement;
   res = aDoc->GetDocumentElement(getter_AddRefs(rootElement));
   NS_ENSURE_SUCCESS(res, res);
 
   // process clearing any styles first
   nsAutoPtr<PropItem> item(mHTMLEditor->mTypeInState->TakeClearProperty());
-  while (item && node != rootElement) {
+  while (item && GetAsDOMNode(node) != rootElement) {
     NS_ENSURE_STATE(mHTMLEditor);
     res = mHTMLEditor->ClearStyle(address_of(node), &offset,
                                   item->tag, &item->attr);
     NS_ENSURE_SUCCESS(res, res);
     item = mHTMLEditor->mTypeInState->TakeClearProperty();
     weDidSomething = true;
   }
 
   // then process setting any styles
   int32_t relFontSize = mHTMLEditor->mTypeInState->TakeRelativeFontSize();
   item = mHTMLEditor->mTypeInState->TakeSetProperty();
 
   if (item || relFontSize) {
     // we have at least one style to add; make a new text node to insert style
     // nodes above.
-    if (mHTMLEditor->IsTextNode(node)) {
+    if (RefPtr<Text> text = node->GetAsText()) {
       // if we are in a text node, split it
       NS_ENSURE_STATE(mHTMLEditor);
-      nsCOMPtr<nsIContent> content = do_QueryInterface(node);
-      NS_ENSURE_STATE(content || !node);
-      offset = mHTMLEditor->SplitNodeDeep(*content, *content, offset);
+      offset = mHTMLEditor->SplitNodeDeep(*text, *text, offset);
       NS_ENSURE_STATE(offset != -1);
-      node->GetParentNode(getter_AddRefs(tmp));
-      node = tmp;
+      node = node->GetParentNode();
     }
     if (!mHTMLEditor->IsContainer(node)) {
       return NS_OK;
     }
-    nsCOMPtr<nsIDOMNode> newNode;
+    nsCOMPtr<nsIContent> newNode;
     nsCOMPtr<nsIDOMText> nodeAsText;
     res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
     NS_ENSURE_SUCCESS(res, res);
     NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
     newNode = do_QueryInterface(nodeAsText);
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->InsertNode(newNode, node, offset);
+    res = mHTMLEditor->InsertNode(*newNode, *node, offset);
     NS_ENSURE_SUCCESS(res, res);
     node = newNode;
     offset = 0;
     weDidSomething = true;
 
     if (relFontSize) {
       // dir indicated bigger versus smaller.  1 = bigger, -1 = smaller
       int32_t dir = relFontSize > 0 ? 1 : -1;
@@ -4521,20 +4515,19 @@ nsHTMLEditRules::CreateStyleForInsertTex
         res = mHTMLEditor->RelativeFontChangeOnTextNode(dir, nodeAsText,
                                                         0, -1);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
 
     while (item) {
       NS_ENSURE_STATE(mHTMLEditor);
-      nsCOMPtr<nsIContent> content = do_QueryInterface(node);
-      NS_ENSURE_STATE(content || !node);
-      res = mHTMLEditor->SetInlinePropertyOnNode(*content, *item->tag,
-                                                 &item->attr, item->value);
+      res = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
+                                                 *item->tag, &item->attr,
+                                                 item->value);
       NS_ENSURE_SUCCESS(res, res);
       item = mHTMLEditor->mTypeInState->TakeSetProperty();
     }
   }
   if (weDidSomething) {
     return aSelection->Collapse(node, offset);
   }
 
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -750,17 +750,17 @@ protected:
                                    const nsAString& aFlavor,
                                    nsIDOMDocument* aSourceDoc,
                                    nsIDOMNode* aDestNode,
                                    int32_t aDestOffset,
                                    bool aDeleteSelection,
                                    bool aTrustedInput,
                                    bool aClearStyle = true);
 
-  nsresult ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
+  nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
                       nsIAtom* aProperty, const nsAString* aAttribute);
 
   void SetElementPosition(mozilla::dom::Element& aElement,
                           int32_t aX, int32_t aY);
 
 // Data members
 protected:
 
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -600,25 +600,23 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOM
     }
     node = node->GetParent();
   }
 
   return NS_OK;
 }
 
 nsresult
-nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
+nsHTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
                          nsIAtom* aProperty, const nsAString* aAttribute)
 {
-  nsCOMPtr<nsINode> node = do_QueryInterface(*aNode);
   nsCOMPtr<nsIContent> leftNode, rightNode;
-  nsresult res = SplitStyleAbovePoint(address_of(node), aOffset, aProperty,
+  nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty,
                                       aAttribute, getter_AddRefs(leftNode),
                                       getter_AddRefs(rightNode));
-  *aNode = GetAsDOMNode(node);
   NS_ENSURE_SUCCESS(res, res);
 
   if (leftNode) {
     bool bIsEmptyNode;
     IsEmptyNode(leftNode, &bIsEmptyNode, false, true);
     if (bIsEmptyNode) {
       // delete leftNode if it became empty
       res = DeleteNode(leftNode);
@@ -674,17 +672,17 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOM
       // have to use the range tracking system to find the right spot to put
       // selection.
       nsAutoTrackDOMPoint tracker(mRangeUpdater,
                                   address_of(newSelParent), &newSelOffset);
       res = RemoveStyleInside(GetAsDOMNode(leftNode), aProperty, aAttribute);
       NS_ENSURE_SUCCESS(res, res);
     }
     // reset our node offset values to the resulting new sel point
-    *aNode = GetAsDOMNode(newSelParent);
+    *aNode = newSelParent;
     *aOffset = newSelOffset;
   }
 
   return NS_OK;
 }
 
 bool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
 {