Skip to content
Permalink
Browse files

Let Stylist compute and store viewport constraints when setting the d…

…evice
  • Loading branch information...
tschneidereit committed Oct 5, 2015
1 parent f173504 commit f1b6c7cc99d0804daa52753d02368927176b6c05
Showing with 24 additions and 13 deletions.
  1. +2 −2 components/layout/layout_task.rs
  2. +21 −10 components/style/selector_matching.rs
  3. +1 −1 components/style_traits/viewport.rs
@@ -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>,

0 comments on commit f1b6c7c

Please sign in to comment.
You can’t perform that action at this time.