mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use typed coordinates.
We use Size2D and Point2D across compositing, constellation and script, losing the type of pixels we use (DevicePixel, DeviceIndepententPixel or CSSPixel) along the way, which might lead to bugs like window.outerHeight not taking into account the page zoom (using DeviceIndepententPixel instead of CSSPixel).
This commit is contained in:
parent
b93f153ed5
commit
ac4614d6ce
10 changed files with 122 additions and 102 deletions
|
@ -11,9 +11,10 @@ use dom::bindings::root::{Dom, DomRoot};
|
|||
use dom::globalscope::GlobalScope;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::Size2D;
|
||||
use euclid::TypedSize2D;
|
||||
use ipc_channel::ipc;
|
||||
use script_traits::ScriptMsg;
|
||||
use style_traits::{CSSPixel, DevicePixel};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct Screen {
|
||||
|
@ -35,18 +36,22 @@ impl Screen {
|
|||
ScreenBinding::Wrap)
|
||||
}
|
||||
|
||||
fn screen_size(&self) -> Size2D<u32> {
|
||||
let (send, recv) = ipc::channel::<(Size2D<u32>)>().unwrap();
|
||||
fn screen_size(&self) -> TypedSize2D<u32, CSSPixel> {
|
||||
let (send, recv) = ipc::channel::<(TypedSize2D<u32, DevicePixel>)>().unwrap();
|
||||
self.window.upcast::<GlobalScope>()
|
||||
.script_to_constellation_chan().send(ScriptMsg::GetScreenSize(send)).unwrap();
|
||||
recv.recv().unwrap_or(Size2D::zero())
|
||||
let dpr = self.window.device_pixel_ratio();
|
||||
let screen = recv.recv().unwrap_or(TypedSize2D::zero());
|
||||
(screen.to_f32() / dpr).to_u32()
|
||||
}
|
||||
|
||||
fn screen_avail_size(&self) -> Size2D<u32> {
|
||||
let (send, recv) = ipc::channel::<(Size2D<u32>)>().unwrap();
|
||||
fn screen_avail_size(&self) -> TypedSize2D<u32, CSSPixel> {
|
||||
let (send, recv) = ipc::channel::<(TypedSize2D<u32, DevicePixel>)>().unwrap();
|
||||
self.window.upcast::<GlobalScope>()
|
||||
.script_to_constellation_chan().send(ScriptMsg::GetScreenAvailSize(send)).unwrap();
|
||||
recv.recv().unwrap_or(Size2D::zero())
|
||||
let dpr = self.window.device_pixel_ratio();
|
||||
let screen = recv.recv().unwrap_or(TypedSize2D::zero());
|
||||
(screen.to_f32() / dpr).to_u32()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue