mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: Parameterize the update and rebuild methods to take an iterator.
In preparation to avoid cloning the stylesheets while rebuilding in Gecko.
This commit is contained in:
parent
50e0c67e2c
commit
677daaabc5
5 changed files with 39 additions and 30 deletions
|
@ -1091,7 +1091,7 @@ impl LayoutThread {
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
};
|
};
|
||||||
let needs_dirtying = self.stylist.update(
|
let needs_dirtying = self.stylist.update(
|
||||||
&data.document_stylesheets,
|
data.document_stylesheets.iter(),
|
||||||
&guards,
|
&guards,
|
||||||
Some(ua_stylesheets),
|
Some(ua_stylesheets),
|
||||||
data.stylesheets_changed,
|
data.stylesheets_changed,
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl PerDocumentStyleDataImpl {
|
||||||
let mut stylesheets = Vec::<Arc<Stylesheet>>::new();
|
let mut stylesheets = Vec::<Arc<Stylesheet>>::new();
|
||||||
self.stylesheets.flush(&mut stylesheets);
|
self.stylesheets.flush(&mut stylesheets);
|
||||||
self.stylist.clear();
|
self.stylist.clear();
|
||||||
self.stylist.rebuild(stylesheets.as_slice(),
|
self.stylist.rebuild(stylesheets.iter(),
|
||||||
&StylesheetGuards::same(guard),
|
&StylesheetGuards::same(guard),
|
||||||
/* ua_sheets = */ None,
|
/* ua_sheets = */ None,
|
||||||
/* stylesheets_changed = */ true,
|
/* stylesheets_changed = */ true,
|
||||||
|
|
|
@ -268,13 +268,15 @@ impl Stylist {
|
||||||
/// This method resets all the style data each time the stylesheets change
|
/// This method resets all the style data each time the stylesheets change
|
||||||
/// (which is indicated by the `stylesheets_changed` parameter), or the
|
/// (which is indicated by the `stylesheets_changed` parameter), or the
|
||||||
/// device is dirty, which means we need to re-evaluate media queries.
|
/// device is dirty, which means we need to re-evaluate media queries.
|
||||||
pub fn rebuild<'a>(&mut self,
|
pub fn rebuild<'a, 'b, I>(&mut self,
|
||||||
doc_stylesheets: &[Arc<Stylesheet>],
|
doc_stylesheets: I,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
ua_stylesheets: Option<&UserAgentStylesheets>,
|
ua_stylesheets: Option<&UserAgentStylesheets>,
|
||||||
stylesheets_changed: bool,
|
stylesheets_changed: bool,
|
||||||
author_style_disabled: bool,
|
author_style_disabled: bool,
|
||||||
extra_data: &mut ExtraStyleData<'a>) -> bool {
|
extra_data: &mut ExtraStyleData<'a>) -> bool
|
||||||
|
where I: Iterator<Item = &'b Arc<Stylesheet>> + Clone,
|
||||||
|
{
|
||||||
debug_assert!(!self.is_cleared || self.is_device_dirty);
|
debug_assert!(!self.is_cleared || self.is_device_dirty);
|
||||||
|
|
||||||
self.is_cleared = false;
|
self.is_cleared = false;
|
||||||
|
@ -287,7 +289,7 @@ impl Stylist {
|
||||||
|
|
||||||
let cascaded_rule = ViewportRule {
|
let cascaded_rule = ViewportRule {
|
||||||
declarations: viewport::Cascade::from_stylesheets(
|
declarations: viewport::Cascade::from_stylesheets(
|
||||||
doc_stylesheets, guards.author, &self.device
|
doc_stylesheets.clone(), guards.author, &self.device
|
||||||
).finish(),
|
).finish(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -317,7 +319,7 @@ impl Stylist {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only use author stylesheets if author styles are enabled.
|
// Only use author stylesheets if author styles are enabled.
|
||||||
let sheets_to_add = doc_stylesheets.iter().filter(|s| {
|
let sheets_to_add = doc_stylesheets.filter(|s| {
|
||||||
!author_style_disabled || s.origin != Origin::Author
|
!author_style_disabled || s.origin != Origin::Author
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -338,13 +340,15 @@ impl Stylist {
|
||||||
|
|
||||||
/// clear the stylist and then rebuild it. Chances are, you want to use
|
/// clear the stylist and then rebuild it. Chances are, you want to use
|
||||||
/// either clear() or rebuild(), with the latter done lazily, instead.
|
/// either clear() or rebuild(), with the latter done lazily, instead.
|
||||||
pub fn update<'a>(&mut self,
|
pub fn update<'a, 'b, I>(&mut self,
|
||||||
doc_stylesheets: &[Arc<Stylesheet>],
|
doc_stylesheets: I,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
ua_stylesheets: Option<&UserAgentStylesheets>,
|
ua_stylesheets: Option<&UserAgentStylesheets>,
|
||||||
stylesheets_changed: bool,
|
stylesheets_changed: bool,
|
||||||
author_style_disabled: bool,
|
author_style_disabled: bool,
|
||||||
extra_data: &mut ExtraStyleData<'a>) -> bool {
|
extra_data: &mut ExtraStyleData<'a>) -> bool
|
||||||
|
where I: Iterator<Item = &'b Arc<Stylesheet>> + Clone,
|
||||||
|
{
|
||||||
debug_assert!(!self.is_cleared || self.is_device_dirty);
|
debug_assert!(!self.is_cleared || self.is_device_dirty);
|
||||||
|
|
||||||
// We have to do a dirtiness check before clearing, because if
|
// We have to do a dirtiness check before clearing, because if
|
||||||
|
@ -357,7 +361,9 @@ impl Stylist {
|
||||||
author_style_disabled, extra_data)
|
author_style_disabled, extra_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_stylesheet<'a>(&mut self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard,
|
fn add_stylesheet<'a>(&mut self,
|
||||||
|
stylesheet: &Stylesheet,
|
||||||
|
guard: &SharedRwLockReadGuard,
|
||||||
extra_data: &mut ExtraStyleData<'a>) {
|
extra_data: &mut ExtraStyleData<'a>) {
|
||||||
if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device, guard) {
|
if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device, guard) {
|
||||||
return;
|
return;
|
||||||
|
@ -656,10 +662,12 @@ impl Stylist {
|
||||||
/// FIXME(emilio): The semantics of the device for Servo and Gecko are
|
/// FIXME(emilio): The semantics of the device for Servo and Gecko are
|
||||||
/// different enough we may want to unify them.
|
/// different enough we may want to unify them.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub fn set_device(&mut self, mut device: Device, guard: &SharedRwLockReadGuard,
|
pub fn set_device(&mut self,
|
||||||
|
mut device: Device,
|
||||||
|
guard: &SharedRwLockReadGuard,
|
||||||
stylesheets: &[Arc<Stylesheet>]) {
|
stylesheets: &[Arc<Stylesheet>]) {
|
||||||
let cascaded_rule = ViewportRule {
|
let cascaded_rule = ViewportRule {
|
||||||
declarations: viewport::Cascade::from_stylesheets(stylesheets, guard, &device).finish(),
|
declarations: viewport::Cascade::from_stylesheets(stylesheets.iter(), guard, &device).finish(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.viewport_constraints =
|
self.viewport_constraints =
|
||||||
|
|
|
@ -26,6 +26,7 @@ use std::iter::Enumerate;
|
||||||
use std::str::Chars;
|
use std::str::Chars;
|
||||||
use style_traits::{PinchZoomFactor, ToCss};
|
use style_traits::{PinchZoomFactor, ToCss};
|
||||||
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
|
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
|
||||||
|
use stylearc::Arc;
|
||||||
use stylesheets::{Stylesheet, Origin};
|
use stylesheets::{Stylesheet, Origin};
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::specified::{NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength};
|
use values::specified::{NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength};
|
||||||
|
@ -329,7 +330,6 @@ fn is_whitespace_separator_or_equals(c: &char) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for ViewportRule {
|
impl Parse for ViewportRule {
|
||||||
#[allow(missing_docs)]
|
|
||||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
let parser = ViewportRuleParser { context: context };
|
let parser = ViewportRuleParser { context: context };
|
||||||
|
|
||||||
|
@ -545,14 +545,15 @@ impl Cascade {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_stylesheets<'a, I>(stylesheets: I, guard: &SharedRwLockReadGuard,
|
pub fn from_stylesheets<'a, I>(stylesheets: I,
|
||||||
device: &Device) -> Self
|
guard: &SharedRwLockReadGuard,
|
||||||
where I: IntoIterator,
|
device: &Device)
|
||||||
I::Item: AsRef<Stylesheet>,
|
-> Self
|
||||||
|
where I: Iterator<Item = &'a Arc<Stylesheet>>,
|
||||||
{
|
{
|
||||||
let mut cascade = Self::new();
|
let mut cascade = Self::new();
|
||||||
for stylesheet in stylesheets {
|
for stylesheet in stylesheets {
|
||||||
stylesheet.as_ref().effective_viewport_rules(device, guard, |rule| {
|
stylesheet.effective_viewport_rules(device, guard, |rule| {
|
||||||
for declaration in &rule.declarations {
|
for declaration in &rule.declarations {
|
||||||
cascade.add(Cow::Borrowed(declaration))
|
cascade.add(Cow::Borrowed(declaration))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ macro_rules! stylesheet {
|
||||||
stylesheet!($css, $origin, $error_reporter, SharedRwLock::new())
|
stylesheet!($css, $origin, $error_reporter, SharedRwLock::new())
|
||||||
};
|
};
|
||||||
($css:expr, $origin:ident, $error_reporter:expr, $shared_lock:expr) => {
|
($css:expr, $origin:ident, $error_reporter:expr, $shared_lock:expr) => {
|
||||||
Box::new(Stylesheet::from_str(
|
Arc::new(Stylesheet::from_str(
|
||||||
$css,
|
$css,
|
||||||
ServoUrl::parse("http://localhost").unwrap(),
|
ServoUrl::parse("http://localhost").unwrap(),
|
||||||
Origin::$origin,
|
Origin::$origin,
|
||||||
|
@ -269,7 +269,7 @@ fn multiple_stylesheets_cascading() {
|
||||||
Author, error_reporter, shared_lock.clone())
|
Author, error_reporter, shared_lock.clone())
|
||||||
];
|
];
|
||||||
|
|
||||||
let declarations = Cascade::from_stylesheets(&stylesheets, &shared_lock.read(), &device).finish();
|
let declarations = Cascade::from_stylesheets(stylesheets.iter(), &shared_lock.read(), &device).finish();
|
||||||
assert_decl_len!(declarations == 3);
|
assert_decl_len!(declarations == 3);
|
||||||
assert_decl_eq!(&declarations[0], UserAgent, Zoom: Zoom::Number(1.));
|
assert_decl_eq!(&declarations[0], UserAgent, Zoom: Zoom::Number(1.));
|
||||||
assert_decl_eq!(&declarations[1], User, MinHeight: viewport_length!(200., px));
|
assert_decl_eq!(&declarations[1], User, MinHeight: viewport_length!(200., px));
|
||||||
|
@ -283,7 +283,7 @@ fn multiple_stylesheets_cascading() {
|
||||||
stylesheet!("@viewport { min-width: 300px !important; min-height: 300px !important; zoom: 3 !important; }",
|
stylesheet!("@viewport { min-width: 300px !important; min-height: 300px !important; zoom: 3 !important; }",
|
||||||
Author, error_reporter, shared_lock.clone())
|
Author, error_reporter, shared_lock.clone())
|
||||||
];
|
];
|
||||||
let declarations = Cascade::from_stylesheets(&stylesheets, &shared_lock.read(), &device).finish();
|
let declarations = Cascade::from_stylesheets(stylesheets.iter(), &shared_lock.read(), &device).finish();
|
||||||
assert_decl_len!(declarations == 3);
|
assert_decl_len!(declarations == 3);
|
||||||
assert_decl_eq!(&declarations[0], UserAgent, MinWidth: viewport_length!(100., px), !important);
|
assert_decl_eq!(&declarations[0], UserAgent, MinWidth: viewport_length!(100., px), !important);
|
||||||
assert_decl_eq!(&declarations[1], User, MinHeight: viewport_length!(200., px), !important);
|
assert_decl_eq!(&declarations[1], User, MinHeight: viewport_length!(200., px), !important);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue