Skip to content

Commit a9f1997

Browse files
authored
Allow updating DPI, viewport, and theme of a pre-existing Device (#260)
This will allow Servo to update the `Device` and do media queries without having to create a new one. Signed-off-by: Martin Robinson <[email protected]>
1 parent 85ae0b1 commit a9f1997

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

style/servo/media_queries.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ impl Device {
225225
self.used_font_metrics.load(Ordering::Relaxed)
226226
}
227227

228+
/// Get the viewport size on this [`Device`].
229+
pub fn viewport_size(&self) -> Size2D<f32, CSSPixel> {
230+
self.viewport_size
231+
}
232+
233+
/// Set the viewport size on this [`Device`].
234+
///
235+
/// Note that this does not update any associated `Stylist`. For this you must call
236+
/// `Stylist::media_features_change_changed_style` and
237+
/// `Stylist::force_stylesheet_origins_dirty`.
238+
pub fn set_viewport_size(&mut self, viewport_size: Size2D<f32, CSSPixel>) {
239+
self.viewport_size = viewport_size;
240+
}
241+
228242
/// Returns the viewport size of the current device in app units, needed,
229243
/// among other things, to resolve viewport units.
230244
#[inline]
@@ -266,6 +280,18 @@ impl Device {
266280
self.device_pixel_ratio
267281
}
268282

283+
/// Set a new device pixel ratio on this [`Device`].
284+
///
285+
/// Note that this does not update any associated `Stylist`. For this you must call
286+
/// `Stylist::media_features_change_changed_style` and
287+
/// `Stylist::force_stylesheet_origins_dirty`.
288+
pub fn set_device_pixel_ratio(
289+
&mut self,
290+
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
291+
) {
292+
self.device_pixel_ratio = device_pixel_ratio;
293+
}
294+
269295
/// Gets the size of the scrollbar in CSS pixels.
270296
pub fn scrollbar_inline_size(&self) -> CSSPixelLength {
271297
// TODO: implement this.
@@ -305,6 +331,15 @@ impl Device {
305331
AbsoluteColor::BLACK
306332
}
307333

334+
/// Set the [`PrefersColorScheme`] value on this [`Device`].
335+
///
336+
/// Note that this does not update any associated `Stylist`. For this you must call
337+
/// `Stylist::media_features_change_changed_style` and
338+
/// `Stylist::force_stylesheet_origins_dirty`.
339+
pub fn set_color_scheme(&mut self, new_color_scheme: PrefersColorScheme) {
340+
self.prefers_color_scheme = new_color_scheme;
341+
}
342+
308343
/// Returns the color scheme of this [`Device`].
309344
pub fn color_scheme(&self) -> PrefersColorScheme {
310345
self.prefers_color_scheme

0 commit comments

Comments
 (0)