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