Force events should not require preventDefault in order to fire
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2015 18:25:25 +0000 (18:25 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2015 18:25:25 +0000 (18:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143503
-and corresponding-
rdar://problem/20458916

Reviewed by Tim Horton.

Source/WebCore:

Since these events will fire whether or not preventDefault was set on the
willBegin event, we should make sure we only send them when there are registered
event listeners. These are new events, so we don’t want to spam the vast majority
of web content that doesn’t use them yet.
* dom/Document.cpp:
(WebCore::Document::addListenerTypeIfNeeded):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::dispatchMouseForceWillBegin):
(WebCore::Element::dispatchMouseForceChanged):
(WebCore::Element::dispatchMouseForceDown):
(WebCore::Element::dispatchMouseForceUp):
(WebCore::Element::dispatchMouseForceClick):
(WebCore::Element::dispatchMouseForceCancelled):

Source/WebKit2:

We no longer need m_lastActionMenuHitTestPreventsDefault since we’ll always
dispatch the events to Element.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performActionMenuHitTestAtLocation):
(WebKit::WebPage::inputDeviceForceDidChange):
(WebKit::WebPage::immediateActionDidCancel):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182556 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index dbc5c273afc4c489c754c7b07bb92a99bbdfecf2..392e1f61b0d195f460a13ac78345133ac6dc71cb 100644 (file)
@@ -1,3 +1,27 @@
+2015-04-08  Beth Dakin  <bdakin@apple.com>
+
+        Force events should not require preventDefault in order to fire
+        https://bugs.webkit.org/show_bug.cgi?id=143503
+        -and corresponding-
+        rdar://problem/20458916
+
+        Reviewed by Tim Horton.
+
+        Since these events will fire whether or not preventDefault was set on the 
+        willBegin event, we should make sure we only send them when there are registered 
+        event listeners. These are new events, so we don’t want to spam the vast majority 
+        of web content that doesn’t use them yet.
+        * dom/Document.cpp:
+        (WebCore::Document::addListenerTypeIfNeeded):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::dispatchMouseForceWillBegin):
+        (WebCore::Element::dispatchMouseForceChanged):
+        (WebCore::Element::dispatchMouseForceDown):
+        (WebCore::Element::dispatchMouseForceUp):
+        (WebCore::Element::dispatchMouseForceClick):
+        (WebCore::Element::dispatchMouseForceCancelled):
+
 2015-04-08  Jer Noble  <jer.noble@apple.com>
 
         [Mac][WebAudio] Update the AVAudioMix in the AudioSourceProviderAVFObjC when the list of enabled audio tracks change.
index 2424b7518fe3257fabc30ad38cc026b2e1024506..36571e4de9156ff75226fb7a73fdaa6b3dd2c148 100644 (file)
@@ -3999,6 +3999,18 @@ void Document::addListenerTypeIfNeeded(const AtomicString& eventType)
         addListenerType(BEFORELOAD_LISTENER);
     else if (eventType == eventNames().scrollEvent)
         addListenerType(SCROLL_LISTENER);
+    else if (eventType == eventNames().webkitmouseforcewillbeginEvent)
+        addListenerType(FORCEWILLBEGIN_LISTENER);
+    else if (eventType == eventNames().webkitmouseforcechangedEvent)
+        addListenerType(FORCECHANGED_LISTENER);
+    else if (eventType == eventNames().webkitmouseforcedownEvent)
+        addListenerType(FORCEDOWN_LISTENER);
+    else if (eventType == eventNames().webkitmouseforceupEvent)
+        addListenerType(FORCEUP_LISTENER);
+    else if (eventType == eventNames().webkitmouseforceclickEvent)
+        addListenerType(FORCECLICK_LISTENER);
+    else if (eventType == eventNames().webkitmouseforcecancelledEvent)
+        addListenerType(FORCECANCELLED_LISTENER);
 }
 
 CSSStyleDeclaration* Document::getOverrideStyle(Element*, const String&)
index 5b644c0a38bd079f5d545b4694cc091855272c88..2649d9519002240432cebe37baaae2748cad5a3c 100644 (file)
@@ -770,8 +770,13 @@ public:
         ANIMATIONITERATION_LISTENER          = 1 << 9,
         TRANSITIONEND_LISTENER               = 1 << 10,
         BEFORELOAD_LISTENER                  = 1 << 11,
