Bug 1190172 - Back out for now, requested by Masayuki at bug 1191356 comment 23
authorAryeh Gregor <ayg@aryeh.name>
Wed, 20 Apr 2016 20:44:23 +0300
changeset 294060 8e4064f9e7229d67b33db125cfed2f2cf445fc5e
parent 294059 8d8d85843e8caf8824cf5c096c93e23aa16a1849
child 294061 89bcf18a1f4d32436acb4f21d60b57b74f30c437
push id75422
push userayg@aryeh.name
push dateWed, 20 Apr 2016 17:45:08 +0000
treeherdermozilla-inbound@aa95332a325b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1190172, 1191356
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 - Back out for now, requested by Masayuki at bug 1191356 comment 23
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);