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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use app_units::Au;
use crossbeam_channel::{Receiver, Sender};
use euclid::default::{Point2D, Rect};
use gfx_traits::Epoch;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use malloc_size_of_derive::MallocSizeOf;
use metrics::PaintTimeMetrics;
use msg::constellation_msg::{BackgroundHangMonitorRegister, BrowsingContextId, PipelineId};
use net_traits::image_cache::ImageCache;
use profile_traits::mem::ReportsChan;
use script_traits::{
ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg, Painter, ScrollState,
WindowSizeData,
};
use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_url::{ImmutableOrigin, ServoUrl};
use style::animation::DocumentAnimationSet;
use style::context::QuirksMode;
use style::dom::OpaqueNode;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::properties::PropertyId;
use style::selector_parser::{PseudoElement, RestyleDamage, Snapshot};
use style::stylesheets::Stylesheet;
use crate::rpc::LayoutRPC;
use crate::{PendingImage, TrustedNodeAddress};
pub enum Msg {
AddStylesheet(ServoArc<Stylesheet>, Option<ServoArc<Stylesheet>>),
RemoveStylesheet(ServoArc<Stylesheet>),
SetQuirksMode(QuirksMode),
Reflow(ScriptReflow),
GetRPC(Sender<Box<dyn LayoutRPC + Send>>),
CollectReports(ReportsChan),
PrepareToExit(Sender<()>),
ExitNow,
GetCurrentEpoch(IpcSender<Epoch>),
GetWebFontLoadState(IpcSender<bool>),
CreateLayoutThread(LayoutThreadInit),
SetFinalUrl(ServoUrl),
SetScrollStates(Vec<ScrollState>),
RegisterPaint(Atom, Vec<Atom>, Box<dyn Painter>),
SetNavigationStart(u64),
}
#[derive(Debug, PartialEq)]
pub enum NodesFromPointQueryType {
All,
Topmost,
}
#[derive(Debug, PartialEq)]
pub enum QueryMsg {
ContentBoxQuery(OpaqueNode),
ContentBoxesQuery(OpaqueNode),
ClientRectQuery(OpaqueNode),
ScrollingAreaQuery(Option<OpaqueNode>),
OffsetParentQuery(OpaqueNode),
TextIndexQuery(OpaqueNode, Point2D<f32>),
NodesFromPointQuery(Point2D<f32>, NodesFromPointQueryType),
NodeScrollIdQuery(TrustedNodeAddress),
ResolvedStyleQuery(TrustedNodeAddress, Option<PseudoElement>, PropertyId),
StyleQuery,
ElementInnerTextQuery(TrustedNodeAddress),
ResolvedFontStyleQuery(TrustedNodeAddress, PropertyId, String),
InnerWindowDimensionsQuery(BrowsingContextId),
}
#[derive(Debug, PartialEq)]
pub enum ReflowGoal {
Full,
TickAnimations,
LayoutQuery(QueryMsg, u64),
UpdateScrollNode(ScrollState),
}
impl ReflowGoal {
pub fn needs_display_list(&self) -> bool {
match *self {
ReflowGoal::Full | ReflowGoal::TickAnimations | ReflowGoal::UpdateScrollNode(_) => true,
ReflowGoal::LayoutQuery(ref querymsg, _) => match *querymsg {
QueryMsg::ElementInnerTextQuery(_) |
QueryMsg::InnerWindowDimensionsQuery(_) |
QueryMsg::NodesFromPointQuery(..) |
QueryMsg::ResolvedStyleQuery(..) |
QueryMsg::TextIndexQuery(..) => true,
QueryMsg::ClientRectQuery(_) |
QueryMsg::ContentBoxQuery(_) |
QueryMsg::ContentBoxesQuery(_) |
QueryMsg::NodeScrollIdQuery(_) |
QueryMsg::OffsetParentQuery(_) |
QueryMsg::ResolvedFontStyleQuery(..) |
QueryMsg::ScrollingAreaQuery(_) |
QueryMsg::StyleQuery => false,
},
}
}
pub fn needs_display(&self) -> bool {
match *self {
ReflowGoal::Full | ReflowGoal::TickAnimations | ReflowGoal::UpdateScrollNode(_) => true,
ReflowGoal::LayoutQuery(ref querymsg, _) => match *querymsg {
QueryMsg::NodesFromPointQuery(..) |
QueryMsg::TextIndexQuery(..) |
QueryMsg::ElementInnerTextQuery(_) => true,
QueryMsg::ContentBoxQuery(_) |
QueryMsg::ContentBoxesQuery(_) |
QueryMsg::ClientRectQuery(_) |
QueryMsg::ScrollingAreaQuery(_) |
QueryMsg::NodeScrollIdQuery(_) |
QueryMsg::ResolvedStyleQuery(..) |
QueryMsg::ResolvedFontStyleQuery(..) |
QueryMsg::OffsetParentQuery(_) |
QueryMsg::InnerWindowDimensionsQuery(_) |
QueryMsg::StyleQuery => false,
},
}
}
}
pub struct Reflow {
pub page_clip_rect: Rect<Au>,
}
#[derive(Default)]
pub struct ReflowComplete {
pub pending_images: Vec<PendingImage>,
}
pub struct ScriptReflow {
pub reflow_info: Reflow,
pub document: TrustedNodeAddress,
pub dirty_root: Option<TrustedNodeAddress>,
pub stylesheets_changed: bool,
pub window_size: WindowSizeData,
pub script_join_chan: Sender<ReflowComplete>,
pub reflow_goal: ReflowGoal,
pub dom_count: u32,
pub origin: ImmutableOrigin,
pub pending_restyles: Vec<(TrustedNodeAddress, PendingRestyle)>,
pub animation_timeline_value: f64,
pub animations: DocumentAnimationSet,
}
pub struct LayoutThreadInit {
pub id: PipelineId,
pub url: ServoUrl,
pub is_parent: bool,
pub layout_pair: (Sender<Msg>, Receiver<Msg>),
pub pipeline_port: IpcReceiver<LayoutControlMsg>,
pub background_hang_monitor_register: Box<dyn BackgroundHangMonitorRegister>,
pub constellation_chan: IpcSender<ConstellationMsg>,
pub script_chan: IpcSender<ConstellationControlMsg>,
pub image_cache: Arc<dyn ImageCache>,
pub paint_time_metrics: PaintTimeMetrics,
pub layout_is_busy: Arc<AtomicBool>,
pub window_size: WindowSizeData,
}
#[derive(Debug, MallocSizeOf)]
pub struct PendingRestyle {
pub snapshot: Option<Snapshot>,
pub hint: RestyleHint,
pub damage: RestyleDamage,
}
impl PendingRestyle {
#[inline]
pub fn new() -> Self {
PendingRestyle {
snapshot: None,
hint: RestyleHint::empty(),
damage: RestyleDamage::empty(),
}
}
}