Skip to content

Commit af4cc5c

Browse files
committed
Initial window sizes are mandatory.
1 parent 2f96807 commit af4cc5c

File tree

12 files changed

+107
-125
lines changed

12 files changed

+107
-125
lines changed

components/compositing/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub mod windowing;
2727

2828
pub struct SendableFrameTree {
2929
pub pipeline: CompositionPipeline,
30-
pub size: Option<TypedSize2D<f32, CSSPixel>>,
3130
pub children: Vec<SendableFrameTree>,
3231
}
3332

components/constellation/browsingcontext.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct BrowsingContext {
4141
pub top_level_id: TopLevelBrowsingContextId,
4242

4343
/// The size of the frame.
44-
pub size: Option<TypedSize2D<f32, CSSPixel>>,
44+
pub size: TypedSize2D<f32, CSSPixel>,
4545

4646
/// Whether this browsing context is in private browsing mode.
4747
pub is_private: bool,
@@ -70,6 +70,7 @@ impl BrowsingContext {
7070
top_level_id: TopLevelBrowsingContextId,
7171
pipeline_id: PipelineId,
7272
parent_pipeline_id: Option<PipelineId>,
73+
size: TypedSize2D<f32, CSSPixel>,
7374
is_private: bool,
7475
is_visible: bool,
7576
) -> BrowsingContext {
@@ -78,7 +79,7 @@ impl BrowsingContext {
7879
BrowsingContext {
7980
id: id,
8081
top_level_id: top_level_id,
81-
size: None,
82+
size: size,
8283
is_private: is_private,
8384
is_visible: is_visible,
8485
pipeline_id: pipeline_id,

components/constellation/constellation.rs

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ where
734734
top_level_browsing_context_id: TopLevelBrowsingContextId,
735735
parent_pipeline_id: Option<PipelineId>,
736736
opener: Option<BrowsingContextId>,
737-
initial_window_size: Option<TypedSize2D<f32, CSSPixel>>,
737+
initial_window_size: TypedSize2D<f32, CSSPixel>,
738738
// TODO: we have to provide ownership of the LoadData
739739
// here, because it will be send on an ipc channel,
740740
// and ipc channels take onership of their data.
@@ -889,6 +889,7 @@ where
889889
top_level_id: TopLevelBrowsingContextId,
890890
pipeline_id: PipelineId,
891891
parent_pipeline_id: Option<PipelineId>,
892+
size: TypedSize2D<f32, CSSPixel>,
892893
is_private: bool,
893894
is_visible: bool,
894895
) {
@@ -898,6 +899,7 @@ where
898899
top_level_id,
899900
pipeline_id,
900901
parent_pipeline_id,
902+
size,
901903
is_private,
902904
is_visible,
903905
);
@@ -1599,14 +1601,22 @@ where
15991601
EmbedderMsg::Panic(reason, backtrace),
16001602
));
16011603

1602-
let browsing_context = self.browsing_contexts.get(&browsing_context_id);
1603-
let window_size = browsing_context.and_then(|ctx| ctx.size);
1604-
let pipeline_id = browsing_context.map(|ctx| ctx.pipeline_id);
1605-
let is_visible = browsing_context.map(|ctx| ctx.is_visible);
1604+
// The none branch should be unreachable.
1605+
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
1606+
Some(context) => context,
1607+
None => return,
1608+
};
1609+
let window_size = browsing_context.size;
1610+
let pipeline_id = browsing_context.pipeline_id;
1611+
let is_visible = browsing_context.is_visible;
16061612

1607-
let pipeline = pipeline_id.and_then(|id| self.pipelines.get(&id));
1608-
let pipeline_url = pipeline.map(|pipeline| pipeline.url.clone());
1609-
let opener = pipeline.and_then(|pipeline| pipeline.opener);
1613+
// the none branch should be unreachable.
1614+
let pipeline = match self.pipelines.get(&pipeline_id) {
1615+
Some(p) => p,
1616+
None => return,
1617+
};
1618+
let pipeline_url = pipeline.url.clone();
1619+
let opener = pipeline.opener;
16101620

