Make Stylesheet.dirty_on_viewport_size_change an AtomicBool

This commit is contained in:
Simon Sapin 2016-11-18 17:13:30 +01:00
parent 236c575c50
commit cf7adcdca5
4 changed files with 27 additions and 6 deletions

View file

@ -1055,7 +1055,7 @@ impl LayoutThread {
.send(ConstellationMsg::ViewportConstrained(self.id, constraints)) .send(ConstellationMsg::ViewportConstrained(self.id, constraints))
.unwrap(); .unwrap();
} }
if data.document_stylesheets.iter().any(|sheet| sheet.dirty_on_viewport_size_change) { if data.document_stylesheets.iter().any(|sheet| sheet.dirty_on_viewport_size_change()) {
let mut iter = node.traverse_preorder(); let mut iter = node.traverse_preorder();
let mut next = iter.next(); let mut next = iter.next();

View file

@ -21,6 +21,7 @@ use html5ever_atoms::LocalName;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use style::attr::AttrValue; use style::attr::AttrValue;
use style::str::HTML_SPACE_CHARACTERS; use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{Stylesheet, CssRule, Origin}; use style::stylesheets::{Stylesheet, CssRule, Origin};
@ -101,7 +102,7 @@ impl HTMLMetaElement {
media: Default::default(), media: Default::default(),
// Viewport constraints are always recomputed on resize; they don't need to // Viewport constraints are always recomputed on resize; they don't need to
// force all styles to be recomputed. // force all styles to be recomputed.
dirty_on_viewport_size_change: false, dirty_on_viewport_size_change: AtomicBool::new(false),
})); }));
let doc = document_from_node(self); let doc = document_from_node(self);
doc.invalidate_stylesheets(); doc.invalidate_stylesheets();

View file

@ -22,6 +22,7 @@ use servo_url::ServoUrl;
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use style_traits::ToCss; use style_traits::ToCss;
use viewport::ViewportRule; use viewport::ViewportRule;
@ -59,7 +60,7 @@ pub struct Stylesheet {
/// List of media associated with the Stylesheet. /// List of media associated with the Stylesheet.
pub media: Arc<RwLock<MediaList>>, pub media: Arc<RwLock<MediaList>>,
pub origin: Origin, pub origin: Origin,
pub dirty_on_viewport_size_change: bool, pub dirty_on_viewport_size_change: AtomicBool,
} }
@ -215,11 +216,29 @@ impl Stylesheet {
origin: origin, origin: origin,
rules: rules.into(), rules: rules.into(),
media: Arc::new(RwLock::new(media)), media: Arc::new(RwLock::new(media)),
dirty_on_viewport_size_change: dirty_on_viewport_size_change: AtomicBool::new(input.seen_viewport_percentages()),
input.seen_viewport_percentages(),
} }
} }
pub fn dirty_on_viewport_size_change(&self) -> bool {
self.dirty_on_viewport_size_change.load(Ordering::SeqCst)
}
/// When CSSOM inserts a rule or declaration into this stylesheet, it needs to call this method
/// with the return value of `cssparser::Parser::seen_viewport_percentages`.
///
/// FIXME: actually make these calls
///
/// Note: when *removing* a rule or declaration that contains a viewport percentage,
/// to keep the flag accurate wed need to iterator through the rest of the stylesheet to
/// check for *other* such values.
///
/// Instead, we conservatively assume there might be some.
/// Restyling will some some more work than necessary, but give correct results.
pub fn inserted_has_viewport_percentages(&self, has_viewport_percentages: bool) {
self.dirty_on_viewport_size_change.fetch_or(has_viewport_percentages, Ordering::SeqCst);
}
/// Returns whether the style-sheet applies for the current device depending /// Returns whether the style-sheet applies for the current device depending
/// on the associated MediaList. /// on the associated MediaList.
/// ///

View file

@ -12,6 +12,7 @@ use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::atomic::AtomicBool;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage}; use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
@ -55,7 +56,7 @@ fn test_parse_stylesheet() {
let expected = Stylesheet { let expected = Stylesheet {
origin: Origin::UserAgent, origin: Origin::UserAgent,
media: Default::default(), media: Default::default(),
dirty_on_viewport_size_change: false, dirty_on_viewport_size_change: AtomicBool::new(false),
rules: vec![ rules: vec![
CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule { CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule {
prefix: None, prefix: None,