| OLD | NEW |
| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 void FocusManager::SetFocusedViewWithReason( | 311 void FocusManager::SetFocusedViewWithReason( |
| 312 View* view, FocusChangeReason reason) { | 312 View* view, FocusChangeReason reason) { |
| 313 if (focused_view_ == view) | 313 if (focused_view_ == view) |
| 314 return; | 314 return; |
| 315 | 315 |
| 316 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); | 316 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); |
| 317 // Update the reason for the focus change (since this is checked by | 317 // Update the reason for the focus change (since this is checked by |
| 318 // some listeners), then notify all listeners. | 318 // some listeners), then notify all listeners. |
| 319 focus_change_reason_ = reason; | 319 focus_change_reason_ = reason; |
| 320 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 320 for (FocusChangeListener& observer : focus_change_listeners_) |
| 321 OnWillChangeFocus(focused_view_, view)); | 321 observer.OnWillChangeFocus(focused_view_, view); |
| 322 | 322 |
| 323 View* old_focused_view = focused_view_; | 323 View* old_focused_view = focused_view_; |
| 324 focused_view_ = view; | 324 focused_view_ = view; |
| 325 if (old_focused_view) | 325 if (old_focused_view) |
| 326 old_focused_view->Blur(); | 326 old_focused_view->Blur(); |
| 327 // Also make |focused_view_| the stored focus view. This way the stored focus | 327 // Also make |focused_view_| the stored focus view. This way the stored focus |
| 328 // view is remembered if focus changes are requested prior to a show or while | 328 // view is remembered if focus changes are requested prior to a show or while |
| 329 // hidden. | 329 // hidden. |
| 330 SetStoredFocusView(focused_view_); | 330 SetStoredFocusView(focused_view_); |
| 331 if (focused_view_) | 331 if (focused_view_) |
| 332 focused_view_->Focus(); | 332 focused_view_->Focus(); |
| 333 | 333 |
| 334 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 334 for (FocusChangeListener& observer : focus_change_listeners_) |
| 335 OnDidChangeFocus(old_focused_view, focused_view_)); | 335 observer.OnDidChangeFocus(old_focused_view, focused_view_); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void FocusManager::ClearFocus() { | 338 void FocusManager::ClearFocus() { |
| 339 // SetFocusedView(NULL) is going to clear out the stored view to. We need to | 339 // SetFocusedView(NULL) is going to clear out the stored view to. We need to |
| 340 // persist it in this case. | 340 // persist it in this case. |
| 341 views::View* focused_view = GetStoredFocusView(); | 341 views::View* focused_view = GetStoredFocusView(); |
| 342 SetFocusedView(NULL); | 342 SetFocusedView(NULL); |
| 343 ClearNativeFocus(); | 343 ClearNativeFocus(); |
| 344 SetStoredFocusView(focused_view); | 344 SetStoredFocusView(focused_view); |
| 345 } | 345 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // |keyboard_accessible_| is only used on Mac. | 553 // |keyboard_accessible_| is only used on Mac. |
| 554 #if defined(OS_MACOSX) | 554 #if defined(OS_MACOSX) |
| 555 return keyboard_accessible_ ? view->IsAccessibilityFocusable() | 555 return keyboard_accessible_ ? view->IsAccessibilityFocusable() |
| 556 : view->IsFocusable(); | 556 : view->IsFocusable(); |
| 557 #else | 557 #else |
| 558 return view->IsAccessibilityFocusable(); | 558 return view->IsAccessibilityFocusable(); |
| 559 #endif | 559 #endif |
| 560 } | 560 } |
| 561 | 561 |
| 562 } // namespace views | 562 } // namespace views |
| OLD | NEW |