16111621
self.close_browsing_context_children(
16121622
browsing_context_id,
@@ -1616,10 +1626,8 @@ where
16161626

16171627
let failure_url = ServoUrl::parse("about:failure").expect("infallible");
16181628

1619-
if let Some(pipeline_url) = pipeline_url {
1620-
if pipeline_url == failure_url {
1621-
return error!("about:failure failed");
1622-
}
1629+
if pipeline_url == failure_url {
1630+
return error!("about:failure failed");
16231631
}
16241632

16251633
warn!("creating replacement pipeline for about:failure");
@@ -1638,7 +1646,7 @@ where
16381646
load_data.clone(),
16391647
sandbox,
16401648
is_private,
1641-
is_visible.unwrap_or(true),
1649+
is_visible,
16421650
);
16431651
self.add_pending_change(SessionHistoryChange {
16441652
top_level_browsing_context_id: top_level_browsing_context_id,
@@ -1737,7 +1745,7 @@ where
17371745
top_level_browsing_context_id,
17381746
None,
17391747
None,
1740-
Some(window_size),
1748+
window_size,
17411749
load_data.clone(),
17421750
sandbox,
17431751
is_private,
@@ -3275,6 +3283,7 @@ where
32753283
change.top_level_browsing_context_id,
32763284
change.new_pipeline_id,
32773285
new_context_info.parent_pipeline_id,
3286+
self.window_size.initial_viewport, //XXXjdm is this valid?
32783287
new_context_info.is_private,
32793288
new_context_info.is_visible,
32803289
);
@@ -3612,44 +3621,41 @@ where
36123621
}
36133622

36143623
// Check the visible rectangle for this pipeline. If the constellation has received a
3615-
// size for the pipeline, then its painting should be up to date. If the constellation
3616-
// *hasn't* received a size, it could be that the layer was hidden by script before the
3617-
// compositor discovered it, so we just don't check the layer.
3618-
if let Some(size) = browsing_context.size {
3619-
// If the rectangle for this pipeline is zero sized, it will
3620-
// never be painted. In this case, don't query the layout
3621-
// thread as it won't contribute to the final output image.
3622-
if size == TypedSize2D::zero() {
3623-
continue;
3624-
}
3624+
// size for the pipeline, then its painting should be up to date.
3625+
//
3626+
// If the rectangle for this pipeline is zero sized, it will
3627+
// never be painted. In this case, don't query the layout
3628+
// thread as it won't contribute to the final output image.
3629+
if browsing_context.size == TypedSize2D::zero() {
3630+
continue;
3631+
}
36253632

3626-
// Get the epoch that the compositor has drawn for this pipeline.
3627-
let compositor_epoch = pipeline_states.get(&browsing_context.pipeline_id);
3628-
match compositor_epoch {
3629-
Some(compositor_epoch) => {
3630-
// Synchronously query the layout thread to see if the current
3631-
// epoch matches what the compositor has drawn. If they match
3632-
// (and script is idle) then this pipeline won't change again
3633-
// and can be considered stable.
3634-
let message = LayoutControlMsg::GetCurrentEpoch(epoch_sender.clone());
3635-
if let Err(e) = pipeline.layout_chan.send(message) {
3636-
warn!("Failed to send GetCurrentEpoch ({}).", e);
3637-
}
3638-
match epoch_receiver.recv() {
3639-
Err(e) => warn!("Failed to receive current epoch ({}).", e),
3640-
Ok(layout_thread_epoch) => {
3641-
if layout_thread_epoch != *compositor_epoch {
3642-
return ReadyToSave::EpochMismatch;
3643-
}
3644-
},
3645-
}
3646-
},
3647-
None => {
3648-
// The compositor doesn't know about this pipeline yet.
3649-
// Assume it hasn't rendered yet.
3650-
return ReadyToSave::PipelineUnknown;
3651-
},
3652-
}
3633+
// Get the epoch that the compositor has drawn for this pipeline.
3634+
let compositor_epoch = pipeline_states.get(&browsing_context.pipeline_id);
3635+
match compositor_epoch {
3636+
Some(compositor_epoch) => {
3637+
// Synchronously query the layout thread to see if the current
3638+
// epoch matches what the compositor has drawn. If they match
3639+
// (and script is idle) then this pipeline won't change again
3640+
// and can be considered stable.
3641+
let message = LayoutControlMsg::GetCurrentEpoch(epoch_sender.clone());
3642+
if let Err(e) = pipeline.layout_chan.send(message) {
3643+
warn!("Failed to send GetCurrentEpoch ({}).", e);
3644+
}
3645+
match epoch_receiver.recv() {
3646+
Err(e) => warn!("Failed to receive current epoch ({}).", e),
3647+
Ok(layout_thread_epoch) => {
3648+
if layout_thread_epoch != *compositor_epoch {
3649+
return ReadyToSave::EpochMismatch;
3650+
}
3651+
},
3652+
}
3653+
},
3654+
None => {
3655+
// The compositor doesn't know about this pipeline yet.
3656+
// Assume it hasn't rendered yet.
3657+
return ReadyToSave::PipelineUnknown;
3658+
},
36533659
}
36543660
}
36553661

@@ -3715,7 +3721,7 @@ where
37153721
browsing_context_id: BrowsingContextId,
37163722
) {
37173723
if let Some(browsing_context) = self.browsing_contexts.get_mut(&browsing_context_id) {
3718-
browsing_context.size = Some(new_size.initial_viewport);
3724+
browsing_context.size = new_size.initial_viewport;
37193725
// Send Resize (or ResizeInactive) messages to each pipeline in the frame tree.
37203726
let pipeline_id = browsing_context.pipeline_id;
37213727
let pipeline = match self.pipelines.get(&pipeline_id) {
@@ -4001,7 +4007,6 @@ where
40014007
.map(|pipeline| {
40024008
let mut frame_tree = SendableFrameTree {
40034009
pipeline: pipeline.to_sendable(),
4004-
size: browsing_context.size,
40054010
children: vec![],
40064011
};
40074012

components/constellation/pipeline.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub struct InitialPipelineState {
152152
pub mem_profiler_chan: profile_mem::ProfilerChan,
153153

154154
/// Information about the initial window size.
155-
pub window_size: Option<TypedSize2D<f32, CSSPixel>>,
155+
pub window_size: TypedSize2D<f32, CSSPixel>,
156156

157157
/// Information about the device pixel ratio.
158158
pub device_pixel_ratio: TypedScale<f32, CSSPixel, DevicePixel>,
@@ -200,11 +200,10 @@ impl Pipeline {
200200
let (layout_content_process_shutdown_chan, layout_content_process_shutdown_port) =
201201
ipc::channel().expect("Pipeline layout content shutdown chan");
202202

203-
let device_pixel_ratio = state.device_pixel_ratio;
204-
let window_size = state.window_size.map(|size| WindowSizeData {
205-
initial_viewport: size,
206-
device_pixel_ratio: device_pixel_ratio,
207-
});
203+
let window_size = WindowSizeData {
204+
initial_viewport: state.window_size,
205+
device_pixel_ratio: state.device_pixel_ratio,
206+
};
208207

209208
let url = state.load_data.url.clone();
210209

@@ -477,7 +476,7 @@ pub struct UnprivilegedPipelineContent {
477476
resource_threads: ResourceThreads,
478477
time_profiler_chan: time::ProfilerChan,
479478
mem_profiler_chan: profile_mem::ProfilerChan,
480-
window_size: Option<WindowSizeData>,
479+
window_size: WindowSizeData,
481480
script_chan: IpcSender<ConstellationControlMsg>,
482481
load_data: LoadData,
483482
script_port: IpcReceiver<ConstellationControlMsg>,

components/script/dom/document.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,17 +2800,15 @@ impl Document {
28002800
///
28012801
/// FIXME(emilio): This really needs to be somehow more in sync with layout.
28022802
/// Feels like a hack.
2803-
///
2804-
/// Also, shouldn't return an option, I'm quite sure.
2805-
pub fn device(&self) -> Option<Device> {
2806-
let window_size = self.window().window_size()?;
2803+
pub fn device(&self) -> Device {
2804+
let window_size = self.window().window_size();
28072805
let viewport_size = window_size.initial_viewport;
28082806
let device_pixel_ratio = window_size.device_pixel_ratio;
2809-
Some(Device::new(
2807+
Device::new(
28102808
MediaType::screen(),
28112809
viewport_size,
28122810
device_pixel_ratio,
2813-
))
2811+
)
28142812
}
28152813

28162814
/// Remove a stylesheet owned by `owner` from the list of document sheets.
@@ -4177,7 +4175,7 @@ impl DocumentMethods for Document {
41774175
let y = *y as f32;
41784176
let point = &Point2D::new(x, y);
41794177
let window = window_from_node(self);
4180-
let viewport = window.window_size()?.initial_viewport;
4178+
let viewport = window.window_size().initial_viewport;
41814179

41824180
if self.browsing_context().is_none() {
41834181
return None;
@@ -4212,10 +4210,7 @@ impl DocumentMethods for Document {
42124210
let y = *y as f32;
42134211
let point = &Point2D::new(x, y);
42144212
let window = window_from_node(self);
4215-
let viewport = match window.window_size() {
4216-
Some(size) => size.initial_viewport,
4217-
None => return vec![],
4218-
};
4213+
let viewport = window.window_size().initial_viewport;
42194214

42204215
if self.browsing_context().is_none() {
42214216
return vec![];

components/script/dom/htmliframeelement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl HTMLIFrameElement {
194194
load_data: load_data.unwrap(),
195195
pipeline_port: pipeline_receiver,
196196
content_process_shutdown_chan: None,
197-
window_size: Some(WindowSizeData {
197+
window_size: WindowSizeData {
198198
initial_viewport: {
199199
let rect = self.upcast::<Node>().bounding_content_box_or_zero();
200200
TypedSize2D::new(
@@ -203,7 +203,7 @@ impl HTMLIFrameElement {
203203
)
204204
},
205205
device_pixel_ratio: window.device_pixel_ratio(),
206-
}),
206+
},
207207
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
208208
};
209209

components/script/dom/htmlimageelement.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -634,21 +634,14 @@ impl HTMLImageElement {
634634
) -> Au {
635635
let document = document_from_node(self);
636636
let device = document.device();
637-
if !device.is_some() {
638-
return Au(1);
639-
}
640637
let quirks_mode = document.quirks_mode();
641638
//FIXME https://github.com/whatwg/html/issues/3832
642-
source_size_list.evaluate(&device.unwrap(), quirks_mode)
639+
source_size_list.evaluate(&device, quirks_mode)
643640
}
644641

645642
/// https://html.spec.whatwg.org/multipage/#matches-the-environment
646643
fn matches_environment(&self, media_query: String) -> bool {
647644
let document = document_from_node(self);
648-
let device = match document.device() {
649-
Some(device) => device,
650-
None => return false,
651-
};
652645
let quirks_mode = document.quirks_mode();
653646
let document_url = &document.url();
654647
// FIXME(emilio): This should do the same that we do for other media
@@ -668,7 +661,7 @@ impl HTMLImageElement {
668661
let mut parserInput = ParserInput::new(&media_query);
669662
let mut parser = Parser::new(&mut parserInput);
670663
let media_list = MediaList::parse(&context, &mut parser);
671-
media_list.evaluate(&device, quirks_mode)
664+
media_list.evaluate(&document.device(), quirks_mode)
672665
}
673666

674667
/// <https://html.spec.whatwg.org/multipage/#normalise-the-source-densities>
@@ -740,13 +733,11 @@ impl HTMLImageElement {
740733
// Step 5
741734
let mut best_candidate = max;
742735
let device = document_from_node(self).device();
743-
if let Some(device) = device {
744-
let device_den = device.device_pixel_ratio().get() as f64;
745-
for (index, image_source) in img_sources.iter().enumerate() {
746-
let current_den = image_source.descriptor.den.unwrap();
747-
if current_den < best_candidate.0 && current_den >= device_den {
748-
best_candidate = (current_den, index);
749-
}
736+
let device_den = device.device_pixel_ratio().get() as f64;
737+
for (index, image_source) in img_sources.iter().enumerate() {
738+
let current_den = image_source.descriptor.den.unwrap();
739+
if current_den < best_candidate.0 && current_den >= device_den {
740+
best_candidate = (current_den, index);
750741
}
751742
}
752743
let selected_source = img_sources.remove(best_candidate.1).clone();

components/script/dom/mediaquerylist.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ impl MediaQueryList {
6969
}
7070

7171
pub fn evaluate(&self) -> bool {
72-
self.document.device().map_or(false, |device| {
73-
self.media_query_list
74-
.evaluate(&device, self.document.quirks_mode())
75-
})
72+
self.media_query_list
73+
.evaluate(&self.document.device(), self.document.quirks_mode())
7674
}
7775
}
7876

0 commit comments

Comments
 (0)