From 00b42fc6ef6c123c4ab1bb97ac65603e13e20d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 May 2018 20:11:22 +0200 Subject: [PATCH 01/19] style: Remove some cfgs. --- components/style/properties/declaration_block.rs | 4 +--- .../style/properties/helpers/animated_properties.mako.rs | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 4e368c0c2b7..2319ded2e14 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -24,7 +24,7 @@ use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCs use stylesheets::{CssRuleType, Origin, UrlExtraData}; use super::*; use values::computed::Context; -#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap; +use properties::animated_properties::AnimationValueMap; /// The animation rules. /// @@ -667,7 +667,6 @@ impl PropertyDeclarationBlock { } /// Convert AnimationValueMap to PropertyDeclarationBlock. - #[cfg(feature = "gecko")] pub fn from_animation_value_map(animation_value_map: &AnimationValueMap) -> Self { let len = animation_value_map.len(); let mut declarations = Vec::with_capacity(len); @@ -687,7 +686,6 @@ impl PropertyDeclarationBlock { /// Returns true if the declaration block has a CSSWideKeyword for the given /// property. - #[cfg(feature = "gecko")] pub fn has_css_wide_keyword(&self, property: &PropertyId) -> bool { if let Some(id) = property.longhand_id() { if !self.longhands.contains(id) { diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index de0e48c782d..7a34cc4ade4 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -25,7 +25,7 @@ use servo_arc::Arc; use smallvec::SmallVec; use std::{cmp, ptr}; use std::mem::{self, ManuallyDrop}; -#[cfg(feature = "gecko")] use hash::FnvHashMap; +use hash::FnvHashMap; use super::ComputedValues; use values::CSSFloat; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; @@ -229,8 +229,8 @@ impl AnimatedProperty { /// A collection of AnimationValue that were composed on an element. /// This HashMap stores the values that are the last AnimationValue to be /// composed for each TransitionProperty. -#[cfg(feature = "gecko")] pub type AnimationValueMap = FnvHashMap; + #[cfg(feature = "gecko")] unsafe impl HasFFI for AnimationValueMap { type FFIType = RawServoAnimationValueMap; From e6f9ad0edbeb8ce2974b11115d5bd7cd284d4934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 18 Jun 2018 12:30:24 +0200 Subject: [PATCH 02/19] style: Don't call the before change closure with the locked declaration block. Test Plan: No behavior change. Reviewers: xidorn Bug #: 1468665 Differential Revision: https://phabricator.services.mozilla.com/D1681 --- .../style/properties/declaration_block.rs | 94 +++++++++++-------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 2319ded2e14..cd89a4bbfbb 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -564,51 +564,71 @@ impl PropertyDeclarationBlock { true } + /// Returns the first declaration that would be removed by removing + /// `property`. + #[inline] + pub fn first_declaration_to_remove( + &self, + property: &PropertyId, + ) -> Option { + if let Some(id) = property.longhand_id() { + if !self.longhands.contains(id) { + return None; + } + } + + self.declarations.iter().position(|declaration| { + declaration.id().is_or_is_longhand_of(property) + }) + } + + /// Removes a given declaration at a given index. + #[inline] + fn remove_declaration_at(&mut self, i: usize) { + { + let id = self.declarations[i].id(); + if let PropertyDeclarationId::Longhand(id) = id { + self.longhands.remove(id); + } + self.declarations_importance.remove(i); + } + self.declarations.remove(i); + } + /// /// - /// Returns whether any declaration was actually removed. - pub fn remove_property( + /// `first_declaration` needs to be the result of + /// `first_declaration_to_remove`. + #[inline] + pub fn remove_property( &mut self, property: &PropertyId, - mut before_change_callback: C, - ) -> bool - where - C: FnMut(&Self), - { - let longhand_id = property.longhand_id(); - if let Some(id) = longhand_id { - if !self.longhands.contains(id) { - return false - } - } - let mut removed_at_least_one = false; - let mut i = 0; + first_declaration: usize, + ) { + debug_assert_eq!( + Some(first_declaration), + self.first_declaration_to_remove(property) + ); + debug_assert!(self.declarations[first_declaration].id().is_or_is_longhand_of(property)); + + self.remove_declaration_at(first_declaration); + + let shorthand = match property.as_shorthand() { + Ok(s) => s, + Err(_longhand_or_custom) => return, + }; + + let mut i = first_declaration; let mut len = self.len(); while i < len { - { - let id = self.declarations[i].id(); - if !id.is_or_is_longhand_of(property) { - i += 1; - continue; - } - - if !removed_at_least_one { - before_change_callback(&*self); - } - removed_at_least_one = true; - if let PropertyDeclarationId::Longhand(id) = id { - self.longhands.remove(id); - } - self.declarations_importance.remove(i); + if !self.declarations[i].id().is_longhand_of(shorthand) { + i += 1; + continue; } - self.declarations.remove(i); + + self.remove_declaration_at(i); len -= 1; } - - if longhand_id.is_some() { - debug_assert!(removed_at_least_one); - } - removed_at_least_one } /// Take a declaration block known to contain a single property and serialize it. @@ -725,9 +745,7 @@ impl PropertyDeclarationBlock { builder.build() } -} -impl PropertyDeclarationBlock { /// Like the method on ToCss, but without the type parameter to avoid /// accidentally monomorphizing this large function multiple times for /// different writers. From 8db8f95f1f80bcdccec48e313ccbb0a3b131822a Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 11 May 2018 10:12:17 +1000 Subject: [PATCH 03/19] style: Add scrollcorner to -moz-appearance so that widget can render it. Bug: 1463917 Reviewed-by: heycam MozReview-Commit-ID: 1Za22ifONfG --- components/style/properties/longhand/box.mako.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index aea51fed766..ce04a0a66d2 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -606,8 +606,9 @@ ${helpers.single_keyword("-moz-appearance", scalethumb-horizontal scalethumbstart scalethumbtick scalethumb-vertical scale-vertical scrollbar scrollbar-horizontal scrollbar-small scrollbar-vertical scrollbarbutton-down scrollbarbutton-left scrollbarbutton-right scrollbarbutton-up scrollbarthumb-horizontal - scrollbarthumb-vertical scrollbartrack-horizontal scrollbartrack-vertical searchfield - separator spinner spinner-downbutton spinner-textfield spinner-upbutton splitter statusbar + scrollbarthumb-vertical scrollbartrack-horizontal scrollbartrack-vertical scrollcorner + searchfield separator + spinner spinner-downbutton spinner-textfield spinner-upbutton splitter statusbar statusbarpanel tab tabpanel tabpanels tab-scroll-arrow-back tab-scroll-arrow-forward textfield textfield-multiline toolbar toolbarbutton toolbarbutton-dropdown toolbargripper toolbox tooltip treeheader treeheadercell treeheadersortarrow treeitem treeline treetwisty From 3b90ddd5d164c51837190b1134d1f9abb82fcd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 16 Jun 2018 02:50:28 -0700 Subject: [PATCH 04/19] style: Fix the broken invariants of the rule node cache. We were spuriously reframing the because it initially shared style with the
, which ended up being display: none, while the should've been display: contents from the beginning. lookup_by_rules seems pretty prone to obscure bugs, and also it's pretty complex... Probably we should try to get rid of it, I'm unconvinced that it's worth it. Even with that, in a normal restyle the
wouldn't have ended up with a style. It of course never had it before the reframe because the was display: none, but that doesn't mean it shouldn't have gotten one, since we detected we needed to go through kids in: https://searchfox.org/mozilla-central/rev/6eea08365e7386a2b81c044e7cc8a3daa51d8754/servo/components/style/matching.rs#500 That code did happen, but since it's an animation-only restyle, we don't look at unstyled stuff. That looks somewhat fishy, but I guess for now it's fine as long as display isn't animatable. Bug: 1469076 Reviewed-by: heycam MozReview-Commit-ID: B6NMSTNOKgK --- components/style/sharing/mod.rs | 17 +++++++++++++++-- components/style/style_adjuster.rs | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index 314e9877083..d6148d16b49 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -815,7 +815,11 @@ impl StyleSharingCache { Some(candidate.element.borrow_data().unwrap().share_styles()) } - /// Attempts to find an element in the cache with the given primary rule node and parent. + /// Attempts to find an element in the cache with the given primary rule + /// node and parent. + /// + /// FIXME(emilio): re-measure this optimization, and remove if it's not very + /// useful... It's probably not worth the complexity / obscure bugs. pub fn lookup_by_rules( &mut self, shared_context: &SharedStyleContext, @@ -841,7 +845,15 @@ impl StyleSharingCache { if style.visited_rules() != visited_rules { return None; } - + // NOTE(emilio): We only need to check name / namespace because we + // do name-dependent style adjustments, like the display: contents + // to display: none adjustment. + if target.namespace() != candidate.element.namespace() { + return None; + } + if target.local_name() != candidate.element.local_name() { + return None; + } // Rule nodes and styles are computed independent of the element's // actual visitedness, but at the end of the cascade (in // `adjust_for_visited`) we do store the visitedness as a flag in @@ -853,6 +865,7 @@ impl StyleSharingCache { // FIXME(jryans): This seems like it breaks the constant time // requirements of visited, assuming we get a cache hit on only one // of unvisited vs. visited. + // TODO(emilio): We no longer have such a flag, remove this check. if target.is_visited_link() != candidate.element.is_visited_link() { return None; } diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 8bbc40ca8c6..3983c780894 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -19,6 +19,14 @@ use properties::longhands::position::computed_value::T as Position; /// NOTE(emilio): If new adjustments are introduced that depend on reset /// properties of the parent, you may need tweaking the /// `ChildCascadeRequirement` code in `matching.rs`. +/// +/// NOTE(emilio): Also, if new adjustments are introduced that break the +/// following invariant: +/// +/// Given same tag name, namespace, rules and parent style, two elements would +/// end up with exactly the same style. +/// +/// Then you need to adjust the lookup_by_rules conditions in the sharing cache. pub struct StyleAdjuster<'a, 'b: 'a> { style: &'a mut StyleBuilder<'b>, } From 5c15c59f56934b1ce6b0038976cccbbd21aafdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 13 Jun 2018 15:31:05 -0700 Subject: [PATCH 05/19] style: remove shorthand/serialize.mako.rs. Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: 8Xyep2Q7trR --- .../style/properties/properties.mako.rs | 27 ++++++++++++++++++- .../properties/shorthand/serialize.mako.rs | 27 ------------------- 2 files changed, 26 insertions(+), 28 deletions(-) delete mode 100644 components/style/properties/shorthand/serialize.mako.rs diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 4d18e0ca634..e74fc888e4e 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -137,7 +137,32 @@ pub mod shorthands { use style_traits::{ParseError, StyleParseErrorKind}; use values::specified; - <%include file="/shorthand/serialize.mako.rs" /> + use style_traits::{CssWriter, ToCss}; + use values::specified::{BorderStyle, Color}; + use std::fmt::{self, Write}; + + fn serialize_directional_border( + dest: &mut CssWriter, + width: &I, + style: &BorderStyle, + color: &Color, + ) -> fmt::Result + where + W: Write, + I: ToCss, + { + width.to_css(dest)?; + // FIXME(emilio): Should we really serialize the border style if it's + // `solid`? + dest.write_str(" ")?; + style.to_css(dest)?; + if *color != Color::CurrentColor { + dest.write_str(" ")?; + color.to_css(dest)?; + } + Ok(()) + } + <%include file="/shorthand/background.mako.rs" /> <%include file="/shorthand/border.mako.rs" /> <%include file="/shorthand/box.mako.rs" /> diff --git a/components/style/properties/shorthand/serialize.mako.rs b/components/style/properties/shorthand/serialize.mako.rs deleted file mode 100644 index afcbe3c488b..00000000000 --- a/components/style/properties/shorthand/serialize.mako.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use style_traits::{CssWriter, ToCss}; -use values::specified::{BorderStyle, Color}; -use std::fmt::{self, Write}; - -fn serialize_directional_border( - dest: &mut CssWriter, - width: &I, - style: &BorderStyle, - color: &Color, -) -> fmt::Result -where - W: Write, - I: ToCss, -{ - width.to_css(dest)?; - dest.write_str(" ")?; - style.to_css(dest)?; - if *color != Color::CurrentColor { - dest.write_str(" ")?; - color.to_css(dest)?; - } - Ok(()) -} From 0a95513368a31f3d9102a8bed2736bedf913e541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Jun 2018 13:05:25 +0200 Subject: [PATCH 06/19] style: Rename the properties directories from "shorthand" to "shorthands", "longhand" to "longhands". Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: CY4THCC4zkX --- .../background.mako.rs | 0 .../{longhand => longhands}/border.mako.rs | 0 .../{longhand => longhands}/box.mako.rs | 0 .../{longhand => longhands}/color.mako.rs | 0 .../{longhand => longhands}/column.mako.rs | 0 .../{longhand => longhands}/counters.mako.rs | 0 .../{longhand => longhands}/effects.mako.rs | 0 .../{longhand => longhands}/font.mako.rs | 0 .../inherited_box.mako.rs | 0 .../inherited_svg.mako.rs | 0 .../inherited_table.mako.rs | 0 .../inherited_text.mako.rs | 0 .../inherited_ui.mako.rs | 0 .../{longhand => longhands}/list.mako.rs | 0 .../{longhand => longhands}/margin.mako.rs | 0 .../{longhand => longhands}/outline.mako.rs | 0 .../{longhand => longhands}/padding.mako.rs | 0 .../{longhand => longhands}/position.mako.rs | 0 .../{longhand => longhands}/svg.mako.rs | 0 .../{longhand => longhands}/table.mako.rs | 0 .../{longhand => longhands}/text.mako.rs | 0 .../{longhand => longhands}/ui.mako.rs | 0 .../{longhand => longhands}/xul.mako.rs | 0 .../style/properties/properties.mako.rs | 74 +++++++++---------- .../background.mako.rs | 0 .../{shorthand => shorthands}/border.mako.rs | 0 .../{shorthand => shorthands}/box.mako.rs | 0 .../{shorthand => shorthands}/column.mako.rs | 0 .../{shorthand => shorthands}/font.mako.rs | 0 .../inherited_svg.mako.rs | 0 .../inherited_text.mako.rs | 0 .../{shorthand => shorthands}/list.mako.rs | 0 .../{shorthand => shorthands}/margin.mako.rs | 0 .../{shorthand => shorthands}/mask.mako.rs | 0 .../{shorthand => shorthands}/outline.mako.rs | 0 .../{shorthand => shorthands}/padding.mako.rs | 0 .../position.mako.rs | 0 .../{shorthand => shorthands}/text.mako.rs | 0 38 files changed, 37 insertions(+), 37 deletions(-) rename components/style/properties/{longhand => longhands}/background.mako.rs (100%) rename components/style/properties/{longhand => longhands}/border.mako.rs (100%) rename components/style/properties/{longhand => longhands}/box.mako.rs (100%) rename components/style/properties/{longhand => longhands}/color.mako.rs (100%) rename components/style/properties/{longhand => longhands}/column.mako.rs (100%) rename components/style/properties/{longhand => longhands}/counters.mako.rs (100%) rename components/style/properties/{longhand => longhands}/effects.mako.rs (100%) rename components/style/properties/{longhand => longhands}/font.mako.rs (100%) rename components/style/properties/{longhand => longhands}/inherited_box.mako.rs (100%) rename components/style/properties/{longhand => longhands}/inherited_svg.mako.rs (100%) rename components/style/properties/{longhand => longhands}/inherited_table.mako.rs (100%) rename components/style/properties/{longhand => longhands}/inherited_text.mako.rs (100%) rename components/style/properties/{longhand => longhands}/inherited_ui.mako.rs (100%) rename components/style/properties/{longhand => longhands}/list.mako.rs (100%) rename components/style/properties/{longhand => longhands}/margin.mako.rs (100%) rename components/style/properties/{longhand => longhands}/outline.mako.rs (100%) rename components/style/properties/{longhand => longhands}/padding.mako.rs (100%) rename components/style/properties/{longhand => longhands}/position.mako.rs (100%) rename components/style/properties/{longhand => longhands}/svg.mako.rs (100%) rename components/style/properties/{longhand => longhands}/table.mako.rs (100%) rename components/style/properties/{longhand => longhands}/text.mako.rs (100%) rename components/style/properties/{longhand => longhands}/ui.mako.rs (100%) rename components/style/properties/{longhand => longhands}/xul.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/background.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/border.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/box.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/column.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/font.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/inherited_svg.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/inherited_text.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/list.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/margin.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/mask.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/outline.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/padding.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/position.mako.rs (100%) rename components/style/properties/{shorthand => shorthands}/text.mako.rs (100%) diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhands/background.mako.rs similarity index 100% rename from components/style/properties/longhand/background.mako.rs rename to components/style/properties/longhands/background.mako.rs diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhands/border.mako.rs similarity index 100% rename from components/style/properties/longhand/border.mako.rs rename to components/style/properties/longhands/border.mako.rs diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhands/box.mako.rs similarity index 100% rename from components/style/properties/longhand/box.mako.rs rename to components/style/properties/longhands/box.mako.rs diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhands/color.mako.rs similarity index 100% rename from components/style/properties/longhand/color.mako.rs rename to components/style/properties/longhands/color.mako.rs diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhands/column.mako.rs similarity index 100% rename from components/style/properties/longhand/column.mako.rs rename to components/style/properties/longhands/column.mako.rs diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhands/counters.mako.rs similarity index 100% rename from components/style/properties/longhand/counters.mako.rs rename to components/style/properties/longhands/counters.mako.rs diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhands/effects.mako.rs similarity index 100% rename from components/style/properties/longhand/effects.mako.rs rename to components/style/properties/longhands/effects.mako.rs diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhands/font.mako.rs similarity index 100% rename from components/style/properties/longhand/font.mako.rs rename to components/style/properties/longhands/font.mako.rs diff --git a/components/style/properties/longhand/inherited_box.mako.rs b/components/style/properties/longhands/inherited_box.mako.rs similarity index 100% rename from components/style/properties/longhand/inherited_box.mako.rs rename to components/style/properties/longhands/inherited_box.mako.rs diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhands/inherited_svg.mako.rs similarity index 100% rename from components/style/properties/longhand/inherited_svg.mako.rs rename to components/style/properties/longhands/inherited_svg.mako.rs diff --git a/components/style/properties/longhand/inherited_table.mako.rs b/components/style/properties/longhands/inherited_table.mako.rs similarity index 100% rename from components/style/properties/longhand/inherited_table.mako.rs rename to components/style/properties/longhands/inherited_table.mako.rs diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs similarity index 100% rename from components/style/properties/longhand/inherited_text.mako.rs rename to components/style/properties/longhands/inherited_text.mako.rs diff --git a/components/style/properties/longhand/inherited_ui.mako.rs b/components/style/properties/longhands/inherited_ui.mako.rs similarity index 100% rename from components/style/properties/longhand/inherited_ui.mako.rs rename to components/style/properties/longhands/inherited_ui.mako.rs diff --git a/components/style/properties/longhand/list.mako.rs b/components/style/properties/longhands/list.mako.rs similarity index 100% rename from components/style/properties/longhand/list.mako.rs rename to components/style/properties/longhands/list.mako.rs diff --git a/components/style/properties/longhand/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs similarity index 100% rename from components/style/properties/longhand/margin.mako.rs rename to components/style/properties/longhands/margin.mako.rs diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhands/outline.mako.rs similarity index 100% rename from components/style/properties/longhand/outline.mako.rs rename to components/style/properties/longhands/outline.mako.rs diff --git a/components/style/properties/longhand/padding.mako.rs b/components/style/properties/longhands/padding.mako.rs similarity index 100% rename from components/style/properties/longhand/padding.mako.rs rename to components/style/properties/longhands/padding.mako.rs diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhands/position.mako.rs similarity index 100% rename from components/style/properties/longhand/position.mako.rs rename to components/style/properties/longhands/position.mako.rs diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhands/svg.mako.rs similarity index 100% rename from components/style/properties/longhand/svg.mako.rs rename to components/style/properties/longhands/svg.mako.rs diff --git a/components/style/properties/longhand/table.mako.rs b/components/style/properties/longhands/table.mako.rs similarity index 100% rename from components/style/properties/longhand/table.mako.rs rename to components/style/properties/longhands/table.mako.rs diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhands/text.mako.rs similarity index 100% rename from components/style/properties/longhand/text.mako.rs rename to components/style/properties/longhands/text.mako.rs diff --git a/components/style/properties/longhand/ui.mako.rs b/components/style/properties/longhands/ui.mako.rs similarity index 100% rename from components/style/properties/longhand/ui.mako.rs rename to components/style/properties/longhands/ui.mako.rs diff --git a/components/style/properties/longhand/xul.mako.rs b/components/style/properties/longhands/xul.mako.rs similarity index 100% rename from components/style/properties/longhand/xul.mako.rs rename to components/style/properties/longhands/xul.mako.rs diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index e74fc888e4e..a3d4787ab72 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -97,29 +97,29 @@ macro_rules! expanded { /// A module with all the code for longhand properties. #[allow(missing_docs)] pub mod longhands { - <%include file="/longhand/background.mako.rs" /> - <%include file="/longhand/border.mako.rs" /> - <%include file="/longhand/box.mako.rs" /> - <%include file="/longhand/color.mako.rs" /> - <%include file="/longhand/column.mako.rs" /> - <%include file="/longhand/counters.mako.rs" /> - <%include file="/longhand/effects.mako.rs" /> - <%include file="/longhand/font.mako.rs" /> - <%include file="/longhand/inherited_box.mako.rs" /> - <%include file="/longhand/inherited_table.mako.rs" /> - <%include file="/longhand/inherited_text.mako.rs" /> - <%include file="/longhand/inherited_ui.mako.rs" /> - <%include file="/longhand/list.mako.rs" /> - <%include file="/longhand/margin.mako.rs" /> - <%include file="/longhand/outline.mako.rs" /> - <%include file="/longhand/padding.mako.rs" /> - <%include file="/longhand/position.mako.rs" /> - <%include file="/longhand/table.mako.rs" /> - <%include file="/longhand/text.mako.rs" /> - <%include file="/longhand/ui.mako.rs" /> - <%include file="/longhand/inherited_svg.mako.rs" /> - <%include file="/longhand/svg.mako.rs" /> - <%include file="/longhand/xul.mako.rs" /> + <%include file="/longhands/background.mako.rs" /> + <%include file="/longhands/border.mako.rs" /> + <%include file="/longhands/box.mako.rs" /> + <%include file="/longhands/color.mako.rs" /> + <%include file="/longhands/column.mako.rs" /> + <%include file="/longhands/counters.mako.rs" /> + <%include file="/longhands/effects.mako.rs" /> + <%include file="/longhands/font.mako.rs" /> + <%include file="/longhands/inherited_box.mako.rs" /> + <%include file="/longhands/inherited_table.mako.rs" /> + <%include file="/longhands/inherited_text.mako.rs" /> + <%include file="/longhands/inherited_ui.mako.rs" /> + <%include file="/longhands/list.mako.rs" /> + <%include file="/longhands/margin.mako.rs" /> + <%include file="/longhands/outline.mako.rs" /> + <%include file="/longhands/padding.mako.rs" /> + <%include file="/longhands/position.mako.rs" /> + <%include file="/longhands/table.mako.rs" /> + <%include file="/longhands/text.mako.rs" /> + <%include file="/longhands/ui.mako.rs" /> + <%include file="/longhands/inherited_svg.mako.rs" /> + <%include file="/longhands/svg.mako.rs" /> + <%include file="/longhands/xul.mako.rs" /> } macro_rules! unwrap_or_initial { @@ -163,20 +163,20 @@ pub mod shorthands { Ok(()) } - <%include file="/shorthand/background.mako.rs" /> - <%include file="/shorthand/border.mako.rs" /> - <%include file="/shorthand/box.mako.rs" /> - <%include file="/shorthand/column.mako.rs" /> - <%include file="/shorthand/font.mako.rs" /> - <%include file="/shorthand/inherited_text.mako.rs" /> - <%include file="/shorthand/list.mako.rs" /> - <%include file="/shorthand/margin.mako.rs" /> - <%include file="/shorthand/mask.mako.rs" /> - <%include file="/shorthand/outline.mako.rs" /> - <%include file="/shorthand/padding.mako.rs" /> - <%include file="/shorthand/position.mako.rs" /> - <%include file="/shorthand/inherited_svg.mako.rs" /> - <%include file="/shorthand/text.mako.rs" /> + <%include file="/shorthands/background.mako.rs" /> + <%include file="/shorthands/border.mako.rs" /> + <%include file="/shorthands/box.mako.rs" /> + <%include file="/shorthands/column.mako.rs" /> + <%include file="/shorthands/font.mako.rs" /> + <%include file="/shorthands/inherited_text.mako.rs" /> + <%include file="/shorthands/list.mako.rs" /> + <%include file="/shorthands/margin.mako.rs" /> + <%include file="/shorthands/mask.mako.rs" /> + <%include file="/shorthands/outline.mako.rs" /> + <%include file="/shorthands/padding.mako.rs" /> + <%include file="/shorthands/position.mako.rs" /> + <%include file="/shorthands/inherited_svg.mako.rs" /> + <%include file="/shorthands/text.mako.rs" /> // We don't defined the 'all' shorthand using the regular helpers:shorthand // mechanism, since it causes some very large types to be generated. diff --git a/components/style/properties/shorthand/background.mako.rs b/components/style/properties/shorthands/background.mako.rs similarity index 100% rename from components/style/properties/shorthand/background.mako.rs rename to components/style/properties/shorthands/background.mako.rs diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthands/border.mako.rs similarity index 100% rename from components/style/properties/shorthand/border.mako.rs rename to components/style/properties/shorthands/border.mako.rs diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthands/box.mako.rs similarity index 100% rename from components/style/properties/shorthand/box.mako.rs rename to components/style/properties/shorthands/box.mako.rs diff --git a/components/style/properties/shorthand/column.mako.rs b/components/style/properties/shorthands/column.mako.rs similarity index 100% rename from components/style/properties/shorthand/column.mako.rs rename to components/style/properties/shorthands/column.mako.rs diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthands/font.mako.rs similarity index 100% rename from components/style/properties/shorthand/font.mako.rs rename to components/style/properties/shorthands/font.mako.rs diff --git a/components/style/properties/shorthand/inherited_svg.mako.rs b/components/style/properties/shorthands/inherited_svg.mako.rs similarity index 100% rename from components/style/properties/shorthand/inherited_svg.mako.rs rename to components/style/properties/shorthands/inherited_svg.mako.rs diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthands/inherited_text.mako.rs similarity index 100% rename from components/style/properties/shorthand/inherited_text.mako.rs rename to components/style/properties/shorthands/inherited_text.mako.rs diff --git a/components/style/properties/shorthand/list.mako.rs b/components/style/properties/shorthands/list.mako.rs similarity index 100% rename from components/style/properties/shorthand/list.mako.rs rename to components/style/properties/shorthands/list.mako.rs diff --git a/components/style/properties/shorthand/margin.mako.rs b/components/style/properties/shorthands/margin.mako.rs similarity index 100% rename from components/style/properties/shorthand/margin.mako.rs rename to components/style/properties/shorthands/margin.mako.rs diff --git a/components/style/properties/shorthand/mask.mako.rs b/components/style/properties/shorthands/mask.mako.rs similarity index 100% rename from components/style/properties/shorthand/mask.mako.rs rename to components/style/properties/shorthands/mask.mako.rs diff --git a/components/style/properties/shorthand/outline.mako.rs b/components/style/properties/shorthands/outline.mako.rs similarity index 100% rename from components/style/properties/shorthand/outline.mako.rs rename to components/style/properties/shorthands/outline.mako.rs diff --git a/components/style/properties/shorthand/padding.mako.rs b/components/style/properties/shorthands/padding.mako.rs similarity index 100% rename from components/style/properties/shorthand/padding.mako.rs rename to components/style/properties/shorthands/padding.mako.rs diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthands/position.mako.rs similarity index 100% rename from components/style/properties/shorthand/position.mako.rs rename to components/style/properties/shorthands/position.mako.rs diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthands/text.mako.rs similarity index 100% rename from components/style/properties/shorthand/text.mako.rs rename to components/style/properties/shorthands/text.mako.rs From 4571a71bfc26f7cf87178619273f2b90e9229c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Jun 2018 13:07:00 +0200 Subject: [PATCH 07/19] style: Rename mask.mako.rs to svg.mako.rs for consistency. Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: 6sqGxL8hhA0 --- components/style/properties/properties.mako.rs | 2 +- .../style/properties/shorthands/{mask.mako.rs => svg.mako.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename components/style/properties/shorthands/{mask.mako.rs => svg.mako.rs} (100%) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index a3d4787ab72..a2ac0603a24 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -171,7 +171,7 @@ pub mod shorthands { <%include file="/shorthands/inherited_text.mako.rs" /> <%include file="/shorthands/list.mako.rs" /> <%include file="/shorthands/margin.mako.rs" /> - <%include file="/shorthands/mask.mako.rs" /> + <%include file="/shorthands/svg.mako.rs" /> <%include file="/shorthands/outline.mako.rs" /> <%include file="/shorthands/padding.mako.rs" /> <%include file="/shorthands/position.mako.rs" /> diff --git a/components/style/properties/shorthands/mask.mako.rs b/components/style/properties/shorthands/svg.mako.rs similarity index 100% rename from components/style/properties/shorthands/mask.mako.rs rename to components/style/properties/shorthands/svg.mako.rs From a4dcb33986a3229dd36f3c6618ad715cf15f3450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Jun 2018 13:19:41 +0200 Subject: [PATCH 08/19] style: Make StyleStruct.name_lower snake case. Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: A3TpDTmFgF --- components/style/properties/data.py | 6 +++++- components/style/properties/properties.mako.rs | 2 +- components/style/style_adjuster.rs | 18 +++++++++--------- components/style/values/computed/text.rs | 2 +- components/style/values/specified/text.rs | 6 +++--- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index fca4b536e01..08001628e60 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -38,6 +38,10 @@ def to_rust_ident(name): return name +def to_snake_case(ident): + return re.sub("([A-Z]+)", lambda m: "_" + m.group(1).lower(), ident).strip("_") + + def to_camel_case(ident): return re.sub("(^|_|-)([a-z0-9])", lambda m: m.group(2).upper(), ident.strip("_").strip("-")) @@ -451,7 +455,7 @@ class StyleStruct(object): def __init__(self, name, inherited, gecko_name=None, additional_methods=None): self.gecko_struct_name = "Gecko" + name self.name = name - self.name_lower = name.lower() + self.name_lower = to_snake_case(name) self.ident = to_rust_ident(self.name_lower) self.longhands = [] self.inherited = inherited diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index a2ac0603a24..38a26a50675 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3877,7 +3877,7 @@ where } % if category_to_cascade_now == "early": let writing_mode = - WritingMode::new(context.builder.get_inheritedbox()); + WritingMode::new(context.builder.get_inherited_box()); context.builder.writing_mode = writing_mode; let mut _skip_font_family = false; diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 3983c780894..754abab0993 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -256,8 +256,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { use computed_values::text_combine_upright::T as TextCombineUpright; use computed_values::writing_mode::T as WritingMode; - let writing_mode = self.style.get_inheritedbox().clone_writing_mode(); - let text_combine_upright = self.style.get_inheritedtext().clone_text_combine_upright(); + let writing_mode = self.style.get_inherited_box().clone_writing_mode(); + let text_combine_upright = self.style.get_inherited_text().clone_text_combine_upright(); if writing_mode != WritingMode::HorizontalTb && text_combine_upright == TextCombineUpright::All @@ -266,7 +266,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { .flags .insert(ComputedValueFlags::IS_TEXT_COMBINED); self.style - .mutate_inheritedbox() + .mutate_inherited_box() .set_writing_mode(WritingMode::HorizontalTb); } } @@ -305,8 +305,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// /// fn adjust_for_writing_mode(&mut self, layout_parent_style: &ComputedValues) { - let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode(); - let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode(); + let our_writing_mode = self.style.get_inherited_box().clone_writing_mode(); + let parent_writing_mode = layout_parent_style.get_inherited_box().clone_writing_mode(); if our_writing_mode != parent_writing_mode && self.style.get_box().clone_display() == Display::Inline @@ -496,13 +496,13 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { return; } - match self.style.get_inheritedtext().clone_text_align() { + match self.style.get_inherited_text().clone_text_align() { TextAlign::MozLeft | TextAlign::MozCenter | TextAlign::MozRight => {}, _ => return, } self.style - .mutate_inheritedtext() + .mutate_inherited_text() .set_text_align(TextAlign::Start) } @@ -516,8 +516,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { use values::computed::text::TextDecorationsInEffect; let decorations_in_effect = TextDecorationsInEffect::from_style(&self.style); - if self.style.get_inheritedtext().text_decorations_in_effect != decorations_in_effect { - self.style.mutate_inheritedtext().text_decorations_in_effect = decorations_in_effect; + if self.style.get_inherited_text().text_decorations_in_effect != decorations_in_effect { + self.style.mutate_inherited_text().text_decorations_in_effect = decorations_in_effect; } } diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index f2bcf11fe62..b41ecdb7e67 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -107,7 +107,7 @@ impl TextDecorationsInEffect { let mut result = match style.get_box().clone_display() { Display::InlineBlock | Display::InlineTable => Self::default(), _ => style - .get_parent_inheritedtext() + .get_parent_inherited_text() .text_decorations_in_effect .clone(), }; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 70947ac0826..ef0e66672d0 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -514,7 +514,7 @@ impl ToComputedValue for TextAlign { } let parent = _context .builder - .get_parent_inheritedtext() + .get_parent_inherited_text() .clone_text_align(); let ltr = _context.builder.inherited_writing_mode().is_bidi_ltr(); match (parent, ltr) { @@ -529,7 +529,7 @@ impl ToComputedValue for TextAlign { TextAlign::MozCenterOrInherit => { let parent = _context .builder - .get_parent_inheritedtext() + .get_parent_inherited_text() .clone_text_align(); if parent == TextAlignKeyword::Start { TextAlignKeyword::Center @@ -653,7 +653,7 @@ impl ToComputedValue for TextEmphasisStyle { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { TextEmphasisStyle::Keyword(ref keyword) => { - let default_shape = if context.style().get_inheritedbox().clone_writing_mode() == + let default_shape = if context.style().get_inherited_box().clone_writing_mode() == SpecifiedWritingMode::HorizontalTb { TextEmphasisShapeKeyword::Circle From 202ec8a8c8524a8d7e7d3545d95a291d781ed041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 Jun 2018 13:30:04 +0200 Subject: [PATCH 09/19] style: Generate different files for different structs. Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: KEDJ1zJVwMx --- components/style/properties/build.py | 63 +++++++++++++++++-- .../style/properties/properties.mako.rs | 45 +++---------- 2 files changed, 66 insertions(+), 42 deletions(-) diff --git a/components/style/properties/build.py b/components/style/properties/build.py index 04418723ee4..34c1b3560a6 100644 --- a/components/style/properties/build.py +++ b/components/style/properties/build.py @@ -19,6 +19,34 @@ import data RE_PYTHON_ADDR = re.compile(r'<.+? object at 0x[0-9a-fA-F]+>') +OUT_DIR = os.environ.get("OUT_DIR", "") + +STYLE_STRUCT_LIST = [ + "background", + "border", + "box", + "color", + "column", + "counters", + "effects", + "font", + "inherited_box", + "inherited_table", + "inherited_text", + "inherited_ui", + "inherited_svg", + "list", + "margin", + "outline", + "padding", + "position", + "table", + "text", + "ui", + "svg", + "xul", +] + def main(): usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib