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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 // Perform a safe iteration over the focus listeners, as the array of | 57 // Perform a safe iteration over the focus listeners, as the array of |
58 // may change during notification. | 58 // may change during notification. |
59 WidgetFocusChangeListenerList local_listeners(focus_change_listeners_); | 59 WidgetFocusChangeListenerList local_listeners(focus_change_listeners_); |
60 WidgetFocusChangeListenerList::iterator iter(local_listeners.begin()); | 60 WidgetFocusChangeListenerList::iterator iter(local_listeners.begin()); |
61 for (;iter != local_listeners.end(); ++iter) { | 61 for (;iter != local_listeners.end(); ++iter) { |
62 (*iter)->NativeFocusWillChange(focused_before, focused_now); | 62 (*iter)->NativeFocusWillChange(focused_before, focused_now); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
| 66 // static |
| 67 FocusManager::WidgetFocusManager* |
| 68 FocusManager::WidgetFocusManager::GetInstance() { |
| 69 return Singleton<WidgetFocusManager>::get(); |
| 70 } |
| 71 |
66 // FocusManager ----------------------------------------------------- | 72 // FocusManager ----------------------------------------------------- |
67 | 73 |
68 FocusManager::FocusManager(Widget* widget) | 74 FocusManager::FocusManager(Widget* widget) |
69 : widget_(widget), | 75 : widget_(widget), |
70 focused_view_(NULL), | 76 focused_view_(NULL), |
71 focus_change_reason_(kReasonDirectFocusChange) { | 77 focus_change_reason_(kReasonDirectFocusChange) { |
72 DCHECK(widget_); | 78 DCHECK(widget_); |
73 stored_focused_view_storage_id_ = | 79 stored_focused_view_storage_id_ = |
74 ViewStorage::GetSharedInstance()->CreateStorageID(); | 80 ViewStorage::GetSharedInstance()->CreateStorageID(); |
75 } | 81 } |
76 | 82 |
77 FocusManager::~FocusManager() { | 83 FocusManager::~FocusManager() { |
78 // If there are still registered FocusChange listeners, chances are they were | 84 // If there are still registered FocusChange listeners, chances are they were |
79 // leaked so warn about them. | 85 // leaked so warn about them. |
80 DCHECK(focus_change_listeners_.empty()); | 86 DCHECK(focus_change_listeners_.empty()); |
81 } | 87 } |
82 | 88 |
83 // static | 89 // static |
84 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { | 90 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { |
85 return Singleton<WidgetFocusManager>::get(); | 91 return WidgetFocusManager::GetInstance(); |
86 } | 92 } |
87 | 93 |
88 bool FocusManager::OnKeyEvent(const KeyEvent& event) { | 94 bool FocusManager::OnKeyEvent(const KeyEvent& event) { |
89 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
90 // If the focused view wants to process the key event as is, let it be. | 96 // If the focused view wants to process the key event as is, let it be. |
91 // On Linux we always dispatch key events to the focused view first, so | 97 // On Linux we always dispatch key events to the focused view first, so |
92 // we should not do this check here. See also WidgetGtk::OnKeyEvent(). | 98 // we should not do this check here. See also WidgetGtk::OnKeyEvent(). |
93 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event)) | 99 if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event)) |
94 return true; | 100 return true; |
95 #endif | 101 #endif |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 530 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
525 listener); | 531 listener); |
526 if (place == focus_change_listeners_.end()) { | 532 if (place == focus_change_listeners_.end()) { |
527 NOTREACHED() << "Removing a listener that isn't registered."; | 533 NOTREACHED() << "Removing a listener that isn't registered."; |
528 return; | 534 return; |
529 } | 535 } |
530 focus_change_listeners_.erase(place); | 536 focus_change_listeners_.erase(place); |
531 } | 537 } |
532 | 538 |
533 } // namespace views | 539 } // namespace views |
OLD | NEW |