Backout changeset 7207f05dd558 (bug 1190172 part 1)
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Apr 2016 20:02:28 +0900
changeset 332545 e5bfcb0917c0921e22ae9d844aa5a5edd12c8e42
parent 332544 6b1fc61b9be27e348be8da32d78668ff72d8aed6
child 332546 f0837841e7dff6a9c5ecc26ecb8de5e9a0c07e77
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)
bugs1190172
milestone48.0a1
backs out7207f05dd558cd5cde2d354a51f7d04cc800decf
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
Backout changeset 7207f05dd558 (bug 1190172 part 1)
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -2742,24 +2742,32 @@ nsHTMLEditRules::JoinBlocks(nsIContent& 
         previousContentOffset++;
       }
 
       // Because we don't want the moving content to receive the style of the
       // previous content, we split the previous content's style.
 
       nsCOMPtr<Element> editorRoot = mHTMLEditor->GetEditorRoot();
       if (!editorRoot || &aLeftNode != editorRoot) {
-        nsCOMPtr<nsIContent> splittedPreviousContent;
-        res = mHTMLEditor->SplitStyleAbovePoint(address_of(previousContentParent),
+        nsCOMPtr<nsIDOMNode> previousContentParentDOM =
+          GetAsDOMNode(previousContentParent);
+        nsCOMPtr<nsIDOMNode> splittedPreviousContentDOM;
+        res = mHTMLEditor->SplitStyleAbovePoint(address_of(previousContentParentDOM),
                                                 &previousContentOffset,
                                                 nullptr, nullptr, nullptr,
-                                                getter_AddRefs(splittedPreviousContent));
+                                                address_of(splittedPreviousContentDOM));
         NS_ENSURE_SUCCESS(res, res);
-
-        if (splittedPreviousContent) {
+        previousContentParent = do_QueryInterface(previousContentParentDOM);
+        NS_ENSURE_STATE(previousContentParent || !previousContentParentDOM);
+
+        if (splittedPreviousContentDOM) {
+          nsCOMPtr<nsINode> splittedPreviousContent =
+            do_QueryInterface(splittedPreviousContentDOM);
+          NS_ENSURE_STATE(splittedPreviousContent ||
+                          !splittedPreviousContentDOM);
           previousContentParent = splittedPreviousContent->GetParentNode();
           previousContentOffset = previousContentParent ?
             previousContentParent->IndexOf(splittedPreviousContent) : -1;
         }
       }
 
       res = MoveBlock(GetAsDOMNode(previousContentParent),
                       GetAsDOMNode(rightBlock),
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -659,21 +659,22 @@ protected:
                                    const nsAString* aAttribute,
                                    const nsAString& aValue);
 
   nsresult PromoteInlineRange(nsRange* aRange);
   nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange* aRange);
   nsresult SplitStyleAboveRange(nsRange* aRange,
                                 nsIAtom *aProperty,
                                 const nsAString *aAttribute);
