| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 void FocusManager::RestoreFocusedView() { | 354 void FocusManager::RestoreFocusedView() { |
| 355 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); | 355 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); |
| 356 if (!view_storage) { | 356 if (!view_storage) { |
| 357 // This should never happen but bug 981648 seems to indicate it could. | 357 // This should never happen but bug 981648 seems to indicate it could. |
| 358 NOTREACHED(); | 358 NOTREACHED(); |
| 359 return; | 359 return; |
| 360 } | 360 } |
| 361 | 361 |
| 362 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); | 362 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); |
| 363 if (view) { | 363 if (view) { |
| 364 if (ContainsView(view) && (view->IsFocusableInRootView() || | 364 if (ContainsView(view)) { |
| 365 view->IsAccessibilityFocusableInRootView())) { | 365 if (!view->IsFocusableInRootView() && |
| 366 SetFocusedViewWithReason(view, kReasonFocusRestore); | 366 view->IsAccessibilityFocusableInRootView()) { |
| 367 // RequestFocus would fail, but we want to restore focus to controls |
| 368 // that had focus in accessibility mode. |
| 369 SetFocusedViewWithReason(view, kReasonFocusRestore); |
| 370 } else { |
| 371 // This usually just sets the focus if this view is focusable, but |
| 372 // let the view override RequestFocus if necessary. |
| 373 view->RequestFocus(); |
| 374 |
| 375 // If it succeeded, the reason would be incorrect; set it to |
| 376 // focus restore. |
| 377 if (focused_view_ == view) |
| 378 focus_change_reason_ = kReasonFocusRestore; |
| 379 } |
| 367 } | 380 } |
| 368 } else { | 381 } else { |
| 369 // Clearing the focus will focus the root window, so we still get key | 382 // Clearing the focus will focus the root window, so we still get key |
| 370 // events. | 383 // events. |
| 371 ClearFocus(); | 384 ClearFocus(); |
| 372 } | 385 } |
| 373 } | 386 } |
| 374 | 387 |
| 375 void FocusManager::ClearStoredFocusedView() { | 388 void FocusManager::ClearStoredFocusedView() { |
| 376 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); | 389 ViewStorage* view_storage = ViewStorage::GetSharedInstance(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 511 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
| 499 listener); | 512 listener); |
| 500 if (place == focus_change_listeners_.end()) { | 513 if (place == focus_change_listeners_.end()) { |
| 501 NOTREACHED() << "Removing a listener that isn't registered."; | 514 NOTREACHED() << "Removing a listener that isn't registered."; |
| 502 return; | 515 return; |
| 503 } | 516 } |
| 504 focus_change_listeners_.erase(place); | 517 focus_change_listeners_.erase(place); |
| 505 } | 518 } |
| 506 | 519 |
| 507 } // namespace views | 520 } // namespace views |
| OLD | NEW |