Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send touch events to root pipeline, and allow forwarding to iframes. #13633

Merged
merged 1 commit into from Oct 8, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Send touch events to root pipeline, and allow forwarding to iframes.

Instead of letting the compositor try to find the correct scroll
layer for a touch event, switch touch events to work the same way
that mouse events do.

Touch events are now dispatched to the root pipeline, and then
forwarded to child iframes as required.
  • Loading branch information
gw3583 committed Oct 7, 2016
commit 291af9d11504f974828a7cf0cd5f6c89f9c6992e
@@ -37,7 +37,7 @@ use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg};
use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton, MouseEventType};
use script_traits::{StackingContextScrollState, TouchpadPressurePhase, TouchEventType};
use script_traits::{TouchId, WindowSizeData};
use script_traits::CompositorEvent::{MouseMoveEvent, MouseButtonEvent, TouchEvent};
use script_traits::CompositorEvent::{self, MouseMoveEvent, MouseButtonEvent, TouchEvent, TouchpadPressureEvent};
use std::collections::{HashMap, HashSet};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::fs::File;
@@ -1511,12 +1511,27 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}

fn send_event_to_root_pipeline(&self, event: CompositorEvent) {
let root_pipeline_id = match self.get_root_pipeline_id() {
Some(root_pipeline_id) => root_pipeline_id,
None => return,
};

if let Some(pipeline) = self.pipeline(root_pipeline_id) {
let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event);
if let Err(e) = pipeline.script_chan.send(msg) {
warn!("Sending control event to script failed ({}).", e);
}
}
}

fn on_touch_down(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
self.touch_handler.on_touch_down(identifier, point);
if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) {
result.layer.send_event(self, TouchEvent(TouchEventType::Down, identifier,
result.point.to_untyped()));
}
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
let translated_point = (point / dppx).to_untyped();
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Down,
identifier,
translated_point));
}

fn on_touch_move(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
@@ -1539,20 +1554,22 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.composite_if_necessary_if_not_using_webrender(CompositingReason::Zoom);
}
TouchAction::DispatchEvent => {
if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) {
result.layer.send_event(self, TouchEvent(TouchEventType::Move, identifier,
result.point.to_untyped()));
}
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
let translated_point = (point / dppx).to_untyped();
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Move,
identifier,
translated_point));
}
_ => {}
}
}

fn on_touch_up(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) {
result.layer.send_event(self, TouchEvent(TouchEventType::Up, identifier,
result.point.to_untyped()));
}
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
let translated_point = (point / dppx).to_untyped();
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Up,
identifier,
translated_point));
if let TouchAction::Click = self.touch_handler.on_touch_up(identifier, point) {
self.simulate_mouse_click(point);
}
@@ -1561,9 +1578,23 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_touch_cancel(&mut self, identifier: TouchId, point: TypedPoint2D<f32, DevicePixel>) {
// Send the event to script.
self.touch_handler.on_touch_cancel(identifier, point);
if let Some(result) = self.find_topmost_layer_at_point(point / self.scene.scale) {
result.layer.send_event(self, TouchEvent(TouchEventType::Cancel, identifier,
result.point.to_untyped()));
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
let translated_point = (point / dppx).to_untyped();
self.send_event_to_root_pipeline(TouchEvent(TouchEventType::Cancel,
identifier,
translated_point));
}

fn on_touchpad_pressure_event(&self,
point: TypedPoint2D<f32, DevicePixel>,
pressure: f32,
phase: TouchpadPressurePhase) {
if let Some(true) = PREFS.get("dom.forcetouch.enabled").as_boolean() {
let dppx = self.page_zoom * self.device_pixels_per_screen_px();
let translated_point = (point / dppx).to_untyped();
self.send_event_to_root_pipeline(TouchpadPressureEvent(translated_point,
pressure,
phase));
}
}

@@ -1877,16 +1908,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}

