| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 // FocusManager ----------------------------------------------------- | 66 // FocusManager ----------------------------------------------------- |
| 67 | 67 |
| 68 FocusManager::FocusManager(Widget* widget) | 68 FocusManager::FocusManager(Widget* widget) |
| 69 : widget_(widget), | 69 : widget_(widget), |
| 70 focused_view_(NULL), | 70 focused_view_(NULL), |
| 71 focus_change_reason_(kReasonDirectFocusChange) { | 71 focus_change_reason_(kReasonDirectFocusChange) { |
| 72 DCHECK(widget_); | 72 DCHECK(widget_); |
| 73 stored_focused_view_storage_id_ = | 73 stored_focused_view_storage_id_ = |
| 74 ViewStorage::GetSharedInstance()->CreateStorageID(); | 74 ViewStorage::GetInstance()->CreateStorageID(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 FocusManager::~FocusManager() { | 77 FocusManager::~FocusManager() { |
| 78 // If there are still registered FocusChange listeners, chances are they were | 78 // If there are still registered FocusChange listeners, chances are they were |
| 79 // leaked so warn about them. | 79 // leaked so warn about them. |
| 80 DCHECK(focus_change_listeners_.empty()); | 80 DCHECK(focus_change_listeners_.empty()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { | 84 FocusManager::WidgetFocusManager* FocusManager::GetWidgetFocusManager() { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 void FocusManager::ClearFocus() { | 329 void FocusManager::ClearFocus() { |
| 330 SetFocusedView(NULL); | 330 SetFocusedView(NULL); |
| 331 ClearNativeFocus(); | 331 ClearNativeFocus(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void FocusManager::StoreFocusedView() { | 334 void FocusManager::StoreFocusedView() { |
| 335 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); | 335 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 336 if (!view_storage) { | 336 if (!view_storage) { |
| 337 // This should never happen but bug 981648 seems to indicate it could. | 337 // This should never happen but bug 981648 seems to indicate it could. |
| 338 NOTREACHED(); | 338 NOTREACHED(); |
| 339 return; | 339 return; |
| 340 } | 340 } |
| 341 | 341 |
| 342 // TODO (jcampan): when a TabContents containing a popup is closed, the focus | 342 // TODO (jcampan): when a TabContents containing a popup is closed, the focus |
| 343 // is stored twice causing an assert. We should find a better alternative than | 343 // is stored twice causing an assert. We should find a better alternative than |
| 344 // removing the view from the storage explicitly. | 344 // removing the view from the storage explicitly. |
| 345 view_storage->RemoveView(stored_focused_view_storage_id_); | 345 view_storage->RemoveView(stored_focused_view_storage_id_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 358 // is not changing due to a user-initiated event. | 358 // is not changing due to a user-initiated event. |
| 359 AutoNativeNotificationDisabler local_notification_disabler; | 359 AutoNativeNotificationDisabler local_notification_disabler; |
| 360 ClearFocus(); | 360 ClearFocus(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 if (v) | 363 if (v) |
| 364 v->SchedulePaint(); // Remove focus border. | 364 v->SchedulePaint(); // Remove focus border. |
| 365 } | 365 } |
| 366 | 366 |
| 367 void FocusManager::RestoreFocusedView() { | 367 void FocusManager::RestoreFocusedView() { |
| 368 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); | 368 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 369 if (!view_storage) { | 369 if (!view_storage) { |
| 370 // This should never happen but bug 981648 seems to indicate it could. | 370 // This should never happen but bug 981648 seems to indicate it could. |
| 371 NOTREACHED(); | 371 NOTREACHED(); |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 | 374 |
| 375 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); | 375 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); |
| 376 if (view) { | 376 if (view) { |
| 377 if (ContainsView(view)) { | 377 if (ContainsView(view)) { |
| 378 if (!view->IsFocusableInRootView() && | 378 if (!view->IsFocusableInRootView() && |
| (...skipping 13 matching lines...) Expand all Loading... |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 } else { | 394 } else { |
| 395 // Clearing the focus will focus the root window, so we still get key | 395 // Clearing the focus will focus the root window, so we still get key |
| 396 // events. | 396 // events. |
| 397 ClearFocus(); | 397 ClearFocus(); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 void FocusManager::ClearStoredFocusedView() { | 401 void FocusManager::ClearStoredFocusedView() { |
| 402 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); | 402 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 403 if (!view_storage) { | 403 if (!view_storage) { |
| 404 // This should never happen but bug 981648 seems to indicate it could. | 404 // This should never happen but bug 981648 seems to indicate it could. |
| 405 NOTREACHED(); | 405 NOTREACHED(); |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 view_storage->RemoveView(stored_focused_view_storage_id_); | 408 view_storage->RemoveView(stored_focused_view_storage_id_); |
| 409 } | 409 } |
| 410 | 410 |
| 411 // Find the next (previous if reverse is true) focusable view for the specified | 411 // Find the next (previous if reverse is true) focusable view for the specified |
| 412 // FocusTraversable, starting at the specified view, traversing down the | 412 // FocusTraversable, starting at the specified view, traversing down the |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 524 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
| 525 listener); | 525 listener); |
| 526 if (place == focus_change_listeners_.end()) { | 526 if (place == focus_change_listeners_.end()) { |
| 527 NOTREACHED() << "Removing a listener that isn't registered."; | 527 NOTREACHED() << "Removing a listener that isn't registered."; |
| 528 return; | 528 return; |
| 529 } | 529 } |
| 530 focus_change_listeners_.erase(place); | 530 focus_change_listeners_.erase(place); |
| 531 } | 531 } |
| 532 | 532 |
| 533 } // namespace views | 533 } // namespace views |
| OLD | NEW |