pub struct Device {Show 20 fields
media_type: MediaType,
viewport_size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
quirks_mode: QuirksMode,
root_style: RwLock<Arc<ComputedValues>>,
root_font_size: AtomicU32,
root_line_height: AtomicU32,
root_font_metrics_ex: AtomicU32,
root_font_metrics_cap: AtomicU32,
root_font_metrics_ch: AtomicU32,
root_font_metrics_ic: AtomicU32,
used_root_font_size: AtomicBool,
used_root_line_height: AtomicBool,
used_root_font_metrics: RwLock<bool>,
used_font_metrics: AtomicBool,
used_viewport_units: AtomicBool,
prefers_color_scheme: PrefersColorScheme,
environment: CssEnvironment,
font_metrics_provider: Box<dyn FontMetricsProvider>,
default_computed_values: Arc<ComputedValues>,
}Expand description
A device is a structure that represents the current media a given document is displayed in.
This is the struct against which media queries are evaluated. and contains all the viewport rule state.
This structure also contains atomics used for computing root font-relative units. These atomics use relaxed ordering, since 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).
Fields§
§media_type: MediaTypeThe current media type used by de device.
viewport_size: Size2D<f32, CSSPixel>The current viewport size, in CSS pixels.
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>The current device pixel ratio, from CSS pixels to device pixels.
quirks_mode: QuirksModeThe current quirks mode.
root_style: RwLock<Arc<ComputedValues>>Current computed style of the root element, used for calculations of root font-relative units.
root_font_size: AtomicU32Font size of the root element, used for rem units in other elements.
root_line_height: AtomicU32Line height of the root element, used for rlh units in other elements.
root_font_metrics_ex: AtomicU32X-height of the root element, used for rex units in other elements.
root_font_metrics_cap: AtomicU32Cap-height of the root element, used for rcap units in other elements.
root_font_metrics_ch: AtomicU32Advance measure (ch) of the root element, used for rch units in other elements.
root_font_metrics_ic: AtomicU32Ideographic advance measure of the root element, used for ric units in other elements.
used_root_font_size: AtomicBoolWhether any styles computed in the document relied on the root font-size by using rem units.
used_root_line_height: AtomicBoolWhether any styles computed in the document relied on the root line-height by using rlh units.
used_root_font_metrics: RwLock<bool>Whether any styles computed in the document relied on the root font metrics by using rcap, rch, rex, or ric units. This is a lock instead of an atomic in order to prevent concurrent writes to the root font metric values.
used_font_metrics: AtomicBoolWhether any styles computed in the document relied on font metrics.
used_viewport_units: AtomicBoolWhether any styles computed in the document relied on the viewport size.
prefers_color_scheme: PrefersColorSchemeWhether the user prefers light mode or dark mode
environment: CssEnvironmentThe CssEnvironment object responsible of getting CSS environment variables.
font_metrics_provider: Box<dyn FontMetricsProvider>An implementation of a trait which implements support for querying font metrics.
default_computed_values: Arc<ComputedValues>The default computed values for this Device.
Implementations§
Source§impl Device
impl Device
Sourcepub fn new(
media_type: MediaType,
quirks_mode: QuirksMode,
viewport_size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
font_metrics_provider: Box<dyn FontMetricsProvider>,
default_computed_values: Arc<ComputedValues>,
prefers_color_scheme: PrefersColorScheme,
) -> Device
pub fn new( media_type: MediaType, quirks_mode: QuirksMode, viewport_size: Size2D<f32, CSSPixel>, device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>, font_metrics_provider: Box<dyn FontMetricsProvider>, default_computed_values: Arc<ComputedValues>, prefers_color_scheme: PrefersColorScheme, ) -> Device
Trivially construct a new Device.
Sourcepub fn environment(&self) -> &CssEnvironment
pub fn environment(&self) -> &CssEnvironment
Get the relevant environment to resolve env() functions.
Sourcepub fn default_computed_values(&self) -> &ComputedValues
pub fn default_computed_values(&self) -> &ComputedValues
Return the default computed values for this device.
Sourcepub fn set_root_style(&self, style: &Arc<ComputedValues>)
pub fn set_root_style(&self, style: &Arc<ComputedValues>)
Store a pointer to the root element’s computed style, for use in calculation of root font-relative metrics.
Sourcepub fn root_font_size(&self) -> CSSPixelLength
pub fn root_font_size(&self) -> CSSPixelLength
Get the font size of the root element (for rem)
Sourcepub fn set_root_font_size(&self, size: f32)
pub fn set_root_font_size(&self, size: f32)
Set the font size of the root element (for rem), in zoom-independent CSS pixels.
Sourcepub fn root_line_height(&self) -> CSSPixelLength
pub fn root_line_height(&self) -> CSSPixelLength
Get the line height of the root element (for rlh)
Sourcepub fn set_root_line_height(&self, size: f32)
pub fn set_root_line_height(&self, size: f32)
Set the line height of the root element (for rlh), in zoom-independent CSS pixels.
Sourcepub fn root_font_metrics_ex(&self) -> Length
pub fn root_font_metrics_ex(&self) -> Length
Get the x-height of the root element (for rex)
Sourcepub fn set_root_font_metrics_ex(&self, size: f32) -> bool
pub fn set_root_font_metrics_ex(&self, size: f32) -> bool
Set the x-height of the root element (for rex), in zoom-independent CSS pixels.
Sourcepub fn root_font_metrics_cap(&self) -> Length
pub fn root_font_metrics_cap(&self) -> Length
Get the cap-height of the root element (for rcap)
Sourcepub fn set_root_font_metrics_cap(&self, size: f32) -> bool
pub fn set_root_font_metrics_cap(&self, size: f32) -> bool
Set the cap-height of the root element (for rcap), in zoom-independent CSS pixels.
Sourcepub fn root_font_metrics_ch(&self) -> Length
pub fn root_font_metrics_ch(&self) -> Length
Get the advance measure of the root element (for rch)
Sourcepub fn set_root_font_metrics_ch(&self, size: f32) -> bool
pub fn set_root_font_metrics_ch(&self, size: f32) -> bool
Set the advance measure of the root element (for rch), in zoom-independent CSS pixels.
Sourcepub fn root_font_metrics_ic(&self) -> Length
pub fn root_font_metrics_ic(&self) -> Length
Get the ideographic advance measure of the root element (for ric)
Sourcepub fn set_root_font_metrics_ic(&self, size: f32) -> bool
pub fn set_root_font_metrics_ic(&self, size: f32) -> bool
Set the ideographic advance measure of the root element (for ric), in zoom-independent CSS pixels.
Sourcepub fn calc_line_height(
&self,
font: &Font,
_writing_mode: WritingMode,
_element: Option<()>,
) -> NonNegativeLength
pub fn calc_line_height( &self, font: &Font, _writing_mode: WritingMode, _element: Option<()>, ) -> NonNegativeLength
Returns the computed line-height for the font in a given computed values instance.
If you pass down an element, then the used line-height is returned.
Sourcepub fn quirks_mode(&self) -> QuirksMode
pub fn quirks_mode(&self) -> QuirksMode
Get the quirks mode of the current device.
Sourcepub fn set_body_text_color(&self, _color: AbsoluteColor)
pub fn set_body_text_color(&self, _color: AbsoluteColor)
Sets the body text color for the “inherit color from body” quirk.
https://quirks.spec.whatwg.org/#the-tables-inherit-color-from-body-quirk
Sourcepub fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length
pub fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length
Gets the base size given a generic font family.
Sourcepub fn animation_name_may_be_referenced(&self, _: &KeyframesName) -> bool
pub fn animation_name_may_be_referenced(&self, _: &KeyframesName) -> bool
Whether a given animation name may be referenced from style.
Sourcepub fn used_root_font_size(&self) -> bool
pub fn used_root_font_size(&self) -> bool
Returns whether we ever looked up the root font size of the Device.
Sourcepub fn used_root_line_height(&self) -> bool
pub fn used_root_line_height(&self) -> bool
Returns whether we ever looked up the root line-height of the device.
Sourcepub fn used_root_font_metrics(&self) -> bool
pub fn used_root_font_metrics(&self) -> bool
Returns whether we ever looked up the root font metrics of the device.
Sourcepub fn used_font_metrics(&self) -> bool
pub fn used_font_metrics(&self) -> bool
Returns whether font metrics have been queried.
Sourcepub fn set_viewport_size(&mut self, viewport_size: Size2D<f32, CSSPixel>)
pub fn set_viewport_size(&mut self, viewport_size: Size2D<f32, CSSPixel>)
Set the viewport size on this Device.
Note that this does not update any associated Stylist. For this you must call
Stylist::media_features_change_changed_style and
Stylist::force_stylesheet_origins_dirty.
Sourcepub fn au_viewport_size(&self) -> UntypedSize2D<Au>
pub fn au_viewport_size(&self) -> UntypedSize2D<Au>
Returns the viewport size of the current device in app units, needed, among other things, to resolve viewport units.
Sourcepub fn au_viewport_size_for_viewport_unit_resolution(
&self,
_: ViewportVariant,
) -> UntypedSize2D<Au>
pub fn au_viewport_size_for_viewport_unit_resolution( &self, _: ViewportVariant, ) -> UntypedSize2D<Au>
Like the above, but records that we’ve used viewport units.
Sourcepub fn used_viewport_units(&self) -> bool
pub fn used_viewport_units(&self) -> bool
Whether viewport units were used since the last device change.
Sourcepub fn app_units_per_device_pixel(&self) -> i32
pub fn app_units_per_device_pixel(&self) -> i32
Returns the number of app units per device pixel we’re using currently.
Sourcepub fn device_pixel_ratio_ignoring_full_zoom(
&self,
) -> Scale<f32, CSSPixel, DevicePixel>
pub fn device_pixel_ratio_ignoring_full_zoom( &self, ) -> Scale<f32, CSSPixel, DevicePixel>
Returns the device pixel ratio, ignoring the full zoom factor.
Sourcepub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>
pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>
Returns the device pixel ratio.
Sourcepub fn set_device_pixel_ratio(
&mut self,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
)
pub fn set_device_pixel_ratio( &mut self, device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>, )
Set a new device pixel ratio on this Device.
Note that this does not update any associated Stylist. For this you must call
Stylist::media_features_change_changed_style and
Stylist::force_stylesheet_origins_dirty.
Sourcepub fn scrollbar_inline_size(&self) -> CSSPixelLength
pub fn scrollbar_inline_size(&self) -> CSSPixelLength
Gets the size of the scrollbar in CSS pixels.
Sourcepub fn query_font_metrics(
&self,
vertical: bool,
font: &Font,
base_size: CSSPixelLength,
flags: QueryFontMetricsFlags,
track_usage: bool,
) -> FontMetrics
pub fn query_font_metrics( &self, vertical: bool, font: &Font, base_size: CSSPixelLength, flags: QueryFontMetricsFlags, track_usage: bool, ) -> FontMetrics
Queries font metrics using the FontMetricsProvider interface.
fn ensure_root_font_metrics_updated(&self)
Sourcepub fn update_root_font_metrics(&self) -> bool
pub fn update_root_font_metrics(&self) -> bool
Compute the root element’s font metrics, and returns a bool indicating whether the font metrics have changed since the previous restyle.
Sourcepub fn media_type(&self) -> MediaType
pub fn media_type(&self) -> MediaType
Return the media type of the current device.
Sourcepub fn forced_colors(&self) -> ForcedColors
pub fn forced_colors(&self) -> ForcedColors
Returns whether document colors are enabled.
Sourcepub fn default_background_color(&self) -> AbsoluteColor
pub fn default_background_color(&self) -> AbsoluteColor
Returns the default background color.
Sourcepub fn default_color(&self) -> AbsoluteColor
pub fn default_color(&self) -> AbsoluteColor
Returns the default foreground color.
Sourcepub fn set_color_scheme(&mut self, new_color_scheme: PrefersColorScheme)
pub fn set_color_scheme(&mut self, new_color_scheme: PrefersColorScheme)
Set the PrefersColorScheme value on this Device.
Note that this does not update any associated Stylist. For this you must call
Stylist::media_features_change_changed_style and
Stylist::force_stylesheet_origins_dirty.
Sourcepub fn color_scheme(&self) -> PrefersColorScheme
pub fn color_scheme(&self) -> PrefersColorScheme
Returns the color scheme of this Device.
pub(crate) fn is_dark_color_scheme(&self, _: ColorSchemeFlags) -> bool
Sourcepub fn safe_area_insets(&self) -> SideOffsets2D<f32, CSSPixel>
pub fn safe_area_insets(&self) -> SideOffsets2D<f32, CSSPixel>
Returns safe area insets
Sourcepub fn is_supported_mime_type(&self, mime_type: &str) -> bool
pub fn is_supported_mime_type(&self, mime_type: &str) -> bool
Returns true if the given MIME type is supported
Sourcepub fn chrome_rules_enabled_for_document(&self) -> bool
pub fn chrome_rules_enabled_for_document(&self) -> bool
Return whether the document is a chrome document.
Trait Implementations§
Source§impl MallocSizeOf for Device
impl MallocSizeOf for Device
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !Freeze for Device
impl !RefUnwindSafe for Device
impl !Send for Device
impl Sync for Device
impl Unpin for Device
impl !UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more