Skip to content
Permalink
Browse files
Tell the UI client when a key event is not handled
When the web process receives an event, it sends a
WebPageProxyMessage::DidReceiveEvent message back to the UI process.
That message is now sent after handling the event, and includes a
boolean signifying whether or not the event was actually handled.

Every time WebPageProxy receives a key event, it adds it to a queue.
When it receives a WebPageProxyMessage::DidReceiveEvent for a key
event, the event is removed from the queue. If the event was not
handled, we tell the UI client.

Fixes <http://webkit.org/b/46660> <rdar://problem/8483465> Need API to
tell a WebKit2 client application that a key event was not handled

Reviewed by Kenneth Rohde Christiansen and Sam Weinig.

WebKit2:

* Shared/NativeWebKeyboardEvent.h: Added. This class wraps a
WebKeyboardEvent and the native event that was used to construct it.
(WebKit::NativeWebKeyboardEvent::nativeEvent): Simple getter.

* Shared/WebEvent.h: Made isKeyboardEventType public for
WebPageProxy's benefit.

* Shared/mac/NativeWebKeyboardEventMac.mm: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/qt/NativeWebKeyboardEventQt.cpp: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/win/NativeWebKeyboardEventWin.cpp: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
The constructor creates a WebKeyboardEvent and stores the native
event.

* UIProcess/API/C/WKNativeEvent.h: Added.

* UIProcess/API/C/WKPage.h: Added WKPageDidNotHandleKeyEventCallback
and WKPageUIClient::didNotHandleKeyEvent.

* UIProcess/API/mac/WKView.mm:
(-[WKView keyUp:]):
(-[WKView keyDown:]):
* UIProcess/win/WebView.cpp:
(WebKit::WebView::onKeyEvent):
* UIProcess/API/qt/qwkpage.cpp:
(QWKPagePrivate::keyPressEvent):
(QWKPagePrivate::keyReleaseEvent):
Changed to use NativeWebKeyboardEvent.

(QWKPage::QWKPage): Updated for addition of didNotHandleKeyEvent.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleKeyboardEvent): Changed to take a
NativeWebKeyboardEvent and to add it to m_keyEventQueue.
(WebKit::WebPageProxy::didReceiveMessage): Changed to expect a boolean
parameter in WebPageProxyMessage::DidReceiveEvent.
(WebKit::WebPageProxy::didReceiveEvent): Added a boolean "handled"
parameter. If the event was a keyboard event, we remove it from
m_keyEventQueue, and if it wasn't handled by WebCore, we tell the UI
client.

* UIProcess/WebPageProxy.h: Added m_keyEventQueue.

* UIProcess/WebUIClient.cpp:
(WebKit::WebUIClient::didNotHandleKeyEvent):
* UIProcess/WebUIClient.h:
Added. Just calls through to the WKPageUIClient.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::handleMouseEvent):
(WebKit::WebPage::mouseEvent):
(WebKit::handleWheelEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::handleKeyEvent):
(WebKit::WebPage::keyEvent):
(WebKit::handleTouchEvent):
(WebKit::WebPage::touchEvent):
Moved code from the *Event functions into new helper handle*Event
functions, and changed to pass a boolean to
WebPageProxyMessage::DidReceiveEvent signaling whether the event was
handled or not.

* WebKit2.pro:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:
* win/WebKit2Generated.make:
Added WKNativeEvent.h and NativeWebKeyboardEvent.

WebKitTools:

Update for the addition of WKPageUIClient::didNotHandleKeyEvent

* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController awakeFromNib]):
* MiniBrowser/win/BrowserView.cpp:
(BrowserView::create):
* WebKitTestRunner/TestController.cpp:
(WTR::createOtherPage):
(WTR::TestController::initialize):

Conflicts:

	WebKit2/WebKit2.xcodeproj/project.pbxproj

Canonical link: https://commits.webkit.org/59225@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@68538 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aroben committed Sep 28, 2010
1 parent 61704c0 commit ccabdf1b3116128afbf646abeb8d13a3f630269d
Showing 24 changed files with 489 additions and 55 deletions.
@@ -1,3 +1,92 @@
2010-09-28 Adam Roben <aroben@apple.com>

