gecko-dev/servo/components/script/dom/forcetouchevent.rs
Simon Sapin c08c32ca01 servo: Merge #18900 - Remove use of unstable box syntax (from servo:box_syntax); r=emilio
http://www.robohornet.org gives a score of 101.36 on master, and 102.68 with this PR. The latter is slightly better, but probably within noise level. So it looks like this PR does not affect DOM performance.

This is expected since `Box::new` is defined as:

```rust
impl<T> Box<T> {
    #[inline(always)]
    pub fn new(x: T) -> Box<T> {
        box x
    }
}
```

With inlining, it should compile to the same as box syntax.

Source-Repo: https://github.com/servo/servo
Source-Revision: a9022be0c3e30249845ca5947ac0c0a6743c7991

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 97a17674f72dbfcb99552fe4877789f149ccfc84
2017-10-16 11:21:21 -05:00

59 lines
1.8 KiB
Rust

/* 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::inheritance::Castable;
use dom::bindings::num::Finite;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::DomRoot;
use dom::bindings::str::DOMString;
use dom::uievent::UIEvent;
use dom::window::Window;
use dom_struct::dom_struct;
#[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) -> DomRoot<ForceTouchEvent> {
let event = Box::new(ForceTouchEvent::new_inherited(force));
let ev = reflect_dom_object(event, 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()
}
}