alias some euclid types

This commit is contained in:
Paul Rouget 2018-03-13 14:36:00 +08:00
parent ac4614d6ce
commit e25dd45139
11 changed files with 73 additions and 69 deletions

1
Cargo.lock generated
View file

@ -2807,6 +2807,7 @@ dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1", "malloc_size_of 0.0.1",
"malloc_size_of_derive 0.0.1", "malloc_size_of_derive 0.0.1",
"style_traits 0.0.1",
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)", "webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
] ]

View file

@ -6,7 +6,7 @@ use CompositionPipeline;
use SendableFrameTree; use SendableFrameTree;
use compositor_thread::{CompositorProxy, CompositorReceiver}; use compositor_thread::{CompositorProxy, CompositorReceiver};
use compositor_thread::{InitialCompositorState, Msg}; use compositor_thread::{InitialCompositorState, Msg};
use euclid::{Length, TypedPoint2D, TypedVector2D, TypedScale}; use euclid::{TypedPoint2D, TypedVector2D, TypedScale};
use gfx_traits::Epoch; use gfx_traits::Epoch;
use gleam::gl; use gleam::gl;
use image::{DynamicImage, ImageFormat, RgbImage}; use image::{DynamicImage, ImageFormat, RgbImage};
@ -21,7 +21,7 @@ use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, To
use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType}; use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use script_traits::CompositorEvent::{MouseMoveEvent, MouseButtonEvent, TouchEvent}; use script_traits::CompositorEvent::{MouseMoveEvent, MouseButtonEvent, TouchEvent};
use servo_config::opts; use servo_config::opts;
use servo_geometry::DeviceIndependentPixel; use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::rc::Rc; use std::rc::Rc;
@ -33,7 +33,7 @@ use style_traits::viewport::ViewportConstraints;
use time::{precise_time_ns, precise_time_s}; use time::{precise_time_ns, precise_time_s};
use touch::{TouchHandler, TouchAction}; use touch::{TouchHandler, TouchAction};
use webrender; use webrender;
use webrender_api::{self, DeviceUintRect, DeviceUintSize, HitTestFlags, HitTestResult}; use webrender_api::{self, DeviceIntPoint, DevicePoint, DeviceUintRect, DeviceUintSize, HitTestFlags, HitTestResult};
use webrender_api::{LayoutVector2D, ScrollEventPhase, ScrollLocation}; use webrender_api::{LayoutVector2D, ScrollEventPhase, ScrollLocation};
use windowing::{self, MouseWindowEvent, WebRenderDebugOption, WindowMethods}; use windowing::{self, MouseWindowEvent, WebRenderDebugOption, WindowMethods};
@ -201,7 +201,7 @@ struct ScrollZoomEvent {
/// Scroll by this offset, or to Start or End /// Scroll by this offset, or to Start or End
scroll_location: ScrollLocation, scroll_location: ScrollLocation,
/// Apply changes to the frame at this location /// Apply changes to the frame at this location
cursor: TypedPoint2D<i32, DevicePixel>, cursor: DeviceIntPoint,
/// The scroll event phase. /// The scroll event phase.
phase: ScrollEventPhase, phase: ScrollEventPhase,
/// The number of OS events that have been coalesced together into this one event. /// The number of OS events that have been coalesced together into this one event.
@ -274,7 +274,7 @@ impl RenderTargetInfo {
} }
} }
fn initialize_png(gl: &gl::Gl, width: Length<u32, DevicePixel>, height: Length<u32, DevicePixel>) -> RenderTargetInfo { fn initialize_png(gl: &gl::Gl, width: DeviceUintLength, height: DeviceUintLength) -> RenderTargetInfo {
let framebuffer_ids = gl.gen_framebuffers(1); let framebuffer_ids = gl.gen_framebuffers(1);
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]); gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);
@ -729,7 +729,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
} }
} }
fn hit_test_at_point(&self, point: TypedPoint2D<f32, DevicePixel>) -> HitTestResult { fn hit_test_at_point(&self, point: DevicePoint) -> HitTestResult {
let dppx = self.page_zoom * self.hidpi_factor(); let dppx = self.page_zoom * self.hidpi_factor();
let scaled_point = (point / dppx).to_untyped(); let scaled_point = (point / dppx).to_untyped();
@ -743,7 +743,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
} }
pub fn on_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D<f32, DevicePixel>) { pub fn on_mouse_window_move_event_class(&mut self, cursor: DevicePoint) {
if opts::get().convert_mouse_to_touch { if opts::get().convert_mouse_to_touch {
self.on_touch_move(TouchId(0), cursor); self.on_touch_move(TouchId(0), cursor);
return return
@ -752,7 +752,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.dispatch_mouse_window_move_event_class(cursor); self.dispatch_mouse_window_move_event_class(cursor);
} }
fn dispatch_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D<f32, DevicePixel>) { fn dispatch_mouse_window_move_event_class(&mut self, cursor: DevicePoint) {
let root_pipeline_id = match self.get_root_pipeline_id() { let root_pipeline_id = match self.get_root_pipeline_id() {
Some(root_pipeline_id) => root_pipeline_id, Some(root_pipeline_id) => root_pipeline_id,
None => return, None => return,
@ -784,7 +784,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
&self, &self,
event_type: TouchEventType, event_type: TouchEventType,
identifier: TouchId, identifier: TouchId,
point: TypedPoint2D<f32, DevicePixel>) point: DevicePoint)
{ {
let results = self.hit_test_at_point(point); let results = self.hit_test_at_point(point);
if let Some(item) = results.items.first() { if let Some(item) = results.items.first() {
@ -805,7 +805,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pub fn on_touch_event(&mut self, pub fn on_touch_event(&mut self,
event_type: TouchEventType, event_type: TouchEventType,
identifier: TouchId, identifier: TouchId,
location: TypedPoint2D<f32, DevicePixel>) { location: DevicePoint) {
match event_type { match event_type {
TouchEventType::Down => self.on_touch_down(identifier, location), TouchEventType::Down => self.on_touch_down(identifier, location),
TouchEventType::Move => self.on_touch_move(identifier, location), TouchEventType::Move => self.on_touch_move(identifier, location),
@ -814,12 +814,12 @@ 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: DevicePoint) {
self.touch_handler.on_touch_down(identifier, point); self.touch_handler.on_touch_down(identifier, point);
self.send_touch_event(TouchEventType::Down, identifier, point); self.send_touch_event(TouchEventType::Down, identifier, point);
} }
fn on_touch_move(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) { fn on_touch_move(&mut self, identifier: TouchId, point: DevicePoint) {
match self.touch_handler.on_touch_move(identifier, point) { match self.touch_handler.on_touch_move(identifier, point) {
TouchAction::Scroll(delta) => { TouchAction::Scroll(delta) => {
match point.cast() { match point.cast() {
@ -850,7 +850,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: DevicePoint) {
self.send_touch_event(TouchEventType::Up, identifier, point); self.send_touch_event(TouchEventType::Up, identifier, point);
if let TouchAction::Click = self.touch_handler.on_touch_up(identifier, point) { if let TouchAction::Click = self.touch_handler.on_touch_up(identifier, point) {
@ -858,14 +858,14 @@ 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: DevicePoint) {
// 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);
self.send_touch_event(TouchEventType::Cancel, identifier, point); self.send_touch_event(TouchEventType::Cancel, identifier, point);
} }
/// <http://w3c.github.io/touch-events/#mouse-events> /// <http://w3c.github.io/touch-events/#mouse-events>
fn simulate_mouse_click(&mut self, p: TypedPoint2D<f32, DevicePixel>) { fn simulate_mouse_click(&mut self, p: DevicePoint) {
let button = MouseButton::Left; let button = MouseButton::Left;
self.dispatch_mouse_window_move_event_class(p); self.dispatch_mouse_window_move_event_class(p);
self.dispatch_mouse_window_event_class(MouseWindowEvent::MouseDown(button, p)); self.dispatch_mouse_window_event_class(MouseWindowEvent::MouseDown(button, p));
@ -875,7 +875,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pub fn on_scroll_event(&mut self, pub fn on_scroll_event(&mut self,
delta: ScrollLocation, delta: ScrollLocation,
cursor: TypedPoint2D<i32, DevicePixel>, cursor: DeviceIntPoint,
phase: TouchEventType) { phase: TouchEventType) {
match phase { match phase {
TouchEventType::Move => self.on_scroll_window_event(delta, cursor), TouchEventType::Move => self.on_scroll_window_event(delta, cursor),
@ -890,7 +890,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_scroll_window_event(&mut self, fn on_scroll_window_event(&mut self,
scroll_location: ScrollLocation, scroll_location: ScrollLocation,
cursor: TypedPoint2D<i32, DevicePixel>) { cursor: DeviceIntPoint) {
let event_phase = match (self.scroll_in_progress, self.in_scroll_transaction) { let event_phase = match (self.scroll_in_progress, self.in_scroll_transaction) {
(false, None) => ScrollEventPhase::Start, (false, None) => ScrollEventPhase::Start,
(false, Some(last_scroll)) if last_scroll.elapsed() > Duration::from_millis(80) => (false, Some(last_scroll)) if last_scroll.elapsed() > Duration::from_millis(80) =>
@ -909,7 +909,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_scroll_start_window_event(&mut self, fn on_scroll_start_window_event(&mut self,
scroll_location: ScrollLocation, scroll_location: ScrollLocation,
cursor: TypedPoint2D<i32, DevicePixel>) { cursor: DeviceIntPoint) {
self.scroll_in_progress = true; self.scroll_in_progress = true;
self.pending_scroll_zoom_events.push(ScrollZoomEvent { self.pending_scroll_zoom_events.push(ScrollZoomEvent {
magnification: 1.0, magnification: 1.0,
@ -922,7 +922,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_scroll_end_window_event(&mut self, fn on_scroll_end_window_event(&mut self,
scroll_location: ScrollLocation, scroll_location: ScrollLocation,
cursor: TypedPoint2D<i32, DevicePixel>) { cursor: DeviceIntPoint) {
self.scroll_in_progress = false; self.scroll_in_progress = false;
self.pending_scroll_zoom_events.push(ScrollZoomEvent { self.pending_scroll_zoom_events.push(ScrollZoomEvent {
magnification: 1.0, magnification: 1.0,
@ -1375,8 +1375,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn draw_img(&self, fn draw_img(&self,
render_target_info: RenderTargetInfo, render_target_info: RenderTargetInfo,
width: Length<u32, DevicePixel>, width: DeviceUintLength,
height: Length<u32, DevicePixel>) height: DeviceUintLength)
-> RgbImage { -> RgbImage {
let width = width.get() as usize; let width = width.get() as usize;
let height = height.get() as usize; let height = height.get() as usize;

View file

@ -6,7 +6,6 @@
use SendableFrameTree; use SendableFrameTree;
use compositor::CompositingReason; use compositor::CompositingReason;
use euclid::{TypedPoint2D, TypedSize2D};
use gfx_traits::Epoch; use gfx_traits::Epoch;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::{Key, KeyModifiers, KeyState, PipelineId, TopLevelBrowsingContextId}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, PipelineId, TopLevelBrowsingContextId};
@ -17,11 +16,10 @@ use script_traits::{AnimationState, ConstellationMsg, EventResult, LoadData};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::fmt::{Debug, Error, Formatter}; use std::fmt::{Debug, Error, Formatter};
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{Receiver, Sender};
use style_traits::DevicePixel;
use style_traits::cursor::CursorKind; use style_traits::cursor::CursorKind;
use style_traits::viewport::ViewportConstraints; use style_traits::viewport::ViewportConstraints;
use webrender; use webrender;
use webrender_api; use webrender_api::{self, DeviceIntPoint, DeviceUintSize};
/// Used to wake up the event loop, provided by the servo port/embedder. /// Used to wake up the event loop, provided by the servo port/embedder.
@ -120,16 +118,16 @@ pub enum EmbedderMsg {
/// Alerts the embedder that the current page has changed its title. /// Alerts the embedder that the current page has changed its title.
ChangePageTitle(TopLevelBrowsingContextId, Option<String>), ChangePageTitle(TopLevelBrowsingContextId, Option<String>),
/// Move the window to a point /// Move the window to a point
MoveTo(TopLevelBrowsingContextId, TypedPoint2D<i32, DevicePixel>), MoveTo(TopLevelBrowsingContextId, DeviceIntPoint),
/// Resize the window to size /// Resize the window to size
ResizeTo(TopLevelBrowsingContextId, TypedSize2D<u32, DevicePixel>), ResizeTo(TopLevelBrowsingContextId, DeviceUintSize),
/// Get Window Informations size and position /// Get Window Informations size and position
GetClientWindow(TopLevelBrowsingContextId, GetClientWindow(TopLevelBrowsingContextId,
IpcSender<(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>)>), IpcSender<(DeviceUintSize, DeviceIntPoint)>),
/// Get screen size (pixel) /// Get screen size (pixel)
GetScreenSize(TopLevelBrowsingContextId, IpcSender<(TypedSize2D<u32, DevicePixel>)>), GetScreenSize(TopLevelBrowsingContextId, IpcSender<(DeviceUintSize)>),
/// Get screen available size (pixel) /// Get screen available size (pixel)
GetScreenAvailSize(TopLevelBrowsingContextId, IpcSender<(TypedSize2D<u32, DevicePixel>)>), GetScreenAvailSize(TopLevelBrowsingContextId, IpcSender<(DeviceUintSize)>),
/// Wether or not to follow a link /// Wether or not to follow a link
AllowNavigation(TopLevelBrowsingContextId, ServoUrl, IpcSender<bool>), AllowNavigation(TopLevelBrowsingContextId, ServoUrl, IpcSender<bool>),
/// Sends an unconsumed key event back to the embedder. /// Sends an unconsumed key event back to the embedder.

View file

@ -5,25 +5,25 @@
//! Abstract windowing methods. The concrete implementations of these can be found in `platform/`. //! Abstract windowing methods. The concrete implementations of these can be found in `platform/`.
use compositor_thread::EventLoopWaker; use compositor_thread::EventLoopWaker;
use euclid::{Length, TypedScale, TypedPoint2D, TypedSize2D}; use euclid::TypedScale;
use gleam::gl; use gleam::gl;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::{Key, KeyModifiers, KeyState, TopLevelBrowsingContextId, TraversalDirection}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, TopLevelBrowsingContextId, TraversalDirection};
use net_traits::net_error_list::NetError; use net_traits::net_error_list::NetError;
use script_traits::{LoadData, MouseButton, TouchEventType, TouchId}; use script_traits::{LoadData, MouseButton, TouchEventType, TouchId};
use servo_geometry::DeviceIndependentPixel; use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::fmt::{Debug, Error, Formatter}; use std::fmt::{Debug, Error, Formatter};
use std::rc::Rc; use std::rc::Rc;
use style_traits::DevicePixel; use style_traits::DevicePixel;
use style_traits::cursor::CursorKind; use style_traits::cursor::CursorKind;
use webrender_api::{DeviceUintSize, DeviceUintRect, ScrollLocation}; use webrender_api::{DeviceIntPoint, DeviceSize, DevicePoint, DeviceUintSize, DeviceUintRect, ScrollLocation};
#[derive(Clone)] #[derive(Clone)]
pub enum MouseWindowEvent { pub enum MouseWindowEvent {
Click(MouseButton, TypedPoint2D<f32, DevicePixel>), Click(MouseButton, DevicePoint),
MouseDown(MouseButton, TypedPoint2D<f32, DevicePixel>), MouseDown(MouseButton, DevicePoint),
MouseUp(MouseButton, TypedPoint2D<f32, DevicePixel>), MouseUp(MouseButton, DevicePoint),
} }
/// Various debug and profiling flags that WebRender supports. /// Various debug and profiling flags that WebRender supports.
@ -54,12 +54,12 @@ pub enum WindowEvent {
/// Sent when a mouse hit test is to be performed. /// Sent when a mouse hit test is to be performed.
MouseWindowEventClass(MouseWindowEvent), MouseWindowEventClass(MouseWindowEvent),
/// Sent when a mouse move. /// Sent when a mouse move.
MouseWindowMoveEventClass(TypedPoint2D<f32, DevicePixel>), MouseWindowMoveEventClass(DevicePoint),
/// Touch event: type, identifier, point /// Touch event: type, identifier, point
Touch(TouchEventType, TouchId, TypedPoint2D<f32, DevicePixel>), Touch(TouchEventType, TouchId, DevicePoint),
/// Sent when the user scrolls. The first point is the delta and the second point is the /// Sent when the user scrolls. The first point is the delta and the second point is the
/// origin. /// origin.
Scroll(ScrollLocation, TypedPoint2D<i32, DevicePixel>, TouchEventType), Scroll(ScrollLocation, DeviceIntPoint, TouchEventType),
/// Sent when the user zooms. /// Sent when the user zooms.
Zoom(f32), Zoom(f32),
/// Simulated "pinch zoom" gesture for non-touch platforms (e.g. ctrl-scrollwheel). /// Simulated "pinch zoom" gesture for non-touch platforms (e.g. ctrl-scrollwheel).
@ -123,21 +123,20 @@ pub trait WindowMethods {
/// Returns the position and size of the window within the rendering area. /// Returns the position and size of the window within the rendering area.
fn window_rect(&self) -> DeviceUintRect; fn window_rect(&self) -> DeviceUintRect;
/// Returns the size of the window. /// Returns the size of the window.
fn size(&self) -> TypedSize2D<f32, DevicePixel>; fn size(&self) -> DeviceSize;
/// 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);
/// Return the size of the window with head and borders and position of the window values /// Return the size of the window with head and borders and position of the window values
fn client_window(&self, ctx: TopLevelBrowsingContextId) -> fn client_window(&self, ctx: TopLevelBrowsingContextId) -> (DeviceUintSize, DeviceIntPoint);
(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>);
/// Return the size of the screen. /// Return the size of the screen.
fn screen_size(&self, ctx: TopLevelBrowsingContextId) -> TypedSize2D<u32, DevicePixel>; fn screen_size(&self, ctx: TopLevelBrowsingContextId) -> DeviceUintSize;
/// Return the available size of the screen. /// Return the available size of the screen.
fn screen_avail_size(&self, ctx: TopLevelBrowsingContextId) -> TypedSize2D<u32, DevicePixel>; fn screen_avail_size(&self, ctx: TopLevelBrowsingContextId) -> DeviceUintSize;
/// Set the size inside of borders and head /// Set the size inside of borders and head
fn set_inner_size(&self, ctx: TopLevelBrowsingContextId, size: TypedSize2D<u32, DevicePixel>); fn set_inner_size(&self, ctx: TopLevelBrowsingContextId, size: DeviceUintSize);
/// Set the window position /// Set the window position
fn set_position(&self, ctx: TopLevelBrowsingContextId, point: TypedPoint2D<i32, DevicePixel>); fn set_position(&self, ctx: TopLevelBrowsingContextId, point: DeviceIntPoint);
/// Set fullscreen state /// Set fullscreen state
fn set_fullscreen_state(&self, ctx: TopLevelBrowsingContextId, state: bool); fn set_fullscreen_state(&self, ctx: TopLevelBrowsingContextId, state: bool);
@ -167,7 +166,7 @@ pub trait WindowMethods {
/// Requests that the window system prepare a composite. Typically this will involve making /// Requests that the window system prepare a composite. Typically this will involve making
/// some type of platform-specific graphics context current. Returns true if the composite may /// some type of platform-specific graphics context current. Returns true if the composite may
/// proceed and false if it should not. /// proceed and false if it should not.
fn prepare_for_composite(&self, width: Length<u32, DevicePixel>, height: Length<u32, DevicePixel>) -> bool; fn prepare_for_composite(&self, width: DeviceUintLength, height: DeviceUintLength) -> bool;
/// Sets the cursor to be used in the window. /// Sets the cursor to be used in the window.
fn set_cursor(&self, cursor: CursorKind); fn set_cursor(&self, cursor: CursorKind);

View file

@ -14,4 +14,5 @@ app_units = "0.6"
euclid = "0.17" euclid = "0.17"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" } malloc_size_of_derive = { path = "../malloc_size_of_derive" }
style_traits = { path = "../style_traits" }
webrender_api = { git = "https://github.com/servo/webrender" } webrender_api = { git = "https://github.com/servo/webrender" }

View file

@ -5,16 +5,20 @@
extern crate app_units; extern crate app_units;
extern crate euclid; extern crate euclid;
extern crate malloc_size_of; extern crate malloc_size_of;
extern crate style_traits;
#[macro_use] extern crate malloc_size_of_derive; #[macro_use] extern crate malloc_size_of_derive;
extern crate webrender_api; extern crate webrender_api;
use app_units::{Au, MAX_AU, MIN_AU}; use app_units::{Au, MAX_AU, MIN_AU};
use euclid::{Point2D, Rect, Size2D}; use euclid::{Length, Point2D, Rect, Size2D};
use std::f32; use std::f32;
use style_traits::DevicePixel;
use webrender_api::{LayoutPoint, LayoutRect, LayoutSize}; use webrender_api::{LayoutPoint, LayoutRect, LayoutSize};
// Units for use with euclid::length and euclid::scale_factor. // Units for use with euclid::length and euclid::scale_factor.
pub type DeviceUintLength = Length<u32, DevicePixel>;
/// A normalized "pixel" at the default resolution for the display. /// A normalized "pixel" at the default resolution for the display.
/// ///
/// Like the CSS "px" unit, the exact physical size of this unit may vary between devices, but it /// Like the CSS "px" unit, the exact physical size of this unit may vary between devices, but it

View file

@ -14,7 +14,8 @@ use dom_struct::dom_struct;
use euclid::TypedSize2D; use euclid::TypedSize2D;
use ipc_channel::ipc; use ipc_channel::ipc;
use script_traits::ScriptMsg; use script_traits::ScriptMsg;
use style_traits::{CSSPixel, DevicePixel}; use style_traits::CSSPixel;
use webrender_api::DeviceUintSize;
#[dom_struct] #[dom_struct]
pub struct Screen { pub struct Screen {
@ -37,7 +38,7 @@ impl Screen {
} }
fn screen_size(&self) -> TypedSize2D<u32, CSSPixel> { fn screen_size(&self) -> TypedSize2D<u32, CSSPixel> {
let (send, recv) = ipc::channel::<(TypedSize2D<u32, DevicePixel>)>().unwrap(); let (send, recv) = ipc::channel::<DeviceUintSize>().unwrap();
self.window.upcast::<GlobalScope>() self.window.upcast::<GlobalScope>()
.script_to_constellation_chan().send(ScriptMsg::GetScreenSize(send)).unwrap(); .script_to_constellation_chan().send(ScriptMsg::GetScreenSize(send)).unwrap();
let dpr = self.window.device_pixel_ratio(); let dpr = self.window.device_pixel_ratio();
@ -46,7 +47,7 @@ impl Screen {
} }
fn screen_avail_size(&self) -> TypedSize2D<u32, CSSPixel> { fn screen_avail_size(&self) -> TypedSize2D<u32, CSSPixel> {
let (send, recv) = ipc::channel::<(TypedSize2D<u32, DevicePixel>)>().unwrap(); let (send, recv) = ipc::channel::<DeviceUintSize>().unwrap();
self.window.upcast::<GlobalScope>() self.window.upcast::<GlobalScope>()
.script_to_constellation_chan().send(ScriptMsg::GetScreenAvailSize(send)).unwrap(); .script_to_constellation_chan().send(ScriptMsg::GetScreenAvailSize(send)).unwrap();
let dpr = self.window.device_pixel_ratio(); let dpr = self.window.device_pixel_ratio();

View file

@ -116,7 +116,7 @@ use timers::{IsInterval, TimerCallback};
use tinyfiledialogs::{self, MessageBoxIcon}; use tinyfiledialogs::{self, MessageBoxIcon};
use url::Position; use url::Position;
use webdriver_handlers::jsval_to_webdriver; use webdriver_handlers::jsval_to_webdriver;
use webrender_api::{ExternalScrollId, DocumentId}; use webrender_api::{ExternalScrollId, DeviceIntPoint, DeviceUintSize, DocumentId};
use webvr_traits::WebVRMsg; use webvr_traits::WebVRMsg;
/// Current state of the window object /// Current state of the window object
@ -1180,7 +1180,7 @@ impl Window {
} }
fn client_window(&self) -> (TypedSize2D<u32, CSSPixel>, TypedPoint2D<i32, CSSPixel>) { fn client_window(&self) -> (TypedSize2D<u32, CSSPixel>, TypedPoint2D<i32, CSSPixel>) {
let (send, recv) = ipc::channel::<(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>)>().unwrap(); let (send, recv) = ipc::channel::<(DeviceUintSize, DeviceIntPoint)>().unwrap();
self.send_to_constellation(ScriptMsg::GetClientWindow(send)); self.send_to_constellation(ScriptMsg::GetClientWindow(send));
let (size, point) = recv.recv().unwrap_or((TypedSize2D::zero(), TypedPoint2D::zero())); let (size, point) = recv.recv().unwrap_or((TypedSize2D::zero(), TypedPoint2D::zero()));
let dpr = self.device_pixel_ratio(); let dpr = self.device_pixel_ratio();

View file

@ -69,7 +69,7 @@ use style_traits::CSSPixel;
use style_traits::SpeculativePainter; use style_traits::SpeculativePainter;
use style_traits::cursor::CursorKind; use style_traits::cursor::CursorKind;
use webdriver_msg::{LoadStatus, WebDriverScriptCommand}; use webdriver_msg::{LoadStatus, WebDriverScriptCommand};
use webrender_api::{ExternalScrollId, DevicePixel, DocumentId, ImageKey}; use webrender_api::{ExternalScrollId, DevicePixel, DeviceUintSize, DocumentId, ImageKey};
use webvr_traits::{WebVREvent, WebVRMsg}; use webvr_traits::{WebVREvent, WebVRMsg};
pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry}; pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
@ -650,7 +650,7 @@ pub enum WebDriverCommandMsg {
/// Act as if keys were pressed in the browsing context with the given ID. /// Act as if keys were pressed in the browsing context with the given ID.
SendKeys(BrowsingContextId, Vec<(Key, KeyModifiers, KeyState)>), SendKeys(BrowsingContextId, Vec<(Key, KeyModifiers, KeyState)>),
/// Set the window size. /// Set the window size.
SetWindowSize(TopLevelBrowsingContextId, TypedSize2D<u32, DevicePixel>, IpcSender<WindowSizeData>), SetWindowSize(TopLevelBrowsingContextId, DeviceUintSize, IpcSender<WindowSizeData>),
/// Take a screenshot of the window. /// Take a screenshot of the window.
TakeScreenshot(TopLevelBrowsingContextId, IpcSender<Option<Image>>), TakeScreenshot(TopLevelBrowsingContextId, IpcSender<Option<Image>>),
} }

View file

@ -13,7 +13,7 @@ use WorkerGlobalScopeInit;
use WorkerScriptLoadOrigin; use WorkerScriptLoadOrigin;
use canvas_traits::canvas::CanvasMsg; use canvas_traits::canvas::CanvasMsg;
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
use euclid::{Size2D, TypedPoint2D, TypedSize2D}; use euclid::{Size2D, TypedSize2D};
use gfx_traits::Epoch; use gfx_traits::Epoch;
use ipc_channel::ipc::{IpcReceiver, IpcSender}; use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::{BrowsingContextId, PipelineId, TraversalDirection}; use msg::constellation_msg::{BrowsingContextId, PipelineId, TraversalDirection};
@ -23,9 +23,10 @@ use net_traits::request::RequestInit;
use net_traits::storage_thread::StorageType; use net_traits::storage_thread::StorageType;
use servo_url::ImmutableOrigin; use servo_url::ImmutableOrigin;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use style_traits::{DevicePixel, CSSPixel}; use style_traits::CSSPixel;
use style_traits::cursor::CursorKind; use style_traits::cursor::CursorKind;
use style_traits::viewport::ViewportConstraints; use style_traits::viewport::ViewportConstraints;
use webrender_api::{DeviceIntPoint, DeviceUintSize};
/// Messages from the layout to the constellation. /// Messages from the layout to the constellation.
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -136,11 +137,11 @@ pub enum ScriptMsg {
/// Send a key event /// Send a key event
SendKeyEvent(Option<char>, Key, KeyState, KeyModifiers), SendKeyEvent(Option<char>, Key, KeyState, KeyModifiers),
/// Get Window Informations size and position /// Get Window Informations size and position
GetClientWindow(IpcSender<(TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>)>), GetClientWindow(IpcSender<(DeviceUintSize, DeviceIntPoint)>),
/// Move the window to a point /// Move the window to a point
MoveTo(TypedPoint2D<i32, DevicePixel>), MoveTo(DeviceIntPoint),
/// Resize the window to size /// Resize the window to size
ResizeTo(TypedSize2D<u32, DevicePixel>), ResizeTo(DeviceUintSize),
/// Script has handled a touch event, and either prevented or allowed default actions. /// Script has handled a touch event, and either prevented or allowed default actions.
TouchEventProcessed(EventResult), TouchEventProcessed(EventResult),
/// A log entry, with the top-level browsing context id and thread name /// A log entry, with the top-level browsing context id and thread name
@ -155,9 +156,9 @@ pub enum ScriptMsg {
/// Enter or exit fullscreen /// Enter or exit fullscreen
SetFullscreenState(bool), SetFullscreenState(bool),
/// Get the screen size (pixel) /// Get the screen size (pixel)
GetScreenSize(IpcSender<(TypedSize2D<u32, DevicePixel>)>), GetScreenSize(IpcSender<(DeviceUintSize)>),
/// Get the available screen size (pixel) /// Get the available screen size (pixel)
GetScreenAvailSize(IpcSender<(TypedSize2D<u32, DevicePixel>)>), GetScreenAvailSize(IpcSender<(DeviceUintSize)>),
/// Requests that the compositor shut down. /// Requests that the compositor shut down.
Exit, Exit,
} }

View file

@ -40,7 +40,7 @@ use style_traits::cursor::CursorKind;
use tinyfiledialogs; use tinyfiledialogs;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use user32; use user32;
use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation}; use webrender_api::{DeviceIntPoint, DeviceUintRect, DeviceUintSize, ScrollLocation};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use winapi; use winapi;
use winit; use winit;
@ -222,8 +222,7 @@ impl Window {
pub fn new(is_foreground: bool, pub fn new(is_foreground: bool,
window_size: TypedSize2D<u32, DeviceIndependentPixel>) -> Rc<Window> { window_size: TypedSize2D<u32, DeviceIndependentPixel>) -> Rc<Window> {
let win_size: TypedSize2D<u32, DevicePixel> = let win_size: DeviceUintSize = (window_size.to_f32() * window_creation_scale_factor()).to_u32();
(window_size.to_f32() * window_creation_scale_factor()).to_u32();
let width = win_size.to_untyped().width; let width = win_size.to_untyped().width;
let height = win_size.to_untyped().height; let height = win_size.to_untyped().height;
@ -882,7 +881,7 @@ impl WindowMethods for Window {
self.inner_size.get().to_f32() * self.hidpi_factor() self.inner_size.get().to_f32() * self.hidpi_factor()
} }
fn client_window(&self, _: BrowserId) -> (TypedSize2D<u32, DevicePixel>, TypedPoint2D<i32, DevicePixel>) { fn client_window(&self, _: BrowserId) -> (DeviceUintSize, DeviceIntPoint) {
let (size, point) = match self.kind { let (size, point) = match self.kind {
WindowKind::Window(ref window, ..) => { WindowKind::Window(ref window, ..) => {
// TODO(ajeffrey): can this fail? // TODO(ajeffrey): can this fail?
@ -903,11 +902,11 @@ impl WindowMethods for Window {
((size * dpr).to_u32(), (point * dpr).to_i32()) ((size * dpr).to_u32(), (point * dpr).to_i32())
} }
fn screen_size(&self, _: BrowserId) -> TypedSize2D<u32, DevicePixel> { fn screen_size(&self, _: BrowserId) -> DeviceUintSize {
(self.screen_size.to_f32() * self.hidpi_factor()).to_u32() (self.screen_size.to_f32() * self.hidpi_factor()).to_u32()
} }
fn screen_avail_size(&self, browser_id: BrowserId) -> TypedSize2D<u32, DevicePixel> { fn screen_avail_size(&self, browser_id: BrowserId) -> DeviceUintSize {
// FIXME: Glutin doesn't have API for available size. Fallback to screen size // FIXME: Glutin doesn't have API for available size. Fallback to screen size
self.screen_size(browser_id) self.screen_size(browser_id)
} }
@ -916,7 +915,7 @@ impl WindowMethods for Window {
self.animation_state.set(state); self.animation_state.set(state);
} }
fn set_inner_size(&self, _: BrowserId, size: TypedSize2D<u32, DevicePixel>) { fn set_inner_size(&self, _: BrowserId, size: DeviceUintSize) {
match self.kind { match self.kind {
WindowKind::Window(ref window, ..) => { WindowKind::Window(ref window, ..) => {
let size = size.to_f32() / self.hidpi_factor(); let size = size.to_f32() / self.hidpi_factor();
@ -926,7 +925,7 @@ impl WindowMethods for Window {
} }
} }
fn set_position(&self, _: BrowserId, point: TypedPoint2D<i32, DevicePixel>) { fn set_position(&self, _: BrowserId, point: DeviceIntPoint) {
match self.kind { match self.kind {
WindowKind::Window(ref window, ..) => { WindowKind::Window(ref window, ..) => {
let point = point.to_f32() / self.hidpi_factor(); let point = point.to_f32() / self.hidpi_factor();