| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/focus/focus_manager.h" | 5 #include "views/focus/focus_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return false; | 113 return false; |
| 114 } | 114 } |
| 115 #else | 115 #else |
| 116 if (IsTabTraversalKeyEvent(event)) { | 116 if (IsTabTraversalKeyEvent(event)) { |
| 117 AdvanceFocus(event.IsShiftDown()); | 117 AdvanceFocus(event.IsShiftDown()); |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 #endif | 120 #endif |
| 121 | 121 |
| 122 // Intercept arrow key messages to switch between grouped views. | 122 // Intercept arrow key messages to switch between grouped views. |
| 123 ui::KeyboardCode key_code = event.GetKeyCode(); | 123 ui::KeyboardCode key_code = event.key_code(); |
| 124 if (focused_view_ && focused_view_->GetGroup() != -1 && | 124 if (focused_view_ && focused_view_->GetGroup() != -1 && |
| 125 (key_code == ui::VKEY_UP || key_code == ui::VKEY_DOWN || | 125 (key_code == ui::VKEY_UP || key_code == ui::VKEY_DOWN || |
| 126 key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { | 126 key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { |
| 127 bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); | 127 bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); |
| 128 std::vector<View*> views; | 128 std::vector<View*> views; |
| 129 focused_view_->parent()->GetViewsWithGroup(focused_view_->GetGroup(), | 129 focused_view_->parent()->GetViewsWithGroup(focused_view_->GetGroup(), |
| 130 &views); | 130 &views); |
| 131 std::vector<View*>::const_iterator iter = std::find(views.begin(), | 131 std::vector<View*>::const_iterator iter = std::find(views.begin(), |
| 132 views.end(), | 132 views.end(), |
| 133 focused_view_); | 133 focused_view_); |
| 134 DCHECK(iter != views.end()); | 134 DCHECK(iter != views.end()); |
| 135 int index = static_cast<int>(iter - views.begin()); | 135 int index = static_cast<int>(iter - views.begin()); |
| 136 index += next ? 1 : -1; | 136 index += next ? 1 : -1; |
| 137 if (index < 0) { | 137 if (index < 0) { |
| 138 index = static_cast<int>(views.size()) - 1; | 138 index = static_cast<int>(views.size()) - 1; |
| 139 } else if (index >= static_cast<int>(views.size())) { | 139 } else if (index >= static_cast<int>(views.size())) { |
| 140 index = 0; | 140 index = 0; |
| 141 } | 141 } |
| 142 SetFocusedViewWithReason(views[index], kReasonFocusTraversal); | 142 SetFocusedViewWithReason(views[index], kReasonFocusTraversal); |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Process keyboard accelerators. | 146 // Process keyboard accelerators. |
| 147 // If the key combination matches an accelerator, the accelerator is | 147 // If the key combination matches an accelerator, the accelerator is |
| 148 // triggered, otherwise the key event is processed as usual. | 148 // triggered, otherwise the key event is processed as usual. |
| 149 Accelerator accelerator(event.GetKeyCode(), | 149 Accelerator accelerator(event.key_code(), |
| 150 event.IsShiftDown(), | 150 event.IsShiftDown(), |
| 151 event.IsControlDown(), | 151 event.IsControlDown(), |
| 152 event.IsAltDown()); | 152 event.IsAltDown()); |
| 153 if (ProcessAccelerator(accelerator)) { | 153 if (ProcessAccelerator(accelerator)) { |
| 154 // If a shortcut was activated for this keydown message, do not propagate | 154 // If a shortcut was activated for this keydown message, do not propagate |
| 155 // the event further. | 155 // the event further. |
| 156 return false; | 156 return false; |
| 157 } | 157 } |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( | 502 AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( |
| 503 const views::Accelerator& accelerator) const { | 503 const views::Accelerator& accelerator) const { |
| 504 AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator); | 504 AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator); |
| 505 if (map_iter == accelerators_.end() || map_iter->second.empty()) | 505 if (map_iter == accelerators_.end() || map_iter->second.empty()) |
| 506 return NULL; | 506 return NULL; |
| 507 return map_iter->second.front(); | 507 return map_iter->second.front(); |
| 508 } | 508 } |
| 509 | 509 |
| 510 // static | 510 // static |
| 511 bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { | 511 bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) { |
| 512 return key_event.GetKeyCode() == ui::VKEY_TAB && | 512 return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown(); |
| 513 !key_event.IsControlDown(); | |
| 514 } | 513 } |
| 515 | 514 |
| 516 void FocusManager::ViewRemoved(View* parent, View* removed) { | 515 void FocusManager::ViewRemoved(View* parent, View* removed) { |
| 517 if (focused_view_ && focused_view_ == removed) | 516 if (focused_view_ && focused_view_ == removed) |
| 518 ClearFocus(); | 517 ClearFocus(); |
| 519 } | 518 } |
| 520 | 519 |
| 521 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { | 520 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { |
| 522 DCHECK(std::find(focus_change_listeners_.begin(), | 521 DCHECK(std::find(focus_change_listeners_.begin(), |
| 523 focus_change_listeners_.end(), listener) == | 522 focus_change_listeners_.end(), listener) == |
| 524 focus_change_listeners_.end()) << "Adding a listener twice."; | 523 focus_change_listeners_.end()) << "Adding a listener twice."; |
| 525 focus_change_listeners_.push_back(listener); | 524 focus_change_listeners_.push_back(listener); |
| 526 } | 525 } |
| 527 | 526 |
| 528 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { | 527 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { |
| 529 FocusChangeListenerList::iterator place = | 528 FocusChangeListenerList::iterator place = |
| 530 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 529 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
| 531 listener); | 530 listener); |
| 532 if (place == focus_change_listeners_.end()) { | 531 if (place == focus_change_listeners_.end()) { |
| 533 NOTREACHED() << "Removing a listener that isn't registered."; | 532 NOTREACHED() << "Removing a listener that isn't registered."; |
| 534 return; | 533 return; |
| 535 } | 534 } |
| 536 focus_change_listeners_.erase(place); | 535 focus_change_listeners_.erase(place); |
| 537 } | 536 } |
| 538 | 537 |
| 539 } // namespace views | 538 } // namespace views |
| OLD | NEW |