Title: [223023] trunk
Revision
223023
Author
[email protected]
Date
2017-10-07 16:44:45 -0700 (Sat, 07 Oct 2017)

Log Message

Update Document.createEvent for recent DOM specification changes
https://bugs.webkit.org/show_bug.cgi?id=178052

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt: Updated to expect more tests to pass.
* web-platform-tests/dom/nodes/Document-createEvent-expected.txt: Ditto.
* web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt: Ditto.

Source/WebCore:

* dom/BeforeUnloadEvent.cpp:
(WebCore::BeforeUnloadEvent::BeforeUnloadEvent): Added a constructor for
createForBindings.
(WebCore::BeforeUnloadEvent::~BeforeUnloadEvent): Deleted. Just let the
compiler generate this.
* dom/BeforeUnloadEvent.h: Added createForBindings. Also made more things private.

* dom/Document.cpp:
(WebCore::Document::createEvent): Updated comments for clarity. Responding to
changes to the DOM specification, added support for "beforeunloadevent", "focusevent",
and "svgevents", moved "keyboardevents" and "popstateevent" into the list of strings
we should remove, and moved "compositionevent", "devicemotionevent",
"deviceorientationevent", "hashchangeevent", "storageevent", and "textevent" into
the list of strings we should keep.

* dom/Event.h: Added a virtual setRelatedTarget alongside the virtual relatedTarget
to allow us to clean up the code that manipulates it.

* dom/EventContext.cpp:
(WebCore::MouseOrFocusEventContext::handleLocalEvents const): Call the virtual
setRelatedTarget instead of doing a little type casting dance.

* dom/FocusEvent.h: Added createForBindings. Made more functions private and
changed setRelatedTarget into a private final override.

* dom/MouseEvent.h: Changed setRelatedTarget into a private final override.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (223022 => 223023)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-10-07 23:44:45 UTC (rev 223023)
@@ -1,3 +1,14 @@
+2017-10-07  Darin Adler  <[email protected]>
+
+        Update Document.createEvent for recent DOM specification changes
+        https://bugs.webkit.org/show_bug.cgi?id=178052
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt: Updated to expect more tests to pass.
+        * web-platform-tests/dom/nodes/Document-createEvent-expected.txt: Ditto.
+        * web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt: Ditto.
+
 2017-10-07  Andy Estes  <[email protected]>
 
         [Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt (223022 => 223023)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt	2017-10-07 23:44:45 UTC (rev 223023)
@@ -1,7 +1,7 @@
 CONSOLE MESSAGE: line 60: Error
 
 PASS Calling dispatchEvent(null). 
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (BeforeUnloadEvent). The operation is not supported.
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (BeforeUnloadEvent). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (CompositionEvent). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (CustomEvent). 
 FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (DeviceMotionEvent). The operation is not supported.
@@ -9,7 +9,7 @@
 FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (DragEvent). The operation is not supported.
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (Event). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (Events). 
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (FocusEvent). The operation is not supported.
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (FocusEvent). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (HashChangeEvent). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (HTMLEvents). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (KeyboardEvent). 
@@ -17,7 +17,7 @@
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvent). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (MouseEvents). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (StorageEvent). 
-FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (SVGEvents). The operation is not supported.
+PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (SVGEvents). 
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (TextEvent). 
 FAIL If the event's initialized flag is not set, an InvalidStateError must be thrown (TouchEvent). The operation is not supported.
 PASS If the event's initialized flag is not set, an InvalidStateError must be thrown (UIEvent). 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt (223022 => 223023)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt	2017-10-07 23:44:45 UTC (rev 223023)
@@ -1,10 +1,10 @@
 
