servo: Merge #17972 - style: Allow styles to be computed ignoring existing element data (from heycam:ignore-existing); r=bholley

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

Source-Repo: https://github.com/servo/servo
Source-Revision: ac37f81c1f70f6994444ca0c40ad9d91a228ec87

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 0caf23c831e67a51eb6375817f45ef6ba4670f81
This commit is contained in:
Cameron McCormack 2017-08-04 21:33:59 -05:00
parent 2685e4feb0
commit 18350e6b56
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, 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 style = styles.primary();
let longhand_id = match *property { let longhand_id = match *property {
PropertyId::Longhand(id) => id, PropertyId::Longhand(id) => id,

View File

@ -2827,7 +2827,8 @@ extern "C" {
rule_inclusion: StyleRuleInclusion, rule_inclusion: StyleRuleInclusion,
snapshots: snapshots:
*const ServoElementSnapshotTable, *const ServoElementSnapshotTable,
set: RawServoStyleSetBorrowed) set: RawServoStyleSetBorrowed,
ignore_existing_styles: bool)
-> ServoStyleContextStrong; -> ServoStyleContextStrong;
} }
extern "C" { 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) { 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; let list = &mut self.gecko.mFont.fontlist;
unsafe { Gecko_FontFamilyList_Clear(list); } unsafe { Gecko_FontFamilyList_Clear(list); }
@ -2191,7 +2191,8 @@ fn static_assert() {
for family in &v.0 { for family in &v.0 {
match *family { match *family {
FontFamily::FamilyName(ref f) => { 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) => { FontFamily::Generic(ref name) => {
let (family_type, generic) = FontFamily::generic(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 { 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_bindings::structs::FontFamilyType;
use gecko_string_cache::Atom; use gecko_string_cache::Atom;
@ -2235,13 +2236,16 @@ fn static_assert() {
FontFamilyType::eFamily_cursive => FontFamily::Generic(atom!("cursive")), FontFamilyType::eFamily_cursive => FontFamily::Generic(atom!("cursive")),
FontFamilyType::eFamily_fantasy => FontFamily::Generic(atom!("fantasy")), FontFamilyType::eFamily_fantasy => FontFamily::Generic(atom!("fantasy")),
FontFamilyType::eFamily_moz_fixed => FontFamily::Generic(Atom::from("-moz-fixed")), FontFamilyType::eFamily_moz_fixed => FontFamily::Generic(Atom::from("-moz-fixed")),
FontFamilyType::eFamily_named => FontFamily::FamilyName(FamilyName { FontFamilyType::eFamily_named => {
name: (&*gecko_font_family_name.mName).into(), let name = Atom::from(&*gecko_font_family_name.mName);
quoted: false FontFamily::FamilyName(FamilyName {
}), name: name.clone(),
syntax: FamilyNameSyntax::Identifiers(vec![name]),
})
},
FontFamilyType::eFamily_named_quoted => FontFamily::FamilyName(FamilyName { FontFamilyType::eFamily_named_quoted => FontFamily::FamilyName(FamilyName {
name: (&*gecko_font_family_name.mName).into(), name: (&*gecko_font_family_name.mName).into(),
quoted: true syntax: FamilyNameSyntax::Quoted,
}), }),
x => panic!("Found unexpected font FontFamilyType: {:?}", x), 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))] #[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct FamilyName { pub struct FamilyName {
pub name: Atom, 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 { impl FontFamily {
@ -139,7 +146,7 @@ macro_rules! impl_gecko_keyword_conversions {
// quoted by default. // quoted by default.
FontFamily::FamilyName(FamilyName { FontFamily::FamilyName(FamilyName {
name: input, 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()) { if let Ok(value) = input.try(|i| i.expect_string_cloned()) {
return Ok(FontFamily::FamilyName(FamilyName { return Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(&*value), name: Atom::from(&*value),
quoted: true, syntax: FamilyNameSyntax::Quoted,
})) }))
} }
let mut identifiers = vec![];
let first_ident = input.expect_ident()?.clone(); 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 // 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 // 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()?; let ident = input.expect_ident()?;
value.push_str(" "); value.push_str(" ");
value.push_str(&ident); value.push_str(&ident);
identifiers.push(Atom::from(&*ident.clone()));
} }
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
value.push_str(" "); value.push_str(" ");
value.push_str(&ident); value.push_str(&ident);
identifiers.push(Atom::from(&*ident));
} }
Ok(FontFamily::FamilyName(FamilyName { Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(value), name: Atom::from(value),
quoted: false, syntax: FamilyNameSyntax::Identifiers(identifiers),
})) }))
} }
@ -229,12 +242,23 @@ macro_rules! impl_gecko_keyword_conversions {
impl ToCss for FamilyName { impl ToCss for FamilyName {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.quoted { match self.syntax {
FamilyNameSyntax::Quoted => {
dest.write_char('"')?; dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?; write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"') dest.write_char('"')
} else { }
serialize_identifier(&*self.name.to_string(), dest) 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::*; use properties::longhands::font_family::computed_value::*;
FontFamily::FamilyName(FamilyName { FontFamily::FamilyName(FamilyName {
name: (&*font.mName).into(), name: (&*font.mName).into(),
quoted: true syntax: FamilyNameSyntax::Quoted,
}) })
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight); 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>, context: &mut StyleContext<E>,
element: E, element: E,
rule_inclusion: RuleInclusion, rule_inclusion: RuleInclusion,
ignore_existing_style: bool,
) -> ElementStyles ) -> ElementStyles
where where
E: TElement, E: TElement,
@ -398,6 +399,7 @@ where
use style_resolver::StyleResolverForElement; use style_resolver::StyleResolverForElement;
debug_assert!(rule_inclusion == RuleInclusion::DefaultOnly || debug_assert!(rule_inclusion == RuleInclusion::DefaultOnly ||
ignore_existing_style ||
element.borrow_data().map_or(true, |d| !d.has_styles()), element.borrow_data().map_or(true, |d| !d.has_styles()),
"Why are we here?"); "Why are we here?");
let mut ancestors_requiring_style_resolution = SmallVec::<[E; 16]>::new(); let mut ancestors_requiring_style_resolution = SmallVec::<[E; 16]>::new();
@ -408,7 +410,7 @@ where
let mut style = None; let mut style = None;
let mut ancestor = element.traversal_parent(); let mut ancestor = element.traversal_parent();
while let Some(current) = ancestor { 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(data) = current.borrow_data() {
if let Some(ancestor_style) = data.styles.get_primary() { if let Some(ancestor_style) = data.styles.get_primary() {
style = Some(ancestor_style.clone()); style = Some(ancestor_style.clone());

View File

@ -2831,7 +2831,8 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType, pseudo_type: CSSPseudoElementType,
rule_inclusion: StyleRuleInclusion, rule_inclusion: StyleRuleInclusion,
snapshots: *const ServoElementSnapshotTable, snapshots: *const ServoElementSnapshotTable,
raw_data: RawServoStyleSetBorrowed) raw_data: RawServoStyleSetBorrowed,
ignore_existing_styles: bool)
-> ServoStyleContextStrong -> ServoStyleContextStrong
{ {
debug_assert!(!snapshots.is_null()); debug_assert!(!snapshots.is_null());
@ -2862,8 +2863,9 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
// In the common case we already have the style. Check that before setting // In the common case we already have the style. Check that before setting
// up all the computation machinery. (Don't use it when we're getting // up all the computation machinery. (Don't use it when we're getting
// default styles, though.) // default styles or in a bfcached document (as indicated by
if rule_inclusion == RuleInclusion::All { // ignore_existing_styles), though.)
if rule_inclusion == RuleInclusion::All && !ignore_existing_styles {
let styles = element.mutate_data().and_then(|d| { let styles = element.mutate_data().and_then(|d| {
if d.has_styles() { if d.has_styles() {
Some(finish(&d.styles)) Some(finish(&d.styles))
@ -2888,7 +2890,7 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
thread_local: &mut tlc, thread_local: &mut tlc,
}; };
let styles = resolve_style(&mut context, element, rule_inclusion); let styles = resolve_style(&mut context, element, rule_inclusion, ignore_existing_styles);
finish(&styles).into() finish(&styles).into()
} }

View File

@ -5,7 +5,7 @@
use cssparser::SourceLocation; use cssparser::SourceLocation;
use gfx::font_cache_thread::FontCacheThread; use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc; use ipc_channel::ipc;
use style::computed_values::font_family::FamilyName; use style::computed_values::font_family::{FamilyName, FamilyNameSyntax};
use style::font_face::{FontFaceRuleData, Source}; use style::font_face::{FontFaceRuleData, Source};
#[test] #[test]
@ -15,11 +15,11 @@ fn test_local_web_font() {
let font_cache_thread = FontCacheThread::new(inp_chan, None); let font_cache_thread = FontCacheThread::new(inp_chan, None);
let family_name = FamilyName { let family_name = FamilyName {
name: From::from("test family"), name: From::from("test family"),
quoted: true, syntax: FamilyNameSyntax::Quoted,
}; };
let variant_name = FamilyName { let variant_name = FamilyName {
name: From::from("test font face"), name: From::from("test font face"),
quoted: true, syntax: FamilyNameSyntax::Quoted,
}; };
let font_face_rule = FontFaceRuleData { let font_face_rule = FontFaceRuleData {
family: Some(family_name.clone()), family: Some(family_name.clone()),

View File

@ -14,7 +14,7 @@ use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use style::computed_values::font_family::FamilyName; use style::computed_values::font_family::{FamilyName, FamilyNameSyntax};
use style::context::QuirksMode; use style::context::QuirksMode;
use style::error_reporting::{ParseErrorReporter, ContextualParseError}; use style::error_reporting::{ParseErrorReporter, ContextualParseError};
use style::media_queries::MediaList; use style::media_queries::MediaList;
@ -254,7 +254,7 @@ fn test_parse_stylesheet() {
CssRule::FontFeatureValues(Arc::new(stylesheet.shared_lock.wrap(FontFeatureValuesRule { CssRule::FontFeatureValues(Arc::new(stylesheet.shared_lock.wrap(FontFeatureValuesRule {
family_names: vec![FamilyName { family_names: vec![FamilyName {
name: Atom::from("test"), name: Atom::from("test"),
quoted: false, syntax: FamilyNameSyntax::Identifiers(vec![Atom::from("test")]),
}], }],
swash: vec![ swash: vec![
FFVDeclaration { FFVDeclaration {