mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Initial window sizes are mandatory.
This commit is contained in:
parent
34e77f62af
commit
231a37be24
12 changed files with 101 additions and 130 deletions
|
@ -2806,17 +2806,11 @@ impl Document {
|
|||
///
|
||||
/// FIXME(emilio): This really needs to be somehow more in sync with layout.
|
||||
/// Feels like a hack.
|
||||
///
|
||||
/// Also, shouldn't return an option, I'm quite sure.
|
||||
pub fn device(&self) -> Option<Device> {
|
||||
let window_size = self.window().window_size()?;
|
||||
pub fn device(&self) -> Device {
|
||||
let window_size = self.window().window_size();
|
||||
let viewport_size = window_size.initial_viewport;
|
||||
let device_pixel_ratio = window_size.device_pixel_ratio;
|
||||
Some(Device::new(
|
||||
MediaType::screen(),
|
||||
viewport_size,
|
||||
device_pixel_ratio,
|
||||
))
|
||||
Device::new(MediaType::screen(), viewport_size, device_pixel_ratio)
|
||||
}
|
||||
|
||||
/// Remove a stylesheet owned by `owner` from the list of document sheets.
|
||||
|
@ -4183,7 +4177,7 @@ impl DocumentMethods for Document {
|
|||
let y = *y as f32;
|
||||
let point = &Point2D::new(x, y);
|
||||
let window = window_from_node(self);
|
||||
let viewport = window.window_size()?.initial_viewport;
|
||||
let viewport = window.window_size().initial_viewport;
|
||||
|
||||
if self.browsing_context().is_none() {
|
||||
return None;
|
||||
|
@ -4218,10 +4212,7 @@ impl DocumentMethods for Document {
|
|||
let y = *y as f32;
|
||||
let point = &Point2D::new(x, y);
|
||||
let window = window_from_node(self);
|
||||
let viewport = match window.window_size() {
|
||||
Some(size) => size.initial_viewport,
|
||||
None => return vec![],
|
||||
};
|
||||
let viewport = window.window_size().initial_viewport;
|
||||
|
||||
if self.browsing_context().is_none() {
|
||||
return vec![];
|
||||
|
|
|
@ -194,7 +194,7 @@ impl HTMLIFrameElement {
|
|||
load_data: load_data.unwrap(),
|
||||
pipeline_port: pipeline_receiver,
|
||||
content_process_shutdown_chan: None,
|
||||
window_size: Some(WindowSizeData {
|
||||
window_size: WindowSizeData {
|
||||
initial_viewport: {
|
||||
let rect = self.upcast::<Node>().bounding_content_box_or_zero();
|
||||
TypedSize2D::new(
|
||||
|
@ -203,7 +203,7 @@ impl HTMLIFrameElement {
|
|||
)
|
||||
},
|
||||
device_pixel_ratio: window.device_pixel_ratio(),
|
||||
}),
|
||||
},
|
||||
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
|
||||
};
|
||||
|
||||
|
|
|
@ -634,21 +634,14 @@ impl HTMLImageElement {
|
|||
) -> Au {
|
||||
let document = document_from_node(self);
|
||||
let device = document.device();
|
||||
if !device.is_some() {
|
||||
return Au(1);
|
||||
}
|
||||
let quirks_mode = document.quirks_mode();
|
||||
//FIXME https://github.com/whatwg/html/issues/3832
|
||||
source_size_list.evaluate(&device.unwrap(), quirks_mode)
|
||||
source_size_list.evaluate(&device, quirks_mode)
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#matches-the-environment
|
||||
fn matches_environment(&self, media_query: String) -> bool {
|
||||
let document = document_from_node(self);
|
||||
let device = match document.device() {
|
||||
Some(device) => device,
|
||||
None => return false,
|
||||
};
|
||||
let quirks_mode = document.quirks_mode();
|
||||
let document_url = &document.url();
|
||||
// FIXME(emilio): This should do the same that we do for other media
|
||||
|
@ -668,7 +661,7 @@ impl HTMLImageElement {
|
|||
let mut parserInput = ParserInput::new(&media_query);
|
||||
let mut parser = Parser::new(&mut parserInput);
|
||||
let media_list = MediaList::parse(&context, &mut parser);
|
||||
media_list.evaluate(&device, quirks_mode)
|
||||
media_list.evaluate(&document.device(), quirks_mode)
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#normalise-the-source-densities>
|
||||
|
@ -740,13 +733,11 @@ impl HTMLImageElement {
|
|||
// Step 5
|
||||
let mut best_candidate = max;
|
||||
let device = document_from_node(self).device();
|
||||
if let Some(device) = device {
|
||||
let device_den = device.device_pixel_ratio().get() as f64;
|
||||
for (index, image_source) in img_sources.iter().enumerate() {
|
||||
let current_den = image_source.descriptor.den.unwrap();
|
||||
if current_den < best_candidate.0 && current_den >= device_den {
|
||||
best_candidate = (current_den, index);
|
||||
}
|
||||
let device_den = device.device_pixel_ratio().get() as f64;
|
||||
for (index, image_source) in img_sources.iter().enumerate() {
|
||||
let current_den = image_source.descriptor.den.unwrap();
|
||||
if current_den < best_candidate.0 && current_den >= device_den {
|
||||
best_candidate = (current_den, index);
|
||||
}
|
||||
}
|
||||
let selected_source = img_sources.remove(best_candidate.1).clone();
|
||||
|
|
|
@ -69,10 +69,8 @@ impl MediaQueryList {
|
|||
}
|
||||
|
||||
pub fn evaluate(&self) -> bool {
|
||||
self.document.device().map_or(false, |device| {
|
||||
self.media_query_list
|
||||
.evaluate(&device, self.document.quirks_mode())
|
||||
})
|
||||
self.media_query_list
|
||||
.evaluate(&self.document.device(), self.document.quirks_mode())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ pub struct Window {
|
|||
layout_rpc: Box<LayoutRPC + Send + 'static>,
|
||||
|
||||
/// The current size of the window, in pixels.
|
||||
window_size: Cell<Option<WindowSizeData>>,
|
||||
window_size: Cell<WindowSizeData>,
|
||||
|
||||
/// A handle for communicating messages to the bluetooth thread.
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
|
@ -958,7 +958,9 @@ impl WindowMethods for Window {
|
|||
fn InnerHeight(&self) -> i32 {
|
||||
self.window_size
|
||||
.get()
|
||||
.and_then(|e| e.initial_viewport.height.to_i32())
|
||||
.initial_viewport
|
||||
.height
|
||||
.to_i32()
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
|
@ -967,7 +969,9 @@ impl WindowMethods for Window {
|
|||
fn InnerWidth(&self) -> i32 {
|
||||
self.window_size
|
||||
.get()
|
||||
.and_then(|e| e.initial_viewport.width.to_i32())
|
||||
.initial_viewport
|
||||
.width
|
||||
.to_i32()
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
|
@ -1245,10 +1249,7 @@ impl Window {
|
|||
let xfinite = if x_.is_finite() { x_ } else { 0.0f64 };
|
||||
let yfinite = if y_.is_finite() { y_ } else { 0.0f64 };
|
||||
|
||||
// Step 4
|
||||
if self.window_size.get().is_none() {
|
||||
return;
|
||||
}
|
||||
// TODO Step 4 - determine if a window has a viewport
|
||||
|
||||
// Step 5
|
||||
//TODO remove scrollbar width
|
||||
|
@ -1322,9 +1323,7 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn device_pixel_ratio(&self) -> TypedScale<f32, CSSPixel, DevicePixel> {
|
||||
self.window_size
|
||||
.get()
|
||||
.map_or(TypedScale::new(1.0), |data| data.device_pixel_ratio)
|
||||
self.window_size.get().device_pixel_ratio
|
||||
}
|
||||
|
||||
fn client_window(&self) -> (TypedSize2D<u32, CSSPixel>, TypedPoint2D<i32, CSSPixel>) {
|
||||
|
@ -1369,12 +1368,6 @@ impl Window {
|
|||
_ => (),
|
||||
}
|
||||
|
||||
// If there is no window size, we have nothing to do.
|
||||
let window_size = match self.window_size.get() {
|
||||
Some(window_size) => window_size,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let for_display = reflow_goal == ReflowGoal::Full;
|
||||
if for_display && self.suppress_reflow.get() {
|
||||
debug!(
|
||||
|
@ -1417,7 +1410,7 @@ impl Window {
|
|||
},
|
||||
document: self.Document().upcast::<Node>().to_trusted_node_address(),
|
||||
stylesheets_changed,
|
||||
window_size,
|
||||
window_size: self.window_size.get(),
|
||||
reflow_goal,
|
||||
script_join_chan: join_chan,
|
||||
dom_count: self.Document().dom_count(),
|
||||
|
@ -1510,13 +1503,11 @@ impl Window {
|
|||
if !for_display || self.Document().needs_reflow() {
|
||||
issued_reflow = self.force_reflow(reflow_goal, reason);
|
||||
|
||||
// If window_size is `None`, we don't reflow, so the document stays
|
||||
// dirty. Otherwise, we shouldn't need a reflow immediately after a
|
||||
// We shouldn't need a reflow immediately after a
|
||||
// reflow, except if we're waiting for a deferred paint.
|
||||
assert!(
|
||||
!self.Document().needs_reflow() ||
|
||||
(!for_display && self.Document().needs_paint()) ||
|
||||
self.window_size.get().is_none() ||
|
||||
self.suppress_reflow.get()
|
||||
);
|
||||
} else {
|
||||
|
@ -1801,10 +1792,10 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn set_window_size(&self, size: WindowSizeData) {
|
||||
self.window_size.set(Some(size));
|
||||
self.window_size.set(size);
|
||||
}
|
||||
|
||||
pub fn window_size(&self) -> Option<WindowSizeData> {
|
||||
pub fn window_size(&self) -> WindowSizeData {
|
||||
self.window_size.get()
|
||||
}
|
||||
|
||||
|
@ -2021,7 +2012,7 @@ impl Window {
|
|||
layout_chan: Sender<Msg>,
|
||||
pipelineid: PipelineId,
|
||||
parent_info: Option<PipelineId>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
window_size: WindowSizeData,
|
||||
origin: MutableOrigin,
|
||||
navigation_start: u64,
|
||||
navigation_start_precise: u64,
|
||||
|
|
|
@ -289,7 +289,7 @@ impl WindowProxy {
|
|||
load_data: load_data,
|
||||
pipeline_port: pipeline_receiver,
|
||||
content_process_shutdown_chan: None,
|
||||
window_size: None,
|
||||
window_size: window.window_size(),
|
||||
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
|
||||
};
|
||||
let constellation_msg = ScriptMsg::ScriptNewAuxiliary(load_info, pipeline_sender);
|
||||
|
|
|
@ -182,7 +182,7 @@ struct InProgressLoad {
|
|||
/// The opener, if this is an auxiliary.
|
||||
opener: Option<BrowsingContextId>,
|
||||
/// The current window size associated with this pipeline.
|
||||
window_size: Option<WindowSizeData>,
|
||||
window_size: WindowSizeData,
|
||||
/// Channel to the layout thread associated with this pipeline.
|
||||
layout_chan: Sender<message::Msg>,
|
||||
/// The activity level of the document (inactive, active or fully active).
|
||||
|
@ -210,7 +210,7 @@ impl InProgressLoad {
|
|||
parent_info: Option<PipelineId>,
|
||||
opener: Option<BrowsingContextId>,
|
||||
layout_chan: Sender<message::Msg>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
window_size: WindowSizeData,
|
||||
url: ServoUrl,
|
||||
origin: MutableOrigin,
|
||||
) -> InProgressLoad {
|
||||
|
@ -1852,7 +1852,7 @@ impl ScriptThread {
|
|||
}
|
||||
let mut loads = self.incomplete_loads.borrow_mut();
|
||||
if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
|
||||
load.window_size = Some(size);
|
||||
load.window_size = size;
|
||||
return;
|
||||
}
|
||||
warn!("resize sent to nonexistent pipeline");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue