-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondition-promote-flush-type
155 lines (134 loc) · 5.34 KB
/
condition-promote-flush-type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From: L. David Baron <dbaron@dbaron.org>
Bug 1368348 - Condition changing flush type for media queries on media queries actually being present.
This modifies code that was originally added in changeset
b62942dc462209526159c654454d968a345020f2 for bug 156716.
For what it's worth, Chromium appears to have tests for size-dependent
media queries, but it only uses them to determine whether
getComputedStyle() results require flushing layout. That is, it appears
to give out-of-date results for flushes other than getComputedStyle()
when a parent requires layout that would change a media query.
TODO: Fix two stylo-only mochitest failures:
TEST-UNEXPECTED-FAIL | layout/style/test/test_bug453896_deck.html | all and (width: 157px) should apply
TEST-UNEXPECTED-FAIL | layout/style/test/test_media_queries.html | all and (width: 117px) should apply
MozReview-Commit-ID: ETxokFiNc5T
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -7585,25 +7585,32 @@ nsIDocument::FlushPendingNotifications(m
return;
}
// If we have a parent we must flush the parent too to ensure that our
// container is reflowed if its size was changed. But if it's not safe to
// flush ourselves, then don't flush the parent, since that can cause things
// like resizes of our frame's widget, which we can't handle while flushing
// is unsafe.
- // Since media queries mean that a size change of our container can
- // affect style, we need to promote a style flush on ourself to a
- // layout flush on our parent, since we need our container to be the
- // correct size to determine the correct style.
if (mParentDocument && IsSafeToFlush()) {
mozilla::ChangesToFlush parentFlush = aFlush;
+
+ // Since media queries mean that a size change of our container can
+ // affect style, if we have media queries on our size, we need to
+ // promote a style flush on ourself to a layout flush on our parent,
+ // since we need our container to be the correct size to determine
+ // the correct style.
if (flushType >= FlushType::Style) {
- parentFlush.mFlushType = std::max(FlushType::Layout, flushType);
- }
+ nsIPresShell* shell = GetShell();
+ nsPresContext* presContext = shell ? shell->GetPresContext() : nullptr;
+ if (presContext && presContext->HasSizeMediaQueries()) {
+ parentFlush.mFlushType = std::max(FlushType::Layout, flushType);
+ }
+ }
+
mParentDocument->FlushPendingNotifications(parentFlush);
}
if (nsIPresShell* shell = GetShell()) {
shell->FlushPendingNotifications(aFlush);
}
}
diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -246,17 +246,18 @@ nsPresContext::nsPresContext(nsIDocument
mIsChrome(false),
mIsChromeOriginImage(false),
mPaintFlashing(false),
mPaintFlashingInitialized(false),
mHasWarnedAboutPositionedTableParts(false),
mHasWarnedAboutTooLargeDashedOrDottedRadius(false),
mQuirkSheetAdded(false),
mNeedsPrefUpdate(false),
- mHadNonBlankPaint(false)
+ mHadNonBlankPaint(false),
+ mHasSizeMediaQueries(false)
#ifdef DEBUG
, mInitialized(false)
#endif
{
PodZero(&mBorderWidthTable);
#ifdef DEBUG
PodZero(&mLayoutPhaseCount);
#endif
diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -1161,16 +1161,24 @@ public:
bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
return mHasWarnedAboutTooLargeDashedOrDottedRadius;
}
void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
}
+ bool HasSizeMediaQueries() const {
+ return mHasSizeMediaQueries;
+ }
+
+ void SetHasSizeMediaQueries() {
+ mHasSizeMediaQueries = true;
+ }
+
nsBidi& GetBidiEngine();
gfxFontFeatureValueSet* GetFontFeatureValuesLookup() const {
return mFontFeatureValuesLookup;
}
/**
* State that is cleared each reflow, to indicate that something
@@ -1478,16 +1486,19 @@ protected:
unsigned mQuirkSheetAdded : 1;
// Is there a pref update to process once we have a container?
unsigned mNeedsPrefUpdate : 1;
// Has NotifyNonBlankPaint been called on this PresContext?
unsigned mHadNonBlankPaint : 1;
+ // Do we have any media queries on our size?
+ unsigned mHasSizeMediaQueries : 1;
+
#ifdef DEBUG
unsigned mInitialized : 1;
#endif
mozilla::Maybe<mozilla::MediaFeatureChange> mPendingMediaFeatureValuesChange;
protected:
diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -51,16 +51,19 @@ GetSize(nsIDocument* aDocument)
//
// * https://github.com/w3c/csswg-drafts/issues/571
// * https://github.com/whatwg/html/issues/1813
//
if (!pc) {
return { };
}
+ // FIXME: Does this need to be proxied to the main thread for stylo?
+ pc->SetHasSizeMediaQueries();
+
if (pc->IsRootPaginatedDocument()) {
// We want the page size, including unprintable areas and margins.
//
// FIXME(emilio, bug 1414600): Not quite!
return pc->GetPageSize();
}
return pc->GetVisibleArea().Size();