Skip to content

Commit

Permalink
Implement viewport functions for window #1718
Browse files Browse the repository at this point in the history
  • Loading branch information
farodin91 committed Sep 1, 2015
1 parent 9f85370 commit f098738
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 63 deletions.
29 changes: 23 additions & 6 deletions components/compositing/compositor.rs
Expand Up @@ -11,11 +11,11 @@ use surface_map::SurfaceMap;
use windowing;
use windowing::{MouseWindowEvent, WindowEvent, WindowMethods, WindowNavigateMsg};

use euclid::Matrix4;
use euclid::point::{Point2D, TypedPoint2D};
use euclid::rect::{Rect, TypedRect};
use euclid::point::TypedPoint2D;
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::{Size2D, TypedSize2D};
use euclid::size::TypedSize2D;
use euclid::{Size2D, Point2D, Rect, Matrix4};
use gfx::paint_task::{ChromeToPaintMsg, PaintRequest};
use gfx_traits::color;
use gleam::gl;
Expand Down Expand Up @@ -390,7 +390,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.send_buffer_requests_for_all_layers();
}

(Msg::GetNativeDisplay(chan), ShutdownState::NotShuttingDown) => {
(Msg::GetNativeDisplay(chan),
ShutdownState::NotShuttingDown) => {
chan.send(Some(self.native_display.clone())).unwrap();
}

Expand All @@ -415,11 +416,27 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.surface_map.insert_surfaces(&self.native_display, native_surfaces);
}

(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point),
(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point, _),
ShutdownState::NotShuttingDown) => {
self.scroll_fragment_to_point(pipeline_id, layer_id, point);
}

(Msg::MoveTo(point),
ShutdownState::NotShuttingDown) => {
self.window.set_position(point);
}

(Msg::ResizeTo(size),
ShutdownState::NotShuttingDown) => {
self.window.set_inner_size(size);
}

(Msg::GetClientWindow(send),
ShutdownState::NotShuttingDown) => {
let rect = self.window.client_window();
send.send(rect).unwrap();
}

(Msg::Status(message), ShutdownState::NotShuttingDown) => {
self.window.status(message);
}
Expand Down
30 changes: 25 additions & 5 deletions components/compositing/compositor_task.rs
Expand Up @@ -11,8 +11,7 @@ use compositor;
use headless;
use windowing::{WindowEvent, WindowMethods};

