Title: [191806] trunk/Source/WebKit2
Revision
191806
Author
timothy_hor...@apple.com
Date
2015-10-30 13:05:05 -0700 (Fri, 30 Oct 2015)

Log Message

WKView being inside WKWebView leads to weird API issues
https://bugs.webkit.org/show_bug.cgi?id=150174

Reviewed by Anders Carlsson.

* UIProcess/API/mac/WKView.mm:
(-[WKView mouseMoved:]):
(-[WKView mouseDown:]):
(-[WKView mouseUp:]):
(-[WKView mouseDragged:]):
(-[WKView mouseEntered:]):
(-[WKView mouseExited:]):
(-[WKView otherMouseDown:]):
(-[WKView otherMouseDragged:]):
(-[WKView otherMouseUp:]):
(-[WKView rightMouseDown:]):
(-[WKView rightMouseDragged:]):
(-[WKView rightMouseUp:]):
(-[WKView _updateViewExposedRect]): Deleted.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::mouseMoved):
(WebKit::WebViewImpl::mouseDown):
(WebKit::WebViewImpl::mouseUp):
(WebKit::WebViewImpl::mouseDragged):
Move mouse event handling.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (191805 => 191806)


--- trunk/Source/WebKit2/ChangeLog	2015-10-30 19:38:40 UTC (rev 191805)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-30 20:05:05 UTC (rev 191806)
@@ -1,3 +1,32 @@
+2015-10-30  Tim Horton  <timothy_hor...@apple.com>
+
+        WKView being inside WKWebView leads to weird API issues
+        https://bugs.webkit.org/show_bug.cgi?id=150174
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView mouseMoved:]):
+        (-[WKView mouseDown:]):
+        (-[WKView mouseUp:]):
+        (-[WKView mouseDragged:]):
+        (-[WKView mouseEntered:]):
+        (-[WKView mouseExited:]):
+        (-[WKView otherMouseDown:]):
+        (-[WKView otherMouseDragged:]):
+        (-[WKView otherMouseUp:]):
+        (-[WKView rightMouseDown:]):
+        (-[WKView rightMouseDragged:]):
+        (-[WKView rightMouseUp:]):
+        (-[WKView _updateViewExposedRect]): Deleted.
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::mouseMoved):
+        (WebKit::WebViewImpl::mouseDown):
+        (WebKit::WebViewImpl::mouseUp):
+        (WebKit::WebViewImpl::mouseDragged):
+        Move mouse event handling.
+
 2015-10-30  Beth Dakin  <bda...@apple.com>
 
         Tapping and holding a link should have a share option

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191805 => 191806)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-30 19:38:40 UTC (rev 191805)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-30 20:05:05 UTC (rev 191806)
@@ -557,88 +557,6 @@
     return _data->_impl->wantsKeyDownForEvent(event);
 }
 
