Bug 1154149 - Remove nsPresContext arguments from a bunch of nsStyleSet methods. r=dbaron

This commit is contained in:
Cameron McCormack 2015-04-17 11:09:59 +10:00
parent 9e48addb00
commit 84ff03514a
9 changed files with 60 additions and 79 deletions

View File

@ -164,7 +164,7 @@ ElementHasActiveStyle(dom::Element* aElement)
}
nsStyleSet* styleSet = pc->StyleSet();
for (dom::Element* e = aElement; e; e = e->GetParentElement()) {
if (styleSet->HasStateDependentStyle(pc, e, NS_EVENT_STATE_ACTIVE)) {
if (styleSet->HasStateDependentStyle(e, NS_EVENT_STATE_ACTIVE)) {
AEM_LOG("Element %p's style is dependent on the active state\n", e);
return true;
}

View File

@ -1092,16 +1092,14 @@ RestyleManager::ContentStateChanged(nsIContent* aContent,
nsRestyleHint rshint;
if (pseudoType >= nsCSSPseudoElements::ePseudo_PseudoElementCount) {
rshint = styleSet->HasStateDependentStyle(mPresContext, aElement,
aStateMask);
rshint = styleSet->HasStateDependentStyle(aElement, aStateMask);
} else if (nsCSSPseudoElements::PseudoElementSupportsUserActionState(
pseudoType)) {
// If aElement is a pseudo-element, we want to check to see whether there
// are any state-dependent rules applying to that pseudo.
Element* ancestor = ElementForStyleContext(nullptr, primaryFrame,
pseudoType);
rshint = styleSet->HasStateDependentStyle(mPresContext, ancestor,
pseudoType, aElement,
rshint = styleSet->HasStateDependentStyle(ancestor, pseudoType, aElement,
aStateMask);
} else {
rshint = nsRestyleHint(0);
@ -1130,8 +1128,7 @@ RestyleManager::AttributeWillChange(Element* aElement,
int32_t aModType)
{
nsRestyleHint rshint =
mPresContext->StyleSet()->HasAttributeDependentStyle(mPresContext,
aElement,
mPresContext->StyleSet()->HasAttributeDependentStyle(aElement,
aAttribute,
aModType,
false);
@ -1218,8 +1215,7 @@ RestyleManager::AttributeChanged(Element* aElement,
// See if we can optimize away the style re-resolution -- must be called after
// the frame's AttributeChanged() in case it does something that affects the style
nsRestyleHint rshint =
mPresContext->StyleSet()->HasAttributeDependentStyle(mPresContext,
aElement,
mPresContext->StyleSet()->HasAttributeDependentStyle(aElement,
aAttribute,
aModType,
true);

View File

@ -1881,7 +1881,7 @@ nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
mPendingMediaFeatureValuesChanged = false;
// MediumFeaturesChanged updates the applied rules, so it always gets called.
if (mShell && mShell->StyleSet()->MediumFeaturesChanged(this)) {
if (mShell && mShell->StyleSet()->MediumFeaturesChanged()) {
aRestyleHint |= eRestyle_Subtree;
}
@ -2095,7 +2095,7 @@ nsPresContext::FlushUserFontSet()
if (mFontFaceSetDirty) {
if (gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) {
nsTArray<nsFontFaceRuleContainer> rules;
if (!mShell->StyleSet()->AppendFontFaceRules(this, rules)) {
if (!mShell->StyleSet()->AppendFontFaceRules(rules)) {
return;
}

View File

@ -1204,7 +1204,7 @@ PresShell::Destroy()
mViewManager = nullptr;
}
mStyleSet->BeginShutdown(mPresContext);
mStyleSet->BeginShutdown();
nsRefreshDriver* rd = GetPresContext()->RefreshDriver();
// This shell must be removed from the document before the frame
@ -1262,7 +1262,7 @@ PresShell::Destroy()
}
// Let the style set do its cleanup.
mStyleSet->Shutdown(mPresContext);
mStyleSet->Shutdown();
if (mPresContext) {
// We hold a reference to the pres context, and it holds a weak link back
@ -4399,8 +4399,7 @@ PresShell::DocumentStatesChanged(nsIDocument* aDocument,
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
if (mDidInitialize &&
mStyleSet->HasDocumentStateDependentStyle(mPresContext,
mDocument->GetRootElement(),
mStyleSet->HasDocumentStateDependentStyle(mDocument->GetRootElement(),
aStateMask)) {
mPresContext->RestyleManager()->PostRestyleEvent(mDocument->GetRootElement(),
eRestyle_Subtree,

View File

@ -2021,7 +2021,7 @@ CounterStyleManager::BuildCounterStyle(const nsSubstring& aName)
// It is intentional that the predefined names are case-insensitive
// but the user-defined names case-sensitive.
nsCSSCounterStyleRule* rule =
mPresContext->StyleSet()->CounterStyleRuleForName(mPresContext, aName);
mPresContext->StyleSet()->CounterStyleRuleForName(aName);
if (rule) {
data = new (mPresContext) CustomCounterStyle(this, rule);
} else {
@ -2074,7 +2074,7 @@ InvalidateOldStyle(const nsSubstring& aKey,
bool toBeUpdated = false;
bool toBeRemoved = false;
nsCSSCounterStyleRule* newRule = data->mPresContext->
StyleSet()->CounterStyleRuleForName(data->mPresContext, aKey);
StyleSet()->CounterStyleRuleForName(aKey);
if (!newRule) {
if (aStyle->IsCustomStyle()) {
toBeRemoved = true;

View File

@ -511,8 +511,7 @@ nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
nsCSSKeyframesRule* rule =
src.GetName().IsEmpty()
? nullptr
: mPresContext->StyleSet()->KeyframesRuleForName(mPresContext,
src.GetName());
: mPresContext->StyleSet()->KeyframesRuleForName(src.GetName());
if (!rule) {
continue;
}

View File

@ -153,7 +153,7 @@ nsStyleContext::~nsStyleContext()
mRuleNode->Release();
styleSet->NotifyStyleContextDestroyed(presContext, this);
styleSet->NotifyStyleContextDestroyed(this);
if (mParent) {
mParent->RemoveChild(this);

View File

@ -1855,8 +1855,7 @@ nsStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
// Add any @page rules that are specified.
nsTArray<nsCSSPageRule*> rules;
nsTArray<css::ImportantRule*> importantRules;
nsPresContext* presContext = PresContext();
presContext->StyleSet()->AppendPageRules(presContext, rules);
PresContext()->StyleSet()->AppendPageRules(rules);
for (uint32_t i = 0, i_end = rules.Length(); i != i_end; ++i) {
ruleWalker.Forward(rules[i]);
css::ImportantRule* importantRule = rules[i]->GetImportantRule();
@ -1916,30 +1915,30 @@ nsStyleSet::ResolveXULTreePseudoStyle(Element* aParentElement,
#endif
bool
nsStyleSet::AppendFontFaceRules(nsPresContext* aPresContext,
nsTArray<nsFontFaceRuleContainer>& aArray)
nsStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
{
NS_ENSURE_FALSE(mInShutdown, false);
NS_ASSERTION(mBatching == 0, "rule processors out of date");
nsPresContext* presContext = PresContext();
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
if (gCSSSheetTypes[i] == eScopedDocSheet)
continue;
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
(mRuleProcessors[gCSSSheetTypes[i]].get());
if (ruleProc && !ruleProc->AppendFontFaceRules(aPresContext, aArray))
if (ruleProc && !ruleProc->AppendFontFaceRules(presContext, aArray))
return false;
}
return true;
}
nsCSSKeyframesRule*
nsStyleSet::KeyframesRuleForName(nsPresContext* aPresContext,
const nsString& aName)
nsStyleSet::KeyframesRuleForName(const nsString& aName)
{
NS_ENSURE_FALSE(mInShutdown, nullptr);
NS_ASSERTION(mBatching == 0, "rule processors out of date");
nsPresContext* presContext = PresContext();
for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
if (gCSSSheetTypes[i] == eScopedDocSheet)
continue;
@ -1948,7 +1947,7 @@ nsStyleSet::KeyframesRuleForName(nsPresContext* aPresContext,
if (!ruleProc)
continue;
nsCSSKeyframesRule* result =
ruleProc->KeyframesRuleForName(aPresContext, aName);
ruleProc->KeyframesRuleForName(presContext, aName);
if (result)
return result;
}
@ -1956,12 +1955,12 @@ nsStyleSet::KeyframesRuleForName(nsPresContext* aPresContext,
}
nsCSSCounterStyleRule*
nsStyleSet::CounterStyleRuleForName(nsPresContext* aPresContext,
const nsAString& aName)
nsStyleSet::CounterStyleRuleForName(const nsAString& aName)
{
NS_ENSURE_FALSE(mInShutdown, nullptr);
NS_ASSERTION(mBatching == 0, "rule processors out of date");
nsPresContext* presContext = PresContext();
for (uint32_t i = ArrayLength(gCSSSheetTypes); i-- != 0; ) {
if (gCSSSheetTypes[i] == eScopedDocSheet)
continue;
@ -1970,7 +1969,7 @@ nsStyleSet::CounterStyleRuleForName(nsPresContext* aPresContext,
if (!ruleProc)
continue;
nsCSSCounterStyleRule *result =
ruleProc->CounterStyleRuleForName(aPresContext, aName);
ruleProc->CounterStyleRuleForName(presContext, aName);
if (result)
return result;
}
@ -1978,17 +1977,18 @@ nsStyleSet::CounterStyleRuleForName(nsPresContext* aPresContext,
}
bool
nsStyleSet::AppendFontFeatureValuesRules(nsPresContext* aPresContext,
nsStyleSet::AppendFontFeatureValuesRules(
nsTArray<nsCSSFontFeatureValuesRule*>& aArray)
{
NS_ENSURE_FALSE(mInShutdown, false);
NS_ASSERTION(mBatching == 0, "rule processors out of date");
nsPresContext* presContext = PresContext();
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
nsCSSRuleProcessor *ruleProc = static_cast<nsCSSRuleProcessor*>
(mRuleProcessors[gCSSSheetTypes[i]].get());
if (ruleProc &&
!ruleProc->AppendFontFeatureValuesRules(aPresContext, aArray))
!ruleProc->AppendFontFeatureValuesRules(presContext, aArray))
{
return false;
}
@ -2003,7 +2003,7 @@ nsStyleSet::GetFontFeatureValuesLookup()
mInitFontFeatureValuesLookup = false;
nsTArray<nsCSSFontFeatureValuesRule*> rules;
AppendFontFeatureValuesRules(PresContext(), rules);
AppendFontFeatureValuesRules(rules);
mFontFeatureValuesLookup = new gfxFontFeatureValueSet();
@ -2031,32 +2031,32 @@ nsStyleSet::GetFontFeatureValuesLookup()
}
bool
nsStyleSet::AppendPageRules(nsPresContext* aPresContext,
nsTArray<nsCSSPageRule*>& aArray)
nsStyleSet::AppendPageRules(nsTArray<nsCSSPageRule*>& aArray)
{
NS_ENSURE_FALSE(mInShutdown, false);
NS_ASSERTION(mBatching == 0, "rule processors out of date");
nsPresContext* presContext = PresContext();
for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) {
if (gCSSSheetTypes[i] == eScopedDocSheet)
continue;
nsCSSRuleProcessor* ruleProc = static_cast<nsCSSRuleProcessor*>
(mRuleProcessors[gCSSSheetTypes[i]].get());
if (ruleProc && !ruleProc->AppendPageRules(aPresContext, aArray))
if (ruleProc && !ruleProc->AppendPageRules(presContext, aArray))
return false;
}
return true;
}
void
nsStyleSet::BeginShutdown(nsPresContext* aPresContext)
nsStyleSet::BeginShutdown()
{
mInShutdown = 1;
mRoots.Clear(); // no longer valid, since we won't keep it up to date
}
void
nsStyleSet::Shutdown(nsPresContext* aPresContext)
nsStyleSet::Shutdown()
{
mRuleTree->Destroy();
mRuleTree = nullptr;
@ -2074,8 +2074,7 @@ nsStyleSet::Shutdown(nsPresContext* aPresContext)
static const uint32_t kGCInterval = 300;
void
nsStyleSet::NotifyStyleContextDestroyed(nsPresContext* aPresContext,
nsStyleContext* aStyleContext)
nsStyleSet::NotifyStyleContextDestroyed(nsStyleContext* aStyleContext)
{
if (mInShutdown)
return;
@ -2223,8 +2222,7 @@ static bool SheetHasDocumentStateStyle(nsIStyleRuleProcessor* aProcessor,
// Test if style is dependent on a document state.
bool
nsStyleSet::HasDocumentStateDependentStyle(nsPresContext* aPresContext,
nsIContent* aContent,
nsStyleSet::HasDocumentStateDependentStyle(nsIContent* aContent,
EventStates aStateMask)
{
if (!aContent || !aContent->IsElement())
@ -2233,7 +2231,7 @@ nsStyleSet::HasDocumentStateDependentStyle(nsPresContext* aPresContext,
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
aContent->OwnerDoc());
InitStyleScopes(treeContext, aContent->AsElement());
StatefulData data(aPresContext, aContent->AsElement(), aStateMask,
StatefulData data(PresContext(), aContent->AsElement(), aStateMask,
treeContext);
WalkRuleProcessors(SheetHasDocumentStateStyle, &data, true);
return data.mHint != 0;
@ -2259,21 +2257,19 @@ static bool SheetHasStatefulPseudoElementStyle(nsIStyleRuleProcessor* aProcessor
// Test if style is dependent on content state
nsRestyleHint
nsStyleSet::HasStateDependentStyle(nsPresContext* aPresContext,
Element* aElement,
nsStyleSet::HasStateDependentStyle(Element* aElement,
EventStates aStateMask)
{
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
aElement->OwnerDoc());
InitStyleScopes(treeContext, aElement);
StatefulData data(aPresContext, aElement, aStateMask, treeContext);
StatefulData data(PresContext(), aElement, aStateMask, treeContext);
WalkRuleProcessors(SheetHasStatefulStyle, &data, false);
return data.mHint;
}
nsRestyleHint
nsStyleSet::HasStateDependentStyle(nsPresContext* aPresContext,
Element* aElement,
nsStyleSet::HasStateDependentStyle(Element* aElement,
nsCSSPseudoElements::Type aPseudoType,
Element* aPseudoElement,
EventStates aStateMask)
@ -2281,7 +2277,7 @@ nsStyleSet::HasStateDependentStyle(nsPresContext* aPresContext,
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
aElement->OwnerDoc());
InitStyleScopes(treeContext, aElement);
StatefulPseudoElementData data(aPresContext, aElement, aStateMask,
StatefulPseudoElementData data(PresContext(), aElement, aStateMask,
aPseudoType, treeContext, aPseudoElement);
WalkRuleProcessors(SheetHasStatefulPseudoElementStyle, &data, false);
return data.mHint;
@ -2309,8 +2305,7 @@ SheetHasAttributeStyle(nsIStyleRuleProcessor* aProcessor, void *aData)
// Test if style is dependent on content state
nsRestyleHint
nsStyleSet::HasAttributeDependentStyle(nsPresContext* aPresContext,
Element* aElement,
nsStyleSet::HasAttributeDependentStyle(Element* aElement,
nsIAtom* aAttribute,
int32_t aModType,
bool aAttrHasChanged)
@ -2318,36 +2313,37 @@ nsStyleSet::HasAttributeDependentStyle(nsPresContext* aPresContext,
TreeMatchContext treeContext(false, nsRuleWalker::eLinksVisitedOrUnvisited,
aElement->OwnerDoc());
InitStyleScopes(treeContext, aElement);
AttributeData data(aPresContext, aElement, aAttribute,
AttributeData data(PresContext(), aElement, aAttribute,
aModType, aAttrHasChanged, treeContext);
WalkRuleProcessors(SheetHasAttributeStyle, &data, false);
return data.mHint;
}
bool
nsStyleSet::MediumFeaturesChanged(nsPresContext* aPresContext)
nsStyleSet::MediumFeaturesChanged()
{
NS_ASSERTION(mBatching == 0, "rule processors out of date");
// We can't use WalkRuleProcessors without a content node.
nsPresContext* presContext = PresContext();
bool stylesChanged = false;
for (uint32_t i = 0; i < ArrayLength(mRuleProcessors); ++i) {
nsIStyleRuleProcessor *processor = mRuleProcessors[i];
if (!processor) {
continue;
}
bool thisChanged = processor->MediumFeaturesChanged(aPresContext);
bool thisChanged = processor->MediumFeaturesChanged(presContext);
stylesChanged = stylesChanged || thisChanged;
}
for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); ++i) {
nsIStyleRuleProcessor *processor = mScopedDocSheetRuleProcessors[i];
bool thisChanged = processor->MediumFeaturesChanged(aPresContext);
bool thisChanged = processor->MediumFeaturesChanged(presContext);
stylesChanged = stylesChanged || thisChanged;
}
if (mBindingManager) {
bool thisChanged = false;
mBindingManager->MediumFeaturesChanged(aPresContext, &thisChanged);
mBindingManager->MediumFeaturesChanged(presContext, &thisChanged);
stylesChanged = stylesChanged || thisChanged;
}

View File

@ -209,40 +209,35 @@ class nsStyleSet
// Append all the currently-active font face rules to aArray. Return
// true for success and false for failure.
bool AppendFontFaceRules(nsPresContext* aPresContext,
nsTArray<nsFontFaceRuleContainer>& aArray);
bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
// Return the winning (in the cascade) @keyframes rule for the given name.
nsCSSKeyframesRule* KeyframesRuleForName(nsPresContext* aPresContext,
const nsString& aName);
nsCSSKeyframesRule* KeyframesRuleForName(const nsString& aName);
// Return the winning (in the cascade) @counter-style rule for the given name.
nsCSSCounterStyleRule* CounterStyleRuleForName(nsPresContext* aPresContext,
const nsAString& aName);
nsCSSCounterStyleRule* CounterStyleRuleForName(const nsAString& aName);
// Fetch object for looking up font feature values
already_AddRefed<gfxFontFeatureValueSet> GetFontFeatureValuesLookup();
// Append all the currently-active font feature values rules to aArray.
// Return true for success and false for failure.
bool AppendFontFeatureValuesRules(nsPresContext* aPresContext,
bool AppendFontFeatureValuesRules(
nsTArray<nsCSSFontFeatureValuesRule*>& aArray);
// Append all the currently-active page rules to aArray. Return
// true for success and false for failure.
bool AppendPageRules(nsPresContext* aPresContext,
nsTArray<nsCSSPageRule*>& aArray);
bool AppendPageRules(nsTArray<nsCSSPageRule*>& aArray);
// Begin ignoring style context destruction, to avoid lots of unnecessary
// work on document teardown.
void BeginShutdown(nsPresContext* aPresContext);
void BeginShutdown();
// Free all of the data associated with this style set.
void Shutdown(nsPresContext* aPresContext);
void Shutdown();
// Notification that a style context is being destroyed.
void NotifyStyleContextDestroyed(nsPresContext* aPresContext,
nsStyleContext* aStyleContext);
void NotifyStyleContextDestroyed(nsStyleContext* aStyleContext);
// Get a new style context that lives in a different parent
// The new context will be the same as the old if the new parent is the
@ -256,23 +251,19 @@ class nsStyleSet
mozilla::dom::Element* aElement);
// Test if style is dependent on a document state.
bool HasDocumentStateDependentStyle(nsPresContext* aPresContext,
nsIContent* aContent,
bool HasDocumentStateDependentStyle(nsIContent* aContent,
mozilla::EventStates aStateMask);
// Test if style is dependent on content state
nsRestyleHint HasStateDependentStyle(nsPresContext* aPresContext,
mozilla::dom::Element* aElement,
nsRestyleHint HasStateDependentStyle(mozilla::dom::Element* aElement,
mozilla::EventStates aStateMask);
nsRestyleHint HasStateDependentStyle(nsPresContext* aPresContext,
mozilla::dom::Element* aElement,
nsRestyleHint HasStateDependentStyle(mozilla::dom::Element* aElement,
nsCSSPseudoElements::Type aPseudoType,
mozilla::dom::Element* aPseudoElement,
mozilla::EventStates aStateMask);
// Test if style is dependent on the presence of an attribute.
nsRestyleHint HasAttributeDependentStyle(nsPresContext* aPresContext,
mozilla::dom::Element* aElement,
nsRestyleHint HasAttributeDependentStyle(mozilla::dom::Element* aElement,
nsIAtom* aAttribute,
int32_t aModType,
bool aAttrHasChanged);
@ -282,7 +273,7 @@ class nsStyleSet
* the characteristics of the medium, and return whether style rules
* may have changed as a result.
*/
bool MediumFeaturesChanged(nsPresContext* aPresContext);
bool MediumFeaturesChanged();
// APIs for registering objects that can supply additional
// rules during processing.