[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

aroben at apple.com aroben at apple.com
Wed Dec 22 14:38:35 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit d948e4887cf24aef8cc9c9e087b13e936a28fabd
Author: aroben at apple.com <aroben at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Oct 14 19:21:32 2010 +0000

    Call ::DefWindowProcW for unhandled key events
    
    ::DefWindowProcW does important things for at least some key events
    (e.g., it generates a WM_SYSCOMMAND message when the Alt key is
    released), so we need to make sure to call it when we don't handle key
    events.
    
    Fixes <http://webkit.org/b/47671> <rdar://problem/8435594> Pressing
    the Alt key when MiniBrowser's WKView is focused doesn't send focus to
    the menu bar
    
    Reviewed by Steve Falkenburg.
    
    WebKit2:
    
    * UIProcess/API/mac/PageClientImpl.h:
    * UIProcess/API/mac/PageClientImpl.mm:
    (WebKit::PageClientImpl::didNotHandleKeyEvent):
    * UIProcess/API/qt/qwkpage.cpp:
    (QWKPagePrivate::didNotHandleKeyEvent):
    * UIProcess/API/qt/qwkpage_p.h:
    Stubbed out didNotHandleKeyEvent.
    
    * UIProcess/PageClient.h: Added didNotHandleKeyEvent.
    
    * UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::didReceiveEvent): Tell the PageClient about the
    unhandled event.
    
    * UIProcess/win/WebView.cpp:
    (WebKit::WebView::onKeyEvent): Added a comment.
    (WebKit::WebView::didNotHandleKeyEvent): Pass the event to
    ::DefWindowProcW.
    
    * UIProcess/win/WebView.h: Added didNotHandleKeyEvent.
    
    WebKitTools:
    
    Test that pressing the Alt key generates a WM_SYSCOMMAND message
    
    * TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops: Added
    TestWebKitAPI/win to the include path so that WindowMessageObserver
    can be found.
    
    * TestWebKitAPI/PlatformWebView.h: Added simulateAltKeyPress and
    Windows-specific members.
    (TestWebKitAPI::PlatformWebView::setParentWindowMessageObserver):
    Added this simple setter.
    
    * TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp: Added.
    (TestWebKitAPI::WMSysCommandObserver::WMSysCommandObserver):
    Initialize our lone data member.
    (TestWebKitAPI::WMSysCommandObserver::windowDidReceiveWMSysCommand):
    Simple getter.
    (TestWebKitAPI::WMSysCommandObserver::windowReceivedMessage): Record
    when a WM_SYSCOMMAND message is received.
    (TestWebKitAPI::didNotHandleKeyEventCallback): Record when a
    WM_SYSKEYUP message is not handled.
    (TestWebKitAPI::WebKit2_AltKeyGeneratesWMSysCommand): Simulate
    pressing the Alt key and check that a WM_SYSCOMMAND message got sent
    to the WKView's parent window.
    
    * TestWebKitAPI/win/PlatformWebViewWin.cpp:
    (TestWebKitAPI::PlatformWebView::registerWindowClass): Made this a
    member function so it could access PlatformWebView::wndProc. Use
    PlatformWebView::wndProc as the WNDPROC.
    (TestWebKitAPI::PlatformWebView::PlatformWebView): Initialize our new
    data member and pass the this pointer to CreateWindowEx so we can
    store it on the HWND.
    (TestWebKitAPI::PlatformWebView::simulateSpacebarKeyPress): Moved some
    constants from here to the top of the file.
    (TestWebKitAPI::PlatformWebView::simulateAltKeyPress): Added. Sends
    the same messages that Notepad receives when you press the Alt key.
    (TestWebKitAPI::PlatformWebView::wndProc): Added.
      - When WM_CREATE is received, we set the PlatformWebView instance
        pointer as a property on the HWND so we can access it later.
      - For other messages, we try to get the PlatformWebView instance
        pointer from the HWND property.
      - When WM_NCDESTROY is received (which is the last message we will
        receive), we remove the PlatformWebView instance property.
      - Pass messages to the parent window's message observer, if there is
        one.
      - Pass all messages through to ::DefWindowProcW.
    
    * TestWebKitAPI/win/TestWebKitAPI.vcproj: Added WindowMessageObserver
    and AltKeyGeneratesWMSysCommand.
    
    * TestWebKitAPI/win/WindowMessageObserver.h: Added. This class can be
    used to observe messages sent to one or more windows.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69788 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index bfb5bd2..6790223 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,39 @@
