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 "ash/system/ime/tray_ime.h" | 5 #include "ash/system/ime/tray_ime_chromeos.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/metrics/user_metrics_recorder.h" | 9 #include "ash/metrics/user_metrics_recorder.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/session/session_state_delegate.h" | 11 #include "ash/session/session_state_delegate.h" |
12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/system/tray/hover_highlight_view.h" | 14 #include "ash/system/tray/hover_highlight_view.h" |
15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
16 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
17 #include "ash/system/tray/system_tray_notifier.h" | 17 #include "ash/system/tray/system_tray_notifier.h" |
18 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
19 #include "ash/system/tray/tray_details_view.h" | 19 #include "ash/system/tray/tray_details_view.h" |
20 #include "ash/system/tray/tray_item_more.h" | 20 #include "ash/system/tray/tray_item_more.h" |
21 #include "ash/system/tray/tray_item_view.h" | 21 #include "ash/system/tray/tray_item_view.h" |
22 #include "ash/system/tray/tray_utils.h" | 22 #include "ash/system/tray/tray_utils.h" |
23 #include "ash/system/tray_accessibility.h" | |
24 #include "ash/virtual_keyboard_controller.h" | |
23 #include "base/logging.h" | 25 #include "base/logging.h" |
24 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
25 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
26 #include "grit/ash_strings.h" | 28 #include "grit/ash_strings.h" |
27 #include "ui/accessibility/ax_enums.h" | 29 #include "ui/accessibility/ax_enums.h" |
28 #include "ui/accessibility/ax_view_state.h" | 30 #include "ui/accessibility/ax_view_state.h" |
29 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
30 #include "ui/gfx/font.h" | 32 #include "ui/gfx/font.h" |
31 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
34 #include "ui/keyboard/keyboard_util.h" | |
32 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
33 #include "ui/views/layout/box_layout.h" | 36 #include "ui/views/layout/box_layout.h" |
34 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
35 | 38 |
36 namespace ash { | 39 namespace ash { |
37 namespace tray { | 40 namespace tray { |
38 | 41 |
39 // A |HoverHighlightView| that uses bold or normal font depending on whetehr | 42 // A |HoverHighlightView| that uses bold or normal font depending on whether |
40 // it is selected. This view exposes itself as a checkbox to the accessibility | 43 // it is selected. This view exposes itself as a checkbox to the accessibility |
41 // framework. | 44 // framework. |
42 class SelectableHoverHighlightView : public HoverHighlightView { | 45 class SelectableHoverHighlightView : public HoverHighlightView { |
43 public: | 46 public: |
44 SelectableHoverHighlightView(ViewClickListener* listener, | 47 SelectableHoverHighlightView(ViewClickListener* listener, |
45 const base::string16& label, | 48 const base::string16& label, |
46 bool selected) | 49 bool selected) |
47 : HoverHighlightView(listener), selected_(selected) { | 50 : HoverHighlightView(listener), selected_(selected) { |
48 AddLabel( | 51 AddLabel(label, |
49 label, gfx::ALIGN_LEFT, selected ? gfx::Font::BOLD : gfx::Font::NORMAL); | 52 gfx::ALIGN_LEFT, |
53 selected ? gfx::Font::BOLD : gfx::Font::NORMAL); | |
50 } | 54 } |
51 | 55 |
52 ~SelectableHoverHighlightView() override {} | 56 ~SelectableHoverHighlightView() override {} |
53 | 57 |
54 protected: | 58 protected: |
55 // Overridden from views::View. | 59 // Overridden from views::View. |
56 void GetAccessibleState(ui::AXViewState* state) override { | 60 void GetAccessibleState(ui::AXViewState* state) override { |
57 HoverHighlightView::GetAccessibleState(state); | 61 HoverHighlightView::GetAccessibleState(state); |
58 state->role = ui::AX_ROLE_CHECK_BOX; | 62 state->role = ui::AX_ROLE_CHECK_BOX; |
59 if (selected_) | 63 if (selected_) |
60 state->AddStateFlag(ui::AX_STATE_CHECKED); | 64 state->AddStateFlag(ui::AX_STATE_CHECKED); |
61 } | 65 } |
62 | 66 |
63 private: | 67 private: |
64 bool selected_; | 68 bool selected_; |
65 | 69 |
66 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); | 70 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); |
67 }; | 71 }; |
68 | 72 |
69 class IMEDefaultView : public TrayItemMore { | 73 class IMEDefaultView : public TrayItemMore { |
70 public: | 74 public: |
71 explicit IMEDefaultView(SystemTrayItem* owner) | 75 explicit IMEDefaultView(SystemTrayItem* owner, const base::string16& label) |
72 : TrayItemMore(owner, true) { | 76 : TrayItemMore(owner, true) { |
73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 77 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
74 | 78 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME).ToImageSkia()); |
75 SetImage(bundle.GetImageNamed( | 79 UpdateLabel(label); |
76 IDR_AURA_UBER_TRAY_IME).ToImageSkia()); | |
77 | |
78 IMEInfo info; | |
79 Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(&info); | |
80 UpdateLabel(info); | |
81 } | 80 } |
82 | 81 |
83 ~IMEDefaultView() override {} | 82 ~IMEDefaultView() override {} |
84 | 83 |
85 void UpdateLabel(const IMEInfo& info) { | 84 void UpdateLabel(const base::string16& label) { |
86 SetLabel(info.name); | 85 SetLabel(label); |
87 SetAccessibleName(info.name); | 86 SetAccessibleName(label); |
88 } | 87 } |
89 | 88 |
90 private: | 89 private: |
91 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); | 90 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
92 }; | 91 }; |
93 | 92 |
94 class IMEDetailedView : public TrayDetailsView, | 93 class IMEDetailedView : public TrayDetailsView, public ViewClickListener { |
95 public ViewClickListener { | |
96 public: | 94 public: |
97 IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) | 95 IMEDetailedView(SystemTrayItem* owner, |
98 : TrayDetailsView(owner), | 96 user::LoginStatus login, |
99 login_(login) { | 97 bool show_keyboard_toggle) |
98 : TrayDetailsView(owner), login_(login) { | |
100 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 99 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
101 IMEInfoList list; | 100 IMEInfoList list; |
102 delegate->GetAvailableIMEList(&list); | 101 delegate->GetAvailableIMEList(&list); |
103 IMEPropertyInfoList property_list; | 102 IMEPropertyInfoList property_list; |
104 delegate->GetCurrentIMEProperties(&property_list); | 103 delegate->GetCurrentIMEProperties(&property_list); |
105 Update(list, property_list); | 104 Update(list, property_list, show_keyboard_toggle); |
106 } | 105 } |
107 | 106 |
108 ~IMEDetailedView() override {} | 107 ~IMEDetailedView() override {} |
109 | 108 |
110 void Update(const IMEInfoList& list, | 109 void Update(const IMEInfoList& list, |
111 const IMEPropertyInfoList& property_list) { | 110 const IMEPropertyInfoList& property_list, |
111 bool show_keyboard_toggle) { | |
112 Reset(); | 112 Reset(); |
113 ime_map_.clear(); | |
114 property_map_.clear(); | |
115 CreateScrollableList(); | |
113 | 116 |
114 AppendIMEList(list); | 117 if (list.size() > 1) |
115 if (!property_list.empty()) | 118 AppendIMEList(list); |
119 if (property_list.size() > 1) | |
116 AppendIMEProperties(property_list); | 120 AppendIMEProperties(property_list); |
121 | |
122 if (show_keyboard_toggle) { | |
123 if (list.size() > 1 || property_list.size() > 1) | |
124 AddScrollSeparator(); | |
125 AppendKeyboardStatus(); | |
126 } | |
127 | |
117 bool userAddingRunning = ash::Shell::GetInstance() | 128 bool userAddingRunning = ash::Shell::GetInstance() |
118 ->session_state_delegate() | 129 ->session_state_delegate() |
119 ->IsInSecondaryLoginScreen(); | 130 ->IsInSecondaryLoginScreen(); |
120 | |
121 if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED && | 131 if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED && |
122 !userAddingRunning) | 132 !userAddingRunning) |
123 AppendSettings(); | 133 AppendSettings(); |
124 AppendHeaderEntry(); | 134 AppendHeaderEntry(); |
125 | 135 |
126 Layout(); | 136 Layout(); |
127 SchedulePaint(); | 137 SchedulePaint(); |
128 } | 138 } |
129 | 139 |
130 private: | 140 private: |
131 void AppendHeaderEntry() { | 141 friend class TrayIMETest; |
Mr4D (OOO till 08-26)
2015/01/12 22:35:37
I think this can go...
rsadam
2015/01/13 00:05:34
Done.
| |
132 CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); | |
133 } | |
134 | 142 |
143 void AppendHeaderEntry() { CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); } | |
144 | |
145 // Appends the IMEs to the scrollable area of the detailed view. | |
135 void AppendIMEList(const IMEInfoList& list) { | 146 void AppendIMEList(const IMEInfoList& list) { |
136 ime_map_.clear(); | 147 DCHECK(ime_map_.empty()); |
137 CreateScrollableList(); | |
138 for (size_t i = 0; i < list.size(); i++) { | 148 for (size_t i = 0; i < list.size(); i++) { |
139 HoverHighlightView* container = new SelectableHoverHighlightView( | 149 HoverHighlightView* container = new SelectableHoverHighlightView( |
140 this, list[i].name, list[i].selected); | 150 this, list[i].name, list[i].selected); |
141 scroll_content()->AddChildView(container); | 151 scroll_content()->AddChildView(container); |
142 ime_map_[container] = list[i].id; | 152 ime_map_[container] = list[i].id; |
143 } | 153 } |
144 } | 154 } |
145 | 155 |
156 // Appends the IME listed to the scrollable area of the detailed | |
157 // view. | |
146 void AppendIMEProperties(const IMEPropertyInfoList& property_list) { | 158 void AppendIMEProperties(const IMEPropertyInfoList& property_list) { |
147 property_map_.clear(); | 159 DCHECK(property_map_.empty()); |
148 for (size_t i = 0; i < property_list.size(); i++) { | 160 for (size_t i = 0; i < property_list.size(); i++) { |
149 HoverHighlightView* container = new SelectableHoverHighlightView( | 161 HoverHighlightView* container = new SelectableHoverHighlightView( |
150 this, property_list[i].name, property_list[i].selected); | 162 this, property_list[i].name, property_list[i].selected); |
151 if (i == 0) | 163 if (i == 0) |
152 container->SetBorder(views::Border::CreateSolidSidedBorder( | 164 container->SetBorder(views::Border::CreateSolidSidedBorder( |
153 1, 0, 0, 0, kBorderLightColor)); | 165 1, 0, 0, 0, kBorderLightColor)); |
154 scroll_content()->AddChildView(container); | 166 scroll_content()->AddChildView(container); |
155 property_map_[container] = property_list[i].key; | 167 property_map_[container] = property_list[i].key; |
156 } | 168 } |
157 } | 169 } |
158 | 170 |
171 void AppendKeyboardStatus() { | |
172 HoverHighlightView* container = new HoverHighlightView(this); | |
173 int id = keyboard::IsKeyboardEnabled() | |
174 ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | |
175 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | |
176 container->AddLabel( | |
177 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), | |
178 gfx::ALIGN_LEFT, | |
179 gfx::Font::NORMAL); | |
180 scroll_content()->AddChildView(container); | |
181 keyboard_status_ = container; | |
182 } | |
183 | |
159 void AppendSettings() { | 184 void AppendSettings() { |
160 HoverHighlightView* container = new HoverHighlightView(this); | 185 HoverHighlightView* container = new HoverHighlightView(this); |
161 container->AddLabel( | 186 container->AddLabel( |
162 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 187 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
163 IDS_ASH_STATUS_TRAY_IME_SETTINGS), | 188 IDS_ASH_STATUS_TRAY_IME_SETTINGS), |
164 gfx::ALIGN_LEFT, | 189 gfx::ALIGN_LEFT, gfx::Font::NORMAL); |
Mr4D (OOO till 08-26)
2015/01/12 22:35:37
And another of this missing parameter line breaks
rsadam
2015/01/13 00:05:34
Oops. Removed.
| |
165 gfx::Font::NORMAL); | |
166 AddChildView(container); | 190 AddChildView(container); |
167 settings_ = container; | 191 settings_ = container; |
168 } | 192 } |
169 | 193 |
170 // Overridden from ViewClickListener. | 194 // Overridden from ViewClickListener. |
171 void OnViewClicked(views::View* sender) override { | 195 void OnViewClicked(views::View* sender) override { |
172 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 196 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
173 if (sender == footer()->content()) { | 197 if (sender == footer()->content()) { |
174 TransitionToDefaultView(); | 198 TransitionToDefaultView(); |
175 } else if (sender == settings_) { | 199 } else if (sender == settings_) { |
176 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 200 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
177 ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); | 201 ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); |
178 delegate->ShowIMESettings(); | 202 delegate->ShowIMESettings(); |
203 } else if (sender == keyboard_status_) { | |
204 Shell::GetInstance() | |
Mr4D (OOO till 08-26)
2015/01/12 22:35:37
Sorry for the nit, but you should be able to move
rsadam
2015/01/13 00:05:34
I completely missed that, thanks for pointing it o
| |
205 ->virtual_keyboard_controller() | |
206 ->ToggleIgnoreExternalKeyboard(); | |
179 } else { | 207 } else { |
180 std::map<views::View*, std::string>::const_iterator ime_find; | 208 std::map<views::View*, std::string>::const_iterator ime_find; |
181 ime_find = ime_map_.find(sender); | 209 ime_find = ime_map_.find(sender); |
182 if (ime_find != ime_map_.end()) { | 210 if (ime_find != ime_map_.end()) { |
183 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 211 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
184 ash::UMA_STATUS_AREA_IME_SWITCH_MODE); | 212 ash::UMA_STATUS_AREA_IME_SWITCH_MODE); |
185 std::string ime_id = ime_find->second; | 213 std::string ime_id = ime_find->second; |
186 delegate->SwitchIME(ime_id); | 214 delegate->SwitchIME(ime_id); |
187 GetWidget()->Close(); | 215 GetWidget()->Close(); |
188 } else { | 216 } else { |
189 std::map<views::View*, std::string>::const_iterator prop_find; | 217 std::map<views::View*, std::string>::const_iterator prop_find; |
190 prop_find = property_map_.find(sender); | 218 prop_find = property_map_.find(sender); |
191 if (prop_find != property_map_.end()) { | 219 if (prop_find != property_map_.end()) { |
192 const std::string key = prop_find->second; | 220 const std::string key = prop_find->second; |
193 delegate->ActivateIMEProperty(key); | 221 delegate->ActivateIMEProperty(key); |
194 GetWidget()->Close(); | 222 GetWidget()->Close(); |
195 } | 223 } |
196 } | 224 } |
197 } | 225 } |
198 } | 226 } |
199 | 227 |
200 user::LoginStatus login_; | 228 user::LoginStatus login_; |
201 | 229 |
202 std::map<views::View*, std::string> ime_map_; | 230 std::map<views::View*, std::string> ime_map_; |
203 std::map<views::View*, std::string> property_map_; | 231 std::map<views::View*, std::string> property_map_; |
204 views::View* settings_; | 232 views::View* settings_; |
233 views::View* keyboard_status_; | |
205 | 234 |
206 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 235 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
207 }; | 236 }; |
208 | 237 |
209 } // namespace tray | 238 } // namespace tray |
210 | 239 |
211 TrayIME::TrayIME(SystemTray* system_tray) | 240 TrayIME::TrayIME(SystemTray* system_tray) |
212 : SystemTrayItem(system_tray), | 241 : SystemTrayItem(system_tray), |
213 tray_label_(NULL), | 242 tray_label_(NULL), |
214 default_(NULL), | 243 default_(NULL), |
215 detailed_(NULL) { | 244 detailed_(NULL), |
245 keyboard_suppressed_(false) { | |
216 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); | 246 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); |
247 Shell::GetInstance()->system_tray_notifier()->AddVirtualKeyboardObserver( | |
248 this); | |
249 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); | |
217 } | 250 } |
218 | 251 |
219 TrayIME::~TrayIME() { | 252 TrayIME::~TrayIME() { |
220 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); | 253 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); |
254 Shell::GetInstance()->system_tray_notifier()->RemoveAccessibilityObserver( | |
255 this); | |
256 Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver( | |
257 this); | |
258 } | |
259 | |
260 void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) { | |
261 keyboard_suppressed_ = suppressed; | |
262 Update(); | |
263 } | |
264 | |
265 void TrayIME::OnAccessibilityModeChanged( | |
266 ui::AccessibilityNotificationVisibility notify) { | |
267 Update(); | |
268 } | |
269 | |
270 void TrayIME::Update() { | |
271 UpdateTrayLabel(current_ime_, ime_list_.size()); | |
272 if (default_) { | |
273 default_->SetVisible(ShouldDefaultViewBeVisible()); | |
274 default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1)); | |
275 } | |
276 if (detailed_) | |
277 detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle()); | |
221 } | 278 } |
222 | 279 |
223 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 280 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
224 if (tray_label_) { | 281 if (tray_label_) { |
225 bool visible = count > 1; | 282 bool visible = count > 1; |
226 tray_label_->SetVisible(visible); | 283 tray_label_->SetVisible(visible); |
227 // Do not change label before hiding because this change is noticeable. | 284 // Do not change label before hiding because this change is noticeable. |
228 if (!visible) | 285 if (!visible) |
229 return; | 286 return; |
230 if (current.third_party) { | 287 if (current.third_party) { |
231 tray_label_->label()->SetText( | 288 tray_label_->label()->SetText(current.short_name + |
232 current.short_name + base::UTF8ToUTF16("*")); | 289 base::UTF8ToUTF16("*")); |
233 } else { | 290 } else { |
234 tray_label_->label()->SetText(current.short_name); | 291 tray_label_->label()->SetText(current.short_name); |
235 } | 292 } |
236 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); | 293 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); |
237 tray_label_->Layout(); | 294 tray_label_->Layout(); |
238 } | 295 } |
239 } | 296 } |
240 | 297 |
298 bool TrayIME::ShouldShowKeyboardToggle() { | |
299 return keyboard_suppressed_ && | |
300 !Shell::GetInstance() | |
301 ->accessibility_delegate() | |
302 ->IsVirtualKeyboardEnabled(); | |
303 } | |
304 | |
305 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) { | |
306 if (show_ime_label) { | |
307 IMEInfo current; | |
308 Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(¤t); | |
309 return current.name; | |
310 } else { | |
311 // Display virtual keyboard status instead. | |
312 int id = keyboard::IsKeyboardEnabled() | |
313 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED | |
314 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED; | |
315 return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id); | |
316 } | |
317 } | |
318 | |
241 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 319 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
242 CHECK(tray_label_ == NULL); | 320 CHECK(tray_label_ == NULL); |
243 tray_label_ = new TrayItemView(this); | 321 tray_label_ = new TrayItemView(this); |
244 tray_label_->CreateLabel(); | 322 tray_label_->CreateLabel(); |
245 SetupLabelForTray(tray_label_->label()); | 323 SetupLabelForTray(tray_label_->label()); |
246 // Hide IME tray when it is created, it will be updated when it is notified | 324 // Hide IME tray when it is created, it will be updated when it is notified |
247 // for IME refresh event. | 325 // of the IME refresh event. |
248 tray_label_->SetVisible(false); | 326 tray_label_->SetVisible(false); |
249 return tray_label_; | 327 return tray_label_; |
250 } | 328 } |
251 | 329 |
252 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { | 330 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
253 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | |
254 IMEInfoList list; | |
255 IMEPropertyInfoList property_list; | |
256 delegate->GetAvailableIMEList(&list); | |
257 delegate->GetCurrentIMEProperties(&property_list); | |
258 if (list.size() <= 1 && property_list.size() <= 1) | |
259 return NULL; | |
260 CHECK(default_ == NULL); | 331 CHECK(default_ == NULL); |
261 default_ = new tray::IMEDefaultView(this); | 332 default_ = |
333 new tray::IMEDefaultView(this, GetDefaultViewLabel(ime_list_.size() > 1)); | |
334 default_->SetVisible(ShouldDefaultViewBeVisible()); | |
262 return default_; | 335 return default_; |
263 } | 336 } |
264 | 337 |
265 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { | 338 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { |
266 CHECK(detailed_ == NULL); | 339 CHECK(detailed_ == NULL); |
267 detailed_ = new tray::IMEDetailedView(this, status); | 340 detailed_ = |
341 new tray::IMEDetailedView(this, status, ShouldShowKeyboardToggle()); | |
268 return detailed_; | 342 return detailed_; |
269 } | 343 } |
270 | 344 |
271 void TrayIME::DestroyTrayView() { | 345 void TrayIME::DestroyTrayView() { |
272 tray_label_ = NULL; | 346 tray_label_ = NULL; |
273 } | 347 } |
274 | 348 |
275 void TrayIME::DestroyDefaultView() { | 349 void TrayIME::DestroyDefaultView() { |
276 default_ = NULL; | 350 default_ = NULL; |
277 } | 351 } |
278 | 352 |
279 void TrayIME::DestroyDetailedView() { | 353 void TrayIME::DestroyDetailedView() { |
280 detailed_ = NULL; | 354 detailed_ = NULL; |
281 } | 355 } |
282 | 356 |
283 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 357 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
284 } | 358 } |
285 | 359 |
286 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 360 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
287 SetTrayLabelItemBorder(tray_label_, alignment); | 361 SetTrayLabelItemBorder(tray_label_, alignment); |
288 tray_label_->Layout(); | 362 tray_label_->Layout(); |
289 } | 363 } |
290 | 364 |
291 void TrayIME::OnIMERefresh() { | 365 void TrayIME::OnIMERefresh() { |
366 // Caches the current ime state. | |
292 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 367 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
293 IMEInfoList list; | 368 ime_list_.clear(); |
294 IMEInfo current; | 369 property_list_.clear(); |
295 IMEPropertyInfoList property_list; | 370 delegate->GetCurrentIME(¤t_ime_); |
296 delegate->GetCurrentIME(¤t); | 371 delegate->GetAvailableIMEList(&ime_list_); |
297 delegate->GetAvailableIMEList(&list); | 372 delegate->GetCurrentIMEProperties(&property_list_); |
298 delegate->GetCurrentIMEProperties(&property_list); | |
299 | 373 |
300 UpdateTrayLabel(current, list.size()); | 374 Update(); |
375 } | |
301 | 376 |
302 if (default_) | 377 bool TrayIME::ShouldDefaultViewBeVisible() { |
303 default_->UpdateLabel(current); | 378 return ime_list_.size() > 1 || property_list_.size() > 1 || |
304 if (detailed_) | 379 ShouldShowKeyboardToggle(); |
305 detailed_->Update(list, property_list); | |
306 } | 380 } |
307 | 381 |
308 } // namespace ash | 382 } // namespace ash |
OLD | NEW |