mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
Bug 585014 - Use Element in nsDOMCSSAttributeDeclaration; r=bzbarsky approval2.0=benjamin
This commit is contained in:
parent
b99743ae55
commit
5e0a33b6d2
@ -20,6 +20,7 @@
|
||||
* 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"),
|
||||
@ -38,35 +39,33 @@
|
||||
/* 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 "nsIURI.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIURI.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()
|
||||
@ -74,7 +73,7 @@ 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
|
||||
@ -87,13 +86,13 @@ 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);
|
||||
@ -103,9 +102,9 @@ nsDOMCSSAttributeDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
|
||||
|
||||
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*
|
||||
@ -119,29 +118,29 @@ nsDOMCSSAttributeDeclaration::DocToUpdate()
|
||||
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();
|
||||
@ -159,10 +158,10 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate)
|
||||
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
|
||||
@ -182,27 +181,27 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
|
||||
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;
|
||||
}
|
||||
@ -216,3 +215,8 @@ nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* virtual */ nsINode*
|
||||
nsDOMCSSAttributeDeclaration::GetParentObject()
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
* 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"),
|
||||
@ -42,21 +43,26 @@
|
||||
|
||||
#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
|
||||
@ -76,17 +82,13 @@ public:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user