Skip to content

Commit

Permalink
Auto merge of #15680 - glennw:zoom-wip, r=mbrubeck
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Feb 22, 2017
2 parents 07debf5 + 0af27a3 commit 03893e2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 44 deletions.
30 changes: 15 additions & 15 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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, _) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions components/compositing/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions components/config/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
Expand Down
14 changes: 7 additions & 7 deletions components/geometry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion components/servo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions components/style_traits/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions ports/cef/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use gleam::gl;
use msg::constellation_msg::{Key, KeyModifiers};
use net_traits::net_error_list::NetError;
use script_traits::DevicePixel;
use servo_geometry::ScreenPx;
use servo_geometry::DeviceIndependentPixel;
use std::cell::RefCell;
use std::ffi::CString;
use std::os::raw::{c_char, c_void};
Expand Down Expand Up @@ -206,7 +206,7 @@ impl WindowMethods for Window {
}
}

fn size(&self) -> TypedSize2D<f32, ScreenPx> {
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> {
let browser = self.cef_browser.borrow();
match *browser {
None => TypedSize2D::new(400.0, 300.0),
Expand Down Expand Up @@ -250,7 +250,7 @@ impl WindowMethods for Window {
}
}

fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
if cfg!(target_os="macos") {
let browser = self.cef_browser.borrow();
match *browser {
Expand Down
14 changes: 7 additions & 7 deletions ports/glutin/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use script_traits::{DevicePixel, TouchEventType, TouchpadPressurePhase};
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_config::resource_files;
use servo_geometry::ScreenPx;
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use std::cell::{Cell, RefCell};
#[cfg(any(target_os = "linux", target_os = "macos"))]
Expand Down Expand Up @@ -193,12 +193,12 @@ pub struct Window {
}

#[cfg(not(target_os = "windows"))]
fn window_creation_scale_factor() -> ScaleFactor<f32, ScreenPx, DevicePixel> {
fn window_creation_scale_factor() -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
ScaleFactor::new(1.0)
}

#[cfg(target_os = "windows")]
fn window_creation_scale_factor() -> ScaleFactor<f32, ScreenPx, DevicePixel> {
fn window_creation_scale_factor() -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
let hdc = unsafe { user32::GetDC(::std::ptr::null_mut()) };
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
ScaleFactor::new(ppi as f32 / 96.0)
Expand All @@ -207,7 +207,7 @@ fn window_creation_scale_factor() -> ScaleFactor<f32, ScreenPx, DevicePixel> {

impl Window {
pub fn new(is_foreground: bool,
window_size: TypedSize2D<u32, ScreenPx>,
window_size: TypedSize2D<u32, DeviceIndependentPixel>,
parent: Option<glutin::WindowID>) -> Rc<Window> {
let win_size: TypedSize2D<u32, DevicePixel> =
(window_size.to_f32() * window_creation_scale_factor())
Expand Down Expand Up @@ -797,7 +797,7 @@ impl WindowMethods for Window {
}
}

fn size(&self) -> TypedSize2D<f32, ScreenPx> {
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> {
match self.kind {
WindowKind::Window(ref window) => {
// TODO(ajeffrey): can this fail?
Expand Down Expand Up @@ -881,7 +881,7 @@ impl WindowMethods for Window {
}

#[cfg(not(target_os = "windows"))]
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
match self.kind {
WindowKind::Window(ref window) => {
ScaleFactor::new(window.hidpi_factor())
Expand All @@ -893,7 +893,7 @@ impl WindowMethods for Window {
}

#[cfg(target_os = "windows")]
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
let hdc = unsafe { user32::GetDC(::std::ptr::null_mut()) };
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
ScaleFactor::new(ppi as f32 / 96.0)
Expand Down

0 comments on commit 03893e2

Please sign in to comment.