-FAIL BeforeUnloadEvent should be an alias for BeforeUnloadEvent. The operation is not supported.
-FAIL createEvent('BeforeUnloadEvent') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL beforeunloadevent should be an alias for BeforeUnloadEvent. The operation is not supported.
-FAIL createEvent('beforeunloadevent') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL BEFOREUNLOADEVENT should be an alias for BeforeUnloadEvent. The operation is not supported.
-FAIL createEvent('BEFOREUNLOADEVENT') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
+PASS BeforeUnloadEvent should be an alias for BeforeUnloadEvent. 
+PASS createEvent('BeforeUnloadEvent') should be initialized correctly. 
+PASS beforeunloadevent should be an alias for BeforeUnloadEvent. 
+PASS createEvent('beforeunloadevent') should be initialized correctly. 
+PASS BEFOREUNLOADEVENT should be an alias for BeforeUnloadEvent. 
+PASS createEvent('BEFOREUNLOADEVENT') should be initialized correctly. 
 PASS Should throw NOT_SUPPORTED_ERR for pluralized legacy event interface "BeforeUnloadEvents" 
 PASS CompositionEvent should be an alias for CompositionEvent. 
 PASS createEvent('CompositionEvent') should be initialized correctly. 
@@ -53,12 +53,12 @@
 PASS createEvent('events') should be initialized correctly. 
 PASS EVENTS should be an alias for Event. 
 PASS createEvent('EVENTS') should be initialized correctly. 
-FAIL FocusEvent should be an alias for FocusEvent. The operation is not supported.
-FAIL createEvent('FocusEvent') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL focusevent should be an alias for FocusEvent. The operation is not supported.
-FAIL createEvent('focusevent') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL FOCUSEVENT should be an alias for FocusEvent. The operation is not supported.
-FAIL createEvent('FOCUSEVENT') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
+PASS FocusEvent should be an alias for FocusEvent. 
+PASS createEvent('FocusEvent') should be initialized correctly. 
+PASS focusevent should be an alias for FocusEvent. 
+PASS createEvent('focusevent') should be initialized correctly. 
+PASS FOCUSEVENT should be an alias for FocusEvent. 
+PASS createEvent('FOCUSEVENT') should be initialized correctly. 
 PASS Should throw NOT_SUPPORTED_ERR for pluralized legacy event interface "FocusEvents" 
 PASS HashChangeEvent should be an alias for HashChangeEvent. 
 PASS createEvent('HashChangeEvent') should be initialized correctly. 
@@ -108,12 +108,12 @@
 PASS STORAGEEVENT should be an alias for StorageEvent. 
 PASS createEvent('STORAGEEVENT') should be initialized correctly. 
 PASS Should throw NOT_SUPPORTED_ERR for pluralized legacy event interface "StorageEvents" 
-FAIL SVGEvents should be an alias for Event. The operation is not supported.
-FAIL createEvent('SVGEvents') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL svgevents should be an alias for Event. The operation is not supported.
-FAIL createEvent('svgevents') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
-FAIL SVGEVENTS should be an alias for Event. The operation is not supported.
-FAIL createEvent('SVGEVENTS') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
+PASS SVGEvents should be an alias for Event. 
+PASS createEvent('SVGEvents') should be initialized correctly. 
+PASS svgevents should be an alias for Event. 
+PASS createEvent('svgevents') should be initialized correctly. 
+PASS SVGEVENTS should be an alias for Event. 
+PASS createEvent('SVGEVENTS') should be initialized correctly. 
 FAIL TextEvent should be an alias for CompositionEvent. assert_equals: expected object "[object CompositionEventPrototype]" but got object "[object TextEventPrototype]"
 PASS createEvent('TextEvent') should be initialized correctly. 
 FAIL textevent should be an alias for CompositionEvent. assert_equals: expected object "[object CompositionEventPrototype]" but got object "[object TextEventPrototype]"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt (223022 => 223023)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling-expected.txt	2017-10-07 23:44:45 UTC (rev 223023)
@@ -2,7 +2,7 @@
 PASS Returning a string must not cancel the event: CustomEvent, non-cancelable 
 PASS Returning a string must not cancel the event: CustomEvent, cancelable 
 FAIL Returning false must not cancel the event, because it's coerced to the DOMString "false" which does not cancel CustomEvents: CustomEvent, cancelable assert_false: The event must not have been canceled expected false got true