-  nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
-                                nsIAtom* aProperty,
-                                const nsAString* aAttribute,
-                                nsIContent** aOutLeftNode = nullptr,
-                                nsIContent** aOutRightNode = nullptr);
+  nsresult SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
+                                int32_t *aOffset,
+                                nsIAtom *aProperty,
+                                const nsAString *aAttribute,
+                                nsCOMPtr<nsIDOMNode> *outLeftNode = nullptr,
+                                nsCOMPtr<nsIDOMNode> *outRightNode = nullptr);
   nsresult ApplyDefaultProperties();
   nsresult RemoveStyleInside(nsIDOMNode *aNode,
                              nsIAtom *aProperty,
                              const nsAString *aAttribute,
                              const bool aChildrenOnly = false);
   nsresult RemoveStyleInside(nsIContent& aNode,
                              nsIAtom* aProperty,
                              const nsAString* aAttribute,
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -518,143 +518,156 @@ nsHTMLEditor::SetInlinePropertyOnNode(ns
 
 
 nsresult
 nsHTMLEditor::SplitStyleAboveRange(nsRange* inRange, nsIAtom* aProperty,
                                    const nsAString* aAttribute)
 {
   NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
   nsresult res;
+  nsCOMPtr<nsIDOMNode> startNode, endNode, origStartNode;
+  int32_t startOffset, endOffset;
 
-  nsCOMPtr<nsINode> startNode = inRange->GetStartParent();
-  int32_t startOffset = inRange->StartOffset();
-  nsCOMPtr<nsINode> endNode = inRange->GetEndParent();
-  int32_t endOffset = inRange->EndOffset();
+  res = inRange->GetStartContainer(getter_AddRefs(startNode));
+  NS_ENSURE_SUCCESS(res, res);
+  res = inRange->GetStartOffset(&startOffset);
+  NS_ENSURE_SUCCESS(res, res);
+  res = inRange->GetEndContainer(getter_AddRefs(endNode));
+  NS_ENSURE_SUCCESS(res, res);
+  res = inRange->GetEndOffset(&endOffset);
+  NS_ENSURE_SUCCESS(res, res);
 
-  nsCOMPtr<nsINode> origStartNode = startNode;
+  origStartNode = startNode;
 
   // split any matching style nodes above the start of range
   {
     nsAutoTrackDOMPoint tracker(mRangeUpdater, address_of(endNode), &endOffset);
-    res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty,
-                               aAttribute);
+    res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty, aAttribute);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   // second verse, same as the first...
-  res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty,
-                             aAttribute);
+  res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty, aAttribute);
   NS_ENSURE_SUCCESS(res, res);
 
   // reset the range
   res = inRange->SetStart(startNode, startOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->SetEnd(endNode, endOffset);
   return res;
 }
 
-nsresult
-nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
-                                   int32_t* aOffset,
-                                   // null here means we split all properties
-                                   nsIAtom* aProperty,
-                                   const nsAString* aAttribute,
-                                   nsIContent** aOutLeftNode,
-                                   nsIContent** aOutRightNode)
+nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
+                                           int32_t *aOffset,
+                                           nsIAtom *aProperty,          // null here means we split all properties
+                                           const nsAString *aAttribute,
+                                           nsCOMPtr<nsIDOMNode> *outLeftNode,
+                                           nsCOMPtr<nsIDOMNode> *outRightNode)
 {
-  MOZ_ASSERT(aNode && *aNode && aOffset);
-  NS_ENSURE_TRUE((*aNode)->IsContent(), NS_OK);
-
-  // Split any matching style nodes above the node/offset
-  OwningNonNull<nsIContent> node = *(*aNode)->AsContent();
+  NS_ENSURE_TRUE(aNode && *aNode && aOffset, NS_ERROR_NULL_POINTER);
+  if (outLeftNode)  *outLeftNode  = nullptr;
+  if (outRightNode) *outRightNode = nullptr;
+  // split any matching style nodes above the node/offset
+  nsCOMPtr<nsIContent> node = do_QueryInterface(*aNode);
+  NS_ENSURE_STATE(node);
+  int32_t offset;
 
   bool useCSS = IsCSSEnabled();
 
   bool isSet;
-  while (!IsBlockNode(node) && node->GetParent() &&
-         IsEditable(node->GetParent())) {
+  while (node && !IsBlockNode(node) && node->GetParentNode() &&
+         IsEditable(node->GetParentNode())) {
     isSet = false;
-    if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
-                                                       aAttribute)) {
-      // The HTML style defined by aProperty/aAttribute has a CSS equivalence
-      // in this implementation for the node; let's check if it carries those
-      // CSS styles
+    if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
+      // the HTML style defined by aProperty/aAttribute has a CSS equivalence
+      // in this implementation for the node; let's check if it carries those css styles
       nsAutoString firstValue;
       mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node),
         aProperty, aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified);
     }
     if (// node is the correct inline prop
         (aProperty && node->IsHTMLElement(aProperty)) ||
         // node is href - test if really <a href=...
         (aProperty == nsGkAtoms::href && nsHTMLEditUtils::IsLink(node)) ||
         // or node is any prop, and we asked to split them all
         (!aProperty && NodeIsProperty(GetAsDOMNode(node))) ||
         // or the style is specified in the style attribute
         isSet) {
-      // Found a style node we need to split
-      int32_t offset = SplitNodeDeep(*node, *(*aNode)->AsContent(), *aOffset,
-                                     EmptyContainers::yes, aOutLeftNode,
-                                     aOutRightNode);
+      // found a style node we need to split
+      nsCOMPtr<nsIContent> outLeftContent, outRightContent;
+      nsCOMPtr<nsIContent> nodeParam = do_QueryInterface(*aNode);
+      NS_ENSURE_STATE(nodeParam || !*aNode);
+      offset = SplitNodeDeep(*node, *nodeParam, *aOffset, EmptyContainers::yes,
+                             getter_AddRefs(outLeftContent),
+                             getter_AddRefs(outRightContent));
       NS_ENSURE_TRUE(offset != -1, NS_ERROR_FAILURE);
       // reset startNode/startOffset
-      *aNode = node->GetParent();
+      *aNode = GetAsDOMNode(node->GetParent());
       *aOffset = offset;
+      if (outLeftNode) {
+        *outLeftNode = GetAsDOMNode(outLeftContent);
+      }
+      if (outRightNode) {
+        *outRightNode = GetAsDOMNode(outRightContent);
+      }
     }
     node = node->GetParent();
   }
