Bug 585014 - Use Element in nsDOMCSSAttributeDeclaration; r=bzbarsky approval2.0=benjamin
authorMs2ger <ms2ger@gmail.com>
Fri, 27 Aug 2010 09:03:36 +0200
changeset 51555 e1d55bbd1d1d9d671ea834d7e4b30e9d9117d99a
parent 51554 4a800d695ac9ad56982b1eb5e936dabb94dfa827
child 51556 8f5523c9a830ee1b3a432af04b3279f702bc58c9
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs585014
milestone2.0b5pre
first release with
nightly linux32
e1d55bbd1d1d / 4.0b5pre / 20100827025605 / files
nightly linux64
e1d55bbd1d1d / 4.0b5pre / 20100827031135 / files
nightly mac
e1d55bbd1d1d / 4.0b5pre / 20100827030533 / files
nightly win32
e1d55bbd1d1d / 4.0b5pre / 20100827040251 / files
nightly win64
e1d55bbd1d1d / 4.0b5pre / 20100827011146 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 585014 - Use Element in nsDOMCSSAttributeDeclaration; r=bzbarsky approval2.0=benjamin
layout/style/nsDOMCSSAttrDeclaration.cpp
layout/style/nsDOMCSSAttrDeclaration.h
--- a/layout/style/nsDOMCSSAttrDeclaration.cpp
+++ b/layout/style/nsDOMCSSAttrDeclaration.cpp
@@ -15,16 +15,17 @@
  * The Original Code is Mozilla Communicator client code.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Ms2ger <ms2ger@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -33,120 +34,118 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* DOM object for element.style */
 
 #include "nsDOMCSSAttrDeclaration.h"
+
 #include "mozilla/css/Declaration.h"
+#include "mozilla/css/Loader.h"
+#include "mozilla/dom/Element.h"
+#include "nsICSSStyleRule.h"
 #include "nsIDocument.h"
 #include "nsIDOMMutationEvent.h"
-#include "nsICSSStyleRule.h"
-#include "mozilla/css/Loader.h"
+#include "nsIPrincipal.h"
 #include "nsIURI.h"
-#include "nsINameSpaceManager.h"
-#include "nsStyleConsts.h"
-#include "nsContentUtils.h"
-#include "nsIContent.h"
-#include "nsIPrincipal.h"
 #include "nsNodeUtils.h"
 
 namespace css = mozilla::css;
+namespace dom = mozilla::dom;
 
-nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIContent *aContent
+nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(dom::Element* aElement
 #ifdef MOZ_SMIL
                                                            , PRBool aIsSMILOverride
 #endif // MOZ_SMIL
                                                            )
-  : mContent(aContent)
+  : mElement(aElement)
 #ifdef MOZ_SMIL
   , mIsSMILOverride(aIsSMILOverride)
 #endif // MOZ_SMIL
 {
   MOZ_COUNT_CTOR(nsDOMCSSAttributeDeclaration);
 
-  NS_ASSERTION(aContent && aContent->IsElement(),
-               "Inline style for non-element content?");
+  NS_ASSERTION(aElement, "Inline style for a NULL element?");
 }
 
 nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
 {
   MOZ_COUNT_DTOR(nsDOMCSSAttributeDeclaration);
 }
 
