mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move root_font_size to the device
This commit is contained in:
parent
af124f2d89
commit
ce2237e123
5 changed files with 53 additions and 24 deletions
|
@ -17,7 +17,9 @@ use gecko_bindings::structs::RawGeckoPresContextOwned;
|
|||
use media_queries::MediaType;
|
||||
use parser::ParserContext;
|
||||
use properties::{ComputedValues, StyleBuilder};
|
||||
use properties::longhands::font_size;
|
||||
use std::fmt::{self, Write};
|
||||
use std::sync::atomic::{AtomicIsize, Ordering};
|
||||
use str::starts_with_ignore_ascii_case;
|
||||
use string_cache::Atom;
|
||||
use style_traits::ToCss;
|
||||
|
@ -35,8 +37,20 @@ pub struct Device {
|
|||
pub pres_context: RawGeckoPresContextOwned,
|
||||
default_values: Arc<ComputedValues>,
|
||||
viewport_override: Option<ViewportConstraints>,
|
||||
/// The font size of the root element
|
||||
/// This is set when computing the style of the root
|
||||
/// element, and used for rem units in other elements.
|
||||
///
|
||||
/// When computing the style of the root element, there can't be any
|
||||
/// other style being computed at the same time, given we need the style of
|
||||
/// the parent to compute everything else. So it is correct to just use
|
||||
/// a relaxed atomic here.
|
||||
root_font_size: AtomicIsize,
|
||||
}
|
||||
|
||||
unsafe impl Sync for Device {}
|
||||
unsafe impl Send for Device {}
|
||||
|
||||
impl Device {
|
||||
/// Trivially constructs a new `Device`.
|
||||
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
|
||||
|
@ -45,6 +59,7 @@ impl Device {
|
|||
pres_context: pres_context,
|
||||
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
||||
viewport_override: None,
|
||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +88,16 @@ impl Device {
|
|||
&self.default_values
|
||||
}
|
||||
|
||||
/// Get the font size of the root element (for rem)
|
||||
pub fn root_font_size(&self) -> Au {
|
||||
Au::new(self.root_font_size.load(Ordering::Relaxed) as i32)
|
||||
}
|
||||
|
||||
/// Set the font size of the root element (for rem)
|
||||
pub fn set_root_font_size(&self, size: Au) {
|
||||
self.root_font_size.store(size.0 as isize, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Recreates all the temporary state that the `Device` stores.
|
||||
///
|
||||
/// This includes the viewport override from `@viewport` rules, and also the
|
||||
|
@ -111,9 +136,6 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for Device {}
|
||||
unsafe impl Send for Device {}
|
||||
|
||||
/// A expression for gecko contains a reference to the media feature, the value
|
||||
/// the media query contained, and the range to evaluate.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -84,7 +84,6 @@ pub struct ComputedValues {
|
|||
|
||||
custom_properties: Option<Arc<ComputedValuesMap>>,
|
||||
pub writing_mode: WritingMode,
|
||||
pub root_font_size: Au,
|
||||
pub font_computation_data: FontComputationData,
|
||||
|
||||
/// The element's computed values if visited, only computed if there's a
|
||||
|
@ -96,7 +95,6 @@ pub struct ComputedValues {
|
|||
impl ComputedValues {
|
||||
pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
% for style_struct in data.style_structs:
|
||||
|
@ -106,7 +104,6 @@ impl ComputedValues {
|
|||
ComputedValues {
|
||||
custom_properties: custom_properties,
|
||||
writing_mode: writing_mode,
|
||||
root_font_size: root_font_size,
|
||||
font_computation_data: FontComputationData::new(font_size_keyword),
|
||||
visited_style: visited_style,
|
||||
% for style_struct in data.style_structs:
|
||||
|
@ -119,7 +116,6 @@ impl ComputedValues {
|
|||
Arc::new(ComputedValues {
|
||||
custom_properties: None,
|
||||
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
|
||||
font_computation_data: FontComputationData::default_values(),
|
||||
visited_style: None,
|
||||
% for style_struct in data.style_structs:
|
||||
|
|
|
@ -1828,8 +1828,6 @@ pub struct ComputedValues {
|
|||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
/// The writing mode of this computed values struct.
|
||||
pub writing_mode: WritingMode,
|
||||
/// The root element's computed font size.
|
||||
pub root_font_size: Au,
|
||||
/// The keyword behind the current font-size property, if any
|
||||
pub font_computation_data: FontComputationData,
|
||||
|
||||
|
@ -1844,7 +1842,6 @@ impl ComputedValues {
|
|||
/// Construct a `ComputedValues` instance.
|
||||
pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -1854,7 +1851,6 @@ impl ComputedValues {
|
|||
ComputedValues {
|
||||
custom_properties: custom_properties,
|
||||
writing_mode: writing_mode,
|
||||
root_font_size: root_font_size,
|
||||
font_computation_data: FontComputationData::new(font_size_keyword),
|
||||
visited_style: visited_style,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2292,8 +2288,6 @@ pub struct StyleBuilder<'a> {
|
|||
///
|
||||
/// TODO(emilio): Make private.
|
||||
pub writing_mode: WritingMode,
|
||||
/// The font size of the root element.
|
||||
pub root_font_size: Au,
|
||||
/// The keyword behind the current font-size property, if any.
|
||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
/// The element's style if visited, only computed if there's a relevant link
|
||||
|
@ -2310,7 +2304,6 @@ impl<'a> StyleBuilder<'a> {
|
|||
pub fn new(
|
||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2320,7 +2313,6 @@ impl<'a> StyleBuilder<'a> {
|
|||
StyleBuilder {
|
||||
custom_properties: custom_properties,
|
||||
writing_mode: writing_mode,
|
||||
root_font_size: root_font_size,
|
||||
font_size_keyword: font_size_keyword,
|
||||
visited_style: visited_style,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2340,7 +2332,6 @@ impl<'a> StyleBuilder<'a> {
|
|||
pub fn for_inheritance(parent: &'a ComputedValues, default: &'a ComputedValues) -> Self {
|
||||
Self::new(parent.custom_properties(),
|
||||
parent.writing_mode,
|
||||
parent.root_font_size,
|
||||
parent.font_computation_data.font_size_keyword,
|
||||
parent.clone_visited_style(),
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2414,7 +2405,6 @@ impl<'a> StyleBuilder<'a> {
|
|||
pub fn build(self) -> ComputedValues {
|
||||
ComputedValues::new(self.custom_properties,
|
||||
self.writing_mode,
|
||||
self.root_font_size,
|
||||
self.font_size_keyword,
|
||||
self.visited_style,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2458,8 +2448,7 @@ mod lazy_static_module {
|
|||
% endfor
|
||||
custom_properties: None,
|
||||
writing_mode: WritingMode::empty(),
|
||||
root_font_size: longhands::font_size::get_initial_value(),
|
||||
font_computation_data: FontComputationData::default_values()
|
||||
font_computation_data: FontComputationData::default_values(),
|
||||
visited_style: None,
|
||||
};
|
||||
}
|
||||
|
@ -2608,7 +2597,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
let builder = if !flags.contains(INHERIT_ALL) {
|
||||
StyleBuilder::new(custom_properties,
|
||||
WritingMode::empty(),
|
||||
inherited_style.root_font_size,
|
||||
inherited_style.font_computation_data.font_size_keyword,
|
||||
visited_style,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2622,7 +2610,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
} else {
|
||||
StyleBuilder::new(custom_properties,
|
||||
WritingMode::empty(),
|
||||
inherited_style.root_font_size,
|
||||
inherited_style.font_computation_data.font_size_keyword,
|
||||
visited_style,
|
||||
% for style_struct in data.active_style_structs():
|
||||
|
@ -2788,7 +2775,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
|
||||
if is_root_element {
|
||||
let s = context.style.get_font().clone_font_size();
|
||||
context.style.root_font_size = s;
|
||||
context.device.set_root_font_size(s);
|
||||
}
|
||||
% endif
|
||||
% endfor
|
||||
|
|
|
@ -12,7 +12,9 @@ use font_metrics::ServoMetricsProvider;
|
|||
use media_queries::MediaType;
|
||||
use parser::ParserContext;
|
||||
use properties::{ComputedValues, StyleBuilder};
|
||||
use properties::longhands::font_size;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicIsize, Ordering};
|
||||
use style_traits::{CSSPixel, ToCss};
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use values::computed::{self, ToComputedValue};
|
||||
|
@ -22,12 +24,23 @@ use values::specified;
|
|||
/// is displayed in.
|
||||
///
|
||||
/// This is the struct against which media queries are evaluated.
|
||||
#[derive(Debug, HeapSizeOf)]
|
||||
#[derive(HeapSizeOf)]
|
||||
pub struct Device {
|
||||
/// The current media type used by de device.
|
||||
media_type: MediaType,
|
||||
/// The current viewport size, in CSS pixels.
|
||||
viewport_size: TypedSize2D<f32, CSSPixel>,
|
||||
|
||||
/// The font size of the root element
|
||||
/// This is set when computing the style of the root
|
||||
/// element, and used for rem units in other elements
|
||||
///
|
||||
/// When computing the style of the root element, there can't be any
|
||||
/// other style being computed at the same time, given we need the style of
|
||||
/// the parent to compute everything else. So it is correct to just use
|
||||
/// a relaxed atomic here.
|
||||
#[ignore_heap_size_of = "Pure stack type"]
|
||||
root_font_size: AtomicIsize,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
|
@ -38,6 +51,7 @@ impl Device {
|
|||
Device {
|
||||
media_type: media_type,
|
||||
viewport_size: viewport_size,
|
||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +63,16 @@ impl Device {
|
|||
ComputedValues::initial_values()
|
||||
}
|
||||
|
||||
/// Get the font size of the root element (for rem)
|
||||
pub fn root_font_size(&self) -> Au {
|
||||
Au::new(self.root_font_size.load(Ordering::Relaxed) as i32)
|
||||
}
|
||||
|
||||
/// Set the font size of the root element (for rem)
|
||||
pub fn set_root_font_size(&self, size: Au) {
|
||||
self.root_font_size.store(size.0 as isize, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Returns the viewport size of the current device in app units, needed,
|
||||
/// among other things, to resolve viewport units.
|
||||
#[inline]
|
||||
|
|
|
@ -112,7 +112,7 @@ impl FontRelativeLength {
|
|||
|
||||
let reference_font_size = base_size.resolve(context);
|
||||
|
||||
let root_font_size = context.style().root_font_size;
|
||||
let root_font_size = context.device.root_font_size();
|
||||
match *self {
|
||||
FontRelativeLength::Em(length) => reference_font_size.scale_by(length),
|
||||
FontRelativeLength::Ex(length) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue