pub struct Device {
    media_type: MediaType,
    viewport_size: Size2D<f32, CSSPixel>,
    device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
    quirks_mode: QuirksMode,
    root_font_size: AtomicU32,
    used_root_font_size: AtomicBool,
    used_viewport_units: AtomicBool,
    environment: CssEnvironment,
}
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.

§used_root_font_size: AtomicBool

Whether any styles computed in the document relied on the root font-size by using rem units.

§used_viewport_units: AtomicBool

Whether any styles computed in the document relied on the viewport size.

§environment: CssEnvironment

The CssEnvironment object responsible of getting CSS environment variables.

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>
) -> 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: CSSPixelLength)

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

source

pub fn quirks_mode(&self) -> QuirksMode

Get the quirks mode of the current device.

source

pub fn set_body_text_color(&self, _color: RGBA)

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 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 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) -> 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 device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel>

Returns the device pixel ratio.

source

pub fn query_font_metrics(
    &self,
    _vertical: bool,
    _font: &Font,
    _base_size: CSSPixelLength,
    _in_media_query: bool,
    _retrieve_math_scales: bool
) -> FontMetrics

Queries dummy font metrics for Servo. Knows nothing about fonts and does not provide any metrics. TODO: Servo’s font metrics provider will probably not live in this crate, so this will have to be replaced with something else (perhaps a trait method on TElement) when we get there

source

pub fn account_for_viewport_rule(&mut self, constraints: &ViewportConstraints)

Take into account a viewport rule taken from the stylesheets.

source

pub fn media_type(&self) -> MediaType

Return the media type of the current device.

source

pub fn use_document_colors(&self) -> bool

Returns whether document colors are enabled.

source

pub fn default_background_color_for_forced_colors(&self) -> RGBA

Returns the default background color.

source

pub fn default_color_for_forced_colors(&self) -> RGBA

Returns the default foreground color.

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 titlebar_radius(&self) -> f32

Returns the gtk titlebar radius in CSS pixels. TODO: implement this method.

source

pub fn menu_radius(&self) -> f32

Returns the gtk menu radius in CSS pixels. TODO: implement this method.

source

pub fn is_chrome_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§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> MaybeBoxed<Box<T, Global>> for T

source§

fn maybe_boxed(self) -> Box<T, Global>

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 = mem::align_of::<T>()

The alignment of pointer.
§

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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere
    V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
    S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Erased for T