Update Event's timestamp

This commit is contained in:
George Roman 2019-03-26 09:38:22 +02:00
parent c9b5b8fad3
commit e63de4d52c
4 changed files with 16 additions and 15 deletions

View file

@ -6,8 +6,11 @@ use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::EventBinding; use crate::dom::bindings::codegen::Bindings::EventBinding;
use crate::dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethods}; use crate::dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethods};
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceBinding::PerformanceMethods;
use crate::dom::bindings::error::Fallible; use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, DomSlice, MutNullableDom}; use crate::dom::bindings::root::{DomRoot, DomSlice, MutNullableDom};
@ -21,6 +24,7 @@ use crate::dom::window::Window;
use crate::task::TaskOnce; use crate::task::TaskOnce;
use devtools_traits::{TimelineMarker, TimelineMarkerType}; use devtools_traits::{TimelineMarker, TimelineMarkerType};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use metrics::ToMs;
use servo_atoms::Atom; use servo_atoms::Atom;
use std::cell::Cell; use std::cell::Cell;
use std::default::Default; use std::default::Default;
@ -40,7 +44,7 @@ pub struct Event {
trusted: Cell<bool>, trusted: Cell<bool>,
dispatching: Cell<bool>, dispatching: Cell<bool>,
initialized: Cell<bool>, initialized: Cell<bool>,
timestamp: u64, precise_time_ns: u64,
} }
impl Event { impl Event {
@ -59,7 +63,7 @@ impl Event {
trusted: Cell::new(false), trusted: Cell::new(false),
dispatching: Cell::new(false), dispatching: Cell::new(false),
initialized: Cell::new(false), initialized: Cell::new(false),
timestamp: time::get_time().sec as u64, precise_time_ns: time::precise_time_ns(),
} }
} }
@ -322,8 +326,11 @@ impl EventMethods for Event {
} }
// https://dom.spec.whatwg.org/#dom-event-timestamp // https://dom.spec.whatwg.org/#dom-event-timestamp
fn TimeStamp(&self) -> u64 { fn TimeStamp(&self) -> DOMHighResTimeStamp {
self.timestamp Finite::wrap(
(self.precise_time_ns - (*self.global().performance().TimeOrigin()).round() as u64)
.to_ms(),
)
} }
// https://dom.spec.whatwg.org/#dom-event-initevent // https://dom.spec.whatwg.org/#dom-event-initevent

View file

@ -35,7 +35,7 @@ interface Event {
[Unforgeable] [Unforgeable]
readonly attribute boolean isTrusted; readonly attribute boolean isTrusted;
[Constant] [Constant]
readonly attribute DOMTimeStamp timeStamp; readonly attribute DOMHighResTimeStamp timeStamp;
void initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); void initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false);
}; };

View file

@ -3,18 +3,9 @@
[Untitled] [Untitled]
expected: FAIL expected: FAIL
[Constructed MouseEvent timestamp should be high resolution and have the same time origin as performance.now()]
expected: FAIL
[Constructed KeyboardEvent timestamp should be high resolution and have the same time origin as performance.now()]
expected: FAIL
[Constructed WheelEvent timestamp should be high resolution and have the same time origin as performance.now()] [Constructed WheelEvent timestamp should be high resolution and have the same time origin as performance.now()]
expected: FAIL expected: FAIL
[Constructed GamepadEvent timestamp should be high resolution and have the same time origin as performance.now()] [Constructed GamepadEvent timestamp should be high resolution and have the same time origin as performance.now()]
expected: FAIL expected: FAIL
[Constructed FocusEvent timestamp should be high resolution and have the same time origin as performance.now()]
expected: FAIL

View file

@ -1,3 +1,6 @@
[Event-timestamp-safe-resolution.html] [Event-timestamp-safe-resolution.html]
type: testharness type: testharness
expected: TIMEOUT
[Event timestamp should not have a resolution better than 5 microseconds]
expected: FAIL