From 4e6fd5693a5243c086e4a03084d17a17fadc269f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 26 Sep 2017 14:30:16 +0200 Subject: [PATCH 1/3] style: Cleanup some media-query-related code. --- components/style/gecko/media_queries.rs | 14 +++++++------- components/style/servo/media_queries.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 2e298431820..130651cbd72 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -695,11 +695,12 @@ impl Expression { self.evaluate_against(device, &value, quirks_mode) } - fn evaluate_against(&self, - device: &Device, - actual_value: &MediaExpressionValue, - quirks_mode: QuirksMode) - -> bool { + fn evaluate_against( + &self, + device: &Device, + actual_value: &MediaExpressionValue, + quirks_mode: QuirksMode, + ) -> bool { use self::MediaExpressionValue::*; use std::cmp::Ordering; @@ -721,8 +722,7 @@ impl Expression { font_metrics_provider: &provider, cached_system_font: None, in_media_query: true, - // TODO: pass the correct value here. - quirks_mode: quirks_mode, + quirks_mode, for_smil_animation: false, for_non_inherited_property: None, rule_cache_conditions: RefCell::new(&mut conditions), diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index bd6b2a1f003..36e64ee47da 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -265,7 +265,7 @@ impl Range { font_metrics_provider: &ServoMetricsProvider, in_media_query: true, cached_system_font: None, - quirks_mode: quirks_mode, + quirks_mode, for_smil_animation: false, for_non_inherited_property: None, rule_cache_conditions: RefCell::new(&mut conditions), From 8a51a4eb0136f2575b518491985763c76a6c330c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 26 Sep 2017 14:48:49 +0200 Subject: [PATCH 2/3] style: Reformat a bunch of signatures in wrapper.rs --- components/style/gecko/wrapper.rs | 201 +++++++++++++++++------------- 1 file changed, 114 insertions(+), 87 deletions(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index e4f2ad31b4b..0c7fd22ed31 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -187,7 +187,7 @@ impl<'ln> GeckoNode<'ln> { /// WARNING: This logic is duplicated in Gecko's FlattenedTreeParentIsParent. /// Make sure to mirror any modifications in both places. fn flattened_tree_parent_is_parent(&self) -> bool { - use ::gecko_bindings::structs::*; + use gecko_bindings::structs::*; let flags = self.flags(); if flags & (NODE_MAY_BE_IN_BINDING_MNGR as u32 | NODE_IS_IN_SHADOW_TREE as u32) != 0 { @@ -448,12 +448,14 @@ impl<'le> fmt::Debug for GeckoElement<'le> { impl<'le> GeckoElement<'le> { /// Parse the style attribute of an element. - pub fn parse_style_attribute(value: &str, - url_data: &UrlExtraData, - quirks_mode: QuirksMode, - reporter: &R) - -> PropertyDeclarationBlock - where R: ParseErrorReporter + pub fn parse_style_attribute( + value: &str, + url_data: &UrlExtraData, + quirks_mode: QuirksMode, + reporter: &R, + ) -> PropertyDeclarationBlock + where + R: ParseErrorReporter, { parse_style_attribute(value, url_data, reporter, quirks_mode) } @@ -480,7 +482,7 @@ impl<'le> GeckoElement<'le> { /// Returns true if this element has descendants for lazy frame construction. pub fn descendants_need_frames(&self) -> bool { - self.flags() & (NODE_DESCENDANTS_NEED_FRAMES as u32) != 0 + self.flags() & (NODE_DESCENDANTS_NEED_FRAMES as u32) != 0 } /// Returns true if this element needs lazy frame construction. @@ -507,7 +509,8 @@ impl<'le> GeckoElement<'le> { /// Returns true if this element has a shadow root. fn has_shadow_root(&self) -> bool { - self.get_extended_slots().map_or(false, |slots| !slots.mShadowRoot.mRawPtr.is_null()) + self.get_extended_slots() + .map_or(false, |slots| !slots.mShadowRoot.mRawPtr.is_null()) } /// Returns a reference to the DOM slots for this Element, if they exist. @@ -517,10 +520,11 @@ impl<'le> GeckoElement<'le> { } /// Returns a reference to the extended DOM slots for this Element. - fn get_extended_slots(&self) -> Option<&structs::FragmentOrElement_nsExtendedDOMSlots> { - self.get_dom_slots().and_then(|s| { - unsafe { s.mExtendedSlots.mPtr.as_ref() } - }) + fn get_extended_slots( + &self, + ) -> Option<&structs::FragmentOrElement_nsExtendedDOMSlots> { + self.get_dom_slots() + .and_then(|s| unsafe { s.mExtendedSlots.mPtr.as_ref() }) } #[inline] @@ -534,7 +538,8 @@ impl<'le> GeckoElement<'le> { #[inline] fn get_xbl_binding_with_content(&self) -> Option { - self.get_xbl_binding().and_then(|b| b.get_binding_with_content()) + self.get_xbl_binding() + .and_then(|b| b.get_binding_with_content()) } #[inline] @@ -551,23 +556,23 @@ impl<'le> GeckoElement<'le> { // FIXME(heycam): Having trouble with bindgen on nsXULElement, // where the binding parent is stored in a member variable // rather than in slots. So just get it through FFI for now. - unsafe { bindings::Gecko_GetBindingParent(self.0).map(GeckoElement) } + unsafe { + bindings::Gecko_GetBindingParent(self.0).map(GeckoElement) + } } else { - let binding_parent = - unsafe { self.get_non_xul_xbl_binding_parent_raw_content().as_ref() } - .map(GeckoNode::from_content) - .and_then(|n| n.as_element()); - debug_assert!(binding_parent == - unsafe { bindings::Gecko_GetBindingParent(self.0).map(GeckoElement) }); + let binding_parent = unsafe { + self.get_non_xul_xbl_binding_parent_raw_content().as_ref() + }.map(GeckoNode::from_content) + .and_then(|n| n.as_element()); + debug_assert!(binding_parent == unsafe { bindings::Gecko_GetBindingParent(self.0).map(GeckoElement) }); binding_parent } } fn get_non_xul_xbl_binding_parent_raw_content(&self) -> *mut nsIContent { debug_assert!(!self.is_xul_element()); - self.get_extended_slots().map_or(ptr::null_mut(), |slots| { - slots.mBindingParent - }) + self.get_extended_slots() + .map_or(ptr::null_mut(), |slots| slots.mBindingParent) } fn has_xbl_binding_parent(&self) -> bool { @@ -639,7 +644,8 @@ impl<'le> GeckoElement<'le> { #[inline] fn may_have_class(&self) -> bool { - self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementMayHaveClass) + self.as_node() + .get_bool_flag(nsINode_BooleanFlag::ElementMayHaveClass) } #[inline] @@ -655,15 +661,13 @@ impl<'le> GeckoElement<'le> { return None; } - unsafe { - bindings::Gecko_GetBeforeOrAfterPseudo(self.0, is_before) - .map(GeckoElement) - } + unsafe { bindings::Gecko_GetBeforeOrAfterPseudo(self.0, is_before).map(GeckoElement) } } #[inline] fn may_have_style_attribute(&self) -> bool { - self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementMayHaveStyle) + self.as_node() + .get_bool_flag(nsINode_BooleanFlag::ElementMayHaveStyle) } #[inline] @@ -682,9 +686,11 @@ impl<'le> GeckoElement<'le> { /// This function is also called after display property changed for SMIL animation. /// /// Also this function schedules style flush. - unsafe fn maybe_restyle<'a>(&self, - data: &'a mut ElementData, - animation_only: bool) -> bool { + unsafe fn maybe_restyle<'a>( + &self, + data: &'a mut ElementData, + animation_only: bool, + ) -> bool { if !data.has_styles() { return false; } @@ -701,9 +707,11 @@ impl<'le> GeckoElement<'le> { } /// Set restyle and change hints to the element data. - pub fn note_explicit_hints(&self, - restyle_hint: nsRestyleHint, - change_hint: nsChangeHint) { + pub fn note_explicit_hints( + &self, + restyle_hint: nsRestyleHint, + change_hint: nsChangeHint, + ) { use gecko::restyle_damage::GeckoRestyleDamage; use invalidation::element::restyle_hints::RestyleHint; @@ -721,7 +729,11 @@ impl<'le> GeckoElement<'le> { self.maybe_restyle(d, restyle_hint.has_animation_hint()) }); if should_restyle { - maybe_data.as_mut().unwrap().hint.insert(restyle_hint.into()); + maybe_data + .as_mut() + .unwrap() + .hint + .insert(restyle_hint.into()); maybe_data.as_mut().unwrap().damage |= damage; } else { debug!("(Element not styled, discarding hints)"); @@ -787,9 +799,10 @@ fn selector_flags_to_node_flags(flags: ElementSelectorFlags) -> u32 { gecko_flags } -fn get_animation_rule(element: &GeckoElement, - cascade_level: CascadeLevel) - -> Option>> { +fn get_animation_rule( + element: &GeckoElement, + cascade_level: CascadeLevel, +) -> Option>> { use gecko_bindings::sugar::ownership::HasSimpleFFI; // Also, we should try to reuse the PDB, to avoid creating extra rule nodes. let mut animation_values = AnimationValueMap::default(); @@ -837,23 +850,29 @@ impl FontMetricsProvider for GeckoFontMetricsProvider { if let Some(sizes) = cache.iter().find(|el| el.0 == *font_name) { return sizes.1.size_for_generic(font_family); } - let sizes = unsafe { - Gecko_GetBaseSize(font_name.as_ptr()) - }; + let sizes = unsafe { Gecko_GetBaseSize(font_name.as_ptr()) }; cache.push((font_name.clone(), sizes)); sizes.size_for_generic(font_family) } - fn query(&self, font: &Font, font_size: Au, wm: WritingMode, - in_media_query: bool, device: &Device) -> FontMetricsQueryResult { + fn query( + &self, + font: &Font, + font_size: Au, + wm: WritingMode, + in_media_query: bool, + device: &Device, + ) -> FontMetricsQueryResult { use gecko_bindings::bindings::Gecko_GetFontMetrics; let gecko_metrics = unsafe { - Gecko_GetFontMetrics(device.pres_context(), - wm.is_vertical() && !wm.is_sideways(), - font.gecko(), - font_size.0, - // we don't use the user font set in a media query - !in_media_query) + Gecko_GetFontMetrics( + device.pres_context(), + wm.is_vertical() && !wm.is_sideways(), + font.gecko(), + font_size.0, + // we don't use the user font set in a media query + !in_media_query, + ) }; let metrics = FontMetrics { x_height: Au(gecko_metrics.mXSize), @@ -886,7 +905,9 @@ impl<'le> TElement for GeckoElement<'le> { if self.is_native_anonymous() { self.closest_non_native_anonymous_ancestor() } else { - self.as_node().flattened_tree_parent().and_then(|n| n.as_element()) + self.as_node() + .flattened_tree_parent() + .and_then(|n| n.as_element()) } } @@ -987,13 +1008,15 @@ impl<'le> TElement for GeckoElement<'le> { } } - fn get_animation_rule(&self) - -> Option>> { + fn get_animation_rule( + &self, + ) -> Option>> { get_animation_rule(self, CascadeLevel::Animations) } - fn get_transition_rule(&self) - -> Option>> { + fn get_transition_rule( + &self, + ) -> Option>> { get_animation_rule(self, CascadeLevel::Transitions) } @@ -1004,20 +1027,17 @@ impl<'le> TElement for GeckoElement<'le> { #[inline] fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool { unsafe { - bindings::Gecko_HasAttr(self.0, - namespace.0.as_ptr(), - attr.as_ptr()) + bindings::Gecko_HasAttr(self.0, namespace.0.as_ptr(), attr.as_ptr()) } } fn get_id(&self) -> Option { if !self.has_id() { - return None + return None; } let ptr = unsafe { - bindings::Gecko_AtomAttrValue(self.0, - atom!("id").as_ptr()) + bindings::Gecko_AtomAttrValue(self.0, atom!("id").as_ptr()) }; if ptr.is_null() { @@ -1028,11 +1048,10 @@ impl<'le> TElement for GeckoElement<'le> { } fn each_class(&self, callback: F) - where F: FnMut(&Atom) + where + F: FnMut(&Atom), { - snapshot_helpers::each_class(self.0, - callback, - Gecko_ClassOrClassList) + snapshot_helpers::each_class(self.0, callback, Gecko_ClassOrClassList) } #[inline] @@ -1299,8 +1318,9 @@ impl<'le> TElement for GeckoElement<'le> { .map(GeckoNode::from_content) } - fn get_css_transitions_info(&self) - -> HashMap> { + fn get_css_transitions_info( + &self, + ) -> HashMap> { use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt; use gecko_bindings::bindings::Gecko_ElementTransitions_Length; use gecko_bindings::bindings::Gecko_ElementTransitions_PropertyAt; @@ -1320,9 +1340,11 @@ impl<'le> TElement for GeckoElement<'le> { map } - fn might_need_transitions_update(&self, - old_values: Option<&ComputedValues>, - new_values: &ComputedValues) -> bool { + fn might_need_transitions_update( + &self, + old_values: Option<&ComputedValues>, + new_values: &ComputedValues, + ) -> bool { use properties::longhands::display::computed_value as display; let old_values = match old_values { @@ -1527,10 +1549,13 @@ impl<'le> Hash for GeckoElement<'le> { } impl<'le> PresentationalHintsSynthesizer for GeckoElement<'le> { - fn synthesize_presentational_hints_for_legacy_attributes(&self, - visited_handling: VisitedHandlingMode, - hints: &mut V) - where V: Push, + fn synthesize_presentational_hints_for_legacy_attributes( + &self, + visited_handling: VisitedHandlingMode, + hints: &mut V + ) + where + V: Push, { use properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang; use properties::longhands::_x_text_zoom::SpecifiedValue as SpecifiedZoom; @@ -1826,13 +1851,15 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { } } - fn match_non_ts_pseudo_class(&self, - pseudo_class: &NonTSPseudoClass, - context: &mut LocalMatchingContext, - relevant_link: &RelevantLinkStatus, - flags_setter: &mut F) - -> bool - where F: FnMut(&Self, ElementSelectorFlags), + fn match_non_ts_pseudo_class( + &self, + pseudo_class: &NonTSPseudoClass, + context: &mut LocalMatchingContext, + relevant_link: &RelevantLinkStatus, + flags_setter: &mut F, + ) -> bool + where + F: FnMut(&Self, ElementSelectorFlags), { use selectors::matching::*; match *pseudo_class { @@ -1976,11 +2003,11 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { } } - fn match_pseudo_element(&self, - pseudo_element: &PseudoElement, - _context: &mut MatchingContext) - -> bool - { + fn match_pseudo_element( + &self, + pseudo_element: &PseudoElement, + _context: &mut MatchingContext + ) -> bool { // TODO(emilio): I believe we could assert we are a pseudo-element and // match the proper pseudo-element, given how we rulehash the stuff // based on the pseudo. From 2bf84ba4683b2621c797017c7f17e26ac0df3b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 26 Sep 2017 14:52:00 +0200 Subject: [PATCH 3/3] style: There are no more ua_sheets. --- components/style/stylist.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 5962117fbad..5eaeeecdece 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -499,8 +499,6 @@ impl Stylist { /// Flush the list of stylesheets if they changed, ensuring the stylist is /// up-to-date. - /// - /// FIXME(emilio): Move the `ua_sheets` to the Stylist too? pub fn flush( &mut self, guards: &StylesheetGuards,