Changeset 83633 in webkit


Ignore:
Timestamp:
Apr 12, 2011 1:44:17 PM (13 years ago)
Author:
jeffm@apple.com
Message:

2011-04-12 Jeff Miller <jeffm@apple.com>

Reviewed by Adam Roben.

WebKit2: Pressing Tab in Web Inspector's console does not cycle through completion options
https://bugs.webkit.org/show_bug.cgi?id=56020

Don't call TranslateMessage() in the MiniBrowser or TestWebKitAPI for key messages destined for a WebKit2 view,
since WebKit will do this for us. If we didn't do this, TranslateMessage() would be called twice,
which would generate two characters for every keypress (for example). I didn't bother doing this for
WebKitTestRunner, since it doesn't get any WM_KEYDOWN events.


Add new WebKit2/TranslateMessageGeneratesWMChar test to test expected TranslateMessage() behavior.

  • MiniBrowser/win/main.cpp: (shouldTranslateMessage): Added. (_tWinMain): Don't call TranslateMessage() unless shouldTranslateMessage() says to.
  • TestWebKitAPI/PlatformUtilities.h: Added shouldTranslateMessage() on Windows.
  • TestWebKitAPI/PlatformWebView.h: Added simulateAKeyDown().
  • TestWebKitAPI/Tests/WebKit2/win/TranslateMessageGeneratesWMChar.cpp: Added. (TestWebKitAPI::didNotHandleKeyEventCallback): Added. (TestWebKitAPI::runAndWatchForWMChar): Added. (TestWebKitAPI::TEST): Added.
  • TestWebKitAPI/win/PlatformUtilitiesWin.cpp: (TestWebKitAPI::Util::run): Don't call TranslateMessage() unless shouldTranslateMessage() says to. (TestWebKitAPI::Util::shouldTranslateMessage): Added.
  • TestWebKitAPI/win/PlatformWebViewWin.cpp: (TestWebKitAPI::PlatformWebView::simulateAKeyDown): Added.
  • TestWebKitAPI/win/TestWebKitAPI.vcproj: Added TranslateMessageGeneratesWMChar.cpp.

2011-04-12 Jeff Miller <jeffm@apple.com>

Reviewed by Adam Roben.

WebKit2: Pressing Tab in Web Inspector's console does not cycle through completion options
https://bugs.webkit.org/show_bug.cgi?id=56020