-
   return NS_OK;
 }
 
 nsresult
 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(address_of(node), aOffset, aProperty,
-                                      aAttribute, getter_AddRefs(leftNode),
-                                      getter_AddRefs(rightNode));
-  *aNode = GetAsDOMNode(node);
+  nsCOMPtr<nsIDOMNode> leftNode, rightNode, tmp;
+  nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty, aAttribute,
+                                      address_of(leftNode),
+                                      address_of(rightNode));
   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);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   if (rightNode) {
-    nsCOMPtr<nsINode> secondSplitParent = GetLeftmostChild(rightNode);
+    nsCOMPtr<nsINode> rightNode_ = do_QueryInterface(rightNode);
+    NS_ENSURE_STATE(rightNode_);
+    nsCOMPtr<nsIDOMNode> secondSplitParent =
+      GetAsDOMNode(GetLeftmostChild(rightNode_));
     // don't try to split non-containers (br's, images, hr's, etc)
     if (!secondSplitParent) {
       secondSplitParent = rightNode;
     }
     nsCOMPtr<Element> savedBR;
     if (!IsContainer(secondSplitParent)) {
       if (nsTextEditUtils::IsBreak(secondSplitParent)) {
         savedBR = do_QueryInterface(secondSplitParent);
         NS_ENSURE_STATE(savedBR);
       }
 
-      secondSplitParent = secondSplitParent->GetParentNode();
+      secondSplitParent->GetParentNode(getter_AddRefs(tmp));
+      secondSplitParent = tmp;
     }
     *aOffset = 0;
     res = SplitStyleAbovePoint(address_of(secondSplitParent),
                                aOffset, aProperty, aAttribute,
-                               getter_AddRefs(leftNode),
-                               getter_AddRefs(rightNode));
+                               address_of(leftNode), address_of(rightNode));
     NS_ENSURE_SUCCESS(res, res);
     // should be impossible to not get a new leftnode here
-    nsCOMPtr<nsINode> newSelParent = GetLeftmostChild(leftNode);
+    nsCOMPtr<nsINode> leftNode_ = do_QueryInterface(leftNode);
+    NS_ENSURE_TRUE(leftNode_, NS_ERROR_FAILURE);
+    nsCOMPtr<nsINode> newSelParent = GetLeftmostChild(leftNode_);
     if (!newSelParent) {
-      newSelParent = leftNode;
+      newSelParent = do_QueryInterface(leftNode);
+      NS_ENSURE_STATE(newSelParent);
     }
     // If rightNode starts with a br, suck it out of right node and into
     // leftNode.  This is so we you don't revert back to the previous style
     // if you happen to click at the end of a line.
     if (savedBR) {
       res = MoveNode(savedBR, newSelParent, 0);
       NS_ENSURE_SUCCESS(res, res);
     }
@@ -670,17 +683,17 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOM
     {
       // Track the point at the new hierarchy.  This is so we can know where
       // to put the selection after we call RemoveStyleInside().
       // RemoveStyleInside() could remove any and all of those nodes, so I
       // 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);
+      res = RemoveStyleInside(leftNode, aProperty, aAttribute);
       NS_ENSURE_SUCCESS(res, res);
     }
     // reset our node offset values to the resulting new sel point
     *aNode = GetAsDOMNode(newSelParent);
     *aOffset = newSelOffset;
   }
 
   return NS_OK;