mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Let Stylist compute and store viewport constraints when setting the device
This commit is contained in:
parent
f173504ded
commit
f1b6c7cc99
3 changed files with 24 additions and 13 deletions
|
@ -1077,7 +1077,7 @@ impl LayoutTask {
|
|||
flow_ref::deref_mut(layout_root));
|
||||
let root_size = {
|
||||
let root_flow = flow::base(&**layout_root);
|
||||
if rw_data.stylist.constrain_viewport().is_some() {
|
||||
if rw_data.stylist.get_viewport_constraints().is_some() {
|
||||
root_flow.position.size.to_physical(root_flow.writing_mode)
|
||||
} else {
|
||||
root_flow.overflow.size
|
||||
|
@ -1164,7 +1164,7 @@ impl LayoutTask {
|
|||
let device = Device::new(MediaType::Screen, initial_viewport);
|
||||
rw_data.stylist.set_device(device);
|
||||
|
||||
let constraints = rw_data.stylist.constrain_viewport();
|
||||
let constraints = rw_data.stylist.get_viewport_constraints();
|
||||
rw_data.viewport_size = match constraints {
|
||||
Some(ref constraints) => {
|
||||
debug!("Viewport constraints: {:?}", constraints);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use legacy::PresentationalHintSynthesis;
|
||||
use media_queries::Device;
|
||||
use media_queries::{Device, MediaType};
|
||||
use node::TElementAttributes;
|
||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use restyle_hints::{RestyleHint, StateDependencySet};
|
||||
|
@ -63,6 +63,9 @@ pub struct Stylist {
|
|||
// Device that the stylist is currently evaluating against.
|
||||
pub device: Device,
|
||||
|
||||
// Viewport constraints based on the current device.
|
||||
viewport_constraints: Option<ViewportConstraints>,
|
||||
|
||||
// If true, a stylesheet has been added or the device has
|
||||
// changed, and the stylist needs to be updated.
|
||||
is_dirty: bool,
|
||||
|
@ -83,6 +86,7 @@ impl Stylist {
|
|||
pub fn new(device: Device) -> Stylist {
|
||||
let stylist = Stylist {
|
||||
stylesheets: vec!(),
|
||||
viewport_constraints: None,
|
||||
device: device,
|
||||
is_dirty: true,
|
||||
|
||||
|
@ -101,14 +105,6 @@ impl Stylist {
|
|||
&self.stylesheets
|
||||
}
|
||||
|
||||
pub fn constrain_viewport(&self) -> Option<ViewportConstraints> {
|
||||
let cascaded_rule = self.stylesheets.iter()
|
||||
.flat_map(|s| s.effective_rules(&self.device).viewport())
|
||||
.cascade();
|
||||
|
||||
ViewportConstraints::maybe_new(self.device.viewport_size, &cascaded_rule)
|
||||
}
|
||||
|
||||
pub fn update(&mut self) -> bool {
|
||||
if self.is_dirty {
|
||||
self.element_map = PerPseudoElementSelectorMap::new();
|
||||
|
@ -187,7 +183,15 @@ impl Stylist {
|
|||
self.state_deps.compute_hint(element, current_state, state_change)
|
||||
}
|
||||
|
||||
pub fn set_device(&mut self, device: Device) {
|
||||
pub fn set_device(&mut self, mut device: Device) {
|
||||
let cascaded_rule = self.stylesheets.iter()
|
||||
.flat_map(|s| s.effective_rules(&self.device).viewport())
|
||||
.cascade();
|
||||
|
||||
self.viewport_constraints = ViewportConstraints::maybe_new(self.device.viewport_size, &cascaded_rule);
|
||||
if let Some(ref constraints) = self.viewport_constraints {
|
||||
device = Device::new(MediaType::Screen, constraints.size);
|
||||
}
|
||||
let is_dirty = self.is_dirty || self.stylesheets.iter()
|
||||
.flat_map(|stylesheet| stylesheet.rules().media())
|
||||
.any(|media_rule| media_rule.evaluate(&self.device) != media_rule.evaluate(&device));
|
||||
|
@ -196,6 +200,13 @@ impl Stylist {
|
|||
self.is_dirty |= is_dirty;
|
||||
}
|
||||
|
||||
pub fn get_viewport_constraints(&self) -> Option<ViewportConstraints> {
|
||||
match self.viewport_constraints {
|
||||
Some(ref constraints) => Some(constraints.clone()),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_quirks_mode_stylesheet(&mut self) {
|
||||
match read_resource_file(&["quirks-mode.css"]) {
|
||||
Ok(res) => {
|
||||
|
|
|
@ -20,7 +20,7 @@ define_css_keyword_enum!(Orientation:
|
|||
"landscape" => Landscape);
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
pub struct ViewportConstraints {
|
||||
pub size: TypedSize2D<ViewportPx, f32>,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue