mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #15680 - glennw:zoom-wip, r=mbrubeck
Rename ScreenPx to DeviceIndependentPixel. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15680) <!-- Reviewable:end -->
This commit is contained in:
commit
03893e25cc
9 changed files with 43 additions and 44 deletions
|
@ -27,7 +27,7 @@ use script_traits::{TouchpadPressurePhase, TouchEventType, TouchId, WindowSizeDa
|
|||
use script_traits::CompositorEvent::{self, MouseMoveEvent, MouseButtonEvent, TouchEvent, TouchpadPressureEvent};
|
||||
use servo_config::opts;
|
||||
use servo_config::prefs::PREFS;
|
||||
use servo_geometry::ScreenPx;
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
use servo_url::ServoUrl;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
|
@ -155,10 +155,10 @@ pub struct IOCompositor<Window: WindowMethods> {
|
|||
|
||||
/// "Desktop-style" zoom that resizes the viewport to fit the window.
|
||||
/// See `ViewportPx` docs in util/geom.rs for details.
|
||||
page_zoom: ScaleFactor<f32, ViewportPx, ScreenPx>,
|
||||
page_zoom: ScaleFactor<f32, ViewportPx, DeviceIndependentPixel>,
|
||||
|
||||
/// The device pixel ratio for this window.
|
||||
scale_factor: ScaleFactor<f32, ScreenPx, DevicePixel>,
|
||||
scale_factor: ScaleFactor<f32, DeviceIndependentPixel, DevicePixel>,
|
||||
|
||||
channel_to_self: Box<CompositorProxy + Send>,
|
||||
|
||||
|
@ -378,7 +378,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
fn new(window: Rc<Window>, state: InitialCompositorState)
|
||||
-> IOCompositor<Window> {
|
||||
let window_size = window.framebuffer_size();
|
||||
let scale_factor = window.scale_factor();
|
||||
let scale_factor = window.hidpi_factor();
|
||||
let composite_target = match opts::get().output_file {
|
||||
Some(_) => CompositeTarget::PngFile,
|
||||
None => CompositeTarget::Window
|
||||
|
@ -756,7 +756,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
|
||||
fn send_window_size(&self, size_type: WindowSizeType) {
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let initial_viewport = self.window_size.to_f32() / dppx;
|
||||
let visible_viewport = initial_viewport / self.viewport_zoom;
|
||||
let msg = ConstellationMsg::WindowSize(WindowSizeData {
|
||||
|
@ -889,7 +889,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
debug!("compositor resizing to {:?}", new_size.to_untyped());
|
||||
|
||||
// A size change could also mean a resolution change.
|
||||
let new_scale_factor = self.window.scale_factor();
|
||||
let new_scale_factor = self.window.hidpi_factor();
|
||||
if self.scale_factor != new_scale_factor {
|
||||
self.scale_factor = new_scale_factor;
|
||||
self.update_zoom_transform();
|
||||
|
@ -948,7 +948,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
};
|
||||
|
||||
if let Some(pipeline) = self.pipeline(root_pipeline_id) {
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
let event_to_send = match mouse_window_event {
|
||||
MouseWindowEvent::Click(button, _) => {
|
||||
|
@ -986,7 +986,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
return;
|
||||
}
|
||||
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let event_to_send = MouseMoveEvent(Some((cursor / dppx).to_untyped()));
|
||||
let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send);
|
||||
if let Some(pipeline) = self.pipeline(root_pipeline_id) {
|
||||
|
@ -1012,7 +1012,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||
self.touch_handler.on_touch_down(identifier, point);
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Down,
|
||||
identifier,
|
||||
|
@ -1042,7 +1042,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
});
|
||||
}
|
||||
TouchAction::DispatchEvent => {
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Move,
|
||||
identifier,
|
||||
|
@ -1053,7 +1053,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
|
||||
fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Up,
|
||||
identifier,
|
||||
|
@ -1066,7 +1066,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||
// Send the event to script.
|
||||
self.touch_handler.on_touch_cancel(identifier, point);
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Cancel,
|
||||
identifier,
|
||||
|
@ -1078,7 +1078,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
pressure: f32,
|
||||
phase: TouchpadPressurePhase) {
|
||||
if let Some(true) = PREFS.get("dom.forcetouch.enabled").as_boolean() {
|
||||
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
|
||||
let dppx = self.page_zoom * self.hidpi_factor();
|
||||
let translated_point = (point / dppx).to_untyped();
|
||||
self.send_event_to_root_pipeline(TouchpadPressureEvent(translated_point,
|
||||
pressure,
|
||||
|
@ -1291,7 +1291,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
}
|
||||
|
||||
fn device_pixels_per_screen_px(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
|
||||
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
|
||||
match opts::get().device_pixels_per_px {
|
||||
Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px),
|
||||
None => match opts::get().output_file {
|
||||
|
@ -1302,7 +1302,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
}
|
||||
|
||||
fn device_pixels_per_page_px(&self) -> ScaleFactor<f32, PagePx, DevicePixel> {
|
||||
self.viewport_zoom * self.page_zoom * self.device_pixels_per_screen_px()
|
||||
self.viewport_zoom * self.page_zoom * self.hidpi_factor()
|
||||
}
|
||||
|
||||
fn update_zoom_transform(&mut self) {
|
||||
|
|
|
@ -7,7 +7,7 @@ use euclid::scale_factor::ScaleFactor;
|
|||
use script_traits::{DevicePixel, EventResult, TouchId};
|
||||
use self::TouchState::*;
|
||||
|
||||
/// Minimum number of `ScreenPx` to begin touch scrolling.
|
||||
/// Minimum number of `DeviceIndependentPixel` to begin touch scrolling.
|
||||
const TOUCH_PAN_MIN_SCREEN_PX: f32 = 20.0;
|
||||
|
||||
pub struct TouchHandler {
|
||||
|
@ -100,7 +100,6 @@ impl TouchHandler {
|
|||
let action = match self.state {
|
||||
Touching => {
|
||||
let delta = point - old_point;
|
||||
// TODO let delta: TypedPoint2D<_, ScreenPx> = delta / self.device_pixels_per_screen_px();
|
||||
|
||||
if delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
|
||||
delta.y.abs() > TOUCH_PAN_MIN_SCREEN_PX
|
||||
|
|
|
@ -12,7 +12,7 @@ use euclid::size::TypedSize2D;
|
|||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||
use net_traits::net_error_list::NetError;
|
||||
use script_traits::{DevicePixel, MouseButton, TouchEventType, TouchId, TouchpadPressurePhase};
|
||||
use servo_geometry::ScreenPx;
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
use servo_url::ServoUrl;
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use style_traits::cursor::Cursor;
|
||||
|
@ -109,7 +109,7 @@ pub trait WindowMethods {
|
|||
/// Returns the size of the window in hardware pixels.
|
||||
fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>;
|
||||
/// Returns the size of the window in density-independent "px" units.
|
||||
fn size(&self) -> TypedSize2D<f32, ScreenPx>;
|
||||
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel>;
|
||||
/// Presents the window to the screen (perhaps by page flipping).
|
||||
fn present(&self);
|
||||
|
||||
|
@ -137,8 +137,8 @@ pub trait WindowMethods {
|
|||
/// Called when the <head> tag has finished parsing
|
||||
fn head_parsed(&self);
|
||||
|
||||
/// Returns the scale factor of the system (device pixels / screen pixels).
|
||||
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel>;
|
||||
/// Returns the scale factor of the system (device pixels / device independent pixels).
|
||||
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel>;
|
||||
|
||||
/// Creates a channel to the compositor. The dummy parameter is needed because we don't have
|
||||
/// UFCS in Rust yet.
|
||||
|
|
|
@ -10,7 +10,7 @@ use getopts::Options;
|
|||
use num_cpus;
|
||||
use prefs::{self, PrefValue, PREFS};
|
||||
use resource_files::set_resources_path;
|
||||
use servo_geometry::ScreenPx;
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::cmp;
|
||||
|
@ -143,7 +143,7 @@ pub struct Opts {
|
|||
pub webdriver_port: Option<u16>,
|
||||
|
||||
/// The initial requested size of the window.
|
||||
pub initial_window_size: TypedSize2D<u32, ScreenPx>,
|
||||
pub initial_window_size: TypedSize2D<u32, DeviceIndependentPixel>,
|
||||
|
||||
/// An optional string allowing the user agent to be set for testing.
|
||||
pub user_agent: Cow<'static, str>,
|
||||
|
|
|
@ -20,17 +20,17 @@ use std::i32;
|
|||
/// should approximate a device-independent reference length. This unit corresponds to Android's
|
||||
/// "density-independent pixel" (dip), Mac OS X's "point", and Windows "device-independent pixel."
|
||||
///
|
||||
/// The relationship between DevicePixel and ScreenPx is defined by the OS. On most low-dpi
|
||||
/// screens, one ScreenPx is equal to one DevicePixel. But on high-density screens it can be
|
||||
/// some larger number. For example, by default on Apple "retina" displays, one ScreenPx equals
|
||||
/// two DevicePixels. On Android "MDPI" displays, one ScreenPx equals 1.5 device pixels.
|
||||
/// The relationship between DevicePixel and DeviceIndependentPixel is defined by the OS. On most low-dpi
|
||||
/// screens, one DeviceIndependentPixel is equal to one DevicePixel. But on high-density screens it can be
|
||||
/// some larger number. For example, by default on Apple "retina" displays, one DeviceIndependentPixel equals
|
||||
/// two DevicePixels. On Android "MDPI" displays, one DeviceIndependentPixel equals 1.5 device pixels.
|
||||
///
|
||||
/// The ratio between ScreenPx and DevicePixel for a given display be found by calling
|
||||
/// The ratio between DeviceIndependentPixel and DevicePixel for a given display be found by calling
|
||||
/// `servo::windowing::WindowMethods::hidpi_factor`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum ScreenPx {}
|
||||
pub enum DeviceIndependentPixel {}
|
||||
|
||||
known_heap_size!(0, ScreenPx);
|
||||
known_heap_size!(0, DeviceIndependentPixel);
|
||||
|
||||
// An Au is an "App Unit" and represents 1/60th of a CSS pixel. It was
|
||||
// originally proposed in 2002 as a standard unit of measure in Gecko.
|
||||
|
|
|
@ -149,7 +149,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
|
|||
|
||||
let (webrender, webrender_api_sender) = {
|
||||
// TODO(gw): Duplicates device_pixels_per_screen_px from compositor. Tidy up!
|
||||
let scale_factor = window.scale_factor().get();
|
||||
let scale_factor = window.hidpi_factor().get();
|
||||
let device_pixel_ratio = match opts.device_pixels_per_px {
|
||||
Some(device_pixels_per_px) => device_pixels_per_px,
|
||||
None => match opts.output_file {
|
||||
|
|
|
@ -29,11 +29,11 @@ pub type UnsafeNode = (usize, usize);
|
|||
/// 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 `ScreenPx` times a "page zoom" factor controlled by the user. This is
|
||||
/// `ViewportPx` 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 `ScreenPx`. However, if the
|
||||
/// At the default zoom level of 100%, one `PagePx` 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 {}
|
||||
|
@ -50,7 +50,7 @@ pub enum PagePx {}
|
|||
// In summary, the hierarchy of pixel units and the factors to convert from one to the next:
|
||||
//
|
||||
// DevicePixel
|
||||
// / hidpi_ratio => ScreenPx
|
||||
// / hidpi_ratio => DeviceIndependentPixel
|
||||
// / desktop_zoom => ViewportPx
|
||||
// / pinch_zoom => PagePx
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue