OLD | NEW |
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 DCHECK(ime_menu_tray_); | 183 DCHECK(ime_menu_tray_); |
184 | 184 |
185 Init(show_emoji, show_handwriting, show_voice); | 185 Init(show_emoji, show_handwriting, show_voice); |
186 } | 186 } |
187 | 187 |
188 ~ImeButtonsView() override {} | 188 ~ImeButtonsView() override {} |
189 | 189 |
190 // views::ButtonListener: | 190 // views::ButtonListener: |
191 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 191 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
192 if (sender == settings_button_) { | 192 if (sender == settings_button_) { |
193 ime_menu_tray_->HideImeMenuBubble(); | 193 ime_menu_tray_->CloseBubble(); |
194 ShowIMESettings(); | 194 ShowIMESettings(); |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 // The |keyset| will be used for drawing input view keyset in IME | 198 // The |keyset| will be used for drawing input view keyset in IME |
199 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with | 199 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with |
200 // the |keyset| string to generate the right input view url. | 200 // the |keyset| string to generate the right input view url. |
201 std::string keyset; | 201 std::string keyset; |
202 if (sender == emoji_button_) { | 202 if (sender == emoji_button_) { |
203 keyset = "emoji"; | 203 keyset = "emoji"; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 bubble_->bubble_view()->ResetDelegate(); | 313 bubble_->bubble_view()->ResetDelegate(); |
314 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 314 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
315 tray_notifier->RemoveIMEObserver(this); | 315 tray_notifier->RemoveIMEObserver(this); |
316 tray_notifier->RemoveVirtualKeyboardObserver(this); | 316 tray_notifier->RemoveVirtualKeyboardObserver(this); |
317 keyboard::KeyboardController* keyboard_controller = | 317 keyboard::KeyboardController* keyboard_controller = |
318 keyboard::KeyboardController::GetInstance(); | 318 keyboard::KeyboardController::GetInstance(); |
319 if (keyboard_controller) | 319 if (keyboard_controller) |
320 keyboard_controller->RemoveObserver(this); | 320 keyboard_controller->RemoveObserver(this); |
321 } | 321 } |
322 | 322 |
323 void ImeMenuTray::ShowImeMenuBubble() { | |
324 keyboard::KeyboardController* keyboard_controller = | |
325 keyboard::KeyboardController::GetInstance(); | |
326 if (keyboard_controller && keyboard_controller->keyboard_visible()) { | |
327 show_bubble_after_keyboard_hidden_ = true; | |
328 keyboard_controller->AddObserver(this); | |
329 keyboard_controller->HideKeyboard( | |
330 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
331 } else { | |
332 ShowImeMenuBubbleInternal(); | |
333 } | |
334 } | |
335 | |
336 void ImeMenuTray::ShowImeMenuBubbleInternal() { | 323 void ImeMenuTray::ShowImeMenuBubbleInternal() { |
337 views::TrayBubbleView::InitParams init_params; | 324 views::TrayBubbleView::InitParams init_params; |
338 init_params.delegate = this; | 325 init_params.delegate = this; |
339 init_params.parent_window = GetBubbleWindowContainer(); | 326 init_params.parent_window = GetBubbleWindowContainer(); |
340 init_params.anchor_view = GetBubbleAnchor(); | 327 init_params.anchor_view = GetBubbleAnchor(); |
341 init_params.anchor_alignment = GetAnchorAlignment(); | 328 init_params.anchor_alignment = GetAnchorAlignment(); |
342 init_params.min_width = kTrayMenuMinimumWidth; | 329 init_params.min_width = kTrayMenuMinimumWidth; |
343 init_params.max_width = kTrayMenuMinimumWidth; | 330 init_params.max_width = kTrayMenuMinimumWidth; |
344 init_params.close_on_deactivate = true; | 331 init_params.close_on_deactivate = true; |
345 | 332 |
(...skipping 12 matching lines...) Expand all Loading... |
358 | 345 |
359 if (show_bottom_buttons) { | 346 if (show_bottom_buttons) { |
360 bubble_view->AddChildView(new ImeButtonsView( | 347 bubble_view->AddChildView(new ImeButtonsView( |
361 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); | 348 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); |
362 } | 349 } |
363 | 350 |
364 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); | 351 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
365 SetIsActive(true); | 352 SetIsActive(true); |
366 } | 353 } |
367 | 354 |
368 void ImeMenuTray::HideImeMenuBubble() { | |
369 bubble_.reset(); | |
370 ime_list_view_ = nullptr; | |
371 SetIsActive(false); | |
372 shelf()->UpdateAutoHideState(); | |
373 } | |
374 | |
375 bool ImeMenuTray::IsImeMenuBubbleShown() { | |
376 return !!bubble_; | |
377 } | |
378 | |
379 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) { | 355 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) { |
380 HideImeMenuBubble(); | 356 CloseBubble(); |
381 | 357 |
382 // Overrides the keyboard url ref to make it shown with the given keyset. | 358 // Overrides the keyboard url ref to make it shown with the given keyset. |
383 if (InputMethodManager::Get()) | 359 if (InputMethodManager::Get()) |
384 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset); | 360 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset); |
385 | 361 |
386 // If onscreen keyboard has been enabled, shows the keyboard directly. | 362 // If onscreen keyboard has been enabled, shows the keyboard directly. |
387 keyboard::KeyboardController* keyboard_controller = | 363 keyboard::KeyboardController* keyboard_controller = |
388 keyboard::KeyboardController::GetInstance(); | 364 keyboard::KeyboardController::GetInstance(); |
389 show_keyboard_ = true; | 365 show_keyboard_ = true; |
390 if (keyboard_controller) { | 366 if (keyboard_controller) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 return keyboard_suppressed_ && | 424 return keyboard_suppressed_ && |
449 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); | 425 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); |
450 } | 426 } |
451 | 427 |
452 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | 428 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
453 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 429 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
454 } | 430 } |
455 | 431 |
456 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 432 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
457 if (bubble_->bubble_view() == bubble_view) | 433 if (bubble_->bubble_view() == bubble_view) |
458 HideImeMenuBubble(); | 434 CloseBubble(); |
459 } | 435 } |
460 | 436 |
461 void ImeMenuTray::ClickedOutsideBubble() { | 437 void ImeMenuTray::ClickedOutsideBubble() { |
462 HideImeMenuBubble(); | 438 CloseBubble(); |
463 } | 439 } |
464 | 440 |
465 bool ImeMenuTray::PerformAction(const ui::Event& event) { | 441 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
466 if (bubble_) | 442 if (bubble_) |
467 HideImeMenuBubble(); | 443 CloseBubble(); |
468 else | 444 else |
469 ShowImeMenuBubble(); | 445 ShowBubble(); |
470 return true; | 446 return true; |
471 } | 447 } |
472 | 448 |
| 449 void ImeMenuTray::CloseBubble() { |
| 450 bubble_.reset(); |
| 451 ime_list_view_ = nullptr; |
| 452 SetIsActive(false); |
| 453 shelf()->UpdateAutoHideState(); |
| 454 } |
| 455 |
| 456 void ImeMenuTray::ShowBubble() { |
| 457 keyboard::KeyboardController* keyboard_controller = |
| 458 keyboard::KeyboardController::GetInstance(); |
| 459 if (keyboard_controller && keyboard_controller->keyboard_visible()) { |
| 460 show_bubble_after_keyboard_hidden_ = true; |
| 461 keyboard_controller->AddObserver(this); |
| 462 keyboard_controller->HideKeyboard( |
| 463 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
| 464 } else { |
| 465 ShowImeMenuBubbleInternal(); |
| 466 } |
| 467 } |
| 468 |
| 469 views::TrayBubbleView* ImeMenuTray::GetBubbleView() { |
| 470 return bubble_ ? bubble_->bubble_view() : nullptr; |
| 471 } |
| 472 |
| 473 void ImeMenuTray::OnGestureEvent(ui::GestureEvent* event) { |
| 474 if (!drag_controller()->ProcessGestureEvent(event, this)) |
| 475 TrayBackgroundView::OnGestureEvent(event); |
| 476 } |
| 477 |
473 void ImeMenuTray::OnIMERefresh() { | 478 void ImeMenuTray::OnIMERefresh() { |
474 UpdateTrayLabel(); | 479 UpdateTrayLabel(); |
475 if (bubble_ && ime_list_view_) { | 480 if (bubble_ && ime_list_view_) { |
476 ime_list_view_->Update(ime_controller_->current_ime().id, | 481 ime_list_view_->Update(ime_controller_->current_ime().id, |
477 ime_controller_->available_imes(), | 482 ime_controller_->available_imes(), |
478 ime_controller_->current_ime_menu_items(), false, | 483 ime_controller_->current_ime_menu_items(), false, |
479 ImeListView::SHOW_SINGLE_IME); | 484 ImeListView::SHOW_SINGLE_IME); |
480 } | 485 } |
481 } | 486 } |
482 | 487 |
483 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | 488 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { |
484 SetVisible(is_activated); | 489 SetVisible(is_activated); |
485 if (is_activated) | 490 if (is_activated) |
486 UpdateTrayLabel(); | 491 UpdateTrayLabel(); |
487 else | 492 else |
488 HideImeMenuBubble(); | 493 CloseBubble(); |
489 } | 494 } |
490 | 495 |
491 void ImeMenuTray::BubbleViewDestroyed() { | 496 void ImeMenuTray::BubbleViewDestroyed() { |
492 } | 497 } |
493 | 498 |
494 void ImeMenuTray::OnMouseEnteredView() {} | 499 void ImeMenuTray::OnMouseEnteredView() {} |
495 | 500 |
496 void ImeMenuTray::OnMouseExitedView() {} | 501 void ImeMenuTray::OnMouseExitedView() {} |
497 | 502 |
498 void ImeMenuTray::RegisterAccelerators( | 503 void ImeMenuTray::RegisterAccelerators( |
(...skipping 13 matching lines...) Expand all Loading... |
512 } | 517 } |
513 | 518 |
514 bool ImeMenuTray::ShouldEnableExtraKeyboardAccessibility() { | 519 bool ImeMenuTray::ShouldEnableExtraKeyboardAccessibility() { |
515 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); | 520 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); |
516 } | 521 } |
517 | 522 |
518 void ImeMenuTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 523 void ImeMenuTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
519 HideBubbleWithView(bubble_view); | 524 HideBubbleWithView(bubble_view); |
520 } | 525 } |
521 | 526 |
| 527 bool ImeMenuTray::ProcessGestureEventForBubble(ui::GestureEvent* event) { |
| 528 return drag_controller()->ProcessGestureEvent(event, this); |
| 529 } |
522 void ImeMenuTray::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {} | 530 void ImeMenuTray::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {} |
523 | 531 |
524 void ImeMenuTray::OnKeyboardClosed() { | 532 void ImeMenuTray::OnKeyboardClosed() { |
525 if (InputMethodManager::Get()) | 533 if (InputMethodManager::Get()) |
526 InputMethodManager::Get()->OverrideKeyboardUrlRef(std::string()); | 534 InputMethodManager::Get()->OverrideKeyboardUrlRef(std::string()); |
527 keyboard::KeyboardController* keyboard_controller = | 535 keyboard::KeyboardController* keyboard_controller = |
528 keyboard::KeyboardController::GetInstance(); | 536 keyboard::KeyboardController::GetInstance(); |
529 if (keyboard_controller) | 537 if (keyboard_controller) |
530 keyboard_controller->RemoveObserver(this); | 538 keyboard_controller->RemoveObserver(this); |
531 | 539 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 return; | 573 return; |
566 | 574 |
567 // Posts a task to disable the virtual keyboard. | 575 // Posts a task to disable the virtual keyboard. |
568 base::ThreadTaskRunnerHandle::Get()->PostTask( | 576 base::ThreadTaskRunnerHandle::Get()->PostTask( |
569 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard, | 577 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard, |
570 weak_ptr_factory_.GetWeakPtr())); | 578 weak_ptr_factory_.GetWeakPtr())); |
571 } | 579 } |
572 | 580 |
573 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) { | 581 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) { |
574 if (suppressed != keyboard_suppressed_ && bubble_) | 582 if (suppressed != keyboard_suppressed_ && bubble_) |
575 HideImeMenuBubble(); | 583 CloseBubble(); |
576 keyboard_suppressed_ = suppressed; | 584 keyboard_suppressed_ = suppressed; |
577 } | 585 } |
578 | 586 |
579 void ImeMenuTray::UpdateTrayLabel() { | 587 void ImeMenuTray::UpdateTrayLabel() { |
580 const mojom::ImeInfo& current_ime = ime_controller_->current_ime(); | 588 const mojom::ImeInfo& current_ime = ime_controller_->current_ime(); |
581 | 589 |
582 // Updates the tray label based on the current input method. | 590 // Updates the tray label based on the current input method. |
583 if (current_ime.third_party) | 591 if (current_ime.third_party) |
584 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*")); | 592 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*")); |
585 else | 593 else |
586 label_->SetText(current_ime.short_name); | 594 label_->SetText(current_ime.short_name); |
587 } | 595 } |
588 | 596 |
589 void ImeMenuTray::DisableVirtualKeyboard() { | 597 void ImeMenuTray::DisableVirtualKeyboard() { |
590 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); | 598 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); |
591 force_show_keyboard_ = false; | 599 force_show_keyboard_ = false; |
592 } | 600 } |
593 | 601 |
594 } // namespace ash | 602 } // namespace ash |
OLD | NEW |