Backout changeset 643bf6006fea (bug 1190172 part 2)
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Apr 2016 20:02:00 +0900
changeset 318447 6b1fc61b9be27e348be8da32d78668ff72d8aed6
parent 318446 d0ac4b785b4a261383488dad7416ad9bff29f1d4
child 318448 e5bfcb0917c0921e22ae9d844aa5a5edd12c8e42
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1190172
milestone48.0a1
backs out643bf6006fea9dd538675a8b3e3c0617e84f3d29
Backout changeset 643bf6006fea (bug 1190172 part 2)
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,17 +339,18 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
 
   if (!cellSelectionMode)
   {
     rv = DeleteSelectionAndPrepareToCreateNode();
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (aClearStyle) {
       // pasting does not inherit local inline styles
-      nsCOMPtr<nsINode> tmpNode = selection->GetAnchorNode();
+      nsCOMPtr<nsIDOMNode> tmpNode =
+        do_QueryInterface(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,21 +4420,24 @@ nsHTMLEditRules::ConvertListType(Element
 //
 //
 nsresult
 nsHTMLEditRules::CreateStyleForInsertText(Selection* aSelection,
                                           nsIDOMDocument *aDoc)
 {
   MOZ_ASSERT(aSelection && aDoc && mHTMLEditor->mTypeInState);
 
-  nsresult res;
   bool weDidSomething = false;
-  NS_ENSURE_STATE(aSelection->GetRangeAt(0));
-  nsCOMPtr<nsINode> node = aSelection->GetRangeAt(0)->GetStartParent();
-  int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
+  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);
 
   // 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);
@@ -4463,50 +4466,53 @@ 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 && GetAsDOMNode(node) != rootElement) {
+  while (item && 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 (RefPtr<Text> text = node->GetAsText()) {
+    if (mHTMLEditor->IsTextNode(node)) {
       // if we are in a text node, split it
       NS_ENSURE_STATE(mHTMLEditor);
-      offset = mHTMLEditor->SplitNodeDeep(*text, *text, offset);
+      nsCOMPtr<nsIContent> content = do_QueryInterface(node);
+      NS_ENSURE_STATE(content || !node);
+      offset = mHTMLEditor->SplitNodeDeep(*content, *content, offset);
       NS_ENSURE_STATE(offset != -1);
-      node = node->GetParentNode();
+      node->GetParentNode(getter_AddRefs(tmp));
+      node = tmp;
     }
     if (!mHTMLEditor->IsContainer(node)) {
       return NS_OK;
     }
-    nsCOMPtr<nsIContent> newNode;
+    nsCOMPtr<nsIDOMNode> 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;
@@ -4515,19 +4521,20 @@ nsHTMLEditRules::CreateStyleForInsertTex
         res = mHTMLEditor->RelativeFontChangeOnTextNode(dir, nodeAsText,
                                                         0, -1);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
 
     while (item) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
-                                                 *item->tag, &item->attr,
-                                                 item->value);
+      nsCOMPtr<nsIContent> content = do_QueryInterface(node);
+      NS_ENSURE_STATE(content || !node);
+      res = mHTMLEditor->SetInlinePropertyOnNode(*content, *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<nsINode>* aNode, int32_t* aOffset,
+  nsresult ClearStyle(nsCOMPtr<nsIDOMNode>* 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,23 +600,25 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOM
     }
     node = node->GetParent();
   }
 
   return NS_OK;
 }
 
 nsresult
-nsHTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
+nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
                          nsIAtom* aProperty, const nsAString* aAttribute)
 {
+  nsCOMPtr<nsINode> node = do_QueryInterface(*aNode);
   nsCOMPtr<nsIContent> leftNode, rightNode;
-  nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty,
+  nsresult res = SplitStyleAbovePoint(address_of(node), 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);
@@ -672,17 +674,17 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsINod
       // 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 = newSelParent;
+    *aNode = GetAsDOMNode(newSelParent);
     *aOffset = newSelOffset;
   }
 
   return NS_OK;
 }
 
 bool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
 {