Auto merge of #17972 - heycam:ignore-existing, r=bholley

style: Allow styles to be computed ignoring existing element data.

From https://bugzilla.mozilla.org/show_bug.cgi?id=1384824.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17972)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-04 21:33:59 -05:00 committed by GitHub
commit ac37f81c1f
8 changed files with 64 additions and 31 deletions

View file

@ -702,7 +702,7 @@ pub fn process_resolved_style_request<'a, N>(context: &LayoutContext,
thread_local: &mut tlc,
};
let styles = resolve_style(&mut context, element, RuleInclusion::All);
let styles = resolve_style(&mut context, element, RuleInclusion::All, false);
let style = styles.primary();
let longhand_id = match *property {
PropertyId::Longhand(id) => id,

View file

@ -2827,7 +2827,8 @@ extern "C" {
rule_inclusion: StyleRuleInclusion,
snapshots:
*const ServoElementSnapshotTable,
set: RawServoStyleSetBorrowed)
set: RawServoStyleSetBorrowed,
ignore_existing_styles: bool)
-> ServoStyleContextStrong;
}
extern "C" {

View file

@ -2181,7 +2181,7 @@ fn static_assert() {
}
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
use properties::longhands::font_family::computed_value::FontFamily;
use properties::longhands::font_family::computed_value::{FontFamily, FamilyNameSyntax};
let list = &mut self.gecko.mFont.fontlist;
unsafe { Gecko_FontFamilyList_Clear(list); }
@ -2191,7 +2191,8 @@ fn static_assert() {
for family in &v.0 {
match *family {
FontFamily::FamilyName(ref f) => {
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), f.quoted); }
let quoted = matches!(f.syntax, FamilyNameSyntax::Quoted);
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), quoted); }
}
FontFamily::Generic(ref name) => {
let (family_type, generic) = FontFamily::generic(name);
@ -2222,7 +2223,7 @@ fn static_assert() {
}
pub fn clone_font_family(&self) -> longhands::font_family::computed_value::T {
use properties::longhands::font_family::computed_value::{FontFamily, FamilyName};
use properties::longhands::font_family::computed_value::{FontFamily, FamilyName, FamilyNameSyntax};
use gecko_bindings::structs::FontFamilyType;
use gecko_string_cache::Atom;
@ -2235,13 +2236,16 @@ fn static_assert() {
FontFamilyType::eFamily_cursive => FontFamily::Generic(atom!("cursive")),
FontFamilyType::eFamily_fantasy => FontFamily::Generic(atom!("fantasy")),
FontFamilyType::eFamily_moz_fixed => FontFamily::Generic(Atom::from("-moz-fixed")),
FontFamilyType::eFamily_named => FontFamily::FamilyName(FamilyName {
name: (&*gecko_font_family_name.mName).into(),
quoted: false
}),
FontFamilyType::eFamily_named => {
let name = Atom::from(&*gecko_font_family_name.mName);
FontFamily::FamilyName(FamilyName {
name: name.clone(),
syntax: FamilyNameSyntax::Identifiers(vec![name]),
})
},
FontFamilyType::eFamily_named_quoted => FontFamily::FamilyName(FamilyName {
name: (&*gecko_font_family_name.mName).into(),
quoted: true
syntax: FamilyNameSyntax::Quoted,
}),
x => panic!("Found unexpected font FontFamilyType: {:?}", x),
}

View file

@ -96,7 +96,14 @@ macro_rules! impl_gecko_keyword_conversions {
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct FamilyName {
pub name: Atom,
pub quoted: bool,
pub syntax: FamilyNameSyntax,
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub enum FamilyNameSyntax {
Quoted,
Identifiers(Vec<Atom>),
}
impl FontFamily {
@ -139,7 +146,7 @@ macro_rules! impl_gecko_keyword_conversions {
// quoted by default.
FontFamily::FamilyName(FamilyName {
name: input,
quoted: true,
syntax: FamilyNameSyntax::Quoted,
})
}
@ -148,10 +155,14 @@ macro_rules! impl_gecko_keyword_conversions {
if let Ok(value) = input.try(|i| i.expect_string_cloned()) {
return Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(&*value),
quoted: true,
syntax: FamilyNameSyntax::Quoted,
}))
}
let mut identifiers = vec![];
let first_ident = input.expect_ident()?.clone();
identifiers.push(Atom::from(&*first_ident));
// FIXME(bholley): The fast thing to do here would be to look up the
// string (as lowercase) in the static atoms table. We don't have an
@ -188,14 +199,16 @@ macro_rules! impl_gecko_keyword_conversions {
let ident = input.expect_ident()?;
value.push_str(" ");
value.push_str(&ident);
identifiers.push(Atom::from(&*ident.clone()));
}
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
value.push_str(" ");
value.push_str(&ident);
identifiers.push(Atom::from(&*ident));
}
Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(value),
quoted: false,
syntax: FamilyNameSyntax::Identifiers(identifiers),
}))
}
@ -229,12 +242,23 @@ macro_rules! impl_gecko_keyword_conversions {
impl ToCss for FamilyName {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.quoted {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"')
} else {
serialize_identifier(&*self.name.to_string(), dest)
match self.syntax {
FamilyNameSyntax::Quoted => {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"')
}
FamilyNameSyntax::Identifiers(ref identifiers) => {
let mut first = true;
for identifier in identifiers {
if !first {
dest.write_char(' ')?;
}
serialize_identifier(&*identifier.to_string(), dest)?;
first = false;
}
Ok(())
}
}
}
}
@ -2508,7 +2532,7 @@ ${helpers.single_keyword("-moz-math-variant",
use properties::longhands::font_family::computed_value::*;
FontFamily::FamilyName(FamilyName {
name: (&*font.mName).into(),
quoted: true
syntax: FamilyNameSyntax::Quoted,
})
}).collect::<Vec<_>>();
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);

View file

@ -391,6 +391,7 @@ pub fn resolve_style<E>(
context: &mut StyleContext<E>,
element: E,
rule_inclusion: RuleInclusion,
ignore_existing_style: bool,
) -> ElementStyles
where
E: TElement,
@ -398,6 +399,7 @@ where
use style_resolver::StyleResolverForElement;
debug_assert!(rule_inclusion == RuleInclusion::DefaultOnly ||
ignore_existing_style ||
element.borrow_data().map_or(true, |d| !d.has_styles()),
"Why are we here?");
let mut ancestors_requiring_style_resolution = SmallVec::<[E; 16]>::new();
@ -408,7 +410,7 @@ where
let mut style = None;
let mut ancestor = element.traversal_parent();
while let Some(current) = ancestor {
if rule_inclusion == RuleInclusion::All {
if rule_inclusion == RuleInclusion::All && !ignore_existing_style {
if let Some(data) = current.borrow_data() {
if let Some(ancestor_style) = data.styles.get_primary() {
style = Some(ancestor_style.clone());