Tell the UI client when a key event is not handled

When the web process receives an event, it sends a
WebPageProxyMessage::DidReceiveEvent message back to the UI process.
That message is now sent after handling the event, and includes a
boolean signifying whether or not the event was actually handled.

Every time WebPageProxy receives a key event, it adds it to a queue.
When it receives a WebPageProxyMessage::DidReceiveEvent for a key
event, the event is removed from the queue. If the event was not
handled, we tell the UI client.

Fixes <http://webkit.org/b/46660> <rdar://problem/8483465> Need API to
tell a WebKit2 client application that a key event was not handled

Reviewed by Kenneth Rohde Christiansen and Sam Weinig.

* Shared/NativeWebKeyboardEvent.h: Added. This class wraps a
WebKeyboardEvent and the native event that was used to construct it.
(WebKit::NativeWebKeyboardEvent::nativeEvent): Simple getter.

* Shared/WebEvent.h: Made isKeyboardEventType public for
WebPageProxy's benefit.

* Shared/mac/NativeWebKeyboardEventMac.mm: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/qt/NativeWebKeyboardEventQt.cpp: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/win/NativeWebKeyboardEventWin.cpp: Added.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
The constructor creates a WebKeyboardEvent and stores the native
event.

* UIProcess/API/C/WKNativeEvent.h: Added.

* UIProcess/API/C/WKPage.h: Added WKPageDidNotHandleKeyEventCallback
and WKPageUIClient::didNotHandleKeyEvent.

* UIProcess/API/mac/WKView.mm:
(-[WKView keyUp:]):
(-[WKView keyDown:]):
* UIProcess/win/WebView.cpp:
(WebKit::WebView::onKeyEvent):
* UIProcess/API/qt/qwkpage.cpp:
(QWKPagePrivate::keyPressEvent):
(QWKPagePrivate::keyReleaseEvent):
Changed to use NativeWebKeyboardEvent.

(QWKPage::QWKPage): Updated for addition of didNotHandleKeyEvent.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleKeyboardEvent): Changed to take a
NativeWebKeyboardEvent and to add it to m_keyEventQueue.
(WebKit::WebPageProxy::didReceiveMessage): Changed to expect a boolean
parameter in WebPageProxyMessage::DidReceiveEvent.
(WebKit::WebPageProxy::didReceiveEvent): Added a boolean "handled"
parameter. If the event was a keyboard event, we remove it from
m_keyEventQueue, and if it wasn't handled by WebCore, we tell the UI
client.

* UIProcess/WebPageProxy.h: Added m_keyEventQueue.

* UIProcess/WebUIClient.cpp:
(WebKit::WebUIClient::didNotHandleKeyEvent):
* UIProcess/WebUIClient.h:
Added. Just calls through to the WKPageUIClient.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::handleMouseEvent):
(WebKit::WebPage::mouseEvent):
(WebKit::handleWheelEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::handleKeyEvent):
(WebKit::WebPage::keyEvent):
(WebKit::handleTouchEvent):
(WebKit::WebPage::touchEvent):
Moved code from the *Event functions into new helper handle*Event
functions, and changed to pass a boolean to
WebPageProxyMessage::DidReceiveEvent signaling whether the event was
handled or not.

* WebKit2.pro:
* WebKit2.xcodeproj/project.pbxproj:
* win/WebKit2.vcproj:
* win/WebKit2Generated.make:
Added WKNativeEvent.h and NativeWebKeyboardEvent.

2010-09-28 Anders Carlsson <andersca@apple.com>

Reviewed by Adam Roben.
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef NativeWebKeyboardEvent_h
#define NativeWebKeyboardEvent_h

#include "WebEvent.h"

#if PLATFORM(MAC)
#ifdef __OBJC__
@class NSView;
#else
class NSView;
#endif
#elif PLATFORM(QT)
#include <QKeyEvent>
#endif

