Backout changeset 6d1996e26f78 (bug 1190172 part 8)
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Apr 2016 19:59:06 +0900
changeset 332538 a5e01f5e3813ea70986d53e9f043ac34ce89f874
parent 332537 0056f4033542ee392659b0a4e1ee3f2403ae2c8a
child 332539 ae3969f6fad59beb95c5c80131604ca5b7a02a70
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 out6d1996e26f78dad15207da2bb1d80ff71bbf9b57
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 6d1996e26f78 (bug 1190172 part 8)
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -655,17 +655,17 @@ protected:
                                        const nsAString* aAttribute,
                                        const nsAString& aValue);
   nsresult SetInlinePropertyOnNode(nsIContent& aNode,
                                    nsIAtom& aProperty,
                                    const nsAString* aAttribute,
                                    const nsAString& aValue);
 
   nsresult PromoteInlineRange(nsRange& aRange);
-  nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(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);
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -20,17 +20,19 @@
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLCSSUtils.h"
 #include "nsHTMLEditUtils.h"
 #include "nsHTMLEditor.h"
 #include "nsIAtom.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
+#include "nsIDOMCharacterData.h"
 #include "nsIDOMElement.h"
+#include "nsIDOMNode.h"
 #include "nsIEditor.h"
 #include "nsIEditorIMESupport.h"
 #include "nsNameSpaceManager.h"
 #include "nsINode.h"
 #include "nsISupportsImpl.h"
 #include "nsLiteralString.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
@@ -704,17 +706,17 @@ nsresult nsHTMLEditor::ApplyDefaultPrope
 }
 
 nsresult
 nsHTMLEditor::RemoveStyleInside(nsIContent& aNode,
                                 nsIAtom* aProperty,
                                 const nsAString* aAttribute,
                                 const bool aChildrenOnly /* = false */)
 {
-  if (aNode.GetAsText()) {
+  if (aNode.NodeType() == nsIDOMNode::TEXT_NODE) {
     return NS_OK;
   }
 
   // first process the children
   RefPtr<nsIContent> child = aNode.GetFirstChild();
   while (child) {
     // cache next sibling since we might remove child
     nsCOMPtr<nsIContent> next = child->GetNextSibling();
@@ -837,55 +839,68 @@ nsHTMLEditor::IsOnlyAttribute(const nsIC
     }
   }
   // if we made it through all of them without finding a real attribute
   // other than aAttribute, then return true
   return true;
 }
 
 nsresult
-nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange)
+nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange* inRange)
 {
-  // We assume that <a> is not nested.
-  nsCOMPtr<nsINode> startNode = aRange.GetStartParent();
-  int32_t startOffset = aRange.StartOffset();
-  nsCOMPtr<nsINode> endNode = aRange.GetEndParent();
-  int32_t endOffset = aRange.EndOffset();
-
-  nsCOMPtr<nsINode> parent = startNode;
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
+  nsresult res;
+  nsCOMPtr<nsIDOMNode> startNode, endNode, parent, tmp;
+  int32_t startOffset, endOffset, tmpOffset;
 
-  while (parent && !parent->IsHTMLElement(nsGkAtoms::body) &&
-         !nsHTMLEditUtils::IsNamedAnchor(parent)) {
-    parent = parent->GetParentNode();
+  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);
+
+  tmp = startNode;
+  while ( tmp &&
+          !nsTextEditUtils::IsBody(tmp) &&
+          !nsHTMLEditUtils::IsNamedAnchor(tmp))
+  {
+    parent = GetNodeLocation(tmp, &tmpOffset);
+    tmp = parent;
   }
-  NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-
-  if (nsHTMLEditUtils::IsNamedAnchor(parent)) {
-    startNode = parent->GetParentNode();
-    startOffset = startNode ? startNode->IndexOf(parent) : -1;
+  NS_ENSURE_TRUE(tmp, NS_ERROR_NULL_POINTER);
+  if (nsHTMLEditUtils::IsNamedAnchor(tmp))
+  {
+    parent = GetNodeLocation(tmp, &tmpOffset);
+    startNode = parent;
+    startOffset = tmpOffset;
   }
 
-  parent = endNode;
-  while (parent && !parent->IsHTMLElement(nsGkAtoms::body) &&
-         !nsHTMLEditUtils::IsNamedAnchor(parent)) {
-    parent = parent->GetParentNode();
+  tmp = endNode;
+  while ( tmp &&
+          !nsTextEditUtils::IsBody(tmp) &&
+          !nsHTMLEditUtils::IsNamedAnchor(tmp))
+  {
+    parent = GetNodeLocation(tmp, &tmpOffset);
+    tmp = parent;
   }
-  NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-
-  if (nsHTMLEditUtils::IsNamedAnchor(parent)) {
-    endNode = parent->GetParentNode();
-    endOffset = endNode ? endNode->IndexOf(parent) + 1 : 0;
+  NS_ENSURE_TRUE(tmp, NS_ERROR_NULL_POINTER);
+  if (nsHTMLEditUtils::IsNamedAnchor(tmp))
+  {
+    parent = GetNodeLocation(tmp, &tmpOffset);
+    endNode = parent;
+    endOffset = tmpOffset + 1;
   }
 
-  nsresult res = aRange.SetStart(startNode, startOffset);
+  res = inRange->SetStart(startNode, startOffset);
   NS_ENSURE_SUCCESS(res, res);
-  res = aRange.SetEnd(endNode, endOffset);
-  NS_ENSURE_SUCCESS(res, res);
-
-  return NS_OK;
+  res = inRange->SetEnd(endNode, endOffset);
+  return res;
 }
 
 nsresult
 nsHTMLEditor::PromoteInlineRange(nsRange& aRange)
 {
   nsCOMPtr<nsINode> startNode = aRange.GetStartParent();
   int32_t startOffset = aRange.StartOffset();
   nsCOMPtr<nsINode> endNode = aRange.GetEndParent();
@@ -1221,25 +1236,25 @@ nsHTMLEditor::RemoveInlinePropertyImpl(n
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
   nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
-      OwningNonNull<nsRange> range = *selection->GetRangeAt(rangeIdx);
+      RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
       if (aProperty == nsGkAtoms::name) {
         // Promote range if it starts or end in a named anchor and we want to
         // remove named anchors
         res = PromoteRangeIfStartsOrEndsInNamedAnchor(range);
       } else {
         // Adjust range to include any ancestors whose children are entirely
         // selected
-        res = PromoteInlineRange(range);
+        res = PromoteInlineRange(*range);
       }
       NS_ENSURE_SUCCESS(res, res);
 
       // Remove this style from ancestors of our range endpoints, splitting
       // them as appropriate
       res = SplitStyleAboveRange(range, aProperty, aAttribute);
       NS_ENSURE_SUCCESS(res, res);