ime_menu_tray.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_IME_MENU_IME_MENU_TRAY_H_
  5. #define ASH_SYSTEM_IME_MENU_IME_MENU_TRAY_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  8. #include "ash/system/ime/ime_observer.h"
  9. #include "ash/system/tray/tray_background_view.h"
  10. #include "ash/system/tray/tray_bubble_view.h"
  11. #include "ash/system/tray/tray_bubble_wrapper.h"
  12. #include "ash/system/virtual_keyboard/virtual_keyboard_observer.h"
  13. #include "ui/base/ime/ash/ime_keyset.h"
  14. #include "ui/base/metadata/metadata_header_macros.h"
  15. namespace views {
  16. class ImageView;
  17. class Label;
  18. } // namespace views
  19. namespace ash {
  20. class ImeControllerImpl;
  21. class ImeListView;
  22. // A button in the tray which displays the short name of the currently-activated
  23. // IME (e.g., 'GB', 'US'). Clicking this button opens the opt-in IME menu,
  24. // a standalone bubble displaying a list of available IMEs along with buttons
  25. // for emoji, handwriting, and voice.
  26. class ASH_EXPORT ImeMenuTray : public TrayBackgroundView,
  27. public IMEObserver,
  28. public KeyboardControllerObserver,
  29. public VirtualKeyboardObserver {
  30. public:
  31. METADATA_HEADER(ImeMenuTray);
  32. explicit ImeMenuTray(Shelf* shelf);
  33. ImeMenuTray(const ImeMenuTray&) = delete;
  34. ImeMenuTray& operator=(const ImeMenuTray&) = delete;
  35. ~ImeMenuTray() override;
  36. // Shows the virtual keyboard with the given keyset: emoji, handwriting or
  37. // voice.
  38. void ShowKeyboardWithKeyset(input_method::ImeKeyset keyset);
  39. // Returns true if the menu should show emoji, handwriting and voice buttons
  40. // on the bottom. Otherwise, the menu will show a 'Customize...' bottom row
  41. // for non-MD UI, and a Settings button in the title row for MD.
  42. bool ShouldShowBottomButtons();
  43. // Returns whether the virtual keyboard toggle should be shown in shown in the
  44. // opt-in IME menu.
  45. bool ShouldShowKeyboardToggle() const;
  46. // TrayBackgroundView:
  47. void OnThemeChanged() override;
  48. std::u16string GetAccessibleNameForTray() override;
  49. void HandleLocaleChange() override;
  50. void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
  51. void ClickedOutsideBubble() override;
  52. bool PerformAction(const ui::Event& event) override;
  53. void CloseBubble() override;
  54. void ShowBubble() override;
  55. TrayBubbleView* GetBubbleView() override;
  56. views::Widget* GetBubbleWidget() const override;
  57. void AddedToWidget() override;
  58. // IMEObserver:
  59. void OnIMERefresh() override;
  60. void OnIMEMenuActivationChanged(bool is_activated) override;
  61. // TrayBubbleView::Delegate:
  62. std::u16string GetAccessibleNameForBubble() override;
  63. bool ShouldEnableExtraKeyboardAccessibility() override;
  64. void HideBubble(const TrayBubbleView* bubble_view) override;
  65. // KeyboardControllerObserver:
  66. void OnKeyboardHidden(bool is_temporary_hide) override;
  67. // VirtualKeyboardObserver:
  68. void OnKeyboardSuppressionChanged(bool suppressed) override;
  69. private:
  70. friend class ImeMenuTrayTest;
  71. // Show the IME menu bubble immediately.
  72. void ShowImeMenuBubbleInternal();
  73. // Updates the text of the label on the tray.
  74. void UpdateTrayLabel();
  75. void CreateLabel();
  76. void CreateImageView();
  77. ImeControllerImpl* ime_controller_;
  78. // Bubble for default and detailed views.
  79. std::unique_ptr<TrayBubbleWrapper> bubble_;
  80. ImeListView* ime_list_view_;
  81. // Only one of |label_| and |image_view_| can be non null at the same time.
  82. views::Label* label_;
  83. views::ImageView* image_view_;
  84. bool keyboard_suppressed_;
  85. bool show_bubble_after_keyboard_hidden_;
  86. bool is_emoji_enabled_;
  87. bool is_handwriting_enabled_;
  88. bool is_voice_enabled_;
  89. base::WeakPtrFactory<ImeMenuTray> weak_ptr_factory_{this};
  90. };
  91. } // namespace ash
  92. #endif // ASH_SYSTEM_IME_MENU_IME_MENU_TRAY_H_