-        SCROLL_LISTENER                      = 1 << 12
-        // 3 bits remaining
+        SCROLL_LISTENER                      = 1 << 12,
+        FORCEWILLBEGIN_LISTENER              = 1 << 13,
+        FORCECHANGED_LISTENER                = 1 << 14,
+        FORCEDOWN_LISTENER                   = 1 << 15,
+        FORCEUP_LISTENER                     = 1 << 16,
+        FORCECLICK_LISTENER                  = 1 << 17,
+        FORCECANCELLED_LISTENER              = 1 << 18
     };
 
     bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
@@ -1400,7 +1405,7 @@ private:
     HashSet<NodeIterator*> m_nodeIterators;
     HashSet<Range*> m_ranges;
 
-    unsigned short m_listenerTypes;
+    unsigned m_listenerTypes;
 
     MutationObserverOptions m_mutationObserverTypes;
 
index 14038feb99169ed23fce727430735fbb68353033..5148f3573a8cb097e149da60e278555403cfb4ca 100644 (file)
@@ -2237,6 +2237,9 @@ void Element::dispatchBlurEvent(RefPtr<Element>&& newFocusedElement)
 #if ENABLE(MOUSE_FORCE_EVENTS)
 bool Element::dispatchMouseForceWillBegin()
 {
+    if (!document().hasListenerType(Document::FORCEWILLBEGIN_LISTENER))
+        return false;
+
     Frame* frame = document().frame();
     if (!frame)
         return false;
@@ -2253,6 +2256,9 @@ bool Element::dispatchMouseForceWillBegin()
 
 void Element::dispatchMouseForceChanged(float force, const PlatformMouseEvent& platformMouseEvent)
 {
+    if (!document().hasListenerType(Document::FORCECHANGED_LISTENER))
+        return;
+
     RefPtr<WebKitMouseForceEvent> mouseForceChangedEvent = WebKitMouseForceEvent::create(eventNames().webkitmouseforcechangedEvent, force, platformMouseEvent, document().defaultView());
     mouseForceChangedEvent->setTarget(this);
     dispatchEvent(mouseForceChangedEvent);
@@ -2260,6 +2266,9 @@ void Element::dispatchMouseForceChanged(float force, const PlatformMouseEvent& p
 
 void Element::dispatchMouseForceDown(const PlatformMouseEvent& platformMouseEvent)
 {
+    if (!document().hasListenerType(Document::FORCEDOWN_LISTENER))
+        return;
+
     RefPtr<Event> mouseForceDownEvent = WebKitMouseForceEvent::create(eventNames().webkitmouseforcedownEvent, 1, platformMouseEvent, document().defaultView());
     mouseForceDownEvent->setTarget(this);
     dispatchEvent(mouseForceDownEvent);
@@ -2267,6 +2276,9 @@ void Element::dispatchMouseForceDown(const PlatformMouseEvent& platformMouseEven
 
 void Element::dispatchMouseForceUp(const PlatformMouseEvent& platformMouseEvent)
 {
+    if (!document().hasListenerType(Document::FORCEUP_LISTENER))
+        return;
+
     RefPtr<Event> mouseForceUpEvent = WebKitMouseForceEvent::create(eventNames().webkitmouseforceupEvent, 1, platformMouseEvent, document().defaultView());
     mouseForceUpEvent->setTarget(this);
     dispatchEvent(mouseForceUpEvent);
@@ -2274,6 +2286,9 @@ void Element::dispatchMouseForceUp(const PlatformMouseEvent& platformMouseEvent)
 
 void Element::dispatchMouseForceClick(const PlatformMouseEvent& platformMouseEvent)
 {
+    if (!document().hasListenerType(Document::FORCECLICK_LISTENER))
+        return;
+
     RefPtr<Event> mouseForceClickEvent = WebKitMouseForceEvent::create(eventNames().webkitmouseforceclickEvent, 1, platformMouseEvent, document().defaultView());
     mouseForceClickEvent->setTarget(this);
     dispatchEvent(mouseForceClickEvent);
@@ -2281,6 +2296,9 @@ void Element::dispatchMouseForceClick(const PlatformMouseEvent& platformMouseEve
 
 void Element::dispatchMouseForceCancelled(const PlatformMouseEvent& platformMouseEvent)
 {
+    if (!document().hasListenerType(Document::FORCECANCELLED_LISTENER))
+        return;
+
     RefPtr<Event> mouseForceCancelledEvent = WebKitMouseForceEvent::create(eventNames().webkitmouseforcecancelledEvent, 0, platformMouseEvent, document().defaultView());
     mouseForceCancelledEvent->setTarget(this);
     dispatchEvent(mouseForceCancelledEvent);
index 2b8ac4502bddcd60571b3d226aa6a8de5d70bd18..d086bc24c4df84a7af4c4a08ac1ca1ae3fdee169 100644 (file)
@@ -1,3 +1,22 @@
+2015-04-08  Beth Dakin  <bdakin@apple.com>
+
+        Force events should not require preventDefault in order to fire
+        https://bugs.webkit.org/show_bug.cgi?id=143503
+        -and corresponding-
+        rdar://problem/20458916
+
+        Reviewed by Tim Horton.
+
+        We no longer need m_lastActionMenuHitTestPreventsDefault since we’ll always 
+        dispatch the events to Element.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        (WebKit::WebPage::inputDeviceForceDidChange):
+        (WebKit::WebPage::immediateActionDidCancel):
+
 2015-04-08  Enrica Casucci  <enrica@apple.com>
 
         Calling makeFirstResponder on WKWebView doesn't work.
index 72e429b31a78041f4285ee99772921ac2fef7aaf..5bd73a79e642dc7bc7094ef953a046a24a5bee13 100644 (file)
@@ -339,9 +339,6 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_pendingNavigationID(0)
 #if ENABLE(WEBGL)
     , m_systemWebGLPolicy(WebGLAllowCreation)
-#endif
-#if PLATFORM(MAC)
-    , m_lastActionMenuHitTestPreventsDefault(false)
 #endif
     , m_mainFrameProgressCompleted(false)
     , m_shouldDispatchFakeMouseMoveEvents(true)
index c3a6385004bc54cf7f66b196335cd3bdd7f0da5d..5302b7d1418157bfc0125ea33b524e7d7e363090 100644 (file)
@@ -1348,7 +1348,6 @@ private:
     RefPtr<WebCore::Range> m_lastActionMenuRangeForSelection;
     WebCore::HitTestResult m_lastActionMenuHitTestResult;
     RefPtr<WebPageOverlay> m_lastActionMenuHitPageOverlay;
-    bool m_lastActionMenuHitTestPreventsDefault;
     int m_lastForceStage { 0 };
 #endif
 
index 08bb62f1fb27d92150bb971f4d801b2d5b7fc17f..fe121342448db5725c124031fdc313041f9d7986 100644 (file)
@@ -1024,13 +1024,13 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
     IntPoint locationInContentCoordinates = mainFrame.view()->rootViewToContents(roundedIntPoint(locationInViewCooordinates));
     HitTestResult hitTestResult = mainFrame.eventHandler().hitTestResultAtPoint(locationInContentCoordinates);
 
-    m_lastActionMenuHitTestPreventsDefault = false;
+    bool actionMenuHitTestPreventsDefault = false;
     Element* element = hitTestResult.innerElement();
 
     if (forImmediateAction) {
         mainFrame.eventHandler().setImmediateActionStage(ImmediateActionStage::PerformedHitTest);
         if (element)
-            m_lastActionMenuHitTestPreventsDefault = element->dispatchMouseForceWillBegin();
+            actionMenuHitTestPreventsDefault = element->dispatchMouseForceWillBegin();
     }
 
     WebHitTestResult::Data actionMenuResult(hitTestResult);
@@ -1116,7 +1116,7 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
     RefPtr<API::Object> userData;
     injectedBundleContextMenuClient().prepareForActionMenu(*this, hitTestResult, userData);
 
-    send(Messages::WebPageProxy::DidPerformActionMenuHitTest(actionMenuResult, forImmediateAction, m_lastActionMenuHitTestPreventsDefault, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
+    send(Messages::WebPageProxy::DidPerformActionMenuHitTest(actionMenuResult, forImmediateAction, actionMenuHitTestPreventsDefault, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
 }
 
 PassRefPtr<WebCore::Range> WebPage::lookupTextAtLocation(FloatPoint locationInViewCooordinates, NSDictionary **options)
@@ -1160,9 +1160,6 @@ void WebPage::inputDeviceForceDidChange(float force, int stage)
     if (!element)
         return;
 
-    if (!m_lastActionMenuHitTestPreventsDefault)
-        return;
-
     float overallForce = stage < 1 ? force : force + stage - 1;
     element->dispatchMouseForceChanged(overallForce, m_page->mainFrame().eventHandler().lastMouseDownEvent());
 
@@ -1189,9 +1186,6 @@ void WebPage::immediateActionDidCancel()
     if (!element)
         return;
 
-    if (!m_lastActionMenuHitTestPreventsDefault)
-        return;
-
     element->dispatchMouseForceCancelled(m_page->mainFrame().eventHandler().lastMouseDownEvent());
 }