From 40ff6cff57e0d1ba7a8ac76e610f867379a99918 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 31 Jul 2015 14:03:42 +0200 Subject: [PATCH 01/13] viewport --- components/script/dom/webidls/Window.webidl | 37 +++-- components/script/dom/window.rs | 172 ++++++++++++++++++-- tests/html/viewport.html | 18 ++ 3 files changed, 200 insertions(+), 27 deletions(-) create mode 100644 tests/html/viewport.html diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 1fa85ffbe636..5d0fe546b879 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -97,6 +97,20 @@ partial interface Window { CSSStyleDeclaration getComputedStyle(HTMLElement 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); @@ -105,21 +119,24 @@ partial interface Window { // browsing context //void moveTo(double x, double y); //void moveBy(double x, double y); - //void resizeTo(double x, double y); + void resizeTo(double x, double y); //void resizeBy(double x, double y); // viewport - //readonly attribute double innerWidth; - //readonly attribute double innerHeight; + readonly attribute double innerWidth; + readonly attribute double 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 double scrollX; + readonly attribute double pageXOffset; + readonly attribute double scrollY; + readonly attribute double pageYOffset; + void scroll(optional ScrollToOptions options); + void scroll(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scrollTo(optional ScrollToOptions options); + void scrollTo(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scrollBy(optional ScrollToOptions options); + void scrollBy(unrestricted double x, unrestricted double y, optional ScrollOptions options); // client //readonly attribute double screenX; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d4f2a36eabff..654d4152967c 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,7 +7,7 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::FunctionBinding::Function; -use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback}; +use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions}; use dom::bindings::codegen::InheritTypes::{NodeCast, EventTargetCast}; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; @@ -39,7 +39,7 @@ use script_task::ScriptMsg; use script_traits::ScriptControlChan; use timers::{IsInterval, TimerId, TimerManager, TimerCallback}; use webdriver_handlers::jsval_to_webdriver; - +use core::ops::Deref; use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; use devtools_traits::{TracingMetadata}; use msg::compositor_msg::ScriptListener; @@ -48,6 +48,7 @@ use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use net_traits::ResourceTask; use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask}; use net_traits::storage_task::{StorageTask, StorageType}; +use num::traits::ToPrimitive; use profile_traits::mem; use string_cache::Atom; use util::geometry::{self, Au, MAX_RECT}; @@ -103,6 +104,8 @@ pub enum ReflowReason { RequestAnimationFrame, } +pub type ScrollPoint = Point2D; + #[dom_struct] pub struct Window { eventtarget: EventTarget, @@ -196,6 +199,8 @@ pub struct Window { /// The current state of the window object current_state: Cell, + + current_scroll_position: Cell> } impl Window { @@ -561,6 +566,136 @@ impl<'a> WindowMethods for &'a Window { // Step 5. CSSStyleDeclaration::new(self, element, pseudo, CSSModificationAccess::Readonly) } + + // https://drafts.csswg.org/cssom-view/#dom-window-innerheight + //TODO Include Scrollbar + fn InnerHeight(self) -> Finite { + let size = self.window_size.get(); + match size { + Some(e) => { + let height = e.visible_viewport.height.get().to_f64().unwrap_or(0.0f64); + Finite::wrap(height) + } + None => Finite::wrap(0.0f64) + } + } + + // https://drafts.csswg.org/cssom-view/#dom-window-innerwidth + //TODO Include Scrollbar + fn InnerWidth(self) -> Finite { + let size = self.window_size.get(); + match size { + Some(e) => { + let width = e.visible_viewport.width.get().to_f64().unwrap_or(0.0f64); + Finite::wrap(width) + } + None => Finite::wrap(0.0f64) + } + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollx + fn ScrollX(self) -> Finite { + let origin = self.current_scroll_position.get().origin; + Finite::wrap(origin.x.to_f64_px()) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset + fn PageXOffset(self) -> Finite { + self.ScrollX() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrolly + fn ScrollY(self) -> Finite { + let origin = self.current_scroll_position.get().origin; + Finite::wrap(origin.y.to_f64_px()) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset + fn PageYOffset(self) -> Finite { + self.ScrollY() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scroll + fn Scroll(self, options: &ScrollToOptions) { + // Step 1 + let left = options.left.unwrap_or(0.0f64); + let top = options.top.unwrap_or(0.0f64); + self.Scroll_(left, top, &options.parent); + + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scroll + fn Scroll_(self, x: f64, y: f64, options: &ScrollOptions) { + // Step 4 + if self.window_size.get.is_none() { + return; + } + + // Step 5 + //TODO Exclude Scrollbar + let width = self.InnerWidth(); + // Step 6 + //TODO Exclude Scrollbar + let height = self.InnerHeight(); + + + + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollto + fn ScrollTo(self, options: &ScrollToOptions) { + self.Scroll(options); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollto + fn ScrollTo_(self, x: f64, y: f64, options: &ScrollOptions) { + self.Scroll_(x, y, options); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollby + fn ScrollBy(self, options: &ScrollToOptions) { + // Step 1 + let x = options.left.unwrap_or(0.0f64); + let y = options.top.unwrap_or(0.0f64); + self.ScrollBy_(x, y, &options.parent); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollby + fn ScrollBy_(self, x: f64, y: f64, options: &ScrollOptions) { + // Step 3 + let left = x + self.ScrollX().deref(); + // Step 4 + let top = y + self.ScrollY().deref(); + + // Step 5 + self.Scroll_(left, top, options); + } + + fn ResizeTo(self, x: Finite, y: Finite) { + // Step 1 + } + + // https://drafts.csswg.org/cssom-view/#dom-window-screenx + //fn ScreenX(self) -> Finite { + // Finite::wrap(0.0f64) + //} + + // https://drafts.csswg.org/cssom-view/#dom-window-screeny + //fn ScreenY(self) -> Finite { + // Finite::wrap(0.0f64) + //} + + // https://drafts.csswg.org/cssom-view/#dom-window-outerwidth + //fn OuterHeight(self) -> Finite { + // Finite::wrap(0.0f64) + //} + + // https://drafts.csswg.org/cssom-view/#dom-window-outerheight + //fn OuterWidth(self) -> Finite { + // Finite::wrap(0.0f64) + //} + + } pub trait WindowHelpers { @@ -936,28 +1071,30 @@ impl<'a> WindowHelpers for &'a Window { } fn set_page_clip_rect_with_new_viewport(self, viewport: Rect) -> bool { + let rect = geometry::f32_rect_to_au_rect(viewport.clone()); + self.current_scroll_position.set(rect); // We use a clipping rectangle that is five times the size of the of the viewport, // so that we don't collect display list items for areas too far outside the viewport, // but also don't trigger reflows every time the viewport changes. static VIEWPORT_EXPANSION: f32 = 2.0; // 2 lengths on each side plus original length is 5 total. - let proposed_clip_rect = geometry::f32_rect_to_au_rect( - viewport.inflate(viewport.size.width * VIEWPORT_EXPANSION, - viewport.size.height * VIEWPORT_EXPANSION)); - let clip_rect = self.page_clip_rect.get(); - if proposed_clip_rect == clip_rect { - return false; - } + let proposed_clip_rect = geometry::f32_rect_to_au_rect( + viewport.inflate(viewport.size.width * VIEWPORT_EXPANSION, + viewport.size.height * VIEWPORT_EXPANSION)); + let clip_rect = self.page_clip_rect.get(); + if proposed_clip_rect == clip_rect { + return false; + } - let had_clip_rect = clip_rect != MAX_RECT; - if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) { - return false; - } + let had_clip_rect = clip_rect != MAX_RECT; + if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) { + return false; + } - self.page_clip_rect.set(proposed_clip_rect); + self.page_clip_rect.set(proposed_clip_rect); - // If we didn't have a clip rect, the previous display doesn't need rebuilding - // because it was built for infinite clip (MAX_RECT). - had_clip_rect + // If we didn't have a clip rect, the previous display doesn't need rebuilding + // because it was built for infinite clip (MAX_RECT). + had_clip_rect } fn set_devtools_wants_updates(self, value: bool) { @@ -1090,6 +1227,7 @@ impl Window { layout_rpc: layout_rpc, layout_join_port: DOMRefCell::new(None), window_size: Cell::new(window_size), + current_scroll_position: Cell::new(Rect::zero()), pending_reflow_count: Cell::new(0), current_state: Cell::new(WindowState::Alive), diff --git a/tests/html/viewport.html b/tests/html/viewport.html new file mode 100644 index 000000000000..ac3e7491dd96 --- /dev/null +++ b/tests/html/viewport.html @@ -0,0 +1,18 @@ + + + + Test innerHeight + + + + +
+ + From a9df5f2f660b401c65f99f8bd271f8653162038d Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 31 Jul 2015 20:25:35 +0200 Subject: [PATCH 02/13] [WIP] Implement viewport stuffs for window #1718 --- components/compositing/compositor.rs | 10 ++++++- components/compositing/compositor_task.rs | 8 ++++++ components/compositing/headless.rs | 1 + components/msg/compositor_msg.rs | 7 ++++- components/script/dom/webidls/Window.webidl | 2 +- components/script/dom/window.rs | 26 ++++++++++--------- components/script/script_task.rs | 9 +++++++ tests/html/viewport.html | 6 ++++- .../window-properties.html.ini | 10 ------- 9 files changed, 53 insertions(+), 26 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 0061a4baa400..3ec51dc2c57c 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -420,6 +420,11 @@ impl IOCompositor { self.scroll_fragment_to_point(pipeline_id, layer_id, point); } + (Msg::ScrollDelta(pipeline_id, layer_id, delta), + ShutdownState::NotShuttingDown) => { + self.scroll_delta(pipeline_id, layer_id, delta); + } + (Msg::Status(message), ShutdownState::NotShuttingDown) => { self.window.status(message); } @@ -877,6 +882,10 @@ impl IOCompositor { } } + fn scroll_delta(&mut self, id: PipelineId, layer: LayerId, delta: Point2D) { + println!("test"); + } + fn handle_window_message(&mut self, event: WindowEvent) { match event { WindowEvent::Idle => {} @@ -1752,4 +1761,3 @@ pub enum CompositingReason { /// The window has been zoomed. Zoom, } - diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index d559630bfcf8..5db5ba478737 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -83,6 +83,10 @@ pub fn run_script_listener_thread(compositor_proxy: Box { compositor_proxy.send(Msg::KeyEvent(key, key_state, key_modifiers)) } + + ScriptToCompositorMsg::ScrollDelta(pipeline_id, layer_id, delta) => { + + } } } } @@ -160,6 +164,9 @@ pub enum Msg { SetLayerRect(PipelineId, LayerId, Rect), /// Scroll a page in a window ScrollFragmentPoint(PipelineId, LayerId, Point2D), + + + ScrollDelta(PipelineId, LayerId, Point2D), /// Requests that the compositor assign the painted buffers to the given layers. AssignPaintedBuffers(PipelineId, Epoch, Vec<(LayerId, Box)>, FrameTreeId), /// Alerts the compositor that the current page has changed its title. @@ -220,6 +227,7 @@ impl Debug for Msg { Msg::LoadComplete(..) => write!(f, "LoadComplete"), Msg::LoadStart(..) => write!(f, "LoadStart"), Msg::ScrollTimeout(..) => write!(f, "ScrollTimeout"), + Msg::ScrollDelta(..) => write!(f, "ScrollDelta"), Msg::RecompositeAfterScroll => write!(f, "RecompositeAfterScroll"), Msg::KeyEvent(..) => write!(f, "KeyEvent"), Msg::SetCursor(..) => write!(f, "SetCursor"), diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index d56c50de1d27..d12ad27df69c 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -97,6 +97,7 @@ impl CompositorEventListener for NullCompositor { Msg::AssignPaintedBuffers(..) | Msg::ChangeRunningAnimationsState(..) | Msg::ScrollFragmentPoint(..) | + Msg::ScrollDelta(..) | Msg::Status(..) | Msg::LoadStart(..) | Msg::LoadComplete(..) | diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index 3a1d098eb363..ac9e88f27415 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -119,6 +119,7 @@ pub trait PaintListener { #[derive(Deserialize, Serialize)] pub enum ScriptToCompositorMsg { ScrollFragmentPoint(PipelineId, LayerId, Point2D), + ScrollDelta(PipelineId, LayerId, Point2D), SetTitle(PipelineId, Option), SendKeyEvent(Key, KeyState, KeyModifiers), Exit, @@ -143,6 +144,11 @@ impl ScriptListener { .unwrap() } + pub fn scroll_delta(&mut self, id: PipelineId, layer: LayerId, delta: Point2D) { + self.0.send(ScriptToCompositorMsg::ScrollDelta(id, layer, delta)) + .unwrap() + } + pub fn close(&mut self) { self.0.send(ScriptToCompositorMsg::Exit).unwrap() } @@ -159,4 +165,3 @@ impl ScriptListener { self.0.send(ScriptToCompositorMsg::SendKeyEvent(key, state, modifiers)).unwrap() } } - diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 5d0fe546b879..995d6c88dcae 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -119,7 +119,7 @@ partial interface Window { // browsing context //void moveTo(double x, double y); //void moveBy(double x, double y); - void resizeTo(double x, double y); + //void resizeTo(double x, double y); //void resizeBy(double x, double y); // viewport diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 654d4152967c..83d094faad81 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,7 +7,7 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::FunctionBinding::Function; -use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions}; +use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions, ScrollBehavior}; use dom::bindings::codegen::InheritTypes::{NodeCast, EventTargetCast}; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; @@ -626,20 +626,22 @@ impl<'a> WindowMethods for &'a Window { // https://drafts.csswg.org/cssom-view/#dom-window-scroll fn Scroll_(self, x: f64, y: f64, options: &ScrollOptions) { + println!("test"); // Step 4 - if self.window_size.get.is_none() { + if self.window_size.get().is_none() { return; } - // Step 5 - //TODO Exclude Scrollbar - let width = self.InnerWidth(); - // Step 6 - //TODO Exclude Scrollbar - let height = self.InnerHeight(); - + let width = (*self.ScrollX()); + let height = (*self.ScrollY()); + let offsetx = width - x; + let offsety = height - y; + println!("offsetx: {}, offsety: {}", offsetx, offsety); + let delta = Point2D::new(offsetx.to_f32().unwrap_or(0.0f32), offsety.to_f32().unwrap_or(0.0f32)); + //let script_chan = self.script_chan.clone(); + //script_chan.send(ScriptMsg::ScrollDelta(self.pipeline(), delta)).unwrap() } // https://drafts.csswg.org/cssom-view/#dom-window-scrollto @@ -671,9 +673,9 @@ impl<'a> WindowMethods for &'a Window { self.Scroll_(left, top, options); } - fn ResizeTo(self, x: Finite, y: Finite) { - // Step 1 - } + //fn ResizeTo(self, x: Finite, y: Finite) { + // // Step 1 + //} // https://drafts.csswg.org/cssom-view/#dom-window-screenx //fn ScreenX(self) -> Finite { diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 7deed84430d2..1dc21a3a0dd2 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -23,6 +23,7 @@ use document_loader::{LoadType, DocumentLoader, NotifierData}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; +use dom::bindings::codegen::Bindings::WindowBinding::ScrollOptions; use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast, EventCast}; use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::StringificationBehavior; @@ -204,6 +205,8 @@ pub enum ScriptMsg { /// Requests that the script task measure its memory usage. The results are sent back via the /// supplied channel. CollectReports(ReportsChan), + + ScrollDelta(PipelineId, Point2D) } /// A cloneable interface for communicating with an event loop. @@ -836,9 +839,15 @@ impl ScriptTask { self.handle_loads_complete(id), ScriptMsg::CollectReports(reports_chan) => self.collect_reports(reports_chan), + ScriptMsg::ScrollDelta(id, delta) => + self.handle_scroll_delta(id, delta), } } + fn handle_scroll_delta(&self, id: PipelineId, delta: Point2D) { + self.compositor.borrow_mut().scroll_delta(id, LayerId::null(), delta); + } + fn handle_msg_from_devtools(&self, msg: DevtoolScriptControlMsg) { let page = self.root_page(); match msg { diff --git a/tests/html/viewport.html b/tests/html/viewport.html index ac3e7491dd96..e6c9fc7eed6f 100644 --- a/tests/html/viewport.html +++ b/tests/html/viewport.html @@ -9,10 +9,14 @@ console.log("ScrollY: "+ window.scrollY); console.log("ScrollX: "+ window.scrollX); } + function scroll(){ + window.scroll(0,0); + } -
+
+ diff --git a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini index 680491000819..8e3e65c87627 100644 --- a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini +++ b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini @@ -57,15 +57,6 @@ [Window method: matchMedia] expected: FAIL - [Window method: scroll] - expected: FAIL - - [Window method: scrollTo] - expected: FAIL - - [Window method: scrollBy] - expected: FAIL - [Window readonly attribute: history] expected: FAIL @@ -377,4 +368,3 @@ [Window replaceable attribute: devicePixelRatio] expected: FAIL - From 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 31 Jul 2015 14:03:42 +0200 Subject: [PATCH 03/13] [WIP] Implement viewport stuffs for window #1718 --- components/compositing/compositor.rs | 16 +- components/compositing/compositor_task.rs | 19 ++ components/compositing/headless.rs | 3 + components/compositing/windowing.rs | 12 +- components/msg/compositor_msg.rs | 17 +- components/script/dom/webidls/Window.webidl | 53 ++-- components/script/dom/window.rs | 241 ++++++++++++++++-- components/script/script_task.rs | 8 + ports/cef/window.rs | 20 +- ports/glutin/window.rs | 17 ++ ports/gonk/src/window.rs | 15 +- tests/html/viewport.html | 27 ++ .../window-properties.html.ini | 1 - 13 files changed, 403 insertions(+), 46 deletions(-) create mode 100644 tests/html/viewport.html diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index b3830a111403..9032e76068d1 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -418,6 +418,21 @@ impl IOCompositor { 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); } @@ -1750,4 +1765,3 @@ pub enum CompositingReason { /// The window has been zoomed. Zoom, } - diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index d559630bfcf8..59ceedb70788 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -12,6 +12,7 @@ use headless; use windowing::{WindowEvent, WindowMethods}; use euclid::point::Point2D; +use euclid::size::Size2D; use euclid::rect::Rect; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use layers::platform::surface::{NativeDisplay, NativeSurface}; @@ -70,6 +71,18 @@ pub fn run_script_listener_thread(compositor_proxy: Box { + 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 => { let (chan, port) = channel(); compositor_proxy.send(Msg::Exit(chan)); @@ -201,6 +214,9 @@ pub enum Msg { CollectMemoryReports(mem::ReportsChan), /// A status message to be displayed by the browser chrome. Status(Option), + GetClientWindow(IpcSender>), + MoveTo(Point2D), + ResizeTo(Size2D), } impl Debug for Msg { @@ -232,6 +248,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"), } } } diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index d56c50de1d27..ff173a5d98d8 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -109,6 +109,9 @@ impl CompositorEventListener for NullCompositor { Msg::ViewportConstrained(..) => {} Msg::CreatePng(..) | Msg::PaintTaskExited(..) | + Msg::GetClientWindow(..) | + Msg::MoveTo(..) | + Msg::ResizeTo(..) | Msg::IsReadyToSaveImageReply(..) => {} Msg::NewFavicon(..) => {} Msg::HeadParsed => {} diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 6ad7790edaa7..67609719ce6b 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -6,9 +6,10 @@ use compositor_task::{CompositorProxy, CompositorReceiver}; -use euclid::point::TypedPoint2D; +use euclid::rect::Rect; +use euclid::point::{TypedPoint2D, Point2D}; use euclid::scale_factor::ScaleFactor; -use euclid::size::TypedSize2D; +use euclid::size::{TypedSize2D, Size2D}; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; use msg::constellation_msg::{Key, KeyState, KeyModifiers}; @@ -103,6 +104,13 @@ pub trait WindowMethods { /// Presents the window to the screen (perhaps by page flipping). fn present(&self); + /// Return outersize and position values + fn client_window(&self) -> Rect; + + fn set_inner_size(&self, size: Size2D); + + fn set_position(&self, point: Point2D); + /// Sets the page title for the current page. fn set_page_title(&self, title: Option); /// Sets the load data for the current page. diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index 3a1d098eb363..595e975e4b5d 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -5,6 +5,7 @@ use azure::azure_hl::Color; use constellation_msg::{Key, KeyState, KeyModifiers}; use euclid::point::Point2D; +use euclid::size::Size2D; use euclid::rect::Rect; use euclid::Matrix4; use ipc_channel::ipc::IpcSender; @@ -121,6 +122,9 @@ pub enum ScriptToCompositorMsg { ScrollFragmentPoint(PipelineId, LayerId, Point2D), SetTitle(PipelineId, Option), SendKeyEvent(Key, KeyState, KeyModifiers), + GetClientWindow(IpcSender>), + MoveTo(Point2D), + ResizeTo(Size2D), Exit, } @@ -143,6 +147,18 @@ impl ScriptListener { .unwrap() } + pub fn client_window(&mut self, send: IpcSender>) { + self.0.send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap() + } + + pub fn move_window(&mut self, point: Point2D) { + self.0.send(ScriptToCompositorMsg::MoveTo(point)).unwrap() + } + + pub fn resize_window(&mut self, size: Size2D) { + self.0.send(ScriptToCompositorMsg::ResizeTo(size)).unwrap() + } + pub fn close(&mut self) { self.0.send(ScriptToCompositorMsg::Exit).unwrap() } @@ -159,4 +175,3 @@ impl ScriptListener { self.0.send(ScriptToCompositorMsg::SendKeyEvent(key, state, modifiers)).unwrap() } } - diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 1fa85ffbe636..caca210be682 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -97,36 +97,53 @@ partial interface Window { CSSStyleDeclaration getComputedStyle(HTMLElement 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, optional ScrollOptions options); + void scrollTo(optional ScrollToOptions options); + void scrollTo(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scrollBy(optional ScrollToOptions options); + void scrollBy(unrestricted double x, unrestricted double y, optional ScrollOptions options); // 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. diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d7a9e9f243a5..9aae7eceec6f 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,7 +7,8 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::FunctionBinding::Function; -use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback}; +use dom::bindings::codegen::Bindings::WindowBinding::{self, + WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions}; use dom::bindings::codegen::InheritTypes::{NodeCast, EventTargetCast}; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; @@ -39,15 +40,15 @@ use script_task::ScriptMsg; use script_traits::ScriptControlChan; use timers::{IsInterval, TimerId, TimerManager, TimerCallback}; use webdriver_handlers::jsval_to_webdriver; - use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; use devtools_traits::{TracingMetadata}; -use msg::compositor_msg::ScriptListener; +use msg::compositor_msg::{ScriptListener, LayerId}; use msg::constellation_msg::{LoadData, PipelineId, SubpageId, ConstellationChan, WindowSizeData, WorkerId}; use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use net_traits::ResourceTask; use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask}; use net_traits::storage_task::{StorageTask, StorageType}; +use num::traits::ToPrimitive; use profile_traits::mem; use string_cache::Atom; use util::geometry::{self, Au, MAX_RECT}; @@ -55,7 +56,7 @@ use util::{breakpoint, opts}; use util::str::{DOMString,HTML_SPACE_CHARACTERS}; use euclid::{Point2D, Rect, Size2D}; -use ipc_channel::ipc::IpcSender; +use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{Evaluate2, MutableHandleValue}; use js::jsapi::{JSContext, HandleValue}; use js::jsapi::{JS_GC, JS_GetRuntime, JSAutoCompartment, JSAutoRequest}; @@ -104,6 +105,8 @@ pub enum ReflowReason { RequestAnimationFrame, } +pub type ScrollPoint = Point2D; + #[dom_struct] pub struct Window { eventtarget: EventTarget, @@ -197,6 +200,8 @@ pub struct Window { /// The current state of the window object current_state: Cell, + + current_scroll_position: Cell> } impl Window { @@ -562,6 +567,186 @@ impl<'a> WindowMethods for &'a Window { // Step 5. CSSStyleDeclaration::new(self, element, pseudo, CSSModificationAccess::Readonly) } + + // https://drafts.csswg.org/cssom-view/#dom-window-innerheight + //TODO Include Scrollbar + fn InnerHeight(self) -> i32 { + let size = self.window_size.get(); + match size { + Some(e) => e.visible_viewport.height.get().to_i32().unwrap_or(0), + None => 0 + } + } + + // https://drafts.csswg.org/cssom-view/#dom-window-innerwidth + //TODO Include Scrollbar + fn InnerWidth(self) -> i32 { + let size = self.window_size.get(); + match size { + Some(e) => e.visible_viewport.width.get().to_i32().unwrap_or(0), + None => 0 + } + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollx + fn ScrollX(self) -> i32 { + self.current_scroll_position.get().origin.x.to_px() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset + fn PageXOffset(self) -> i32{ + self.ScrollX() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrolly + fn ScrollY(self) -> i32 { + self.current_scroll_position.get().origin.y.to_px() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset + fn PageYOffset(self) -> i32 { + self.ScrollY() + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scroll + fn Scroll(self, options: &ScrollToOptions) { + // Step 1 + let left = options.left.unwrap_or(0.0f64); + let top = options.top.unwrap_or(0.0f64); + self.Scroll_(left, top, &options.parent); + + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scroll + fn Scroll_(self, x: f64, y: f64, _: &ScrollOptions) { + // Step 4 + if self.window_size.get().is_none() { + return; + } + + // Step 5 remove scrollbar width + let width = self.InnerWidth() as f64; + // Step 6 remove scrollbar height + let height = self.InnerHeight() as f64; + + // Step 7 & 8 + // TODO use overflow direction + let body = self.Document().GetBody(); + let (rangedx,rangedy) = match body { + Some(e) => { + let node = NodeCast::from_ref(e.r()); + let content_size = node.get_bounding_content_box(); + + let content_height = content_size.size.height.to_f64_px(); + let content_width = content_size.size.width.to_f64_px(); + (x.max(0.0f64).min(content_width - width), + y.max(0.0f64).min(content_height - height)) + }, + None => { + (x.max(0.0f64), y.max(0.0f64)) + } + }; + + // Step 10 + // TODO handling ongoing smoth scrolling + if rangedx == self.ScrollX() as f64 && rangedy == self.ScrollX() as f64 { + return; + } + + // TODO Step 11 + + // Step 12 Perform Scroll + let point = Point2D::new(rangedx.to_f32().unwrap_or(0.0f32), rangedy.to_f32().unwrap_or(0.0f32)); + self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollto + fn ScrollTo(self, options: &ScrollToOptions) { + self.Scroll(options); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollto + fn ScrollTo_(self, x: f64, y: f64, options: &ScrollOptions) { + self.Scroll_(x, y, options); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollby + fn ScrollBy(self, options: &ScrollToOptions) { + // Step 1 + let x = options.left.unwrap_or(0.0f64); + let y = options.top.unwrap_or(0.0f64); + self.ScrollBy_(x, y, &options.parent); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-scrollby + fn ScrollBy_(self, x: f64, y: f64, options: &ScrollOptions) { + // Step 3 + let left = x + self.ScrollX() as f64; + // Step 4 + let top = y + self.ScrollY() as f64; + + // Step 5 + self.Scroll_(left, top, options); + } + + // https://drafts.csswg.org/cssom-view/#dom-window-resizeto + fn ResizeTo(self, x: i32, y: i32) { + // Step 1 + let size = Size2D::new(x,y); + self.compositor.borrow_mut().resize_window(size) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-resizeby + fn ResizeBy(self, x: i32, y: i32) { + let client = self.client_window(); + // Step 1 + self.MoveTo(x + client.size.width, y + client.size.height) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-moveto + fn MoveTo(self, x: i32, y: i32) { + // Step 1 + let point = Point2D::new(x,y); + self.compositor.borrow_mut().move_window(point) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-moveby + fn MoveBy(self, x: i32, y: i32) { + let client = self.client_window(); + // Step 1 + self.MoveTo(x + client.origin.x, y + client.origin.y) + } + + // https://drafts.csswg.org/cssom-view/#dom-window-screenx + fn ScreenX(self) -> i32 { + let client = self.client_window(); + client.origin.x + } + + // https://drafts.csswg.org/cssom-view/#dom-window-screeny + fn ScreenY(self) -> i32 { + let client = self.client_window(); + client.origin.y + } + + // https://drafts.csswg.org/cssom-view/#dom-window-outerheight + fn OuterHeight(self) -> i32 { + let client = self.client_window(); + client.size.height + } + + // https://drafts.csswg.org/cssom-view/#dom-window-outerwidth + fn OuterWidth(self) -> i32 { + let client = self.client_window(); + client.size.width + } + + // https://drafts.csswg.org/cssom-view/#dom-window-devicepixelratio + fn DevicePixelRatio(self) -> Finite { + Finite::wrap(0.0f64) + } + + } pub trait WindowHelpers { @@ -583,6 +768,7 @@ pub trait WindowHelpers { fn steal_fragment_name(self) -> Option; fn set_window_size(self, size: WindowSizeData); fn window_size(self) -> Option; + fn client_window(self) -> Rect; fn get_url(self) -> Url; fn resource_task(self) -> ResourceTask; fn mem_profiler_chan(self) -> mem::ProfilerChan; @@ -787,6 +973,20 @@ impl<'a> WindowHelpers for &'a Window { } } + fn client_window(self) -> Rect { + let channel = ipc::channel::>(); + match channel { + Ok((send,recv)) => { + self.compositor.borrow_mut().client_window(send); + recv.recv().unwrap_or(Rect::zero()) + } + Err(_) =>{ + Rect::zero() + } + } + + } + fn layout(&self) -> &LayoutRPC { &*self.layout_rpc } @@ -937,28 +1137,30 @@ impl<'a> WindowHelpers for &'a Window { } fn set_page_clip_rect_with_new_viewport(self, viewport: Rect) -> bool { + let rect = geometry::f32_rect_to_au_rect(viewport.clone()); + self.current_scroll_position.set(rect); // We use a clipping rectangle that is five times the size of the of the viewport, // so that we don't collect display list items for areas too far outside the viewport, // but also don't trigger reflows every time the viewport changes. static VIEWPORT_EXPANSION: f32 = 2.0; // 2 lengths on each side plus original length is 5 total. - let proposed_clip_rect = geometry::f32_rect_to_au_rect( - viewport.inflate(viewport.size.width * VIEWPORT_EXPANSION, - viewport.size.height * VIEWPORT_EXPANSION)); - let clip_rect = self.page_clip_rect.get(); - if proposed_clip_rect == clip_rect { - return false; - } + let proposed_clip_rect = geometry::f32_rect_to_au_rect( + viewport.inflate(viewport.size.width * VIEWPORT_EXPANSION, + viewport.size.height * VIEWPORT_EXPANSION)); + let clip_rect = self.page_clip_rect.get(); + if proposed_clip_rect == clip_rect { + return false; + } - let had_clip_rect = clip_rect != MAX_RECT; - if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) { - return false; - } + let had_clip_rect = clip_rect != MAX_RECT; + if had_clip_rect && !should_move_clip_rect(clip_rect, viewport) { + return false; + } - self.page_clip_rect.set(proposed_clip_rect); + self.page_clip_rect.set(proposed_clip_rect); - // If we didn't have a clip rect, the previous display doesn't need rebuilding - // because it was built for infinite clip (MAX_RECT). - had_clip_rect + // If we didn't have a clip rect, the previous display doesn't need rebuilding + // because it was built for infinite clip (MAX_RECT). + had_clip_rect } fn set_devtools_wants_updates(self, value: bool) { @@ -1091,6 +1293,7 @@ impl Window { layout_rpc: layout_rpc, layout_join_port: DOMRefCell::new(None), window_size: Cell::new(window_size), + current_scroll_position: Cell::new(Rect::zero()), pending_reflow_count: Cell::new(0), current_state: Cell::new(WindowState::Alive), diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 279ff364bda5..39d9b4d7cd6b 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -205,6 +205,8 @@ pub enum ScriptMsg { /// Requests that the script task measure its memory usage. The results are sent back via the /// supplied channel. CollectReports(ReportsChan), + + ScrollPoint(PipelineId, Point2D) } /// A cloneable interface for communicating with an event loop. @@ -838,6 +840,8 @@ impl ScriptTask { self.handle_loads_complete(id), ScriptMsg::CollectReports(reports_chan) => self.collect_reports(reports_chan), + ScriptMsg::ScrollPoint(id, point) => + self.handle_scroll_point(id, point), } } @@ -1490,6 +1494,10 @@ impl ScriptTask { } } + fn handle_scroll_point(&self, id: PipelineId, point: Point2D) { + self.compositor.borrow_mut().scroll_fragment_point(id, LayerId::null(), point); + } + fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &Element) { let node = NodeCast::from_ref(node); let rect = node.get_bounding_content_box(); diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 0a65da35a86d..f0c48855e178 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -19,6 +19,8 @@ use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; +use euclid::point::Point2D; +use euclid::rect::Rect; use gleam::gl; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; @@ -144,16 +146,16 @@ impl Window { Cursor::TextCursor => msg_send![class("NSCursor"), IBeamCursor], Cursor::GrabCursor | Cursor::AllScrollCursor => msg_send![class("NSCursor"), openHandCursor], - Cursor::NoDropCursor | Cursor::NotAllowedCursor => + Cursor::NoDropCursor | Cursor::NotAllowedCursor => msg_send![class("NSCursor"), operationNotAllowedCursor], Cursor::PointerCursor => msg_send![class("NSCursor"), pointingHandCursor], Cursor::SResizeCursor => msg_send![class("NSCursor"), resizeDownCursor], Cursor::WResizeCursor => msg_send![class("NSCursor"), resizeLeftCursor], - Cursor::EwResizeCursor | Cursor::ColResizeCursor => + Cursor::EwResizeCursor | Cursor::ColResizeCursor => msg_send![class("NSCursor"), resizeLeftRightCursor], Cursor::EResizeCursor => msg_send![class("NSCursor"), resizeRightCursor], Cursor::NResizeCursor => msg_send![class("NSCursor"), resizeUpCursor], - Cursor::NsResizeCursor | Cursor::RowResizeCursor => + Cursor::NsResizeCursor | Cursor::RowResizeCursor => msg_send![class("NSCursor"), resizeUpDownCursor], Cursor::VerticalTextCursor => msg_send![class("NSCursor"), IBeamCursorForVerticalLayout], _ => msg_send![class("NSCursor"), arrowCursor], @@ -220,6 +222,18 @@ impl WindowMethods for Window { } } + fn client_window(&self) -> Rect { + Rect::zero() + } + + fn set_inner_size(&self, size: Size2D) { + + } + + fn set_position(&self, point: Point2D) { + + } + fn present(&self) { let browser = self.cef_browser.borrow(); match *browser { diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 0e28d1abd855..fb352bfee93c 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -6,6 +6,7 @@ use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; +use euclid::rect::Rect; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; use gleam::gl; @@ -518,6 +519,22 @@ impl WindowMethods for Window { Size2D::typed(width as f32, height as f32) } + fn client_window(&self) -> Rect { + let (width, height) = self.window.get_outer_size().unwrap(); + let size = Size2D::new(width as i32, height as i32); + let (x,y) = self.window.get_position().unwrap(); + let origin = Point2D::new(x as i32,y as i32); + Rect::new(origin,size) + } + + fn set_inner_size(&self, size: Size2D) { + self.window.set_inner_size(size.width as u32, size.height as u32) + } + + fn set_position(&self, point: Point2D) { + self.window.set_position(point.x, point.y) + } + fn present(&self) { self.window.swap_buffers() } diff --git a/ports/gonk/src/window.rs b/ports/gonk/src/window.rs index 88ba3ceca96f..2c76c0620afc 100644 --- a/ports/gonk/src/window.rs +++ b/ports/gonk/src/window.rs @@ -8,6 +8,8 @@ use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; +use euclid::point::Point2D; +use euclid::rect::Rect; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; use libc::c_int; @@ -792,6 +794,18 @@ impl WindowMethods for Window { Size2D::typed(self.width as f32, self.height as f32) } + fn client_window(&self) -> Rect { + Rect::zero() + } + + fn set_inner_size(&self, size: Size2D) { + + } + + fn set_position(&self, point: Point2D) { + + } + /// Presents the window to the screen (perhaps by page flipping). fn present(&self) { let _ = egl::SwapBuffers(self.dpy, self.surf); @@ -872,4 +886,3 @@ impl CompositorProxy for GonkCompositorProxy { } as Box } } - diff --git a/tests/html/viewport.html b/tests/html/viewport.html new file mode 100644 index 000000000000..d091c9f5a962 --- /dev/null +++ b/tests/html/viewport.html @@ -0,0 +1,27 @@ + + + + Test innerHeight + + + + +
+ + + + diff --git a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini index 680491000819..e2a63b297569 100644 --- a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini +++ b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini @@ -377,4 +377,3 @@ [Window replaceable attribute: devicePixelRatio] expected: FAIL - From bb393cdc997a32ee8c7f70d1b4871ae6b7385919 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Tue, 4 Aug 2015 19:31:29 +0200 Subject: [PATCH 04/13] Merging conflict --- components/script/dom/window.rs | 102 ------------------------------- components/script/script_task.rs | 9 --- tests/html/viewport.html | 12 ---- 3 files changed, 123 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index c14707b052db..9824ef07ee03 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,12 +7,8 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::FunctionBinding::Function; -<<<<<<< HEAD -use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions, ScrollBehavior}; -======= use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions}; ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd use dom::bindings::codegen::InheritTypes::{NodeCast, EventTargetCast}; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; @@ -44,10 +40,6 @@ use script_task::ScriptMsg; use script_traits::ScriptControlChan; use timers::{IsInterval, TimerId, TimerManager, TimerCallback}; use webdriver_handlers::jsval_to_webdriver; -<<<<<<< HEAD -use core::ops::Deref; -======= ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; use devtools_traits::{TracingMetadata}; use msg::compositor_msg::{ScriptListener, LayerId}; @@ -578,83 +570,41 @@ impl<'a> WindowMethods for &'a Window { // https://drafts.csswg.org/cssom-view/#dom-window-innerheight //TODO Include Scrollbar -<<<<<<< HEAD - fn InnerHeight(self) -> Finite { - let size = self.window_size.get(); - match size { - Some(e) => { - let height = e.visible_viewport.height.get().to_f64().unwrap_or(0.0f64); - Finite::wrap(height) - } - None => Finite::wrap(0.0f64) -======= fn InnerHeight(self) -> i32 { let size = self.window_size.get(); match size { Some(e) => e.visible_viewport.height.get().to_i32().unwrap_or(0), None => 0 ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd } } // https://drafts.csswg.org/cssom-view/#dom-window-innerwidth //TODO Include Scrollbar -<<<<<<< HEAD - fn InnerWidth(self) -> Finite { - let size = self.window_size.get(); - match size { - Some(e) => { - let width = e.visible_viewport.width.get().to_f64().unwrap_or(0.0f64); - Finite::wrap(width) - } - None => Finite::wrap(0.0f64) -======= fn InnerWidth(self) -> i32 { let size = self.window_size.get(); match size { Some(e) => e.visible_viewport.width.get().to_i32().unwrap_or(0), None => 0 ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd } } // https://drafts.csswg.org/cssom-view/#dom-window-scrollx -<<<<<<< HEAD - fn ScrollX(self) -> Finite { - let origin = self.current_scroll_position.get().origin; - Finite::wrap(origin.x.to_f64_px()) - } - - // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset - fn PageXOffset(self) -> Finite { -======= fn ScrollX(self) -> i32 { self.current_scroll_position.get().origin.x.to_px() } // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset fn PageXOffset(self) -> i32{ ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd self.ScrollX() } // https://drafts.csswg.org/cssom-view/#dom-window-scrolly -<<<<<<< HEAD - fn ScrollY(self) -> Finite { - let origin = self.current_scroll_position.get().origin; - Finite::wrap(origin.y.to_f64_px()) - } - - // https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset - fn PageYOffset(self) -> Finite { -======= fn ScrollY(self) -> i32 { self.current_scroll_position.get().origin.y.to_px() } // https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset fn PageYOffset(self) -> i32 { ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd self.ScrollY() } @@ -668,29 +618,12 @@ impl<'a> WindowMethods for &'a Window { } // https://drafts.csswg.org/cssom-view/#dom-window-scroll -<<<<<<< HEAD - fn Scroll_(self, x: f64, y: f64, options: &ScrollOptions) { - println!("test"); -======= fn Scroll_(self, x: f64, y: f64, _: &ScrollOptions) { ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd // Step 4 if self.window_size.get().is_none() { return; } -<<<<<<< HEAD - let width = (*self.ScrollX()); - let height = (*self.ScrollY()); - - let offsetx = width - x; - let offsety = height - y; - - println!("offsetx: {}, offsety: {}", offsetx, offsety); - let delta = Point2D::new(offsetx.to_f32().unwrap_or(0.0f32), offsety.to_f32().unwrap_or(0.0f32)); - //let script_chan = self.script_chan.clone(); - //script_chan.send(ScriptMsg::ScrollDelta(self.pipeline(), delta)).unwrap() -======= // Step 5 remove scrollbar width let width = self.InnerWidth() as f64; // Step 6 remove scrollbar height @@ -725,7 +658,6 @@ impl<'a> WindowMethods for &'a Window { // Step 12 Perform Scroll let point = Point2D::new(rangedx.to_f32().unwrap_or(0.0f32), rangedy.to_f32().unwrap_or(0.0f32)); self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd } // https://drafts.csswg.org/cssom-view/#dom-window-scrollto @@ -749,45 +681,14 @@ impl<'a> WindowMethods for &'a Window { // https://drafts.csswg.org/cssom-view/#dom-window-scrollby fn ScrollBy_(self, x: f64, y: f64, options: &ScrollOptions) { // Step 3 -<<<<<<< HEAD - let left = x + self.ScrollX().deref(); - // Step 4 - let top = y + self.ScrollY().deref(); -======= let left = x + self.ScrollX() as f64; // Step 4 let top = y + self.ScrollY() as f64; ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd // Step 5 self.Scroll_(left, top, options); } -<<<<<<< HEAD - //fn ResizeTo(self, x: Finite, y: Finite) { - // // Step 1 - //} - - // https://drafts.csswg.org/cssom-view/#dom-window-screenx - //fn ScreenX(self) -> Finite { - // Finite::wrap(0.0f64) - //} - - // https://drafts.csswg.org/cssom-view/#dom-window-screeny - //fn ScreenY(self) -> Finite { - // Finite::wrap(0.0f64) - //} - - // https://drafts.csswg.org/cssom-view/#dom-window-outerwidth - //fn OuterHeight(self) -> Finite { - // Finite::wrap(0.0f64) - //} - - // https://drafts.csswg.org/cssom-view/#dom-window-outerheight - //fn OuterWidth(self) -> Finite { - // Finite::wrap(0.0f64) - //} -======= // https://drafts.csswg.org/cssom-view/#dom-window-resizeto fn ResizeTo(self, x: i32, y: i32) { // Step 1 @@ -844,9 +745,6 @@ impl<'a> WindowMethods for &'a Window { fn DevicePixelRatio(self) -> Finite { Finite::wrap(0.0f64) } ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd - - } pub trait WindowHelpers { diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 26920fe5e629..652eb63de04e 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -840,20 +840,11 @@ impl ScriptTask { self.handle_loads_complete(id), ScriptMsg::CollectReports(reports_chan) => self.collect_reports(reports_chan), -<<<<<<< HEAD - ScriptMsg::ScrollDelta(id, delta) => - self.handle_scroll_delta(id, delta), -======= ScriptMsg::ScrollPoint(id, point) => self.handle_scroll_point(id, point), ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd } } - fn handle_scroll_delta(&self, id: PipelineId, delta: Point2D) { - self.compositor.borrow_mut().scroll_delta(id, LayerId::null(), delta); - } - fn handle_msg_from_devtools(&self, msg: DevtoolScriptControlMsg) { let page = self.root_page(); match msg { diff --git a/tests/html/viewport.html b/tests/html/viewport.html index 8be635dcf14d..d091c9f5a962 100644 --- a/tests/html/viewport.html +++ b/tests/html/viewport.html @@ -8,11 +8,6 @@ console.log("innerWidth: "+ window.innerWidth); console.log("ScrollY: "+ window.scrollY); console.log("ScrollX: "+ window.scrollX); -<<<<<<< HEAD - } - function scroll(){ - window.scroll(0,0); -======= console.log("outerHeight: "+ window.outerHeight); console.log("outerWidth: "+ window.outerWidth); console.log("screenY: "+ window.screenY); @@ -20,20 +15,13 @@ } function test_scroll(){ window.scroll(0,100); ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd } -<<<<<<< HEAD - -
- -=======
->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd From 4557a5da6ae66bdb475ca8eb79be0a609ef57101 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Tue, 4 Aug 2015 19:33:13 +0200 Subject: [PATCH 05/13] Merging conflict 2 --- .../the-window-object/window-properties.html.ini | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini index 8e3e65c87627..e2a63b297569 100644 --- a/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini +++ b/tests/wpt/metadata/html/browsers/the-window-object/window-properties.html.ini @@ -57,6 +57,15 @@ [Window method: matchMedia] expected: FAIL + [Window method: scroll] + expected: FAIL + + [Window method: scrollTo] + expected: FAIL + + [Window method: scrollBy] + expected: FAIL + [Window readonly attribute: history] expected: FAIL From a5944c77865c4a65baa12f450632f06cc188f745 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Tue, 4 Aug 2015 20:20:10 +0200 Subject: [PATCH 06/13] last Conflict --- components/compositing/compositor.rs | 6 +----- components/script/dom/webidls/Window.webidl | 11 ----------- components/script/script_task.rs | 1 - 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 12f990bd54e6..9032e76068d1 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -417,7 +417,7 @@ impl IOCompositor { ShutdownState::NotShuttingDown) => { self.scroll_fragment_to_point(pipeline_id, layer_id, point); } - + (Msg::MoveTo(point), ShutdownState::NotShuttingDown) => { self.window.set_position(point); @@ -890,10 +890,6 @@ impl IOCompositor { } } - fn scroll_delta(&mut self, id: PipelineId, layer: LayerId, delta: Point2D) { - println!("test"); - } - fn handle_window_message(&mut self, event: WindowEvent) { match event { WindowEvent::Idle => {} diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 8fe24bd587b3..caca210be682 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -123,16 +123,6 @@ partial interface Window { void resizeBy(long x, long y); // viewport -<<<<<<< HEAD - readonly attribute double innerWidth; - readonly attribute double innerHeight; - - // viewport scrolling - readonly attribute double scrollX; - readonly attribute double pageXOffset; - readonly attribute double scrollY; - readonly attribute double pageYOffset; -======= readonly attribute long innerWidth; readonly attribute long innerHeight; @@ -141,7 +131,6 @@ partial interface Window { readonly attribute long pageXOffset; readonly attribute long scrollY; readonly attribute long pageYOffset; ->>>>>>> 43d6d5e76f8713ba9f2cb2ade7cdb703ab3416cd void scroll(optional ScrollToOptions options); void scroll(unrestricted double x, unrestricted double y, optional ScrollOptions options); void scrollTo(optional ScrollToOptions options); diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 8f2d7ffa3765..e808cb5ad1d6 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -23,7 +23,6 @@ use document_loader::{LoadType, DocumentLoader, NotifierData}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; -use dom::bindings::codegen::Bindings::WindowBinding::ScrollOptions; use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast, EventCast}; use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::StringificationBehavior; From 6dabb5dfc63adb0971aaaf907c2f9d018747a47a Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 7 Aug 2015 12:36:00 +0200 Subject: [PATCH 07/13] review changes --- components/compositing/compositor.rs | 14 +- components/compositing/compositor_task.rs | 11 +- components/compositing/headless.rs | 7 +- components/compositing/windowing.rs | 16 +- components/msg/compositor_msg.rs | 12 +- components/script/dom/webidls/Window.webidl | 6 +- components/script/dom/window.rs | 175 +++++++++++--------- components/script/script_task.rs | 7 - ports/cef/window.rs | 13 +- ports/glutin/window.rs | 14 +- ports/gonk/src/window.rs | 13 +- 11 files changed, 152 insertions(+), 136 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 9032e76068d1..39d9076dac23 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -11,11 +11,11 @@ use scrolling::ScrollingTimerProxy; use windowing; use windowing::{MouseWindowEvent, WindowEvent, WindowMethods, WindowNavigateMsg}; -use euclid::Matrix4; -use euclid::point::{Point2D, TypedPoint2D}; -use euclid::rect::{Rect, TypedRect}; +use euclid::{Size2D, Point2D, Rect, Matrix4}; +use euclid::point::TypedPoint2D; +use euclid::rect::TypedRect; use euclid::scale_factor::ScaleFactor; -use euclid::size::{Size2D, TypedSize2D}; +use euclid::size::TypedSize2D; use gfx_traits::color; use gfx::paint_task::{ChromeToPaintMsg, PaintRequest}; use gleam::gl::types::{GLint, GLsizei}; @@ -388,7 +388,8 @@ impl IOCompositor { 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(); } @@ -428,7 +429,8 @@ impl IOCompositor { self.window.set_inner_size(size); } - (Msg::GetClientWindow(send), ShutdownState::NotShuttingDown) => { + (Msg::GetClientWindow(send), + ShutdownState::NotShuttingDown) => { let rect = self.window.client_window(); send.send(rect).unwrap(); } diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 59ceedb70788..28b6dfcfae48 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -11,9 +11,7 @@ use compositor; use headless; use windowing::{WindowEvent, WindowMethods}; -use euclid::point::Point2D; -use euclid::size::Size2D; -use euclid::rect::Rect; +use euclid::{Size2D, Point2D, Rect}; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use layers::platform::surface::{NativeDisplay, NativeSurface}; use layers::layers::{BufferRequest, LayerBufferSet}; @@ -214,9 +212,12 @@ pub enum Msg { CollectMemoryReports(mem::ReportsChan), /// A status message to be displayed by the browser chrome. Status(Option), - GetClientWindow(IpcSender>), + /// Get Window Informations size and position + GetClientWindow(IpcSender<(Size2D, Point2D)>), + /// Move the window to a point MoveTo(Point2D), - ResizeTo(Size2D), + /// Resize the window to size + ResizeTo(Size2D), } impl Debug for Msg { diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index ff173a5d98d8..509c2802a0b0 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -5,8 +5,8 @@ use compositor_task::{CompositorEventListener, CompositorReceiver, Msg}; use windowing::WindowEvent; +use euclid::{Size2D, Point2D}; use euclid::scale_factor::ScaleFactor; -use euclid::size::Size2D; use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, WindowSizeData}; use profile_traits::mem; @@ -88,6 +88,10 @@ impl CompositorEventListener for NullCompositor { response_chan.send(()).unwrap(); } + Msg::GetClientWindow(send) => { + let rect = (Size2D::zero(), Point2D::zero()); + send.send(rect).unwrap(); + } // Explicitly list ignored messages so that when we add a new one, // we'll notice and think about whether it needs a response, like // SetFrameTree. @@ -109,7 +113,6 @@ impl CompositorEventListener for NullCompositor { Msg::ViewportConstrained(..) => {} Msg::CreatePng(..) | Msg::PaintTaskExited(..) | - Msg::GetClientWindow(..) | Msg::MoveTo(..) | Msg::ResizeTo(..) | Msg::IsReadyToSaveImageReply(..) => {} diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 67609719ce6b..5efddfb6eaa3 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -6,10 +6,10 @@ use compositor_task::{CompositorProxy, CompositorReceiver}; -use euclid::rect::Rect; -use euclid::point::{TypedPoint2D, Point2D}; +use euclid::{Size2D, Point2D}; +use euclid::point::TypedPoint2D; use euclid::scale_factor::ScaleFactor; -use euclid::size::{TypedSize2D, Size2D}; +use euclid::size::TypedSize2D; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; use msg::constellation_msg::{Key, KeyState, KeyModifiers}; @@ -104,11 +104,11 @@ pub trait WindowMethods { /// Presents the window to the screen (perhaps by page flipping). fn present(&self); - /// Return outersize and position values - fn client_window(&self) -> Rect; - - fn set_inner_size(&self, size: Size2D); - + /// Return the size of the window with head and borders and position of the window values + fn client_window(&self) -> (Size2D, Point2D); + /// Set the size inside of borders and head + fn set_inner_size(&self, size: Size2D); + /// Set the window position fn set_position(&self, point: Point2D); /// Sets the page title for the current page. diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index 595e975e4b5d..3c359a57d7c0 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -4,9 +4,7 @@ use azure::azure_hl::Color; use constellation_msg::{Key, KeyState, KeyModifiers}; -use euclid::point::Point2D; -use euclid::size::Size2D; -use euclid::rect::Rect; +use euclid::{Size2D, Point2D, Rect}; use euclid::Matrix4; use ipc_channel::ipc::IpcSender; use layers::platform::surface::NativeDisplay; @@ -122,9 +120,9 @@ pub enum ScriptToCompositorMsg { ScrollFragmentPoint(PipelineId, LayerId, Point2D), SetTitle(PipelineId, Option), SendKeyEvent(Key, KeyState, KeyModifiers), - GetClientWindow(IpcSender>), + GetClientWindow(IpcSender<(Size2D, Point2D)>), MoveTo(Point2D), - ResizeTo(Size2D), + ResizeTo(Size2D), Exit, } @@ -147,7 +145,7 @@ impl ScriptListener { .unwrap() } - pub fn client_window(&mut self, send: IpcSender>) { + pub fn client_window(&mut self, send: IpcSender<(Size2D, Point2D)>) { self.0.send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap() } @@ -155,7 +153,7 @@ impl ScriptListener { self.0.send(ScriptToCompositorMsg::MoveTo(point)).unwrap() } - pub fn resize_window(&mut self, size: Size2D) { + pub fn resize_window(&mut self, size: Size2D) { self.0.send(ScriptToCompositorMsg::ResizeTo(size)).unwrap() } diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index caca210be682..7a6c1d7a9889 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -132,11 +132,11 @@ partial interface Window { readonly attribute long scrollY; readonly attribute long pageYOffset; void scroll(optional ScrollToOptions options); - void scroll(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scroll(unrestricted double x, unrestricted double y); void scrollTo(optional ScrollToOptions options); - void scrollTo(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scrollTo(unrestricted double x, unrestricted double y); void scrollBy(optional ScrollToOptions options); - void scrollBy(unrestricted double x, unrestricted double y, optional ScrollOptions options); + void scrollBy(unrestricted double x, unrestricted double y); // client readonly attribute long screenX; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 66109a6e2a0f..28b2e03cfe30 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,8 +7,8 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::FunctionBinding::Function; -use dom::bindings::codegen::Bindings::WindowBinding::{self, - WindowMethods, FrameRequestCallback, ScrollOptions, ScrollToOptions}; +use dom::bindings::codegen::Bindings::WindowBinding::{self, WindowMethods, FrameRequestCallback}; +use dom::bindings::codegen::Bindings::WindowBinding::{ScrollToOptions, ScrollBehavior}; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, EventTargetCast, WindowDerived}; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; @@ -56,6 +56,7 @@ use util::{breakpoint, opts}; use util::str::{DOMString,HTML_SPACE_CHARACTERS}; use euclid::{Point2D, Rect, Size2D}; +use euclid::scale_factor::ScaleFactor; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{Evaluate2, MutableHandleValue}; use js::jsapi::{JSContext, HandleValue}; @@ -220,7 +221,7 @@ pub struct Window { /// The current state of the window object current_state: Cell, - current_scroll_position: Cell> + current_viewport: Cell> } impl Window { @@ -612,7 +613,7 @@ impl<'a> WindowMethods for &'a Window { // https://drafts.csswg.org/cssom-view/#dom-window-scrollx fn ScrollX(self) -> i32 { - self.current_scroll_position.get().origin.x.to_px() + self.current_viewport.get().origin.x.to_px() } // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset @@ -622,7 +623,7 @@ impl<'a> WindowMethods for &'a Window { // https://drafts.csswg.org/cssom-view/#dom-window-scrolly fn ScrollY(self) -> i32 { - self.current_scroll_position.get().origin.y.to_px() + self.current_viewport.get().origin.y.to_px() } // https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset @@ -635,51 +636,13 @@ impl<'a> WindowMethods for &'a Window { // Step 1 let left = options.left.unwrap_or(0.0f64); let top = options.top.unwrap_or(0.0f64); - self.Scroll_(left, top, &options.parent); + self.scroll(left, top, options.parent.behavior); } // https://drafts.csswg.org/cssom-view/#dom-window-scroll - fn Scroll_(self, x: f64, y: f64, _: &ScrollOptions) { - // Step 4 - if self.window_size.get().is_none() { - return; - } - - // Step 5 remove scrollbar width - let width = self.InnerWidth() as f64; - // Step 6 remove scrollbar height - let height = self.InnerHeight() as f64; - - // Step 7 & 8 - // TODO use overflow direction - let body = self.Document().GetBody(); - let (rangedx,rangedy) = match body { - Some(e) => { - let node = NodeCast::from_ref(e.r()); - let content_size = node.get_bounding_content_box(); - - let content_height = content_size.size.height.to_f64_px(); - let content_width = content_size.size.width.to_f64_px(); - (x.max(0.0f64).min(content_width - width), - y.max(0.0f64).min(content_height - height)) - }, - None => { - (x.max(0.0f64), y.max(0.0f64)) - } - }; - - // Step 10 - // TODO handling ongoing smoth scrolling - if rangedx == self.ScrollX() as f64 && rangedy == self.ScrollX() as f64 { - return; - } - - // TODO Step 11 - - // Step 12 Perform Scroll - let point = Point2D::new(rangedx.to_f32().unwrap_or(0.0f32), rangedy.to_f32().unwrap_or(0.0f32)); - self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) + fn Scroll_(self, x: f64, y: f64) { + self.scroll(x, y, ScrollBehavior::Auto); } // https://drafts.csswg.org/cssom-view/#dom-window-scrollto @@ -688,8 +651,8 @@ impl<'a> WindowMethods for &'a Window { } // https://drafts.csswg.org/cssom-view/#dom-window-scrollto - fn ScrollTo_(self, x: f64, y: f64, options: &ScrollOptions) { - self.Scroll_(x, y, options); + fn ScrollTo_(self, x: f64, y: f64) { + self.scroll(x, y, ScrollBehavior::Auto); } // https://drafts.csswg.org/cssom-view/#dom-window-scrollby @@ -697,79 +660,86 @@ impl<'a> WindowMethods for &'a Window { // Step 1 let x = options.left.unwrap_or(0.0f64); let y = options.top.unwrap_or(0.0f64); - self.ScrollBy_(x, y, &options.parent); + self.ScrollBy_(x, y, ); + self.scroll(x, y, options.parent.behavior); } // https://drafts.csswg.org/cssom-view/#dom-window-scrollby - fn ScrollBy_(self, x: f64, y: f64, options: &ScrollOptions) { + fn ScrollBy_(self, x: f64, y: f64) { // Step 3 let left = x + self.ScrollX() as f64; // Step 4 let top = y + self.ScrollY() as f64; // Step 5 - self.Scroll_(left, top, options); + self.scroll(left, top, ScrollBehavior::Auto); } // https://drafts.csswg.org/cssom-view/#dom-window-resizeto fn ResizeTo(self, x: i32, y: i32) { // Step 1 - let size = Size2D::new(x,y); + //TODO determine if this operation is allowed + let size = Size2D::new(x.to_u32().unwrap_or(1), y.to_u32().unwrap_or(1)); self.compositor.borrow_mut().resize_window(size) } // https://drafts.csswg.org/cssom-view/#dom-window-resizeby fn ResizeBy(self, x: i32, y: i32) { - let client = self.client_window(); + let (size, _) = self.client_window(); // Step 1 - self.MoveTo(x + client.size.width, y + client.size.height) + self.ResizeTo(x + size.width.to_i32().unwrap_or(1), y + size.height.to_i32().unwrap_or(1)) } // https://drafts.csswg.org/cssom-view/#dom-window-moveto fn MoveTo(self, x: i32, y: i32) { // Step 1 + //TODO determine if this operation is allowed let point = Point2D::new(x,y); self.compositor.borrow_mut().move_window(point) } // https://drafts.csswg.org/cssom-view/#dom-window-moveby fn MoveBy(self, x: i32, y: i32) { - let client = self.client_window(); + let (_, origin) = self.client_window(); // Step 1 - self.MoveTo(x + client.origin.x, y + client.origin.y) + self.MoveTo(x + origin.x, y + origin.y) } // https://drafts.csswg.org/cssom-view/#dom-window-screenx fn ScreenX(self) -> i32 { - let client = self.client_window(); - client.origin.x + let (_, origin) = self.client_window(); + origin.x } // https://drafts.csswg.org/cssom-view/#dom-window-screeny fn ScreenY(self) -> i32 { - let client = self.client_window(); - client.origin.y + let (_, origin) = self.client_window(); + origin.y } // https://drafts.csswg.org/cssom-view/#dom-window-outerheight fn OuterHeight(self) -> i32 { - let client = self.client_window(); - client.size.height + let (size, _) = self.client_window(); + size.height.to_i32().unwrap_or(1) } // https://drafts.csswg.org/cssom-view/#dom-window-outerwidth fn OuterWidth(self) -> i32 { - let client = self.client_window(); - client.size.width + let (size, _) = self.client_window(); + size.width.to_i32().unwrap_or(1) } // https://drafts.csswg.org/cssom-view/#dom-window-devicepixelratio fn DevicePixelRatio(self) -> Finite { - Finite::wrap(0.0f64) + let dpr = self.window_size.get() + .map(|data| data.device_pixel_ratio).unwrap_or(ScaleFactor::new(1.0f32)).get(); + Finite::wrap(dpr.to_f64().unwrap_or(1.0f64)) } } pub trait WindowHelpers { + fn scroll(self, x_: f64, y_: f64, behavior: ScrollBehavior); + fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior); fn clear_js_runtime(self); fn init_browsing_context(self, doc: &Document, frame_element: Option<&Element>); fn load_url(self, href: DOMString); @@ -789,7 +759,7 @@ pub trait WindowHelpers { fn steal_fragment_name(self) -> Option; fn set_window_size(self, size: WindowSizeData); fn window_size(self) -> Option; - fn client_window(self) -> Rect; + fn client_window(self) -> (Size2D, Point2D); fn get_url(self) -> Url; fn resource_task(self) -> ResourceTask; fn mem_profiler_chan(self) -> mem::ProfilerChan; @@ -876,6 +846,59 @@ impl<'a> WindowHelpers for &'a Window { *self.js_runtime.borrow_mut() = None; *self.browsing_context.borrow_mut() = None; } + // https://drafts.csswg.org/cssom-view/#dom-window-scroll + fn scroll(self, x_: f64, y_: f64, behavior: ScrollBehavior) { + // Step 4 + if self.window_size.get().is_none() { + return; + } + + // Step 5 + //TODO remove scrollbar width + let width = self.InnerWidth() as f64; + // Step 6 + //TODO remove scrollbar width + let height = self.InnerHeight() as f64; + + // Step 7 & 8 + // TODO use overflow direction + let body = self.Document().GetBody(); + let (x, y) = match body { + Some(e) => { + let node = NodeCast::from_ref(e.r()); + let content_size = node.get_bounding_content_box(); + + let content_height = content_size.size.height.to_f64_px(); + let content_width = content_size.size.width.to_f64_px(); + (x_.max(0.0f64).min(content_width - width), + y_.max(0.0f64).min(content_height - height)) + }, + None => { + (x_.max(0.0f64), y_.max(0.0f64)) + } + }; + + // Step 10 + // TODO handling ongoing smoth scrolling + if x == self.ScrollX() as f64 && y == self.ScrollX() as f64 { + return; + } + + // TODO Step 11 + let document = self.Document(); + // Step 12 + let root = document.r().GetDocumentElement(); + let root = match root.r() { + Some(..) |, + None => return + }; + self.perform_a_scroll(x.to_f32().unwrap_or(0.0f32), y.to_f32().unwrap_or(0.0f32), behavior); + } + + fn perform_a_scroll(self, x: f32, y: f32, _: ScrollBehavior) { + let point = Point2D::new(x, y); + self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) + } /// Reflows the page unconditionally. This method will wait for the layout thread to complete /// (but see the `TODO` below). If there is no window size yet, the page is presumed invisible @@ -994,18 +1017,10 @@ impl<'a> WindowHelpers for &'a Window { } } - fn client_window(self) -> Rect { - let channel = ipc::channel::>(); - match channel { - Ok((send,recv)) => { - self.compositor.borrow_mut().client_window(send); - recv.recv().unwrap_or(Rect::zero()) - } - Err(_) =>{ - Rect::zero() - } - } - + fn client_window(self) -> (Size2D, Point2D) { + let (send,recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); + self.compositor.borrow_mut().client_window(send); + recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) } fn layout(&self) -> &LayoutRPC { @@ -1180,7 +1195,7 @@ impl<'a> WindowHelpers for &'a Window { fn set_page_clip_rect_with_new_viewport(self, viewport: Rect) -> bool { let rect = geometry::f32_rect_to_au_rect(viewport.clone()); - self.current_scroll_position.set(rect); + self.current_viewport.set(rect); // We use a clipping rectangle that is five times the size of the of the viewport, // so that we don't collect display list items for areas too far outside the viewport, // but also don't trigger reflows every time the viewport changes. @@ -1335,7 +1350,7 @@ impl Window { layout_rpc: layout_rpc, layout_join_port: DOMRefCell::new(None), window_size: Cell::new(window_size), - current_scroll_position: Cell::new(Rect::zero()), + current_viewport: Cell::new(Rect::zero()), pending_reflow_count: Cell::new(0), current_state: Cell::new(WindowState::Alive), diff --git a/components/script/script_task.rs b/components/script/script_task.rs index e808cb5ad1d6..b3ea5b168181 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -206,7 +206,6 @@ pub enum ScriptMsg { /// Requests that the script task measure its memory usage. The results are sent back via the /// supplied channel. CollectReports(ReportsChan), - ScrollPoint(PipelineId, Point2D) } /// A cloneable interface for communicating with an event loop. @@ -840,8 +839,6 @@ impl ScriptTask { self.handle_loads_complete(id), ScriptMsg::CollectReports(reports_chan) => self.collect_reports(reports_chan), - ScriptMsg::ScrollPoint(id, point) => - self.handle_scroll_point(id, point), } } @@ -1511,10 +1508,6 @@ impl ScriptTask { } } - fn handle_scroll_point(&self, id: PipelineId, point: Point2D) { - self.compositor.borrow_mut().scroll_fragment_point(id, LayerId::null(), point); - } - fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &Element) { let node = NodeCast::from_ref(node); let rect = node.get_bounding_content_box(); diff --git a/ports/cef/window.rs b/ports/cef/window.rs index f0c48855e178..8f82386cdfda 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -17,10 +17,10 @@ use wrappers::CefWrap; use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; -use euclid::scale_factor::ScaleFactor; -use euclid::size::{Size2D, TypedSize2D}; use euclid::point::Point2D; use euclid::rect::Rect; +use euclid::scale_factor::ScaleFactor; +use euclid::size::{Size2D, TypedSize2D}; use gleam::gl; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; @@ -222,11 +222,14 @@ impl WindowMethods for Window { } } - fn client_window(&self) -> Rect { - Rect::zero() + fn client_window(&self) -> (Size2D, Point2D) { + let size = self.size().to_untyped(); + let width = size.width as u32; + let height = size.height as u32; + (Size2D::new(width, height), Point2D::zero()) } - fn set_inner_size(&self, size: Size2D) { + fn set_inner_size(&self, size: Size2D) { } diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index fb352bfee93c..75e08dd4c41a 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -6,9 +6,9 @@ use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; -use euclid::rect::Rect; +use euclid::{Size2D, Point2D}; use euclid::scale_factor::ScaleFactor; -use euclid::size::{Size2D, TypedSize2D}; +use euclid::size::TypedSize2D; use gleam::gl; use glutin; use layers::geometry::DevicePixel; @@ -27,8 +27,6 @@ use NestedEventLoopListener; #[cfg(feature = "window")] use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg}; #[cfg(feature = "window")] -use euclid::point::Point2D; -#[cfg(feature = "window")] use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode, MouseScrollDelta}; #[cfg(feature = "window")] use msg::constellation_msg::{KeyState, NONE, CONTROL, SHIFT, ALT, SUPER}; @@ -519,15 +517,15 @@ impl WindowMethods for Window { Size2D::typed(width as f32, height as f32) } - fn client_window(&self) -> Rect { + fn client_window(&self) -> (Size2D, Point2D) { let (width, height) = self.window.get_outer_size().unwrap(); - let size = Size2D::new(width as i32, height as i32); + let size = Size2D::new(width as u32, height as u32); let (x,y) = self.window.get_position().unwrap(); let origin = Point2D::new(x as i32,y as i32); - Rect::new(origin,size) + (size,origin) } - fn set_inner_size(&self, size: Size2D) { + fn set_inner_size(&self, size: Size2D) { self.window.set_inner_size(size.width as u32, size.height as u32) } diff --git a/ports/gonk/src/window.rs b/ports/gonk/src/window.rs index 2c76c0620afc..29e6d0a741e5 100644 --- a/ports/gonk/src/window.rs +++ b/ports/gonk/src/window.rs @@ -6,10 +6,10 @@ use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::windowing::{WindowEvent, WindowMethods}; -use euclid::scale_factor::ScaleFactor; -use euclid::size::{Size2D, TypedSize2D}; use euclid::point::Point2D; use euclid::rect::Rect; +use euclid::scale_factor::ScaleFactor; +use euclid::size::{Size2D, TypedSize2D}; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; use libc::c_int; @@ -794,11 +794,14 @@ impl WindowMethods for Window { Size2D::typed(self.width as f32, self.height as f32) } - fn client_window(&self) -> Rect { - Rect::zero() + fn client_window(&self) -> (Size2D, Point2D) { + let size = self.size().to_untyped(); + let width = size.width as u32; + let height = size.height as u32; + (Size2D::new(width, height), Point2D::zero()) } - fn set_inner_size(&self, size: Size2D) { + fn set_inner_size(&self, size: Size2D) { } From 225d2ee07d05527d80c4d25a9a1b53a92e6872b7 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 7 Aug 2015 12:57:21 +0200 Subject: [PATCH 08/13] current state --- components/script/dom/window.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 5b294d439caa..2ab9d3eb02ae 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -851,7 +851,7 @@ impl<'a> WindowHelpers for &'a Window { *self.js_runtime.borrow_mut() = None; *self.browsing_context.borrow_mut() = None; } - // https://drafts.csswg.org/cssom-view/#dom-window-scroll + /// https://drafts.csswg.org/cssom-view/#dom-window-scroll fn scroll(self, x_: f64, y_: f64, behavior: ScrollBehavior) { // Step 4 if self.window_size.get().is_none() { @@ -866,7 +866,7 @@ impl<'a> WindowHelpers for &'a Window { let height = self.InnerHeight() as f64; // Step 7 & 8 - // TODO use overflow direction + //TODO use overflow direction let body = self.Document().GetBody(); let (x, y) = match body { Some(e) => { @@ -884,23 +884,20 @@ impl<'a> WindowHelpers for &'a Window { }; // Step 10 - // TODO handling ongoing smoth scrolling + //TODO handling ongoing smoth scrolling if x == self.ScrollX() as f64 && y == self.ScrollX() as f64 { return; } - // TODO Step 11 - let document = self.Document(); + //TODO Step 11 + //let document = self.Document(); // Step 12 - let root = document.r().GetDocumentElement(); - let root = match root.r() { - Some(..) |, - None => return - }; self.perform_a_scroll(x.to_f32().unwrap_or(0.0f32), y.to_f32().unwrap_or(0.0f32), behavior); } + /// https://drafts.csswg.org/cssom-view/#perform-a-scroll fn perform_a_scroll(self, x: f32, y: f32, _: ScrollBehavior) { + //TODO Step 1 let point = Point2D::new(x, y); self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) } From cc7fc18722fbd2a474a954da9e0473549c510f40 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Sun, 9 Aug 2015 14:46:40 +0200 Subject: [PATCH 09/13] most changes to the last review --- components/script/dom/window.rs | 15 ++++++++++----- ports/cef/window.rs | 1 + ports/glutin/window.rs | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 2ab9d3eb02ae..bdda1dcbdac2 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -738,7 +738,7 @@ impl<'a> WindowMethods for &'a Window { fn DevicePixelRatio(self) -> Finite { let dpr = self.window_size.get() .map(|data| data.device_pixel_ratio).unwrap_or(ScaleFactor::new(1.0f32)).get(); - Finite::wrap(dpr.to_f64().unwrap_or(1.0f64)) + Finite::wrap(dpr as f64) } } @@ -851,8 +851,13 @@ impl<'a> WindowHelpers for &'a Window { *self.js_runtime.borrow_mut() = None; *self.browsing_context.borrow_mut() = None; } + /// https://drafts.csswg.org/cssom-view/#dom-window-scroll fn scroll(self, x_: f64, y_: f64, behavior: ScrollBehavior) { + // Step 3 + let xfinite = if x_.is_finite() { x_ } else { 0.0f64 }; + let yfinite = if y_.is_finite() { y_ } else { 0.0f64 }; + // Step 4 if self.window_size.get().is_none() { return; @@ -875,17 +880,17 @@ impl<'a> WindowHelpers for &'a Window { let content_height = content_size.size.height.to_f64_px(); let content_width = content_size.size.width.to_f64_px(); - (x_.max(0.0f64).min(content_width - width), - y_.max(0.0f64).min(content_height - height)) + (xfinite.max(0.0f64).min(content_width - width), + yfinite.max(0.0f64).min(content_height - height)) }, None => { - (x_.max(0.0f64), y_.max(0.0f64)) + (xfinite.max(0.0f64), yfinite.max(0.0f64)) } }; // Step 10 //TODO handling ongoing smoth scrolling - if x == self.ScrollX() as f64 && y == self.ScrollX() as f64 { + if x == self.ScrollX() as f64 && y == self.ScrollY() as f64 { return; } diff --git a/ports/cef/window.rs b/ports/cef/window.rs index e1113739fe87..df3fe13a5006 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -226,6 +226,7 @@ impl WindowMethods for Window { let size = self.size().to_untyped(); let width = size.width as u32; let height = size.height as u32; + //TODO get real window position (Size2D::new(width, height), Point2D::zero()) } diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 74295dccf0e3..55392c6702c5 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -519,10 +519,10 @@ impl WindowMethods for Window { fn client_window(&self) -> (Size2D, Point2D) { let (width, height) = self.window.get_outer_size().unwrap(); - let size = Size2D::new(width as u32, height as u32); + let size = Size2D::new(width, height); let (x,y) = self.window.get_position().unwrap(); let origin = Point2D::new(x as i32,y as i32); - (size,origin) + (size, origin) } fn set_inner_size(&self, size: Size2D) { From 9a803396f92cfb2de6853f976fcf27bcbb427281 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Sun, 9 Aug 2015 15:32:43 +0200 Subject: [PATCH 10/13] init support of smooth --- components/msg/compositor_msg.rs | 3 ++- components/script/dom/window.rs | 9 +++++++-- components/script/script_task.rs | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index 3c359a57d7c0..ca7292004401 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -139,7 +139,8 @@ impl ScriptListener { pub fn scroll_fragment_point(&mut self, pipeline_id: PipelineId, layer_id: LayerId, - point: Point2D) { + point: Point2D, + _: bool) { self.0 .send(ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point)) .unwrap() diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d39dabd6fd45..ebee9280b6af 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -901,10 +901,15 @@ impl<'a> WindowHelpers for &'a Window { } /// https://drafts.csswg.org/cssom-view/#perform-a-scroll - fn perform_a_scroll(self, x: f32, y: f32, _: ScrollBehavior) { + fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior) { //TODO Step 1 let point = Point2D::new(x, y); - self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point) + let smooth = match behavior { + ScrollBehavior::Auto => false, + ScrollBehavior::Instant => false, + ScrollBehavior::Smooth => true + }; + self.compositor.borrow_mut().scroll_fragment_point(self.pipeline(), LayerId::null(), point, smooth) } /// Reflows the page unconditionally. This method will wait for the layout thread to complete diff --git a/components/script/script_task.rs b/components/script/script_task.rs index efbad39dc86f..0e7fdc90cb40 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -1559,7 +1559,7 @@ impl ScriptTask { // Really what needs to happen is that this needs to go through layout to ask which // layer the element belongs to, and have it send the scroll message to the // compositor. - self.compositor.borrow_mut().scroll_fragment_point(pipeline_id, LayerId::null(), point); + self.compositor.borrow_mut().scroll_fragment_point(pipeline_id, LayerId::null(), point, false); } /// Reflows non-incrementally, rebuilding the entire layout tree in the process. From c0e028e4048985e3601611aec02e05384c0b9569 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Fri, 14 Aug 2015 19:59:37 +0200 Subject: [PATCH 11/13] review changes --- components/msg/compositor_msg.rs | 2 +- components/script/dom/window.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index 822b06f9af6e..c62a40bfc899 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -142,7 +142,7 @@ impl ScriptListener { pipeline_id: PipelineId, layer_id: LayerId, point: Point2D, - _: bool) { + _smooth: bool) { self.0 .send(ScriptToCompositorMsg::ScrollFragmentPoint(pipeline_id, layer_id, point)) .unwrap() diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index b7ba365c8b52..41cd051d362f 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -740,7 +740,7 @@ impl<'a> WindowMethods for &'a Window { pub trait WindowHelpers { fn scroll(self, x_: f64, y_: f64, behavior: ScrollBehavior); - fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior); + fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior, element: Option<&Element>); fn clear_js_runtime(self); fn init_browsing_context(self, doc: &Document, frame_element: Option<&Element>); fn load_url(self, url: Url); @@ -893,15 +893,15 @@ impl<'a> WindowHelpers for &'a Window { //TODO Step 11 //let document = self.Document(); // Step 12 - self.perform_a_scroll(x.to_f32().unwrap_or(0.0f32), y.to_f32().unwrap_or(0.0f32), behavior); + self.perform_a_scroll(x.to_f32().unwrap_or(0.0f32), y.to_f32().unwrap_or(0.0f32), behavior, None); } /// https://drafts.csswg.org/cssom-view/#perform-a-scroll - fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior) { + fn perform_a_scroll(self, x: f32, y: f32, behavior: ScrollBehavior, _element: Option<&Element>) { //TODO Step 1 let point = Point2D::new(x, y); let smooth = match behavior { - ScrollBehavior::Auto => false, + ScrollBehavior::Auto => false, //TODO check css scroll behavior ScrollBehavior::Instant => false, ScrollBehavior::Smooth => true }; From 10597e25fea5a21e93b8e7d51bca21faa119ea56 Mon Sep 17 00:00:00 2001 From: farodin91 Date: Sun, 16 Aug 2015 20:29:19 +0200 Subject: [PATCH 12/13] fix tidy --- components/script/dom/window.rs | 6 +++--- ports/glutin/window.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 53a905a21f39..ceda0a89071e 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -623,7 +623,7 @@ impl<'a> WindowMethods for &'a Window { } // https://drafts.csswg.org/cssom-view/#dom-window-pagexoffset - fn PageXOffset(self) -> i32{ + fn PageXOffset(self) -> i32 { self.ScrollX() } @@ -700,7 +700,7 @@ impl<'a> WindowMethods for &'a Window { fn MoveTo(self, x: i32, y: i32) { // Step 1 //TODO determine if this operation is allowed - let point = Point2D::new(x,y); + let point = Point2D::new(x, y); self.compositor.borrow_mut().send(ScriptToCompositorMsg::MoveTo(point)).unwrap() } @@ -1041,7 +1041,7 @@ impl<'a> WindowHelpers for &'a Window { } fn client_window(self) -> (Size2D, Point2D) { - let (send,recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); + let (send, recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); self.compositor.borrow_mut().send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap(); recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) } diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 9a2865f727d8..5a7316fcdf36 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -520,8 +520,8 @@ impl WindowMethods for Window { fn client_window(&self) -> (Size2D, Point2D) { let (width, height) = self.window.get_outer_size().unwrap(); let size = Size2D::new(width, height); - let (x,y) = self.window.get_position().unwrap(); - let origin = Point2D::new(x as i32,y as i32); + let (x, y) = self.window.get_position().unwrap(); + let origin = Point2D::new(x as i32, y as i32); (size, origin) } From a9d703ab2d577b44097918984c29f3dcc9a1fe1c Mon Sep 17 00:00:00 2001 From: farodin91 Date: Wed, 19 Aug 2015 20:24:02 +0200 Subject: [PATCH 13/13] fixing borrow_mut --- components/script/dom/window.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 1c1f9a50310c..55294bc08726 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -686,7 +686,7 @@ impl<'a> WindowMethods for &'a Window { // Step 1 //TODO determine if this operation is allowed let size = Size2D::new(x.to_u32().unwrap_or(1), y.to_u32().unwrap_or(1)); - self.compositor.borrow_mut().send(ScriptToCompositorMsg::ResizeTo(size)).unwrap() + self.compositor.send(ScriptToCompositorMsg::ResizeTo(size)).unwrap() } // https://drafts.csswg.org/cssom-view/#dom-window-resizeby @@ -701,7 +701,7 @@ impl<'a> WindowMethods for &'a Window { // Step 1 //TODO determine if this operation is allowed let point = Point2D::new(x, y); - self.compositor.borrow_mut().send(ScriptToCompositorMsg::MoveTo(point)).unwrap() + self.compositor.send(ScriptToCompositorMsg::MoveTo(point)).unwrap() } // https://drafts.csswg.org/cssom-view/#dom-window-moveby @@ -919,10 +919,16 @@ impl<'a> WindowHelpers for &'a Window { let size = self.current_viewport.get().size; self.current_viewport.set(Rect::new(Point2D::new(Au::from_f32_px(x), Au::from_f32_px(y)), size)); - self.compositor.borrow_mut().send(ScriptToCompositorMsg::ScrollFragmentPoint( + self.compositor.send(ScriptToCompositorMsg::ScrollFragmentPoint( self.pipeline(), LayerId::null(), point, smooth)).unwrap() } + fn client_window(self) -> (Size2D, Point2D) { + let (send, recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); + self.compositor.send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap(); + recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) + } + /// Reflows the page unconditionally. This method will wait for the layout thread to complete /// (but see the `TODO` below). If there is no window size yet, the page is presumed invisible /// and no reflow is performed. @@ -1040,12 +1046,6 @@ impl<'a> WindowHelpers for &'a Window { } } - fn client_window(self) -> (Size2D, Point2D) { - let (send, recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); - self.compositor.borrow_mut().send(ScriptToCompositorMsg::GetClientWindow(send)).unwrap(); - recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) - } - fn layout(&self) -> &LayoutRPC { &*self.layout_rpc }