-FAIL Returning a string must not cancel the event: BeforeUnloadEvent with type "click", cancelable The operation is not supported.
+PASS Returning a string must not cancel the event: BeforeUnloadEvent with type "click", cancelable 
 PASS Returning null with a real iframe unloading 
 PASS Returning undefined with a real iframe unloading 
 PASS Returning  with a real iframe unloading 

Modified: trunk/Source/WebCore/ChangeLog (223022 => 223023)


--- trunk/Source/WebCore/ChangeLog	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/ChangeLog	2017-10-07 23:44:45 UTC (rev 223023)
@@ -1,3 +1,37 @@
+2017-10-07  Darin Adler  <[email protected]>
+
+        Update Document.createEvent for recent DOM specification changes
+        https://bugs.webkit.org/show_bug.cgi?id=178052
+
+        Reviewed by Chris Dumez.
+
+        * dom/BeforeUnloadEvent.cpp:
+        (WebCore::BeforeUnloadEvent::BeforeUnloadEvent): Added a constructor for
+        createForBindings.
+        (WebCore::BeforeUnloadEvent::~BeforeUnloadEvent): Deleted. Just let the
+        compiler generate this.
+        * dom/BeforeUnloadEvent.h: Added createForBindings. Also made more things private.
+
+        * dom/Document.cpp:
+        (WebCore::Document::createEvent): Updated comments for clarity. Responding to
+        changes to the DOM specification, added support for "beforeunloadevent", "focusevent",
+        and "svgevents", moved "keyboardevents" and "popstateevent" into the list of strings
+        we should remove, and moved "compositionevent", "devicemotionevent",
+        "deviceorientationevent", "hashchangeevent", "storageevent", and "textevent" into
+        the list of strings we should keep.
+
+        * dom/Event.h: Added a virtual setRelatedTarget alongside the virtual relatedTarget
+        to allow us to clean up the code that manipulates it.
+
+        * dom/EventContext.cpp:
+        (WebCore::MouseOrFocusEventContext::handleLocalEvents const): Call the virtual
+        setRelatedTarget instead of doing a little type casting dance.
+
+        * dom/FocusEvent.h: Added createForBindings. Made more functions private and
+        changed setRelatedTarget into a private final override.
+
+        * dom/MouseEvent.h: Changed setRelatedTarget into a private final override.
+
 2017-10-07  Andy Estes  <[email protected]>
 
         [Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()

Modified: trunk/Source/WebCore/dom/BeforeUnloadEvent.cpp (223022 => 223023)


--- trunk/Source/WebCore/dom/BeforeUnloadEvent.cpp	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/BeforeUnloadEvent.cpp	2017-10-07 23:44:45 UTC (rev 223023)
@@ -32,13 +32,13 @@
 {
 }
 
-bool BeforeUnloadEvent::isBeforeUnloadEvent() const
+BeforeUnloadEvent::BeforeUnloadEvent(ForBindingsFlag)
 {
-    return true;
 }
 
-BeforeUnloadEvent::~BeforeUnloadEvent()
+bool BeforeUnloadEvent::isBeforeUnloadEvent() const
 {
+    return true;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/BeforeUnloadEvent.h (223022 => 223023)


--- trunk/Source/WebCore/dom/BeforeUnloadEvent.h	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/BeforeUnloadEvent.h	2017-10-07 23:44:45 UTC (rev 223023)
@@ -2,7 +2,7 @@
  * Copyright (C) 2001 Peter Kelly ([email protected])
  * Copyright (C) 2001 Tobias Anton ([email protected])
  * Copyright (C) 2006 Samuel Weinig ([email protected])
- * Copyright (C) 2003, 2004, 2005, 2006 Apple Inc.
+ * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
  * Copyright (C) 2013 Samsung Electronics
  *
  * This library is free software; you can redistribute it and/or
@@ -30,22 +30,26 @@
 
 class BeforeUnloadEvent final : public Event {
 public:
-    virtual ~BeforeUnloadEvent();
-
     static Ref<BeforeUnloadEvent> create()
     {
         return adoptRef(*new BeforeUnloadEvent);
     }
 
+    static Ref<BeforeUnloadEvent> createForBindings()
+    {
+        return adoptRef(*new BeforeUnloadEvent { ForBindings });
+    }
+
     String returnValue() const { return m_returnValue; }
     void setReturnValue(const String& returnValue) { m_returnValue = returnValue; }
 
-    EventInterface eventInterface() const override { return BeforeUnloadEventInterfaceType; }
-
 private:
+    enum ForBindingsFlag { ForBindings };
     BeforeUnloadEvent();
+    BeforeUnloadEvent(ForBindingsFlag);
 
-    bool isBeforeUnloadEvent() const override;
+    EventInterface eventInterface() const final { return BeforeUnloadEventInterfaceType; }
+    bool isBeforeUnloadEvent() const final;
 
     String m_returnValue;
 };

Modified: trunk/Source/WebCore/dom/Document.cpp (223022 => 223023)


--- trunk/Source/WebCore/dom/Document.cpp	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/Document.cpp	2017-10-07 23:44:45 UTC (rev 223023)
@@ -30,6 +30,7 @@
 
 #include "AXObjectCache.h"
 #include "Attr.h"
+#include "BeforeUnloadEvent.h"
 #include "CDATASection.h"
 #include "CSSAnimationController.h"
 #include "CSSFontSelector.h"
@@ -64,6 +65,7 @@
 #include "EventHandler.h"
 #include "ExtensionStyleSheets.h"
 #include "FocusController.h"
+#include "FocusEvent.h"
 #include "FontFaceSet.h"
 #include "FormController.h"
 #include "FrameLoader.h"
@@ -4259,8 +4261,8 @@
 
 ExceptionOr<Ref<Event>> Document::createEvent(const String& type)
 {
-    // Please do *not* add new event classes to this function unless they are
-    // required for compatibility of some actual legacy web content.
+    // Please do *not* add new event classes to this function unless they are required
+    // for compatibility with the DOM specification or some actual legacy web content.
 
     // This mechanism is superceded by use of event constructors.
     // That is what we should use for any new event classes.
@@ -4268,64 +4270,73 @@
     // The following strings are the ones from the DOM specification
     // <https://dom.spec.whatwg.org/#dom-document-createevent>.
 
+    if (equalLettersIgnoringASCIICase(type, "beforeunloadevent"))
+        return Ref<Event> { BeforeUnloadEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "compositionevent"))
+        return Ref<Event> { CompositionEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "customevent"))
         return Ref<Event> { CustomEvent::create() };
-    if (equalLettersIgnoringASCIICase(type, "event") || equalLettersIgnoringASCIICase(type, "events") || equalLettersIgnoringASCIICase(type, "htmlevents"))
+    if (equalLettersIgnoringASCIICase(type, "event") || equalLettersIgnoringASCIICase(type, "events") || equalLettersIgnoringASCIICase(type, "htmlevents") || equalLettersIgnoringASCIICase(type, "svgevents"))
         return Event::createForBindings();
-    if (equalLettersIgnoringASCIICase(type, "keyboardevent") || equalLettersIgnoringASCIICase(type, "keyboardevents"))
+    if (equalLettersIgnoringASCIICase(type, "focusevent"))
+        return Ref<Event> { FocusEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "hashchangeevent"))
+        return Ref<Event> { HashChangeEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "keyboardevent"))
         return Ref<Event> { KeyboardEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "messageevent"))
         return Ref<Event> { MessageEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "storageevent"))
