diff options
Diffstat (limited to 'servo/components/style/gecko/media_queries.rs')
-rw-r--r-- | servo/components/style/gecko/media_queries.rs | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/servo/components/style/gecko/media_queries.rs b/servo/components/style/gecko/media_queries.rs index ef156ab380..ded66027f2 100644 --- a/servo/components/style/gecko/media_queries.rs +++ b/servo/components/style/gecko/media_queries.rs @@ -29,6 +29,8 @@ use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering}; use std::{cmp, fmt}; use style_traits::{CSSPixel, DevicePixel}; +use super::media_features::ForcedColors; + /// The `Device` in Gecko wraps a pres context, has a default values computed, /// and contains all the viewport rule state. pub struct Device { @@ -172,10 +174,9 @@ impl Device { Length::new(f32::from_bits(self.root_font_size.load(Ordering::Relaxed))) } - /// Set the font size of the root element (for rem) - pub fn set_root_font_size(&self, size: Length) { - self.root_font_size - .store(size.px().to_bits(), Ordering::Relaxed) + /// Set the font size of the root element (for rem), in zoom-independent CSS pixels. + pub fn set_root_font_size(&self, size: f32) { + self.root_font_size.store(size.to_bits(), Ordering::Relaxed) } /// Get the line height of the root element (for rlh) @@ -186,10 +187,9 @@ impl Device { )) } - /// Set the line height of the root element (for rlh) - pub fn set_root_line_height(&self, size: Length) { - self.root_line_height - .store(size.px().to_bits(), Ordering::Relaxed); + /// Set the line height of the root element (for rlh), in zoom-independent CSS pixels. + pub fn set_root_line_height(&self, size: f32) { + self.root_line_height.store(size.to_bits(), Ordering::Relaxed); } /// The quirks mode of the document. @@ -498,12 +498,27 @@ impl Device { /// Returns whether document colors are enabled. #[inline] - pub fn use_document_colors(&self) -> bool { - let doc = self.document(); - if doc.mIsBeingUsedAsImage() { - return true; + pub fn forced_colors(&self) -> ForcedColors { + if self.document().mIsBeingUsedAsImage() { + // SVG images never force colors. + return ForcedColors::None + } + let prefs = self.pref_sheet_prefs(); + if !prefs.mUseDocumentColors { + return ForcedColors::Active + } + // On Windows, having a high contrast theme also means that the OS is requesting the + // colors to be forced. This is mostly convenience for the front-end, which wants to + // reuse the forced-colors styles for chrome in this case as well, and it's a lot + // more convenient to use `(forced-colors)` than + // `(forced-colors) or ((-moz-platform: windows) and (prefers-contrast))`. + // + // TODO(emilio): We might want to factor in here the lwtheme attribute in the root element + // and so on. + if cfg!(target_os = "windows") && prefs.mUseAccessibilityTheme && prefs.mIsChrome { + return ForcedColors::Requested; } - self.pref_sheet_prefs().mUseDocumentColors + ForcedColors::None } /// Computes a system color and returns it as an nscolor. |