+2010-10-14  Adam Roben  <aroben at apple.com>
+
+        Call ::DefWindowProcW for unhandled key events
+
+        ::DefWindowProcW does important things for at least some key events
+        (e.g., it generates a WM_SYSCOMMAND message when the Alt key is
+        released), so we need to make sure to call it when we don't handle key
+        events.
+
+        Fixes <http://webkit.org/b/47671> <rdar://problem/8435594> Pressing
+        the Alt key when MiniBrowser's WKView is focused doesn't send focus to
+        the menu bar
+
+        Reviewed by Steve Falkenburg.
+
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didNotHandleKeyEvent):
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::didNotHandleKeyEvent):
+        * UIProcess/API/qt/qwkpage_p.h:
+        Stubbed out didNotHandleKeyEvent.
+
+        * UIProcess/PageClient.h: Added didNotHandleKeyEvent.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didReceiveEvent): Tell the PageClient about the
+        unhandled event.
+
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::onKeyEvent): Added a comment.
+        (WebKit::WebView::didNotHandleKeyEvent): Pass the event to
+        ::DefWindowProcW.
+
+        * UIProcess/win/WebView.h: Added didNotHandleKeyEvent.
+
 2010-10-13  Sam Weinig  <sam at webkit.org>
 
         Reviewed by Jon Honeycutt.
diff --git a/WebKit2/UIProcess/API/mac/PageClientImpl.h b/WebKit2/UIProcess/API/mac/PageClientImpl.h
index f539d47..6b426a6 100644
--- a/WebKit2/UIProcess/API/mac/PageClientImpl.h
+++ b/WebKit2/UIProcess/API/mac/PageClientImpl.h
@@ -60,6 +60,8 @@ private:
     WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
     WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
 
+    virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
+
 #if USE(ACCELERATED_COMPOSITING)
     void pageDidEnterAcceleratedCompositing();
     void pageDidLeaveAcceleratedCompositing();
diff --git a/WebKit2/UIProcess/API/mac/PageClientImpl.mm b/WebKit2/UIProcess/API/mac/PageClientImpl.mm
index a522c3d..6e7d0f8 100644
--- a/WebKit2/UIProcess/API/mac/PageClientImpl.mm
+++ b/WebKit2/UIProcess/API/mac/PageClientImpl.mm
@@ -221,6 +221,10 @@ FloatRect PageClientImpl::convertToUserSpace(const FloatRect& rect)
     return [m_wkView _convertToUserSpace:rect];
 }
 
+void PageClientImpl::didNotHandleKeyEvent(const NativeWebKeyboardEvent&)
+{
+}
+
 #if USE(ACCELERATED_COMPOSITING)
 void PageClientImpl::pageDidEnterAcceleratedCompositing()
 {
diff --git a/WebKit2/UIProcess/API/qt/qwkpage.cpp b/WebKit2/UIProcess/API/qt/qwkpage.cpp
index 4c51966..5ad7e87 100644
--- a/WebKit2/UIProcess/API/qt/qwkpage.cpp
+++ b/WebKit2/UIProcess/API/qt/qwkpage.cpp
@@ -108,6 +108,10 @@ FloatRect QWKPagePrivate::convertToUserSpace(const FloatRect& rect)
     return rect;
 }
 
+void QWKPagePrivate::didNotHandleKeyEvent(const NativeWebKeyboardEvent&)
+{
+}
+
 void QWKPagePrivate::paint(QPainter* painter, QRect area)
 {
     painter->save();
diff --git a/WebKit2/UIProcess/API/qt/qwkpage_p.h b/WebKit2/UIProcess/API/qt/qwkpage_p.h
index 4299052..a48a0dd 100644
--- a/WebKit2/UIProcess/API/qt/qwkpage_p.h
+++ b/WebKit2/UIProcess/API/qt/qwkpage_p.h
@@ -58,6 +58,7 @@ public:
     virtual void clearAllEditCommands();
     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
+    virtual void didNotHandleKeyEvent(const WebKit::NativeWebKeyboardEvent&);
 
     void paint(QPainter* painter, QRect);
 
diff --git a/WebKit2/UIProcess/PageClient.h b/WebKit2/UIProcess/PageClient.h
index 2f5d3cf..30ee1fd 100644
--- a/WebKit2/UIProcess/PageClient.h
+++ b/WebKit2/UIProcess/PageClient.h
@@ -36,6 +36,7 @@ namespace WebCore {
 
 namespace WebKit {
 
+class NativeWebKeyboardEvent;
 class WebEditCommandProxy;
 
 class PageClient {
@@ -58,6 +59,8 @@ public:
     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) = 0;
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) = 0;
 
+    virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&) = 0;
+
 #if USE(ACCELERATED_COMPOSITING)
     virtual void pageDidEnterAcceleratedCompositing() = 0;
     virtual void pageDidLeaveAcceleratedCompositing() = 0;
diff --git a/WebKit2/UIProcess/WebPageProxy.cpp b/WebKit2/UIProcess/WebPageProxy.cpp
index 5819e09..190d144 100644
--- a/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/WebKit2/UIProcess/WebPageProxy.cpp
@@ -1033,6 +1033,7 @@ void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
     if (handled)
         return;
 
+    m_pageClient->didNotHandleKeyEvent(event);
     m_uiClient.didNotHandleKeyEvent(this, event);
 }
 