+        return Ref<Event> { StorageEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "mouseevent") || equalLettersIgnoringASCIICase(type, "mouseevents"))
         return Ref<Event> { MouseEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "textevent"))
+        return Ref<Event> { TextEvent::createForBindings() }; // FIXME: HTML specification says this should create a CompositionEvent, not a TextEvent.
     if (equalLettersIgnoringASCIICase(type, "uievent") || equalLettersIgnoringASCIICase(type, "uievents"))
         return Ref<Event> { UIEvent::createForBindings() };
-    if (equalLettersIgnoringASCIICase(type, "popstateevent"))
-        return Ref<Event> { PopStateEvent::createForBindings() };
 
+    // FIXME: Consider including support for these event classes even when device orientation
+    // support is not enabled.
+#if ENABLE(DEVICE_ORIENTATION)
+    if (equalLettersIgnoringASCIICase(type, "devicemotionevent"))
+        return Ref<Event> { DeviceMotionEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "deviceorientationevent"))
+        return Ref<Event> { DeviceOrientationEvent::createForBindings() };
+#endif
+
 #if ENABLE(TOUCH_EVENTS)
     if (equalLettersIgnoringASCIICase(type, "touchevent"))
         return Ref<Event> { TouchEvent::createForBindings() };
 #endif
 
