Bug 1156062 part 10 - Clean up MarginPropertyAtomForIndent; r=masayuki
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:10:52 +0300
changeset 295624 0f9d679b1e77974a5c82fbbb58e18ec23be9d897
parent 295623 b0899873114542f7a46f13c8b438d301c1dfda3a
child 295625 19dfc13809d12009ccdf2967489cae72885e6f2c
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1156062
milestone49.0a1
Bug 1156062 part 10 - Clean up MarginPropertyAtomForIndent; r=masayuki
editor/libeditor/nsHTMLEditRules.cpp
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -939,24 +939,23 @@ nsHTMLEditRules::GetAlignment(bool *aMix
       }
     }
     isFirstNodeToExamine = false;
     nodeToExamine = nodeToExamine->GetParentNode();
   }
   return NS_OK;
 }
 
-static nsIAtom* MarginPropertyAtomForIndent(nsHTMLCSSUtils* aHTMLCSSUtils,
-                                            nsIDOMNode* aNode) {
-  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
-  NS_ENSURE_TRUE(node || !aNode, nsGkAtoms::marginLeft);
+static nsIAtom& MarginPropertyAtomForIndent(nsHTMLCSSUtils& aHTMLCSSUtils,
+                                            nsINode& aNode)
+{
   nsAutoString direction;
-  aHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::direction, direction);
+  aHTMLCSSUtils.GetComputedProperty(aNode, *nsGkAtoms::direction, direction);
   return direction.EqualsLiteral("rtl") ?
-    nsGkAtoms::marginRight : nsGkAtoms::marginLeft;
+    *nsGkAtoms::marginRight : *nsGkAtoms::marginLeft;
 }
 
 nsresult
 nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent)
 {
   NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_FAILURE);
   *aCanIndent = true;
   *aCanOutdent = false;
@@ -979,24 +978,23 @@ nsHTMLEditRules::GetIndentState(bool *aC
   for (auto& curNode : Reversed(arrayOfNodes)) {
     if (nsHTMLEditUtils::IsNodeThatCanOutdent(GetAsDOMNode(curNode))) {
       *aCanOutdent = true;
       break;
     }
     else if (useCSS) {
       // we are in CSS mode, indentation is done using the margin-left (or margin-right) property
       NS_ENSURE_STATE(mHTMLEditor);
-      nsIAtom* marginProperty =
-        MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils,
-                                    GetAsDOMNode(curNode));
+      nsIAtom& marginProperty =
+        MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
       nsAutoString value;
       // retrieve its specified value
       NS_ENSURE_STATE(mHTMLEditor);
       mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*curNode,
-                                                       *marginProperty, value);
+                                                       marginProperty, value);
       float f;
       nsCOMPtr<nsIAtom> unit;
       // get its number part and its unit
       NS_ENSURE_STATE(mHTMLEditor);
       mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
       // if the number part is strictly positive, outdent is possible
       if (0 < f) {
         *aCanOutdent = true;
@@ -4054,23 +4052,22 @@ nsHTMLEditRules::WillOutdent(Selection* 
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->RemoveBlockContainer(GetAsDOMNode(curNode));
         NS_ENSURE_SUCCESS(res, res);
         continue;
       }
       // is it a block with a 'margin' property?
       if (useCSS && IsBlockNode(GetAsDOMNode(curNode))) {
         NS_ENSURE_STATE(mHTMLEditor);
-        nsIAtom* marginProperty =
-          MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils,
-                                      GetAsDOMNode(curNode));
+        nsIAtom& marginProperty =
+          MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
         nsAutoString value;
         NS_ENSURE_STATE(mHTMLEditor);
-        mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*curNode,
-                                                         *marginProperty,
+        mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(curNode,
+                                                         marginProperty,
                                                          value);
         float f;
         nsCOMPtr<nsIAtom> unit;
         NS_ENSURE_STATE(mHTMLEditor);
         mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
         if (f > 0)
         {
           RelativeChangeIndentationOfElementNode(GetAsDOMNode(curNode), -1);
@@ -4141,22 +4138,21 @@ nsHTMLEditRules::WillOutdent(Selection* 
           curBlockQuote = GetAsDOMNode(n);
           firstBQChild  = GetAsDOMNode(curNode);
           lastBQChild   = GetAsDOMNode(curNode);
           break;
         }
         else if (useCSS)
         {
           NS_ENSURE_STATE(mHTMLEditor);
-          nsIAtom* marginProperty =
-            MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils,
-                                        GetAsDOMNode(curNode));
+          nsIAtom& marginProperty =
+            MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
           nsAutoString value;
           NS_ENSURE_STATE(mHTMLEditor);
-          mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*n, *marginProperty,
+          mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*n, marginProperty,
                                                            value);
           float f;
           nsCOMPtr<nsIAtom> unit;
           NS_ENSURE_STATE(mHTMLEditor);
           mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
           if (f > 0 && !(nsHTMLEditUtils::IsList(curParent) && nsHTMLEditUtils::IsList(curNode)))
           {
             curBlockQuote = GetAsDOMNode(n);
@@ -8650,22 +8646,21 @@ nsHTMLEditRules::RelativeChangeIndentati
   }
 
   nsCOMPtr<Element> element = do_QueryInterface(aNode);
   if (!element) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsIAtom* marginProperty =
-    MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils,
-                                GetAsDOMNode(element));
+  nsIAtom& marginProperty =
+    MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, *element);
   nsAutoString value;
   NS_ENSURE_STATE(mHTMLEditor);
-  mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*element, *marginProperty,
+  mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*element, marginProperty,
                                                    value);
   float f;
   nsCOMPtr<nsIAtom> unit;
   NS_ENSURE_STATE(mHTMLEditor);
   mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
   if (0 == f) {
     nsAutoString defaultLengthUnit;
     NS_ENSURE_STATE(mHTMLEditor);
@@ -8692,23 +8687,23 @@ nsHTMLEditRules::RelativeChangeIndentati
             f += NS_EDITOR_INDENT_INCREMENT_PERCENT * aRelativeChange;
   }
 
   if (0 < f) {
     nsAutoString newValue;
     newValue.AppendFloat(f);
     newValue.Append(nsDependentAtomString(unit));
     NS_ENSURE_STATE(mHTMLEditor);
-    mHTMLEditor->mHTMLCSSUtils->SetCSSProperty(*element, *marginProperty,
+    mHTMLEditor->mHTMLCSSUtils->SetCSSProperty(*element, marginProperty,
                                                newValue);
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
-  mHTMLEditor->mHTMLCSSUtils->RemoveCSSProperty(*element, *marginProperty,
+  mHTMLEditor->mHTMLCSSUtils->RemoveCSSProperty(*element, marginProperty,
                                                 value);
 
   // remove unnecessary DIV blocks:
   // we could skip this section but that would cause a FAIL in
   // editor/libeditor/tests/browserscope/richtext.html, which expects
   // to unapply a CSS "indent" (<div style="margin-left: 40px;">) by
   // removing the DIV container instead of just removing the CSS property.
   nsCOMPtr<dom::Element> node = do_QueryInterface(aNode);