From 49d1d307bf5427ed637af8ec126165c121f08095 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 4 Mar 2016 10:52:46 -0800 Subject: [PATCH 1/2] Record whether viewport percentage dimensions are seen Used to tell Servo to recalulate styles on window resize (servo/servo#8754). --- src/parser.rs | 14 ++++++++++++++ src/tokenizer.rs | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index df827173..2240c4de 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -236,6 +236,20 @@ impl<'i, 't> Parser<'i, 't> { self.tokenizer.seen_var_functions() } + /// Start looking for viewport percentage lengths. (See the `seen_viewport_percentages` + /// method.) + #[inline] + pub fn look_for_viewport_percentages(&mut self) { + self.tokenizer.look_for_viewport_percentages() + } + + /// Return whether a `vh`, `vw`, `vmin`, or `vmax` dimension has been seen by the tokenizer + /// since `look_for_viewport_percentages` was called, and stop looking. + #[inline] + pub fn seen_viewport_percentages(&mut self) -> bool { + self.tokenizer.seen_viewport_percentages() + } + /// Execute the given closure, passing it the parser. /// If the result (returned unchanged) is `Err`, /// the internal state of the parser (including position within the input) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index a2ba721d..ebf032ac 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -211,11 +211,12 @@ pub struct Tokenizer<'a> { position: usize, /// Cache for `source_location()` last_known_line_break: Cell<(usize, usize)>, - var_functions: VarFunctions, + var_functions: SeenStatus, + viewport_percentages: SeenStatus, } #[derive(Copy, Clone, PartialEq, Eq)] -enum VarFunctions { +enum SeenStatus { DontCare, LookingForThem, SeenAtLeastOne, @@ -229,19 +230,32 @@ impl<'a> Tokenizer<'a> { input: input, position: 0, last_known_line_break: Cell::new((1, 0)), - var_functions: VarFunctions::DontCare, + var_functions: SeenStatus::DontCare, + viewport_percentages: SeenStatus::DontCare, } } #[inline] pub fn look_for_var_functions(&mut self) { - self.var_functions = VarFunctions::LookingForThem; + self.var_functions = SeenStatus::LookingForThem; } #[inline] pub fn seen_var_functions(&mut self) -> bool { - let seen = self.var_functions == VarFunctions::SeenAtLeastOne; - self.var_functions = VarFunctions::DontCare; + let seen = self.var_functions == SeenStatus::SeenAtLeastOne; + self.var_functions = SeenStatus::DontCare; + seen + } + + #[inline] + pub fn look_for_viewport_percentages(&mut self) { + self.viewport_percentages = SeenStatus::LookingForThem; + } + + #[inline] + pub fn seen_viewport_percentages(&mut self) -> bool { + let seen = self.viewport_percentages == SeenStatus::SeenAtLeastOne; + self.viewport_percentages = SeenStatus::DontCare; seen } @@ -630,9 +644,9 @@ fn consume_ident_like<'a>(tokenizer: &mut Tokenizer<'a>) -> Token<'a> { if value.eq_ignore_ascii_case("url") { consume_unquoted_url(tokenizer).unwrap_or(Function(value)) } else { - if tokenizer.var_functions == VarFunctions::LookingForThem && + if tokenizer.var_functions == SeenStatus::LookingForThem && value.eq_ignore_ascii_case("var") { - tokenizer.var_functions = VarFunctions::SeenAtLeastOne; + tokenizer.var_functions = SeenStatus::SeenAtLeastOne; } Function(value) } @@ -784,7 +798,16 @@ fn consume_numeric<'a>(tokenizer: &mut Tokenizer<'a>) -> Token<'a> { has_sign: has_sign, }; if is_ident_start(tokenizer) { - Dimension(value, consume_name(tokenizer)) + let name = consume_name(tokenizer); + if tokenizer.viewport_percentages == SeenStatus::LookingForThem { + if name.eq_ignore_ascii_case("vh") || + name.eq_ignore_ascii_case("vw") || + name.eq_ignore_ascii_case("vmin") || + name.eq_ignore_ascii_case("vmax") { + tokenizer.viewport_percentages = SeenStatus::SeenAtLeastOne; + } + } + Dimension(value, name) } else { Number(value) } From 81523c406a767a8edec2f896de5093ec184db3ae Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 18 Mar 2016 16:32:31 -0700 Subject: [PATCH 2/2] Version 0.5.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 35655002..bb7e4e62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cssparser" -version = "0.5.4" +version = "0.5.5" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3"