From 739d6d14ab09b32a90765f7656535c9bdeef7a7a Mon Sep 17 00:00:00 2001 From: David Shin Date: Sun, 18 Jun 2023 14:06:52 +0200 Subject: [PATCH] style: Migrate `` `text-align` behaviour from presentation hint to UA CSS Differential Revision: https://phabricator.services.mozilla.com/D142494 --- components/style/gecko/wrapper.rs | 18 +----------------- components/style/values/specified/text.rs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index c7aea5b84d8..f5113de277d 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1588,23 +1588,9 @@ impl<'le> TElement for GeckoElement<'le> { use crate::properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang; use crate::properties::longhands::_x_text_zoom::SpecifiedValue as SpecifiedZoom; use crate::properties::longhands::color::SpecifiedValue as SpecifiedColor; - use crate::properties::longhands::text_align::SpecifiedValue as SpecifiedTextAlign; use crate::stylesheets::layer_rule::LayerOrder; use crate::values::specified::color::Color; lazy_static! { - static ref TH_RULE: ApplicableDeclarationBlock = { - let global_style_data = &*GLOBAL_STYLE_DATA; - let pdb = PropertyDeclarationBlock::with_one( - PropertyDeclaration::TextAlign(SpecifiedTextAlign::MozCenterOrInherit), - Importance::Normal, - ); - let arc = Arc::new_leaked(global_style_data.shared_lock.wrap(pdb)); - ApplicableDeclarationBlock::from_declarations( - arc, - ServoCascadeLevel::PresHints, - LayerOrder::root(), - ) - }; static ref TABLE_COLOR_RULE: ApplicableDeclarationBlock = { let global_style_data = &*GLOBAL_STYLE_DATA; let pdb = PropertyDeclarationBlock::with_one( @@ -1649,9 +1635,7 @@ impl<'le> TElement for GeckoElement<'le> { let ns = self.namespace_id(); // elements get a default MozCenterOrInherit which may get overridden if ns == structs::kNameSpaceID_XHTML as i32 { - if self.local_name().as_ptr() == atom!("th").as_ptr() { - hints.push(TH_RULE.clone()); - } else if self.local_name().as_ptr() == atom!("table").as_ptr() && + if self.local_name().as_ptr() == atom!("table").as_ptr() && self.as_node().owner_doc().quirks_mode() == QuirksMode::Quirks { hints.push(TABLE_COLOR_RULE.clone()); diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index b5ad73bf250..9c58b6a4572 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -528,11 +528,20 @@ pub enum TextAlign { /// unlike other keywords. #[cfg(feature = "gecko")] MatchParent, - /// `MozCenterOrInherit` value of text-align property. It cannot be parsed, - /// only set directly on the elements and it has a different handling - /// unlike other values. + /// This is how we implement the following HTML behavior from + /// https://html.spec.whatwg.org/#tables-2: + /// + /// User agents are expected to have a rule in their user agent style sheet + /// that matches th elements that have a parent node whose computed value + /// for the 'text-align' property is its initial value, whose declaration + /// block consists of just a single declaration that sets the 'text-align' + /// property to the value 'center'. + /// + /// Since selectors can't depend on the ancestor styles, we implement it with a + /// magic value that computes to the right thing. Since this is an + /// implementation detail, it shouldn't be exposed to web content. #[cfg(feature = "gecko")] - #[css(skip)] + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] MozCenterOrInherit, }