-    // The following string comes from the SVG specifications
+    // FIXME: Add support for "dragevent", which the DOM specification calls for.
+
+    // The following string comes from the SVG specification
     // <http://www.w3.org/TR/SVG/script.html#InterfaceSVGZoomEvent>
-    // <http://www.w3.org/TR/SVG2/interact.html#InterfaceSVGZoomEvent>.
     // However, since there is no provision for initializing the event once it is created,
     // there is no practical value in this feature.
+    // FIXME: Confirm there is no content depending on this and remove it.
 
     if (equalLettersIgnoringASCIICase(type, "svgzoomevents"))
         return Ref<Event> { SVGZoomEvent::createForBindings() };
 
-    // The following strings are for event classes where WebKit supplies an init function.
-    // These strings are not part of the DOM specification and we would like to eliminate them.
-    // However, we currently include these because we have concerns about backward compatibility.
+    // The following strings are not part of the DOM specification and we would like to eliminate them.
+    // However, we currently include them until we resolve any issues with backward compatibility.
+    // FIXME: For each of the strings below, confirm that there is no content depending on it and remove
+    // the string, remove the createForBindings function, and also consider removing the corresponding
+    // init function for that class.
 
-    // FIXME: For each of the strings below, prove there is no content depending on it and remove
-    // both the string and the corresponding init function for that class.
-
-    if (equalLettersIgnoringASCIICase(type, "compositionevent"))
-        return Ref<Event> { CompositionEvent::createForBindings() };
-    if (equalLettersIgnoringASCIICase(type, "hashchangeevent"))
-        return Ref<Event> { HashChangeEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "keyboardevents"))
+        return Ref<Event> { KeyboardEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "mutationevent") || equalLettersIgnoringASCIICase(type, "mutationevents"))
         return Ref<Event> { MutationEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "overflowevent"))
         return Ref<Event> { OverflowEvent::createForBindings() };
-    if (equalLettersIgnoringASCIICase(type, "storageevent"))
-        return Ref<Event> { StorageEvent::createForBindings() };
-    if (equalLettersIgnoringASCIICase(type, "textevent"))
-        return Ref<Event> { TextEvent::createForBindings() };
+    if (equalLettersIgnoringASCIICase(type, "popstateevent"))
+        return Ref<Event> { PopStateEvent::createForBindings() };
     if (equalLettersIgnoringASCIICase(type, "wheelevent"))
         return Ref<Event> { WheelEvent::createForBindings() };
 
-#if ENABLE(DEVICE_ORIENTATION)
-    if (equalLettersIgnoringASCIICase(type, "devicemotionevent"))
-        return Ref<Event> { DeviceMotionEvent::createForBindings() };
-    if (equalLettersIgnoringASCIICase(type, "deviceorientationevent"))
-        return Ref<Event> { DeviceOrientationEvent::createForBindings() };
-#endif
-
     return Exception { NotSupportedError };
 }
 

Modified: trunk/Source/WebCore/dom/Event.h (223022 => 223023)


