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

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

Issue 2961313003: Touch gestures for System Tray/ IME/ Stylus/ Notifications (Closed)
Patch Set: Fixed msw's comments. Created 3 years, 5 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/system/ime_menu/ime_menu_tray.h" 5 #include "ash/system/ime_menu/ime_menu_tray.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h" 7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ime/ime_controller.h" 10 #include "ash/ime/ime_controller.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DCHECK(ime_menu_tray_); 188 DCHECK(ime_menu_tray_);
189 189
190 Init(show_emoji, show_handwriting, show_voice); 190 Init(show_emoji, show_handwriting, show_voice);
191 } 191 }
192 192
193 ~ImeButtonsView() override {} 193 ~ImeButtonsView() override {}
194 194
195 // views::ButtonListener: 195 // views::ButtonListener:
196 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 196 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
197 if (sender == settings_button_) { 197 if (sender == settings_button_) {
198 ime_menu_tray_->HideImeMenuBubble(); 198 ime_menu_tray_->CloseBubble();
199 ShowIMESettings(); 199 ShowIMESettings();
200 return; 200 return;
201 } 201 }
202 202
203 // The |keyset| will be used for drawing input view keyset in IME 203 // The |keyset| will be used for drawing input view keyset in IME
204 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with 204 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with
205 // the |keyset| string to generate the right input view url. 205 // the |keyset| string to generate the right input view url.
206 std::string keyset; 206 std::string keyset;
207 if (sender == emoji_button_) { 207 if (sender == emoji_button_) {
208 keyset = "emoji"; 208 keyset = "emoji";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 bubble_->bubble_view()->ResetDelegate(); 319 bubble_->bubble_view()->ResetDelegate();
320 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); 320 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier();
321 tray_notifier->RemoveIMEObserver(this); 321 tray_notifier->RemoveIMEObserver(this);
322 tray_notifier->RemoveVirtualKeyboardObserver(this); 322 tray_notifier->RemoveVirtualKeyboardObserver(this);
323 keyboard::KeyboardController* keyboard_controller = 323 keyboard::KeyboardController* keyboard_controller =
324 keyboard::KeyboardController::GetInstance(); 324 keyboard::KeyboardController::GetInstance();
325 if (keyboard_controller) 325 if (keyboard_controller)
326 keyboard_controller->RemoveObserver(this); 326 keyboard_controller->RemoveObserver(this);
327 } 327 }
328 328
329 void ImeMenuTray::ShowImeMenuBubble() {
330 keyboard::KeyboardController* keyboard_controller =
331 keyboard::KeyboardController::GetInstance();
332 if (keyboard_controller && keyboard_controller->keyboard_visible()) {
333 show_bubble_after_keyboard_hidden_ = true;
334 keyboard_controller->AddObserver(this);
335 keyboard_controller->HideKeyboard(
336 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
337 } else {
338 ShowImeMenuBubbleInternal();
339 }
340 }
341
342 void ImeMenuTray::ShowImeMenuBubbleInternal() { 329 void ImeMenuTray::ShowImeMenuBubbleInternal() {
343 views::TrayBubbleView::InitParams init_params; 330 views::TrayBubbleView::InitParams init_params;
344 init_params.delegate = this; 331 init_params.delegate = this;
345 init_params.parent_window = GetBubbleWindowContainer(); 332 init_params.parent_window = GetBubbleWindowContainer();
346 init_params.anchor_view = GetBubbleAnchor(); 333 init_params.anchor_view = GetBubbleAnchor();
347 init_params.anchor_alignment = GetAnchorAlignment(); 334 init_params.anchor_alignment = GetAnchorAlignment();
348 init_params.min_width = kTrayMenuMinimumWidth; 335 init_params.min_width = kTrayMenuMinimumWidth;
349 init_params.max_width = kTrayMenuMinimumWidth; 336 init_params.max_width = kTrayMenuMinimumWidth;
350 init_params.close_on_deactivate = true; 337 init_params.close_on_deactivate = true;
351 338
(...skipping 12 matching lines...) Expand all
364 351
365 if (show_bottom_buttons) { 352 if (show_bottom_buttons) {
366 bubble_view->AddChildView(new ImeButtonsView( 353 bubble_view->AddChildView(new ImeButtonsView(
367 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); 354 this, emoji_enabled_, handwriting_enabled_, voice_enabled_));
368 } 355 }
369 356
370 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); 357 bubble_.reset(new TrayBubbleWrapper(this, bubble_view));
371 SetIsActive(true); 358 SetIsActive(true);
372 } 359 }
373 360
374 void ImeMenuTray::HideImeMenuBubble() {
375 bubble_.reset();
376 ime_list_view_ = nullptr;
377 SetIsActive(false);
378 shelf()->UpdateAutoHideState();
379 }
380
381 bool ImeMenuTray::IsImeMenuBubbleShown() {
382 return !!bubble_;
383 }
384
385 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) { 361 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) {
386 HideImeMenuBubble(); 362 CloseBubble();
387 363
388 // Overrides the keyboard url ref to make it shown with the given keyset. 364 // Overrides the keyboard url ref to make it shown with the given keyset.
389 if (InputMethodManager::Get()) 365 if (InputMethodManager::Get())
390 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset); 366 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset);
391 367
392 // If onscreen keyboard has been enabled, shows the keyboard directly. 368 // If onscreen keyboard has been enabled, shows the keyboard directly.
393 keyboard::KeyboardController* keyboard_controller = 369 keyboard::KeyboardController* keyboard_controller =
394 keyboard::KeyboardController::GetInstance(); 370 keyboard::KeyboardController::GetInstance();
395 show_keyboard_ = true; 371 show_keyboard_ = true;
396 if (keyboard_controller) { 372 if (keyboard_controller) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 return keyboard_suppressed_ && 430 return keyboard_suppressed_ &&
455 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); 431 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled();
456 } 432 }
457 433
458 base::string16 ImeMenuTray::GetAccessibleNameForTray() { 434 base::string16 ImeMenuTray::GetAccessibleNameForTray() {
459 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); 435 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
460 } 436 }
461 437
462 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { 438 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
463 if (bubble_->bubble_view() == bubble_view) 439 if (bubble_->bubble_view() == bubble_view)
464 HideImeMenuBubble(); 440 CloseBubble();
465 } 441 }
466 442
467 void ImeMenuTray::ClickedOutsideBubble() { 443 void ImeMenuTray::ClickedOutsideBubble() {
468 HideImeMenuBubble(); 444 CloseBubble();
469 } 445 }
470 446
471 bool ImeMenuTray::PerformAction(const ui::Event& event) { 447 bool ImeMenuTray::PerformAction(const ui::Event& event) {
472 if (bubble_) 448 if (bubble_)
473 HideImeMenuBubble(); 449 CloseBubble();
474 else 450 else
475 ShowImeMenuBubble(); 451 ShowBubble();
476 return true; 452 return true;
477 } 453 }
478 454
455 void ImeMenuTray::CloseBubble() {
456 bubble_.reset();
457 ime_list_view_ = nullptr;
458 SetIsActive(false);
459 shelf()->UpdateAutoHideState();
460 }
461
462 void ImeMenuTray::ShowBubble() {
463 keyboard::KeyboardController* keyboard_controller =
464 keyboard::KeyboardController::GetInstance();
465 if (keyboard_controller && keyboard_controller->keyboard_visible()) {
466 show_bubble_after_keyboard_hidden_ = true;
467 keyboard_controller->AddObserver(this);
468 keyboard_controller->HideKeyboard(
469 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
470 } else {
471 ShowImeMenuBubbleInternal();
472 }
473 }
474
475 views::TrayBubbleView* ImeMenuTray::GetBubbleView() {
476 return bubble_ ? bubble_->bubble_view() : nullptr;
477 }
478
479 void ImeMenuTray::OnIMERefresh() { 479 void ImeMenuTray::OnIMERefresh() {
480 UpdateTrayLabel(); 480 UpdateTrayLabel();
481 if (bubble_ && ime_list_view_) { 481 if (bubble_ && ime_list_view_) {
482 ime_list_view_->Update(ime_controller_->current_ime().id, 482 ime_list_view_->Update(ime_controller_->current_ime().id,
483 ime_controller_->available_imes(), 483 ime_controller_->available_imes(),
484 ime_controller_->current_ime_menu_items(), false, 484 ime_controller_->current_ime_menu_items(), false,
485 ImeListView::SHOW_SINGLE_IME); 485 ImeListView::SHOW_SINGLE_IME);
486 } 486 }
487 } 487 }
488 488
489 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { 489 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
490 SetVisible(is_activated); 490 SetVisible(is_activated);
491 if (is_activated) 491 if (is_activated)
492 UpdateTrayLabel(); 492 UpdateTrayLabel();
493 else 493 else
494 HideImeMenuBubble(); 494 CloseBubble();
495 } 495 }
496 496
497 void ImeMenuTray::BubbleViewDestroyed() { 497 void ImeMenuTray::BubbleViewDestroyed() {
498 } 498 }
499 499
500 void ImeMenuTray::OnMouseEnteredView() {} 500 void ImeMenuTray::OnMouseEnteredView() {}
501 501
502 void ImeMenuTray::OnMouseExitedView() {} 502 void ImeMenuTray::OnMouseExitedView() {}
503 503
504 void ImeMenuTray::RegisterAccelerators( 504 void ImeMenuTray::RegisterAccelerators(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 return; 571 return;
572 572
573 // Posts a task to disable the virtual keyboard. 573 // Posts a task to disable the virtual keyboard.
574 base::ThreadTaskRunnerHandle::Get()->PostTask( 574 base::ThreadTaskRunnerHandle::Get()->PostTask(
575 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard, 575 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard,
576 weak_ptr_factory_.GetWeakPtr())); 576 weak_ptr_factory_.GetWeakPtr()));
577 } 577 }
578 578
579 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) { 579 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) {
580 if (suppressed != keyboard_suppressed_ && bubble_) 580 if (suppressed != keyboard_suppressed_ && bubble_)
581 HideImeMenuBubble(); 581 CloseBubble();
582 keyboard_suppressed_ = suppressed; 582 keyboard_suppressed_ = suppressed;
583 } 583 }
584 584
585 void ImeMenuTray::UpdateTrayLabel() { 585 void ImeMenuTray::UpdateTrayLabel() {
586 const mojom::ImeInfo& current_ime = ime_controller_->current_ime(); 586 const mojom::ImeInfo& current_ime = ime_controller_->current_ime();
587 587
588 // Updates the tray label based on the current input method. 588 // Updates the tray label based on the current input method.
589 if (current_ime.third_party) 589 if (current_ime.third_party)
590 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*")); 590 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*"));
591 else 591 else
592 label_->SetText(current_ime.short_name); 592 label_->SetText(current_ime.short_name);
593 } 593 }
594 594
595 void ImeMenuTray::DisableVirtualKeyboard() { 595 void ImeMenuTray::DisableVirtualKeyboard() {
596 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); 596 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false);
597 force_show_keyboard_ = false; 597 force_show_keyboard_ = false;
598 } 598 }
599 599
600 } // namespace ash 600 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698