Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit e191632

Browse files
committed
Bug 1409672: Hook in the invalidator stuff. r=xidorn
MozReview-Commit-ID: EoSMrYPS7dl
1 parent 1417924 commit e191632

File tree

6 files changed

+65
-44
lines changed

6 files changed

+65
-44
lines changed

dom/xbl/nsBindingManager.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,20 +1144,3 @@ nsBindingManager::FindNestedSingleInsertionPoint(nsIContent* aContainer,
11441144

11451145
return parent;
11461146
}
1147-
1148-
bool
1149-
nsBindingManager::AnyBindingHasDocumentStateDependency(EventStates aStateMask)
1150-
{
1151-
MOZ_ASSERT(mDocument->IsStyledByServo());
1152-
1153-
bool result = false;
1154-
EnumerateBoundContentBindings([&](nsXBLBinding* aBinding) {
1155-
ServoStyleSet* styleSet = aBinding->PrototypeBinding()->GetServoStyleSet();
1156-
if (styleSet && styleSet->HasDocumentStateDependency(aStateMask)) {
1157-
result = true;
1158-
return false;
1159-
}
1160-
return true;
1161-
});
1162-
return result;
1163-
}

dom/xbl/nsBindingManager.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ class nsBindingManager final : public nsStubMutationObserver
173173

174174
nsIContent* FindNestedSingleInsertionPoint(nsIContent* aContainer, bool* aMulti);
175175

176-
bool AnyBindingHasDocumentStateDependency(mozilla::EventStates aStateMask);
176+
// Enumerate each bound content's bindings (including its base bindings)
177+
// in mBoundContentSet. Return false from the callback to stop enumeration.
178+
using BoundContentBindingCallback = std::function<bool (nsXBLBinding*)>;
179+
bool EnumerateBoundContentBindings(
180+
const BoundContentBindingCallback& aCallback) const;
177181

178182
protected:
179183
nsIXPConnectWrappedJS* GetWrappedJS(nsIContent* aContent);
@@ -195,14 +199,7 @@ class nsBindingManager final : public nsStubMutationObserver
195199
// Call PostProcessAttachedQueueEvent() on a timer.
196200
static void PostPAQEventCallback(nsITimer* aTimer, void* aClosure);
197201

198-
// Enumerate each bound content's bindings (including its base bindings)
199-
// in mBoundContentSet. Return false from the callback to stop enumeration.
200-
using BoundContentBindingCallback = std::function<bool (nsXBLBinding*)>;
201-
bool EnumerateBoundContentBindings(
202-
const BoundContentBindingCallback& aCallback) const;
203-
204202
// MEMBER VARIABLES
205-
protected:
206203
// A set of nsIContent that currently have a binding installed.
207204
nsAutoPtr<nsTHashtable<nsRefPtrHashKey<nsIContent> > > mBoundContentSet;
208205

layout/base/PresShell.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,35 +4352,30 @@ PresShell::ContentStateChanged(nsIDocument* aDocument,
43524352
}
43534353