--- trunk/Source/WebCore/dom/Event.h	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/Event.h	2017-10-07 23:44:45 UTC (rev 223023)
@@ -168,6 +168,7 @@
     bool isBeingDispatched() const { return eventPhase(); }
 
     virtual EventTarget* relatedTarget() const { return nullptr; }
+    virtual void setRelatedTarget(EventTarget&) { }
 
 protected:
     Event(IsTrusted = IsTrusted::No);

Modified: trunk/Source/WebCore/dom/EventContext.cpp (223022 => 223023)


--- trunk/Source/WebCore/dom/EventContext.cpp	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/EventContext.cpp	2017-10-07 23:44:45 UTC (rev 223023)
@@ -75,13 +75,8 @@
 
 void MouseOrFocusEventContext::handleLocalEvents(Event& event) const
 {
-    ASSERT(is<MouseEvent>(event) || is<FocusEvent>(event));
-    if (m_relatedTarget) {
-        if (is<MouseEvent>(event))
-            downcast<MouseEvent>(event).setRelatedTarget(m_relatedTarget.get());
-        else if (is<FocusEvent>(event))
-            downcast<FocusEvent>(event).setRelatedTarget(m_relatedTarget.get());
-    }
+    if (m_relatedTarget)
+        event.setRelatedTarget(*m_relatedTarget);
     EventContext::handleLocalEvents(event);
 }
 

Modified: trunk/Source/WebCore/dom/FocusEvent.h (223022 => 223023)


--- trunk/Source/WebCore/dom/FocusEvent.h	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/FocusEvent.h	2017-10-07 23:44:45 UTC (rev 223023)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -39,6 +40,11 @@
         return adoptRef(*new FocusEvent(type, canBubble, cancelable, view, detail, WTFMove(relatedTarget)));
     }
 
+    static Ref<FocusEvent> createForBindings()
+    {
+        return adoptRef(*new FocusEvent);
+    }
+
     struct Init : UIEventInit {
         RefPtr<EventTarget> relatedTarget;
     };
@@ -48,17 +54,18 @@
         return adoptRef(*new FocusEvent(type, initializer, isTrusted));
     }
 
-    EventTarget* relatedTarget() const override { return m_relatedTarget.get(); }
-    void setRelatedTarget(RefPtr<EventTarget>&& relatedTarget) { m_relatedTarget = WTFMove(relatedTarget); }
+    EventTarget* relatedTarget() const final { return m_relatedTarget.get(); }
 
-    EventInterface eventInterface() const override;
-
 private:
+    FocusEvent() = default;
     FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow*, int, RefPtr<EventTarget>&&);
     FocusEvent(const AtomicString& type, const Init&, IsTrusted);
 
-    bool isFocusEvent() const override;
+    EventInterface eventInterface() const final;
+    bool isFocusEvent() const final;
 
+    void setRelatedTarget(EventTarget& relatedTarget) final { m_relatedTarget = &relatedTarget; }
+
     RefPtr<EventTarget> m_relatedTarget;
 };
 

Modified: trunk/Source/WebCore/dom/MouseEvent.h (223022 => 223023)


--- trunk/Source/WebCore/dom/MouseEvent.h	2017-10-07 21:16:24 UTC (rev 223022)
+++ trunk/Source/WebCore/dom/MouseEvent.h	2017-10-07 23:44:45 UTC (rev 223023)
@@ -57,7 +57,6 @@
     unsigned short syntheticClickType() const { return m_syntheticClickType; }
     bool buttonDown() const { return m_buttonDown; }
     EventTarget* relatedTarget() const final { return m_relatedTarget.get(); }
-    void setRelatedTarget(EventTarget* relatedTarget) { m_relatedTarget = relatedTarget; }
     double force() const { return m_force; }
     void setForce(double force) { m_force = force; }
 
@@ -94,6 +93,8 @@
 
     bool isDragEvent() const;
 
+    void setRelatedTarget(EventTarget& relatedTarget) final { m_relatedTarget = &relatedTarget; }
+
     unsigned short m_button { 0 };
     unsigned short m_syntheticClickType { 0 };
     bool m_buttonDown { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to