-NS_IMPL_CYCLE_COLLECTION_1(nsDOMCSSAttributeDeclaration, mContent)
+NS_IMPL_CYCLE_COLLECTION_1(nsDOMCSSAttributeDeclaration, mElement)
 
 NS_INTERFACE_MAP_BEGIN(nsDOMCSSAttributeDeclaration)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsDOMCSSAttributeDeclaration)
 NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSAttributeDeclaration)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSAttributeDeclaration)
 
 nsresult
 nsDOMCSSAttributeDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
 {
-  NS_ASSERTION(mContent, "Must have content node to set the decl!");
+  NS_ASSERTION(mElement, "Must have Element to set the declaration!");
   nsICSSStyleRule* oldRule =
 #ifdef MOZ_SMIL
-    mIsSMILOverride ? mContent->GetSMILOverrideStyleRule() :
+    mIsSMILOverride ? mElement->GetSMILOverrideStyleRule() :
 #endif // MOZ_SMIL
-    mContent->GetInlineStyleRule();
-  NS_ASSERTION(oldRule, "content must have rule");
+    mElement->GetInlineStyleRule();
+  NS_ASSERTION(oldRule, "Element must have rule");
 
   nsCOMPtr<nsICSSStyleRule> newRule =
     oldRule->DeclarationChanged(aDecl, PR_FALSE);
   if (!newRule) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return
 #ifdef MOZ_SMIL
-    mIsSMILOverride ? mContent->SetSMILOverrideStyleRule(newRule, PR_TRUE) :
+    mIsSMILOverride ? mElement->SetSMILOverrideStyleRule(newRule, PR_TRUE) :
 #endif // MOZ_SMIL
-    mContent->SetInlineStyleRule(newRule, PR_TRUE);
+    mElement->SetInlineStyleRule(newRule, PR_TRUE);
 }
 
 nsIDocument*
 nsDOMCSSAttributeDeclaration::DocToUpdate()
 {
   // XXXbz this is a bit of a hack, especially doing it before the
   // BeginUpdate(), but this is a good chokepoint where we know we
   // plan to modify the CSSDeclaration, so need to notify
   // AttributeWillChange if this is inline style.
 #ifdef MOZ_SMIL
   if (!mIsSMILOverride)
 #endif
   {
-    nsNodeUtils::AttributeWillChange(mContent->AsElement(), kNameSpaceID_None,
+    nsNodeUtils::AttributeWillChange(mElement, kNameSpaceID_None,
                                      nsGkAtoms::style,
                                      nsIDOMMutationEvent::MODIFICATION);
   }
-  
+ 
   // We need GetOwnerDoc() rather than GetCurrentDoc() because it might
-  // be the BeginUpdate call that inserts mContent into the document.
-  return mContent->GetOwnerDoc();
+  // be the BeginUpdate call that inserts mElement into the document.
+  return mElement->GetOwnerDoc();
 }
 
 css::Declaration*
 nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate)
 {
-  if (!mContent)
+  if (!mElement)
     return nsnull;
 
   nsICSSStyleRule* cssRule;
 #ifdef MOZ_SMIL
   if (mIsSMILOverride)
-    cssRule = mContent->GetSMILOverrideStyleRule();
+    cssRule = mElement->GetSMILOverrideStyleRule();
   else
 #endif // MOZ_SMIL
-    cssRule = mContent->GetInlineStyleRule();
+    cssRule = mElement->GetInlineStyleRule();
 
   if (cssRule) {
     return cssRule->GetDeclaration();
   }
   if (!aAllocate) {
     return nsnull;
   }
 
@@ -154,20 +153,20 @@ nsDOMCSSAttributeDeclaration::GetCSSDecl
   css::Declaration *decl = new css::Declaration();
   decl->InitializeEmpty();
   nsCOMPtr<nsICSSStyleRule> newRule = NS_NewCSSStyleRule(nsnull, decl);
 
   // this *can* fail (inside SetAttrAndNotify, at least).
   nsresult rv;
 #ifdef MOZ_SMIL
   if (mIsSMILOverride)
-    rv = mContent->SetSMILOverrideStyleRule(newRule, PR_FALSE);
+    rv = mElement->SetSMILOverrideStyleRule(newRule, PR_FALSE);
   else
 #endif // MOZ_SMIL
-    rv = mContent->SetInlineStyleRule(newRule, PR_FALSE);
+    rv = mElement->SetInlineStyleRule(newRule, PR_FALSE);
 
   if (NS_FAILED(rv)) {
     return nsnull; // the decl will be destroyed along with the style rule
   }
 
   return decl;
 }
 
