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

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

Issue 2624193002: Scroll to make the selected IME visible. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_list_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 views::ToggleButton* toggle_; 255 views::ToggleButton* toggle_;
256 256
257 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); 257 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView);
258 }; 258 };
259 259
260 ImeListView::ImeListView(SystemTrayItem* owner, 260 ImeListView::ImeListView(SystemTrayItem* owner,
261 bool show_keyboard_toggle, 261 bool show_keyboard_toggle,
262 SingleImeBehavior single_ime_behavior) 262 SingleImeBehavior single_ime_behavior)
263 : TrayDetailsView(owner), 263 : TrayDetailsView(owner),
264 last_item_selected_with_keyboard_(false), 264 last_item_selected_with_keyboard_(false),
265 should_focus_ime_after_selection_with_keyboard_(false) { 265 should_focus_ime_after_selection_with_keyboard_(false),
266 current_ime_view_(nullptr) {
266 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 267 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
267 IMEInfoList list; 268 IMEInfoList list;
268 delegate->GetAvailableIMEList(&list); 269 delegate->GetAvailableIMEList(&list);
269 IMEPropertyInfoList property_list; 270 IMEPropertyInfoList property_list;
270 delegate->GetCurrentIMEProperties(&property_list); 271 delegate->GetCurrentIMEProperties(&property_list);
271 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); 272 Update(list, property_list, show_keyboard_toggle, single_ime_behavior);
272 } 273 }
273 274
274 ImeListView::~ImeListView() {} 275 ImeListView::~ImeListView() {}
275 276
(...skipping 24 matching lines...) Expand all
300 if (list.size() > 1 || !property_list.empty()) 301 if (list.size() > 1 || !property_list.empty())
301 AddScrollSeparator(); 302 AddScrollSeparator();
302 AppendKeyboardStatus(); 303 AppendKeyboardStatus();
303 } 304 }
304 } 305 }
305 306
306 Layout(); 307 Layout();
307 SchedulePaint(); 308 SchedulePaint();
308 309
309 if (should_focus_ime_after_selection_with_keyboard_ && 310 if (should_focus_ime_after_selection_with_keyboard_ &&
310 last_item_selected_with_keyboard_) 311 last_item_selected_with_keyboard_) {
311 FocusCurrentImeIfNeeded(); 312 FocusCurrentImeIfNeeded();
313 } else if (current_ime_view_) {
314 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds());
315 }
312 } 316 }
313 317
314 void ImeListView::ResetImeListView() { 318 void ImeListView::ResetImeListView() {
315 // Children are removed from the view hierarchy and deleted in Reset(). 319 // Children are removed from the view hierarchy and deleted in Reset().
316 Reset(); 320 Reset();
317 material_keyboard_status_view_ = nullptr; 321 material_keyboard_status_view_ = nullptr;
318 keyboard_status_ = nullptr; 322 keyboard_status_ = nullptr;
323 current_ime_view_ = nullptr;
319 } 324 }
320 325
321 void ImeListView::CloseImeListView() { 326 void ImeListView::CloseImeListView() {
322 last_selected_item_id_.clear(); 327 last_selected_item_id_.clear();
328 current_ime_view_ = nullptr;
323 last_item_selected_with_keyboard_ = false; 329 last_item_selected_with_keyboard_ = false;
324 GetWidget()->Close(); 330 GetWidget()->Close();
325 } 331 }
326 332
327 void ImeListView::AppendIMEList(const IMEInfoList& list) { 333 void ImeListView::AppendIMEList(const IMEInfoList& list) {
328 DCHECK(ime_map_.empty()); 334 DCHECK(ime_map_.empty());
329 for (size_t i = 0; i < list.size(); i++) { 335 for (size_t i = 0; i < list.size(); i++) {
330 HoverHighlightView* container = 336 HoverHighlightView* container =
331 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); 337 new SelectableHoverHighlightView(this, list[i].name, list[i].selected);
332 scroll_content()->AddChildView(container); 338 scroll_content()->AddChildView(container);
(...skipping 19 matching lines...) Expand all
352 const IMEInfoList& list, 358 const IMEInfoList& list,
353 const IMEPropertyInfoList& property_list) { 359 const IMEPropertyInfoList& property_list) {
354 DCHECK(ime_map_.empty()); 360 DCHECK(ime_map_.empty());
355 for (size_t i = 0; i < list.size(); i++) { 361 for (size_t i = 0; i < list.size(); i++) {
356 views::View* ime_view = 362 views::View* ime_view =
357 new ImeListItemView(owner(), this, list[i].short_name, list[i].name, 363 new ImeListItemView(owner(), this, list[i].short_name, list[i].name,
358 list[i].selected, gfx::kGoogleGreen700); 364 list[i].selected, gfx::kGoogleGreen700);
359 scroll_content()->AddChildView(ime_view); 365 scroll_content()->AddChildView(ime_view);
360 ime_map_[ime_view] = list[i].id; 366 ime_map_[ime_view] = list[i].id;
361 367
368 if (list[i].selected)
369 current_ime_view_ = ime_view;
370
362 // In material design, the property items will be added after the current 371 // In material design, the property items will be added after the current
363 // selected IME item. 372 // selected IME item.
364 if (list[i].selected && !property_list.empty()) { 373 if (list[i].selected && !property_list.empty()) {
365 // Adds a separator on the top of property items. 374 // Adds a separator on the top of property items.
366 scroll_content()->AddChildView( 375 scroll_content()->AddChildView(
367 TrayPopupUtils::CreateListItemSeparator(true)); 376 TrayPopupUtils::CreateListItemSeparator(true));
368 377
369 // Adds the property items. 378 // Adds the property items.
370 for (size_t i = 0; i < property_list.size(); i++) { 379 for (size_t i = 0; i < property_list.size(); i++) {
371 ImeListItemView* property_view = new ImeListItemView( 380 ImeListItemView* property_view = new ImeListItemView(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 void ImeListView::HandleButtonPressed(views::Button* sender, 448 void ImeListView::HandleButtonPressed(views::Button* sender,
440 const ui::Event& event) { 449 const ui::Event& event) {
441 if (material_keyboard_status_view_ && 450 if (material_keyboard_status_view_ &&
442 sender == material_keyboard_status_view_->toggle()) { 451 sender == material_keyboard_status_view_->toggle()) {
443 WmShell::Get()->ToggleIgnoreExternalKeyboard(); 452 WmShell::Get()->ToggleIgnoreExternalKeyboard();
444 last_selected_item_id_.clear(); 453 last_selected_item_id_.clear();
445 last_item_selected_with_keyboard_ = false; 454 last_item_selected_with_keyboard_ = false;
446 } 455 }
447 } 456 }
448 457
458 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) {
459 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ &&
460 last_item_selected_with_keyboard_) ||
461 !current_ime_view_) {
462 return;
463 }
464
465 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds());
466 }
467
449 void ImeListView::FocusCurrentImeIfNeeded() { 468 void ImeListView::FocusCurrentImeIfNeeded() {
450 views::FocusManager* manager = GetFocusManager(); 469 views::FocusManager* manager = GetFocusManager();
451 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty()) 470 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty())
452 return; 471 return;
453 472
454 for (auto ime_map : ime_map_) { 473 for (auto ime_map : ime_map_) {
455 if (ime_map.second == last_selected_item_id_) { 474 if (ime_map.second == last_selected_item_id_) {
456 (ime_map.first)->RequestFocus(); 475 (ime_map.first)->RequestFocus();
457 return; 476 return;
458 } 477 }
459 } 478 }
460 479
461 for (auto property_map : property_map_) { 480 for (auto property_map : property_map_) {
462 if (property_map.second == last_selected_item_id_) { 481 if (property_map.second == last_selected_item_id_) {
463 (property_map.first)->RequestFocus(); 482 (property_map.first)->RequestFocus();
464 return; 483 return;
465 } 484 }
466 } 485 }
467 } 486 }
468 487
469 } // namespace ash 488 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_list_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698