diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-05 21:07:05 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-05 21:07:05 +0530 |
commit | 0ff8adb09778402e88fe0d0ad92f4b399ca8ca01 (patch) | |
tree | fd3403bb54587c41f953e00740be30058c94543d /components/script/dom/forcetouchevent.rs | |
parent | a8ed5c3fc66ab9ea57b6b78311485040dae27328 (diff) | |
parent | 0d529274a425f44b17a93d6823929eacb4ba96f2 (diff) | |
download | servo-0ff8adb09778402e88fe0d0ad92f4b399ca8ca01.tar.gz servo-0ff8adb09778402e88fe0d0ad92f4b399ca8ca01.zip |
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 -->
Diffstat (limited to 'components/script/dom/forcetouchevent.rs')
-rw-r--r-- | components/script/dom/forcetouchevent.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/components/script/dom/forcetouchevent.rs b/components/script/dom/forcetouchevent.rs new file mode 100644 index 00000000000..b0fd6376760 --- /dev/null +++ b/components/script/dom/forcetouchevent.rs @@ -0,0 +1,59 @@ +/* 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::ForceTouchEventBinding; +use dom::bindings::codegen::Bindings::ForceTouchEventBinding::ForceTouchEventMethods; +use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; +use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; +use dom::bindings::js::{Root}; +use dom::bindings::num::Finite; +use dom::bindings::reflector::reflect_dom_object; +use dom::uievent::UIEvent; +use dom::window::Window; +use util::str::DOMString; + +#[dom_struct] +pub struct ForceTouchEvent { + uievent: UIEvent, + force: f32, +} + +impl ForceTouchEvent { + fn new_inherited(force: f32) -> ForceTouchEvent { + ForceTouchEvent { + uievent: UIEvent::new_inherited(), + force: force, + } + } + + pub fn new(window: &Window, + type_: DOMString, + force: f32) -> Root<ForceTouchEvent> { + let event = box ForceTouchEvent::new_inherited(force); + let ev = reflect_dom_object(event, GlobalRef::Window(window), ForceTouchEventBinding::Wrap); + ev.upcast::<UIEvent>().InitUIEvent(type_, true, true, Some(window), 0); + ev + } +} + +impl<'a> ForceTouchEventMethods for &'a ForceTouchEvent { + + fn ServoForce(&self) -> Finite<f32> { + Finite::wrap(self.force) + } + + fn SERVO_FORCE_AT_MOUSE_DOWN(&self) -> Finite<f32> { + Finite::wrap(1.0) + } + + fn SERVO_FORCE_AT_FORCE_MOUSE_DOWN(&self) -> Finite<f32> { + Finite::wrap(2.0) + } + + // https://dom.spec.whatwg.org/#dom-event-istrusted + fn IsTrusted(&self) -> bool { + self.uievent.IsTrusted() + } +} |