Chromium Code Reviews| Index: ash/system/virtual_keyboard/virtual_keyboard_tray.cc |
| diff --git a/ash/system/virtual_keyboard/virtual_keyboard_tray.cc b/ash/system/virtual_keyboard/virtual_keyboard_tray.cc |
| index 89d55053934c2c56e9805db47b363072815c7f62..4c7b2dc49c1a0228bb170ac339f4e8afa6fd9a51 100644 |
| --- a/ash/system/virtual_keyboard/virtual_keyboard_tray.cc |
| +++ b/ash/system/virtual_keyboard/virtual_keyboard_tray.cc |
| @@ -39,8 +39,10 @@ VirtualKeyboardTray::VirtualKeyboardTray(Shelf* shelf) |
| tray_container()->AddChildView(icon_); |
| // The Shell may not exist in some unit tests. |
| - if (Shell::HasInstance()) |
| + if (Shell::HasInstance()) { |
| Shell::Get()->keyboard_ui()->AddObserver(this); |
| + Shell::Get()->AddShellObserver(this); |
| + } |
| // Try observing keyboard controller, in case it is already constructed. |
| ObserveKeyboardController(); |
| } |
| @@ -49,8 +51,10 @@ VirtualKeyboardTray::~VirtualKeyboardTray() { |
| // Try unobserving keyboard controller, in case it still exists. |
| UnobserveKeyboardController(); |
| // The Shell may not exist in some unit tests. |
| - if (Shell::HasInstance()) |
| + if (Shell::HasInstance()) { |
| Shell::Get()->keyboard_ui()->RemoveObserver(this); |
| + Shell::Get()->RemoveShellObserver(this); |
|
James Cook
2017/05/31 23:44:25
super-nit: do this one line above so things are re
bruthig
2017/06/01 14:05:15
Done.
|
| + } |
| } |
| base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
| @@ -96,10 +100,14 @@ void VirtualKeyboardTray::OnKeyboardBoundsChanging( |
| void VirtualKeyboardTray::OnKeyboardClosed() {} |
| +void VirtualKeyboardTray::OnKeyboardControllerCreated() { |
| + ObserveKeyboardController(); |
| +} |
| + |
| void VirtualKeyboardTray::ObserveKeyboardController() { |
| keyboard::KeyboardController* keyboard_controller = |
| keyboard::KeyboardController::GetInstance(); |
| - if (keyboard_controller) |
| + if (keyboard_controller && !keyboard_controller->HasObserver(this)) |
| keyboard_controller->AddObserver(this); |
| } |