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

This commit is contained in:
Cameron McCormack 2017-08-04 19:33:07 +10:00
parent 4f525f6fa0
commit bb44c0a6bc
6 changed files with 17 additions and 12 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

@ -2810,7 +2810,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

@ -388,6 +388,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,
@ -395,6 +396,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();
@ -405,7 +407,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

@ -2857,7 +2857,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());
@ -2888,8 +2889,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))
@ -2914,7 +2916,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 {