@@ -177,42 +176,47 @@ nsDOMCSSAttributeDeclaration::GetCSSDecl
  * being initialized.
  */
 nsresult
 nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
                                                        nsIURI** aBaseURI,
                                                        nsIPrincipal** aSheetPrincipal,
                                                        mozilla::css::Loader** aCSSLoader)
 {
-  NS_ASSERTION(mContent, "Something is severely broken -- there should be an nsIContent here!");
+  NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!");
   // null out the out params since some of them may not get initialized below
   *aSheetURI = nsnull;
   *aBaseURI = nsnull;
   *aSheetPrincipal = nsnull;
   *aCSSLoader = nsnull;
 
-  nsIDocument* doc = mContent->GetOwnerDoc();
+  nsIDocument* doc = mElement->GetOwnerDoc();
   if (!doc) {
     // document has been destroyed
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
+  nsCOMPtr<nsIURI> baseURI = mElement->GetBaseURI();
   nsCOMPtr<nsIURI> sheetURI = doc->GetDocumentURI();
 
   NS_ADDREF(*aCSSLoader = doc->CSSLoader());
 
   baseURI.swap(*aBaseURI);
   sheetURI.swap(*aSheetURI);
-  NS_ADDREF(*aSheetPrincipal = mContent->NodePrincipal());
+  NS_ADDREF(*aSheetPrincipal = mElement->NodePrincipal());
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
 {
   NS_ENSURE_ARG_POINTER(aParent);
 
   *aParent = nsnull;
   return NS_OK;
 }
 
+/* virtual */ nsINode*
+nsDOMCSSAttributeDeclaration::GetParentObject()
+{
+  return mElement;
+}
--- a/layout/style/nsDOMCSSAttrDeclaration.h
+++ b/layout/style/nsDOMCSSAttrDeclaration.h
@@ -15,16 +15,17 @@
  * The Original Code is Mozilla Communicator client code.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Ms2ger <ms2ger@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -37,31 +38,36 @@
 
 /* DOM object for element.style */
 
 #ifndef nsDOMCSSAttributeDeclaration_h
 #define nsDOMCSSAttributeDeclaration_h
 
 #include "nsDOMCSSDeclaration.h"
 
+#include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsWrapperCache.h"
-#include "nsIContent.h"
 
 namespace mozilla {
 namespace css {
 class Loader;
 }
+
+namespace dom {
+class Element;
+}
 }
 
 class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration,
                                      public nsWrapperCache
 {
 public:
-  nsDOMCSSAttributeDeclaration(nsIContent *aContent
+  typedef mozilla::dom::Element Element;
+  nsDOMCSSAttributeDeclaration(Element* aContent
 #ifdef MOZ_SMIL
                                , PRBool aIsSMILOverride
 #endif // MOZ_SMIL
                                );
   ~nsDOMCSSAttributeDeclaration();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMCSSAttributeDeclaration,
@@ -71,27 +77,23 @@ public:
   // is owned by our current style rule.
   virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate);
   virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
                                             nsIURI** aBaseURI,
                                             nsIPrincipal** aSheetPrincipal,
                                             mozilla::css::Loader** aCSSLoader);
   NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
 
-  virtual nsINode *GetParentObject()
-  {
-    return mContent;
-  }
+  virtual nsINode* GetParentObject();
 
 protected:
   virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl);
   virtual nsIDocument* DocToUpdate();
 
-  // XXX bug 585014 use nsRefPtr<Element> and fix mContent->AsElement()
-  nsCOMPtr<nsIContent> mContent;
+  nsRefPtr<Element> mElement;
 
 #ifdef MOZ_SMIL
   /* If true, this indicates that this nsDOMCSSAttributeDeclaration
    * should interact with mContent's SMIL override style rule (rather
    * than the inline style rule).
    */
   const PRBool mIsSMILOverride;
 #endif // MOZ_SMIL