Chromium Code Reviews| 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // static | 510 // static |
| 511 bool FocusManager::IsTabTraversalKeyEvent(const ui::KeyEvent& key_event) { | 511 bool FocusManager::IsTabTraversalKeyEvent(const ui::KeyEvent& key_event) { |
| 512 return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown(); | 512 return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 void FocusManager::ViewRemoved(View* removed) { | 515 void FocusManager::ViewRemoved(View* removed) { |
| 516 // If the view being removed contains (or is) the focused view, | 516 // If the view being removed contains (or is) the focused view, |
| 517 // clear the focus. However, it's not safe to call ClearFocus() | 517 // clear the focus. However, it's not safe to call ClearFocus() |
| 518 // (and in turn ClearNativeFocus()) here because ViewRemoved() can | 518 // (and in turn ClearNativeFocus()) here because ViewRemoved() can |
| 519 // be called while the top level widget is being destroyed. | 519 // be called while the top level widget is being destroyed. |
| 520 if (focused_view_ && removed->Contains(focused_view_)) | 520 if (!focused_view_) |
|
sky
2016/06/09 17:23:14
Contains handles null correctly, so you shouldn't
krasin
2016/06/09 17:46:11
I need an early exit, if ViewRemoved is called wit
sky
2016/06/09 18:06:00
Not sure I follow. If focused_view_ is null Contai
krasin
2016/06/09 18:13:06
Consider the case, when removed == NULL. We have t
sky
2016/06/09 22:34:24
removed == null is an error in the call sites and
krasin
2016/06/09 23:10:57
I have tried that. Multiple (almost all) tests are
| |
| 521 return; | |
| 522 DCHECK(removed != NULL); | |
|
sky
2016/06/09 17:23:14
DCHECK(removed);
krasin
2016/06/09 17:46:11
Done.
| |
| 523 if (removed->Contains(focused_view_)) | |
| 521 SetFocusedView(NULL); | 524 SetFocusedView(NULL); |
| 522 } | 525 } |
| 523 | 526 |
| 524 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { | 527 void FocusManager::AddFocusChangeListener(FocusChangeListener* listener) { |
| 525 focus_change_listeners_.AddObserver(listener); | 528 focus_change_listeners_.AddObserver(listener); |
| 526 } | 529 } |
| 527 | 530 |
| 528 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { | 531 void FocusManager::RemoveFocusChangeListener(FocusChangeListener* listener) { |
| 529 focus_change_listeners_.RemoveObserver(listener); | 532 focus_change_listeners_.RemoveObserver(listener); |
| 530 } | 533 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 552 // |keyboard_accessible_| is only used on Mac. | 555 // |keyboard_accessible_| is only used on Mac. |
| 553 #if defined(OS_MACOSX) | 556 #if defined(OS_MACOSX) |
| 554 return keyboard_accessible_ ? view->IsAccessibilityFocusable() | 557 return keyboard_accessible_ ? view->IsAccessibilityFocusable() |
| 555 : view->IsFocusable(); | 558 : view->IsFocusable(); |
| 556 #else | 559 #else |
| 557 return view->IsAccessibilityFocusable(); | 560 return view->IsAccessibilityFocusable(); |
| 558 #endif | 561 #endif |
| 559 } | 562 } |
| 560 | 563 |
| 561 } // namespace views | 564 } // namespace views |
| OLD | NEW |