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

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

Issue 2474843002: Add virtual keyboard item into opt-in IME menu. (Closed)
Patch Set: Register observer. Created 4 years, 1 month 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_menu_tray.h" 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h"
6 6
7 #include "ash/common/accessibility_delegate.h" 7 #include "ash/common/accessibility_delegate.h"
8 #include "ash/common/ash_constants.h" 8 #include "ash/common/ash_constants.h"
9 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 293 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
294 }; 294 };
295 295
296 } // namespace 296 } // namespace
297 297
298 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 298 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
299 : TrayBackgroundView(wm_shelf), 299 : TrayBackgroundView(wm_shelf),
300 label_(new ImeMenuLabel()), 300 label_(new ImeMenuLabel()),
301 show_keyboard_(false), 301 show_keyboard_(false),
302 force_show_keyboard_(false), 302 force_show_keyboard_(false),
303 should_block_shelf_auto_hide_(false) { 303 should_block_shelf_auto_hide_(false),
304 keyboard_suppressed_(false) {
304 if (MaterialDesignController::IsShelfMaterial()) { 305 if (MaterialDesignController::IsShelfMaterial()) {
305 SetInkDropMode(InkDropMode::ON); 306 SetInkDropMode(InkDropMode::ON);
306 SetContentsBackground(false); 307 SetContentsBackground(false);
307 } else { 308 } else {
308 SetContentsBackground(true); 309 SetContentsBackground(true);
309 } 310 }
310 SetupLabelForTray(label_); 311 SetupLabelForTray(label_);
311 tray_container()->AddChildView(label_); 312 tray_container()->AddChildView(label_);
312 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); 313 SystemTrayNotifier* tray_notifier = WmShell::Get()->system_tray_notifier();
314 tray_notifier->AddIMEObserver(this);
315 tray_notifier->AddVirtualKeyboardObserver(this);
313 } 316 }
314 317
315 ImeMenuTray::~ImeMenuTray() { 318 ImeMenuTray::~ImeMenuTray() {
316 if (bubble_) 319 if (bubble_)
317 bubble_->bubble_view()->reset_delegate(); 320 bubble_->bubble_view()->reset_delegate();
318 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); 321 SystemTrayNotifier* tray_notifier = WmShell::Get()->system_tray_notifier();
322 tray_notifier->RemoveIMEObserver(this);
323 tray_notifier->RemoveVirtualKeyboardObserver(this);
319 } 324 }
320 325
321 void ImeMenuTray::ShowImeMenuBubble() { 326 void ImeMenuTray::ShowImeMenuBubble() {
322 should_block_shelf_auto_hide_ = true; 327 should_block_shelf_auto_hide_ = true;
323 views::TrayBubbleView::InitParams init_params( 328 views::TrayBubbleView::InitParams init_params(
324 GetAnchorAlignment(), kTrayPopupMinWidth, kTrayPopupMaxWidth); 329 GetAnchorAlignment(), kTrayPopupMinWidth, kTrayPopupMaxWidth);
325 init_params.can_activate = true; 330 init_params.can_activate = true;
326 init_params.close_on_deactivate = true; 331 init_params.close_on_deactivate = true;
327 332
328 views::TrayBubbleView* bubble_view = 333 views::TrayBubbleView* bubble_view =
329 views::TrayBubbleView::Create(GetBubbleAnchor(), this, &init_params); 334 views::TrayBubbleView::Create(GetBubbleAnchor(), this, &init_params);
330 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); 335 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets());
331 336
332 // In the material design, we will add a title item with a separator on the 337 // In the material design, we will add a title item with a separator on the
333 // top of the IME menu. 338 // top of the IME menu.
334 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 339 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
335 bubble_view->SetLayoutManager( 340 bubble_view->SetLayoutManager(
336 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 341 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
337 bubble_view->AddChildView( 342 bubble_view->AddChildView(
338 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); 343 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons()));
339 } else { 344 } else {
340 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); 345 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0));
341 } 346 }
342 347
343 // Adds IME list to the bubble. 348 // Adds IME list to the bubble.
344 ime_list_view_ = 349 ime_list_view_ = new ImeListView(nullptr, ShouldShowKeyboardToggle(),
345 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME); 350 ImeListView::SHOW_SINGLE_IME);
346 351
347 uint32_t current_height = ime_list_view_->scroll_content()->height(); 352 uint32_t current_height = ime_list_view_->scroll_content()->height();
348 const gfx::Range height_range = GetImeListViewRange(); 353 const gfx::Range height_range = GetImeListViewRange();
349 354
350 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 355 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
351 ime_list_view_->scroller()->ClipHeightTo(height_range.start(), 356 ime_list_view_->scroller()->ClipHeightTo(height_range.start(),
352 height_range.end()); 357 height_range.end());
353 } else if (current_height > height_range.end()) { 358 } else if (current_height > height_range.end()) {
354 ime_list_view_->scroller()->SetFixedSize( 359 ime_list_view_->scroller()->SetFixedSize(
355 gfx::Size(kTrayPopupMaxWidth, height_range.end())); 360 gfx::Size(kTrayPopupMaxWidth, height_range.end()));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 bool ImeMenuTray::ShouldBlockShelfAutoHide() const { 431 bool ImeMenuTray::ShouldBlockShelfAutoHide() const {
427 return should_block_shelf_auto_hide_; 432 return should_block_shelf_auto_hide_;
428 } 433 }
429 434
430 bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const { 435 bool ImeMenuTray::ShouldShowEmojiHandwritingVoiceButtons() const {
431 return InputMethodManager::Get() && 436 return InputMethodManager::Get() &&
432 InputMethodManager::Get()->IsEmojiHandwritingVoiceOnImeMenuEnabled() && 437 InputMethodManager::Get()->IsEmojiHandwritingVoiceOnImeMenuEnabled() &&
433 !current_ime_.third_party; 438 !current_ime_.third_party;
434 } 439 }
435 440
441 bool ImeMenuTray::ShouldShowKeyboardToggle() const {
442 return keyboard_suppressed_ &&
443 !WmShell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled();
444 }
445
436 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { 446 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) {
437 TrayBackgroundView::SetShelfAlignment(alignment); 447 TrayBackgroundView::SetShelfAlignment(alignment);
438 if (!MaterialDesignController::IsShelfMaterial()) 448 if (!MaterialDesignController::IsShelfMaterial())
439 tray_container()->SetBorder(views::NullBorder()); 449 tray_container()->SetBorder(views::NullBorder());
440 } 450 }
441 451
442 base::string16 ImeMenuTray::GetAccessibleNameForTray() { 452 base::string16 ImeMenuTray::GetAccessibleNameForTray() {
443 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); 453 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
444 } 454 }
445 455
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (keyboard_controller) 544 if (keyboard_controller)
535 keyboard_controller->RemoveObserver(this); 545 keyboard_controller->RemoveObserver(this);
536 546
537 if (!force_show_keyboard_) 547 if (!force_show_keyboard_)
538 return; 548 return;
539 549
540 WmShell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); 550 WmShell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false);
541 force_show_keyboard_ = false; 551 force_show_keyboard_ = false;
542 } 552 }
543 553
554 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) {
555 if (suppressed != keyboard_suppressed_ && bubble_)
tdanderson 2016/11/23 03:08:40 Is this something the IME detailed view OnKeyboard
Azure Wei 2016/11/23 05:21:14 Yes, IME detailed view shares the same logic. I us
556 HideImeMenuBubble();
557 keyboard_suppressed_ = suppressed;
558 }
559
544 void ImeMenuTray::UpdateTrayLabel() { 560 void ImeMenuTray::UpdateTrayLabel() {
545 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_); 561 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_);
546 562
547 // Updates the tray label based on the current input method. 563 // Updates the tray label based on the current input method.
548 if (current_ime_.third_party) 564 if (current_ime_.third_party)
549 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); 565 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*"));
550 else 566 else
551 label_->SetText(current_ime_.short_name); 567 label_->SetText(current_ime_.short_name);
552 } 568 }
553 569
554 } // namespace ash 570 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698