aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/main')
-rw-r--r--src/components/main/compositing/compositor.rs48
-rw-r--r--src/components/main/compositing/headless.rs4
-rw-r--r--src/components/main/constellation.rs34
-rw-r--r--src/components/main/layout/layout_task.rs4
-rw-r--r--src/components/main/pipeline.rs5
-rw-r--r--src/components/main/platform/common/glfw_windowing.rs19
-rw-r--r--src/components/main/platform/common/glut_windowing.rs11
-rw-r--r--src/components/main/windowing.rs8
8 files changed, 71 insertions, 62 deletions
diff --git a/src/components/main/compositing/compositor.rs b/src/components/main/compositing/compositor.rs
index 03d6e600ba1..3eba8719b55 100644
--- a/src/components/main/compositing/compositor.rs
+++ b/src/components/main/compositing/compositor.rs
@@ -128,7 +128,7 @@ impl IOCompositor {
// TODO: There should be no initial layer tree until the renderer creates one from the display
// list. This is only here because we don't have that logic in the renderer yet.
let root_layer = Rc::new(ContainerLayer());
- let window_size = window.size();
+ let window_size = window.framebuffer_size();
let hidpi_factor = window.hidpi_factor();
IOCompositor {
@@ -138,8 +138,8 @@ impl IOCompositor {
context: rendergl::init_render_context(),
root_layer: root_layer.clone(),
root_pipeline: None,
- scene: Scene(ContainerLayerKind(root_layer), window_size.to_untyped(), identity()),
- window_size: window_size.as_uint(),
+ scene: Scene(ContainerLayerKind(root_layer), window_size.as_f32().to_untyped(), identity()),
+ window_size: window_size,
hidpi_factor: hidpi_factor,
graphics_context: CompositorTask::create_graphics_context(),
composite_ready: false,
@@ -176,10 +176,7 @@ impl IOCompositor {
fn run (&mut self) {
// Tell the constellation about the initial window size.
- {
- let ConstellationChan(ref chan) = self.constellation_chan;
- chan.send(ResizedWindowMsg(self.window_size.to_untyped()));
- }
+ self.send_window_size();
// Enter the main event loop.
while !self.done {
@@ -339,13 +336,8 @@ impl IOCompositor {
self.root_pipeline = Some(frame_tree.pipeline.clone());
// Initialize the new constellation channel by sending it the root window size.
- let window_size = self.window.size().as_uint();
- {
- let ConstellationChan(ref chan) = new_constellation_chan;
- chan.send(ResizedWindowMsg(window_size.to_untyped()));
- }
-
self.constellation_chan = new_constellation_chan;
+ self.send_window_size();
}
fn create_root_compositor_layer_if_necessary(&mut self,
@@ -425,6 +417,12 @@ impl IOCompositor {
self.window_size.as_f32() / self.device_pixels_per_page_px()
}
+ /// The size of the window in screen px.
+ fn send_window_size(&self) {
+ let ConstellationChan(ref chan) = self.constellation_chan;
+ chan.send(ResizedWindowMsg(self.page_window()));
+ }
+
fn set_layer_page_size(&mut self,
pipeline_id: PipelineId,
layer_id: LayerId,
@@ -527,8 +525,8 @@ impl IOCompositor {
self.recomposite = true;
}
- ResizeWindowEvent(width, height) => {
- self.on_resize_window_event(width, height);
+ ResizeWindowEvent(size) => {
+ self.on_resize_window_event(size);
}
LoadUrlWindowEvent(url_string) => {
@@ -574,22 +572,20 @@ impl IOCompositor {
}
}
- fn on_resize_window_event(&mut self, width: uint, height: uint) {
- let new_size: TypedSize2D<DevicePixel, uint> = TypedSize2D(width, height);
- if self.window_size != new_size {
- debug!("osmain: window resized to {:u}x{:u}", width, height);
- self.window_size = new_size;
- let ConstellationChan(ref chan) = self.constellation_chan;
- chan.send(ResizedWindowMsg(new_size.to_untyped()))
- } else {
- debug!("osmain: dropping window resize since size is still {:u}x{:u}", width, height);
- }
+ fn on_resize_window_event(&mut self, new_size: TypedSize2D<DevicePixel, uint>) {
// A size change could also mean a resolution change.
let new_hidpi_factor = self.window.hidpi_factor();
if self.hidpi_factor != new_hidpi_factor {
self.hidpi_factor = new_hidpi_factor;
self.update_zoom_transform();
}
+ if self.window_size != new_size {
+ debug!("osmain: window resized to {:?}", new_size);
+ self.window_size = new_size;
+ self.send_window_size();
+ } else {
+ debug!("osmain: dropping window resize since size is still {:?}", new_size);
+ }
}
fn on_load_url_window_event(&mut self, url_string: String) {
@@ -717,7 +713,7 @@ impl IOCompositor {
profile(time::CompositingCategory, self.profiler_chan.clone(), || {
debug!("compositor: compositing");
// Adjust the layer dimensions as necessary to correspond to the size of the window.
- self.scene.size = self.window.size().to_untyped();
+ self.scene.size = self.window_size.as_f32().to_untyped();
// Render the scene.
match self.compositor_layer {
Some(ref mut layer) => {
diff --git a/src/components/main/compositing/headless.rs b/src/components/main/compositing/headless.rs
index 6cd34acd28d..14e587cba32 100644
--- a/src/components/main/compositing/headless.rs
+++ b/src/components/main/compositing/headless.rs
@@ -4,7 +4,7 @@
use compositing::*;
-use geom::size::Size2D;
+use geom::size::TypedSize2D;
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, ResizedWindowMsg};
use servo_util::time::ProfilerChan;
use servo_util::time;
@@ -33,7 +33,7 @@ impl NullCompositor {
// Tell the constellation about the initial fake size.
{
let ConstellationChan(ref chan) = constellation_chan;
- chan.send(ResizedWindowMsg(Size2D(640u, 480u)));
+ chan.send(ResizedWindowMsg(TypedSize2D(640_f32, 480_f32)));
}
compositor.handle_message(constellation_chan);
diff --git a/src/components/main/constellation.rs b/src/components/main/constellation.rs
index 112b5b38ec5..b43f113abb6 100644
--- a/src/components/main/constellation.rs
+++ b/src/components/main/constellation.rs
@@ -5,8 +5,8 @@
use compositing::{CompositorChan, LoadComplete, SetIds, SetLayerClipRect, ShutdownComplete};
use collections::hashmap::{HashMap, HashSet};
-use geom::rect::Rect;
-use geom::size::Size2D;
+use geom::rect::{Rect, TypedRect};
+use geom::size::TypedSize2D;
use gfx::render_task;
use libc;
use pipeline::{Pipeline, CompositionPipeline};
@@ -24,6 +24,7 @@ use servo_msg::constellation_msg;
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask;
use servo_net::resource_task;
+use servo_util::geometry::PagePx;
use servo_util::opts::Opts;
use servo_util::time::ProfilerChan;
use servo_util::url::parse_url;
@@ -45,9 +46,9 @@ pub struct Constellation {
navigation_context: NavigationContext,
next_pipeline_id: PipelineId,
pending_frames: Vec<FrameChange>,
- pending_sizes: HashMap<(PipelineId, SubpageId), Rect<f32>>,
+ pending_sizes: HashMap<(PipelineId, SubpageId), TypedRect<PagePx, f32>>,
pub profiler_chan: ProfilerChan,
- pub window_size: Size2D<uint>,
+ pub window_size: TypedSize2D<PagePx, f32>,
pub opts: Opts,
}
@@ -63,7 +64,7 @@ struct ChildFrameTree {
frame_tree: Rc<FrameTree>,
/// Clipping rect representing the size and position, in page coordinates, of the visible
/// region of the child frame relative to the parent.
- pub rect: Option<Rect<f32>>,
+ pub rect: Option<TypedRect<PagePx, f32>>,
}
pub struct SendableFrameTree {
@@ -73,7 +74,7 @@ pub struct SendableFrameTree {
pub struct SendableChildFrameTree {
pub frame_tree: SendableFrameTree,
- pub rect: Option<Rect<f32>>,
+ pub rect: Option<TypedRect<PagePx, f32>>,
}
enum ReplaceResult {
@@ -260,7 +261,7 @@ impl Constellation {
pending_frames: vec!(),
pending_sizes: HashMap::new(),
profiler_chan: profiler_chan,
- window_size: Size2D(800u, 600u),
+ window_size: TypedSize2D(800_f32, 600_f32),
opts: opts_clone,
};
constellation.run();
@@ -320,7 +321,7 @@ impl Constellation {
// all frame trees in the navigation context containing the subframe.
FrameRectMsg(pipeline_id, subpage_id, rect) => {
debug!("constellation got frame rect message");
- self.handle_frame_rect_msg(pipeline_id, subpage_id, rect);
+ self.handle_frame_rect_msg(pipeline_id, subpage_id, Rect::from_untyped(&rect));
}
LoadIframeUrlMsg(url, source_pipeline_id, subpage_id, sandbox) => {
debug!("constellation got iframe URL load message");
@@ -464,8 +465,9 @@ impl Constellation {
self.pipelines.insert(pipeline_wrapped.id, pipeline_wrapped);
}
- fn handle_frame_rect_msg(&mut self, pipeline_id: PipelineId, subpage_id: SubpageId, rect: Rect<f32>) {
- debug!("Received frame rect {} from {:?}, {:?}", rect, pipeline_id, subpage_id);
+ fn handle_frame_rect_msg(&mut self, pipeline_id: PipelineId, subpage_id: SubpageId,
+ rect: TypedRect<PagePx, f32>) {
+ debug!("Received frame rect {:?} from {:?}, {:?}", rect, pipeline_id, subpage_id);
let mut already_sent = HashSet::new();
// Returns true if a child frame tree's subpage id matches the given subpage id
@@ -483,20 +485,16 @@ impl Constellation {
// if it hasn't been already. Optionally inform the compositor if
// resize happens immediately.
let update_child_rect = |child_frame_tree: &mut ChildFrameTree, is_active: bool| {
- child_frame_tree.rect = Some(rect.clone());
+ child_frame_tree.rect = Some(rect);
// NOTE: work around borrowchk issues
let pipeline = &child_frame_tree.frame_tree.pipeline;
if !already_sent.contains(&pipeline.id) {
- let Size2D { width, height } = rect.size;
if is_active {
let ScriptChan(ref script_chan) = pipeline.script_chan;
- script_chan.send(ResizeMsg(pipeline.id, Size2D {
- width: width as uint,
- height: height as uint
- }));
+ script_chan.send(ResizeMsg(pipeline.id, rect.size));
self.compositor_chan.send(SetLayerClipRect(pipeline.id,
LayerId::null(),
- rect));
+ rect.to_untyped()));
} else {
already_sent.insert(pipeline.id);
}
@@ -790,7 +788,7 @@ impl Constellation {
}
/// Called when the window is resized.
- fn handle_resized_window_msg(&mut self, new_size: Size2D<uint>) {
+ fn handle_resized_window_msg(&mut self, new_size: TypedSize2D<PagePx, f32>) {
let mut already_seen = HashSet::new();
for frame_tree in self.current_frame().iter() {
debug!("constellation sending resize message to active frame");
diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs
index b5aa76a1511..fdbe44fbfeb 100644
--- a/src/components/main/layout/layout_task.rs
+++ b/src/components/main/layout/layout_task.rs
@@ -581,8 +581,8 @@ impl LayoutTask {
_ => false
};
- let current_screen_size = Size2D(Au::from_px(data.window_size.width as int),
- Au::from_px(data.window_size.height as int));
+ let current_screen_size = Size2D(Au::from_page_px(data.window_size.width),
+ Au::from_page_px(data.window_size.height));
if self.screen_size != current_screen_size {
all_style_damage = true
}
diff --git a/src/components/main/pipeline.rs b/src/components/main/pipeline.rs
index b3f18b01d8d..04902ff0a10 100644
--- a/src/components/main/pipeline.rs
+++ b/src/components/main/pipeline.rs
@@ -5,7 +5,7 @@
use compositing::CompositorChan;
use layout::layout_task::LayoutTask;
-use geom::size::Size2D;
+use geom::size::TypedSize2D;
use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked};
use gfx::render_task::{RenderChan, RenderTask};
use script::layout_interface::LayoutChan;
@@ -15,6 +15,7 @@ use script::script_task;
use servo_msg::constellation_msg::{ConstellationChan, Failure, PipelineId, SubpageId};
use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::ResourceTask;
+use servo_util::geometry::PagePx;
use servo_util::opts::Opts;
use servo_util::time::ProfilerChan;
use std::rc::Rc;
@@ -112,7 +113,7 @@ impl Pipeline {
image_cache_task: ImageCacheTask,
resource_task: ResourceTask,
profiler_chan: ProfilerChan,
- window_size: Size2D<uint>,
+ window_size: TypedSize2D<PagePx, f32>,
opts: Opts,
url: Url)
-> Pipeline {
diff --git a/src/components/main/platform/common/glfw_windowing.rs b/src/components/main/platform/common/glfw_windowing.rs
index 0ac70ecbf40..5821dbd21cb 100644
--- a/src/components/main/platform/common/glfw_windowing.rs
+++ b/src/components/main/platform/common/glfw_windowing.rs
@@ -145,9 +145,15 @@ impl WindowMethods<Application> for Window {
wrapped_window
}
- /// Returns the size of the window.
- fn size(&self) -> TypedSize2D<DevicePixel, f32> {
+ /// Returns the size of the window in hardware pixels.
+ fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, uint> {
let (width, height) = self.glfw_window.get_framebuffer_size();
+ TypedSize2D(width as uint, height as uint)
+ }
+
+ /// Returns the size of the window in density-independent "px" units.
+ fn size(&self) -> TypedSize2D<ScreenPx, f32> {
+ let (width, height) = self.glfw_window.get_size();
TypedSize2D(width as f32, height as f32)
}
@@ -196,9 +202,9 @@ impl WindowMethods<Application> for Window {
}
fn hidpi_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32> {
- let (backing_size, _) = self.glfw_window.get_framebuffer_size();
- let (window_size, _) = self.glfw_window.get_size();
- ScaleFactor((backing_size as f32) / (window_size as f32))
+ let backing_size = self.framebuffer_size().width.get();
+ let window_size = self.size().width.get();
+ ScaleFactor((backing_size as f32) / window_size)
}
}
@@ -211,7 +217,8 @@ impl Window {
}
},
glfw::FramebufferSizeEvent(width, height) => {
- self.event_queue.borrow_mut().push(ResizeWindowEvent(width as uint, height as uint));
+ self.event_queue.borrow_mut().push(
+ ResizeWindowEvent(TypedSize2D(width as uint, height as uint)));
},
glfw::RefreshEvent => {
self.event_queue.borrow_mut().push(RefreshWindowEvent);
diff --git a/src/components/main/platform/common/glut_windowing.rs b/src/components/main/platform/common/glut_windowing.rs
index e14728c10d2..4d6a88c9bc2 100644
--- a/src/components/main/platform/common/glut_windowing.rs
+++ b/src/components/main/platform/common/glut_windowing.rs
@@ -144,9 +144,14 @@ impl WindowMethods<Application> for Window {
wrapped_window
}
- /// Returns the size of the window.
- fn size(&self) -> TypedSize2D<DevicePixel, f32> {
- TypedSize2D(glut::get(WindowWidth) as f32, glut::get(WindowHeight) as f32)
+ /// Returns the size of the window in hardware pixels.
+ fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, uint> {
+ TypedSize2D(glut::get(WindowWidth) as uint, glut::get(WindowHeight) as uint)
+ }
+
+ /// Returns the size of the window in density-independent "px" units.
+ fn size(&self) -> TypedSize2D<ScreenPx, f32> {
+ self.framebuffer_size().as_f32() / self.hidpi_factor()
}
/// Presents the window to the screen (perhaps by page flipping).
diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs
index 1cded10aaff..adb7942f460 100644
--- a/src/components/main/windowing.rs
+++ b/src/components/main/windowing.rs
@@ -32,7 +32,7 @@ pub enum WindowEvent {
/// Sent when part of the window is marked dirty and needs to be redrawn.
RefreshWindowEvent,
/// Sent when the window is resized.
- ResizeWindowEvent(uint, uint),
+ ResizeWindowEvent(TypedSize2D<DevicePixel, uint>),
/// Sent when a new URL is to be loaded.
LoadUrlWindowEvent(String),
/// Sent when a mouse hit test is to be performed.
@@ -59,8 +59,10 @@ pub trait ApplicationMethods {
pub trait WindowMethods<A> {
/// Creates a new window.
fn new(app: &A, is_foreground: bool) -> Rc<Self>;
- /// Returns the size of the window.
- fn size(&self) -> TypedSize2D<DevicePixel, f32>;
+ /// Returns the size of the window in hardware pixels.
+ fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, uint>;
+ /// Returns the size of the window in density-independent "px" units.
+ fn size(&self) -> TypedSize2D<ScreenPx, f32>;
/// Presents the window to the screen (perhaps by page flipping).
fn present(&self);