diff options
Diffstat (limited to 'webkit/glue/webview_impl.cc')
-rw-r--r-- | webkit/glue/webview_impl.cc | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 445979f..2fac917 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -480,8 +480,7 @@ void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) { } bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { - DCHECK((event.type == WebInputEvent::RAW_KEY_DOWN) || - (event.type == WebInputEvent::KEY_DOWN) || + DCHECK((event.type == WebInputEvent::KEY_DOWN) || (event.type == WebInputEvent::KEY_UP)); // Please refer to the comments explaining the suppress_next_keypress_event_ @@ -506,9 +505,9 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { #if defined(OS_WIN) // TODO(pinkerton): figure out these keycodes on non-windows - if (((event.modifiers == 0) && (event.windows_key_code == VK_APPS)) || + if (((event.modifiers == 0) && (event.key_code == VK_APPS)) || ((event.modifiers == WebInputEvent::SHIFT_KEY) && - (event.windows_key_code == VK_F10))) { + (event.key_code == VK_F10))) { SendContextMenuEvent(event); return true; } @@ -516,8 +515,11 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { MakePlatformKeyboardEvent evt(event); - if (WebInputEvent::RAW_KEY_DOWN == event.type) { - if (handler->keyEvent(evt) && !evt.isSystemKey()) { +#if !defined(OS_MACOSX) + if (WebInputEvent::KEY_DOWN == event.type) { + MakePlatformKeyboardEvent evt_rawkeydown = evt; + evt_rawkeydown.SetKeyType(WebCore::PlatformKeyboardEvent::RawKeyDown); + if (handler->keyEvent(evt_rawkeydown) && !evt_rawkeydown.isSystemKey()) { suppress_next_keypress_event_ = true; return true; } @@ -526,6 +528,19 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { return true; } } +#else + // Windows and Cocoa handle events in rather different ways. On Windows, + // you get two events: WM_KEYDOWN/WM_KEYUP and WM_CHAR. In + // PlatformKeyboardEvent, RawKeyDown represents the raw messages. When + // processing them, we don't process text editing events, since we'll be + // getting the data soon enough. In Cocoa, we get one event with both the + // raw and processed data. Therefore we need to keep the type as KeyDown, so + // that we'll know that this is the only time we'll have the event and that + // we need to do our thing. + if (handler->keyEvent(evt)) { + return true; + } +#endif return KeyEventDefault(event); } @@ -533,19 +548,18 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { if (!autocomplete_popup_showing_ || // Home and End should be left to the text field to process. - event.windows_key_code == base::VKEY_HOME || - event.windows_key_code == base::VKEY_END) { + event.key_code == base::VKEY_HOME || event.key_code == base::VKEY_END) { return false; } - if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code)) + if (!autocomplete_popup_->isInterestedInEventForKey(event.key_code)) return false; if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { #if defined(OS_WIN) // We need to ignore the next CHAR event after this otherwise pressing // enter when selecting an item in the menu will go to the page. - if (WebInputEvent::RAW_KEY_DOWN == event.type) + if (WebInputEvent::KEY_DOWN == event.type) suppress_next_keypress_event_ = true; #endif return true; @@ -679,7 +693,7 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { case WebInputEvent::CHAR: { #if defined(OS_WIN) // TODO(pinkerton): hook this up for non-win32 - if (event.windows_key_code == VK_SPACE) { + if (event.key_code == VK_SPACE) { int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ? VK_PRIOR : VK_NEXT); return ScrollViewWithKeyboard(key_code); @@ -688,9 +702,9 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { break; } - case WebInputEvent::RAW_KEY_DOWN: { + case WebInputEvent::KEY_DOWN: { if (event.modifiers == WebInputEvent::CTRL_KEY) { - switch (event.windows_key_code) { + switch (event.key_code) { case 'A': GetFocusedFrame()->SelectAll(); return true; @@ -715,7 +729,7 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { } #if defined(OS_WIN) if (!event.system_key) { - return ScrollViewWithKeyboard(event.windows_key_code); + return ScrollViewWithKeyboard(event.key_code); } #endif break; @@ -960,7 +974,6 @@ bool WebViewImpl::HandleInputEvent(const WebInputEvent* input_event) { MouseUp(*static_cast<const WebMouseEvent*>(input_event)); break; - case WebInputEvent::RAW_KEY_DOWN: case WebInputEvent::KEY_DOWN: case WebInputEvent::KEY_UP: handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event)); @@ -1219,14 +1232,15 @@ void WebViewImpl::SetInitialFocus(bool reverse) { // Since we don't have a keyboard event, we'll create one. WebKeyboardEvent keyboard_event; - keyboard_event.type = WebInputEvent::RAW_KEY_DOWN; + keyboard_event.type = WebInputEvent::KEY_DOWN; if (reverse) keyboard_event.modifiers = WebInputEvent::SHIFT_KEY; // VK_TAB which is only defined on Windows. - keyboard_event.windows_key_code = 0x09; + keyboard_event.key_code = 0x09; MakePlatformKeyboardEvent platform_event(keyboard_event); // We have to set the key type explicitly to avoid an assert in the // KeyboardEvent constructor. + platform_event.SetKeyType(PlatformKeyboardEvent::RawKeyDown); RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event, NULL); page()->focusController()->setInitialFocus( |