stylo: Pass the @page values to precomputed pseudo element declarations

We were parsing @page rules correctly and serializing for cssom when we
we need. But we weren't actually including them to the pseudo element
declarations when we need to print a page.
This commit is contained in:
Nazım Can Altınova 2017-09-06 13:59:45 -07:00
parent af587e5f84
commit c533e23220
2 changed files with 119 additions and 16 deletions

View file

@ -12,6 +12,7 @@ use std::env;
use std::fmt::Write;
use std::iter;
use std::ptr;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::context::{CascadeInputs, QuirksMode, SharedStyleContext, StyleContext};
use style::context::ThreadLocalStyleContext;
use style::data::ElementStyles;
@ -113,7 +114,7 @@ use style::properties::PROHIBIT_DISPLAY_CONTENTS;
use style::properties::animated_properties::{AnimatableLonghand, AnimationValue};
use style::properties::animated_properties::compare_property_priority;
use style::properties::parse_one_declaration_into;
use style::rule_tree::StyleSource;
use style::rule_tree::{CascadeLevel, StyleSource};
use style::selector_parser::PseudoElementCascadeType;
use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked};
use style::string_cache::Atom;
@ -1679,11 +1680,44 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
cascade_flags.insert(IS_FIELDSET_CONTENT);
}
let metrics = get_metrics_provider_for_product();
data.stylist.precomputed_values_for_pseudo(
// If the pseudo element is PageContent, we should append the precomputed
// pseudo element declerations with specified page rules.
let page_decls = match pseudo {
PseudoElement::PageContent => {
let mut declarations = vec![];
let iter = data.extra_style_data.iter_origins_rev();
for (data, origin) in iter {
let level = match origin {
Origin::UserAgent => CascadeLevel::UANormal,
Origin::User => CascadeLevel::UserNormal,
Origin::Author => CascadeLevel::AuthorNormal,
};
for rule in data.pages.iter() {
declarations.push(ApplicableDeclarationBlock::from_declarations(
rule.read_with(level.guard(&guards)).block.clone(),
level
));
}
}
Some(declarations)
},
_ => None,
};
let rule_node = data.stylist.rule_node_for_precomputed_pseudo(
&guards,
&pseudo,
page_decls,
);
data.stylist.precomputed_values_for_pseudo_with_rule_node(
&guards,
&pseudo,
parent_style_or_null.map(|x| &*x),
cascade_flags, &metrics
cascade_flags,
&metrics,
&rule_node
).into()
}