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

source

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.

source

pub fn environment(&self) -> &CssEnvironment

Get the relevant environment to resolve env() functions.

source

pub fn default_computed_values(&self) -> &ComputedValues

Return the default computed values for this device.

source

pub fn root_font_size(&self) -> CSSPixelLength

Get the font size of the root element (for rem)

source

pub fn set_root_font_size(&self, size: f32)

Set the font size of the root element (for rem), in zoom-independent CSS pixels.

source

pub fn root_line_height(&self) -> CSSPixelLength

Get the line height of the root element (for rlh)

source

pub fn set_root_line_height(&self, size: f32)

Set the line height of the root element (for rlh), in zoom-independent CSS pixels.

source

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.

source

pub fn quirks_mode(&self) -> QuirksMode

Get the quirks mode of the current device.

source

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

source

pub fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length

Gets the base size given a generic font family.

source

pub fn animation_name_may_be_referenced(&self, _: &KeyframesName) -> bool

Whether a given animation name may be referenced from style.

source

pub fn used_root_font_size(&self) -> bool

Returns whether we ever looked up the root font size of the Device.

source

pub fn used_root_line_height(&self) -> bool

Returns whether we ever looked up the root line-height of the device.

source

pub fn used_font_metrics(&self) -> bool

Returns whether font metrics have been queried.

source

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.

source

pub fn au_viewport_size_for_viewport_unit_resolution( &self, _: ViewportVariant, ) -> UntypedSize2D<Au>

Like the above, but records that we’ve used viewport units.

source

pub fn used_viewport_units(&self) -> bool

Whether viewport units were used since the last device change.

source

pub fn app_units_per_device_pixel(&self) -> i32

Returns the number of app units per device pixel we’re using currently.

source

pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>

Returns the device pixel ratio.

source

pub fn scrollbar_inline_size(&self) -> CSSPixelLength

Gets the size of the scrollbar in CSS pixels.

source

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.

source

pub fn media_type(&self) -> MediaType

Return the media type of the current device.

source

pub fn forced_colors(&self) -> ForcedColors

Returns whether document colors are enabled.

source

pub fn default_background_color(&self) -> AbsoluteColor

Returns the default background color.

source

pub fn default_color(&self) -> AbsoluteColor

Returns the default foreground color.

source

pub fn color_scheme(&self) -> PrefersColorScheme

Returns the color scheme of this Device.

source

pub(crate) fn is_dark_color_scheme(&self, _: ColorSchemeFlags) -> bool

source

pub fn safe_area_insets(&self) -> SideOffsets2D<f32, CSSPixel>

Returns safe area insets

source

pub fn is_supported_mime_type(&self, mime_type: &str) -> bool

Returns true if the given MIME type is supported

source

pub fn chrome_rules_enabled_for_document(&self) -> bool

Return whether the document is a chrome document.

Trait Implementations§

source§

impl Debug for Device

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl MallocSizeOf for Device

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> MaybeBoxed<Box<T>> for T

source§

fn maybe_boxed(self) -> Box<T>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T