mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Introduce CSSPixel as a replacement for ViewportPx and PagePx.
This commit is contained in:
parent
56a99577b3
commit
30ff2f8f0d
16 changed files with 81 additions and 92 deletions
|
@ -26,33 +26,41 @@ extern crate rustc_serialize;
|
|||
/// Must be transmutable to and from `TNode`.
|
||||
pub type UnsafeNode = (usize, usize);
|
||||
|
||||
/// Represents a mobile style pinch zoom factor.
|
||||
/// TODO(gw): Once WR supports pinch zoom, use a type directly from webrender_traits.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, HeapSizeOf))]
|
||||
pub struct PinchZoomFactor(f32);
|
||||
|
||||
impl PinchZoomFactor {
|
||||
/// Construct a new pinch zoom factor.
|
||||
pub fn new(scale: f32) -> PinchZoomFactor {
|
||||
PinchZoomFactor(scale)
|
||||
}
|
||||
|
||||
/// Get the pinch zoom factor as an untyped float.
|
||||
pub fn get(&self) -> f32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// One CSS "px" in the coordinate system of the "initial viewport":
|
||||
/// http://www.w3.org/TR/css-device-adapt/#initial-viewport
|
||||
///
|
||||
/// `ViewportPx` is equal to `DeviceIndependentPixel` times a "page zoom" factor controlled by the user. This is
|
||||
/// `CSSPixel` is equal to `DeviceIndependentPixel` times a "page zoom" factor controlled by the user. This is
|
||||
/// the desktop-style "full page" zoom that enlarges content but then reflows the layout viewport
|
||||
/// so it still exactly fits the visible area.
|
||||
///
|
||||
/// At the default zoom level of 100%, one `PagePx` is equal to one `DeviceIndependentPixel`. However, if the
|
||||
/// At the default zoom level of 100%, one `CSSPixel` is equal to one `DeviceIndependentPixel`. However, if the
|
||||
/// document is zoomed in or out then this scale may be larger or smaller.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum ViewportPx {}
|
||||
|
||||
/// One CSS "px" in the root coordinate system for the content document.
|
||||
///
|
||||
/// `PagePx` is equal to `ViewportPx` multiplied by a "viewport zoom" factor controlled by the user.
|
||||
/// This is the mobile-style "pinch zoom" that enlarges content without reflowing it. When the
|
||||
/// viewport zoom is not equal to 1.0, then the layout viewport is no longer the same physical size
|
||||
/// as the viewable area.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum PagePx {}
|
||||
pub enum CSSPixel {}
|
||||
|
||||
// In summary, the hierarchy of pixel units and the factors to convert from one to the next:
|
||||
//
|
||||
// DevicePixel
|
||||
// / hidpi_ratio => DeviceIndependentPixel
|
||||
// / desktop_zoom => ViewportPx
|
||||
// / pinch_zoom => PagePx
|
||||
// / desktop_zoom => CSSPixel
|
||||
|
||||
pub mod cursor;
|
||||
#[macro_use]
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
//! Helper types for the `@viewport` rule.
|
||||
|
||||
use {PagePx, ViewportPx};
|
||||
use {CSSPixel, PinchZoomFactor};
|
||||
use cssparser::{Parser, ToCss};
|
||||
use euclid::scale_factor::ScaleFactor;
|
||||
use euclid::size::TypedSize2D;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::fmt;
|
||||
|
@ -31,13 +30,13 @@ pub struct ViewportConstraints {
|
|||
/// Width and height:
|
||||
/// * https://drafts.csswg.org/css-device-adapt/#width-desc
|
||||
/// * https://drafts.csswg.org/css-device-adapt/#height-desc
|
||||
pub size: TypedSize2D<f32, ViewportPx>,
|
||||
pub size: TypedSize2D<f32, CSSPixel>,
|
||||
/// https://drafts.csswg.org/css-device-adapt/#zoom-desc
|
||||
pub initial_zoom: ScaleFactor<f32, PagePx, ViewportPx>,
|
||||
pub initial_zoom: PinchZoomFactor,
|
||||
/// https://drafts.csswg.org/css-device-adapt/#min-max-width-desc
|
||||
pub min_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
||||
pub min_zoom: Option<PinchZoomFactor>,
|
||||
/// https://drafts.csswg.org/css-device-adapt/#min-max-width-desc
|
||||
pub max_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
||||
pub max_zoom: Option<PinchZoomFactor>,
|
||||
/// https://drafts.csswg.org/css-device-adapt/#user-zoom-desc
|
||||
pub user_zoom: UserZoom,
|
||||
/// https://drafts.csswg.org/css-device-adapt/#orientation-desc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue