-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This enables Apple forcetouch DOM events. It requires the preference dom.forcetouch.enabled. The DOM events are described here: - https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/RespondingtoForceTouchEventsfromJavaScript.html The Cocoa mechanism is documented here: - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/uid/20000016-SW274
- Loading branch information
1 parent
05a4dcd
commit df6e739
Showing
13 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* 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://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/RespondingtoForceTouchEventsfromJavaScript.html | ||
|
||
/** | ||
* Events: (copy/paste from apple.com) | ||
* | ||
* webkitmouseforcewillbegin: This event occurs immediately before the mousedown event. It allows you to | ||
* prevent the default system behavior, such as displaying a dictionary window when force clicking on a | ||
* word, in order to perform a custom action instead. To prevent the default system behavior, call the | ||
* preventDefault() method on the event. | ||
* webkitmouseforcedown: This event occurs after the mousedown event, once enough force has been applied | ||
* to register as a force click. The user receives haptic feedback representing the force click when this | ||
* event occurs. | ||
* webkitmouseforceup: This event occurs after a webkitmouseforcedown event, once enough force has been | ||
* released to exit the force click operation. The user receives haptic feedback representing the exit | ||
* from force click when this event occurs. | ||
* webkitmouseforcechanged: This event occurs whenever a change in trackpad force is detected between the | ||
* mousedown and mouseup events. | ||
* | ||
*/ | ||
|
||
|
||
[Pref="dom.forcetouch.enabled"] | ||
interface ForceTouchEvent : UIEvent { | ||
// Represents the amount of force required to perform a regular click. | ||
readonly attribute float SERVO_FORCE_AT_MOUSE_DOWN; | ||
// Represents the force required to perform a force click. | ||
readonly attribute float SERVO_FORCE_AT_FORCE_MOUSE_DOWN; | ||
// force level | ||
readonly attribute float servoForce; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.