Struct style::servo::media_queries::Device
source · pub struct Device {Show 14 fields
media_type: MediaType,
viewport_size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
quirks_mode: QuirksMode,
root_font_size: AtomicU32,
root_line_height: AtomicU32,
used_root_font_size: AtomicBool,
used_root_line_height: AtomicBool,
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.
Fields§
§media_type: MediaType
The 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: QuirksMode
The current quirks mode.
root_font_size: AtomicU32
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_line_height: AtomicU32
Line height of the root element, used for rlh units in other elements.
used_root_font_size: AtomicBool
Whether any styles computed in the document relied on the root font-size by using rem units.
used_root_line_height: AtomicBool
Whether any styles computed in the document relied on the root line-height by using rlh units.
used_font_metrics: AtomicBool
Whether any styles computed in the document relied on font metrics.
used_viewport_units: AtomicBool
Whether any styles computed in the document relied on the viewport size.
prefers_color_scheme: PrefersColorScheme
Whether the user prefers light mode or dark mode
environment: CssEnvironment
The 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 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 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_font_metrics(&self) -> bool
pub fn used_font_metrics(&self) -> bool
Returns whether font metrics have been queried.
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(&self) -> Scale<f32, CSSPixel, DevicePixel>
pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>
Returns the device pixel ratio.
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,
in_media_query: bool,
retrieve_math_scales: bool,
) -> FontMetrics
pub fn query_font_metrics( &self, vertical: bool, font: &Font, base_size: CSSPixelLength, in_media_query: bool, retrieve_math_scales: bool, ) -> FontMetrics
Queries font metrics using the FontMetricsProvider
interface.
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 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