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

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
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
276 void ImeListView::Update(const IMEInfoList& list, 277 void ImeListView::Update(const IMEInfoList& list,
277 const IMEPropertyInfoList& property_list, 278 const IMEPropertyInfoList& property_list,
278 bool show_keyboard_toggle, 279 bool show_keyboard_toggle,
279 SingleImeBehavior single_ime_behavior) { 280 SingleImeBehavior single_ime_behavior) {
280 ResetImeListView(); 281 ResetImeListView();
281 ime_map_.clear(); 282 ime_map_.clear();
282 property_map_.clear(); 283 property_map_.clear();
283 CreateScrollableList(); 284 CreateScrollableList();
285 current_ime_view_ = nullptr;
tdanderson 2017/01/12 00:16:14 Should this be placed in ResetImeListView() instea
Azure Wei 2017/01/12 01:20:54 Moved to ResetImeListView(). Thanks.
284 286
285 // Appends IME list and IME properties. 287 // Appends IME list and IME properties.
286 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { 288 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) {
287 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 289 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
288 AppendImeListAndProperties(list, property_list); 290 AppendImeListAndProperties(list, property_list);
289 } else { 291 } else {
290 AppendIMEList(list); 292 AppendIMEList(list);
291 if (!property_list.empty()) 293 if (!property_list.empty())
292 AppendIMEProperties(property_list); 294 AppendIMEProperties(property_list);
293 } 295 }
294 } 296 }
295 297
296 if (show_keyboard_toggle) { 298 if (show_keyboard_toggle) {
297 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 299 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
298 PrependMaterialKeyboardStatus(); 300 PrependMaterialKeyboardStatus();
299 } else { 301 } else {
300 if (list.size() > 1 || !property_list.empty()) 302 if (list.size() > 1 || !property_list.empty())
301 AddScrollSeparator(); 303 AddScrollSeparator();
302 AppendKeyboardStatus(); 304 AppendKeyboardStatus();
303 } 305 }
304 } 306 }
305 307
306 Layout(); 308 Layout();
307 SchedulePaint(); 309 SchedulePaint();
308 310
309 if (should_focus_ime_after_selection_with_keyboard_ && 311 if (should_focus_ime_after_selection_with_keyboard_ &&
310 last_item_selected_with_keyboard_) 312 last_item_selected_with_keyboard_)
311 FocusCurrentImeIfNeeded(); 313 FocusCurrentImeIfNeeded();
314 else if (current_ime_view_ != nullptr)
tdanderson 2017/01/12 00:16:15 I don't think I understand why this is an 'else if
Azure Wei 2017/01/12 01:20:54 If (should_focus_ime_after_selection_with_keyboard
tdanderson 2017/01/12 21:27:33 Acknowledged.
315 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds());
tdanderson 2017/01/12 00:16:14 please use {} after the if and else-if clauses sin
Azure Wei 2017/01/12 01:20:54 Done.
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;
319 } 323 }
320 324
321 void ImeListView::CloseImeListView() { 325 void ImeListView::CloseImeListView() {
322 last_selected_item_id_.clear(); 326 last_selected_item_id_.clear();
327 current_ime_view_ = nullptr;
323 last_item_selected_with_keyboard_ = false; 328 last_item_selected_with_keyboard_ = false;
324 GetWidget()->Close(); 329 GetWidget()->Close();
325 } 330 }
326 331
327 void ImeListView::AppendIMEList(const IMEInfoList& list) { 332 void ImeListView::AppendIMEList(const IMEInfoList& list) {
328 DCHECK(ime_map_.empty()); 333 DCHECK(ime_map_.empty());
329 for (size_t i = 0; i < list.size(); i++) { 334 for (size_t i = 0; i < list.size(); i++) {
330 HoverHighlightView* container = 335 HoverHighlightView* container =
331 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); 336 new SelectableHoverHighlightView(this, list[i].name, list[i].selected);
332 scroll_content()->AddChildView(container); 337 scroll_content()->AddChildView(container);
(...skipping 19 matching lines...) Expand all
352 const IMEInfoList& list, 357 const IMEInfoList& list,
353 const IMEPropertyInfoList& property_list) { 358 const IMEPropertyInfoList& property_list) {
354 DCHECK(ime_map_.empty()); 359 DCHECK(ime_map_.empty());
355 for (size_t i = 0; i < list.size(); i++) { 360 for (size_t i = 0; i < list.size(); i++) {
356 views::View* ime_view = 361 views::View* ime_view =
357 new ImeListItemView(owner(), this, list[i].short_name, list[i].name, 362 new ImeListItemView(owner(), this, list[i].short_name, list[i].name,
358 list[i].selected, gfx::kGoogleGreen700); 363 list[i].selected, gfx::kGoogleGreen700);
359 scroll_content()->AddChildView(ime_view); 364 scroll_content()->AddChildView(ime_view);
360 ime_map_[ime_view] = list[i].id; 365 ime_map_[ime_view] = list[i].id;
361 366
367 if (list[i].selected)
368 current_ime_view_ = ime_view;
369
362 // In material design, the property items will be added after the current 370 // In material design, the property items will be added after the current
363 // selected IME item. 371 // selected IME item.
364 if (list[i].selected && !property_list.empty()) { 372 if (list[i].selected && !property_list.empty()) {
365 // Adds a separator on the top of property items. 373 // Adds a separator on the top of property items.
366 scroll_content()->AddChildView( 374 scroll_content()->AddChildView(
367 TrayPopupUtils::CreateListItemSeparator(true)); 375 TrayPopupUtils::CreateListItemSeparator(true));
368 376
369 // Adds the property items. 377 // Adds the property items.
370 for (size_t i = 0; i < property_list.size(); i++) { 378 for (size_t i = 0; i < property_list.size(); i++) {
371 ImeListItemView* property_view = new ImeListItemView( 379 ImeListItemView* property_view = new ImeListItemView(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 void ImeListView::HandleButtonPressed(views::Button* sender, 447 void ImeListView::HandleButtonPressed(views::Button* sender,
440 const ui::Event& event) { 448 const ui::Event& event) {
441 if (material_keyboard_status_view_ && 449 if (material_keyboard_status_view_ &&
442 sender == material_keyboard_status_view_->toggle()) { 450 sender == material_keyboard_status_view_->toggle()) {
443 WmShell::Get()->ToggleIgnoreExternalKeyboard(); 451 WmShell::Get()->ToggleIgnoreExternalKeyboard();
444 last_selected_item_id_.clear(); 452 last_selected_item_id_.clear();
445 last_item_selected_with_keyboard_ = false; 453 last_item_selected_with_keyboard_ = false;
446 } 454 }
447 } 455 }
448 456
457 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) {
458 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ &&
459 last_item_selected_with_keyboard_) ||
tdanderson 2017/01/12 00:16:15 This formatting seems strange, can you run 'git cl
Azure Wei 2017/01/12 01:20:54 This is formatted by 'git cl format'.
460 current_ime_view_ == nullptr)
tdanderson 2017/01/12 00:16:14 just "!current_ime_view_" instead of "== nullptr"
Azure Wei 2017/01/12 01:20:54 Done.
461 return;
tdanderson 2017/01/12 00:16:14 use {} since boolean expression spans more than on
Azure Wei 2017/01/12 01:20:54 Done.
462
463 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds());
tdanderson 2017/01/12 00:16:14 If I am switching to an IME that has a property li
Azure Wei 2017/01/12 01:20:54 It's hard to show the whole thing. For opt-in IME
tdanderson 2017/01/12 21:27:33 Acknowledged.
464 }
465
449 void ImeListView::FocusCurrentImeIfNeeded() { 466 void ImeListView::FocusCurrentImeIfNeeded() {
450 views::FocusManager* manager = GetFocusManager(); 467 views::FocusManager* manager = GetFocusManager();
451 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty()) 468 if (!manager || manager->GetFocusedView() || last_selected_item_id_.empty())
452 return; 469 return;
453 470
454 for (auto ime_map : ime_map_) { 471 for (auto ime_map : ime_map_) {
455 if (ime_map.second == last_selected_item_id_) { 472 if (ime_map.second == last_selected_item_id_) {
456 (ime_map.first)->RequestFocus(); 473 (ime_map.first)->RequestFocus();
457 return; 474 return;
458 } 475 }
459 } 476 }
460 477
461 for (auto property_map : property_map_) { 478 for (auto property_map : property_map_) {
462 if (property_map.second == last_selected_item_id_) { 479 if (property_map.second == last_selected_item_id_) {
463 (property_map.first)->RequestFocus(); 480 (property_map.first)->RequestFocus();
464 return; 481 return;
465 } 482 }
466 } 483 }
467 } 484 }
468 485
469 } // namespace ash 486 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698