OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
11 #if defined(OS_LINUX) | 11 #if defined(OS_LINUX) |
12 #include <gtk/gtk.h> | 12 #include <gtk/gtk.h> |
13 #endif | 13 #endif |
14 | 14 |
| 15 #include "base/auto_reset.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
17 #include "views/accelerator.h" | 18 #include "views/accelerator.h" |
18 #include "views/focus/focus_search.h" | 19 #include "views/focus/focus_search.h" |
19 #include "views/focus/view_storage.h" | 20 #include "views/focus/view_storage.h" |
20 #include "views/view.h" | 21 #include "views/view.h" |
21 #include "views/widget/root_view.h" | 22 #include "views/widget/root_view.h" |
22 #include "views/widget/widget.h" | 23 #include "views/widget/widget.h" |
23 | 24 |
24 namespace views { | 25 namespace views { |
(...skipping 29 matching lines...) Expand all Loading... |
54 FocusManager::WidgetFocusManager* | 55 FocusManager::WidgetFocusManager* |
55 FocusManager::WidgetFocusManager::GetInstance() { | 56 FocusManager::WidgetFocusManager::GetInstance() { |
56 return Singleton<WidgetFocusManager>::get(); | 57 return Singleton<WidgetFocusManager>::get(); |
57 } | 58 } |
58 | 59 |
59 // FocusManager ----------------------------------------------------- | 60 // FocusManager ----------------------------------------------------- |
60 | 61 |
61 FocusManager::FocusManager(Widget* widget) | 62 FocusManager::FocusManager(Widget* widget) |
62 : widget_(widget), | 63 : widget_(widget), |
63 focused_view_(NULL), | 64 focused_view_(NULL), |
64 focus_change_reason_(kReasonDirectFocusChange) { | 65 focus_change_reason_(kReasonDirectFocusChange), |
| 66 is_changing_focus_(false) { |
65 DCHECK(widget_); | 67 DCHECK(widget_); |
66 stored_focused_view_storage_id_ = | 68 stored_focused_view_storage_id_ = |
67 ViewStorage::GetInstance()->CreateStorageID(); | 69 ViewStorage::GetInstance()->CreateStorageID(); |
68 } | 70 } |
69 | 71 |
70 FocusManager::~FocusManager() { | 72 FocusManager::~FocusManager() { |
71 } | 73 } |
72 | 74 |
73 // static | 75 // static |
74 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { | 76 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 265 } |
264 } | 266 } |
265 return NULL; | 267 return NULL; |
266 } | 268 } |
267 | 269 |
268 void FocusManager::SetFocusedViewWithReason( | 270 void FocusManager::SetFocusedViewWithReason( |
269 View* view, FocusChangeReason reason) { | 271 View* view, FocusChangeReason reason) { |
270 if (focused_view_ == view) | 272 if (focused_view_ == view) |
271 return; | 273 return; |
272 | 274 |
| 275 AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); |
273 // Update the reason for the focus change (since this is checked by | 276 // Update the reason for the focus change (since this is checked by |
274 // some listeners), then notify all listeners. | 277 // some listeners), then notify all listeners. |
275 focus_change_reason_ = reason; | 278 focus_change_reason_ = reason; |
276 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 279 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, |
277 FocusWillChange(focused_view_, view)); | 280 FocusWillChange(focused_view_, view)); |
278 | 281 |
279 if (focused_view_) | 282 if (focused_view_) |
280 focused_view_->Blur(); | 283 focused_view_->Blur(); |
281 focused_view_ = view; | 284 focused_view_ = view; |
282 if (focused_view_) | 285 if (focused_view_) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 477 |
475 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { | 478 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { |
476 focus_change_listeners_.AddObserver(listener); | 479 focus_change_listeners_.AddObserver(listener); |
477 } | 480 } |
478 | 481 |
479 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { | 482 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { |
480 focus_change_listeners_.RemoveObserver(listener); | 483 focus_change_listeners_.RemoveObserver(listener); |
481 } | 484 } |
482 | 485 |
483 } // namespace views | 486 } // namespace views |
OLD | NEW |