Bug 1190172 part 5 - Clean up nsHTMLEditor::NodeIsProperty; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Tue, 19 Apr 2016 05:42:00 +0200
changeset 331773 f8ae8039c7adfc08f712fc4a6aade266c746da6d
parent 331772 6a900f9ebc764b8b58b4a08e27226ededdd78dfe
child 331774 e5e7a733fdbc1f1c8daf814137701225152985b7
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)
reviewersehsan
bugs1190172
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 part 5 - Clean up nsHTMLEditor::NodeIsProperty; r=ehsan
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -672,17 +672,17 @@ protected:
   nsresult ApplyDefaultProperties();
   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 NodeIsProperty(nsINode& aNode);
   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);
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -581,17 +581,17 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOM
       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))) ||
+        (!aProperty && NodeIsProperty(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);
       NS_ENSURE_TRUE(offset != -1, NS_ERROR_FAILURE);
       // reset startNode/startOffset
@@ -679,26 +679,21 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsINod
     // reset our node offset values to the resulting new sel point
     *aNode = newSelParent;
     *aOffset = newSelOffset;
   }
 
   return NS_OK;
 }
 
-bool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
+bool
+nsHTMLEditor::NodeIsProperty(nsINode& aNode)
 {
-  NS_ENSURE_TRUE(aNode, false);
-  if (!IsContainer(aNode))  return false;
-  if (!IsEditable(aNode))   return false;
-  if (IsBlockNode(aNode))   return false;
-  if (NodeIsType(aNode, nsGkAtoms::a)) {
-    return false;
-  }
-  return true;
+  return IsContainer(&aNode) && IsEditable(&aNode) && !IsBlockNode(&aNode) &&
+         !aNode.IsHTMLElement(nsGkAtoms::a);
 }
 
 nsresult nsHTMLEditor::ApplyDefaultProperties()
 {
   nsresult res = NS_OK;
   uint32_t j, defcon = mDefaultStyles.Length();
   for (j=0; j<defcon; j++)
   {
@@ -735,17 +730,17 @@ nsHTMLEditor::RemoveStyleInside(nsIConte
     (
       // node is prop we asked for
       (aProperty && aNode.NodeInfo()->NameAtom() == aProperty) ||
       // but check for link (<a href=...)
       (aProperty == nsGkAtoms::href && nsHTMLEditUtils::IsLink(&aNode)) ||
       // and for named anchors
       (aProperty == nsGkAtoms::name && nsHTMLEditUtils::IsNamedAnchor(&aNode)) ||
       // or node is any prop and we asked for that
-      (!aProperty && NodeIsProperty(aNode.AsDOMNode()))
+      (!aProperty && NodeIsProperty(aNode))
     )
   ) {
     nsresult res;
     // if we weren't passed an attribute, then we want to
     // remove any matching inlinestyles entirely
     if (!aAttribute || aAttribute->IsEmpty()) {
       NS_NAMED_LITERAL_STRING(styleAttr, "style");
       NS_NAMED_LITERAL_STRING(classAttr, "class");