Jacek Caban : mshtml: Added IDOMEvent::get_timeStamp implementation.

Alexandre Julliard julliard at winehq.org
Tue Dec 5 15:02:14 CST 2017


Module: wine
Branch: master
Commit: c0f96a406f13e1b94d57ae7aece5bacc5300ffd8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c0f96a406f13e1b94d57ae7aece5bacc5300ffd8

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Dec  5 18:24:46 2017 +0100

mshtml: Added IDOMEvent::get_timeStamp implementation.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/dispex.c        |  3 ++-
 dlls/mshtml/htmlevent.c     | 16 ++++++++++++++--
 dlls/mshtml/htmlevent.h     |  1 +
 dlls/mshtml/tests/events.js | 41 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/dlls/mshtml/dispex.c b/dlls/mshtml/dispex.c
index 64ad555..a46a0cd 100644
--- a/dlls/mshtml/dispex.c
+++ b/dlls/mshtml/dispex.c
@@ -219,7 +219,8 @@ HRESULT get_class_typeinfo(const CLSID *clsid, ITypeInfo **typeinfo)
     CASE_VT(VT_VARIANT, VARIANT, *);                    \
     CASE_VT(VT_PTR, void*, V_BYREF);                    \
     CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN);          \
-    CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH)
+    CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH);       \
+    CASE_VT(VT_UI8, ULONGLONG, V_UI8)
 
 static BOOL is_arg_type_supported(VARTYPE vt)
 {
diff --git a/dlls/mshtml/htmlevent.c b/dlls/mshtml/htmlevent.c
index 7a01ba5..cbb9954 100644
--- a/dlls/mshtml/htmlevent.c
+++ b/dlls/mshtml/htmlevent.c
@@ -1054,8 +1054,11 @@ static HRESULT WINAPI DOMEvent_get_target(IDOMEvent *iface, IEventTarget **p)
 static HRESULT WINAPI DOMEvent_get_timeStamp(IDOMEvent *iface, ULONGLONG *p)
 {
     DOMEvent *This = impl_from_IDOMEvent(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    *p = This->time_stamp;
+    return S_OK;
 }
 
 static HRESULT WINAPI DOMEvent_get_type(IDOMEvent *iface, BSTR *p)
@@ -1208,6 +1211,10 @@ static dispex_static_data_t DOMEvent_dispex = {
 static DOMEvent *alloc_event(nsIDOMEvent *nsevent, eventid_t event_id)
 {
     DOMEvent *event;
+    FILETIME time;
+
+    /* 1601 to 1970 is 369 years plus 89 leap days */
+    const ULONGLONG time_epoch = (ULONGLONG)(369 * 365 + 89) * 86400 * 1000;
 
     event = heap_alloc_zero(sizeof(*event));
     if(!event)
@@ -1227,6 +1234,11 @@ static DOMEvent *alloc_event(nsIDOMEvent *nsevent, eventid_t event_id)
         event->cancelable = (event_info[event_id].flags & EVENT_CANCELABLE) != 0;
     }
     nsIDOMEvent_AddRef(event->nsevent = nsevent);
+
+    GetSystemTimeAsFileTime(&time);
+    event->time_stamp = (((ULONGLONG)time.dwHighDateTime<<32) + time.dwLowDateTime) / 10000
+        - time_epoch;
+
     return event;
 }
 
diff --git a/dlls/mshtml/htmlevent.h b/dlls/mshtml/htmlevent.h
index 3775e44..0f1ac41 100644
--- a/dlls/mshtml/htmlevent.h
+++ b/dlls/mshtml/htmlevent.h
@@ -67,6 +67,7 @@ typedef struct {
     WCHAR *type;
     EventTarget *target;
     EventTarget *current_target;
+    ULONGLONG time_stamp;
     BOOL bubbles;
     BOOL cancelable;
     BOOL prevent_default;
diff --git a/dlls/mshtml/tests/events.js b/dlls/mshtml/tests/events.js
index fc68d8a..f7df4d8 100644
--- a/dlls/mshtml/tests/events.js
+++ b/dlls/mshtml/tests/events.js
@@ -295,10 +295,10 @@ function test_prevent_default() {
     var calls;
 
     div.addEventListener("click", function(e) {
-        calls += "div,";
         ok(e.defaultPrevented === false, "e.defaultPrevented = " + e.defaultPrevented);
         e.preventDefault();
         ok(e.defaultPrevented === e.cancelable, "e.defaultPrevented = " + e.defaultPrevented);
+        calls += "div,";
     }, true);
 
     a.addEventListener("click", function(e) {
@@ -551,6 +551,44 @@ function test_recursive_dispatch() {
     next_test();
 }
 
+function test_time_stamp() {
+    document.body.innerHTML = '<div></div>';
+    var elem = document.body.firstChild;
+    var calls, last_time_stamp;
+
+    elem.onclick = function(event) {
+        ok(event.timeStamp === last_time_stamp, "timeStamp = " + event.timeStamp);
+        calls++;
+    }
+
+    var e = document.createEvent("Event");
+    ok(typeof(e.timeStamp) === "number", "typeof(timeStamp) = " + typeof(e.timeStamp));
+    ok(e.timeStamp > 0, "timeStamp = " + e.timeStamp);
+
+    var now = (new Date()).getTime();
+    last_time_stamp = e.timeStamp;
+    ok(Math.abs(now - last_time_stamp) < 3, "timeStamp " + last_time_stamp + " != now " + now);
+
+    e.initEvent("click", true, true);
+    ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
+    calls = 0;
+    elem.dispatchEvent(e);
+    ok(calls === 1, "calls = " + calls);
+    ok(e.timeStamp === last_time_stamp, "timeStamp = " + e.timeStamp);
+
+    elem.onclick = function(event) {
+        ok(event.timeStamp > 0, "timeStamp = " + event.timeStamp);
+        trace("timestamp " + event.timeStamp);
+        calls++;
+    }
+
+    calls = 0;
+    elem.click();
+    ok(calls === 1, "calls = " + calls);
+
+    next_test();
+}
+
 var tests = [
     test_content_loaded,
     test_add_remove_listener,
@@ -563,5 +601,6 @@ var tests = [
     test_current_target,
     test_dispatch_event,
     test_recursive_dispatch,
+    test_time_stamp,
     test_listener_order
 ];




More information about the wine-cvs mailing list