mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue