| 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 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // By calling with NULL as the starting view, we'll start from the | 242 // By calling with NULL as the starting view, we'll start from the |
| 243 // top_root_view. | 243 // top_root_view. |
| 244 return GetNextFocusableView(NULL, reverse, true); | 244 return GetNextFocusableView(NULL, reverse, true); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 return NULL; | 247 return NULL; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void FocusManager::SetFocusedViewWithReason( | 250 void FocusManager::SetFocusedViewWithReason( |
| 251 View* view, FocusChangeReason reason) { | 251 View* view, FocusChangeReason reason) { |
| 252 if (focused_view_ == view) | 252 // Force a focus update on kReasonFocusRestore, even if the view is focused. |
| 253 // This is needed to restore focus to a child HWND when its top-level window |
| 254 // is restored from the minimized state. See http://crbug.com/125976 |
| 255 if (focused_view_ == view && reason != kReasonFocusRestore) |
| 253 return; | 256 return; |
| 254 | 257 |
| 255 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); | 258 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); |
| 256 // Update the reason for the focus change (since this is checked by | 259 // Update the reason for the focus change (since this is checked by |
| 257 // some listeners), then notify all listeners. | 260 // some listeners), then notify all listeners. |
| 258 focus_change_reason_ = reason; | 261 focus_change_reason_ = reason; |
| 259 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 262 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, |
| 260 OnWillChangeFocus(focused_view_, view)); | 263 OnWillChangeFocus(focused_view_, view)); |
| 261 | 264 |
| 262 View* old_focused_view = focused_view_; | 265 View* old_focused_view = focused_view_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 bool FocusManager::RestoreFocusedView() { | 316 bool FocusManager::RestoreFocusedView() { |
| 314 ViewStorage* view_storage = ViewStorage::GetInstance(); | 317 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 315 if (!view_storage) { | 318 if (!view_storage) { |
| 316 // This should never happen but bug 981648 seems to indicate it could. | 319 // This should never happen but bug 981648 seems to indicate it could. |
| 317 NOTREACHED(); | 320 NOTREACHED(); |
| 318 return false; | 321 return false; |
| 319 } | 322 } |
| 320 | 323 |
| 321 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); | 324 View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); |
| 322 if (view) { | 325 if (view) { |
| 323 if (ContainsView(view)) { | 326 if (ContainsView(view)) |
| 324 if (!view->IsFocusable() && view->IsAccessibilityFocusable()) { | 327 SetFocusedViewWithReason(view, kReasonFocusRestore); |
| 325 // RequestFocus would fail, but we want to restore focus to controls | |
| 326 // that had focus in accessibility mode. | |
| 327 SetFocusedViewWithReason(view, kReasonFocusRestore); | |
| 328 } else { | |
| 329 // This usually just sets the focus if this view is focusable, but | |
| 330 // let the view override RequestFocus if necessary. | |
| 331 view->RequestFocus(); | |
| 332 | |
| 333 // If it succeeded, the reason would be incorrect; set it to | |
| 334 // focus restore. | |
| 335 if (focused_view_ == view) | |
| 336 focus_change_reason_ = kReasonFocusRestore; | |
| 337 } | |
| 338 } | |
| 339 return true; | 328 return true; |
| 340 } | 329 } |
| 341 return false; | 330 return false; |
| 342 } | 331 } |
| 343 | 332 |
| 344 void FocusManager::ClearStoredFocusedView() { | 333 void FocusManager::ClearStoredFocusedView() { |
| 345 ViewStorage* view_storage = ViewStorage::GetInstance(); | 334 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 346 if (!view_storage) { | 335 if (!view_storage) { |
| 347 // This should never happen but bug 981648 seems to indicate it could. | 336 // This should never happen but bug 981648 seems to indicate it could. |
| 348 NOTREACHED(); | 337 NOTREACHED(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 428 |
| 440 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { | 429 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { |
| 441 focus_change_listeners_.AddObserver(listener); | 430 focus_change_listeners_.AddObserver(listener); |
| 442 } | 431 } |
| 443 | 432 |
| 444 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { | 433 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { |
| 445 focus_change_listeners_.RemoveObserver(listener); | 434 focus_change_listeners_.RemoveObserver(listener); |
| 446 } | 435 } |
| 447 | 436 |
| 448 } // namespace views | 437 } // namespace views |
| OLD | NEW |