зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1373018 - Part 7: stylo: Move nsStyleContext::mSource into subclasses; r=bholley
MozReview-Commit-ID: AspYUJ7lGqD --HG-- extra : rebase_source : 1f8d368312bd8149f32efc31130f4bf6659064ed
This commit is contained in:
Родитель
092c404741
Коммит
828745da04
|
@ -22,16 +22,16 @@ GeckoStyleContext::GeckoStyleContext(nsStyleContext* aParent,
|
|||
CSSPseudoElementType aPseudoType,
|
||||
already_AddRefed<nsRuleNode> aRuleNode,
|
||||
bool aSkipParentDisplayBasedStyleFixup)
|
||||
: nsStyleContext(aParent, OwningStyleContextSource(Move(aRuleNode)),
|
||||
aPseudoTag, aPseudoType)
|
||||
: nsStyleContext(aParent, aPseudoTag, aPseudoType)
|
||||
, mChild(nullptr)
|
||||
, mEmptyChild(nullptr)
|
||||
, mRuleNode(Move(aRuleNode))
|
||||
{
|
||||
mBits |= NS_STYLE_CONTEXT_IS_GECKO;
|
||||
|
||||
if (aParent) {
|
||||
#ifdef DEBUG
|
||||
nsRuleNode *r1 = mParent->RuleNode(), *r2 = mSource.AsGeckoRuleNode();
|
||||
nsRuleNode *r1 = mParent->RuleNode(), *r2 = mRuleNode;
|
||||
while (r1->GetParent())
|
||||
r1 = r1->GetParent();
|
||||
while (r2->GetParent())
|
||||
|
@ -42,7 +42,7 @@ GeckoStyleContext::GeckoStyleContext(nsStyleContext* aParent,
|
|||
PresContext()->PresShell()->StyleSet()->RootStyleContextAdded();
|
||||
}
|
||||
|
||||
mSource.AsGeckoRuleNode()->SetUsedDirectly(); // before ApplyStyleFixups()!
|
||||
mRuleNode->SetUsedDirectly(); // before ApplyStyleFixups()!
|
||||
// FinishConstruction() calls AddChild which needs these
|
||||
// to be initialized!
|
||||
mNextSibling = this;
|
||||
|
@ -71,7 +71,13 @@ GeckoStyleContext::AddChild(GeckoStyleContext* aChild)
|
|||
aChild->mNextSibling == aChild,
|
||||
"child already in a child list");
|
||||
|
||||
GeckoStyleContext **listPtr = aChild->mSource.MatchesNoRules() ? &mEmptyChild : &mChild;
|
||||
GeckoStyleContext **listPtr = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
||||
if (const nsRuleNode* source = aChild->mRuleNode) {
|
||||
if (source->IsRoot()) {
|
||||
listPtr = &mEmptyChild;
|
||||
}
|
||||
}
|
||||
|
||||
// Explicitly dereference listPtr so that compiler doesn't have to know that mNextSibling
|
||||
// etc. don't alias with what ever listPtr points at.
|
||||
GeckoStyleContext *list = *listPtr;
|
||||
|
@ -92,7 +98,8 @@ GeckoStyleContext::RemoveChild(GeckoStyleContext* aChild)
|
|||
{
|
||||
NS_PRECONDITION(nullptr != aChild && this == aChild->mParent, "bad argument");
|
||||
|
||||
GeckoStyleContext **list = aChild->mSource.MatchesNoRules() ? &mEmptyChild : &mChild;
|
||||
MOZ_ASSERT(aChild->mRuleNode, "child context should have rule node");
|
||||
GeckoStyleContext **list = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild;
|
||||
|
||||
if (aChild->mPrevSibling != aChild) { // has siblings
|
||||
if ((*list) == aChild) {
|
||||
|
@ -189,30 +196,30 @@ GeckoStyleContext::DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStruct
|
|||
ClearCachedInheritedStyleDataOnDescendants(aStructs);
|
||||
}
|
||||
|
||||
|
||||
already_AddRefed<GeckoStyleContext>
|
||||
GeckoStyleContext::FindChildWithRules(const nsIAtom* aPseudoTag,
|
||||
NonOwningStyleContextSource aSource,
|
||||
NonOwningStyleContextSource aSourceIfVisited,
|
||||
nsRuleNode* aSource,
|
||||
nsRuleNode* aSourceIfVisited,
|
||||
bool aRelevantLinkVisited)
|
||||
{
|
||||
uint32_t threshold = 10; // The # of siblings we're willing to examine
|
||||
// before just giving this whole thing up.
|
||||
|
||||
RefPtr<GeckoStyleContext> result;
|
||||
GeckoStyleContext *list = aSource.MatchesNoRules() ? mEmptyChild : mChild;
|
||||
MOZ_ASSERT(aSource);
|
||||
GeckoStyleContext *list = aSource->IsRoot() ? mEmptyChild : mChild;
|
||||
|
||||
if (list) {
|
||||
GeckoStyleContext *child = list;
|
||||
do {
|
||||
if (child->mSource.AsRaw() == aSource &&
|
||||
if (child->StyleSource() == aSource &&
|
||||
child->mPseudoTag == aPseudoTag &&
|
||||
!child->IsStyleIfVisited() &&
|
||||
child->RelevantLinkVisited() == aRelevantLinkVisited) {
|
||||
bool match = false;
|
||||
if (!aSourceIfVisited.IsNull()) {
|
||||
if (aSourceIfVisited) {
|
||||
match = child->GetStyleIfVisited() &&
|
||||
child->GetStyleIfVisited()->AsGecko()->mSource.AsRaw() == aSourceIfVisited;
|
||||
child->GetStyleIfVisited()->RuleNode() == aSourceIfVisited;
|
||||
} else {
|
||||
match = !child->GetStyleIfVisited();
|
||||
}
|
||||
|
@ -348,6 +355,7 @@ GeckoStyleContext::SetIneligibleForSharing()
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef RESTYLE_LOGGING
|
||||
void
|
||||
GeckoStyleContext::LogChildStyleContextTree(uint32_t aStructs) const
|
||||
{
|
||||
|
@ -366,6 +374,7 @@ GeckoStyleContext::LogChildStyleContextTree(uint32_t aStructs) const
|
|||
} while (mEmptyChild != child);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
ShouldSuppressLineBreak(const nsStyleContext* aContext,
|
||||
|
@ -511,9 +520,6 @@ GeckoStyleContext::AssertChildStructsNotUsedElsewhere(nsStyleContext* aDestroyin
|
|||
void
|
||||
GeckoStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup)
|
||||
{
|
||||
MOZ_ASSERT(!mSource.IsServoComputedValues(),
|
||||
"Can't do Gecko style fixups on Servo values");
|
||||
|
||||
#define GET_UNIQUE_STYLE_DATA(name_) \
|
||||
static_cast<nsStyle##name_*>(GetUniqueStyleData(eStyleStruct_##name_))
|
||||
|
||||
|
@ -737,9 +743,9 @@ GeckoStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup)
|
|||
if (disp->mDisplay == mozilla::StyleDisplay::Inline &&
|
||||
!nsCSSAnonBoxes::IsNonElement(mPseudoTag) &&
|
||||
mParent) {
|
||||
auto cbContext = mParent;
|
||||
auto cbContext = GetParent();
|
||||
while (cbContext->StyleDisplay()->mDisplay == mozilla::StyleDisplay::Contents) {
|
||||
cbContext = cbContext->mParent;
|
||||
cbContext = cbContext->GetParent();
|
||||
}
|
||||
MOZ_ASSERT(cbContext, "the root context can't have display:contents");
|
||||
// We don't need the full mozilla::WritingMode value (incorporating dir
|
||||
|
@ -762,4 +768,4 @@ bool
|
|||
GeckoStyleContext::HasNoChildren() const
|
||||
{
|
||||
return (nullptr == mChild) && (nullptr == mEmptyChild);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
void* operator new(size_t sz, nsPresContext* aPresContext);
|
||||
|
||||
nsPresContext* PresContext() const {
|
||||
return mSource.AsGeckoRuleNode()->PresContext();
|
||||
return RuleNode()->PresContext();
|
||||
}
|
||||
|
||||
void AddChild(GeckoStyleContext* aChild);
|
||||
|
@ -38,7 +38,6 @@ public:
|
|||
* already set, assumes that it can skip that subtree.
|
||||
*/
|
||||
void SetIneligibleForSharing();
|
||||
void LogChildStyleContextTree(uint32_t aStructs) const;
|
||||
/**
|
||||
* On each descendant of this style context, clears out any cached inherited
|
||||
* structs indicated in aStructs.
|
||||
|
@ -47,20 +46,25 @@ public:
|
|||
// Find, if it already exists *and is easily findable* (i.e., near the
|
||||
// start of the child list), a style context whose:
|
||||
// * GetPseudo() matches aPseudoTag
|
||||
// * mSource matches aSource
|
||||
// * mRuleNode matches aSource
|
||||
// * !!GetStyleIfVisited() == !!aSourceIfVisited, and, if they're
|
||||
// non-null, GetStyleIfVisited()->mSource == aSourceIfVisited
|
||||
// non-null, GetStyleIfVisited()->mRuleNode == aSourceIfVisited
|
||||
// * RelevantLinkVisited() == aRelevantLinkVisited
|
||||
already_AddRefed<GeckoStyleContext>
|
||||
FindChildWithRules(const nsIAtom* aPseudoTag,
|
||||
mozilla::NonOwningStyleContextSource aSource,
|
||||
mozilla::NonOwningStyleContextSource aSourceIfVisited,
|
||||
nsRuleNode* aSource,
|
||||
nsRuleNode* aSourceIfVisited,
|
||||
bool aRelevantLinkVisited);
|
||||
|
||||
#ifdef DEBUG
|
||||
void AssertChildStructsNotUsedElsewhere(nsStyleContext* aDestroyingContext,
|
||||
int32_t aLevels) const;
|
||||
void ListDescendants(FILE* out, int32_t aIndent);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef RESTYLE_LOGGING
|
||||
void LogChildStyleContextTree(uint32_t aStructs) const;
|
||||
#endif
|
||||
|
||||
// Only called for Gecko-backed nsStyleContexts.
|
||||
|
@ -68,6 +72,19 @@ public:
|
|||
|
||||
bool HasNoChildren() const;
|
||||
|
||||
NonOwningStyleContextSource StyleSource() const {
|
||||
return NonOwningStyleContextSource(mRuleNode);
|
||||
}
|
||||
|
||||
nsRuleNode* RuleNode() const {
|
||||
MOZ_ASSERT(mRuleNode);
|
||||
return mRuleNode;
|
||||
}
|
||||
|
||||
~GeckoStyleContext() {
|
||||
Destructor();
|
||||
}
|
||||
|
||||
private:
|
||||
// Helper for ClearCachedInheritedStyleDataOnDescendants.
|
||||
void DoClearCachedInheritedStyleDataOnDescendants(uint32_t aStructs);
|
||||
|
@ -82,6 +99,7 @@ private:
|
|||
GeckoStyleContext* mEmptyChild;
|
||||
GeckoStyleContext* mPrevSibling;
|
||||
GeckoStyleContext* mNextSibling;
|
||||
RefPtr<nsRuleNode> mRuleNode;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ ServoStyleContext::ServoStyleContext(nsStyleContext* aParent,
|
|||
nsIAtom* aPseudoTag,
|
||||
CSSPseudoElementType aPseudoType,
|
||||
already_AddRefed<ServoComputedValues> aComputedValues)
|
||||
: nsStyleContext(aParent, OwningStyleContextSource(Move(aComputedValues)),
|
||||
aPseudoTag, aPseudoType)
|
||||
: nsStyleContext(aParent, aPseudoTag, aPseudoType),
|
||||
mSource(Move(aComputedValues))
|
||||
{
|
||||
mPresContext = aPresContext;
|
||||
|
||||
|
|
|
@ -23,8 +23,18 @@ public:
|
|||
return mPresContext;
|
||||
}
|
||||
|
||||
NonOwningStyleContextSource StyleSource() const {
|
||||
return NonOwningStyleContextSource(mSource);
|
||||
}
|
||||
ServoComputedValues* ComputedValues() const {
|
||||
return mSource;
|
||||
}
|
||||
~ServoStyleContext() {
|
||||
Destructor();
|
||||
}
|
||||
private:
|
||||
nsPresContext* mPresContext;
|
||||
RefPtr<ServoComputedValues> mSource;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "nsIDocument.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "gfx2DGlue.h"
|
||||
#include "nsStyleContextInlines.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::css;
|
||||
|
|
|
@ -70,92 +70,10 @@ struct NonOwningStyleContextSource
|
|||
return reinterpret_cast<ServoComputedValues*>(mBits & ~1);
|
||||
}
|
||||
|
||||
bool MatchesNoRules() const {
|
||||
if (IsGeckoRuleNodeOrNull()) {
|
||||
return AsGeckoRuleNode()->IsRoot();
|
||||
}
|
||||
|
||||
// Just assume a Servo-backed StyleContextSource always matches some rules.
|
||||
//
|
||||
// MatchesNoRules is used to ensure style contexts that match no rules
|
||||
// go into a separate mEmptyChild list on their parent. This is only used
|
||||
// as an optimization so that calling FindChildWithRules for style context
|
||||
// sharing is faster for text nodes (which match no rules, and are common).
|
||||
// Since Servo will handle sharing for us, there's no need to split children
|
||||
// into two lists.
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
uintptr_t mBits;
|
||||
};
|
||||
|
||||
// Higher-level struct that owns a strong reference to the source. The source
|
||||
// is never null.
|
||||
struct OwningStyleContextSource
|
||||
{
|
||||
explicit OwningStyleContextSource(already_AddRefed<nsRuleNode> aRuleNode)
|
||||
: mRaw(aRuleNode.take())
|
||||
{
|
||||
MOZ_COUNT_CTOR(OwningStyleContextSource);
|
||||
MOZ_ASSERT(!mRaw.IsNull());
|
||||
};
|
||||
|
||||
explicit OwningStyleContextSource(already_AddRefed<ServoComputedValues> aComputedValues)
|
||||
: mRaw(aComputedValues.take())
|
||||
{
|
||||
MOZ_COUNT_CTOR(OwningStyleContextSource);
|
||||
MOZ_ASSERT(!mRaw.IsNull());
|
||||
}
|
||||
|
||||
OwningStyleContextSource(OwningStyleContextSource&& aOther)
|
||||
: mRaw(aOther.mRaw)
|
||||
{
|
||||
MOZ_COUNT_CTOR(OwningStyleContextSource);
|
||||
aOther.mRaw = nullptr;
|
||||
}
|
||||
|
||||
OwningStyleContextSource& operator=(OwningStyleContextSource&) = delete;
|
||||
OwningStyleContextSource(OwningStyleContextSource&) = delete;
|
||||
|
||||
~OwningStyleContextSource() {
|
||||
MOZ_COUNT_DTOR(OwningStyleContextSource);
|
||||
if (mRaw.IsNull()) {
|
||||
// We must have invoked the move constructor.
|
||||
} else if (IsGeckoRuleNode()) {
|
||||
RefPtr<nsRuleNode> releaseme = dont_AddRef(AsGeckoRuleNode());
|
||||
} else {
|
||||
MOZ_ASSERT(IsServoComputedValues());
|
||||
RefPtr<ServoComputedValues> releaseme =
|
||||
dont_AddRef(AsServoComputedValues());
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const OwningStyleContextSource& aOther) const {
|
||||
return mRaw == aOther.mRaw;
|
||||
}
|
||||
bool operator!=(const OwningStyleContextSource& aOther) const {
|
||||
return !(*this == aOther);
|
||||
}
|
||||
bool IsNull() const { return mRaw.IsNull(); }
|
||||
bool IsGeckoRuleNode() const {
|
||||
MOZ_ASSERT(!mRaw.IsNull());
|
||||
return mRaw.IsGeckoRuleNodeOrNull();
|
||||
}
|
||||
bool IsServoComputedValues() const { return mRaw.IsServoComputedValues(); }
|
||||
|
||||
NonOwningStyleContextSource AsRaw() const { return mRaw; }
|
||||
nsRuleNode* AsGeckoRuleNode() const { return mRaw.AsGeckoRuleNode(); }
|
||||
ServoComputedValues* AsServoComputedValues() const {
|
||||
return const_cast<ServoComputedValues*>(mRaw.AsServoComputedValues());
|
||||
}
|
||||
|
||||
bool MatchesNoRules() const { return mRaw.MatchesNoRules(); }
|
||||
|
||||
private:
|
||||
NonOwningStyleContextSource mRaw;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_StyleContextSource_h
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "nsWrapperCacheInlines.h"
|
||||
#include "mozilla/AppUnits.h"
|
||||
#include <algorithm>
|
||||
#include "nsStyleContextInlines.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
|
|
@ -82,12 +82,10 @@ static bool sExpensiveStyleStructAssertionsEnabled;
|
|||
#endif
|
||||
|
||||
nsStyleContext::nsStyleContext(nsStyleContext* aParent,
|
||||
OwningStyleContextSource&& aSource,
|
||||
nsIAtom* aPseudoTag,
|
||||
CSSPseudoElementType aPseudoType)
|
||||
: mParent(aParent)
|
||||
, mPseudoTag(aPseudoTag)
|
||||
, mSource(Move(aSource))
|
||||
, mCachedResetData(nullptr)
|
||||
, mBits(((uint64_t)aPseudoType) << NS_STYLE_CONTEXT_TYPE_SHIFT)
|
||||
, mRefCnt(0)
|
||||
|
@ -106,7 +104,7 @@ nsStyleContext::FinishConstruction()
|
|||
static_cast<CSSPseudoElementTypeBase>(
|
||||
CSSPseudoElementType::MAX),
|
||||
"pseudo element bits no longer fit in a uint64_t");
|
||||
MOZ_ASSERT(!mSource.IsNull());
|
||||
MOZ_ASSERT(!StyleSource().IsNull());
|
||||
|
||||
#ifdef DEBUG
|
||||
static_assert(MOZ_ARRAY_LENGTH(nsStyleContext::sDependencyTable)
|
||||
|
@ -126,15 +124,16 @@ nsStyleContext::FinishConstruction()
|
|||
#undef eStyleStruct_LastItem
|
||||
}
|
||||
|
||||
nsStyleContext::~nsStyleContext()
|
||||
void
|
||||
nsStyleContext::Destructor()
|
||||
{
|
||||
if (const GeckoStyleContext* gecko = GetAsGecko()) {
|
||||
NS_ASSERTION(gecko->HasNoChildren(), "destructing context with children");
|
||||
}
|
||||
MOZ_ASSERT(!mSource.IsServoComputedValues() || !mCachedResetData);
|
||||
MOZ_ASSERT(!IsServo() || !mCachedResetData);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (mSource.IsServoComputedValues()) {
|
||||
if (IsServo()) {
|
||||
MOZ_ASSERT(!mCachedResetData,
|
||||
"Servo shouldn't cache reset structs in nsStyleContext");
|
||||
for (const auto* data : mCachedInheritedData.mStyleStructs) {
|
||||
|
@ -163,7 +162,7 @@ nsStyleContext::~nsStyleContext()
|
|||
nsPresContext *presContext = PresContext();
|
||||
DebugOnly<nsStyleSet*> geckoStyleSet = presContext->PresShell()->StyleSet()->GetAsGecko();
|
||||
NS_ASSERTION(!geckoStyleSet ||
|
||||
geckoStyleSet->GetRuleTree() == mSource.AsGeckoRuleNode()->RuleTree() ||
|
||||
geckoStyleSet->GetRuleTree() == AsGecko()->RuleNode()->RuleTree() ||
|
||||
geckoStyleSet->IsInRuleTreeReconstruct(),
|
||||
"destroying style context from old rule tree too late");
|
||||
|
||||
|
@ -326,8 +325,8 @@ const void* nsStyleContext::StyleData(nsStyleStructID aSID)
|
|||
return cachedData; // We have computed data stored on this node in the context tree.
|
||||
// Our style source will take care of it for us.
|
||||
const void* newData;
|
||||
if (mSource.IsGeckoRuleNode()) {
|
||||
newData = mSource.AsGeckoRuleNode()->GetStyleData(aSID, this, true);
|
||||
if (IsGecko()) {
|
||||
newData = AsGecko()->RuleNode()->GetStyleData(aSID, this, true);
|
||||
if (!nsCachedStyleData::IsReset(aSID)) {
|
||||
// always cache inherited data on the style context; the rule
|
||||
// node set the bit in mBits for us if needed.
|
||||
|
@ -370,7 +369,7 @@ const void* nsStyleContext::StyleData(nsStyleStructID aSID)
|
|||
void
|
||||
nsStyleContext::SetStyle(nsStyleStructID aSID, void* aStruct)
|
||||
{
|
||||
MOZ_ASSERT(!mSource.IsServoComputedValues(),
|
||||
MOZ_ASSERT(!IsServo(),
|
||||
"Servo shouldn't cache style structs in the style context!");
|
||||
// This method should only be called from nsRuleNode! It is not a public
|
||||
// method!
|
||||
|
@ -443,7 +442,7 @@ nsStyleContext::CalcStyleDifferenceInternal(StyleContextLike* aNewContext,
|
|||
// structs, not just those that are returned from PeekStyleData, although
|
||||
// if PeekStyleData does return null we still don't want to accumulate
|
||||
// any change hints for those structs.
|
||||
bool checkUnrequestedServoStructs = mSource.IsServoComputedValues();
|
||||
bool checkUnrequestedServoStructs = IsServo();
|
||||
|
||||
#define EXPAND(...) __VA_ARGS__
|
||||
#define DO_STRUCT_DIFFERENCE_WITH_ARGS(struct_, extra_args_) \
|
||||
|
@ -455,7 +454,7 @@ nsStyleContext::CalcStyleDifferenceInternal(StyleContextLike* aNewContext,
|
|||
structsFound |= NS_STYLE_INHERIT_BIT(struct_); \
|
||||
} else if (checkUnrequestedServoStructs) { \
|
||||
this##struct_ = \
|
||||
Servo_GetStyle##struct_(mSource.AsServoComputedValues()); \
|
||||
Servo_GetStyle##struct_(AsServo()->ComputedValues()); \
|
||||
unrequestedStruct = true; \
|
||||
} else { \
|
||||
unrequestedStruct = false; \
|
||||
|
@ -708,7 +707,7 @@ nsStyleContext::EnsureSameStructsCached(nsStyleContext* aOldContext)
|
|||
#undef STYLE_STRUCT
|
||||
|
||||
#ifdef DEBUG
|
||||
if (mSource.IsServoComputedValues()) {
|
||||
if (IsServo()) {
|
||||
auto oldMask = aOldContext->mBits & NS_STYLE_INHERIT_MASK;
|
||||
auto newMask = mBits & NS_STYLE_INHERIT_MASK;
|
||||
MOZ_ASSERT((oldMask & newMask) == oldMask,
|
||||
|
@ -736,12 +735,11 @@ void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
|
|||
str.Append(' ');
|
||||
}
|
||||
|
||||
if (mSource.IsServoComputedValues()) {
|
||||
if (IsServo()) {
|
||||
fprintf_stderr(out, "%s{ServoComputedValues}\n", str.get());
|
||||
} else if (mSource.IsGeckoRuleNode()) {
|
||||
} else if (nsRuleNode* ruleNode = AsGecko()->RuleNode()) {
|
||||
fprintf_stderr(out, "%s{\n", str.get());
|
||||
str.Truncate();
|
||||
nsRuleNode* ruleNode = mSource.AsGeckoRuleNode();
|
||||
while (ruleNode) {
|
||||
nsIStyleRule *styleRule = ruleNode->GetRule();
|
||||
if (styleRule) {
|
||||
|
@ -766,6 +764,30 @@ void nsStyleContext::List(FILE* out, int32_t aIndent, bool aListDescendants)
|
|||
}
|
||||
#endif
|
||||
|
||||
NonOwningStyleContextSource
|
||||
nsStyleContext::StyleSource() const
|
||||
{
|
||||
MOZ_STYLO_FORWARD(StyleSource, ())
|
||||
}
|
||||
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * \
|
||||
nsStyleContext::Style##name_() { \
|
||||
return DoGetStyle##name_<true>(); \
|
||||
} \
|
||||
const nsStyle##name_ * \
|
||||
nsStyleContext::ThreadsafeStyle##name_() { \
|
||||
if (mozilla::ServoStyleSet::IsInServoTraversal()) { \
|
||||
return Servo_GetStyle##name_(AsServo()->ComputedValues()); \
|
||||
} \
|
||||
return Style##name_(); \
|
||||
} \
|
||||
const nsStyle##name_ * nsStyleContext::PeekStyle##name_() { \
|
||||
return DoGetStyle##name_<false>(); \
|
||||
}
|
||||
#include "nsStyleStructList.h"
|
||||
#undef STYLE_STRUCT
|
||||
|
||||
// Overridden to prevent the global delete from being called, since the memory
|
||||
// came out of an nsIArena instead of the global delete operator's heap.
|
||||
void
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
nsPresContext* PresContext() const;
|
||||
|
||||
nsStyleContext* GetParent() const {
|
||||
MOZ_ASSERT(mSource.IsGeckoRuleNode(),
|
||||
MOZ_ASSERT(IsGecko(),
|
||||
"This should be used only in Gecko-backed style system!");
|
||||
return mParent;
|
||||
}
|
||||
|
@ -279,10 +279,7 @@ public:
|
|||
return mBits & nsCachedStyleData::GetBitForSID(aSID);
|
||||
}
|
||||
|
||||
nsRuleNode* RuleNode() {
|
||||
MOZ_RELEASE_ASSERT(mSource.IsGeckoRuleNode());
|
||||
return mSource.AsGeckoRuleNode();
|
||||
}
|
||||
inline nsRuleNode* RuleNode();
|
||||
|
||||
void AddStyleBit(const uint64_t& aBit) { mBits |= aBit; }
|
||||
|
||||
|
@ -311,10 +308,8 @@ public:
|
|||
* const nsStyleBorder* StyleBorder();
|
||||
* const nsStyleColor* StyleColor();
|
||||
*/
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * Style##name_() MOZ_NONNULL_RETURN { \
|
||||
return DoGetStyle##name_<true>(); \
|
||||
}
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * Style##name_() MOZ_NONNULL_RETURN;
|
||||
#include "nsStyleStructList.h"
|
||||
#undef STYLE_STRUCT
|
||||
|
||||
|
@ -325,13 +320,8 @@ public:
|
|||
* this style struct. Use with care.
|
||||
*/
|
||||
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * ThreadsafeStyle##name_() { \
|
||||
if (mozilla::ServoStyleSet::IsInServoTraversal()) { \
|
||||
return Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
||||
} \
|
||||
return Style##name_(); \
|
||||
}
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * ThreadsafeStyle##name_();
|
||||
#include "nsStyleStructList.h"
|
||||
#undef STYLE_STRUCT
|
||||
|
||||
|
@ -343,10 +333,8 @@ public:
|
|||
*
|
||||
* Perhaps this shouldn't be a public nsStyleContext API.
|
||||
*/
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * PeekStyle##name_() { \
|
||||
return DoGetStyle##name_<false>(); \
|
||||
}
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
const nsStyle##name_ * PeekStyle##name_();
|
||||
#include "nsStyleStructList.h"
|
||||
#undef STYLE_STRUCT
|
||||
|
||||
|
@ -481,15 +469,18 @@ public:
|
|||
return cachedData;
|
||||
}
|
||||
|
||||
mozilla::NonOwningStyleContextSource StyleSource() const { return mSource.AsRaw(); }
|
||||
|
||||
public: // temporary
|
||||
// Private destructor, to discourage deletion outside of Release():
|
||||
~nsStyleContext();
|
||||
mozilla::NonOwningStyleContextSource StyleSource() const;
|
||||
|
||||
protected:
|
||||
// protected destructor to discourage deletion outside of Release()
|
||||
~nsStyleContext() {}
|
||||
// Where the actual destructor lives
|
||||
// We use this instead of a real destructor because we need
|
||||
// this to be called *before* the subclass fields are destroyed
|
||||
// by the subclass destructor
|
||||
void Destructor();
|
||||
// Delegated Helper constructor.
|
||||
nsStyleContext(nsStyleContext* aParent,
|
||||
mozilla::OwningStyleContextSource&& aSource,
|
||||
nsIAtom* aPseudoTag,
|
||||
mozilla::CSSPseudoElementType aPseudoType);
|
||||
|
||||
|
@ -506,7 +497,7 @@ public: // temporary
|
|||
switch (aSID) {
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
case eStyleStruct_##name_: \
|
||||
return Servo_GetStyle##name_(mSource.AsServoComputedValues());
|
||||
return Servo_GetStyle##name_(StyleSource().AsServoComputedValues());
|
||||
#include "nsStyleStructList.h"
|
||||
#undef STYLE_STRUCT
|
||||
default:
|
||||
|
@ -548,7 +539,7 @@ public: // temporary
|
|||
#define STYLE_STRUCT_INHERITED(name_, checkdata_cb_) \
|
||||
template<bool aComputeData> \
|
||||
const nsStyle##name_ * DoGetStyle##name_() { \
|
||||
if (mSource.IsGeckoRuleNode()) { \
|
||||
if (IsGecko()) { \
|
||||
const nsStyle##name_ * cachedData = \
|
||||
static_cast<nsStyle##name_*>( \
|
||||
mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]); \
|
||||
|
@ -562,7 +553,7 @@ public: // temporary
|
|||
/* Have the rulenode deal */ \
|
||||
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
|
||||
const nsStyle##name_ * newData = \
|
||||
mSource.AsGeckoRuleNode()-> \
|
||||
StyleSource().AsGeckoRuleNode()-> \
|
||||
GetStyle##name_<aComputeData>(this, mBits); \
|
||||
/* always cache inherited data on the style context; the rule */\
|
||||
/* node set the bit in mBits for us if needed. */ \
|
||||
|
@ -604,7 +595,7 @@ public: // temporary
|
|||
} \
|
||||
\
|
||||
const nsStyle##name_* data = \
|
||||
Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
||||
Servo_GetStyle##name_(StyleSource().AsServoComputedValues()); \
|
||||
/* perform any remaining main thread work on the struct */ \
|
||||
if (needToCompute) { \
|
||||
MOZ_ASSERT(NS_IsMainThread()); \
|
||||
|
@ -619,7 +610,7 @@ public: // temporary
|
|||
#define STYLE_STRUCT_RESET(name_, checkdata_cb_) \
|
||||
template<bool aComputeData> \
|
||||
const nsStyle##name_ * DoGetStyle##name_() { \
|
||||
if (mSource.IsGeckoRuleNode()) { \
|
||||
if (IsGecko()) { \
|
||||
if (mCachedResetData) { \
|
||||
const nsStyle##name_ * cachedData = \
|
||||
static_cast<nsStyle##name_*>( \
|
||||
|
@ -629,7 +620,7 @@ public: // temporary
|
|||
} \
|
||||
/* Have the rulenode deal */ \
|
||||
AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_); \
|
||||
return mSource.AsGeckoRuleNode()-> \
|
||||
return StyleSource().AsGeckoRuleNode()-> \
|
||||
GetStyle##name_<aComputeData>(this); \
|
||||
} \
|
||||
const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
|
||||
|
@ -637,7 +628,7 @@ public: // temporary
|
|||
return nullptr; \
|
||||
} \
|
||||
const nsStyle##name_* data = \
|
||||
Servo_GetStyle##name_(mSource.AsServoComputedValues()); \
|
||||
Servo_GetStyle##name_(StyleSource().AsServoComputedValues()); \
|
||||
/* perform any remaining main thread work on the struct */ \
|
||||
if (needToCompute) { \
|
||||
const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext()); \
|
||||
|
@ -675,11 +666,6 @@ public: // temporary
|
|||
// the relevant atom.
|
||||
nsCOMPtr<nsIAtom> mPseudoTag;
|
||||
|
||||
// The source for our style data, either a Gecko nsRuleNode or a Servo
|
||||
// ComputedValues struct. This never changes after construction, except
|
||||
// when it's released and nulled out during teardown.
|
||||
const mozilla::OwningStyleContextSource mSource;
|
||||
|
||||
// mCachedInheritedData and mCachedResetData point to both structs that
|
||||
// are owned by this style context and structs that are owned by one of
|
||||
// this style context's ancestors (which are indirectly owned since this
|
||||
|
|
|
@ -23,4 +23,12 @@ using namespace mozilla;
|
|||
|
||||
MOZ_DEFINE_STYLO_METHODS(nsStyleContext, GeckoStyleContext, ServoStyleContext);
|
||||
|
||||
nsRuleNode*
|
||||
nsStyleContext::RuleNode()
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(IsGecko());
|
||||
return AsGecko()->RuleNode();
|
||||
}
|
||||
|
||||
|
||||
#endif // nsStyleContextInlines_h
|
||||
|
|
Загрузка…
Ссылка в новой задаче