OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/common/system/chromeos/ime_menu/ime_list_view.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/system/tray/hover_highlight_view.h" | 8 #include "ash/common/system/tray/hover_highlight_view.h" |
9 #include "ash/common/system/tray/ime_info.h" | 9 #include "ash/common/system/tray/ime_info.h" |
10 #include "ash/common/system/tray/system_menu_button.h" | 10 #include "ash/common/system/tray/system_menu_button.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); | 133 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); |
134 tri_view->AddView(TriView::Container::END, checked_image); | 134 tri_view->AddView(TriView::Container::END, checked_image); |
135 } | 135 } |
136 SetAccessibleName(label_->text()); | 136 SetAccessibleName(label_->text()); |
137 } | 137 } |
138 | 138 |
139 ~ImeListItemView() override {} | 139 ~ImeListItemView() override {} |
140 | 140 |
141 // ActionableView: | 141 // ActionableView: |
142 bool PerformAction(const ui::Event& event) override { | 142 bool PerformAction(const ui::Event& event) override { |
143 ime_list_view_->HandleViewClicked(this); | 143 if (event.type() == ui::EventType::ET_MOUSE_RELEASED) { |
tdanderson
2016/12/08 00:42:11
nit: no {} needed around the if and else-if blocks
Azure Wei
2016/12/08 13:14:55
Done.
| |
144 ime_list_view_->HandleViewClicked(this); | |
145 } else if (event.type() == ui::EventType::ET_KEY_PRESSED) { | |
146 ime_list_view_->HandleViewPressed(this); | |
147 } | |
144 return true; | 148 return true; |
145 } | 149 } |
146 | 150 |
147 void OnFocus() override { | 151 void OnFocus() override { |
148 ActionableView::OnFocus(); | 152 ActionableView::OnFocus(); |
149 if (ime_list_view_ && ime_list_view_->scroll_content()) | 153 if (ime_list_view_ && ime_list_view_->scroll_content()) |
150 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); | 154 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); |
151 } | 155 } |
152 | 156 |
153 // views::View: | 157 // views::View: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 250 |
247 // ToggleButton to toggle keyboard on or off. | 251 // ToggleButton to toggle keyboard on or off. |
248 views::ToggleButton* toggle_; | 252 views::ToggleButton* toggle_; |
249 | 253 |
250 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | 254 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); |
251 }; | 255 }; |
252 | 256 |
253 ImeListView::ImeListView(SystemTrayItem* owner, | 257 ImeListView::ImeListView(SystemTrayItem* owner, |
254 bool show_keyboard_toggle, | 258 bool show_keyboard_toggle, |
255 SingleImeBehavior single_ime_behavior) | 259 SingleImeBehavior single_ime_behavior) |
256 : TrayDetailsView(owner) { | 260 : TrayDetailsView(owner), last_pressed_item_id_("") { |
257 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 261 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
258 IMEInfoList list; | 262 IMEInfoList list; |
259 delegate->GetAvailableIMEList(&list); | 263 delegate->GetAvailableIMEList(&list); |
260 IMEPropertyInfoList property_list; | 264 IMEPropertyInfoList property_list; |
261 delegate->GetCurrentIMEProperties(&property_list); | 265 delegate->GetCurrentIMEProperties(&property_list); |
262 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 266 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
263 } | 267 } |
264 | 268 |
265 ImeListView::~ImeListView() {} | 269 ImeListView::~ImeListView() {} |
266 | 270 |
(...skipping 22 matching lines...) Expand all Loading... | |
289 PrependMaterialKeyboardStatus(); | 293 PrependMaterialKeyboardStatus(); |
290 } else { | 294 } else { |
291 if (list.size() > 1 || !property_list.empty()) | 295 if (list.size() > 1 || !property_list.empty()) |
292 AddScrollSeparator(); | 296 AddScrollSeparator(); |
293 AppendKeyboardStatus(); | 297 AppendKeyboardStatus(); |
294 } | 298 } |
295 } | 299 } |
296 | 300 |
297 Layout(); | 301 Layout(); |
298 SchedulePaint(); | 302 SchedulePaint(); |
303 | |
304 FocusCurrentImeIfNeeded(); | |
305 } | |
306 | |
307 void ImeListView::FocusCurrentImeIfNeeded() { | |
308 views::FocusManager* manager = GetFocusManager(); | |
309 if (!manager || manager->GetFocusedView() || last_pressed_item_id_.empty()) { | |
tdanderson
2016/12/08 00:42:11
Can you clarify why you take an early return if ma
Azure Wei
2016/12/08 13:14:55
When switching IMEs, all the {@link ImeListItemVie
tdanderson
2016/12/08 22:56:37
Acknowledged.
| |
310 return; | |
311 } | |
312 | |
313 for (auto ime_map : ime_map_) { | |
314 if (ime_map.second == last_pressed_item_id_) { | |
tdanderson
2016/12/08 00:42:11
nit: {} not needed for the same reasons mentioned
Azure Wei
2016/12/08 13:14:55
Done.
| |
315 (ime_map.first)->RequestFocus(); | |
316 } | |
317 } | |
299 } | 318 } |
300 | 319 |
301 void ImeListView::ResetImeListView() { | 320 void ImeListView::ResetImeListView() { |
302 // Children are removed from the view hierarchy and deleted in Reset(). | 321 // Children are removed from the view hierarchy and deleted in Reset(). |
303 Reset(); | 322 Reset(); |
304 material_keyboard_status_view_ = nullptr; | 323 material_keyboard_status_view_ = nullptr; |
305 keyboard_status_ = nullptr; | 324 keyboard_status_ = nullptr; |
306 } | 325 } |
307 | 326 |
308 void ImeListView::AppendIMEList(const IMEInfoList& list) { | 327 void ImeListView::AppendIMEList(const IMEInfoList& list) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 398 |
380 void ImeListView::PrependMaterialKeyboardStatus() { | 399 void ImeListView::PrependMaterialKeyboardStatus() { |
381 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial()); | 400 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial()); |
382 DCHECK(!material_keyboard_status_view_); | 401 DCHECK(!material_keyboard_status_view_); |
383 MaterialKeyboardStatusRowView* view = | 402 MaterialKeyboardStatusRowView* view = |
384 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); | 403 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); |
385 scroll_content()->AddChildViewAt(view, 0); | 404 scroll_content()->AddChildViewAt(view, 0); |
386 material_keyboard_status_view_ = view; | 405 material_keyboard_status_view_ = view; |
387 } | 406 } |
388 | 407 |
389 void ImeListView::HandleViewClicked(views::View* view) { | 408 void ImeListView::HandleViewPressed(views::View* view) { |
390 if (view == keyboard_status_) { | 409 if (view == keyboard_status_) { |
tdanderson
2016/12/08 00:42:11
From the documentation in the header apparently |k
Azure Wei
2016/12/08 13:14:55
Done.
| |
391 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 410 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
411 last_pressed_item_id_ = ""; | |
tdanderson
2016/12/08 00:42:11
Consider using base::Optional rather than the empt
Azure Wei
2016/12/08 13:14:55
Updated as last_selected_item_id_.clear().
Also, a
| |
392 return; | 412 return; |
393 } | 413 } |
394 | 414 |
395 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 415 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
396 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 416 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
397 if (ime != ime_map_.end()) { | 417 if (ime != ime_map_.end()) { |
398 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 418 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
399 std::string ime_id = ime->second; | 419 std::string ime_id = ime->second; |
420 last_pressed_item_id_ = ime_id; | |
400 delegate->SwitchIME(ime_id); | 421 delegate->SwitchIME(ime_id); |
401 } else { | 422 } else { |
402 std::map<views::View*, std::string>::const_iterator property = | 423 std::map<views::View*, std::string>::const_iterator property = |
403 property_map_.find(view); | 424 property_map_.find(view); |
404 if (property == property_map_.end()) | 425 if (property == property_map_.end()) |
405 return; | 426 return; |
406 const std::string key = property->second; | 427 const std::string key = property->second; |
428 last_pressed_item_id_ = key; | |
407 delegate->ActivateIMEProperty(key); | 429 delegate->ActivateIMEProperty(key); |
408 } | 430 } |
431 } | |
409 | 432 |
433 void ImeListView::HandleViewClicked(views::View* view) { | |
434 HandleViewPressed(view); | |
435 last_pressed_item_id_ = ""; | |
410 GetWidget()->Close(); | 436 GetWidget()->Close(); |
tdanderson
2016/12/08 00:42:11
So it looks as though when selecting with keyboard
Azure Wei
2016/12/08 13:14:55
Yes, the green checkmarks work correctly.
We are
tdanderson
2016/12/08 22:56:37
Acknowledged.
| |
411 } | 437 } |
412 | 438 |
413 void ImeListView::HandleButtonPressed(views::Button* sender, | 439 void ImeListView::HandleButtonPressed(views::Button* sender, |
414 const ui::Event& event) { | 440 const ui::Event& event) { |
415 if (material_keyboard_status_view_ && | 441 if (material_keyboard_status_view_ && |
416 sender == material_keyboard_status_view_->toggle()) { | 442 sender == material_keyboard_status_view_->toggle()) { |
417 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 443 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
418 } | 444 } |
419 } | 445 } |
420 | 446 |
421 } // namespace ash | 447 } // namespace ash |
OLD | NEW |