From 4ed15a8853fc49d0940ed24d939fd0c407ee80a9 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 10 Aug 2015 20:55:19 -0700 Subject: Add bindings for TouchEvent DOM interfaces --- components/script/dom/touch.rs | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 components/script/dom/touch.rs (limited to 'components/script/dom/touch.rs') diff --git a/components/script/dom/touch.rs b/components/script/dom/touch.rs new file mode 100644 index 00000000000..7fc9f42e23d --- /dev/null +++ b/components/script/dom/touch.rs @@ -0,0 +1,80 @@ +/* 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::TouchBinding; +use dom::bindings::codegen::Bindings::TouchBinding::TouchMethods; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{JS, MutHeap, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::eventtarget::EventTarget; +use dom::window::Window; + +#[dom_struct] +pub struct Touch { + reflector_: Reflector, + identifier: i32, + target: MutHeap>, + screen_x: f64, + screen_y: f64, + client_x: f64, + client_y: f64, +} + +impl Touch { + fn new_inherited(identifier: i32, target: &EventTarget, + screen_x: Finite, screen_y: Finite, + client_x: Finite, client_y: Finite) -> Touch { + Touch { + reflector_: Reflector::new(), + identifier: identifier, + target: MutHeap::new(target), + screen_x: *screen_x, + screen_y: *screen_y, + client_x: *client_x, + client_y: *client_y, + } + } + + pub fn new(window: &Window, identifier: i32, target: &EventTarget, + screen_x: Finite, screen_y: Finite, + client_x: Finite, client_y: Finite) -> Root { + reflect_dom_object(box Touch::new_inherited(identifier, target, + screen_x, screen_y, + client_x, client_y), + GlobalRef::Window(window), TouchBinding::Wrap) + } +} + +impl TouchMethods for Touch { + /// https://w3c.github.io/touch-events/#widl-Touch-identifier + fn Identifier(&self) -> i32 { + self.identifier + } + + /// https://w3c.github.io/touch-events/#widl-Touch-target + fn Target(&self) -> Root { + self.target.get() + } + + /// https://w3c.github.io/touch-events/#widl-Touch-screenX + fn ScreenX(&self) -> Finite { + Finite::wrap(self.screen_x) + } + + /// https://w3c.github.io/touch-events/#widl-Touch-screenY + fn ScreenY(&self) -> Finite { + Finite::wrap(self.screen_y) + } + + /// https://w3c.github.io/touch-events/#widl-Touch-clientX + fn ClientX(&self) -> Finite { + Finite::wrap(self.client_x) + } + + /// https://w3c.github.io/touch-events/#widl-Touch-clientY + fn ClientY(&self) -> Finite { + Finite::wrap(self.client_y) + } +} -- cgit v1.2.3