WKView being inside WKWebView leads to weird API issues
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 20:05:05 +0000 (20:05 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 20:05:05 +0000 (20:05 +0000)
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.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm

index e778c7958bd255823587de941b83b6292d164613..c6a9a4fa8541aa944af58f9eb213a99fb92393ac 100644 (file)
@@ -1,3 +1,32 @@
+2015-10-30  Tim Horton  <timothy_horton@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  <bdakin@apple.com>
 
         Tapping and holding a link should have a share option
index fb4666b70c9ecd5a694e965c184867fc2f347fe7..17e9bf1011f9911b790dd691c63a06fd5ed15185 100644 (file)
@@ -557,88 +557,6 @@ Some other editing-related methods still unimplemented:
     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,44 +569,62 @@ NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDraggedInternal)
 
 - (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);
+}
+
+- (void)rightMouseDown:(NSEvent *)event
+{
+    _data->_impl->rightMouseDown(event);
+}
+
+- (void)rightMouseDragged:(NSEvent *)event
+{
+    _data->_impl->rightMouseDragged(event);
+}
 
-    [self mouseDraggedInternal:event];
+- (void)rightMouseUp:(NSEvent *)event
+{
+    _data->_impl->rightMouseUp(event);
 }
 
 - (void)pressureChangeWithEvent:(NSEvent *)event
@@ -1116,13 +1052,6 @@ NATIVE_MOUSE_EVENT_HANDLER_INTERNAL(mouseDraggedInternal)
 }
 #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)
index 7cfb1167279bb099d215a026f2b0e9ca6befe0e2..a232b9586639c1c5c814d7f1bf58de6092ca54fc 100644 (file)
@@ -458,6 +458,19 @@ public:
     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 @@ private:
     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;
index 81cf15e81538889e3dcab6df5a6d1b8befc41c9c..f487149437d72ce01f95ffd7a7e44edec4ab74bf 100644 (file)
@@ -4169,6 +4169,140 @@ void WebViewImpl::flagsChanged(NSEvent *event)
 
 #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)