43544354
void
4355-
PresShell::DocumentStatesChanged(nsIDocument* aDocument,
4356-
EventStates aStateMask)
4355+
PresShell::DocumentStatesChanged(nsIDocument* aDocument, EventStates aStateMask)
43574356
{
43584357
NS_PRECONDITION(!mIsDocumentGone, "Unexpected DocumentStatesChanged");
43594358
NS_PRECONDITION(aDocument == mDocument, "Unexpected aDocument");
4359+
MOZ_ASSERT(!aStateMask.IsEmpty());
43604360

43614361
if (mDidInitialize) {
4362-
Element* rootElement = aDocument->GetRootElement();
4363-
bool needRestyle = false;
43644362
if (mStyleSet->IsServo()) {
4365-
needRestyle = rootElement &&
4366-
(mStyleSet->AsServo()->HasDocumentStateDependency(aStateMask) ||
4367-
aDocument->BindingManager()->
4368-
AnyBindingHasDocumentStateDependency(aStateMask));
4369-
} else {
4370-
needRestyle = mStyleSet->AsGecko()->
4371-
HasDocumentStateDependentStyle(rootElement, aStateMask);
4372-
}
4373-
if (needRestyle) {
4374-
mPresContext->RestyleManager()->PostRestyleEvent(rootElement,
4375-
eRestyle_Subtree,
4376-
nsChangeHint(0));
4377-
VERIFY_STYLE_TREE;
4363+
mStyleSet->AsServo()->InvalidateStyleForDocumentStateChanges(aStateMask);
4364+
} else if (Element* rootElement = aDocument->GetRootElement()) {
4365+
const bool needRestyle =
4366+
mStyleSet->AsGecko()->HasDocumentStateDependentStyle(
4367+
rootElement, aStateMask);
4368+
if (needRestyle) {
4369+
mPresContext->RestyleManager()->PostRestyleEvent(rootElement,
4370+
eRestyle_Subtree,
4371+
nsChangeHint(0));
4372+
VERIFY_STYLE_TREE;
4373+
}
43784374
}
43794375
}
43804376

43814377
if (aStateMask.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
4382-
nsIFrame* root = mFrameConstructor->GetRootFrame();
4383-
if (root) {
4378+
if (nsIFrame* root = mFrameConstructor->GetRootFrame()) {
43844379
root->SchedulePaint();
43854380
}
43864381
}

layout/style/ServoBindingList.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ SERVO_BINDING_FUNC(Servo_Element_IsDisplayNone,
4040
SERVO_BINDING_FUNC(Servo_Element_IsPrimaryStyleReusedViaRuleNode,
4141
bool,
4242
RawGeckoElementBorrowed element)
43+
SERVO_BINDING_FUNC(Servo_InvalidateStyleForDocStateChanges,
44+
void,
45+
RawGeckoElementBorrowed root,
46+
const nsTArray<RawServoStyleSetBorrowed>* sets,
47+
uint64_t aStatesChanged)
4348

4449
// Styleset and Stylesheet management
4550
SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes,

layout/style/ServoStyleSet.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "nsSMILAnimationController.h"
3434
#include "nsStyleContext.h"
3535
#include "nsStyleSet.h"
36+
#include "nsXBLPrototypeBinding.h"
3637
#include "gfxUserFontSet.h"
3738

3839
using namespace mozilla;
@@ -223,6 +224,43 @@ ServoStyleSet::SetPresContext(nsPresContext* aPresContext)
223224
return false;
224225
}
225226

227+
void
228+
ServoStyleSet::InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged)
229+
{
230+
MOZ_ASSERT(IsMaster());
231+
MOZ_ASSERT(mDocument);
232+
MOZ_ASSERT(!aStatesChanged.IsEmpty());
233+
234+
nsPresContext* pc = GetPresContext();
235+
if (!pc) {
236+
return;
237+
}
238+
239+
Element* root = mDocument->GetRootElement();
240+
if (!root) {
241+
return;
242+
}
243+
244+
// TODO(emilio): It may be nicer to just invalidate stuff in a given subtree
245+
// for XBL sheets / shadow DOM. Consider just enumerating bound content
246+
// instead and run invalidation individually, passing mRawSet for the UA /
247+
// User sheets.
248+
AutoTArray<RawServoStyleSetBorrowed, 20> styleSets;
249+
styleSets.AppendElement(mRawSet.get());
250+
// FIXME(emilio): When bug 1425759 is fixed we need to enumerate ShadowRoots
251+
// too.
252+
mDocument->BindingManager()->EnumerateBoundContentBindings(
253+
[&](nsXBLBinding* aBinding) {
254+
if (ServoStyleSet* set = aBinding->PrototypeBinding()->GetServoStyleSet()) {
255+
styleSets.AppendElement(set->RawSet());
256+
}
257+
return true;
258+
});
259+
260+
Servo_InvalidateStyleForDocStateChanges(
261+
root, &styleSets, aStatesChanged.ServoValue());
262+
}
263+
226264
nsRestyleHint
227265
ServoStyleSet::MediumFeaturesChanged(bool aViewportChanged)
228266
{

layout/style/ServoStyleSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class ServoStyleSet
146146
// the relevant AppendSheet / RemoveSheet...
147147
void RecordStyleSheetChange(ServoStyleSheet*, StyleSheet::ChangeType) {}
148148

149+
// Runs style invalidation due to document state changes.
150+
void InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged);
151+
149152
void RecordShadowStyleChange(dom::ShadowRoot* aShadowRoot) {
150153
// FIXME(emilio): When we properly support shadow dom we'll need to do
151154
// better.

0 commit comments

Comments
 (0)