viewport_units.rs (2105B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 //! Invalidates style of all elements that depend on viewport units. 6 7 use crate::data::ViewportUnitUsage; 8 use crate::dom::{TElement, TNode}; 9 use crate::invalidation::element::restyle_hints::RestyleHint; 10 11 /// Invalidates style of all elements that depend on viewport units. 12 /// 13 /// Returns whether any element was invalidated. 14 pub fn invalidate<E>(root: E) -> bool 15 where 16 E: TElement, 17 { 18 debug!("invalidation::viewport_units::invalidate({:?})", root); 19 invalidate_recursively(root) 20 } 21 22 fn invalidate_recursively<E>(element: E) -> bool 23 where 24 E: TElement, 25 { 26 let mut data = match element.mutate_data() { 27 Some(data) => data, 28 None => return false, 29 }; 30 31 if data.hint.will_recascade_subtree() { 32 debug!("invalidate_recursively: {:?} was already invalid", element); 33 return false; 34 } 35 36 let usage = data.styles.viewport_unit_usage(); 37 let uses_viewport_units = usage != ViewportUnitUsage::None; 38 if uses_viewport_units { 39 debug!( 40 "invalidate_recursively: {:?} uses viewport units {:?}", 41 element, usage 42 ); 43 } 44 45 match usage { 46 ViewportUnitUsage::None => {}, 47 ViewportUnitUsage::FromQuery => { 48 data.hint.insert(RestyleHint::RESTYLE_SELF); 49 }, 50 ViewportUnitUsage::FromDeclaration => { 51 data.hint.insert(RestyleHint::RECASCADE_SELF); 52 }, 53 } 54 55 let mut any_children_invalid = false; 56 for child in element.traversal_children() { 57 if let Some(child) = child.as_element() { 58 any_children_invalid |= invalidate_recursively(child); 59 } 60 } 61 62 if any_children_invalid { 63 debug!( 64 "invalidate_recursively: Children of {:?} changed, setting dirty descendants", 65 element 66 ); 67 unsafe { element.set_dirty_descendants() } 68 } 69 70 uses_viewport_units || any_children_invalid 71 }