Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_list_view.cc

Issue 2560793002: Request focus on IME menu rows after keyboard selection (Closed)
Patch Set: Addressed comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_->should_focus_ime_after_selection_with_keyboard() &&
146 event.type() == ui::EventType::ET_KEY_PRESSED) {
147 ime_list_view_->set_last_item_selected_with_keyboard(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
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 should_focus_ime_after_selection_with_keyboard_(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
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 (should_focus_ime_after_selection_with_keyboard_ &&
311 last_item_selected_with_keyboard_)
312 FocusCurrentImeIfNeeded();
299 } 313 }
300 314
301 void ImeListView::ResetImeListView() { 315 void ImeListView::ResetImeListView() {
302 // Children are removed from the view hierarchy and deleted in Reset(). 316 // Children are removed from the view hierarchy and deleted in Reset().
303 Reset(); 317 Reset();
304 material_keyboard_status_view_ = nullptr; 318 material_keyboard_status_view_ = nullptr;
305 keyboard_status_ = nullptr; 319 keyboard_status_ = nullptr;
306 } 320 }
307 321
322 void ImeListView::CloseImeListView() {
323 last_selected_item_id_.clear();
324 last_item_selected_with_keyboard_ = false;
325 GetWidget()->Close();
326 }
327
308 void ImeListView::AppendIMEList(const IMEInfoList& list) { 328 void ImeListView::AppendIMEList(const IMEInfoList& list) {
309 DCHECK(ime_map_.empty()); 329 DCHECK(ime_map_.empty());
310 for (size_t i = 0; i < list.size(); i++) { 330 for (size_t i = 0; i < list.size(); i++) {
311 HoverHighlightView* container = 331 HoverHighlightView* container =
312 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); 332 new SelectableHoverHighlightView(this, list[i].name, list[i].selected);
313 scroll_content()->AddChildView(container); 333 scroll_content()->AddChildView(container);
314 ime_map_[container] = list[i].id; 334 ime_map_[container] = list[i].id;
315 } 335 }
316 } 336 }
317 337
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 DCHECK(!material_keyboard_status_view_); 402 DCHECK(!material_keyboard_status_view_);
383 MaterialKeyboardStatusRowView* view = 403 MaterialKeyboardStatusRowView* view =
384 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); 404 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled());
385 scroll_content()->AddChildViewAt(view, 0); 405 scroll_content()->AddChildViewAt(view, 0);
386 material_keyboard_status_view_ = view; 406 material_keyboard_status_view_ = view;
387 } 407 }
388 408
389 void ImeListView::HandleViewClicked(views::View* view) { 409 void ImeListView::HandleViewClicked(views::View* view) {
390 if (view == keyboard_status_) { 410 if (view == keyboard_status_) {
391 WmShell::Get()->ToggleIgnoreExternalKeyboard(); 411 WmShell::Get()->ToggleIgnoreExternalKeyboard();
412 last_selected_item_id_.clear();
413 last_item_selected_with_keyboard_ = false;
392 return; 414 return;
393 } 415 }
394 416
395 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 417 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
396 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); 418 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view);
397 if (ime != ime_map_.end()) { 419 if (ime != ime_map_.end()) {
398 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); 420 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE);
399 std::string ime_id = ime->second; 421 std::string ime_id = ime->second;
422 last_selected_item_id_ = ime_id;
400 delegate->SwitchIME(ime_id); 423 delegate->SwitchIME(ime_id);
401 } else { 424 } else {
402 std::map<views::View*, std::string>::const_iterator property = 425 std::map<views::View*, std::string>::const_iterator property =
403 property_map_.find(view); 426 property_map_.find(view);
404 if (property == property_map_.end()) 427 if (property == property_map_.end())
405 return; 428 return;
406 const std::string key = property->second; 429 const std::string key = property->second;
430 last_selected_item_id_ = key;
407 delegate->ActivateIMEProperty(key); 431 delegate->ActivateIMEProperty(key);
408 } 432 };
409
410 GetWidget()->Close();
411 } 433 }
412 434
413 void ImeListView::HandleButtonPressed(views::Button* sender, 435 void ImeListView::HandleButtonPressed(views::Button* sender,
414 const ui::Event& event) { 436 const ui::Event& event) {
415 if (material_keyboard_status_view_ && 437 if (material_keyboard_status_view_ &&
416 sender == material_keyboard_status_view_->toggle()) { 438 sender == material_keyboard_status_view_->toggle()) {
417 WmShell::Get()->ToggleIgnoreExternalKeyboard(); 439 WmShell::Get()->ToggleIgnoreExternalKeyboard();
440 last_selected_item_id_.clear();
441 last_item_selected_with_keyboard_ = false;
418 } 442 }
419 } 443 }
420 444
445 void ImeListView::FocusCurrentImeIfNeeded() {
446 views::FocusManager* manager = GetFocusManager();
447 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty())
448 return;
449
450 for (auto ime_map : ime_map_) {
451 if (ime_map.second == last_selected_item_id_)
452 (ime_map.first)->RequestFocus();
453 }
454 }
455
421 } // namespace ash 456 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_list_view.h ('k') | ash/common/system/chromeos/ime_menu/ime_menu_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698