diff --git a/WebKit2/UIProcess/win/WebView.cpp b/WebKit2/UIProcess/win/WebView.cpp
index 3aff3b2..660e848 100644
--- a/WebKit2/UIProcess/win/WebView.cpp
+++ b/WebKit2/UIProcess/win/WebView.cpp
@@ -337,6 +337,8 @@ LRESULT WebView::onKeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
 {
     m_page->handleKeyboardEvent(NativeWebKeyboardEvent(hWnd, message, wParam, lParam));
 
+    // We claim here to always have handled the event. If the event is not in fact handled, we will
+    // find out later in didNotHandleKeyEvent.
     handled = true;
     return 0;
 }
@@ -599,6 +601,13 @@ FloatRect WebView::convertToUserSpace(const FloatRect& rect)
     return rect;
 }
 
+void WebView::didNotHandleKeyEvent(const NativeWebKeyboardEvent& event)
+{
+    // Calling ::DefWindowProcW will ensure that pressing the Alt key will generate a WM_SYSCOMMAND
+    // event, e.g. See <http://webkit.org/b/47671>.
+    ::DefWindowProcW(event.nativeEvent()->hwnd, event.nativeEvent()->message, event.nativeEvent()->wParam, event.nativeEvent()->lParam);
+}
+
 #if USE(ACCELERATED_COMPOSITING)
 void WebView::pageDidEnterAcceleratedCompositing()
 {
diff --git a/WebKit2/UIProcess/win/WebView.h b/WebKit2/UIProcess/win/WebView.h
index efd53a7..652f2d1 100644
--- a/WebKit2/UIProcess/win/WebView.h
+++ b/WebKit2/UIProcess/win/WebView.h
@@ -101,6 +101,7 @@ private:
     virtual void setEditCommandState(const WTF::String&, bool, int);
     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
+    virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
 
 #if USE(ACCELERATED_COMPOSITING)
     virtual void pageDidEnterAcceleratedCompositing();
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 46ae572..aaa2a47 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,63 @@
+2010-10-14  Adam Roben  <aroben at apple.com>
+
+        Test that pressing the Alt key generates a WM_SYSCOMMAND message
+
+        Test for <http://webkit.org/b/47671> <rdar://problem/8435594> Pressing
+        the Alt key when MiniBrowser's WKView is focused doesn't send focus to
+        the menu bar
+
+        Reviewed by Steve Falkenburg.
+
+        * TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops: Added
+        TestWebKitAPI/win to the include path so that WindowMessageObserver
+        can be found.
+
+        * TestWebKitAPI/PlatformWebView.h: Added simulateAltKeyPress and
+        Windows-specific members.
+        (TestWebKitAPI::PlatformWebView::setParentWindowMessageObserver):
+        Added this simple setter.
+
+        * TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp: Added.
+        (TestWebKitAPI::WMSysCommandObserver::WMSysCommandObserver):
+        Initialize our lone data member.
+        (TestWebKitAPI::WMSysCommandObserver::windowDidReceiveWMSysCommand):
+        Simple getter.
+        (TestWebKitAPI::WMSysCommandObserver::windowReceivedMessage): Record
+        when a WM_SYSCOMMAND message is received.
+        (TestWebKitAPI::didNotHandleKeyEventCallback): Record when a
+        WM_SYSKEYUP message is not handled.
+        (TestWebKitAPI::WebKit2_AltKeyGeneratesWMSysCommand): Simulate
+        pressing the Alt key and check that a WM_SYSCOMMAND message got sent
+        to the WKView's parent window.
+
+        * TestWebKitAPI/win/PlatformWebViewWin.cpp:
+        (TestWebKitAPI::PlatformWebView::registerWindowClass): Made this a
+        member function so it could access PlatformWebView::wndProc. Use
+        PlatformWebView::wndProc as the WNDPROC.
+        (TestWebKitAPI::PlatformWebView::PlatformWebView): Initialize our new
+        data member and pass the this pointer to CreateWindowEx so we can
+        store it on the HWND.
+        (TestWebKitAPI::PlatformWebView::simulateSpacebarKeyPress): Moved some
+        constants from here to the top of the file.
+        (TestWebKitAPI::PlatformWebView::simulateAltKeyPress): Added. Sends
+        the same messages that Notepad receives when you press the Alt key.
+        (TestWebKitAPI::PlatformWebView::wndProc): Added.
+          - When WM_CREATE is received, we set the PlatformWebView instance
+            pointer as a property on the HWND so we can access it later.
+          - For other messages, we try to get the PlatformWebView instance
+            pointer from the HWND property.
+          - When WM_NCDESTROY is received (which is the last message we will
+            receive), we remove the PlatformWebView instance property.
+          - Pass messages to the parent window's message observer, if there is
+            one.
+          - Pass all messages through to ::DefWindowProcW.
+
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj: Added WindowMessageObserver
+        and AltKeyGeneratesWMSysCommand.
+
+        * TestWebKitAPI/win/WindowMessageObserver.h: Added. This class can be
+        used to observe messages sent to one or more windows.
+
 2010-10-01  Martin Robinson  <mrobinson at igalia.com>
 
         Reviewed by Holger Freyther.
diff --git a/WebKitTools/TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops b/WebKitTools/TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops
index 474f3d3..1de3506 100644
--- a/WebKitTools/TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops
+++ b/WebKitTools/TestWebKitAPI/Configurations/TestWebKitAPICommon.vsprops
@@ -6,7 +6,7 @@
 	>
 	<Tool
 		Name="VCCLCompilerTool"
-		AdditionalIncludeDirectories="&quot;$(ProjectDir)\..&quot;;&quot;$(WebKitOutputDir)\include&quot;;&quot;$(WebKitOutputDir)\include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\include\private&quot;;&quot;$(WebKitLibrariesDir)\include&quot;"
+		AdditionalIncludeDirectories="&quot;$(ProjectDir)&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(WebKitOutputDir)\include&quot;;&quot;$(WebKitOutputDir)\include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\include\private&quot;;&quot;$(WebKitLibrariesDir)\include&quot;"
 		ForcedIncludeFiles="TestWebKitAPIPrefix.h"
 	/>
 	<Tool
diff --git a/WebKitTools/TestWebKitAPI/PlatformWebView.h b/WebKitTools/TestWebKitAPI/PlatformWebView.h
index e5db190..7f4f057 100644
--- a/WebKitTools/TestWebKitAPI/PlatformWebView.h
+++ b/WebKitTools/TestWebKitAPI/PlatformWebView.h
@@ -26,6 +26,8 @@
 #ifndef PlatformWebView_h
 #define PlatformWebView_h
 
+#include <wtf/Platform.h>
+
 #ifdef __APPLE__
 #ifdef __OBJC__
 @class WKView;
@@ -43,6 +45,10 @@ typedef HWND PlatformWindow;
 
 namespace TestWebKitAPI {
 
+#if PLATFORM(WIN)
+class WindowMessageObserver;
+#endif
+
 class PlatformWebView {
 public:
     PlatformWebView(WKPageNamespaceRef);
@@ -54,10 +60,24 @@ public:
     void focus();
 
     void simulateSpacebarKeyPress();
+    void simulateAltKeyPress();
+
+#if PLATFORM(WIN)
+    void setParentWindowMessageObserver(WindowMessageObserver* observer) { m_parentWindowMessageObserver = observer; }
+#endif
 
 private:
+#if PLATFORM(WIN)
+    static void registerWindowClass();
+    static LRESULT CALLBACK wndProc(HWND, UINT message, WPARAM, LPARAM);
+#endif
+
     PlatformWKView m_view;
     PlatformWindow m_window;
+
+#if PLATFORM(WIN)
+    WindowMessageObserver* m_parentWindowMessageObserver;
+#endif
 };
 
 } // namespace TestWebKitAPI
diff --git a/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp b/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp
new file mode 100644
index 0000000..c463cf0
--- /dev/null
+++ b/WebKitTools/TestWebKitAPI/Tests/WebKit2/win/AltKeyGeneratesWMSysCommand.cpp
@@ -0,0 +1,88 @@
+/*
+ * 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 "Test.h"
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "WindowMessageObserver.h"
+#include <WebKit2/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+class WMSysCommandObserver : public WindowMessageObserver {
+public:
+    WMSysCommandObserver() : m_windowDidReceiveWMSysCommand(false) { }
+
+    bool windowDidReceiveWMSysCommand() const { return m_windowDidReceiveWMSysCommand; }
+
+private:
+    virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM)
+    {
+        if (message == WM_SYSCOMMAND)
+            m_windowDidReceiveWMSysCommand = true;
+    }
+
+    bool m_windowDidReceiveWMSysCommand;
+};
+
+static bool didNotHandleWMSysKeyUp;
+
+static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, const void*)
+{
+    if (event->message != WM_SYSKEYUP)
+        return;
+
+    didNotHandleWMSysKeyUp = true;
+}
+
+TEST(WebKit2, AltKeyGeneratesWMSysCommand)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
+
+    PlatformWebView webView(pageNamespace.get());
+
+    WKPageUIClient uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback;
+    WKPageSetPageUIClient(webView.page(), &uiClient);
+
+    WMSysCommandObserver observer;
+    webView.setParentWindowMessageObserver(&observer);
+
+    webView.simulateAltKeyPress();
+
+    Util::run(&didNotHandleWMSysKeyUp);
+
+    webView.setParentWindowMessageObserver(0);
+
+    // The WM_SYSKEYUP message should have generated a WM_SYSCOMMAND message that was sent to the
+    // WKView's parent window.
+    TEST_ASSERT(observer.windowDidReceiveWMSysCommand());
+}
+
+} // namespace TestWebKitAPI
diff --git a/WebKitTools/TestWebKitAPI/win/PlatformWebViewWin.cpp b/WebKitTools/TestWebKitAPI/win/PlatformWebViewWin.cpp
index 04dc83b..65bdbc6 100644
--- a/WebKitTools/TestWebKitAPI/win/PlatformWebViewWin.cpp
+++ b/WebKitTools/TestWebKitAPI/win/PlatformWebViewWin.cpp
@@ -25,11 +25,21 @@
 
 #include "PlatformWebView.h"
 
+#include "WindowMessageObserver.h"
+
 namespace TestWebKitAPI {
 
 static const wchar_t* hostWindowClassName = L"org.WebKit.TestWebKitAPI.PlatformWebViewHostWindow";
+static const wchar_t* webViewPointerProperty = L"org.WebKit.TestWebKitAPI.PlatformWebView.InstancePointer";
+
+// These offsets come from rom <http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx>.
+static const size_t repeatCountBitOffset = 0;
+static const size_t scanCodeBitOffset = 16;
+static const size_t contextCodeBitOffset = 29;
+static const size_t previousStateBitOffset = 30;
+static const size_t transitionStateBitOffset = 31;
 
-static void registerWindowClass()
+void PlatformWebView::registerWindowClass()
 {
     static bool initialized;
     if (initialized)
@@ -39,7 +49,7 @@ static void registerWindowClass()
     WNDCLASSEXW wndClass = {0};
     wndClass.cbSize = sizeof(wndClass);
     wndClass.style = CS_HREDRAW | CS_VREDRAW;
-    wndClass.lpfnWndProc = DefWindowProcW;
+    wndClass.lpfnWndProc = wndProc;
     wndClass.hCursor = LoadCursor(0, IDC_ARROW);
     wndClass.lpszClassName = hostWindowClassName;
 
@@ -47,11 +57,12 @@ static void registerWindowClass()
 }
 
 PlatformWebView::PlatformWebView(WKPageNamespaceRef namespaceRef)
+    : m_parentWindowMessageObserver(0)
 {
     registerWindowClass();
 
     RECT viewRect = {0, 0, 800, 600};
-    m_window = CreateWindowExW(0, hostWindowClassName, L"TestWebKitAPI", WS_OVERLAPPEDWINDOW, viewRect.left, viewRect.top, viewRect.right, viewRect.bottom, 0, 0, 0, 0);
+    m_window = CreateWindowExW(0, hostWindowClassName, L"TestWebKitAPI", WS_OVERLAPPEDWINDOW, viewRect.left, viewRect.top, viewRect.right, viewRect.bottom, 0, 0, 0, this);
     m_view = WKViewCreate(viewRect, namespaceRef, m_window);
 }
 
@@ -70,16 +81,38 @@ void PlatformWebView::simulateSpacebarKeyPress()
 {
     HWND window = WKViewGetWindow(m_view);
 
-    // These offsets come from rom <http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx>.
-    static const size_t repeatCountBitOffset = 0;
-    static const size_t scanCodeBitOffset = 16;
-    static const size_t previousStateBitOffset = 30;
-    static const size_t transitionStateBitOffset = 31;
-
     // These values match what happens when you press the spacebar in Notepad, as observed by Spy++.
     ::SendMessageW(window, WM_KEYDOWN, VK_SPACE, (1 << repeatCountBitOffset) | (39 << scanCodeBitOffset));
     ::SendMessageW(window, WM_CHAR, ' ', (1 << repeatCountBitOffset) | (39 << scanCodeBitOffset));
     ::SendMessageW(window, WM_KEYUP, VK_SPACE, (1 << repeatCountBitOffset) | (39 << scanCodeBitOffset) | (1 << previousStateBitOffset) | (1 << transitionStateBitOffset));
 }
 
+void PlatformWebView::simulateAltKeyPress()
+{
+    HWND window = WKViewGetWindow(m_view);
+
+    // These values match what happens when you press the Alt key in Notepad, as observed by Spy++.
+    ::SendMessageW(window, WM_SYSKEYDOWN, VK_MENU, (1 << repeatCountBitOffset) | (38 << scanCodeBitOffset) | (1 << contextCodeBitOffset));
+    ::SendMessageW(window, WM_SYSKEYUP, VK_MENU, (1 << repeatCountBitOffset) | (38 << scanCodeBitOffset) | (1 << previousStateBitOffset) | (1 << transitionStateBitOffset));
+}
+
+LRESULT PlatformWebView::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    PlatformWebView* webView;
+    if (message == WM_CREATE) {
+        CREATESTRUCT* createStruct = reinterpret_cast<CREATESTRUCT*>(lParam);
+        webView = static_cast<PlatformWebView*>(createStruct->lpCreateParams);
+        ::SetPropW(hWnd, webViewPointerProperty, webView);
+    } else
+        webView = reinterpret_cast<PlatformWebView*>(::GetPropW(hWnd, webViewPointerProperty));
+
+    if (webView && webView->m_parentWindowMessageObserver)
+        webView->m_parentWindowMessageObserver->windowReceivedMessage(hWnd, message, wParam, lParam);
+
+    if (message == WM_NCDESTROY)
+        ::RemovePropW(hWnd, webViewPointerProperty);
+
+    return ::DefWindowProcW(hWnd, message, wParam, lParam);
+}
+
 } // namespace TestWebKitAPI
diff --git a/WebKitTools/TestWebKitAPI/win/TestWebKitAPI.vcproj b/WebKitTools/TestWebKitAPI/win/TestWebKitAPI.vcproj
index 0c8b83c..7d5b60b 100644
--- a/WebKitTools/TestWebKitAPI/win/TestWebKitAPI.vcproj
+++ b/WebKitTools/TestWebKitAPI/win/TestWebKitAPI.vcproj
@@ -405,6 +405,10 @@
 				RelativePath=".\PlatformWebViewWin.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\WindowMessageObserver.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="Tests"
@@ -460,6 +464,14 @@
 					RelativePath="..\Tests\WebKit2\WKStringJSString.cpp"
 					>
 				</File>
+				<Filter
+					Name="win"
+					>
+					<File
+						RelativePath="..\Tests\WebKit2\win\AltKeyGeneratesWMSysCommand.cpp"
+						>
+					</File>
+				</Filter>
 			</Filter>
 			<Filter
 				Name="WTF"
diff --git a/WebKitTools/TestWebKitAPI/win/WindowMessageObserver.h b/WebKitTools/TestWebKitAPI/win/WindowMessageObserver.h
new file mode 100644
index 0000000..3388816
--- /dev/null
+++ b/WebKitTools/TestWebKitAPI/win/WindowMessageObserver.h
@@ -0,0 +1,41 @@
+/*
+ * 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 WindowMessageObserver_h
+#define WindowMessageObserver_h
+
+namespace TestWebKitAPI {
+
+class WindowMessageObserver {
+public:
+    virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM) = 0;
+
+protected:
+    virtual ~WindowMessageObserver() { }
+};
+
+} // namespace TestWebKitAPI
+
+#endif // WindowMessageObserver_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list