summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 22:58:17 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 22:58:17 +0000
commit721eb3b8036edf6ba5e58189689b9a4cc4d819e9 (patch)
tree8612d990e56ddd008e566b9aaf61474cf394d827 /chrome/views
parentd167773523031148ad7145019a4c835073ebc46c (diff)
downloadchromium_src-721eb3b8036edf6ba5e58189689b9a4cc4d819e9.zip
chromium_src-721eb3b8036edf6ba5e58189689b9a4cc4d819e9.tar.gz
chromium_src-721eb3b8036edf6ba5e58189689b9a4cc4d819e9.tar.bz2
Handle keys like alt-f4 when focus has been cleared by making sure we don't eat them when no view wants to process them.
I also took the opportunity to shorten ProcessKeyEvent(). BUG=8035 Review URL: http://codereview.chromium.org/28145 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10397 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/root_view.cc47
-rw-r--r--chrome/views/root_view.h7
-rw-r--r--chrome/views/widget_win.cc4
3 files changed, 26 insertions, 32 deletions
diff --git a/chrome/views/root_view.cc b/chrome/views/root_view.cc
index 4ec6eda..dfff6e4 100644
--- a/chrome/views/root_view.cc
+++ b/chrome/views/root_view.cc
@@ -837,43 +837,36 @@ bool RootView::IsViewFocusableCandidate(View* v, int skip_group_id) {
v->GetGroup() != skip_group_id);
}
-void RootView::ProcessKeyEvent(const KeyEvent& event) {
- View* v;
+bool RootView::ProcessKeyEvent(const KeyEvent& event) {
bool consumed = false;
- if (GetFocusedView()) {
+ View* v = GetFocusedView();
#if defined(OS_WIN)
- // Special case to handle right-click context menus triggered by the
- // keyboard.
- if ((event.GetCharacter() == VK_APPS) ||
- (event.GetCharacter() == VK_F10 && event.IsShiftDown())) {
- v = GetFocusedView();
- if (v->IsEnabled()) {
- gfx::Point screen_loc = v->GetKeyboardContextMenuLocation();
- v->ShowContextMenu(screen_loc.x(), screen_loc.y(), false);
- return;
- }
- }
+ // Special case to handle right-click context menus triggered by the
+ // keyboard.
+ if (v && v->IsEnabled() && ((event.GetCharacter() == VK_APPS) ||
+ (event.GetCharacter() == VK_F10 && event.IsShiftDown()))) {
+ gfx::Point screen_loc = v->GetKeyboardContextMenuLocation();
+ v->ShowContextMenu(screen_loc.x(), screen_loc.y(), false);
+ return true;
+ }
#else
- // TODO(port): The above block needs the VK_* refactored out.
- NOTIMPLEMENTED();
+ // TODO(port): The above block needs the VK_* refactored out.
+ NOTIMPLEMENTED();
#endif
- for (v = GetFocusedView();
- v && v != this && !consumed; v = v->GetParent()) {
- if (event.GetType() == Event::ET_KEY_PRESSED)
- consumed = v->OnKeyPressed(event);
- else
- consumed = v->OnKeyReleased(event);
- }
+ for (; v && v != this && !consumed; v = v->GetParent()) {
+ consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
+ v->OnKeyPressed(event) : v->OnKeyReleased(event);
}
if (!consumed && default_keyboard_hander_) {
- if (event.GetType() == Event::ET_KEY_PRESSED)
- default_keyboard_hander_->OnKeyPressed(event);
- else
- default_keyboard_hander_->OnKeyReleased(event);
+ consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
+ default_keyboard_hander_->OnKeyPressed(event) :
+ default_keyboard_hander_->OnKeyReleased(event);
}
+
+ return consumed;
}
bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) {
diff --git a/chrome/views/root_view.h b/chrome/views/root_view.h
index f1a0d89..6538625 100644
--- a/chrome/views/root_view.h
+++ b/chrome/views/root_view.h
@@ -118,9 +118,10 @@ class RootView : public View,
// no View currently has the focus.
View* GetFocusedView();
- // Process a key event. Send the event to the focused view and up
- // the focus path until the event is consumed.
- virtual void ProcessKeyEvent(const KeyEvent& event);
+ // Process a key event. Send the event to the focused view and up the focus
+ // path, and finally to the default keyboard handler, until someone consumes
+ // it. Returns whether anyone consumed the event.
+ bool ProcessKeyEvent(const KeyEvent& event);
// Set the default keyboard handler. The default keyboard handler is
// a view that will get an opportunity to process key events when all
diff --git a/chrome/views/widget_win.cc b/chrome/views/widget_win.cc
index 47edf1b..fea61da 100644
--- a/chrome/views/widget_win.cc
+++ b/chrome/views/widget_win.cc
@@ -518,12 +518,12 @@ LRESULT WidgetWin::OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param) {
void WidgetWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) {
KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags);
- root_view_->ProcessKeyEvent(event);
+ SetMsgHandled(root_view_->ProcessKeyEvent(event));
}
void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) {
KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags);
- root_view_->ProcessKeyEvent(event);
+ SetMsgHandled(root_view_->ProcessKeyEvent(event));
}
void WidgetWin::OnLButtonDown(UINT flags, const CPoint& point) {