ime_list_view.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_LIST_VIEW_H_
  5. #define ASH_SYSTEM_IME_MENU_IME_LIST_VIEW_H_
  6. #include <vector>
  7. #include "ash/ash_export.h"
  8. #include "ash/system/tray/tray_detailed_view.h"
  9. #include "ui/base/metadata/metadata_header_macros.h"
  10. #include "ui/views/controls/button/button.h"
  11. namespace ash {
  12. struct ImeInfo;
  13. struct ImeMenuItem;
  14. class KeyboardStatusRow;
  15. // Base class used to represent a selecatable list of available IMEs.
  16. // Optionally shows a toggle which is used to enable or disable the invocation
  17. // of the virtual keyboard.
  18. class ImeListView : public TrayDetailedView {
  19. public:
  20. METADATA_HEADER(ImeListView);
  21. enum SingleImeBehavior {
  22. // Shows the IME menu if there's only one IME in system.
  23. SHOW_SINGLE_IME,
  24. // Hides the IME menu if there's only one IME in system.
  25. HIDE_SINGLE_IME
  26. };
  27. explicit ImeListView(DetailedViewDelegate* delegate);
  28. ImeListView(const ImeListView&) = delete;
  29. ImeListView& operator=(const ImeListView&) = delete;
  30. ~ImeListView() override;
  31. // Initializes the contents of a newly-instantiated ImeListView.
  32. void Init(bool show_keyboard_toggle, SingleImeBehavior single_ime_behavior);
  33. // Updates the view.
  34. virtual void Update(const std::string& current_ime_id,
  35. const std::vector<ImeInfo>& list,
  36. const std::vector<ImeMenuItem>& property_items,
  37. bool show_keyboard_toggle,
  38. SingleImeBehavior single_ime_behavior);
  39. // Removes (and destroys) all child views.
  40. virtual void ResetImeListView();
  41. // Closes the view.
  42. void CloseImeListView();
  43. // Scrolls contents such that |item_view| is visible.
  44. void ScrollItemToVisible(views::View* item_view);
  45. void set_last_item_selected_with_keyboard(
  46. bool last_item_selected_with_keyboard) {
  47. last_item_selected_with_keyboard_ = last_item_selected_with_keyboard;
  48. }
  49. void set_should_focus_ime_after_selection_with_keyboard(
  50. const bool focus_current_ime) {
  51. should_focus_ime_after_selection_with_keyboard_ = focus_current_ime;
  52. }
  53. bool should_focus_ime_after_selection_with_keyboard() const {
  54. return should_focus_ime_after_selection_with_keyboard_;
  55. }
  56. // TrayDetailedView:
  57. void HandleViewClicked(views::View* view) override;
  58. // views::View:
  59. void VisibilityChanged(View* starting_from, bool is_visible) override;
  60. private:
  61. friend class ImeListViewTestApi;
  62. // Appends the IMEs and properties to the IME menu's scrollable area.
  63. void AppendImeListAndProperties(
  64. const std::string& current_ime_id,
  65. const std::vector<ImeInfo>& list,
  66. const std::vector<ImeMenuItem>& property_items);
  67. // Initializes |keyboard_status_row_| and adds it above the scrollable list.
  68. void PrependKeyboardStatusRow();
  69. void KeyboardStatusTogglePressed();
  70. // Requests focus on the current IME if it was selected with keyboard so that
  71. // accessible text will alert the user of the IME change.
  72. void FocusCurrentImeIfNeeded();
  73. std::map<views::View*, std::string> ime_map_;
  74. std::map<views::View*, std::string> property_map_;
  75. KeyboardStatusRow* keyboard_status_row_;
  76. // The id of the last item selected with keyboard. It will be empty if the
  77. // item is not selected with keyboard.
  78. std::string last_selected_item_id_;
  79. // True if the last item is selected with keyboard.
  80. bool last_item_selected_with_keyboard_ = false;
  81. // True if focus should be requested after switching IMEs with keyboard in
  82. // order to trigger spoken feedback with ChromeVox enabled.
  83. bool should_focus_ime_after_selection_with_keyboard_ = false;
  84. // The item view of the current selected IME.
  85. views::View* current_ime_view_ = nullptr;
  86. };
  87. class ASH_EXPORT ImeListViewTestApi {
  88. public:
  89. explicit ImeListViewTestApi(ImeListView* ime_list_view);
  90. ImeListViewTestApi(const ImeListViewTestApi&) = delete;
  91. ImeListViewTestApi& operator=(const ImeListViewTestApi&) = delete;
  92. virtual ~ImeListViewTestApi();
  93. views::View* GetToggleView() const;
  94. const std::map<views::View*, std::string>& ime_map() const {
  95. return ime_list_view_->ime_map_;
  96. }
  97. private:
  98. ImeListView* ime_list_view_;
  99. };
  100. } // namespace ash
  101. #endif // ASH_SYSTEM_IME_MENU_IME_LIST_VIEW_H_