From 1c23296d8af5299970e5affa48ecdcd0cbbac1f6 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 26 Mar 2017 13:53:34 -0700 Subject: [PATCH] stylo: Add support for color quirk MozReview-Commit-ID: 56IKARwfbhw --- components/style/gecko/wrapper.rs | 25 ++++++++++++---- components/style/gecko_bindings/bindings.rs | 4 +++ .../style/properties/longhand/color.mako.rs | 5 +--- components/style/values/computed/mod.rs | 29 ++++++++++++++----- components/style/values/specified/color.rs | 3 ++ components/style/values/specified/mod.rs | 21 ++++++++------ 6 files changed, 62 insertions(+), 25 deletions(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 12a4c884336..262e7f3018d 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -624,12 +624,23 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes(&self, hints: &mut V) where V: Push, { - use properties::longhands::text_align::SpecifiedValue; + use properties::longhands::text_align::SpecifiedValue as SpecifiedTextAlign; + use properties::longhands::color::SpecifiedValue as SpecifiedColor; + use 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(SpecifiedValue::MozCenterOrInherit), + PropertyDeclaration::TextAlign(SpecifiedTextAlign::MozCenterOrInherit), + Importance::Normal + ); + let arc = Arc::new(global_style_data.shared_lock.wrap(pdb)); + ApplicableDeclarationBlock::from_declarations(arc, ServoCascadeLevel::PresHints) + }; + static ref TABLE_COLOR_RULE: ApplicableDeclarationBlock = { + let global_style_data = &*GLOBAL_STYLE_DATA; + let pdb = PropertyDeclarationBlock::with_one( + PropertyDeclaration::Color(SpecifiedColor(Color::InheritFromBodyQuirk.into())), Importance::Normal ); let arc = Arc::new(global_style_data.shared_lock.wrap(pdb)); @@ -638,9 +649,13 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> { }; //
elements get a default MozCenterOrInherit which may get overridden - if self.get_namespace() == &*Namespace(atom!("http://www.w3.org/1999/xhtml")) && - self.get_local_name().as_ptr() == atom!("th").as_ptr() { - hints.push(TH_RULE.clone()); + if self.get_namespace() == &*Namespace(atom!("http://www.w3.org/1999/xhtml")) { + if self.get_local_name().as_ptr() == atom!("th").as_ptr() { + hints.push(TH_RULE.clone()); + } else if self.get_local_name().as_ptr() == atom!("table").as_ptr() && + self.as_node().owner_doc().mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks { + hints.push(TABLE_COLOR_RULE.clone()); + } } let declarations = unsafe { Gecko_GetHTMLPresentationAttrDeclarationBlock(self.0) }; let declarations = declarations.and_then(|s| s.as_arc_opt()); diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index c68b1294437..999beb32e0e 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1050,6 +1050,10 @@ extern "C" { extern "C" { pub fn Gecko_CSSFontFaceRule_Release(aPtr: *mut nsCSSFontFaceRule); } +extern "C" { + pub fn Gecko_GetBody(pres_context: RawGeckoPresContextBorrowed) + -> RawGeckoElementBorrowedOrNull; +} extern "C" { pub fn Gecko_GetLookAndFeelSystemColor(color_id: i32, pres_context: diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index 436012bf461..3825df7c128 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -26,10 +26,7 @@ #[inline] fn from_computed_value(computed: &computed_value::T) -> Self { - SpecifiedValue(CSSColor { - parsed: Color::RGBA(*computed), - authored: None, - }) + SpecifiedValue(Color::RGBA(*computed).into()) } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 71eacc8bb8f..2cf46210317 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -209,6 +209,24 @@ impl ToComputedValue for specified::Color { specified::Color::MozHyperlinktext => to_rgba(pres_context.mLinkColor), specified::Color::MozActiveHyperlinktext => to_rgba(pres_context.mActiveLinkColor), specified::Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor), + specified::Color::InheritFromBodyQuirk => { + use dom::TElement; + use gecko_bindings::bindings::Gecko_GetBody; + use gecko::wrapper::GeckoElement; + let body = unsafe { + Gecko_GetBody(pres_context) + }; + if let Some(body) = body { + let wrap = GeckoElement(body); + let borrow = wrap.borrow_data(); + borrow.as_ref().unwrap() + .styles().primary.values() + .get_color() + .clone_color() + } else { + to_rgba(pres_context.mDefaultColor) + } + }, } } @@ -239,13 +257,10 @@ impl ToComputedValue for specified::CSSColor { #[inline] fn from_computed_value(computed: &CSSColor) -> Self { - specified::CSSColor { - parsed: match *computed { - CSSColor::RGBA(rgba) => specified::Color::RGBA(rgba), - CSSColor::CurrentColor => specified::Color::CurrentColor, - }, - authored: None, - } + (match *computed { + CSSColor::RGBA(rgba) => specified::Color::RGBA(rgba), + CSSColor::CurrentColor => specified::Color::CurrentColor, + }).into() } } diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 4a3c5498716..fcd6c8be8d8 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -48,6 +48,8 @@ mod gecko { MozActiveHyperlinktext, /// -moz-visitedhyperlinktext MozVisitedHyperlinktext, + /// Quirksmode-only rule for inheriting color from the body + InheritFromBodyQuirk, } no_viewport_percentage!(Color); @@ -89,6 +91,7 @@ mod gecko { Color::MozHyperlinktext => dest.write_str("-moz-hyperlinktext"), Color::MozActiveHyperlinktext => dest.write_str("-moz-activehyperlinktext"), Color::MozVisitedHyperlinktext => dest.write_str("-moz-visitedhyperlinktext"), + Color::InheritFromBodyQuirk => Ok(()), } } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index e6317c6e570..f5ba7b7fb1d 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -107,24 +107,27 @@ impl ToCss for CSSColor { } } +impl From for CSSColor { + fn from(color: Color) -> Self { + CSSColor { + parsed: color, + authored: None, + } + } +} + impl CSSColor { #[inline] /// Returns currentcolor value. pub fn currentcolor() -> CSSColor { - CSSColor { - parsed: Color::CurrentColor, - authored: None, - } + Color::CurrentColor.into() } #[inline] /// Returns transparent value. pub fn transparent() -> CSSColor { - CSSColor { - parsed: Color::RGBA(cssparser::RGBA::transparent()), - // This should probably be "transparent", but maybe it doesn't matter. - authored: None, - } + // We should probably set authored to "transparent", but maybe it doesn't matter. + Color::RGBA(cssparser::RGBA::transparent()).into() } }