fn on_touchpad_pressure_event(&self, cursor: TypedPoint2D<f32, DevicePixel>, pressure: f32,
phase: TouchpadPressurePhase) {
if let Some(true) = PREFS.get("dom.forcetouch.enabled").as_boolean() {
match self.find_topmost_layer_at_point(cursor / self.scene.scale) {
Some(result) => result.layer.send_touchpad_pressure_event(self, result.point, pressure, phase),
None => {},
}
}
}

fn on_key_event(&self, ch: Option<char>, key: Key, state: KeyState, modifiers: KeyModifiers) {
let msg = ConstellationMsg::KeyEvent(ch, key, state, modifiers);
if let Err(e) = self.constellation_chan.send(msg) {
@@ -874,22 +874,10 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
debug!("constellation got focus message");
self.handle_focus_msg(pipeline_id);
}
FromScriptMsg::ForwardMouseButtonEvent(pipeline_id, event_type, button, point) => {
let event = CompositorEvent::MouseButtonEvent(event_type, button, point);
FromScriptMsg::ForwardEvent(pipeline_id, event) => {
let msg = ConstellationControlMsg::SendEvent(pipeline_id, event);
let result = match self.pipelines.get(&pipeline_id) {
None => { debug!("Pipeline {:?} got mouse button event after closure.", pipeline_id); return; }
Some(pipeline) => pipeline.script_chan.send(msg),
};
if let Err(e) = result {
self.handle_send_error(pipeline_id, e);
}
}
FromScriptMsg::ForwardMouseMoveEvent(pipeline_id, point) => {
let event = CompositorEvent::MouseMoveEvent(Some(point));
let msg = ConstellationControlMsg::SendEvent(pipeline_id, event);
let result = match self.pipelines.get(&pipeline_id) {
None => { debug!("Pipeline {:?} got mouse move event after closure.", pipeline_id); return; }
None => { debug!("Pipeline {:?} got event after closure.", pipeline_id); return; }
Some(pipeline) => pipeline.script_chan.send(msg),
};
if let Err(e) = result {
@@ -106,7 +106,7 @@ use origin::Origin;
use parse::{MutNullableParserField, ParserRef, ParserRoot};
use script_layout_interface::message::{Msg, ReflowQueryType};
use script_thread::{MainThreadScriptMsg, Runnable};
use script_traits::{AnimationState, MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{AnimationState, CompositorEvent, MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase};
use script_traits::{TouchEventType, TouchId};
use script_traits::UntrustedNodeAddress;
@@ -133,6 +133,11 @@ use url::Url;
use url::percent_encoding::percent_decode;
use util::prefs::PREFS;

pub enum TouchEventResult {
Processed(bool),
Forwarded,
}

#[derive(JSTraceable, PartialEq, HeapSizeOf)]
pub enum IsHTMLDocument {
HTMLDocument,
@@ -723,9 +728,8 @@ impl Document {
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);
let event = CompositorEvent::MouseButtonEvent(mouse_event_type, button, child_point);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
}
return;
@@ -853,14 +857,6 @@ impl Document {
client_point: Point2D<f32>,
pressure: f32,
phase_now: TouchpadPressurePhase) {
let phase_before = self.touchpad_pressure_phase.get();
self.touchpad_pressure_phase.set(phase_now);

if phase_before == TouchpadPressurePhase::BeforeClick &&
phase_now == TouchpadPressurePhase::BeforeClick {
return;
}

let node = match self.window.hit_test_query(client_point, false) {
Some(node_address) => node::from_untrusted_node_address(js_runtime, node_address),
None => return
@@ -877,6 +873,30 @@ 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 = CompositorEvent::TouchpadPressureEvent(child_point,
pressure,
phase_now);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
}
return;
}

let phase_before = self.touchpad_pressure_phase.get();
self.touchpad_pressure_phase.set(phase_now);

if phase_before == TouchpadPressurePhase::BeforeClick &&
phase_now == TouchpadPressurePhase::BeforeClick {
return;
}

let node = el.upcast::<Node>();
let target = node.upcast();

@@ -963,7 +983,8 @@ impl Document {
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);
let event = CompositorEvent::MouseMoveEvent(Some(child_point));
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
}
return;
@@ -1032,9 +1053,11 @@ impl Document {
pub fn handle_touch_event(&self,
js_runtime: *mut JSRuntime,
event_type: TouchEventType,
TouchId(identifier): TouchId,
touch_id: TouchId,
point: Point2D<f32>)
-> bool {
-> TouchEventResult {
let TouchId(identifier) = touch_id;

let event_name = match event_type {
TouchEventType::Down => "touchstart",
TouchEventType::Move => "touchmove",
@@ -1044,18 +1067,33 @@ impl Document {

let node = match self.window.hit_test_query(point, false) {
Some(node_address) => node::from_untrusted_node_address(js_runtime, node_address),
None => return false,
None => return TouchEventResult::Processed(false),
};
let el = match node.downcast::<Element>() {
Some(el) => Root::from_ref(el),
None => {
let parent = node.GetParentNode();
match parent.and_then(Root::downcast::<Element>) {
Some(parent) => parent,
None => return false,
None => return TouchEventResult::Processed(false),
}
},
};

// 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 = point - child_origin;

let event = CompositorEvent::TouchEvent(event_type, touch_id, child_point);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
}
return TouchEventResult::Forwarded;
}

let target = Root::upcast::<EventTarget>(el);
let window = &*self.window;

@@ -1132,8 +1170,8 @@ impl Document {
ReflowReason::MouseEvent);

match result {
EventStatus::Canceled => false,
EventStatus::NotCanceled => true
EventStatus::Canceled => TouchEventResult::Processed(false),
EventStatus::NotCanceled => TouchEventResult::Processed(true),
}
}

@@ -36,7 +36,7 @@ use dom::bindings::str::DOMString;
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::WRAP_CALLBACKS;
use dom::browsingcontext::BrowsingContext;
use dom::document::{Document, DocumentProgressHandler, DocumentSource, FocusType, IsHTMLDocument};
use dom::document::{Document, DocumentProgressHandler, DocumentSource, FocusType, IsHTMLDocument, TouchEventResult};
use dom::element::Element;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
@@ -1934,9 +1934,9 @@ impl ScriptThread {
}
}
TouchEvent(event_type, identifier, point) => {
let handled = self.handle_touch_event(pipeline_id, event_type, identifier, point);
match event_type {
TouchEventType::Down => {
let touch_result = self.handle_touch_event(pipeline_id, event_type, identifier, point);
match (event_type, touch_result) {
(TouchEventType::Down, TouchEventResult::Processed(handled)) => {
let result = if handled {
// TODO: Wait to see if preventDefault is called on the first touchmove event.
EventResult::DefaultAllowed
@@ -1987,10 +1987,13 @@ impl ScriptThread {
event_type: TouchEventType,
identifier: TouchId,
point: Point2D<f32>)
-> bool {
-> TouchEventResult {
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => { warn!("Message sent to closed pipeline {}.", pipeline_id); return true },
None => {
warn!("Message sent to closed pipeline {}.", pipeline_id);
return TouchEventResult::Processed(true)
},
};
document.handle_touch_event(self.js_runtime.rt(), event_type, identifier, point)
}
@@ -3,10 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use AnimationState;
use CompositorEvent;
use DocumentState;
use IFrameLoadInfo;
use MouseButton;
use MouseEventType;
use MozBrowserEvent;
use WorkerGlobalScopeInit;
use WorkerScriptLoadOrigin;
@@ -72,10 +71,8 @@ pub enum ScriptMsg {
IpcSender<Result<(IpcSender<CanvasMsg>, GLLimits), String>>),
/// 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>),
/// Forward an event that was sent to the parent window.
ForwardEvent(PipelineId, CompositorEvent),
/// Requests that the constellation retrieve the current contents of the clipboard
GetClipboardContents(IpcSender<String>),
/// <head> tag finished parsing
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.