Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: ui/views/controls/webview/unhandled_keyboard_event_handler.cc

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 5 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
6 6
7 #include "ui/content_accelerators/accelerator_util.h" 7 #include "ui/content_accelerators/accelerator_util.h"
8 #include "ui/views/focus/focus_manager.h" 8 #include "ui/views/focus/focus_manager.h"
9 9
10 namespace views { 10 namespace views {
11 11
12 UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler() 12 UnhandledKeyboardEventHandler::UnhandledKeyboardEventHandler()
13 : ignore_next_char_event_(false) { 13 : ignore_next_char_event_(false) {
14 } 14 }
15 15
16 UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() { 16 UnhandledKeyboardEventHandler::~UnhandledKeyboardEventHandler() {
17 } 17 }
18 18
19 void UnhandledKeyboardEventHandler::HandleKeyboardEvent( 19 void UnhandledKeyboardEventHandler::HandleKeyboardEvent(
20 const content::NativeWebKeyboardEvent& event, 20 const content::NativeWebKeyboardEvent& event,
21 FocusManager* focus_manager) { 21 FocusManager* focus_manager) {
22 if (!focus_manager) { 22 if (!focus_manager) {
23 NOTREACHED(); 23 NOTREACHED();
24 return; 24 return;
25 } 25 }
26 // Previous calls to TranslateMessage can generate Char events as well as 26 // Previous calls to TranslateMessage can generate Char events as well as
27 // RawKeyDown events, even if the latter triggered an accelerator. In these 27 // RawKeyDown events, even if the latter triggered an accelerator. In these
28 // cases, we discard the Char events. 28 // cases, we discard the Char events.
29 if (event.type == blink::WebInputEvent::Char && ignore_next_char_event_) { 29 if (event.type() == blink::WebInputEvent::Char && ignore_next_char_event_) {
30 ignore_next_char_event_ = false; 30 ignore_next_char_event_ = false;
31 return; 31 return;
32 } 32 }
33 // It's necessary to reset this flag, because a RawKeyDown event may not 33 // It's necessary to reset this flag, because a RawKeyDown event may not
34 // always generate a Char event. 34 // always generate a Char event.
35 ignore_next_char_event_ = false; 35 ignore_next_char_event_ = false;
36 36
37 if (event.type == blink::WebInputEvent::RawKeyDown) { 37 if (event.type() == blink::WebInputEvent::RawKeyDown) {
38 ui::Accelerator accelerator = 38 ui::Accelerator accelerator =
39 ui::GetAcceleratorFromNativeWebKeyboardEvent(event); 39 ui::GetAcceleratorFromNativeWebKeyboardEvent(event);
40 40
41 // This is tricky: we want to set ignore_next_char_event_ if 41 // This is tricky: we want to set ignore_next_char_event_ if
42 // ProcessAccelerator returns true. But ProcessAccelerator might delete 42 // ProcessAccelerator returns true. But ProcessAccelerator might delete
43 // |this| if the accelerator is a "close tab" one. So we speculatively 43 // |this| if the accelerator is a "close tab" one. So we speculatively
44 // set the flag and fix it if no event was handled. 44 // set the flag and fix it if no event was handled.
45 ignore_next_char_event_ = true; 45 ignore_next_char_event_ = true;
46 46
47 if (focus_manager->ProcessAccelerator(accelerator)) { 47 if (focus_manager->ProcessAccelerator(accelerator)) {
48 return; 48 return;
49 } 49 }
50 50
51 // ProcessAccelerator didn't handle the accelerator, so we know both 51 // ProcessAccelerator didn't handle the accelerator, so we know both
52 // that |this| is still valid, and that we didn't want to set the flag. 52 // that |this| is still valid, and that we didn't want to set the flag.
53 ignore_next_char_event_ = false; 53 ignore_next_char_event_ = false;
54 } 54 }
55 55
56 if (event.os_event && !event.skip_in_browser) 56 if (event.os_event && !event.skip_in_browser)
57 HandleNativeKeyboardEvent(event.os_event, focus_manager); 57 HandleNativeKeyboardEvent(event.os_event, focus_manager);
58 } 58 }
59 59
60 } // namespace views 60 } // namespace views
OLDNEW
« no previous file with comments | « ui/events/blink/web_input_event_unittest.cc ('k') | ui/web_dialogs/web_dialog_web_contents_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698