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:41 +0300
changeset 332010 335658de496d52661b74a33893617cbc246dbe13
parent 332009 b2a788a54f0b453f7d54a238c7889ad38a07d0f3
child 332011 5061f598793413dc99668d8f0d92d7c07dab4d29
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, 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
@@ -665,27 +665,32 @@ protected:
                                 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 ApplyDefaultProperties();
+  nsresult RemoveStyleInside(nsIDOMNode *aNode,
+                             nsIAtom *aProperty,
+                             const nsAString *aAttribute,
+                             const bool aChildrenOnly = false);
   nsresult RemoveStyleInside(nsIContent& aNode,
                              nsIAtom* aProperty,
                              const nsAString* aAttribute,
                              const bool aChildrenOnly = false);
   nsresult RemoveInlinePropertyImpl(nsIAtom* aProperty,
                                     const nsAString* aAttribute);
 
   bool NodeIsProperty(nsIDOMNode *aNode);
   bool HasAttr(nsIDOMNode *aNode, const nsAString *aAttribute);
   bool IsAtFrontOfNode(nsIDOMNode *aNode, int32_t aOffset);
   bool IsAtEndOfNode(nsIDOMNode *aNode, int32_t aOffset);
+  bool IsOnlyAttribute(nsIDOMNode *aElement, const nsAString *aAttribute);
   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
@@ -668,17 +668,17 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsINod
     {
       // 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(*leftNode, aProperty, aAttribute);
+      res = RemoveStyleInside(GetAsDOMNode(leftNode), aProperty, aAttribute);
       NS_ENSURE_SUCCESS(res, res);
     }
     // reset our node offset values to the resulting new sel point
     *aNode = newSelParent;
     *aOffset = newSelOffset;
   }
 
   return NS_OK;
@@ -705,16 +705,29 @@ nsresult nsHTMLEditor::ApplyDefaultPrope
     PropItem *propItem = mDefaultStyles[j];
     NS_ENSURE_TRUE(propItem, NS_ERROR_NULL_POINTER);
     res = SetInlineProperty(propItem->tag, propItem->attr, propItem->value);
     NS_ENSURE_SUCCESS(res, res);
   }
   return res;
 }
 
+nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
+                                         // null here means remove all properties
+                                         nsIAtom *aProperty,
+                                         const nsAString *aAttribute,
+                                         const bool aChildrenOnly)
+{
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
+  NS_ENSURE_STATE(content);
+
+  return RemoveStyleInside(*content, aProperty, aAttribute, aChildrenOnly);
+}
+
 nsresult
 nsHTMLEditor::RemoveStyleInside(nsIContent& aNode,
                                 nsIAtom* aProperty,
                                 const nsAString* aAttribute,
                                 const bool aChildrenOnly /* = false */)
 {
   if (aNode.NodeType() == nsIDOMNode::TEXT_NODE) {
     return NS_OK;
@@ -816,16 +829,27 @@ nsHTMLEditor::RemoveStyleInside(nsIConte
     )
   ) {
     // if we are setting font size, remove any nested bigs and smalls
     return RemoveContainer(&aNode);
   }
   return NS_OK;
 }
 
+bool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
+                                     const nsAString *aAttribute)
+{
+  NS_ENSURE_TRUE(aNode && aAttribute, false);  // ooops
+
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
+  NS_ENSURE_TRUE(content, false);  // ooops
+
+  return IsOnlyAttribute(content, *aAttribute);
+}
+
 bool
 nsHTMLEditor::IsOnlyAttribute(const nsIContent* aContent,
                               const nsAString& aAttribute)
 {
   MOZ_ASSERT(aContent);
 
   uint32_t attrCount = aContent->GetAttrCount();
   for (uint32_t i = 0; i < attrCount; ++i) {
@@ -1324,46 +1348,47 @@ nsHTMLEditor::RemoveInlinePropertyImpl(n
                                           aAttribute, value);
             }
           }
         }
       } else {
         // Not the easy case.  Range not contained in single text node.
         nsCOMPtr<nsIContentIterator> iter = NS_NewContentSubtreeIterator();
 
-        nsTArray<OwningNonNull<nsIContent>> arrayOfNodes;
+        nsTArray<nsCOMPtr<nsINode>> arrayOfNodes;
 
         // Iterate range and build up array
         for (iter->Init(range); !iter->IsDone(); iter->Next()) {
           nsCOMPtr<nsINode> node = iter->GetCurrentNode();
           NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
-          if (IsEditable(node) && node->IsContent()) {
-            arrayOfNodes.AppendElement(*node->AsContent());
+          if (IsEditable(node)) {
+            arrayOfNodes.AppendElement(node);
           }
         }
 
         // Loop through the list, remove the property on each node
         for (auto& node : arrayOfNodes) {
-          res = RemoveStyleInside(node, aProperty, aAttribute);
+          res = RemoveStyleInside(GetAsDOMNode(node), aProperty, aAttribute);
           NS_ENSURE_SUCCESS(res, res);
           if (IsCSSEnabled() &&
               mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
                                                    aAttribute) &&
               mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node,
                   aProperty, aAttribute, EmptyString(),
                   nsHTMLCSSUtils::eComputed) &&
               // startNode's computed style indicates the CSS equivalence to
               // the HTML style to remove is applied; but we found no element
               // in the ancestors of startNode carrying specified styles;
               // assume it comes from a rule and let's try to insert a span
               // "inverting" the style
               mHTMLCSSUtils->IsCSSInvertible(*aProperty, aAttribute)) {
             NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value");
-            SetInlinePropertyOnNode(node, *aProperty, aAttribute, value);
+            SetInlinePropertyOnNode(*node->AsContent(), *aProperty,
+                                    aAttribute, value);
           }
         }
       }
     }
   }
   if (!cancel) {
     // Post-process
     res = mRules->DidDoAction(selection, &ruleInfo, res);