Backout changeset 47a8205beae7 (bug 1190172 part 7)
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Apr 2016 19:59:35 +0900
changeset 332539 ae3969f6fad59beb95c5c80131604ca5b7a02a70
parent 332538 a5e01f5e3813ea70986d53e9f043ac34ce89f874
child 332540 c02a5a394dba5d35110002e6206726e746a7a3ff
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 out47a8205beae7de859c350223bc2caaad51c5f573
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 47a8205beae7 (bug 1190172 part 7)
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -654,17 +654,17 @@ protected:
                                        nsIAtom& aProperty,
                                        const nsAString* aAttribute,
                                        const nsAString& aValue);
   nsresult SetInlinePropertyOnNode(nsIContent& aNode,
                                    nsIAtom& aProperty,
                                    const nsAString* aAttribute,
                                    const nsAString& aValue);
 
-  nsresult PromoteInlineRange(nsRange& aRange);
+  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,
@@ -673,18 +673,18 @@ protected:
   nsresult RemoveStyleInside(nsIContent& aNode,
                              nsIAtom* aProperty,
                              const nsAString* aAttribute,
                              const bool aChildrenOnly = false);
   nsresult RemoveInlinePropertyImpl(nsIAtom* aProperty,
                                     const nsAString* aAttribute);
 
   bool NodeIsProperty(nsINode& aNode);
