Bug 1292432 part 8 - Move XPCOM IDL methods which just call WebIDL methods to StyleSheet. r?heycam
MozReview-Commit-ID: 3xpdLGc6hqH
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -1623,89 +1623,42 @@ CSSStyleSheet::RegisterNamespaceRule(css
nsresult rv = mInner->CreateNamespaceMap();
NS_ENSURE_SUCCESS(rv, rv);
}
AddNamespaceRuleToMap(aRule, mInner->mNameSpaceMap);
return NS_OK;
}
- // nsIDOMStyleSheet interface
-
-NS_IMETHODIMP
-CSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
-{
- NS_ENSURE_ARG_POINTER(aParentStyleSheet);
-
- NS_IF_ADDREF(*aParentStyleSheet = mParent);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-CSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
-{
- NS_ADDREF(*aMedia = Media());
- return NS_OK;
-}
-
nsMediaList*
CSSStyleSheet::Media()
{
if (!mMedia) {
mMedia = new nsMediaList();
mMedia->SetStyleSheet(this);
}
return mMedia;
}
-NS_IMETHODIMP
-CSSStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
-{
- NS_IF_ADDREF(*aOwnerRule = GetOwnerRule());
- return NS_OK;
-}
-
nsIDOMCSSRule*
CSSStyleSheet::GetDOMOwnerRule() const
{
return mOwnerRule ? mOwnerRule->GetDOMRule() : nullptr;
}
-NS_IMETHODIMP
-CSSStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
-{
- ErrorResult rv;
- nsCOMPtr<nsIDOMCSSRuleList> rules =
- GetCssRules(Some(nsContentUtils::SubjectPrincipal()), rv);
- rules.forget(aCssRules);
- return rv.StealNSResult();
-}
-
CSSRuleList*
CSSStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
{
if (!mRuleCollection) {
mRuleCollection = new CSSRuleListImpl(this);
}
return mRuleCollection;
}
-NS_IMETHODIMP
-CSSStyleSheet::InsertRule(const nsAString& aRule,
- uint32_t aIndex,
- uint32_t* aReturn)
-{
- ErrorResult rv;
- *aReturn =
- InsertRule(aRule, aIndex, Some(nsContentUtils::SubjectPrincipal()), rv);
- return rv.StealNSResult();
-}
-
static bool
RuleHasPendingChildSheet(css::Rule *cssRule)
{
nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(cssRule));
NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!");
nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
importRule->GetStyleSheet(getter_AddRefs(childSheet));
RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(childSheet);
@@ -1827,24 +1780,16 @@ CSSStyleSheet::InsertRuleInternal(const
if ((type != css::Rule::IMPORT_RULE || !RuleHasPendingChildSheet(rule)) &&
mDocument) {
mDocument->StyleRuleAdded(this, rule);
}
return aIndex;
}
-NS_IMETHODIMP
-CSSStyleSheet::DeleteRule(uint32_t aIndex)
-{
- ErrorResult rv;
- DeleteRule(aIndex, Some(nsContentUtils::SubjectPrincipal()), rv);
- return rv.StealNSResult();
-}
-
void
CSSStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv)
{
// XXX TBI: handle @rule types
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
WillDirty();
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -157,16 +157,18 @@ public:
nsresult DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t aIndex);
nsresult InsertRuleIntoGroup(const nsAString& aRule, css::GroupRule* aGroup, uint32_t aIndex, uint32_t* _retval);
void SetTitle(const nsAString& aTitle) { mTitle = aTitle; }
void SetMedia(nsMediaList* aMedia);
void SetOwnerRule(css::ImportRule* aOwnerRule) { mOwnerRule = aOwnerRule; /* Not ref counted */ }
css::ImportRule* GetOwnerRule() const { return mOwnerRule; }
+ // Workaround overloaded-virtual warning in GCC.
+ using StyleSheet::GetOwnerRule;
nsXMLNameSpaceMap* GetNameSpaceMap() const { return mInner->mNameSpaceMap; }
already_AddRefed<CSSStyleSheet> Clone(CSSStyleSheet* aCloneParent,
css::ImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const;
@@ -195,47 +197,36 @@ public:
bool UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey) const;
nsresult ReparseSheet(const nsAString& aInput);
void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
- // nsIDOMStyleSheet interface
- NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
- NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
-
- // nsIDOMCSSStyleSheet interface
- NS_DECL_NSIDOMCSSSTYLESHEET
-
// Function used as a callback to rebuild our inner's child sheet
// list after we clone a unique inner for ourselves.
static bool RebuildChildList(css::Rule* aRule, void* aBuilder);
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
dom::Element* GetScopeElement() const { return mScopeElement; }
void SetScopeElement(dom::Element* aScopeElement)
{
mScopeElement = aScopeElement;
}
// WebIDL StyleSheet API
- using GetParentStyleSheet;
nsMediaList* Media() final;
// WebIDL CSSStyleSheet API
// Can't be inline because we can't include ImportRule here. And can't be
// called GetOwnerRule because that would be ambiguous with the ImportRule
// version.
nsIDOMCSSRule* GetDOMOwnerRule() const final;
- using StyleSheet::GetCssRules;
- using StyleSheet::InsertRule;
- using StyleSheet::DeleteRule;
// WebIDL miscellaneous bits
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
void WillDirty();
void DidDirty();
private:
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -107,55 +107,26 @@ ServoStyleSheet::SizeOfIncludingThis(Mal
#ifdef DEBUG
void
ServoStyleSheet::List(FILE* aOut, int32_t aIndex) const
{
MOZ_CRASH("stylo: not implemented");
}
#endif
-// nsIDOMStyleSheet implementation
-
-NS_IMETHODIMP
-ServoStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
+nsMediaList*
+ServoStyleSheet::Media()
{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-ServoStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
+ return nullptr;
}
-// nsIDOMCSSStyleSheet implementation
-
-nsresult
-ServoStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-nsresult
-ServoStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
+nsIDOMCSSRule*
+ServoStyleSheet::GetDOMOwnerRule() const
{
- 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;
+ return nullptr;
}
CSSRuleList*
ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
{
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
return nullptr;
}
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -46,22 +46,24 @@ public:
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
#ifdef DEBUG
void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
#endif
RawServoStyleSheet* RawSheet() const { return mSheet; }
- // nsIDOMStyleSheet interface
- NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
- NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
+ // WebIDL StyleSheet API
+ nsMediaList* Media() final;
- // nsIDOMCSSStyleSheet interface
- NS_DECL_NSIDOMCSSSTYLESHEET
+ // WebIDL CSSStyleSheet API
+ // Can't be inline because we can't include ImportRule here. And can't be
+ // called GetOwnerRule because that would be ambiguous with the ImportRule
+ // version.
+ nsIDOMCSSRule* GetDOMOwnerRule() const final;
void WillDirty() {}
void DidDirty() {}
protected:
~ServoStyleSheet();
// Internal methods which do not have security check and completeness check.
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -6,16 +6,18 @@
#include "mozilla/StyleSheet.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/ServoStyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/CSSStyleSheet.h"
+#include "mozilla/dom/CSSRuleList.h"
+
namespace mozilla {
StyleSheet::StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode)
: mDocument(nullptr)
, mOwningNode(nullptr)
, mParsingMode(aParsingMode)
, mType(aType)
, mDisabled(false)
@@ -130,16 +132,68 @@ StyleSheet::GetHref(nsAString& aHref)
NS_IMETHODIMP
StyleSheet::GetTitle(nsAString& aTitle)
{
aTitle.Assign(mTitle);
return NS_OK;
}
+// nsIDOMStyleSheet interface
+
+NS_IMETHODIMP
+StyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
+{
+ NS_ENSURE_ARG_POINTER(aParentStyleSheet);
+ NS_IF_ADDREF(*aParentStyleSheet = GetParentStyleSheet());
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+StyleSheet::GetMedia(nsIDOMMediaList** aMedia)
+{
+ NS_ADDREF(*aMedia = Media());
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+StyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
+{
+ NS_IF_ADDREF(*aOwnerRule = GetDOMOwnerRule());
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+StyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
+{
+ ErrorResult rv;
+ nsCOMPtr<nsIDOMCSSRuleList> rules =
+ GetCssRules(Some(nsContentUtils::SubjectPrincipal()), rv);
+ rules.forget(aCssRules);
+ return rv.StealNSResult();
+}
+
+NS_IMETHODIMP
+StyleSheet::InsertRule(const nsAString& aRule, uint32_t aIndex,
+ uint32_t* aReturn)
+{
+ ErrorResult rv;
+ *aReturn =
+ InsertRule(aRule, aIndex, Some(nsContentUtils::SubjectPrincipal()), rv);
+ return rv.StealNSResult();
+}
+
+NS_IMETHODIMP
+StyleSheet::DeleteRule(uint32_t aIndex)
+{
+ ErrorResult rv;
+ DeleteRule(aIndex, Some(nsContentUtils::SubjectPrincipal()), rv);
+ return rv.StealNSResult();
+}
+
// WebIDL CSSStyleSheet API
#define FORWARD_INTERNAL(method_, args_) \
if (IsServo()) { \
return AsServo()->method_ args_; \
} \
return AsGecko()->method_ args_;
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -157,18 +157,27 @@ public:
// WebIDL miscellaneous bits
inline dom::ParentObject GetParentObject() const;
// 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 GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
NS_IMETHOD GetHref(nsAString& aHref) final;
NS_IMETHOD GetTitle(nsAString& aTitle) final;
+ NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
+
+ // nsIDOMCSSStyleSheet
+ NS_IMETHOD GetOwnerRule(nsIDOMCSSRule** aOwnerRule) final;
+ NS_IMETHOD GetCssRules(nsIDOMCSSRuleList** aCssRules) final;
+ NS_IMETHOD InsertRule(const nsAString& aRule, uint32_t aIndex,
+ uint32_t* aReturn) final;
+ NS_IMETHOD DeleteRule(uint32_t aIndex) final;
// Changes to sheets should be inside of a WillDirty-DidDirty pair.
// However, the calls do not need to be matched; it's ok to call
// WillDirty and then make no change and skip the DidDirty call.
inline void WillDirty();
inline void DidDirty();
private: