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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ime_list_view_->HandleViewClicked(this); |
| 144 |
| 145 if (ime_list_view_->focus_current_ime() && |
| 146 event.type() == ui::EventType::ET_KEY_PRESSED) { |
| 147 ime_list_view_->SetLastItemSelectedWithKeyboard(true); |
| 148 } else { |
| 149 ime_list_view_->CloseImeListView(); |
| 150 } |
| 151 |
144 return true; | 152 return true; |
145 } | 153 } |
146 | 154 |
147 void OnFocus() override { | 155 void OnFocus() override { |
148 ActionableView::OnFocus(); | 156 ActionableView::OnFocus(); |
149 if (ime_list_view_ && ime_list_view_->scroll_content()) | 157 if (ime_list_view_ && ime_list_view_->scroll_content()) |
150 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); | 158 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); |
151 } | 159 } |
152 | 160 |
153 // views::View: | 161 // views::View: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 254 |
247 // ToggleButton to toggle keyboard on or off. | 255 // ToggleButton to toggle keyboard on or off. |
248 views::ToggleButton* toggle_; | 256 views::ToggleButton* toggle_; |
249 | 257 |
250 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | 258 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); |
251 }; | 259 }; |
252 | 260 |
253 ImeListView::ImeListView(SystemTrayItem* owner, | 261 ImeListView::ImeListView(SystemTrayItem* owner, |
254 bool show_keyboard_toggle, | 262 bool show_keyboard_toggle, |
255 SingleImeBehavior single_ime_behavior) | 263 SingleImeBehavior single_ime_behavior) |
256 : TrayDetailsView(owner) { | 264 : TrayDetailsView(owner), |
| 265 last_item_selected_with_keyboard_(false), |
| 266 focus_current_ime_(false) { |
257 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 267 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
258 IMEInfoList list; | 268 IMEInfoList list; |
259 delegate->GetAvailableIMEList(&list); | 269 delegate->GetAvailableIMEList(&list); |
260 IMEPropertyInfoList property_list; | 270 IMEPropertyInfoList property_list; |
261 delegate->GetCurrentIMEProperties(&property_list); | 271 delegate->GetCurrentIMEProperties(&property_list); |
262 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 272 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
263 } | 273 } |
264 | 274 |
265 ImeListView::~ImeListView() {} | 275 ImeListView::~ImeListView() {} |
266 | 276 |
(...skipping 22 matching lines...) Expand all Loading... |
289 PrependMaterialKeyboardStatus(); | 299 PrependMaterialKeyboardStatus(); |
290 } else { | 300 } else { |
291 if (list.size() > 1 || !property_list.empty()) | 301 if (list.size() > 1 || !property_list.empty()) |
292 AddScrollSeparator(); | 302 AddScrollSeparator(); |
293 AppendKeyboardStatus(); | 303 AppendKeyboardStatus(); |
294 } | 304 } |
295 } | 305 } |
296 | 306 |
297 Layout(); | 307 Layout(); |
298 SchedulePaint(); | 308 SchedulePaint(); |
| 309 |
| 310 if (focus_current_ime_ && last_item_selected_with_keyboard_) |
| 311 FocusCurrentImeIfNeeded(); |
299 } | 312 } |
300 | 313 |
301 void ImeListView::ResetImeListView() { | 314 void ImeListView::ResetImeListView() { |
302 // Children are removed from the view hierarchy and deleted in Reset(). | 315 // Children are removed from the view hierarchy and deleted in Reset(). |
303 Reset(); | 316 Reset(); |
304 material_keyboard_status_view_ = nullptr; | 317 material_keyboard_status_view_ = nullptr; |
305 keyboard_status_ = nullptr; | 318 keyboard_status_ = nullptr; |
306 } | 319 } |
307 | 320 |
| 321 void ImeListView::CloseImeListView() { |
| 322 last_selected_item_id_.clear(); |
| 323 last_item_selected_with_keyboard_ = false; |
| 324 GetWidget()->Close(); |
| 325 } |
| 326 |
308 void ImeListView::AppendIMEList(const IMEInfoList& list) { | 327 void ImeListView::AppendIMEList(const IMEInfoList& list) { |
309 DCHECK(ime_map_.empty()); | 328 DCHECK(ime_map_.empty()); |
310 for (size_t i = 0; i < list.size(); i++) { | 329 for (size_t i = 0; i < list.size(); i++) { |
311 HoverHighlightView* container = | 330 HoverHighlightView* container = |
312 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); | 331 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); |
313 scroll_content()->AddChildView(container); | 332 scroll_content()->AddChildView(container); |
314 ime_map_[container] = list[i].id; | 333 ime_map_[container] = list[i].id; |
315 } | 334 } |
316 } | 335 } |
317 | 336 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::HandleViewClicked(views::View* view) { |
390 if (view == keyboard_status_) { | 409 if (view == keyboard_status_) { |
391 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 410 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 411 last_selected_item_id_.clear(); |
| 412 last_item_selected_with_keyboard_ = false; |
392 return; | 413 return; |
393 } | 414 } |
394 | 415 |
395 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 416 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
396 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 417 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
397 if (ime != ime_map_.end()) { | 418 if (ime != ime_map_.end()) { |
398 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 419 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
399 std::string ime_id = ime->second; | 420 std::string ime_id = ime->second; |
| 421 last_selected_item_id_ = ime_id; |
400 delegate->SwitchIME(ime_id); | 422 delegate->SwitchIME(ime_id); |
401 } else { | 423 } else { |
402 std::map<views::View*, std::string>::const_iterator property = | 424 std::map<views::View*, std::string>::const_iterator property = |
403 property_map_.find(view); | 425 property_map_.find(view); |
404 if (property == property_map_.end()) | 426 if (property == property_map_.end()) |
405 return; | 427 return; |
406 const std::string key = property->second; | 428 const std::string key = property->second; |
| 429 last_selected_item_id_ = key; |
407 delegate->ActivateIMEProperty(key); | 430 delegate->ActivateIMEProperty(key); |
408 } | 431 }; |
409 | |
410 GetWidget()->Close(); | |
411 } | 432 } |
412 | 433 |
413 void ImeListView::HandleButtonPressed(views::Button* sender, | 434 void ImeListView::HandleButtonPressed(views::Button* sender, |
414 const ui::Event& event) { | 435 const ui::Event& event) { |
415 if (material_keyboard_status_view_ && | 436 if (material_keyboard_status_view_ && |
416 sender == material_keyboard_status_view_->toggle()) { | 437 sender == material_keyboard_status_view_->toggle()) { |
417 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 438 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 439 last_selected_item_id_.clear(); |
| 440 last_item_selected_with_keyboard_ = false; |
418 } | 441 } |
419 } | 442 } |
420 | 443 |
| 444 void ImeListView::FocusCurrentImeIfNeeded() { |
| 445 views::FocusManager* manager = GetFocusManager(); |
| 446 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty()) |
| 447 return; |
| 448 |
| 449 for (auto ime_map : ime_map_) { |
| 450 if (ime_map.second == last_selected_item_id_) |
| 451 (ime_map.first)->RequestFocus(); |
| 452 } |
| 453 } |
| 454 |
421 } // namespace ash | 455 } // namespace ash |
OLD | NEW |