OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/system/virtual_keyboard/virtual_keyboard_tray.h" | 5 #include "ash/system/virtual_keyboard/virtual_keyboard_tray.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/keyboard/keyboard_ui.h" | 9 #include "ash/keyboard/keyboard_ui.h" |
10 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 gfx::ImageSkia image = | 32 gfx::ImageSkia image = |
33 gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor); | 33 gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor); |
34 icon_->SetImage(image); | 34 icon_->SetImage(image); |
35 const int vertical_padding = (kTrayItemSize - image.height()) / 2; | 35 const int vertical_padding = (kTrayItemSize - image.height()) / 2; |
36 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; | 36 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; |
37 icon_->SetBorder(views::CreateEmptyBorder( | 37 icon_->SetBorder(views::CreateEmptyBorder( |
38 gfx::Insets(vertical_padding, horizontal_padding))); | 38 gfx::Insets(vertical_padding, horizontal_padding))); |
39 tray_container()->AddChildView(icon_); | 39 tray_container()->AddChildView(icon_); |
40 | 40 |
41 // The Shell may not exist in some unit tests. | 41 // The Shell may not exist in some unit tests. |
42 if (Shell::HasInstance()) | 42 if (Shell::HasInstance()) { |
43 Shell::Get()->keyboard_ui()->AddObserver(this); | 43 Shell::Get()->keyboard_ui()->AddObserver(this); |
44 Shell::Get()->AddShellObserver(this); | |
45 } | |
44 // Try observing keyboard controller, in case it is already constructed. | 46 // Try observing keyboard controller, in case it is already constructed. |
45 ObserveKeyboardController(); | 47 ObserveKeyboardController(); |
46 } | 48 } |
47 | 49 |
48 VirtualKeyboardTray::~VirtualKeyboardTray() { | 50 VirtualKeyboardTray::~VirtualKeyboardTray() { |
49 // Try unobserving keyboard controller, in case it still exists. | 51 // Try unobserving keyboard controller, in case it still exists. |
50 UnobserveKeyboardController(); | 52 UnobserveKeyboardController(); |
51 // The Shell may not exist in some unit tests. | 53 // The Shell may not exist in some unit tests. |
52 if (Shell::HasInstance()) | 54 if (Shell::HasInstance()) { |
53 Shell::Get()->keyboard_ui()->RemoveObserver(this); | 55 Shell::Get()->keyboard_ui()->RemoveObserver(this); |
56 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.
| |
57 } | |
54 } | 58 } |
55 | 59 |
56 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | 60 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
57 return l10n_util::GetStringUTF16( | 61 return l10n_util::GetStringUTF16( |
58 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | 62 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
59 } | 63 } |
60 | 64 |
61 void VirtualKeyboardTray::HideBubbleWithView( | 65 void VirtualKeyboardTray::HideBubbleWithView( |
62 const views::TrayBubbleView* bubble_view) {} | 66 const views::TrayBubbleView* bubble_view) {} |
63 | 67 |
(...skipping 25 matching lines...) Expand all Loading... | |
89 } | 93 } |
90 } | 94 } |
91 | 95 |
92 void VirtualKeyboardTray::OnKeyboardBoundsChanging( | 96 void VirtualKeyboardTray::OnKeyboardBoundsChanging( |
93 const gfx::Rect& new_bounds) { | 97 const gfx::Rect& new_bounds) { |
94 SetIsActive(!new_bounds.IsEmpty()); | 98 SetIsActive(!new_bounds.IsEmpty()); |
95 } | 99 } |
96 | 100 |
97 void VirtualKeyboardTray::OnKeyboardClosed() {} | 101 void VirtualKeyboardTray::OnKeyboardClosed() {} |
98 | 102 |
103 void VirtualKeyboardTray::OnKeyboardControllerCreated() { | |
104 ObserveKeyboardController(); | |
105 } | |
106 | |
99 void VirtualKeyboardTray::ObserveKeyboardController() { | 107 void VirtualKeyboardTray::ObserveKeyboardController() { |
100 keyboard::KeyboardController* keyboard_controller = | 108 keyboard::KeyboardController* keyboard_controller = |
101 keyboard::KeyboardController::GetInstance(); | 109 keyboard::KeyboardController::GetInstance(); |
102 if (keyboard_controller) | 110 if (keyboard_controller && !keyboard_controller->HasObserver(this)) |
103 keyboard_controller->AddObserver(this); | 111 keyboard_controller->AddObserver(this); |
104 } | 112 } |
105 | 113 |
106 void VirtualKeyboardTray::UnobserveKeyboardController() { | 114 void VirtualKeyboardTray::UnobserveKeyboardController() { |
107 keyboard::KeyboardController* keyboard_controller = | 115 keyboard::KeyboardController* keyboard_controller = |
108 keyboard::KeyboardController::GetInstance(); | 116 keyboard::KeyboardController::GetInstance(); |
109 if (keyboard_controller) | 117 if (keyboard_controller) |
110 keyboard_controller->RemoveObserver(this); | 118 keyboard_controller->RemoveObserver(this); |
111 } | 119 } |
112 | 120 |
113 } // namespace ash | 121 } // namespace ash |
OLD | NEW |