зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1292432 part 2 - Make StyleSheet inherit nsIDOMCSSStyleSheet. r=heycam
Some method impls are also moved from CSSStyleSheet to StyleSheet so that they can be shared between the two subclasses. The new interface methods added to ServoStyleSheet is currently left unimplemented. They would be implemented in later patches. MozReview-Commit-ID: 45wHT9BSHTK --HG-- extra : source : f92bc0d37dbfce91334bff1ed2782489bcc8587a
This commit is contained in:
Родитель
d0964d7d45
Коммит
28a773809d
|
@ -1082,7 +1082,6 @@ CSSStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|||
CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
|
||||
CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy)
|
||||
: StyleSheet(StyleBackendType::Gecko, aParsingMode),
|
||||
mTitle(),
|
||||
mParent(nullptr),
|
||||
mOwnerRule(nullptr),
|
||||
mDirty(false),
|
||||
|
@ -1099,7 +1098,6 @@ CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
|
|||
ReferrerPolicy aReferrerPolicy,
|
||||
const SRIMetadata& aIntegrity)
|
||||
: StyleSheet(StyleBackendType::Gecko, aParsingMode),
|
||||
mTitle(),
|
||||
mParent(nullptr),
|
||||
mOwnerRule(nullptr),
|
||||
mDirty(false),
|
||||
|
@ -1117,7 +1115,6 @@ CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet& aCopy,
|
|||
nsIDocument* aDocumentToUse,
|
||||
nsINode* aOwningNodeToUse)
|
||||
: StyleSheet(aCopy, aDocumentToUse, aOwningNodeToUse),
|
||||
mTitle(aCopy.mTitle),
|
||||
mParent(aParentToUse),
|
||||
mOwnerRule(aOwnerRuleToUse),
|
||||
mDirty(aCopy.mDirty),
|
||||
|
@ -1323,12 +1320,6 @@ CSSStyleSheet::DropStyleSet(nsStyleSet* aStyleSet)
|
|||
NS_ASSERTION(found, "didn't find style set");
|
||||
}
|
||||
|
||||
void
|
||||
CSSStyleSheet::GetType(nsString& aType) const
|
||||
{
|
||||
aType.AssignLiteral("text/css");
|
||||
}
|
||||
|
||||
bool
|
||||
CSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
|
||||
nsMediaQueryResultCacheKey& aKey) const
|
||||
|
@ -1675,36 +1666,6 @@ CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule)
|
|||
}
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetType(nsAString& aType)
|
||||
{
|
||||
aType.AssignLiteral("text/css");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetDisabled(bool* aDisabled)
|
||||
{
|
||||
*aDisabled = Disabled();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::SetDisabled(bool aDisabled)
|
||||
{
|
||||
// DOM method, so handle BeginUpdate/EndUpdate
|
||||
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_STYLE, true);
|
||||
CSSStyleSheet::SetEnabled(!aDisabled);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> ownerNode = do_QueryInterface(GetOwnerNode());
|
||||
ownerNode.forget(aOwnerNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
||||
|
@ -1716,34 +1677,6 @@ CSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetHref(nsAString& aHref)
|
||||
{
|
||||
if (mInner->mOriginalSheetURI) {
|
||||
nsAutoCString str;
|
||||
nsresult rv = mInner->mOriginalSheetURI->GetSpec(str);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
CopyUTF8toUTF16(str, aHref);
|
||||
} else {
|
||||
SetDOMStringToNull(aHref);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
CSSStyleSheet::GetTitle(nsString& aTitle) const
|
||||
{
|
||||
aTitle = mTitle;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetTitle(nsAString& aTitle)
|
||||
{
|
||||
aTitle.Assign(mTitle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
|
||||
{
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsTArrayForwardDeclare.h"
|
||||
#include "nsString.h"
|
||||
|
@ -101,10 +100,9 @@ struct CSSStyleSheetInner : public StyleSheetInfo
|
|||
{ 0x98, 0x99, 0x0c, 0x86, 0xec, 0x12, 0x2f, 0x54 } }
|
||||
|
||||
|
||||
class CSSStyleSheet final : public nsIDOMCSSStyleSheet,
|
||||
public nsICSSLoaderObserver,
|
||||
public nsWrapperCache,
|
||||
public StyleSheet
|
||||
class CSSStyleSheet final : public StyleSheet
|
||||
, public nsICSSLoaderObserver
|
||||
, public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
typedef net::ReferrerPolicy ReferrerPolicy;
|
||||
|
@ -120,8 +118,6 @@ public:
|
|||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
|
||||
|
||||
void GetTitle(nsString& aTitle) const;
|
||||
void GetType(nsString& aType) const;
|
||||
bool HasRules() const;
|
||||
|
||||
/**
|
||||
|
@ -206,7 +202,8 @@ public:
|
|||
void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_DECL_NSIDOMSTYLESHEET
|
||||
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
|
||||
NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
|
||||
|
||||
// nsIDOMCSSStyleSheet interface
|
||||
NS_DECL_NSIDOMCSSSTYLESHEET
|
||||
|
@ -224,22 +221,8 @@ public:
|
|||
}
|
||||
|
||||
// WebIDL StyleSheet API
|
||||
// Our CSSStyleSheet::GetType is a const method, so it ends up
|
||||
// ambiguous with with the XPCOM version. Just disambiguate.
|
||||
void GetType(nsString& aType) {
|
||||
const_cast<const CSSStyleSheet*>(this)->GetType(aType);
|
||||
}
|
||||
// Our XPCOM GetHref is fine for WebIDL
|
||||
using StyleSheet::GetOwnerNode;
|
||||
CSSStyleSheet* GetParentStyleSheet() const { return mParent; }
|
||||
// Our CSSStyleSheet::GetTitle is a const method, so it ends up
|
||||
// ambiguous with with the XPCOM version. Just disambiguate.
|
||||
void GetTitle(nsString& aTitle) {
|
||||
const_cast<const CSSStyleSheet*>(this)->GetTitle(aTitle);
|
||||
}
|
||||
nsMediaList* Media();
|
||||
bool Disabled() const { return mDisabled; }
|
||||
// The XPCOM SetDisabled is fine for WebIDL
|
||||
|
||||
// WebIDL CSSStyleSheet API
|
||||
// Can't be inline because we can't include ImportRule here. And can't be
|
||||
|
@ -309,7 +292,6 @@ protected:
|
|||
void TraverseInner(nsCycleCollectionTraversalCallback &);
|
||||
|
||||
protected:
|
||||
nsString mTitle;
|
||||
RefPtr<nsMediaList> mMedia;
|
||||
RefPtr<CSSStyleSheet> mNext;
|
||||
CSSStyleSheet* mParent; // weak ref
|
||||
|
|
|
@ -23,6 +23,14 @@ ServoStyleSheet::~ServoStyleSheet()
|
|||
DropSheet();
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(ServoStyleSheet)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(ServoStyleSheet)
|
||||
NS_IMPL_RELEASE(ServoStyleSheet)
|
||||
|
||||
bool
|
||||
ServoStyleSheet::HasRules() const
|
||||
{
|
||||
|
@ -104,4 +112,45 @@ ServoStyleSheet::List(FILE* aOut, int32_t aIndex) const
|
|||
}
|
||||
#endif
|
||||
|
||||
// nsIDOMStyleSheet implementation
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServoStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServoStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsIDOMCSSStyleSheet implementation
|
||||
|
||||
nsresult
|
||||
ServoStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ServoStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ServoStyleSheet::InsertRule(const nsAString& rule,
|
||||
uint32_t aIndex, uint32_t* aReturn)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ServoStyleSheet::DeleteRule(uint32_t aIndex)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
net::ReferrerPolicy aReferrerPolicy,
|
||||
const dom::SRIMetadata& aIntegrity);
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(ServoStyleSheet)
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
bool HasRules() const;
|
||||
|
||||
|
@ -50,6 +50,13 @@ public:
|
|||
|
||||
RawServoStyleSheet* RawSheet() const { return mSheet; }
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
|
||||
NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
|
||||
|
||||
// nsIDOMCSSStyleSheet interface
|
||||
NS_DECL_NSIDOMCSSSTYLESHEET
|
||||
|
||||
protected:
|
||||
~ServoStyleSheet();
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ StyleSheet::StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMod
|
|||
StyleSheet::StyleSheet(const StyleSheet& aCopy,
|
||||
nsIDocument* aDocumentToUse,
|
||||
nsINode* aOwningNodeToUse)
|
||||
: mDocument(aDocumentToUse)
|
||||
: mTitle(aCopy.mTitle)
|
||||
, mDocument(aDocumentToUse)
|
||||
, mOwningNode(aOwningNodeToUse)
|
||||
, mParsingMode(aCopy.mParsingMode)
|
||||
, mType(aCopy.mType)
|
||||
|
@ -95,4 +96,62 @@ StyleSheetInfo::StyleSheetInfo(CORSMode aCORSMode,
|
|||
}
|
||||
}
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::GetType(nsAString& aType)
|
||||
{
|
||||
aType.AssignLiteral("text/css");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::GetDisabled(bool* aDisabled)
|
||||
{
|
||||
*aDisabled = Disabled();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::SetDisabled(bool aDisabled)
|
||||
{
|
||||
// DOM method, so handle BeginUpdate/EndUpdate
|
||||
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_STYLE, true);
|
||||
if (IsGecko()) {
|
||||
AsGecko()->SetEnabled(!aDisabled);
|
||||
} else {
|
||||
MOZ_CRASH("stylo: unimplemented SetEnabled");
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> ownerNode = do_QueryInterface(GetOwnerNode());
|
||||
ownerNode.forget(aOwnerNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::GetHref(nsAString& aHref)
|
||||
{
|
||||
if (nsIURI* sheetURI = SheetInfo().mOriginalSheetURI) {
|
||||
nsAutoCString str;
|
||||
nsresult rv = sheetURI->GetSpec(str);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
CopyUTF8toUTF16(str, aHref);
|
||||
} else {
|
||||
SetDOMStringToNull(aHref);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
StyleSheet::GetTitle(nsAString& aTitle)
|
||||
{
|
||||
aTitle.Assign(mTitle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/ServoUtils.h"
|
||||
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsINode;
|
||||
|
||||
|
@ -30,7 +32,7 @@ class SRIMetadata;
|
|||
/**
|
||||
* Superclass for data common to CSSStyleSheet and ServoStyleSheet.
|
||||
*/
|
||||
class StyleSheet
|
||||
class StyleSheet : public nsIDOMCSSStyleSheet
|
||||
{
|
||||
protected:
|
||||
StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode);
|
||||
|
@ -115,6 +117,22 @@ public:
|
|||
inline void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
|
||||
#endif
|
||||
|
||||
// WebIDL StyleSheet API
|
||||
// The XPCOM GetType is fine for WebIDL.
|
||||
// The XPCOM GetHref is fine for WebIDL
|
||||
// GetOwnerNode is defined above.
|
||||
// The XPCOM GetTitle is fine for WebIDL.
|
||||
bool Disabled() const { return mDisabled; }
|
||||
// The XPCOM SetDisabled is fine for WebIDL.
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHOD GetType(nsAString& aType) final;
|
||||
NS_IMETHOD GetDisabled(bool* aDisabled) final;
|
||||
NS_IMETHOD SetDisabled(bool aDisabled) final;
|
||||
NS_IMETHOD GetOwnerNode(nsIDOMNode** aOwnerNode) final;
|
||||
NS_IMETHOD GetHref(nsAString& aHref) final;
|
||||
NS_IMETHOD GetTitle(nsAString& aTitle) final;
|
||||
|
||||
private:
|
||||
// Get a handle to the various stylesheet bits which live on the 'inner' for
|
||||
// gecko stylesheets and live on the StyleSheet for Servo stylesheets.
|
||||
|
@ -122,6 +140,7 @@ private:
|
|||
inline const StyleSheetInfo& SheetInfo() const;
|
||||
|
||||
protected:
|
||||
nsString mTitle;
|
||||
nsIDocument* mDocument; // weak ref; parents maintain this for their children
|
||||
nsINode* mOwningNode; // weak ref
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче