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

Side by Side Diff: ui/views/focus/focus_manager.cc

Issue 10134036: Let Chrome app handle Ash accelerators first if the app is launched as a window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 7 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 | Annotate | Revision Log
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/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Always reset |should_handle_menu_key_release_| unless we are handling a 47 // Always reset |should_handle_menu_key_release_| unless we are handling a
48 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only 48 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only
49 // be activated when handling a VKEY_MENU key release event which is preceded 49 // be activated when handling a VKEY_MENU key release event which is preceded
50 // by an un-handled VKEY_MENU key press event. 50 // by an un-handled VKEY_MENU key press event.
51 if (key_code != ui::VKEY_MENU || event.type() != ui::ET_KEY_RELEASED) 51 if (key_code != ui::VKEY_MENU || event.type() != ui::ET_KEY_RELEASED)
52 should_handle_menu_key_release_ = false; 52 should_handle_menu_key_release_ = false;
53 53
54 if (event.type() == ui::ET_KEY_PRESSED) { 54 if (event.type() == ui::ET_KEY_PRESSED) {
55 // VKEY_MENU is triggered by key release event. 55 // VKEY_MENU is triggered by key release event.
56 // FocusManager::OnKeyEvent() returns false when the key has been consumed. 56 // FocusManager::OnKeyEvent() returns false when the key has been consumed.
57 if (key_code == ui::VKEY_MENU) { 57 if ((key_code == ui::VKEY_MENU) &&
58 (event.flags() & ~ui::EF_ALT_DOWN) == 0) {
58 should_handle_menu_key_release_ = true; 59 should_handle_menu_key_release_ = true;
59 return false; 60 return false;
60 } 61 }
61 // Pass through to the reset of OnKeyEvent. 62 // Pass through to the rest of OnKeyEvent.
62 } else if (key_code == ui::VKEY_MENU && should_handle_menu_key_release_ && 63 } else if (key_code == ui::VKEY_MENU && should_handle_menu_key_release_ &&
63 (event.flags() & ~ui::EF_ALT_DOWN) == 0) { 64 (event.flags() & ~ui::EF_ALT_DOWN) == 0) {
64 // Trigger VKEY_MENU when only this key is pressed and released, and both 65 // Trigger VKEY_MENU when only this key is pressed and released, and both
65 // press and release events are not handled by others. 66 // press and release events are not handled by others.
66 ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false); 67 ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false);
67 return ProcessAccelerator(accelerator); 68 return ProcessAccelerator(accelerator);
68 } else { 69 } else if (event.type() != ui::ET_KEY_RELEASED) {
69 return false; 70 return false;
70 } 71 }
71 #else 72 #else
72 if (event.type() != ui::ET_KEY_PRESSED) 73 if (event.type() != ui::ET_KEY_PRESSED && event.type() != ui::ET_KEY_RELEASED)
73 return false; 74 return false;
74 #endif 75 #endif
75 76
76 ui::Accelerator accelerator(event.key_code(), 77 ui::Accelerator accelerator(event.key_code(),
77 event.IsShiftDown(), 78 event.IsShiftDown(),
78 event.IsControlDown(), 79 event.IsControlDown(),
79 event.IsAltDown()); 80 event.IsAltDown());
81 accelerator.set_type(event.type());
80 82
83 if (event.type() == ui::ET_KEY_PRESSED) {
81 #if defined(OS_WIN) 84 #if defined(OS_WIN)
82 // If the focused view wants to process the key event as is, let it be. 85 // If the focused view wants to process the key event as is, let it be.
83 // This is not used for linux/aura. 86 // This is not used for linux/aura.
84 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event) && 87 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event) &&
85 !accelerator_manager_->HasPriorityHandler(accelerator)) 88 !accelerator_manager_->HasPriorityHandler(accelerator))
86 return true; 89 return true;
87 #endif 90 #endif
88 91
89 // Intercept Tab related messages for focus traversal. 92 // Intercept Tab related messages for focus traversal.
90 // Note that we don't do focus traversal if the root window is not part of the 93 // Note that we don't do focus traversal if the root window is not part of
91 // active window hierarchy as this would mean we have no focused view and 94 // the active window hierarchy as this would mean we have no focused view
92 // would focus the first focusable view. 95 // and would focus the first focusable view.
93 #if defined(OS_WIN) && !defined(USE_AURA) 96 #if defined(OS_WIN) && !defined(USE_AURA)
94 HWND top_window = widget_->GetNativeView(); 97 HWND top_window = widget_->GetNativeView();
95 HWND active_window = ::GetActiveWindow(); 98 HWND active_window = ::GetActiveWindow();
96 if ((active_window == top_window || ::IsChild(active_window, top_window)) && 99 if ((active_window == top_window || ::IsChild(active_window, top_window)) &&
97 IsTabTraversalKeyEvent(event)) { 100 IsTabTraversalKeyEvent(event)) {
98 AdvanceFocus(event.IsShiftDown()); 101 AdvanceFocus(event.IsShiftDown());
99 return false; 102 return false;
100 } 103 }
101 #else 104 #else
102 if (IsTabTraversalKeyEvent(event)) { 105 if (IsTabTraversalKeyEvent(event)) {
103 AdvanceFocus(event.IsShiftDown()); 106 AdvanceFocus(event.IsShiftDown());
104 return false; 107 return false;
105 } 108 }
106 #endif 109 #endif
107 110
108 // Intercept arrow key messages to switch between grouped views. 111 // Intercept arrow key messages to switch between grouped views.
109 if (focused_view_ && focused_view_->GetGroup() != -1 && 112 if (focused_view_ && focused_view_->GetGroup() != -1 &&
110 (key_code == ui::VKEY_UP || key_code == ui::VKEY_DOWN || 113 (key_code == ui::VKEY_UP || key_code == ui::VKEY_DOWN ||
111 key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { 114 key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) {
112 bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); 115 bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN);
113 View::Views views; 116 View::Views views;
114 focused_view_->parent()->GetViewsInGroup(focused_view_->GetGroup(), &views); 117 focused_view_->parent()->GetViewsInGroup(focused_view_->GetGroup(),
115 View::Views::const_iterator i( 118 &views);
116 std::find(views.begin(), views.end(), focused_view_)); 119 View::Views::const_iterator i(
117 DCHECK(i != views.end()); 120 std::find(views.begin(), views.end(), focused_view_));
118 int index = static_cast<int>(i - views.begin()); 121 DCHECK(i != views.end());
119 index += next ? 1 : -1; 122 int index = static_cast<int>(i - views.begin());
120 if (index < 0) { 123 index += next ? 1 : -1;
121 index = static_cast<int>(views.size()) - 1; 124 if (index < 0) {
122 } else if (index >= static_cast<int>(views.size())) { 125 index = static_cast<int>(views.size()) - 1;
123 index = 0; 126 } else if (index >= static_cast<int>(views.size())) {
127 index = 0;
128 }
129 SetFocusedViewWithReason(views[index], kReasonFocusTraversal);
130 return false;
124 } 131 }
125 SetFocusedViewWithReason(views[index], kReasonFocusTraversal);
126 return false;
127 } 132 }
128 133
129 // Process keyboard accelerators. 134 // Process keyboard accelerators.
130 // If the key combination matches an accelerator, the accelerator is 135 // If the key combination matches an accelerator, the accelerator is
131 // triggered, otherwise the key event is processed as usual. 136 // triggered, otherwise the key event is processed as usual.
132 if (ProcessAccelerator(accelerator)) { 137 if (ProcessAccelerator(accelerator)) {
133 // If a shortcut was activated for this keydown message, do not propagate 138 // If a shortcut was activated for this keydown message, do not propagate
134 // the event further. 139 // the event further.
135 return false; 140 return false;
136 } 141 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 465
461 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { 466 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) {
462 focus_change_listeners_.AddObserver(listener); 467 focus_change_listeners_.AddObserver(listener);
463 } 468 }
464 469
465 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { 470 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) {
466 focus_change_listeners_.RemoveObserver(listener); 471 focus_change_listeners_.RemoveObserver(listener);
467 } 472 }
468 473
469 } // namespace views 474 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698