use euclid::point::Point2D;
use euclid::rect::Rect;
use euclid::{Size2D, Point2D, Rect};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use layers::layers::{BufferRequest, LayerBufferSet};
use layers::platform::surface::{NativeDisplay, NativeSurface};
Expand Down Expand Up @@ -66,8 +65,20 @@ pub fn run_script_listener_thread(compositor_proxy: Box<CompositorProxy + 'stati
receiver: IpcReceiver<ScriptToCompositorMsg>) {
while let Ok(msg) = receiver.recv() {
match msg {
ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point) => {
compositor_proxy.send(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point));
ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point, _smooth) => {
compositor_proxy.send(Msg::ScrollFragmentPoint(pipeline_id, layer_id, point, _smooth));
}

ScriptToCompositorMsg::GetClientWindow(send) => {
compositor_proxy.send(Msg::GetClientWindow(send));
}

ScriptToCompositorMsg::MoveTo(point) => {
compositor_proxy.send(Msg::MoveTo(point));
}

ScriptToCompositorMsg::ResizeTo(size) => {
compositor_proxy.send(Msg::ResizeTo(size));
}

ScriptToCompositorMsg::Exit => {
Expand Down Expand Up @@ -159,7 +170,7 @@ pub enum Msg {
/// Alerts the compositor that the specified layer's rect has changed.
SetLayerRect(PipelineId, LayerId, Rect<f32>),
/// Scroll a page in a window
ScrollFragmentPoint(PipelineId, LayerId, Point2D<f32>),
ScrollFragmentPoint(PipelineId, LayerId, Point2D<f32>, bool),
/// Requests that the compositor assign the painted buffers to the given layers.
AssignPaintedBuffers(PipelineId, Epoch, Vec<(LayerId, Box<LayerBufferSet>)>, FrameTreeId),
/// Alerts the compositor that the current page has changed its title.
Expand Down Expand Up @@ -201,6 +212,12 @@ pub enum Msg {
CollectMemoryReports(mem::ReportsChan),
/// A status message to be displayed by the browser chrome.
Status(Option<String>),
/// Get Window Informations size and position
GetClientWindow(IpcSender<(Size2D<u32>, Point2D<i32>)>),
/// Move the window to a point
MoveTo(Point2D<i32>),
/// Resize the window to size
ResizeTo(Size2D<u32>),
}

impl Debug for Msg {
Expand Down Expand Up @@ -232,6 +249,9 @@ impl Debug for Msg {
Msg::ReturnUnusedNativeSurfaces(..) => write!(f, "ReturnUnusedNativeSurfaces"),
Msg::CollectMemoryReports(..) => write!(f, "CollectMemoryReports"),
Msg::Status(..) => write!(f, "Status"),
Msg::GetClientWindow(..) => write!(f, "GetClientWindow"),
Msg::MoveTo(..) => write!(f, "MoveTo"),
Msg::ResizeTo(..) => write!(f, "ResizeTo"),
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion components/compositing/headless.rs
Expand Up @@ -6,7 +6,7 @@ use compositor_task::{CompositorEventListener, CompositorReceiver, Msg};
use windowing::WindowEvent;

use euclid::scale_factor::ScaleFactor;
use euclid::size::Size2D;
use euclid::{Size2D, Point2D};
use msg::constellation_msg::AnimationState;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
Expand Down Expand Up @@ -89,6 +89,11 @@ impl CompositorEventListener for NullCompositor {
response_chan.send(()).unwrap();
}

Msg::GetClientWindow(send) => {
let rect = (Size2D::zero(), Point2D::zero());
send.send(rect).unwrap();
}

Msg::ChangeRunningAnimationsState(pipeline_id, animation_state) => {
match animation_state {
AnimationState::AnimationsPresent |
Expand Down Expand Up @@ -121,6 +126,8 @@ impl CompositorEventListener for NullCompositor {
Msg::ViewportConstrained(..) => {}
Msg::CreatePng(..) |
Msg::PaintTaskExited(..) |
Msg::MoveTo(..) |
Msg::ResizeTo(..) |
Msg::IsReadyToSaveImageReply(..) => {}
Msg::NewFavicon(..) => {}
Msg::HeadParsed => {}
Expand Down
8 changes: 8 additions & 0 deletions components/compositing/windowing.rs
Expand Up @@ -9,6 +9,7 @@ use compositor_task::{CompositorProxy, CompositorReceiver};
use euclid::point::TypedPoint2D;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use euclid::{Size2D, Point2D};
use layers::geometry::DevicePixel;
use layers::platform::surface::NativeDisplay;
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
Expand Down Expand Up @@ -103,6 +104,13 @@ pub trait WindowMethods {
/// Presents the window to the screen (perhaps by page flipping).
fn present(&self);

/// Return the size of the window with head and borders and position of the window values
fn client_window(&self) -> (Size2D<u32>, Point2D<i32>);
/// Set the size inside of borders and head
fn set_inner_size(&self, size: Size2D<u32>);
/// Set the window position
fn set_position(&self, point: Point2D<i32>);

/// Sets the page title for the current page.
fn set_page_title(&self, title: Option<String>);
/// Sets the load data for the current page.
Expand Down
10 changes: 6 additions & 4 deletions components/msg/compositor_msg.rs
Expand Up @@ -5,8 +5,8 @@
use azure::azure_hl::Color;
use constellation_msg::{Key, KeyState, KeyModifiers};
use euclid::Matrix4;
use euclid::point::Point2D;
use euclid::rect::Rect;
use euclid::{Size2D, Point2D, Rect};
use ipc_channel::ipc::IpcSender;
use layers::layers::{BufferRequest, LayerBufferSet};
use layers::platform::surface::NativeDisplay;
use std::fmt;
Expand Down Expand Up @@ -119,9 +119,11 @@ pub trait PaintListener {

#[derive(Deserialize, Serialize)]
pub enum ScriptToCompositorMsg {
ScrollFragmentPoint(PipelineId, LayerId, Point2D<f32>),
ScrollFragmentPoint(PipelineId, LayerId, Point2D<f32>, bool),
SetTitle(PipelineId, Option<String>),
SendKeyEvent(Key, KeyState, KeyModifiers),
GetClientWindow(IpcSender<(Size2D<u32>, Point2D<i32>)>),
MoveTo(Point2D<i32>),
ResizeTo(Size2D<u32>),
Exit,
}

3 changes: 1 addition & 2 deletions components/msg/constellation_msg.rs
Expand Up @@ -5,9 +5,8 @@
//! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components.

use compositor_msg::Epoch;

use canvas_traits::CanvasMsg;
use compositor_msg::Epoch;
use euclid::rect::Rect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::{Size2D, TypedSize2D};
Expand Down
53 changes: 35 additions & 18 deletions components/script/dom/webidls/Window.webidl
Expand Up @@ -105,36 +105,53 @@ partial interface Window {
CSSStyleDeclaration getComputedStyle(Element elt, optional DOMString pseudoElt);
};

// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface
enum ScrollBehavior { "auto", "instant", "smooth" };

// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface
dictionary ScrollOptions {
ScrollBehavior behavior = "auto";
};

// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface
dictionary ScrollToOptions : ScrollOptions {
unrestricted double left;
unrestricted double top;
};

// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface
partial interface Window {
//MediaQueryList matchMedia(DOMString query);
[SameObject] readonly attribute Screen screen;

// browsing context
//void moveTo(double x, double y);
//void moveBy(double x, double y);
//void resizeTo(double x, double y);
//void resizeBy(double x, double y);
void moveTo(long x, long y);
void moveBy(long x, long y);
void resizeTo(long x, long y);
void resizeBy(long x, long y);

// viewport
//readonly attribute double innerWidth;
//readonly attribute double innerHeight;
readonly attribute long innerWidth;
readonly attribute long innerHeight;

// viewport scrolling
//readonly attribute double scrollX;
//readonly attribute double pageXOffset;
//readonly attribute double scrollY;
//readonly attribute double pageYOffset;
//void scroll(double x, double y, optional ScrollOptions options);
//void scrollTo(double x, double y, optional ScrollOptions options);
//void scrollBy(double x, double y, optional ScrollOptions options);
readonly attribute long scrollX;
readonly attribute long pageXOffset;
readonly attribute long scrollY;
readonly attribute long pageYOffset;
void scroll(optional ScrollToOptions options);
void scroll(unrestricted double x, unrestricted double y);
void scrollTo(optional ScrollToOptions options);
void scrollTo(unrestricted double x, unrestricted double y);
void scrollBy(optional ScrollToOptions options);
void scrollBy(unrestricted double x, unrestricted double y);

// client
//readonly attribute double screenX;
//readonly attribute double screenY;
//readonly attribute double outerWidth;
//readonly attribute double outerHeight;
//readonly attribute double devicePixelRatio;
readonly attribute long screenX;
readonly attribute long screenY;
readonly attribute long outerWidth;
readonly attribute long outerHeight;
readonly attribute double devicePixelRatio;
};

// Proprietary extensions.
Expand Down

0 comments on commit f098738

Please sign in to comment.