stylo: Add support for <table> color quirk

MozReview-Commit-ID: 56IKARwfbhw
This commit is contained in:
Manish Goregaokar 2017-03-26 13:53:34 -07:00 committed by Manish Goregaokar
parent 0392e58a2f
commit 1c23296d8a
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
6 changed files with 62 additions and 25 deletions

View file

@ -624,12 +624,23 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
where V: Push<ApplicableDeclarationBlock>,
{
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> {
};
// <th> 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());

View file

@ -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:

View file

@ -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())
}
}

View file

@ -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()
}
}

View file

@ -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(()),
}
}
}

View file

@ -107,24 +107,27 @@ impl ToCss for CSSColor {
}
}
impl From<Color> 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()
}
}