Bug 768756 part 4 - Clean up nsHTMLCSSUtils::GetCSSInlinePropertyBase; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 08 Jul 2012 13:31:53 +0300
changeset 99354 ce5629b973e4e2f3b074fc98094481c7349c8ad4
parent 99353 1dcff1db63b4025ef31bd3a329603300fe2af08c
child 99355 6ceeca8b4b73beb91dfd868adb98a34ca6ef414c
push id23123
push userryanvm@gmail.com
push dateSun, 15 Jul 2012 17:16:06 +0000
treeherdermozilla-central@f06d25578bdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs768756
milestone16.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 768756 part 4 - Clean up nsHTMLCSSUtils::GetCSSInlinePropertyBase; r=ehsan
editor/libeditor/html/Makefile.in
editor/libeditor/html/nsHTMLCSSUtils.cpp
--- a/editor/libeditor/html/Makefile.in
+++ b/editor/libeditor/html/Makefile.in
@@ -43,16 +43,18 @@ CPPSRCS  = \
 ifdef ENABLE_EDITOR_API_LOG
 CPPSRCS += nsHTMLEditorLog.cpp             \
            nsEditorTxnLog.cpp              \
            $(NULL)
 
 DEFINES += -DENABLE_EDITOR_API_LOG
 endif
 
+DEFINES += -D_IMPL_NS_LAYOUT
+
 # don't want the shared lib; force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES        += -I$(topsrcdir)/editor/libeditor/base \
                    -I$(topsrcdir)/editor/libeditor/text \
                    -I$(topsrcdir)/editor/txmgr/src \
--- a/editor/libeditor/html/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp
@@ -2,16 +2,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ChangeCSSInlineStyleTxn.h"
 #include "EditTxn.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/css/Declaration.h"
+#include "mozilla/css/StyleRule.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsColor.h"
 #include "nsComputedDOMStyle.h"
 #include "nsContentUtils.h"
@@ -577,63 +579,57 @@ nsHTMLCSSUtils::GetSpecifiedProperty(nsI
 nsresult
 nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
                                     nsAString & aValue)
 {
   return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eComputed);
 }
 
 nsresult
-nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
+nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty,
                                          nsAString& aValue,
                                          StyleType aStyleType)
 {
-  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   return GetCSSInlinePropertyBase(node, aProperty, aValue, aStyleType);
 }
 
 nsresult
-nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
+nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
                                          nsAString& aValue,
                                          StyleType aStyleType)
 {
+  MOZ_ASSERT(aNode && aProperty);
   aValue.Truncate();
-  NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
 
-  nsCOMPtr<nsIDOMElement> element = GetElementContainerOrSelf(aNode);
+  nsCOMPtr<dom::Element> element = GetElementContainerOrSelf(aNode);
   NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
 
-  switch (aStyleType) {
-    case eComputed:
-      if (element) {
-        nsAutoString value, propString;
-        aProperty->ToString(propString);
-        // Get the all the computed css styles attached to the element node
-        nsRefPtr<nsComputedDOMStyle> cssDecl = GetComputedStyle(element);
-        NS_ENSURE_STATE(cssDecl);
-        // from these declarations, get the one we want and that one only
-        nsresult res = cssDecl->GetPropertyValue(propString, value);
-        NS_ENSURE_SUCCESS(res, res);
-        aValue.Assign(value);
-      }
-      break;
-    case eSpecified:
-      if (element) {
-        nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
-        PRUint32 length;
-        nsresult res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length);
-        if (NS_FAILED(res) || !cssDecl) return res;
-        nsAutoString value, propString;
-        aProperty->ToString(propString);
-        res = cssDecl->GetPropertyValue(propString, value);
-        NS_ENSURE_SUCCESS(res, res);
-        aValue.Assign(value);
-      }
-      break;
+  if (aStyleType == eComputed) {
+    // Get the all the computed css styles attached to the element node
+    nsRefPtr<nsComputedDOMStyle> cssDecl = GetComputedStyle(element);
+    NS_ENSURE_STATE(cssDecl);
+
+    // from these declarations, get the one we want and that one only
+    MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
+      cssDecl->GetPropertyValue(nsDependentAtomString(aProperty), aValue)));
+
+    return NS_OK;
   }
+
+  MOZ_ASSERT(aStyleType == eSpecified);
+  nsRefPtr<css::StyleRule> rule = element->GetInlineStyleRule();
+  if (!rule) {
+    return NS_OK;
+  }
+  nsCSSProperty prop =
+    nsCSSProps::LookupProperty(nsDependentAtomString(aProperty));
+  MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
+  rule->GetDeclaration()->GetValue(prop, aValue);
+
   return NS_OK;
 }
 
 already_AddRefed<nsComputedDOMStyle>
 nsHTMLCSSUtils::GetComputedStyle(nsIDOMElement* aElement)
 {
   nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
   return GetComputedStyle(element);