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