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

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

Issue 9402018: Experimental Extension Keybinding (first cut). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false); 67 ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false);
68 return ProcessAccelerator(accelerator); 68 return ProcessAccelerator(accelerator);
69 } else { 69 } else {
70 return false; 70 return false;
71 } 71 }
72 #else 72 #else
73 if (event.type() != ui::ET_KEY_PRESSED) 73 if (event.type() != ui::ET_KEY_PRESSED)
74 return false; 74 return false;
75 #endif 75 #endif
76 76
77 ui::Accelerator accelerator(event.key_code(),
78 event.IsShiftDown(),
79 event.IsControlDown(),
80 event.IsAltDown());
81
77 #if defined(OS_WIN) 82 #if defined(OS_WIN)
78 // If the focused view wants to process the key event as is, let it be. 83 // If the focused view wants to process the key event as is, let it be.
79 // On Linux we always dispatch key events to the focused view first, so 84 // On Linux we always dispatch key events to the focused view first, so
80 // we should not do this check here. See also NativeWidgetGtk::OnKeyEvent(). 85 // we should not do this check here. See also NativeWidgetGtk::OnKeyEvent().
81 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event)) 86 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event) &&
87 !accelerator_manager_->HasPriorityHandler(accelerator))
82 return true; 88 return true;
83 #endif 89 #endif
84 90
85 // Intercept Tab related messages for focus traversal. 91 // Intercept Tab related messages for focus traversal.
86 // Note that we don't do focus traversal if the root window is not part of the 92 // Note that we don't do focus traversal if the root window is not part of the
87 // active window hierarchy as this would mean we have no focused view and 93 // active window hierarchy as this would mean we have no focused view and
88 // would focus the first focusable view. 94 // would focus the first focusable view.
89 #if defined(OS_WIN) && !defined(USE_AURA) 95 #if defined(OS_WIN) && !defined(USE_AURA)
90 HWND top_window = widget_->GetNativeView(); 96 HWND top_window = widget_->GetNativeView();
91 HWND active_window = ::GetActiveWindow(); 97 HWND active_window = ::GetActiveWindow();
(...skipping 26 matching lines...) Expand all
118 } else if (index >= static_cast<int>(views.size())) { 124 } else if (index >= static_cast<int>(views.size())) {
119 index = 0; 125 index = 0;
120 } 126 }
121 SetFocusedViewWithReason(views[index], kReasonFocusTraversal); 127 SetFocusedViewWithReason(views[index], kReasonFocusTraversal);
122 return false; 128 return false;
123 } 129 }
124 130
125 // Process keyboard accelerators. 131 // Process keyboard accelerators.
126 // If the key combination matches an accelerator, the accelerator is 132 // If the key combination matches an accelerator, the accelerator is
127 // triggered, otherwise the key event is processed as usual. 133 // triggered, otherwise the key event is processed as usual.
128 ui::Accelerator accelerator(event.key_code(),
129 event.IsShiftDown(),
130 event.IsControlDown(),
131 event.IsAltDown());
132 if (ProcessAccelerator(accelerator)) { 134 if (ProcessAccelerator(accelerator)) {
133 // If a shortcut was activated for this keydown message, do not propagate 135 // If a shortcut was activated for this keydown message, do not propagate
134 // the event further. 136 // the event further.
135 return false; 137 return false;
136 } 138 }
137 return true; 139 return true;
138 } 140 }
139 141
140 void FocusManager::ValidateFocusedView() { 142 void FocusManager::ValidateFocusedView() {
141 if (focused_view_) { 143 if (focused_view_) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Forget menu key state when the window lost focus. 297 // Forget menu key state when the window lost focus.
296 should_handle_menu_key_release_ = false; 298 should_handle_menu_key_release_ = false;
297 #endif 299 #endif
298 ViewStorage* view_storage = ViewStorage::GetInstance(); 300 ViewStorage* view_storage = ViewStorage::GetInstance();
299 if (!view_storage) { 301 if (!view_storage) {
300 // This should never happen but bug 981648 seems to indicate it could. 302 // This should never happen but bug 981648 seems to indicate it could.
301 NOTREACHED(); 303 NOTREACHED();
302 return; 304 return;
303 } 305 }
304 306
305 // TODO (jcampan): when a TabContents containing a popup is closed, the focus 307 // TODO(jcivelli): when a TabContents containing a popup is closed, the focus
306 // is stored twice causing an assert. We should find a better alternative than 308 // is stored twice causing an assert. We should find a better alternative than
307 // removing the view from the storage explicitly. 309 // removing the view from the storage explicitly.
308 view_storage->RemoveView(stored_focused_view_storage_id_); 310 view_storage->RemoveView(stored_focused_view_storage_id_);
309 311
310 if (!focused_view_) 312 if (!focused_view_)
311 return; 313 return;
312 314
313 view_storage->StoreView(stored_focused_view_storage_id_, focused_view_); 315 view_storage->StoreView(stored_focused_view_storage_id_, focused_view_);
314 316
315 View* v = focused_view_; 317 View* v = focused_view_;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 FocusSearch::DOWN, 400 FocusSearch::DOWN,
399 false, 401 false,
400 &new_focus_traversable, 402 &new_focus_traversable,
401 &new_starting_view); 403 &new_starting_view);
402 } 404 }
403 return v; 405 return v;
404 } 406 }
405 407
406 void FocusManager::RegisterAccelerator( 408 void FocusManager::RegisterAccelerator(
407 const ui::Accelerator& accelerator, 409 const ui::Accelerator& accelerator,
410 bool priority,
408 ui::AcceleratorTarget* target) { 411 ui::AcceleratorTarget* target) {
409 accelerator_manager_->Register(accelerator, target); 412 accelerator_manager_->Register(accelerator, priority, target);
410 } 413 }
411 414
412 void FocusManager::UnregisterAccelerator(const ui::Accelerator& accelerator, 415 void FocusManager::UnregisterAccelerator(const ui::Accelerator& accelerator,
413 ui::AcceleratorTarget* target) { 416 ui::AcceleratorTarget* target) {
414 accelerator_manager_->Unregister(accelerator, target); 417 accelerator_manager_->Unregister(accelerator, target);
415 } 418 }
416 419
417 void FocusManager::UnregisterAccelerators(ui::AcceleratorTarget* target) { 420 void FocusManager::UnregisterAccelerators(ui::AcceleratorTarget* target) {
418 accelerator_manager_->UnregisterAll(target); 421 accelerator_manager_->UnregisterAll(target);
419 } 422 }
(...skipping 17 matching lines...) Expand all
437 void FocusManager::ResetMenuKeyState() { 440 void FocusManager::ResetMenuKeyState() {
438 should_handle_menu_key_release_ = false; 441 should_handle_menu_key_release_ = false;
439 } 442 }
440 #endif 443 #endif
441 444
442 ui::AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( 445 ui::AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator(
443 const ui::Accelerator& accelerator) const { 446 const ui::Accelerator& accelerator) const {
444 return accelerator_manager_->GetCurrentTarget(accelerator); 447 return accelerator_manager_->GetCurrentTarget(accelerator);
445 } 448 }
446 449
450 bool FocusManager::HasPriorityHandler(
451 const ui::Accelerator& accelerator) const {
452 return accelerator_manager_->HasPriorityHandler(accelerator);
453 }
454
447 // static 455 // static
448 bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { 456 bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) {
449 return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown(); 457 return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown();
450 } 458 }
451 459
452 void FocusManager::ViewRemoved(View* removed) { 460 void FocusManager::ViewRemoved(View* removed) {
453 // If the view being removed contains (or is) the focused view, 461 // If the view being removed contains (or is) the focused view,
454 // clear the focus. However, it's not safe to call ClearFocus() 462 // clear the focus. However, it's not safe to call ClearFocus()
455 // (and in turn ClearNativeFocus()) here because ViewRemoved() can 463 // (and in turn ClearNativeFocus()) here because ViewRemoved() can
456 // be called while the top level widget is being destroyed. 464 // be called while the top level widget is being destroyed.
457 if (focused_view_ && removed && removed->Contains(focused_view_)) 465 if (focused_view_ && removed && removed->Contains(focused_view_))
458 SetFocusedView(NULL); 466 SetFocusedView(NULL);
459 } 467 }
460 468
461 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { 469 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) {
462 focus_change_listeners_.AddObserver(listener); 470 focus_change_listeners_.AddObserver(listener);
463 } 471 }
464 472
465 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { 473 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) {
466 focus_change_listeners_.RemoveObserver(listener); 474 focus_change_listeners_.RemoveObserver(listener);
467 } 475 }
468 476
469 } // namespace views 477 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698