-#if USE(ASYNC_NSTEXTINPUTCLIENT)
-#define NATIVE_MOUSE_EVENT_HANDLER(Selector) \
-    - (void)Selector:(NSEvent *)theEvent \
-    { \
-        if (_data->_impl->ignoresNonWheelEvents()) \
-            return; \
-        if (NSTextInputContext *context = [self inputContext]) { \
-            [context handleEvent:theEvent completionHandler:^(BOOL handled) { \
-                if (handled) \
-                    LOG(TextInput, "%s was handled by text input context", String(#Selector).substring(0, String(#Selector).find("Internal")).ascii().data()); \
-                else { \
-                    NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-                    _data->_page->handleMouseEvent(webEvent); \
-                } \
-            }]; \
-            return; \
-        } \
-        NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-        _data->_page->handleMouseEvent(webEvent); \
-    }
-#define NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(Selector) \
-    - (void)Selector:(NSEvent *)theEvent \
-    { \
-        if (_data->_impl->ignoresNonWheelEvents()) \
-            return; \
-        if (NSTextInputContext *context = [self inputContext]) { \
-            [context handleEvent:theEvent completionHandler:^(BOOL handled) { \
-                if (handled) \
-                    LOG(TextInput, "%s was handled by text input context", String(#Selector).substring(0, String(#Selector).find("Internal")).ascii().data()); \
-                else { \
-                    NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-                    _data->_page->handleMouseEvent(webEvent); \
-                } \
-            }]; \
-            return; \
-        } \
-        NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-        _data->_page->handleMouseEvent(webEvent); \
-    }
-#else
-#define NATIVE_MOUSE_EVENT_HANDLER(Selector) \
-    - (void)Selector:(NSEvent *)theEvent \
-    { \
-        if (_data->_impl->ignoresNonWheelEvents()) \
-            return; \
-        if ([[self inputContext] handleEvent:theEvent]) { \
-            LOG(TextInput, "%s was handled by text input context", String(#Selector).substring(0, String(#Selector).find("Internal")).ascii().data()); \
-            return; \
-        } \
-        NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-        _data->_page->handleMouseEvent(webEvent); \
-    }
-#define NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(Selector) \
-    - (void)Selector:(NSEvent *)theEvent \
-    { \
-        if (_data->_impl->ignoresNonWheelEvents()) \
-            return; \
-        if ([[self inputContext] handleEvent:theEvent]) { \
-            LOG(TextInput, "%s was handled by text input context", String(#Selector).substring(0, String(#Selector).find("Internal")).ascii().data()); \
-            return; \
-        } \
-        NativeWebMouseEvent webEvent(theEvent, _data->_impl->lastPressureEvent(), self); \
-        _data->_page->handleMouseEvent(webEvent); \
-    }
-#endif
-
-NATIVE_MOUSE_EVENT_HANDLER(mouseEntered)
-NATIVE_MOUSE_EVENT_HANDLER(mouseExited)
-NATIVE_MOUSE_EVENT_HANDLER(otherMouseDown)
-NATIVE_MOUSE_EVENT_HANDLER(otherMouseDragged)
-NATIVE_MOUSE_EVENT_HANDLER(otherMouseUp)
-NATIVE_MOUSE_EVENT_HANDLER(rightMouseDown)
-NATIVE_MOUSE_EVENT_HANDLER(rightMouseDragged)
-NATIVE_MOUSE_EVENT_HANDLER(rightMouseUp)
-
-NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseMovedInternal)
-NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDownInternal)
-NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseUpInternal)
-NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDraggedInternal)
-
-#undef NATIVE_MOUSE_EVENT_HANDLER
-
 - (void)scrollWheel:(NSEvent *)event
 {
     _data->_impl->scrollWheel(event);
@@ -651,46 +569,64 @@
 
 - (void)mouseMoved:(NSEvent *)event
 {
-    if (_data->_impl->ignoresNonWheelEvents())
-        return;
+    _data->_impl->mouseMoved(event);
+}
 
-    // When a view is first responder, it gets mouse moved events even when the mouse is outside its visible rect.
-    if (self == [[self window] firstResponder] && !NSPointInRect([self convertPoint:[event locationInWindow] fromView:nil], [self visibleRect]))
-        return;
+- (void)mouseDown:(NSEvent *)event
+{
+    _data->_impl->mouseDown(event);
+}
 
-    [self mouseMovedInternal:event];
+- (void)mouseUp:(NSEvent *)event
+{
+    _data->_impl->mouseUp(event);
 }
 
-- (void)mouseDown:(NSEvent *)event
+- (void)mouseDragged:(NSEvent *)event
 {
-    if (_data->_impl->ignoresNonWheelEvents())
-        return;
+    _data->_impl->mouseDragged(event);
+}
 
-    _data->_impl->setLastMouseDownEvent(event);
-    _data->_impl->setIgnoresMouseDraggedEvents(false);
+- (void)mouseEntered:(NSEvent *)event
+{
+    _data->_impl->mouseEntered(event);
+}
 
-    [self mouseDownInternal:event];
+- (void)mouseExited:(NSEvent *)event
+{
+    _data->_impl->mouseExited(event);
 }
 
-- (void)mouseUp:(NSEvent *)event
+- (void)otherMouseDown:(NSEvent *)event
 {
-    if (_data->_impl->ignoresNonWheelEvents())
-        return;
+    _data->_impl->otherMouseDown(event);
+}
 
-    _data->_impl->setLastMouseDownEvent(nil);
-    [self mouseUpInternal:event];
+- (void)otherMouseDragged:(NSEvent *)event
+{
+    _data->_impl->otherMouseDragged(event);
 }
 
-- (void)mouseDragged:(NSEvent *)event
+- (void)otherMouseUp:(NSEvent *)event
 {
-    if (_data->_impl->ignoresNonWheelEvents())
-        return;
-    if (_data->_impl->ignoresMouseDraggedEvents())
-        return;
+    _data->_impl->otherMouseUp(event);
+}
 
-    [self mouseDraggedInternal:event];
+- (void)rightMouseDown:(NSEvent *)event
+{
+    _data->_impl->rightMouseDown(event);
 }
 
+- (void)rightMouseDragged:(NSEvent *)event
+{
+    _data->_impl->rightMouseDragged(event);
+}
+
+- (void)rightMouseUp:(NSEvent *)event
+{
+    _data->_impl->rightMouseUp(event);
+}
+
 - (void)pressureChangeWithEvent:(NSEvent *)event
 {
     _data->_impl->pressureChangeWithEvent(event);
@@ -1116,13 +1052,6 @@
 }
 #endif // WK_API_ENABLED
 
-
-// FIXME: Get rid of this when we have better plumbing to WKViewLayoutStrategy.
-- (void)_updateViewExposedRect
-{
-    _data->_impl->updateViewExposedRect();
-}
-
 @end
 
 @implementation WKView (Private)

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191805 => 191806)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-30 19:38:40 UTC (rev 191805)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-30 20:05:05 UTC (rev 191806)
@@ -458,6 +458,19 @@
     void characterIndexForPoint(NSPoint, void(^)(NSUInteger));
 #endif // USE(ASYNC_NSTEXTINPUTCLIENT)
 
+    void mouseMoved(NSEvent *);
+    void mouseDown(NSEvent *);
+    void mouseUp(NSEvent *);
+    void mouseDragged(NSEvent *);
+    void mouseEntered(NSEvent *);
+    void mouseExited(NSEvent *);
+    void otherMouseDown(NSEvent *);
+    void otherMouseDragged(NSEvent *);
+    void otherMouseUp(NSEvent *);
+    void rightMouseDown(NSEvent *);
+    void rightMouseDragged(NSEvent *);
+    void rightMouseUp(NSEvent *);
+
 private:
     WeakPtr<WebViewImpl> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
 
@@ -485,6 +498,11 @@
     bool interpretKeyEvent(NSEvent *, Vector<WebCore::KeypressCommand>&);
 #endif
 
+    void mouseMovedInternal(NSEvent *);
+    void mouseDownInternal(NSEvent *);
+    void mouseUpInternal(NSEvent *);
+    void mouseDraggedInternal(NSEvent *);
+
     NSView <WebViewImplDelegate> *m_view;
     WebPageProxy& m_page;
     PageClient& m_pageClient;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191805 => 191806)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-30 19:38:40 UTC (rev 191805)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-30 20:05:05 UTC (rev 191806)
@@ -4169,6 +4169,140 @@
 
 #endif // USE(ASYNC_NSTEXTINPUTCLIENT)
 
+#if USE(ASYNC_NSTEXTINPUTCLIENT)
+#define NATIVE_MOUSE_EVENT_HANDLER(EventName) \
+    void WebViewImpl::EventName(NSEvent *event) \
+    { \
+        if (m_ignoresNonWheelEvents) \
+            return; \
+        if (NSTextInputContext *context = m_view.inputContext) { \
+            auto weakThis = createWeakPtr(); \
+            RetainPtr<NSEvent> retainedEvent = event; \
+            [context handleEvent:event completionHandler:[weakThis, retainedEvent] (BOOL handled) { \
+                if (!weakThis) \
+                    return; \
+                if (handled) \
+                    LOG(TextInput, "%s was handled by text input context", String(#EventName).substring(0, String(#EventName).find("Internal")).ascii().data()); \
+                else { \
+                    NativeWebMouseEvent webEvent(retainedEvent.get(), weakThis->m_lastPressureEvent.get(), weakThis->m_view); \
+                    weakThis->m_page.handleMouseEvent(webEvent); \
+                } \
+            }]; \
+            return; \
+        } \
+        NativeWebMouseEvent webEvent(event, m_lastPressureEvent.get(), m_view); \
+        m_page.handleMouseEvent(webEvent); \
+    }
+#define NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(EventName) \
+    void WebViewImpl::EventName(NSEvent *event) \
+    { \
+        if (m_ignoresNonWheelEvents) \
+            return; \
+        if (NSTextInputContext *context = m_view.inputContext) { \
+            auto weakThis = createWeakPtr(); \
+            RetainPtr<NSEvent> retainedEvent = event; \
+            [context handleEvent:event completionHandler:[weakThis, retainedEvent] (BOOL handled) { \
+                if (!weakThis) \
+                    return; \
+                if (handled) \
+                    LOG(TextInput, "%s was handled by text input context", String(#EventName).substring(0, String(#EventName).find("Internal")).ascii().data()); \
+                else { \
+                    NativeWebMouseEvent webEvent(retainedEvent.get(), weakThis->m_lastPressureEvent.get(), weakThis->m_view); \
+                    weakThis->m_page.handleMouseEvent(webEvent); \
+                } \
+            }]; \
+            return; \
+        } \
+        NativeWebMouseEvent webEvent(event, m_lastPressureEvent.get(), m_view); \
+        m_page.handleMouseEvent(webEvent); \
+    }
+    
+#else // USE(ASYNC_NSTEXTINPUTCLIENT)
+#define NATIVE_MOUSE_EVENT_HANDLER(EventName) \
+    void WebViewImpl::EventName(NSEvent *event) \
+    { \
+        if (m_ignoresNonWheelEvents) \
+            return; \
+        if ([m_view.inputContext handleEvent:event]) { \
+            LOG(TextInput, "%s was handled by text input context", String(#EventName).substring(0, String(#EventName).find("Internal")).ascii().data()); \
+            return; \
+        } \
+        NativeWebMouseEvent webEvent(event, m_lastPressureEvent.get(), m_view); \
+        m_page.handleMouseEvent(webEvent); \
+    }
+#define NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(EventName) \
+    void WebViewImpl::EventName(NSEvent *event) \
+    { \
+        if (m_ignoresNonWheelEvents) \
+            return; \
+        if ([m_view.inputContext handleEvent:event]) { \
+            LOG(TextInput, "%s was handled by text input context", String(#EventName).substring(0, String(#EventName).find("Internal")).ascii().data()); \
+            return; \
+        } \
+        NativeWebMouseEvent webEvent(event, m_lastPressureEvent.get(), m_view); \
+        m_page.handleMouseEvent(webEvent); \
+    }
+#endif // USE(ASYNC_NSTEXTINPUTCLIENT)
+
+NATIVE_MOUSE_EVENT_HANDLER(mouseEntered)
+NATIVE_MOUSE_EVENT_HANDLER(mouseExited)
+NATIVE_MOUSE_EVENT_HANDLER(otherMouseDown)
+NATIVE_MOUSE_EVENT_HANDLER(otherMouseDragged)
+NATIVE_MOUSE_EVENT_HANDLER(otherMouseUp)
+NATIVE_MOUSE_EVENT_HANDLER(rightMouseDown)
+NATIVE_MOUSE_EVENT_HANDLER(rightMouseDragged)
+NATIVE_MOUSE_EVENT_HANDLER(rightMouseUp)
+
+NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseMovedInternal)
+NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDownInternal)
+NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseUpInternal)
+NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDraggedInternal)
+
+#undef NATIVE_MOUSE_EVENT_HANDLER
+#undef NATIVE_MOUSE_EVENT_HANDLER_INTERNAL
+
+void WebViewImpl::mouseMoved(NSEvent *event)
+{
+    if (m_ignoresNonWheelEvents)
+        return;
+
+    // When a view is first responder, it gets mouse moved events even when the mouse is outside its visible rect.
+    if (m_view == m_view.window.firstResponder && !NSPointInRect([m_view convertPoint:[event locationInWindow] fromView:nil], m_view.visibleRect))
+        return;
+
+    mouseMovedInternal(event);
+}
+
+void WebViewImpl::mouseDown(NSEvent *event)
+{
+    if (m_ignoresNonWheelEvents)
+        return;
+
+    setLastMouseDownEvent(event);
+    setIgnoresMouseDraggedEvents(false);
+
+    mouseDownInternal(event);
+}
+
+void WebViewImpl::mouseUp(NSEvent *event)
+{
+    if (m_ignoresNonWheelEvents)
+        return;
+
+    setLastMouseDownEvent(nil);
+    mouseUpInternal(event);
+}
+
+void WebViewImpl::mouseDragged(NSEvent *event)
+{
+    if (m_ignoresNonWheelEvents)
+        return;
+    if (ignoresMouseDraggedEvents())
+        return;
+
+    mouseDraggedInternal(event);
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to