namespace WebKit {

class NativeWebKeyboardEvent : public WebKeyboardEvent {
public:
#if PLATFORM(MAC)
NativeWebKeyboardEvent(NSEvent *, NSView *);
#elif PLATFORM(WIN)
NativeWebKeyboardEvent(HWND, UINT message, WPARAM, LPARAM);
#elif PLATFORM(QT)
explicit NativeWebKeyboardEvent(QKeyEvent*);
#endif

#if PLATFORM(MAC)
NSEvent *nativeEvent() const { return m_nativeEvent.get(); }
#elif PLATFORM(WIN)
const MSG* nativeEvent() const { return &m_nativeEvent; }
#elif PLATFORM(QT)
const QKeyEvent* nativeEvent() const { return &m_nativeEvent; }
#endif

private:
#if PLATFORM(MAC)
RetainPtr<NSEvent> m_nativeEvent;
#elif PLATFORM(WIN)
MSG m_nativeEvent;
#elif PLATFORM(QT)
QKeyEvent m_nativeEvent;
#endif
};

} // namespace WebKit

#endif // NativeWebKeyboardEvent_h
@@ -318,12 +318,12 @@ class WebKeyboardEvent : public WebEvent {
return true;
}

private:
static bool isKeyboardEventType(Type type)
{
return type == RawKeyDown || type == KeyDown || type == KeyUp || type == Char;
}

private:
String m_text;
String m_unmodifiedText;
String m_keyIdentifier;
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#import "NativeWebKeyboardEvent.h"

#import "WebEventFactory.h"

namespace WebKit {

NativeWebKeyboardEvent::NativeWebKeyboardEvent(NSEvent *event, NSView *view)
: WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event, view))
, m_nativeEvent(event)
{
}

} // namespace WebKit
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "NativeWebKeyboardEvent.h"

#include "WebEventFactoryQt.h"

namespace WebKit {

NativeWebKeyboardEvent::NativeWebKeyboardEvent(QKeyEvent* event)
: WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event))
, m_nativeEvent(*event)
{
}

} // namespace WebKit
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "NativeWebKeyboardEvent.h"

#include "WebEventFactory.h"

namespace WebKit {

NativeWebKeyboardEvent::NativeWebKeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
: WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(hwnd, message, wParam, lParam))
, m_nativeEvent()
{
m_nativeEvent.hwnd = hwnd;
m_nativeEvent.message = message;
m_nativeEvent.wParam = wParam;
m_nativeEvent.lParam = lParam;
}

} // namespace WebKit
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef WKNativeEvent_h
#define WKNativeEvent_h

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __APPLE__
#ifdef __OBJC__
@class NSEvent;
#else
struct NSEvent;
#endif
typedef NSEvent *WKNativeEventPtr;
#elif defined(WIN32) || defined(_WIN32)
typedef const struct tagMSG* WKNativeEventPtr;
#else
typedef const void* WKNativeEventPtr;
#endif

#ifdef __cplusplus
}
#endif

#endif /* WKNativeEvent_h */
@@ -28,6 +28,7 @@

#include <WebKit2/WKBase.h>
#include <WebKit2/WKEvent.h>
#include <WebKit2/WKNativeEvent.h>

#ifndef __cplusplus
#include <stdbool.h>
@@ -136,6 +137,7 @@ typedef WKStringRef (*WKPageRunJavaScriptPromptCallback)(WKPageRef page, WKStrin
typedef void (*WKPageSetStatusTextCallback)(WKPageRef page, WKStringRef text, const void *clientInfo);
typedef void (*WKPageMouseDidMoveOverElementCallback)(WKPageRef page, WKEventModifiers modifiers, WKTypeRef userData, const void *clientInfo);
typedef void (*WKPageContentsSizeChangedCallback)(WKPageRef page, int width, int height, WKFrameRef frame, const void *clientInfo);
typedef void (*WKPageDidNotHandleKeyEventCallback)(WKPageRef page, WKNativeEventPtr event, const void *clientInfo);

struct WKPageUIClient {
int version;
@@ -149,6 +151,7 @@ struct WKPageUIClient {
WKPageSetStatusTextCallback setStatusText;
WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement;
WKPageContentsSizeChangedCallback contentsSizeChanged;
WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent;
};
typedef struct WKPageUIClient WKPageUIClient;

0 comments on commit ccabdf1

Please sign in to comment.