Safari was always calling TranslateMessage() on key events since it has no way to know whether
WebKit handled the event without a PageUIClient (which Safari only installs on pages inside
a Safari window), which was generating a WM_CHAR message containing the tab in this case. The fix
is for Safari to never call TranslateMessage() on key events outside of a Safari window, but this
means the WebPageProxy needs to do this for unhandled key events if there is no didNotHandleKeyEvent
callback in the PageUIClient.

  • UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::didReceiveEvent): Call TranslateMessage() on Windows for unhandled key events that can't be handled by the PageUIClient.
  • UIProcess/WebUIClient.cpp: (WebKit::WebUIClient::canNotHandleKeyEvent): Added.
  • UIProcess/WebUIClient.h: Added canNotHandleKeyEvent().
Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r83628 r83633  
     12011-04-12  Jeff Miller  <jeffm@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        WebKit2: Pressing Tab in Web Inspector's console does not cycle through completion options
     6        https://bugs.webkit.org/show_bug.cgi?id=56020
     7
     8        Safari was always calling TranslateMessage() on key events since it has no way to know whether
     9        WebKit handled the event without a PageUIClient (which Safari only installs on pages inside
     10        a Safari window), which was generating a WM_CHAR message containing the tab in this case.  The fix
     11        is for Safari to never call TranslateMessage() on key events outside of a Safari window, but this
     12        means the WebPageProxy needs to do this for unhandled key events if there is no didNotHandleKeyEvent
     13        callback in the PageUIClient.
     14
     15        * UIProcess/WebPageProxy.cpp:
     16        (WebKit::WebPageProxy::didReceiveEvent): Call TranslateMessage() on Windows for unhandled key events that can't be handled by the PageUIClient.
     17        * UIProcess/WebUIClient.cpp:
     18        (WebKit::WebUIClient::canNotHandleKeyEvent): Added.
     19        * UIProcess/WebUIClient.h: Added canNotHandleKeyEvent().
     20
    1212011-04-12  Alice Liu  <alice.liu@apple.com>
    222
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r83627 r83633  
    25642564            break;
    25652565
    2566         m_uiClient.didNotHandleKeyEvent(this, event);
     2566        if (m_uiClient.implementsDidNotHandleKeyEvent())
     2567            m_uiClient.didNotHandleKeyEvent(this, event);
     2568#if PLATFORM(WIN)
     2569        else
     2570            ::TranslateMessage(event.nativeEvent());
     2571#endif
    25672572        break;
    25682573    }
  • trunk/Source/WebKit2/UIProcess/WebUIClient.cpp

    r83531 r83633  
    156156}
    157157
     158bool WebUIClient::implementsDidNotHandleKeyEvent() const
     159{
     160    return m_client.didNotHandleKeyEvent;
     161}
     162
    158163void WebUIClient::didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event)
    159164{
  • trunk/Source/WebKit2/UIProcess/WebUIClient.h

    r83531 r83633  
    6767    void mouseDidMoveOverElement(WebPageProxy*, WebEvent::Modifiers, APIObject*);
    6868    void missingPluginButtonClicked(WebPageProxy*, const String& mimeType, const String& url, const String& pluginsPageURL);
     69   
     70    bool implementsDidNotHandleKeyEvent() const;
    6971    void didNotHandleKeyEvent(WebPageProxy*, const NativeWebKeyboardEvent&);
    7072
  • trunk/Tools/ChangeLog

    r83631 r83633  
     12011-04-12  Jeff Miller  <jeffm@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        WebKit2: Pressing Tab in Web Inspector's console does not cycle through completion options
     6        https://bugs.webkit.org/show_bug.cgi?id=56020
     7
     8        Don't call TranslateMessage() in the MiniBrowser or TestWebKitAPI for key messages destined for a WebKit2 view,
     9        since WebKit will do this for us.  If we didn't do this, TranslateMessage() would be called twice,
     10        which would generate two characters for every keypress (for example).  I didn't bother doing this for
     11        WebKitTestRunner, since it doesn't get any WM_KEYDOWN events.
     12       
     13        Add new WebKit2/TranslateMessageGeneratesWMChar test to test expected TranslateMessage() behavior.
     14
     15        * MiniBrowser/win/main.cpp:
     16        (shouldTranslateMessage): Added.
     17        (_tWinMain): Don't call TranslateMessage() unless shouldTranslateMessage() says to.
     18        * TestWebKitAPI/PlatformUtilities.h: Added shouldTranslateMessage() on Windows.
     19        * TestWebKitAPI/PlatformWebView.h: Added simulateAKeyDown().
     20        * TestWebKitAPI/Tests/WebKit2/win/TranslateMessageGeneratesWMChar.cpp: Added.
     21        (TestWebKitAPI::didNotHandleKeyEventCallback): Added.
     22        (TestWebKitAPI::runAndWatchForWMChar): Added.
     23        (TestWebKitAPI::TEST): Added.
     24        * TestWebKitAPI/win/PlatformUtilitiesWin.cpp:
     25        (TestWebKitAPI::Util::run): Don't call TranslateMessage() unless shouldTranslateMessage() says to.
     26        (TestWebKitAPI::Util::shouldTranslateMessage): Added.
     27        * TestWebKitAPI/win/PlatformWebViewWin.cpp:
     28        (TestWebKitAPI::PlatformWebView::simulateAKeyDown): Added.
     29        * TestWebKitAPI/win/TestWebKitAPI.vcproj: Added TranslateMessageGeneratesWMChar.cpp.
     30
    1312011-04-12  Dirk Pranke  <dpranke@chromium.org>
    232
  • trunk/Tools/MiniBrowser/win/main.cpp

    r57849 r83633  
    4242#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='" PROCESSORARCHITECTURE "' publicKeyToken='6595b64144ccf1df' language='*'\"")
    4343
     44static bool shouldTranslateMessage(const MSG& msg)
     45{
     46    // Only these four messages are actually translated by ::TranslateMessage or ::TranslateAccelerator.
     47    // It's useless (though harmless) to call those functions for other messages, so we always allow other messages to be translated.
     48    if (msg.message != WM_KEYDOWN && msg.message != WM_SYSKEYDOWN && msg.message != WM_KEYUP && msg.message != WM_SYSKEYUP)
     49        return true;
     50   
     51    wchar_t className[256];
     52    if (!::GetClassNameW(msg.hwnd, className, ARRAYSIZE(className)))
     53        return true;
     54
     55    // Don't call TranslateMessage() on key events destined for a WebKit2 view, WebKit will do this if it doesn't handle the message.
     56    // It would be nice to use some API here instead of hard-coding the window class name.
     57    return wcscmp(className, L"WebKit2WebViewWindowClass");
     58}
     59
    4460int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow)
    4561{
     
    5369        if (result == -1)
    5470            break;
    55         ::TranslateMessage(&message);
     71       
     72        if (shouldTranslateMessage(message))
     73            ::TranslateMessage(&message);
    5674
    5775        if (!MiniBrowser::shared().handleMessage(&message))
  • trunk/Tools/TestWebKitAPI/PlatformUtilities.h

    r82730 r83633  
    2929#include <WebKit2/WebKit2.h>
    3030#include <WebKit2/WKRetainPtr.h>
     31#include <wtf/Platform.h>
    3132#include <string>
    3233
     
    3637// Runs a platform runloop until the 'done' is true.
    3738void run(bool* done);
     39
     40#if PLATFORM(WIN)
     41bool shouldTranslateMessage(const MSG&);
     42#endif
    3843
    3944void sleep(double seconds);
  • trunk/Tools/TestWebKitAPI/PlatformWebView.h

    r79966 r83633  
    6666
    6767#if PLATFORM(WIN)
     68    void simulateAKeyDown();
    6869    void setParentWindowMessageObserver(WindowMessageObserver* observer) { m_parentWindowMessageObserver = observer; }
    6970#endif
  • trunk/Tools/TestWebKitAPI/win/PlatformUtilitiesWin.cpp

    r81116 r83633  
    5050        if (!result || result == -1)
    5151            break;
    52         ::TranslateMessage(&msg);
     52       
     53        if (shouldTranslateMessage(msg))
     54            ::TranslateMessage(&msg);
    5355        ::DispatchMessage(&msg);
    5456    }
     57}
     58
     59bool shouldTranslateMessage(const MSG& msg)
     60{
     61    // Only these four messages are actually translated by ::TranslateMessage or ::TranslateAccelerator.
     62    // It's useless (though harmless) to call those functions for other messages, so we always allow other messages to be translated.
     63    if (msg.message != WM_KEYDOWN && msg.message != WM_SYSKEYDOWN && msg.message != WM_KEYUP && msg.message != WM_SYSKEYUP)
     64        return true;
     65   
     66    wchar_t className[256];
     67    if (!::GetClassNameW(msg.hwnd, className, ARRAYSIZE(className)))
     68        return true;
     69
     70    // Don't call TranslateMessage() on key events destined for a WebKit2 view, WebKit will do this if it doesn't handle the message.
     71    // It would be nice to use some API here instead of hard-coding the window class name.
     72    return wcscmp(className, L"WebKit2WebViewWindowClass");
    5573}
    5674
  • trunk/Tools/TestWebKitAPI/win/PlatformWebViewWin.cpp

    r79966 r83633  
    9393}
    9494
     95void PlatformWebView::simulateAKeyDown()
     96{
     97    HWND window = WKViewGetWindow(m_view);
     98   
     99    // These values match what happens when you press the 'A' key in Notepad, as observed by Spy++.
     100    ::SendMessageW(window, WM_KEYDOWN, 'A', (1 << repeatCountBitOffset) | (30 << scanCodeBitOffset));
     101}
     102
    95103void PlatformWebView::simulateAltKeyPress()
    96104{
  • trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

    r82906 r83633  
    560560                                        </File>
    561561                                        <File
     562                                                RelativePath="..\Tests\WebKit2\win\TranslateMessageGeneratesWMChar.cpp"
     563                                                >
     564                                        </File>
     565                                        <File
    562566                                                RelativePath="..\Tests\WebKit2\win\WMCloseCallsUIClientClose.cpp"
    563567                                                >
Note: See TracChangeset for help on using the changeset viewer.