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

[WIP] PointerEvent #16273

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -833,6 +833,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.on_mouse_window_move_event_class(cursor);
}

WindowEvent::PointerWindowEventClass(pointer_window_event) => {
unimplemented!()
}

WindowEvent::Touch(event_type, identifier, location) => {
match event_type {
TouchEventType::Down => self.on_touch_down(identifier, location),
@@ -28,6 +28,11 @@ pub enum MouseWindowEvent {
MouseUp(MouseButton, TypedPoint2D<f32, DevicePixel>),
}

#[derive(Clone)]
pub enum PointerWindowEvent {
// PointerDown()
}

#[derive(Clone)]
pub enum WindowNavigateMsg {
Forward,
@@ -62,6 +67,8 @@ pub enum WindowEvent {
MouseWindowEventClass(MouseWindowEvent),
/// Sent when a mouse move.
MouseWindowMoveEventClass(TypedPoint2D<f32, DevicePixel>),
/// Sent when a pointer hit test is to be performed
PointerWindowEventClass(PointerWindowEvent),
/// Touch event: type, identifier, point
Touch(TouchEventType, TouchId, TypedPoint2D<f32, DevicePixel>),
/// Sent when the user scrolls. The first point is the delta and the second point is the
@@ -96,6 +103,7 @@ impl Debug for WindowEvent {
WindowEvent::LoadUrl(..) => write!(f, "LoadUrl"),
WindowEvent::MouseWindowEventClass(..) => write!(f, "Mouse"),
WindowEvent::MouseWindowMoveEventClass(..) => write!(f, "MouseMove"),
WindowEvent::PointerWindowEventClass(..) => write!(f, "Pointer"),
WindowEvent::Touch(..) => write!(f, "Touch"),
WindowEvent::Scroll(..) => write!(f, "Scroll"),
WindowEvent::Zoom(..) => write!(f, "Zoom"),
@@ -73,6 +73,7 @@ use dom::node::VecPreOrderInsertionHelper;
use dom::nodeiterator::NodeIterator;
use dom::nodelist::NodeList;
use dom::pagetransitionevent::PageTransitionEvent;
use dom::pointerevent::PointerEvent;
use dom::popstateevent::PopStateEvent;
use dom::processinginstruction::ProcessingInstruction;
use dom::progressevent::ProgressEvent;
@@ -823,6 +824,17 @@ impl Document {
}
}

pub fn handle_pointer_event(&self,
js_runtime: *mut JSRuntime) {
// pointer_event_type: PointerEventType) {
// let pointer_type_string = match pointer_event_type {
// PointerEventType::PointerDown => "pointerdown".to_owned()
// };

// debug!("{}: at {:?}", pointer_event_type_string)

}

pub fn handle_mouse_event(&self,
js_runtime: *mut JSRuntime,
button: MouseButton,
@@ -461,6 +461,16 @@ macro_rules! global_event_handlers(
event_handler!(pause, GetOnpause, SetOnpause);
event_handler!(play, GetOnplay, SetOnplay);
event_handler!(playing, GetOnplaying, SetOnplaying);
// Pointer event handlers
event_handler!(pointercancel, GetOnpointercancel, SetOnpointercancel);
event_handler!(pointerdown, GetOnpointerdown, SetOnpointerdown);
event_handler!(pointerenter, GetOnpointerenter, SetOnpointerenter);
event_handler!(pointermove, GetOnpointermove, SetOnpointermove);
event_handler!(pointerover, GetOnpointerover, SetOnpointerover);
event_handler!(pointerup, GetOnpointerup, SetOnpointerup);
event_handler!(pointerout, GetOnpointerout, SetOnpointerout);
event_handler!(pointerleave, GetOnpointerleave, SetOnpointerleave);
// event_handler!(gotpointercapture, GetOn)
event_handler!(progress, GetOnprogress, SetOnprogress);
event_handler!(ratechange, GetOnratechange, SetOnratechange);
event_handler!(reset, GetOnreset, SetOnreset);
@@ -393,6 +393,7 @@ pub mod permissions;
pub mod permissionstatus;
pub mod plugin;
pub mod pluginarray;
pub mod pointerevent;
pub mod popstateevent;
pub mod processinginstruction;
pub mod progressevent;
@@ -35,7 +35,7 @@ pub struct MouseEvent {
}

impl MouseEvent {
fn new_inherited() -> MouseEvent {
pub fn new_inherited() -> MouseEvent {
MouseEvent {
uievent: UIEvent::new_inherited(),
screen_x: Cell::new(0),
@@ -16,6 +16,7 @@ use dom::serviceworkercontainer::ServiceWorkerContainer;
use dom::vr::VR;
use dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
use script_traits::WebVREventMsg;

#[dom_struct]
@@ -27,6 +28,7 @@ pub struct Navigator {
service_worker: MutNullableJS<ServiceWorkerContainer>,
vr: MutNullableJS<VR>,
permissions: MutNullableJS<Permissions>,
max_touch_points: Cell<i32>
}

impl Navigator {
@@ -39,6 +41,7 @@ impl Navigator {
service_worker: Default::default(),
vr: Default::default(),
permissions: Default::default(),
max_touch_points: Cell::new(0)
}
}

@@ -132,6 +135,11 @@ impl NavigatorMethods for Navigator {
fn Permissions(&self) -> Root<Permissions> {
self.permissions.or_init(|| Permissions::new(&self.global()))
}

// https://www.w3.org/TR/pointerevents/#extensions-to-the-navigator-interface
fn MaxTouchPoints(&self) -> i32 {
self.max_touch_points.get()
}
}

impl Navigator {
@@ -0,0 +1,122 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::Bindings::PointerEventBinding;
use dom::bindings::codegen::Bindings::PointerEventBinding::PointerEventMethods;
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::error::Fallible;
use dom::mouseevent::MouseEvent;
use dom::bindings::num::Finite;
use dom_struct::dom_struct;
use dom::bindings::js::{Root, RootedReference};
use dom::bindings::reflector::reflect_dom_object;
use dom::window::Window;
use dom::bindings::str::DOMString;
use std::cell::Cell;

// Webidl matching struct
// QUESTION: Are webidl long's i32 or i64?
// Currently pointer types are set by string, but it will be safer to create an enum for each
// pub enum PointerType {
// Unknown,
// Mouse,
// Pen,
// Touch,
// LastEntry
// }

// https://www.w3.org/TR/pointerevents/#the-pointerover-event
#[dom_struct]
pub struct PointerEvent {
mouse_event: MouseEvent,
pointer_id: Cell<i32>, // unique identifier for pointer causing the event, MUST be Unique at the time
width: Cell<f64>, // width (magnitutde on the x axis) in css pixels of the contact geometry of the pointer
height: Cell<f64>, // height
pressure: Cell<f32>, // Normalized pressure of the pointer input from [0,1]
tilt_x: Cell<i32>, // Plane angle [-90,90] between y-Z Plane
tilt_y: Cell<i32>,
pointer_type: DOMString, // Device type that caused the event (e.g mouse, pen, touch)
is_primary: Cell<bool>,
}

impl PointerEvent {
// Called by new_unitialized
pub fn new_inherited() -> PointerEvent {
PointerEvent {
mouse_event: MouseEvent::new_inherited(),
pointer_id: Cell::new(0),
width: Cell::new(0.0),
height: Cell::new(0.0),
pressure: Cell::new(0.0),
tilt_x: Cell::new(0),
tilt_y: Cell::new(0),
pointer_type: DOMString::new(),
is_primary: Cell::new(false)
}
}

// Called by new
pub fn new_uninitialized(window: &Window) -> Root<PointerEvent> {
reflect_dom_object(box Self::new_inherited(),
window,
PointerEventBinding::Wrap)
}

// Called by Constructor
pub fn new(window: &Window,
type_: DOMString) -> Root<PointerEvent> {
let ev = PointerEvent::new_uninitialized(window);

ev
}

/// Called by JS
pub fn Constructor(window: &Window,
type_: DOMString,
init: &PointerEventBinding::PointerEventInit) -> Fallible<Root<PointerEvent>> {
let event = PointerEvent::new(window, type_);

Ok(event)
}
}

impl PointerEventMethods for PointerEvent {
fn PointerId(&self) -> i32 {
self.pointer_id.get()
}

fn Width(&self) -> Finite<f64> {
Finite::wrap(self.width.get())
}

fn Height(&self) -> Finite<f64> {
Finite::wrap(self.height.get())
}

fn Pressure(&self) -> Finite<f32> {
Finite::wrap(self.pressure.get())
}

fn TiltX(&self) -> i32 {
self.tilt_x.get()
}

fn TiltY(&self) -> i32 {
self.tilt_y.get()
}

fn PointerType(&self) -> DOMString {
self.pointer_type.clone()
}

fn IsPrimary(&self) -> bool {
self.is_primary.get()
}

// https://dom.spec.whatwg.org/#dom-event-istrusted
fn IsTrusted(&self) -> bool {
self.mouse_event.IsTrusted()
}
}
@@ -91,6 +91,7 @@ partial interface Element {
void scrollTo(unrestricted double x, unrestricted double y);
void scrollBy(optional ScrollToOptions options);
void scrollBy(unrestricted double x, unrestricted double y);

attribute unrestricted double scrollTop;
attribute unrestricted double scrollLeft;
readonly attribute long scrollWidth;
@@ -115,6 +116,17 @@ partial interface Element {
Promise<void> requestFullscreen();
};

// Extensions to the Element Interface
// https://www.w3.org/TR/pointerevents/#pointer-event-types
partial interface Element {
// void setPointerCapture(long pointerId);
// void releasePointerCapture(long pointerId);

// attribute EventHandler ongotpointercapture
// attribute EventHandler onLostPointerCapture

};

Element implements ChildNode;
Element implements NonDocumentTypeChildNode;
Element implements ParentNode;
@@ -94,6 +94,18 @@ partial interface GlobalEventHandlers {
attribute EventHandler ontransitionend;
};

// https://www.w3.org/TR/pointerevents/#extensions-to-the-globaleventhandlers-interface
partial interface GlobalEventHandlers {
attribute EventHandler onpointerdown;
attribute EventHandler onpointermove;
attribute EventHandler onpointerup;
attribute EventHandler onpointercancel;
attribute EventHandler onpointerover;
attribute EventHandler onpointerout;
attribute EventHandler onpointerenter;
attribute EventHandler onpointerleave;
};

// https://html.spec.whatwg.org/multipage/#windoweventhandlers
[NoInterfaceObject, Exposed=Window]
interface WindowEventHandlers {
@@ -68,3 +68,7 @@ partial interface Navigator {
partial interface Navigator {
[Pref="dom.permissions.enabled"] readonly attribute Permissions permissions;
};

partial interface Navigator {
readonly attribute long maxTouchPoints;
};
@@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://www.w3.org/TR/pointerevents/#pointer-events-and-interfaces
[Constructor(DOMString type, optional PointerEventInit eventInitDict)]
interface PointerEvent : MouseEvent {
readonly attribute long pointerId;
readonly attribute double width;
readonly attribute double height;
readonly attribute float pressure;
readonly attribute long tiltX;
readonly attribute long tiltY;
readonly attribute DOMString pointerType;
readonly attribute boolean isPrimary;
};

dictionary PointerEventInit : MouseEventInit {
long pointerId = 0;
double width = 0;
double height = 0;
float pressure = 0;
long tiltX = 0;
long tiltY = 0;
DOMString pointerType = "";
boolean isPrimary = false;
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.