Bug 1352763 part 3 - Have ServoStyleSheet also implement nsICSSLoaderObserver. r=heycam

MozReview-Commit-ID: 1Z6jAmQ9CY6

--HG--
extra : rebase_source : 1e228d29b6cd6afdc1b47dd28e5a4ff9a79d5af7
This commit is contained in:
Xidorn Quan 2017-04-03 19:55:06 +10:00
Родитель e0f34c4221
Коммит b49153b29e
10 изменённых файлов: 51 добавлений и 13 удалений

Просмотреть файл

@ -31,7 +31,6 @@
#include "nsError.h"
#include "nsCSSParser.h"
#include "mozilla/css/Loader.h"
#include "nsICSSLoaderObserver.h"
#include "nsNameSpaceManager.h"
#include "nsXMLNameSpaceMap.h"
#include "nsCOMPtr.h"
@ -442,8 +441,7 @@ CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb)
// QueryInterface implementation for CSSStyleSheet
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CSSStyleSheet)
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, StyleSheet)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSStyleSheet)
if (aIID.Equals(NS_GET_IID(CSSStyleSheet)))
foundInterface = reinterpret_cast<nsISupports*>(this);
else

Просмотреть файл

@ -19,7 +19,6 @@
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsICSSLoaderObserver.h"
#include "nsTArrayForwardDeclare.h"
#include "nsString.h"
#include "mozilla/CORSMode.h"
@ -87,7 +86,6 @@ struct CSSStyleSheetInner : public StyleSheetInfo
class CSSStyleSheet final : public StyleSheet
, public nsICSSLoaderObserver
{
public:
typedef net::ReferrerPolicy ReferrerPolicy;

Просмотреть файл

@ -2269,10 +2269,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet,
LOG((" No parent load; must be CSSOM"));
// No parent load data, so the sheet will need to be notified when
// we finish, if it can be, if we do the load asynchronously.
// XXXheycam ServoStyleSheet doesn't implement nsICSSLoaderObserver yet.
MOZ_ASSERT(aParentSheet->IsGecko(),
"stylo: ServoStyleSheets don't support child sheet loading yet");
observer = aParentSheet->AsGecko();
observer = aParentSheet;
}
// Now that we know it's safe to load this (passes security check and not a

Просмотреть файл

@ -185,6 +185,16 @@ ServoCSSRuleList::DeleteRule(uint32_t aIndex)
return rv;
}
uint16_t
ServoCSSRuleList::GetRuleType(uint32_t aIndex) const
{
uintptr_t rule = mRules[aIndex];
if (rule <= kMaxRuleType) {
return rule;
}
return CastToPtr(rule)->Type();
}
ServoCSSRuleList::~ServoCSSRuleList()
{
DropAllRules();

Просмотреть файл

@ -42,6 +42,8 @@ public:
nsresult InsertRule(const nsAString& aRule, uint32_t aIndex);
nsresult DeleteRule(uint32_t aIndex);
uint16_t GetRuleType(uint32_t aIndex) const;
private:
virtual ~ServoCSSRuleList();

Просмотреть файл

@ -113,6 +113,31 @@ ServoStyleSheet::LoadFailed()
Inner()->mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume();
}
// nsICSSLoaderObserver implementation
NS_IMETHODIMP
ServoStyleSheet::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
nsresult aStatus)
{
MOZ_ASSERT(aSheet->IsServo(),
"why we were called back with a CSSStyleSheet?");
ServoStyleSheet* sheet = aSheet->AsServo();
if (sheet->GetParentSheet() == nullptr) {
return NS_OK; // ignore if sheet has been detached already
}
NS_ASSERTION(this == sheet->GetParentSheet(),
"We are being notified of a sheet load for a sheet that is not our child!");
if (mDocument && NS_SUCCEEDED(aStatus)) {
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
NS_WARNING("stylo: Import rule object not implemented");
mDocument->StyleRuleAdded(this, nullptr);
}
return NS_OK;
}
void
ServoStyleSheet::DropRuleList()
{
@ -167,9 +192,9 @@ ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
if (aRv.Failed()) {
return 0;
}
// XXX If the inserted rule is an import rule, we should only notify
// the document if its associated child stylesheet has been loaded.
if (mDocument) {
// XXX When we support @import rules, we should not notify here,
// but rather when the sheet the rule is importing is loaded.
// XXX We may not want to get the rule when stylesheet change event
// is not enabled.
mDocument->StyleRuleAdded(this, mRuleList->GetRule(aIndex));

Просмотреть файл

@ -90,6 +90,10 @@ public:
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const final;
// nsICSSLoaderObserver interface
NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
nsresult aStatus) final;
protected:
virtual ~ServoStyleSheet();

Просмотреть файл

@ -118,6 +118,7 @@ StyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb)
// QueryInterface implementation for StyleSheet
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StyleSheet)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
NS_INTERFACE_MAP_END

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/CORSMode.h"
#include "mozilla/ServoUtils.h"
#include "nsICSSLoaderObserver.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsWrapperCache.h"
@ -45,6 +46,7 @@ class Rule;
* Superclass for data common to CSSStyleSheet and ServoStyleSheet.
*/
class StyleSheet : public nsIDOMCSSStyleSheet
, public nsICSSLoaderObserver
, public nsWrapperCache
{
protected:
@ -56,7 +58,8 @@ protected:
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StyleSheet)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(StyleSheet,
nsIDOMCSSStyleSheet)
void SetOwningNode(nsINode* aOwningNode)
{

Просмотреть файл

@ -89,7 +89,7 @@ StyleSheet::GetParentObject() const
if (mOwningNode) {
return dom::ParentObject(mOwningNode);
}
return dom::ParentObject(GetParentSheet());
return dom::ParentObject(static_cast<nsIDOMCSSStyleSheet*>(mParent), mParent);
}
nsIPrincipal*