stylo: Add support for xml:lang

MozReview-Commit-ID: E0GpyPKES3k
This commit is contained in:
Manish Goregaokar 2017-03-26 13:53:34 -07:00 committed by Manish Goregaokar
parent 8dea66e6f1
commit 5d6bc8177e
3 changed files with 31 additions and 7 deletions

View file

@ -624,9 +624,9 @@ 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 as SpecifiedTextAlign;
use properties::longhands::color::SpecifiedValue as SpecifiedColor;
use properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang;
use properties::longhands::color::SpecifiedValue as SpecifiedColor;
use properties::longhands::text_align::SpecifiedValue as SpecifiedTextAlign;
use values::specified::color::Color;
lazy_static! {
static ref TH_RULE: ApplicableDeclarationBlock = {
@ -667,10 +667,6 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {
self.as_node().owner_doc().mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks {
hints.push(TABLE_COLOR_RULE.clone());
}
} else if ns == &*Namespace(atom!("http://www.w3.org/1998/Math/MathML")) {
if self.get_local_name().as_ptr() == atom!("math").as_ptr() {
hints.push(MATHML_LANG_RULE.clone());
}
}
let declarations = unsafe { Gecko_GetHTMLPresentationAttrDeclarationBlock(self.0) };
let declarations = declarations.and_then(|s| s.as_arc_opt());
@ -686,6 +682,30 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {
ApplicableDeclarationBlock::from_declarations(Clone::clone(decl), ServoCascadeLevel::PresHints)
);
}
// xml:lang has precedence over lang, which can be
// set by Gecko_GetHTMLPresentationAttrDeclarationBlock
//
// http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#language
let ptr = unsafe {
bindings::Gecko_GetXMLLangValue(self.0)
};
if !ptr.is_null() {
let global_style_data = &*GLOBAL_STYLE_DATA;
let pdb = PropertyDeclarationBlock::with_one(
PropertyDeclaration::XLang(SpecifiedLang(Atom::from(ptr))),
Importance::Normal
);
let arc = Arc::new(global_style_data.shared_lock.wrap(pdb));
hints.push(ApplicableDeclarationBlock::from_declarations(arc, ServoCascadeLevel::PresHints))
}
// MathML's default lang has precedence over both `lang` and `xml:lang`
if ns == &*Namespace(atom!("http://www.w3.org/1998/Math/MathML")) {
if self.get_local_name().as_ptr() == atom!("math").as_ptr() {
hints.push(MATHML_LANG_RULE.clone());
}
}
}
}

View file

@ -479,6 +479,10 @@ extern "C" {
pub fn Gecko_GetElementId(element: RawGeckoElementBorrowed)
-> *mut nsIAtom;
}
extern "C" {
pub fn Gecko_GetXMLLangValue(element: RawGeckoElementBorrowed)
-> *mut nsIAtom;
}
extern "C" {
pub fn Gecko_AtomAttrValue(element: RawGeckoElementBorrowed,
attribute: *mut nsIAtom) -> *mut nsIAtom;

View file

@ -211,8 +211,8 @@ impl ToComputedValue for specified::Color {
specified::Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor),
specified::Color::InheritFromBodyQuirk => {
use dom::TElement;
use gecko_bindings::bindings::Gecko_GetBody;
use gecko::wrapper::GeckoElement;
use gecko_bindings::bindings::Gecko_GetBody;
let body = unsafe {
Gecko_GetBody(pres_context)
};