-  bool IsAtFrontOfNode(nsINode& aNode, int32_t aOffset);
-  bool IsAtEndOfNode(nsINode& aNode, int32_t aOffset);
+  bool IsAtFrontOfNode(nsIDOMNode *aNode, int32_t aOffset);
+  bool IsAtEndOfNode(nsIDOMNode *aNode, int32_t aOffset);
   bool IsOnlyAttribute(const nsIContent* aElement, const nsAString& aAttribute);
 
   nsresult RemoveBlockContainer(nsIDOMNode *inNode);
 
   nsIContent* GetPriorHTMLSibling(nsINode* aNode);
   nsresult GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode);
   nsIContent* GetPriorHTMLSibling(nsINode* aParent, int32_t aOffset);
   nsresult GetPriorHTMLSibling(nsIDOMNode *inParent, int32_t inOffset, nsCOMPtr<nsIDOMNode> *outNode);
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -140,17 +140,17 @@ nsHTMLEditor::SetInlineProperty(nsIAtom*
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
       RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
 
       // Adjust range to include any ancestors whose children are entirely
       // selected
-      res = PromoteInlineRange(*range);
+      res = PromoteInlineRange(range);
       NS_ENSURE_SUCCESS(res, res);
 
       // Check for easy case: both range endpoints in same text node
       nsCOMPtr<nsINode> startNode = range->GetStartParent();
       nsCOMPtr<nsINode> endNode = range->GetEndParent();
       if (startNode && startNode == endNode && startNode->GetAsText()) {
         res = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
                                           range->StartOffset(),
@@ -894,84 +894,100 @@ nsHTMLEditor::PromoteRangeIfStartsOrEnds
 
   res = inRange->SetStart(startNode, startOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->SetEnd(endNode, endOffset);
   return res;
 }
 
 nsresult
-nsHTMLEditor::PromoteInlineRange(nsRange& aRange)
+nsHTMLEditor::PromoteInlineRange(nsRange* inRange)
 {
-  nsCOMPtr<nsINode> startNode = aRange.GetStartParent();
-  int32_t startOffset = aRange.StartOffset();
-  nsCOMPtr<nsINode> endNode = aRange.GetEndParent();
-  int32_t endOffset = aRange.EndOffset();
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
+  nsresult res;
+  nsCOMPtr<nsIDOMNode> startNode, endNode, parent;
+  int32_t startOffset, endOffset;
 
-  while (startNode && !startNode->IsHTMLElement(nsGkAtoms::body) &&
-         IsEditable(startNode) && IsAtFrontOfNode(*startNode, startOffset)) {
-    nsCOMPtr<nsINode> parent = startNode->GetParentNode();
-    NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-    startOffset = parent->IndexOf(startNode);
+  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);
+
+  while ( startNode &&
+          !nsTextEditUtils::IsBody(startNode) &&
+          IsEditable(startNode) &&
+          IsAtFrontOfNode(startNode, startOffset) )
+  {
+    parent = GetNodeLocation(startNode, &startOffset);
     startNode = parent;
   }
+  NS_ENSURE_TRUE(startNode, NS_ERROR_NULL_POINTER);
 
-  while (endNode && !endNode->IsHTMLElement(nsGkAtoms::body) &&
-         IsEditable(endNode) && IsAtEndOfNode(*endNode, endOffset)) {
-    nsCOMPtr<nsINode> parent = endNode->GetParentNode();
-    NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-    // We are AFTER this node
-    endOffset = 1 + parent->IndexOf(endNode);
+  while ( endNode &&
+          !nsTextEditUtils::IsBody(endNode) &&
+          IsEditable(endNode) &&
+          IsAtEndOfNode(endNode, endOffset) )
+  {
+    parent = GetNodeLocation(endNode, &endOffset);
     endNode = parent;
+    endOffset++;  // we are AFTER this node
   }
+  NS_ENSURE_TRUE(endNode, NS_ERROR_NULL_POINTER);
 
-  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;
 }
 
-bool
-nsHTMLEditor::IsAtFrontOfNode(nsINode& aNode, int32_t aOffset)
+bool nsHTMLEditor::IsAtFrontOfNode(nsIDOMNode *aNode, int32_t aOffset)
 {
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  NS_ENSURE_TRUE(node, false);
   if (!aOffset) {
     return true;
   }
 
-  if (IsTextNode(&aNode)) {
+  if (IsTextNode(aNode))
+  {
     return false;
   }
-
-  nsCOMPtr<nsIContent> firstNode = GetFirstEditableChild(aNode);
-  NS_ENSURE_TRUE(firstNode, true);
-  if (aNode.IndexOf(firstNode) < aOffset) {
-    return false;
+  else
+  {
+    nsCOMPtr<nsIContent> firstNode = GetFirstEditableChild(*node);
+    NS_ENSURE_TRUE(firstNode, true);
+    int32_t offset = node->IndexOf(firstNode);
+    if (offset < aOffset) return false;
+    return true;
   }
-  return true;
 }
 
-bool
-nsHTMLEditor::IsAtEndOfNode(nsINode& aNode, int32_t aOffset)
+bool nsHTMLEditor::IsAtEndOfNode(nsIDOMNode *aNode, int32_t aOffset)
 {
-  if (aOffset == (int32_t)aNode.Length()) {
-    return true;
-  }
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  NS_ENSURE_TRUE(node, false);
+  uint32_t len = node->Length();
+  if (aOffset == (int32_t)len) return true;
 
-  if (IsTextNode(&aNode)) {
+  if (IsTextNode(aNode))
+  {
     return false;
   }
-
-  nsCOMPtr<nsIContent> lastNode = GetLastEditableChild(aNode);
-  NS_ENSURE_TRUE(lastNode, true);
-  if (aNode.IndexOf(lastNode) < aOffset) {
-    return true;
+  else
+  {
+    nsCOMPtr<nsIContent> lastNode = GetLastEditableChild(*node);
+    NS_ENSURE_TRUE(lastNode, true);
+    int32_t offset = node->IndexOf(lastNode);
+    if (offset < aOffset) return true;
+    return false;
   }
-  return false;
 }
 
 
 nsresult
 nsHTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
                                     const nsAString* aAttribute,
                                     const nsAString* aValue,
                                     bool* aFirst,
@@ -1244,17 +1260,17 @@ nsHTMLEditor::RemoveInlinePropertyImpl(n
       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);
 
@@ -1381,17 +1397,17 @@ nsHTMLEditor::RelativeFontChange(FontSiz
   nsAutoTxnsConserveSelection dontSpazMySelection(this);
 
   // Loop through the ranges in the selection
   uint32_t rangeCount = selection->RangeCount();
   for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
     RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
 
     // Adjust range to include any ancestors with entirely selected children
-    nsresult res = PromoteInlineRange(*range);
+    nsresult res = PromoteInlineRange(range);
     NS_ENSURE_SUCCESS(res, res);
 
     // Check for easy case: both range endpoints in same text node
     nsCOMPtr<nsINode> startNode = range->GetStartParent();
     nsCOMPtr<nsINode> endNode = range->GetEndParent();
     if (startNode == endNode && IsTextNode(startNode)) {
       res = RelativeFontChangeOnTextNode(aDir, *startNode->GetAsText(),
                                          range->StartOffset(),