Skip to main content

style/device/
servo.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Servo-specific logic for [`Device`].
6
7use crate::color::AbsoluteColor;
8use crate::context::QuirksMode;
9use crate::substitution::env::CssEnvironment;
10use crate::font_metrics::FontMetrics;
11use crate::logical_geometry::WritingMode;
12use crate::media_queries::MediaType;
13use crate::properties::ComputedValues;
14use crate::properties::style_structs::Font;
15use crate::queries::values::{
16    PrefersColorScheme, PrefersContrast, PrefersReducedMotion, PrefersReducedTransparency,
17};
18use crate::servo::media_features::PointerCapabilities;
19use crate::values::KeyframesName;
20use crate::values::computed::font::GenericFontFamily;
21use crate::values::computed::{
22    CSSPixelLength, Length, LineHeight, LinkParameters, NonNegativeLength,
23};
24use crate::values::specified::ViewportVariant;
25use crate::values::specified::color::{ColorSchemeFlags, ForcedColors, SystemColor};
26use crate::values::specified::font::{
27    FONT_MEDIUM_CAP_PX, FONT_MEDIUM_CH_PX, FONT_MEDIUM_EX_PX, FONT_MEDIUM_IC_PX,
28    FONT_MEDIUM_LINE_HEIGHT_PX, FONT_MEDIUM_PX, QueryFontMetricsFlags,
29};
30use app_units::{AU_PER_PX, Au};
31use euclid::default::Size2D as UntypedSize2D;
32use euclid::{Scale, SideOffsets2D, Size2D};
33use malloc_size_of_derive::MallocSizeOf;
34use mime::Mime;
35use parking_lot::RwLock;
36use servo_arc::Arc;
37use siphasher::sip::SipHasher13;
38use std::fmt::Debug;
39use std::hash::Hasher;
40use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
41use style_traits::{CSSPixel, DevicePixel};
42
43use crate::device::Device;
44
45/// A trait used to query font metrics in clients of Stylo. This is used by Device to
46/// query font metrics in a way that is specific to the client using Stylo.
47pub trait FontMetricsProvider: Debug + Sync {
48    /// Query the font metrics for the given font and the given base font size.
49    fn query_font_metrics(
50        &self,
51        vertical: bool,
52        font: &Font,
53        base_size: CSSPixelLength,
54        flags: QueryFontMetricsFlags,
55    ) -> FontMetrics;
56    /// Gets the base size given a generic font family.
57    fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length;
58}
59
60#[derive(Debug, MallocSizeOf)]
61pub(super) struct ExtraDeviceData {
62    /// Data which Stylo uses to evaluate media queries
63    media_data: MediaData,
64    /// An implementation of a trait which implements support for querying font metrics.
65    #[ignore_malloc_size_of = "Owned by embedder"]
66    font_metrics_provider: Box<dyn FontMetricsProvider>,
67    /// Document-scoped key for hashing the inputs of CSS `random()` functions.
68    document_random_hasher_key: (u64, u64),
69}
70
71#[derive(Debug, MallocSizeOf, Clone, PartialEq)]
72/// Data which Stylo uses to evaluate media queries
73pub struct MediaData {
74    /// The current media type used by de device.
75    pub media_type: MediaType,
76    /// The current viewport size, in CSS pixels.
77    pub viewport_size: Size2D<f32, CSSPixel>,
78    /// The current screen size, in device pixels.
79    pub device_size: Size2D<f32, DevicePixel>,
80    /// The current device pixel ratio, from CSS pixels to device pixels.
81    pub device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
82    /// The current quirks mode.
83    #[ignore_malloc_size_of = "Pure stack type"]
84    pub quirks_mode: QuirksMode,
85    /// Whether the user prefers light mode or dark mode
86    #[ignore_malloc_size_of = "Pure stack type"]
87    pub prefers_color_scheme: PrefersColorScheme,
88    /// Whether the user prefers more or less contrast
89    #[ignore_malloc_size_of = "Pure stack type"]
90    pub prefers_contrast: PrefersContrast,
91    /// Whether the user prefers reduced motion
92    #[ignore_malloc_size_of = "Pure stack type"]
93    pub prefers_reduced_motion: PrefersReducedMotion,
94    /// Whether the user prefers reduced transparency
95    #[ignore_malloc_size_of = "Pure stack type"]
96    pub prefers_reduced_transparency: PrefersReducedTransparency,
97    /// The capabilities of the primary pointer input
98    #[ignore_malloc_size_of = "Pure stack type"]
99    pub primary_pointer_capabilities: PointerCapabilities,
100    /// The union of the capabilities of all pointer inputs
101    #[ignore_malloc_size_of = "Pure stack type"]
102    pub all_pointer_capabilities: PointerCapabilities,
103}
104
105impl Device {
106    /// Trivially construct a new `Device`.
107    pub fn new(
108        default_values: Arc<ComputedValues>,
109        font_metrics_provider: Box<dyn FontMetricsProvider>,
110        submit_string: Box<str>,
111        document_random_hasher_key: (u64, u64),
112        media_data: MediaData,
113    ) -> Device {
114        let root_style = RwLock::new(Arc::clone(&default_values));
115        Device {
116            root_style,
117            root_font_size: AtomicU32::new(FONT_MEDIUM_PX.to_bits()),
118            root_line_height: AtomicU32::new(FONT_MEDIUM_LINE_HEIGHT_PX.to_bits()),
119            root_font_metrics_ex: AtomicU32::new(FONT_MEDIUM_EX_PX.to_bits()),
120            root_font_metrics_cap: AtomicU32::new(FONT_MEDIUM_CAP_PX.to_bits()),
121            root_font_metrics_ch: AtomicU32::new(FONT_MEDIUM_CH_PX.to_bits()),
122            root_font_metrics_ic: AtomicU32::new(FONT_MEDIUM_IC_PX.to_bits()),
123            used_root_font_size: AtomicBool::new(false),
124            used_root_line_height: AtomicBool::new(false),
125            used_root_font_metrics: RwLock::new(false),
126            used_font_metrics: AtomicBool::new(false),
127            used_viewport_size: AtomicBool::new(false),
128            used_dynamic_viewport_size: AtomicBool::new(false),
129            environment: CssEnvironment,
130            default_values,
131            body_text_color: RwLock::new(AbsoluteColor::BLACK),
132            submit_string,
133            extra: ExtraDeviceData {
134                media_data,
135                font_metrics_provider,
136                document_random_hasher_key,
137            },
138        }
139    }
140
141    /// Returns the computed line-height for the font in a given computed values instance.
142    ///
143    /// If you pass down an element, then the used line-height is returned.
144    pub fn calc_line_height(
145        &self,
146        font: &crate::properties::style_structs::Font,
147        _writing_mode: WritingMode,
148        _element: Option<()>,
149    ) -> NonNegativeLength {
150        (match font.line_height {
151            // TODO: compute `normal` from the font metrics
152            LineHeight::Normal => CSSPixelLength::new(0.),
153            LineHeight::Number(number) => font.font_size.computed_size() * number.0,
154            LineHeight::Length(length) => length.0,
155        })
156        .into()
157    }
158
159    /// Get the quirks mode of the current device.
160    pub fn quirks_mode(&self) -> QuirksMode {
161        self.extra.media_data.quirks_mode
162    }
163
164    /// Returns a hasher specific to this document, used to vary the random
165    /// base values of `random()` functions between document instances.
166    #[inline]
167    pub fn document_random_hasher(&self) -> impl Hasher {
168        let (k0, k1) = self.extra.document_random_hasher_key;
169        SipHasher13::new_with_keys(k0, k1)
170    }
171
172    /// Gets the base size given a generic font family.
173    pub fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length {
174        self.extra
175            .font_metrics_provider
176            .base_size_for_generic(generic)
177    }
178
179    /// Whether a given animation name may be referenced from style.
180    pub fn animation_name_may_be_referenced(&self, _: &KeyframesName) -> bool {
181        // Assume it is, since we don't have any good way to prove it's not.
182        true
183    }
184
185    /// Get the [`MediaData`] associated with this [`Device`].
186    #[inline]
187    pub fn media_data(&self) -> &MediaData {
188        &self.extra.media_data
189    }
190
191    /// Mutate the [`MediaData`] on this [`Device`].
192    ///
193    /// Note that this does not update any associated `Stylist`. For this you must call
194    /// `Stylist::media_features_change_changed_style` and
195    /// `Stylist::force_stylesheet_origins_dirty`.
196    pub fn media_data_mut(&mut self) -> &mut MediaData {
197        &mut self.extra.media_data
198    }
199
200    /// Set the [`MediaData`] on this [`Device`].
201    ///
202    /// Note that this does not update any associated `Stylist`. For this you must call
203    /// `Stylist::media_features_change_changed_style` and
204    /// `Stylist::force_stylesheet_origins_dirty`.
205    pub fn set_media_data(&mut self, media_data: MediaData) {
206        self.extra.media_data = media_data;
207    }
208
209    /// Get the viewport size on this [`Device`].
210    pub fn viewport_size(&self) -> Size2D<f32, CSSPixel> {
211        self.extra.media_data.viewport_size
212    }
213
214    /// Set the viewport size on this [`Device`].
215    ///
216    /// Note that this does not update any associated `Stylist`. For this you must call
217    /// `Stylist::media_features_change_changed_style` and
218    /// `Stylist::force_stylesheet_origins_dirty`.
219    pub fn set_viewport_size(&mut self, viewport_size: Size2D<f32, CSSPixel>) {
220        self.extra.media_data.viewport_size = viewport_size;
221    }
222
223    /// Returns the viewport size of the current device in app units, needed,
224    /// among other things, to resolve viewport units.
225    #[inline]
226    pub fn au_viewport_size(&self) -> UntypedSize2D<Au> {
227        Size2D::new(
228            Au::from_f32_px(self.extra.media_data.viewport_size.width),
229            Au::from_f32_px(self.extra.media_data.viewport_size.height),
230        )
231    }
232
233    /// Like the above, but records that we've used viewport units.
234    pub fn au_viewport_size_for_viewport_unit_resolution(
235        &self,
236        _: ViewportVariant,
237    ) -> UntypedSize2D<Au> {
238        self.used_viewport_size.store(true, Ordering::Relaxed);
239        // Servo doesn't have dynamic UA interfaces that affect the viewport,
240        // so we can just ignore the ViewportVariant.
241        self.au_viewport_size()
242    }
243
244    /// Returns the number of app units per device pixel we're using currently.
245    pub fn app_units_per_device_pixel(&self) -> i32 {
246        (AU_PER_PX as f32 / self.extra.media_data.device_pixel_ratio.0) as i32
247    }
248
249    /// Returns the device pixel ratio, ignoring the full zoom factor.
250    pub fn device_pixel_ratio_ignoring_full_zoom(&self) -> Scale<f32, CSSPixel, DevicePixel> {
251        self.extra.media_data.device_pixel_ratio
252    }
253
254    /// Returns the device pixel ratio.
255    pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel> {
256        self.extra.media_data.device_pixel_ratio
257    }
258
259    /// Set a new device pixel ratio on this [`Device`].
260    ///
261    /// Note that this does not update any associated `Stylist`. For this you must call
262    /// `Stylist::media_features_change_changed_style` and
263    /// `Stylist::force_stylesheet_origins_dirty`.
264    pub fn set_device_pixel_ratio(
265        &mut self,
266        device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
267    ) {
268        self.extra.media_data.device_pixel_ratio = device_pixel_ratio;
269    }
270
271    /// Set the device size on this [`Device`] (e.g. the available screen dimensions).
272    ///
273    /// Note that this does not update any associated `Stylist`. For this you must call
274    /// `Stylist::media_features_change_changed_style` and
275    /// `Stylist::force_stylesheet_origins_dirty`.
276    pub fn set_device_size(&mut self, device_size: Size2D<f32, DevicePixel>) {
277        self.extra.media_data.device_size = device_size;
278    }
279
280    /// Returns the screen size of the current device in app units.
281    #[inline]
282    pub fn device_size(&self) -> Size2D<f32, DevicePixel> {
283        self.extra.media_data.device_size
284    }
285
286    /// Gets the size of the scrollbar in CSS pixels.
287    pub fn scrollbar_inline_size(&self) -> CSSPixelLength {
288        // TODO: implement this.
289        CSSPixelLength::new(0.0)
290    }
291
292    /// Queries font metrics using the [`FontMetricsProvider`] interface.
293    pub fn query_font_metrics(
294        &self,
295        vertical: bool,
296        font: &Font,
297        base_size: CSSPixelLength,
298        flags: QueryFontMetricsFlags,
299        track_usage: bool,
300    ) -> FontMetrics {
301        if track_usage {
302            self.used_font_metrics.store(true, Ordering::Relaxed);
303        }
304        self.extra
305            .font_metrics_provider
306            .query_font_metrics(vertical, font, base_size, flags)
307    }
308
309    /// Set the media type on this [`Device`].
310    ///
311    /// Note that this does not update any associated `Stylist`. For this you must call
312    /// `Stylist::media_features_change_changed_style` and
313    /// `Stylist::force_stylesheet_origins_dirty`.
314    pub fn set_media_type(&mut self, media_type: MediaType) {
315        self.extra.media_data.media_type = media_type;
316    }
317
318    /// Return the media type of the current device.
319    pub fn media_type(&self) -> MediaType {
320        self.extra.media_data.media_type.clone()
321    }
322
323    /// Returns whether document colors are enabled.
324    pub fn forced_colors(&self) -> ForcedColors {
325        ForcedColors::None
326    }
327
328    /// Returns the default background color.
329    pub fn default_background_color(&self) -> AbsoluteColor {
330        AbsoluteColor::WHITE
331    }
332
333    /// Returns the default foreground color.
334    pub fn default_color(&self) -> AbsoluteColor {
335        AbsoluteColor::BLACK
336    }
337
338    /// Set the [`PrefersColorScheme`] value on this [`Device`].
339    ///
340    /// Note that this does not update any associated `Stylist`. For this you must call
341    /// `Stylist::media_features_change_changed_style` and
342    /// `Stylist::force_stylesheet_origins_dirty`.
343    pub fn set_color_scheme(&mut self, new_color_scheme: PrefersColorScheme) {
344        self.extra.media_data.prefers_color_scheme = new_color_scheme;
345    }
346
347    /// Returns the color scheme of this [`Device`].
348    pub fn color_scheme(&self) -> PrefersColorScheme {
349        self.extra.media_data.prefers_color_scheme
350    }
351
352    /// Set the [`PrefersContrast`] value on this [`Device`].
353    ///
354    /// Note that this does not update any associated `Stylist`. For this you must call
355    /// `Stylist::media_features_change_changed_style` and
356    /// `Stylist::force_stylesheet_origins_dirty`.
357    pub fn set_contrast(&mut self, new_contrast: PrefersContrast) {
358        self.extra.media_data.prefers_contrast = new_contrast;
359    }
360
361    /// Returns the preferred contrast of this [`Device`].
362    pub fn contrast(&self) -> PrefersContrast {
363        self.extra.media_data.prefers_contrast
364    }
365
366    /// Set the [`PrefersReducedMotion`] value on this [`Device`].
367    ///
368    /// Note that this does not update any associated `Stylist`. For this you must call
369    /// `Stylist::media_features_change_changed_style` and
370    /// `Stylist::force_stylesheet_origins_dirty`.
371    pub fn set_reduced_motion(&mut self, new_reduced_motion: PrefersReducedMotion) {
372        self.extra.media_data.prefers_reduced_motion = new_reduced_motion;
373    }
374
375    /// Returns the preferred reduced motion of this [`Device`].
376    pub fn reduced_motion(&self) -> PrefersReducedMotion {
377        self.extra.media_data.prefers_reduced_motion
378    }
379
380    /// Set the [`PrefersReducedTransparency`] value on this [`Device`].
381    ///
382    /// Note that this does not update any associated `Stylist`. For this you must call
383    /// `Stylist::media_features_change_changed_style` and
384    /// `Stylist::force_stylesheet_origins_dirty`.
385    pub fn set_reduced_transparency(
386        &mut self,
387        new_reduced_transparency: PrefersReducedTransparency,
388    ) {
389        self.extra.media_data.prefers_reduced_transparency = new_reduced_transparency;
390    }
391
392    /// Returns the preferred reduced transparency of this [`Device`].
393    pub fn reduced_transparency(&self) -> PrefersReducedTransparency {
394        self.extra.media_data.prefers_reduced_transparency
395    }
396
397    /// Set the [`PointerCapbabilities`] value for the primary pointer on this [`Device`]
398    ///
399    /// Note that this does not update any associated `Stylist`. For this you must call
400    /// `Stylist::media_features_change_changed_style` and
401    /// `Stylist::force_stylesheet_origins_dirty`.
402    pub fn set_primary_pointer_capabilities(&mut self, capabilities: PointerCapabilities) {
403        self.extra.media_data.primary_pointer_capabilities = capabilities;
404    }
405
406    /// Returns the pointer capabilities of this [`Device`].
407    pub fn primary_pointer_capabilities(&self) -> PointerCapabilities {
408        self.extra.media_data.primary_pointer_capabilities
409    }
410
411    /// Set the [`PointerCapbabilities`] value for all pointers on this [`Device`]
412    ///
413    /// Note that this does not update any associated `Stylist`. For this you must call
414    /// `Stylist::media_features_change_changed_style` and
415    /// `Stylist::force_stylesheet_origins_dirty`.
416    pub fn set_all_pointer_capabilities(&mut self, capabilities: PointerCapabilities) {
417        self.extra.media_data.all_pointer_capabilities = capabilities;
418    }
419
420    /// Returns the pointer capabilities of this [`Device`].
421    pub fn all_pointer_capabilities(&self) -> PointerCapabilities {
422        self.extra.media_data.all_pointer_capabilities
423    }
424
425    pub(crate) fn is_dark_color_scheme(&self, color_scheme_flags: ColorSchemeFlags) -> bool {
426        // Inspired by
427        // https://searchfox.org/firefox-main/rev/0a7f146ccac85b8f413264042dcd764028d419ec/widget/nsXPLookAndFeel.cpp#1296
428        let supports_dark_mode = color_scheme_flags.contains(ColorSchemeFlags::DARK);
429        let supports_light_mode = color_scheme_flags.contains(ColorSchemeFlags::LIGHT);
430
431        // If only one is supported, then use dark mode if it was the supported one.
432        if supports_dark_mode != supports_light_mode {
433            return supports_dark_mode;
434        }
435
436        // If either both or none are supported, then use the preferred color scheme
437        // to determine whether the user wants dark mode.
438        return self.color_scheme() == PrefersColorScheme::Dark;
439    }
440
441    pub(crate) fn system_color(
442        &self,
443        system_color: SystemColor,
444        color_scheme_flags: ColorSchemeFlags,
445    ) -> AbsoluteColor {
446        fn srgb(r: u8, g: u8, b: u8) -> AbsoluteColor {
447            AbsoluteColor::srgb_legacy(r, g, b, 1f32)
448        }
449
450        // Refer to spec
451        // <https://www.w3.org/TR/css-color-4/#css-system-colors>
452        if self.is_dark_color_scheme(color_scheme_flags) {
453            match system_color {
454                SystemColor::Accentcolor => srgb(10, 132, 255),
455                SystemColor::Accentcolortext => srgb(255, 255, 255),
456                SystemColor::Activetext => srgb(255, 0, 0),
457                SystemColor::Linktext => srgb(158, 158, 255),
458                SystemColor::Visitedtext => srgb(208, 173, 240),
459                SystemColor::Buttonborder
460                // Deprecated system colors (CSS Color 4) mapped to Buttonborder.
461                | SystemColor::Activeborder
462                | SystemColor::Inactiveborder
463                | SystemColor::Threeddarkshadow
464                | SystemColor::Threedshadow
465                | SystemColor::Windowframe => srgb(255, 255, 255),
466                SystemColor::Buttonface
467                // Deprecated system colors (CSS Color 4) mapped to Buttonface.
468                | SystemColor::Buttonhighlight
469                | SystemColor::Buttonshadow
470                | SystemColor::Threedface
471                | SystemColor::Threedhighlight
472                | SystemColor::Threedlightshadow => srgb(107, 107, 107),
473                SystemColor::Buttontext => srgb(245, 245, 245),
474                SystemColor::Canvas
475                // Deprecated system colors (CSS Color 4) mapped to Canvas.
476                | SystemColor::Activecaption
477                | SystemColor::Appworkspace
478                | SystemColor::Background
479                | SystemColor::Inactivecaption
480                | SystemColor::Infobackground
481                | SystemColor::Menu
482                | SystemColor::Scrollbar
483                | SystemColor::Window => srgb(30, 30, 30),
484                SystemColor::Canvastext
485                // Deprecated system colors (CSS Color 4) mapped to Canvastext.
486                | SystemColor::Captiontext
487                | SystemColor::Infotext
488                | SystemColor::Menutext
489                | SystemColor::Windowtext => srgb(232, 232, 232),
490                SystemColor::Field => srgb(45, 45, 45),
491                SystemColor::Fieldtext => srgb(240, 240, 240),
492                SystemColor::Graytext
493                // Deprecated system colors (CSS Color 4) mapped to Graytext.
494                | SystemColor::Inactivecaptiontext => srgb(155, 155, 155),
495                SystemColor::Highlight => srgb(38, 79, 120),
496                SystemColor::Highlighttext => srgb(255, 255, 255),
497                SystemColor::Mark => srgb(102, 92, 0),
498                SystemColor::Marktext => srgb(255, 255, 255),
499                SystemColor::Selecteditem => srgb(153, 200, 255),
500                SystemColor::Selecteditemtext => srgb(59, 59, 59),
501            }
502        } else {
503            match system_color {
504                SystemColor::Accentcolor => srgb(0, 102, 204),
505                SystemColor::Accentcolortext => srgb(255, 255, 255),
506                SystemColor::Activetext => srgb(238, 0, 0),
507                SystemColor::Linktext => srgb(0, 0, 238),
508                SystemColor::Visitedtext => srgb(85, 26, 139),
509                SystemColor::Buttonborder
510                // Deprecated system colors (CSS Color 4) mapped to Buttonborder.
511                | SystemColor::Activeborder
512                | SystemColor::Inactiveborder
513                | SystemColor::Threeddarkshadow
514                | SystemColor::Threedshadow
515                | SystemColor::Windowframe => srgb(169, 169, 169),
516                SystemColor::Buttonface
517                // Deprecated system colors (CSS Color 4) mapped to Buttonface.
518                | SystemColor::Buttonhighlight
519                | SystemColor::Buttonshadow
520                | SystemColor::Threedface
521                | SystemColor::Threedhighlight
522                | SystemColor::Threedlightshadow => srgb(220, 220, 220),
523                SystemColor::Buttontext => srgb(0, 0, 0),
524                SystemColor::Canvas
525                // Deprecated system colors (CSS Color 4) mapped to Canvas.
526                | SystemColor::Activecaption
527                | SystemColor::Appworkspace
528                | SystemColor::Background
529                | SystemColor::Inactivecaption
530                | SystemColor::Infobackground
531                | SystemColor::Menu
532                | SystemColor::Scrollbar
533                | SystemColor::Window => srgb(255, 255, 255),
534                SystemColor::Canvastext
535                // Deprecated system colors (CSS Color 4) mapped to Canvastext.
536                | SystemColor::Captiontext
537                | SystemColor::Infotext
538                | SystemColor::Menutext
539                | SystemColor::Windowtext => srgb(0, 0, 0),
540                SystemColor::Field => srgb(255, 255, 255),
541                SystemColor::Fieldtext => srgb(0, 0, 0),
542                SystemColor::Graytext
543                // Deprecated system colors (CSS Color 4) mapped to Graytext.
544                | SystemColor::Inactivecaptiontext => srgb(109, 109, 109),
545                SystemColor::Highlight => srgb(0, 65, 198),
546                SystemColor::Highlighttext => srgb(0, 0, 0),
547                SystemColor::Mark => srgb(255, 235, 59),
548                SystemColor::Marktext => srgb(0, 0, 0),
549                SystemColor::Selecteditem => srgb(0, 102, 204),
550                SystemColor::Selecteditemtext => srgb(255, 255, 255),
551            }
552        }
553    }
554
555    /// Returns the current effective text zoom.
556    #[inline]
557    pub(super) fn text_zoom(&self) -> f32 {
558        // (Servo doesn't do text-zoom)
559        1.
560    }
561
562    /// Returns safe area insets
563    pub fn safe_area_insets(&self) -> SideOffsets2D<f32, CSSPixel> {
564        SideOffsets2D::zero()
565    }
566
567    /// Returns true if the given MIME type is supported
568    pub fn is_supported_mime_type(&self, mime_type: &str) -> bool {
569        match mime_type.parse::<Mime>() {
570            Ok(m) => {
571                // Keep this in sync with 'image_classifer' from
572                // components/net/mime_classifier.rs
573                m == mime::IMAGE_BMP
574                    || m == mime::IMAGE_GIF
575                    || m == mime::IMAGE_PNG
576                    || m == mime::IMAGE_JPEG
577                    || m == "image/x-icon"
578                    || m == "image/webp"
579            },
580            _ => false,
581        }
582    }
583
584    /// Return whether the document is a chrome document.
585    #[inline]
586    pub fn chrome_rules_enabled_for_document(&self) -> bool {
587        false
588    }
589
590    /// Returns the link-parameters that have been set for this document.
591    /// <https://drafts.csswg.org/css-link-params-1/>
592    #[inline]
593    pub fn link_parameters(&self) -> Option<&LinkParameters> {
594        None
595    }
596}