mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #9811 - paulrouget:forceTouch, r=mbrubeck
forcetouch events https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/RespondingtoForceTouchEventsfromJavaScript.html Not sure how we want to land that yet. Maybe reproduce the webkit events (as in this PR), or as touch/mousemouse events. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9811) <!-- Reviewable:end -->
This commit is contained in:
commit
0ff8adb097
14 changed files with 246 additions and 8 deletions
|
@ -37,7 +37,7 @@ use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest};
|
|||
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||
use script_traits::CompositorEvent::{MouseMoveEvent, MouseButtonEvent, TouchEvent};
|
||||
use script_traits::{AnimationState, ConstellationControlMsg, LayoutControlMsg};
|
||||
use script_traits::{MouseButton, MouseEventType, TouchEventType, TouchId};
|
||||
use script_traits::{MouseButton, MouseEventType, TouchpadPressurePhase, TouchEventType, TouchId};
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
|
@ -50,8 +50,8 @@ use time::{precise_time_ns, precise_time_s};
|
|||
use touch::{TouchHandler, TouchAction};
|
||||
use url::Url;
|
||||
use util::geometry::{PagePx, ScreenPx, ViewportPx};
|
||||
use util::opts;
|
||||
use util::print_tree::PrintTree;
|
||||
use util::{opts, prefs};
|
||||
use webrender;
|
||||
use webrender_traits::{self, ScrollEventPhase};
|
||||
use windowing::{self, MouseWindowEvent, WindowEvent, WindowMethods, WindowNavigateMsg};
|
||||
|
@ -1225,6 +1225,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
self.on_navigation_window_event(direction);
|
||||
}
|
||||
|
||||
WindowEvent::TouchpadPressure(cursor, pressure, stage) => {
|
||||
self.on_touchpad_pressure_event(cursor, pressure, stage);
|
||||
}
|
||||
|
||||
WindowEvent::KeyEvent(key, state, modifiers) => {
|
||||
self.on_key_event(key, state, modifiers);
|
||||
}
|
||||
|
@ -1701,6 +1705,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
self.constellation_chan.send(ConstellationMsg::Navigate(None, direction)).unwrap()
|
||||
}
|
||||
|
||||
fn on_touchpad_pressure_event(&self, cursor: TypedPoint2D<DevicePixel, f32>, pressure: f32,
|
||||
phase: TouchpadPressurePhase) {
|
||||
if prefs::get_pref("dom.forcetouch.enabled").as_boolean().unwrap() {
|
||||
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, key: Key, state: KeyState, modifiers: KeyModifiers) {
|
||||
self.constellation_chan.send(ConstellationMsg::KeyEvent(key, state, modifiers)).unwrap()
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ use layers::geometry::LayerPixel;
|
|||
use layers::layers::{Layer, LayerBufferSet};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use script_traits::CompositorEvent;
|
||||
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent};
|
||||
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchpadPressureEvent};
|
||||
use script_traits::ConstellationControlMsg;
|
||||
use script_traits::MouseEventType;
|
||||
use script_traits::TouchpadPressurePhase;
|
||||
use std::rc::Rc;
|
||||
use windowing::{MouseWindowEvent, WindowMethods};
|
||||
|
||||
|
@ -139,6 +140,13 @@ pub trait CompositorLayer {
|
|||
event: CompositorEvent)
|
||||
where Window: WindowMethods;
|
||||
|
||||
fn send_touchpad_pressure_event<Window>(&self,
|
||||
compositor: &IOCompositor<Window>,
|
||||
cursor: TypedPoint2D<LayerPixel, f32>,
|
||||
pressure: f32,
|
||||
phase: TouchpadPressurePhase)
|
||||
where Window: WindowMethods;
|
||||
|
||||
fn clamp_scroll_offset_and_scroll_layer(&self,
|
||||
new_offset: TypedPoint2D<LayerPixel, f32>)
|
||||
-> ScrollEventResult;
|
||||
|
@ -399,6 +407,18 @@ impl CompositorLayer for Layer<CompositorData> {
|
|||
}
|
||||
}
|
||||
|
||||
fn send_touchpad_pressure_event<Window>(&self,
|
||||
compositor: &IOCompositor<Window>,
|
||||
cursor: TypedPoint2D<LayerPixel, f32>,
|
||||
pressure: f32,
|
||||
phase: TouchpadPressurePhase)
|
||||
where Window: WindowMethods {
|
||||
if let Some(pipeline) = compositor.pipeline(self.pipeline_id()) {
|
||||
let message = TouchpadPressureEvent(cursor.to_untyped(), pressure, phase);
|
||||
let _ = pipeline.script_chan.send(ConstellationControlMsg::SendEvent(pipeline.id.clone(), message));
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_layer_and_all_child_layers(&self, new_offset: TypedPoint2D<LayerPixel, f32>)
|
||||
-> bool {
|
||||
let mut result = false;
|
||||
|
|
|
@ -13,7 +13,7 @@ use layers::geometry::DevicePixel;
|
|||
use layers::platform::surface::NativeDisplay;
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||
use net_traits::net_error_list::NetError;
|
||||
use script_traits::{MouseButton, TouchEventType, TouchId};
|
||||
use script_traits::{MouseButton, TouchpadPressurePhase, TouchEventType, TouchId};
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use style_traits::cursor::Cursor;
|
||||
use url::Url;
|
||||
|
@ -50,6 +50,8 @@ pub enum WindowEvent {
|
|||
InitializeCompositing,
|
||||
/// Sent when the window is resized.
|
||||
Resize(TypedSize2D<DevicePixel, u32>),
|
||||
/// Touchpad Pressure
|
||||
TouchpadPressure(TypedPoint2D<DevicePixel, f32>, f32, TouchpadPressurePhase),
|
||||
/// Sent when you want to override the viewport.
|
||||
Viewport(TypedPoint2D<DevicePixel, u32>, TypedSize2D<DevicePixel, u32>),
|
||||
/// Sent when a new URL is to be loaded.
|
||||
|
@ -84,6 +86,7 @@ impl Debug for WindowEvent {
|
|||
WindowEvent::Refresh => write!(f, "Refresh"),
|
||||
WindowEvent::InitializeCompositing => write!(f, "InitializeCompositing"),
|
||||
WindowEvent::Resize(..) => write!(f, "Resize"),
|
||||
WindowEvent::TouchpadPressure(..) => write!(f, "TouchpadPressure"),
|
||||
WindowEvent::Viewport(..) => write!(f, "Viewport"),
|
||||
WindowEvent::KeyEvent(..) => write!(f, "Key"),
|
||||
WindowEvent::LoadUrl(..) => write!(f, "LoadUrl"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue