mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Rename ScreenPx to DeviceIndependentPixel.
This commit is contained in:
parent
ec5ed8edfd
commit
0af27a3434
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 script_traits::CompositorEvent::{self, MouseMoveEvent, MouseButtonEvent, TouchEvent, TouchpadPressureEvent};
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use servo_geometry::ScreenPx;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -155,10 +155,10 @@ pub struct IOCompositor<Window: WindowMethods> {
|
||||||
|
|
||||||
/// "Desktop-style" zoom that resizes the viewport to fit the window.
|
/// "Desktop-style" zoom that resizes the viewport to fit the window.
|
||||||
/// See `ViewportPx` docs in util/geom.rs for details.
|
/// 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.
|
/// 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>,
|
channel_to_self: Box<CompositorProxy + Send>,
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
fn new(window: Rc<Window>, state: InitialCompositorState)
|
fn new(window: Rc<Window>, state: InitialCompositorState)
|
||||||
-> IOCompositor<Window> {
|
-> IOCompositor<Window> {
|
||||||
let window_size = window.framebuffer_size();
|
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 {
|
let composite_target = match opts::get().output_file {
|
||||||
Some(_) => CompositeTarget::PngFile,
|
Some(_) => CompositeTarget::PngFile,
|
||||||
None => CompositeTarget::Window
|
None => CompositeTarget::Window
|
||||||
|
@ -756,7 +756,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_window_size(&self, size_type: WindowSizeType) {
|
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 initial_viewport = self.window_size.to_f32() / dppx;
|
||||||
let visible_viewport = initial_viewport / self.viewport_zoom;
|
let visible_viewport = initial_viewport / self.viewport_zoom;
|
||||||
let msg = ConstellationMsg::WindowSize(WindowSizeData {
|
let msg = ConstellationMsg::WindowSize(WindowSizeData {
|
||||||
|
@ -889,7 +889,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
debug!("compositor resizing to {:?}", new_size.to_untyped());
|
debug!("compositor resizing to {:?}", new_size.to_untyped());
|
||||||
|
|
||||||
// A size change could also mean a resolution change.
|
// 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 {
|
if self.scale_factor != new_scale_factor {
|
||||||
self.scale_factor = new_scale_factor;
|
self.scale_factor = new_scale_factor;
|
||||||
self.update_zoom_transform();
|
self.update_zoom_transform();
|
||||||
|
@ -948,7 +948,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(pipeline) = self.pipeline(root_pipeline_id) {
|
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 translated_point = (point / dppx).to_untyped();
|
||||||
let event_to_send = match mouse_window_event {
|
let event_to_send = match mouse_window_event {
|
||||||
MouseWindowEvent::Click(button, _) => {
|
MouseWindowEvent::Click(button, _) => {
|
||||||
|
@ -986,7 +986,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
return;
|
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 event_to_send = MouseMoveEvent(Some((cursor / dppx).to_untyped()));
|
||||||
let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send);
|
let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send);
|
||||||
if let Some(pipeline) = self.pipeline(root_pipeline_id) {
|
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>) {
|
fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||||
self.touch_handler.on_touch_down(identifier, point);
|
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();
|
let translated_point = (point / dppx).to_untyped();
|
||||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Down,
|
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Down,
|
||||||
identifier,
|
identifier,
|
||||||
|
@ -1042,7 +1042,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
TouchAction::DispatchEvent => {
|
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();
|
let translated_point = (point / dppx).to_untyped();
|
||||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Move,
|
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Move,
|
||||||
identifier,
|
identifier,
|
||||||
|
@ -1053,7 +1053,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
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();
|
let translated_point = (point / dppx).to_untyped();
|
||||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Up,
|
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Up,
|
||||||
identifier,
|
identifier,
|
||||||
|
@ -1066,7 +1066,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
|
||||||
// Send the event to script.
|
// Send the event to script.
|
||||||
self.touch_handler.on_touch_cancel(identifier, point);
|
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();
|
let translated_point = (point / dppx).to_untyped();
|
||||||
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Cancel,
|
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Cancel,
|
||||||
identifier,
|
identifier,
|
||||||
|
@ -1078,7 +1078,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
pressure: f32,
|
pressure: f32,
|
||||||
phase: TouchpadPressurePhase) {
|
phase: TouchpadPressurePhase) {
|
||||||
if let Some(true) = PREFS.get("dom.forcetouch.enabled").as_boolean() {
|
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();
|
let translated_point = (point / dppx).to_untyped();
|
||||||
self.send_event_to_root_pipeline(TouchpadPressureEvent(translated_point,
|
self.send_event_to_root_pipeline(TouchpadPressureEvent(translated_point,
|
||||||
pressure,
|
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 {
|
match opts::get().device_pixels_per_px {
|
||||||
Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px),
|
Some(device_pixels_per_px) => ScaleFactor::new(device_pixels_per_px),
|
||||||
None => match opts::get().output_file {
|
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> {
|
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) {
|
fn update_zoom_transform(&mut self) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use euclid::scale_factor::ScaleFactor;
|
||||||
use script_traits::{DevicePixel, EventResult, TouchId};
|
use script_traits::{DevicePixel, EventResult, TouchId};
|
||||||
use self::TouchState::*;
|
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;
|
const TOUCH_PAN_MIN_SCREEN_PX: f32 = 20.0;
|
||||||
|
|
||||||
pub struct TouchHandler {
|
pub struct TouchHandler {
|
||||||
|
@ -100,7 +100,6 @@ impl TouchHandler {
|
||||||
let action = match self.state {
|
let action = match self.state {
|
||||||
Touching => {
|
Touching => {
|
||||||
let delta = point - old_point;
|
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 ||
|
if delta.x.abs() > TOUCH_PAN_MIN_SCREEN_PX ||
|
||||||
delta.y.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 msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||||
use net_traits::net_error_list::NetError;
|
use net_traits::net_error_list::NetError;
|
||||||
use script_traits::{DevicePixel, MouseButton, TouchEventType, TouchId, TouchpadPressurePhase};
|
use script_traits::{DevicePixel, MouseButton, TouchEventType, TouchId, TouchpadPressurePhase};
|
||||||
use servo_geometry::ScreenPx;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use style_traits::cursor::Cursor;
|
use style_traits::cursor::Cursor;
|
||||||
|
@ -109,7 +109,7 @@ pub trait WindowMethods {
|
||||||
/// Returns the size of the window in hardware pixels.
|
/// Returns the size of the window in hardware pixels.
|
||||||
fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>;
|
fn framebuffer_size(&self) -> TypedSize2D<u32, DevicePixel>;
|
||||||
/// Returns the size of the window in density-independent "px" units.
|
/// 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).
|
/// Presents the window to the screen (perhaps by page flipping).
|
||||||
fn present(&self);
|
fn present(&self);
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ pub trait WindowMethods {
|
||||||
/// Called when the <head> tag has finished parsing
|
/// Called when the <head> tag has finished parsing
|
||||||
fn head_parsed(&self);
|
fn head_parsed(&self);
|
||||||
|
|
||||||
/// Returns the scale factor of the system (device pixels / screen pixels).
|
/// Returns the scale factor of the system (device pixels / device independent pixels).
|
||||||
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel>;
|
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel>;
|
||||||
|
|
||||||
/// Creates a channel to the compositor. The dummy parameter is needed because we don't have
|
/// Creates a channel to the compositor. The dummy parameter is needed because we don't have
|
||||||
/// UFCS in Rust yet.
|
/// UFCS in Rust yet.
|
||||||
|
|
|
@ -10,7 +10,7 @@ use getopts::Options;
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
use prefs::{self, PrefValue, PREFS};
|
use prefs::{self, PrefValue, PREFS};
|
||||||
use resource_files::set_resources_path;
|
use resource_files::set_resources_path;
|
||||||
use servo_geometry::ScreenPx;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -143,7 +143,7 @@ pub struct Opts {
|
||||||
pub webdriver_port: Option<u16>,
|
pub webdriver_port: Option<u16>,
|
||||||
|
|
||||||
/// The initial requested size of the window.
|
/// 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.
|
/// An optional string allowing the user agent to be set for testing.
|
||||||
pub user_agent: Cow<'static, str>,
|
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
|
/// 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."
|
/// "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
|
/// The relationship between DevicePixel and DeviceIndependentPixel 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
|
/// 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 ScreenPx equals
|
/// some larger number. For example, by default on Apple "retina" displays, one DeviceIndependentPixel equals
|
||||||
/// two DevicePixels. On Android "MDPI" displays, one ScreenPx equals 1.5 device pixels.
|
/// 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`.
|
/// `servo::windowing::WindowMethods::hidpi_factor`.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[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
|
// 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.
|
// 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) = {
|
let (webrender, webrender_api_sender) = {
|
||||||
// TODO(gw): Duplicates device_pixels_per_screen_px from compositor. Tidy up!
|
// 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 {
|
let device_pixel_ratio = match opts.device_pixels_per_px {
|
||||||
Some(device_pixels_per_px) => device_pixels_per_px,
|
Some(device_pixels_per_px) => device_pixels_per_px,
|
||||||
None => match opts.output_file {
|
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":
|
/// One CSS "px" in the coordinate system of the "initial viewport":
|
||||||
/// http://www.w3.org/TR/css-device-adapt/#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
|
/// the desktop-style "full page" zoom that enlarges content but then reflows the layout viewport
|
||||||
/// so it still exactly fits the visible area.
|
/// 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.
|
/// document is zoomed in or out then this scale may be larger or smaller.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum ViewportPx {}
|
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:
|
// In summary, the hierarchy of pixel units and the factors to convert from one to the next:
|
||||||
//
|
//
|
||||||
// DevicePixel
|
// DevicePixel
|
||||||
// / hidpi_ratio => ScreenPx
|
// / hidpi_ratio => DeviceIndependentPixel
|
||||||
// / desktop_zoom => ViewportPx
|
// / desktop_zoom => ViewportPx
|
||||||
// / pinch_zoom => PagePx
|
// / pinch_zoom => PagePx
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ use gleam::gl;
|
||||||
use msg::constellation_msg::{Key, KeyModifiers};
|
use msg::constellation_msg::{Key, KeyModifiers};
|
||||||
use net_traits::net_error_list::NetError;
|
use net_traits::net_error_list::NetError;
|
||||||
use script_traits::DevicePixel;
|
use script_traits::DevicePixel;
|
||||||
use servo_geometry::ScreenPx;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::os::raw::{c_char, c_void};
|
use std::os::raw::{c_char, c_void};
|
||||||
|
@ -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();
|
let browser = self.cef_browser.borrow();
|
||||||
match *browser {
|
match *browser {
|
||||||
None => TypedSize2D::new(400.0, 300.0),
|
None => TypedSize2D::new(400.0, 300.0),
|
||||||
|
@ -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") {
|
if cfg!(target_os="macos") {
|
||||||
let browser = self.cef_browser.borrow();
|
let browser = self.cef_browser.borrow();
|
||||||
match *browser {
|
match *browser {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use script_traits::{DevicePixel, TouchEventType, TouchpadPressurePhase};
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use servo_config::resource_files;
|
use servo_config::resource_files;
|
||||||
use servo_geometry::ScreenPx;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
|
@ -193,12 +193,12 @@ pub struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[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)
|
ScaleFactor::new(1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[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 hdc = unsafe { user32::GetDC(::std::ptr::null_mut()) };
|
||||||
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
|
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
|
||||||
ScaleFactor::new(ppi as f32 / 96.0)
|
ScaleFactor::new(ppi as f32 / 96.0)
|
||||||
|
@ -207,7 +207,7 @@ fn window_creation_scale_factor() -> ScaleFactor<f32, ScreenPx, DevicePixel> {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(is_foreground: bool,
|
pub fn new(is_foreground: bool,
|
||||||
window_size: TypedSize2D<u32, ScreenPx>,
|
window_size: TypedSize2D<u32, DeviceIndependentPixel>,
|
||||||
parent: Option<glutin::WindowID>) -> Rc<Window> {
|
parent: Option<glutin::WindowID>) -> Rc<Window> {
|
||||||
let win_size: TypedSize2D<u32, DevicePixel> =
|
let win_size: TypedSize2D<u32, DevicePixel> =
|
||||||
(window_size.to_f32() * window_creation_scale_factor())
|
(window_size.to_f32() * window_creation_scale_factor())
|
||||||
|
@ -797,7 +797,7 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self) -> TypedSize2D<f32, ScreenPx> {
|
fn size(&self) -> TypedSize2D<f32, DeviceIndependentPixel> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
WindowKind::Window(ref window) => {
|
WindowKind::Window(ref window) => {
|
||||||
// TODO(ajeffrey): can this fail?
|
// TODO(ajeffrey): can this fail?
|
||||||
|
@ -881,7 +881,7 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn scale_factor(&self) -> ScaleFactor<f32, ScreenPx, DevicePixel> {
|
fn hidpi_factor(&self) -> ScaleFactor<f32, DeviceIndependentPixel, DevicePixel> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
WindowKind::Window(ref window) => {
|
WindowKind::Window(ref window) => {
|
||||||
ScaleFactor::new(window.hidpi_factor())
|
ScaleFactor::new(window.hidpi_factor())
|
||||||
|
@ -893,7 +893,7 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[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 hdc = unsafe { user32::GetDC(::std::ptr::null_mut()) };
|
||||||
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
|
let ppi = unsafe { gdi32::GetDeviceCaps(hdc, winapi::wingdi::LOGPIXELSY) };
|
||||||
ScaleFactor::new(ppi as f32 / 96.0)
|
ScaleFactor::new(ppi as f32 / 96.0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue