diff options
-rw-r--r-- | components/compositing/compositor.rs | 4 | ||||
-rw-r--r-- | components/compositing/compositor_layer.rs | 10 | ||||
-rw-r--r-- | components/compositing/constellation.rs | 13 | ||||
-rw-r--r-- | components/compositing/windowing.rs | 5 | ||||
-rw-r--r-- | components/msg/constellation_msg.rs | 23 | ||||
-rw-r--r-- | components/script/dom/document.rs | 51 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 5 | ||||
-rw-r--r-- | components/script/script_task.rs | 25 | ||||
-rw-r--r-- | components/script_traits/lib.rs | 20 | ||||
-rw-r--r-- | ports/cef/browser_host.rs | 3 | ||||
-rw-r--r-- | ports/glutin/window.rs | 2 | ||||
-rw-r--r-- | ports/gonk/Cargo.lock | 1 | ||||
-rw-r--r-- | ports/gonk/Cargo.toml | 3 | ||||
-rw-r--r-- | ports/gonk/src/input.rs | 2 | ||||
-rw-r--r-- | ports/gonk/src/main.rs | 1 |
15 files changed, 100 insertions, 68 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index e61dff31d47..3e259a7b35a 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -30,13 +30,13 @@ use msg::compositor_msg::{Epoch, EventResult, FrameTreeId, LayerId, LayerKind}; use msg::compositor_msg::{LayerProperties, ScrollPolicy}; use msg::constellation_msg::CompositorMsg as ConstellationMsg; use msg::constellation_msg::{AnimationState, Image, PixelFormat}; -use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData}; +use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, MouseButton}; use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData}; use pipeline::CompositionPipeline; use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest}; use profile_traits::time::{self, ProfilerCategory, profile}; use script_traits::CompositorEvent::{MouseMoveEvent, TouchEvent}; -use script_traits::{ConstellationControlMsg, LayoutControlMsg, MouseButton}; +use script_traits::{ConstellationControlMsg, LayoutControlMsg}; use script_traits::{TouchEventType, TouchId}; use scrolling::ScrollingTimerProxy; use std::collections::hash_map::Entry::{Occupied, Vacant}; diff --git a/components/compositing/compositor_layer.rs b/components/compositing/compositor_layer.rs index ceb034c83bd..27308adddbc 100644 --- a/components/compositing/compositor_layer.rs +++ b/components/compositing/compositor_layer.rs @@ -12,9 +12,9 @@ use layers::color::Color; use layers::geometry::LayerPixel; use layers::layers::{Layer, LayerBufferSet}; use msg::compositor_msg::{Epoch, LayerId, LayerProperties, ScrollPolicy}; -use msg::constellation_msg::PipelineId; +use msg::constellation_msg::{MouseEventType, PipelineId}; use script_traits::CompositorEvent; -use script_traits::CompositorEvent::{ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; +use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent}; use script_traits::ConstellationControlMsg; use std::rc::Rc; use windowing::{MouseWindowEvent, WindowMethods}; @@ -372,11 +372,11 @@ impl CompositorLayer for Layer<CompositorData> { let event_point = cursor.to_untyped(); let message = match event { MouseWindowEvent::Click(button, _) => - ClickEvent(button, event_point), + MouseButtonEvent(MouseEventType::Click, button, event_point), MouseWindowEvent::MouseDown(button, _) => - MouseDownEvent(button, event_point), + MouseButtonEvent(MouseEventType::MouseDown, button, event_point), MouseWindowEvent::MouseUp(button, _) => - MouseUpEvent(button, event_point), + MouseButtonEvent(MouseEventType::MouseUp, button, event_point), }; self.send_event(compositor, message); } diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 22a22d459e7..34d20d42c0d 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -613,6 +613,19 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { debug!("constellation got focus message"); self.handle_focus_msg(pipeline_id); } + Request::Script(FromScriptMsg::ForwardMouseButtonEvent( + pipeline_id, event_type, button, point)) => { + if let Some(pipeline) = self.pipelines.get(&pipeline_id) { + pipeline.script_chan.send(ConstellationControlMsg::SendEvent(pipeline_id, + CompositorEvent::MouseButtonEvent(event_type, button, point))); + } + } + Request::Script(FromScriptMsg::ForwardMouseMoveEvent(pipeline_id, point)) => { + if let Some(pipeline) = self.pipelines.get(&pipeline_id) { + pipeline.script_chan.send(ConstellationControlMsg::SendEvent(pipeline_id, + CompositorEvent::MouseMoveEvent(Some(point)))); + } + } Request::Script(FromScriptMsg::GetClipboardContents(sender)) => { let result = self.clipboard_ctx.as_ref().map_or( "".to_owned(), diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index d129a6deb5b..2a9dcb9bcb0 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -11,9 +11,9 @@ use euclid::size::TypedSize2D; use euclid::{Point2D, Size2D}; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; -use msg::constellation_msg::{Key, KeyModifiers, KeyState}; +use msg::constellation_msg::{Key, KeyModifiers, KeyState, MouseButton}; use net_traits::net_error_list::NetError; -use script_traits::{MouseButton, TouchEventType, TouchId}; +use script_traits::{TouchEventType, TouchId}; use std::fmt::{Debug, Error, Formatter}; use std::rc::Rc; use url::Url; @@ -27,7 +27,6 @@ pub enum MouseWindowEvent { MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>), } - #[derive(Clone)] pub enum WindowNavigateMsg { Forward, diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 027d8efddd8..d7ff06de6a4 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -7,6 +7,7 @@ use canvas_traits::CanvasMsg; use compositor_msg::Epoch; +use euclid::point::Point2D; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; use hyper::header::Headers; @@ -283,6 +284,10 @@ pub enum ScriptMsg { Failure(Failure), /// Notifies the constellation that this frame has received focus. Focus(PipelineId), + /// Re-send a mouse button event that was sent to the parent window. + ForwardMouseButtonEvent(PipelineId, MouseEventType, MouseButton, Point2D<f32>), + /// Re-send a mouse move event that was sent to the parent window. + ForwardMouseMoveEvent(PipelineId, Point2D<f32>), /// Requests that the constellation retrieve the current contents of the clipboard GetClipboardContents(IpcSender<String>), /// <head> tag finished parsing @@ -307,6 +312,24 @@ pub enum ScriptMsg { ViewportConstrained(PipelineId, ViewportConstraints), } +#[derive(Deserialize, HeapSizeOf, Serialize)] +pub enum MouseEventType { + Click, + MouseDown, + MouseUp, +} + +/// The mouse button involved in the event. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum MouseButton { + /// The left mouse button. + Left, + /// The middle mouse button. + Middle, + /// The right mouse button. + Right, +} + /// Messages from the paint task to the constellation. #[derive(Deserialize, Serialize)] pub enum PaintMsg { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a30e923cee8..0e790188320 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -5,12 +5,15 @@ use document_loader::{DocumentLoader, LoadType}; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; +use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; +use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; @@ -82,13 +85,14 @@ use msg::compositor_msg::ScriptToCompositorMsg; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{AnimationState, PipelineId}; -use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState, MozBrowserEvent, SubpageId}; +use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState}; +use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, SubpageId}; use net_traits::ControlMsg::{GetCookiesForUrl, SetCookiesForUrl}; use net_traits::CookieSource::NonHTTP; use net_traits::{AsyncResponseTarget, PendingAsyncLoad}; use num::ToPrimitive; use script_task::{MainThreadScriptMsg, Runnable}; -use script_traits::{MouseButton, TouchEventType, TouchId, UntrustedNodeAddress}; +use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress}; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::boxed::FnBox; @@ -603,7 +607,7 @@ impl Document { pub fn handle_mouse_event(&self, js_runtime: *mut JSRuntime, - _button: MouseButton, + button: MouseButton, client_point: Point2D<f32>, mouse_event_type: MouseEventType) { let mouse_event_type_string = match mouse_event_type { @@ -634,6 +638,21 @@ impl Document { }, }; + // If the target is an iframe, forward the event to the child document. + if let Some(iframe) = el.downcast::<HTMLIFrameElement>() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::<Element>().GetBoundingClientRect(); + let child_origin = Point2D::new(rect.X() as f32, rect.Y() as f32); + let child_point = client_point - child_origin; + + let event = ConstellationMsg::ForwardMouseButtonEvent(pipeline_id, + mouse_event_type, + button, child_point); + self.window.constellation_chan().0.send(event).unwrap(); + } + return; + } + let node = el.upcast::<Node>(); debug!("{} on {:?}", mouse_event_type_string, node.debug_str()); // Prevent click event if form control element is disabled. @@ -766,11 +785,23 @@ impl Document { if mouse_over_addresses.len() > 0 { let top_most_node = node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]); + let client_point = client_point.unwrap(); // Must succeed because hit test succeeded. - let target = top_most_node.upcast(); - if let Some(client_point) = client_point { - self.fire_mouse_event(client_point, target, "mousemove".to_owned()); + // If the target is an iframe, forward the event to the child document. + if let Some(iframe) = top_most_node.downcast::<HTMLIFrameElement>() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::<Element>().GetBoundingClientRect(); + let child_origin = Point2D::new(rect.X() as f32, rect.Y() as f32); + let child_point = client_point - child_origin; + + let event = ConstellationMsg::ForwardMouseMoveEvent(pipeline_id, child_point); + self.window.constellation_chan().0.send(event).unwrap(); + } + return; } + + let target = top_most_node.upcast(); + self.fire_mouse_event(client_point, target, "mousemove".to_owned()); } // Store the current mouse over targets for next frame @@ -1362,14 +1393,6 @@ impl Document { } } -#[derive(HeapSizeOf)] -pub enum MouseEventType { - Click, - MouseDown, - MouseUp, -} - - #[derive(PartialEq, HeapSizeOf)] pub enum DocumentSource { FromParser, diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 4c7f7276ca7..3798ab4f539 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -186,6 +186,11 @@ impl HTMLIFrameElement { } #[inline] + pub fn pipeline_id(&self) -> Option<PipelineId> { + self.pipeline_id.get() + } + + #[inline] pub fn subpage_id(&self) -> Option<SubpageId> { self.subpage_id.get() } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 8b9800063e2..736c95b0d2d 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -31,8 +31,7 @@ use dom::bindings::js::{Root, RootCollectionPtr, RootedReference}; use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects}; use dom::bindings::trace::{JSTraceable, RootedVec, trace_traceables}; use dom::bindings::utils::{DOM_CALLBACKS, WRAP_CALLBACKS}; -use dom::document::{Document, DocumentProgressHandler, IsHTMLDocument}; -use dom::document::{DocumentSource, MouseEventType}; +use dom::document::{Document, DocumentProgressHandler, DocumentSource, IsHTMLDocument}; use dom::element::Element; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::htmlanchorelement::HTMLAnchorElement; @@ -65,7 +64,7 @@ use mem::heap_size_of_self_and_children; use msg::compositor_msg::{EventResult, LayerId, ScriptToCompositorMsg}; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, FocusType, LoadData}; -use msg::constellation_msg::{MozBrowserEvent, PipelineId}; +use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, PipelineId}; use msg::constellation_msg::{PipelineNamespace}; use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId}; use msg::webdriver_msg::WebDriverScriptCommand; @@ -78,11 +77,9 @@ use page::{Frame, IterablePage, Page}; use parse::html::{ParseContext, parse_html}; use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan}; use profile_traits::time::{self, ProfilerCategory, profile}; -use script_traits::CompositorEvent::{ClickEvent, ResizeEvent}; -use script_traits::CompositorEvent::{KeyEvent, MouseMoveEvent}; -use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent, TouchEvent}; -use script_traits::{CompositorEvent, ConstellationControlMsg}; -use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo}; +use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent}; +use script_traits::CompositorEvent::{TouchEvent}; +use script_traits::{CompositorEvent, ConstellationControlMsg, InitialScriptState, NewLayoutInfo}; use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory}; use script_traits::{TimerEvent, TimerEventRequest, TimerSource}; use script_traits::{TouchEventType, TouchId}; @@ -1786,16 +1783,8 @@ impl ScriptTask { self.handle_resize_event(pipeline_id, new_size); } - ClickEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::Click, button, point); - } - - MouseDownEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::MouseDown, button, point); - } - - MouseUpEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::MouseUp, button, point); + MouseButtonEvent(event_type, button, point) => { + self.handle_mouse_event(pipeline_id, event_type, button, point); } MouseMoveEvent(point) => { diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 8a5ffcb459f..ef86ee26085 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -34,6 +34,7 @@ use msg::compositor_msg::{Epoch, LayerId, ScriptToCompositorMsg}; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, WindowSizeData}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, SubpageId}; +use msg::constellation_msg::{MouseButton, MouseEventType}; use msg::constellation_msg::{MozBrowserEvent, PipelineNamespaceId}; use msg::webdriver_msg::WebDriverScriptCommand; use net_traits::ResourceTask; @@ -146,17 +147,6 @@ pub enum ConstellationControlMsg { }, } -/// The mouse button involved in the event. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum MouseButton { - /// The left mouse button. - Left, - /// The middle mouse button. - Middle, - /// The right mouse button. - Right, -} - /// The type of input represented by a multi-touch event. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum TouchEventType { @@ -181,12 +171,8 @@ pub struct TouchId(pub i32); pub enum CompositorEvent { /// The window was resized. ResizeEvent(WindowSizeData), - /// A point was clicked. - ClickEvent(MouseButton, Point2D<f32>), - /// A mouse button was pressed on a point. - MouseDownEvent(MouseButton, Point2D<f32>), - /// A mouse button was released on a point. - MouseUpEvent(MouseButton, Point2D<f32>), + /// A mouse button state changed. + MouseButtonEvent(MouseEventType, MouseButton, Point2D<f32>), /// The mouse was moved over a point (or was moved out of the recognizable region). MouseMoveEvent(Option<Point2D<f32>>), /// A touch event was generated with a touch ID and location. diff --git a/ports/cef/browser_host.rs b/ports/cef/browser_host.rs index 73ddfdb0676..7dd6830fda1 100644 --- a/ports/cef/browser_host.rs +++ b/ports/cef/browser_host.rs @@ -14,8 +14,7 @@ use compositing::windowing::{WindowEvent, MouseWindowEvent}; use euclid::point::Point2D; use euclid::size::Size2D; use libc::{c_double, c_int}; -use msg::constellation_msg::{self, KeyModifiers, KeyState}; -use script_traits::MouseButton; +use msg::constellation_msg::{self, KeyModifiers, KeyState, MouseButton}; use std::cell::{Cell, RefCell}; pub struct ServoCefBrowserHost { diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index f4b40087f3c..c8e9fa45082 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -253,7 +253,7 @@ impl Window { /// Helper function to handle a click fn handle_mouse(&self, button: glutin::MouseButton, action: glutin::ElementState, x: i32, y: i32) { - use script_traits::MouseButton; + use msg::constellation_msg::MouseButton; // FIXME(tkuehn): max pixel dist should be based on pixel density let max_pixel_dist = 10f64; diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 5bd95dc86bc..b91b08d8bd9 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -17,7 +17,6 @@ dependencies = [ "net_traits 0.0.1", "profile 0.0.1", "script 0.0.1", - "script_traits 0.0.1", "servo 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.toml b/ports/gonk/Cargo.toml index 1003ce7ce2d..f8c095bc270 100644 --- a/ports/gonk/Cargo.toml +++ b/ports/gonk/Cargo.toml @@ -18,9 +18,6 @@ path = "../../components/msg" [dependencies.script] path = "../../components/script" -[dependencies.script_traits] -path = "../../components/script_traits" - [dependencies.net_traits] path = "../../components/net_traits" diff --git a/ports/gonk/src/input.rs b/ports/gonk/src/input.rs index e40900f7acf..b296db77583 100644 --- a/ports/gonk/src/input.rs +++ b/ports/gonk/src/input.rs @@ -6,7 +6,7 @@ use compositing::windowing::{WindowEvent, MouseWindowEvent}; use errno::errno; use euclid::point::Point2D; use libc::{c_int, c_long, time_t}; -use script_traits::MouseButton; +use msg::constellation_msg::MouseButton; use std::fs::File; use std::io::Read; use std::mem::{size_of, transmute, zeroed}; diff --git a/ports/gonk/src/main.rs b/ports/gonk/src/main.rs index 75b31dfa71a..57728f92f81 100644 --- a/ports/gonk/src/main.rs +++ b/ports/gonk/src/main.rs @@ -33,7 +33,6 @@ extern crate layers; extern crate libc; extern crate msg; extern crate net_traits; -extern crate script_traits; extern crate servo; extern crate time; extern crate url; |