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

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_list_view.cc

Issue 2793153004: [Ash] Remove non-MD code from ImeListView and ImeListItemView (Closed)
Patch Set: class level docs for KeyboardStatusRow Created 3 years, 8 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/common/system/chromeos/ime_menu/ime_list_view.h" 5 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/system/tray/actionable_view.h"
8 #include "ash/common/system/tray/hover_highlight_view.h"
9 #include "ash/common/system/tray/ime_info.h" 8 #include "ash/common/system/tray/ime_info.h"
10 #include "ash/common/system/tray/system_menu_button.h" 9 #include "ash/common/system/tray/system_menu_button.h"
11 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/tray_constants.h" 11 #include "ash/common/system/tray/tray_constants.h"
13 #include "ash/common/system/tray/tray_details_view.h" 12 #include "ash/common/system/tray/tray_details_view.h"
14 #include "ash/common/system/tray/tray_popup_header_button.h" 13 #include "ash/common/system/tray/tray_popup_header_button.h"
15 #include "ash/common/system/tray/tray_popup_item_style.h" 14 #include "ash/common/system/tray/tray_popup_item_style.h"
16 #include "ash/common/system/tray/tray_popup_utils.h" 15 #include "ash/common/system/tray/tray_popup_utils.h"
17 #include "ash/common/system/tray/tri_view.h" 16 #include "ash/common/system/tray/tri_view.h"
18 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
19 #include "ash/resources/grit/ash_resources.h" 18 #include "ash/resources/grit/ash_resources.h"
20 #include "ash/resources/vector_icons/vector_icons.h" 19 #include "ash/resources/vector_icons/vector_icons.h"
21 #include "ash/shell.h" 20 #include "ash/shell.h"
22 #include "ash/strings/grit/ash_strings.h" 21 #include "ash/strings/grit/ash_strings.h"
23 #include "ui/accessibility/ax_node_data.h" 22 #include "ui/accessibility/ax_node_data.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/color_palette.h" 25 #include "ui/gfx/color_palette.h"
27 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/keyboard/keyboard_util.h" 27 #include "ui/keyboard/keyboard_util.h"
29 #include "ui/views/background.h" 28 #include "ui/views/background.h"
30 #include "ui/views/border.h"
31 #include "ui/views/controls/button/toggle_button.h" 29 #include "ui/views/controls/button/toggle_button.h"
32 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/label.h" 31 #include "ui/views/controls/label.h"
34 #include "ui/views/controls/separator.h" 32 #include "ui/views/controls/separator.h"
35 #include "ui/views/layout/fill_layout.h" 33 #include "ui/views/layout/fill_layout.h"
36 #include "ui/views/painter.h" 34 #include "ui/views/painter.h"
37 #include "ui/views/view.h" 35 #include "ui/views/view.h"
38 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
39 37
40 namespace ash { 38 namespace ash {
41 namespace { 39 namespace {
42 40
43 const int kMinFontSizeDelta = -10; 41 const int kMinFontSizeDelta = -10;
44 42
45 const SkColor kKeyboardRowSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F); 43 // Represents a row in the scrollable IME list; each row is either an IME or
46 44 // an IME property. A checkmark icon is shown in the row if selected.
47 // A |HoverHighlightView| that uses bold or normal font depending on whether it
48 // is selected. This view exposes itself as a checkbox to the accessibility
49 // framework.
50 class SelectableHoverHighlightView : public HoverHighlightView {
51 public:
52 SelectableHoverHighlightView(ViewClickListener* listener,
53 const base::string16& label,
54 bool selected)
55 : HoverHighlightView(listener), selected_(selected) {
56 AddLabelDeprecated(label, gfx::ALIGN_LEFT, selected);
57 }
58
59 ~SelectableHoverHighlightView() override {}
60
61 protected:
62 // views::View:
63 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
64 HoverHighlightView::GetAccessibleNodeData(node_data);
65 node_data->role = ui::AX_ROLE_CHECK_BOX;
66 if (selected_)
67 node_data->AddStateFlag(ui::AX_STATE_CHECKED);
68 }
69
70 private:
71 bool selected_;
72
73 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView);
74 };
75
76 // The IME list item view used in the material design. It contains IME info
77 // (name and label) and a check button if the item is selected. It's also used
78 // for IME property item, which has no name but label and a gray checked icon.
79 class ImeListItemView : public ActionableView { 45 class ImeListItemView : public ActionableView {
80 public: 46 public:
81 ImeListItemView(SystemTrayItem* owner, 47 ImeListItemView(SystemTrayItem* owner,
82 ImeListView* list_view, 48 ImeListView* list_view,
83 const base::string16& id, 49 const base::string16& id,
84 const base::string16& label, 50 const base::string16& label,
85 bool selected, 51 bool selected,
86 const SkColor button_color) 52 const SkColor button_color)
87 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), 53 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
88 ime_list_view_(list_view), 54 ime_list_view_(list_view),
89 selected_(selected) { 55 selected_(selected) {
90 if (MaterialDesignController::IsSystemTrayMenuMaterial()) 56 SetInkDropMode(InkDropHostView::InkDropMode::ON);
91 SetInkDropMode(InkDropHostView::InkDropMode::ON);
92 57
93 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); 58 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
94 AddChildView(tri_view); 59 AddChildView(tri_view);
95 SetLayoutManager(new views::FillLayout); 60 SetLayoutManager(new views::FillLayout);
96 61
97 // The id button shows the IME short name. 62 // |id_label| contains the IME short name (e.g., 'US', 'GB', 'IT').
98 views::Label* id_label = TrayPopupUtils::CreateDefaultLabel(); 63 views::Label* id_label = TrayPopupUtils::CreateDefaultLabel();
99 id_label->SetText(id); 64 id_label->SetText(id);
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 65 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
101 const gfx::FontList& base_font_list = 66 const gfx::FontList& base_font_list =
102 rb.GetFontList(ui::ResourceBundle::MediumBoldFont); 67 rb.GetFontList(ui::ResourceBundle::MediumBoldFont);
103 id_label->SetFontList(base_font_list); 68 id_label->SetFontList(base_font_list);
104 69
105 // For IMEs whose short name are more than 2 characters (INTL, EXTD, etc.), 70 // IMEs having a short name of more than two characters (e.g., 'INTL') will
106 // |kMenuIconSize| is not enough. The label will trigger eliding as "I..." 71 // elide if rendered within |kMenuIconSize|. Shrink the font size until the
107 // or "...". So we shrink the font size until it fits within the bounds. 72 // entire short name fits within the bounds.
108 int size_delta = -1; 73 int size_delta = -1;
109 while ((id_label->GetPreferredSize().width() - 74 while ((id_label->GetPreferredSize().width() -
110 id_label->GetInsets().width()) > kMenuIconSize && 75 id_label->GetInsets().width()) > kMenuIconSize &&
111 size_delta >= kMinFontSizeDelta) { 76 size_delta >= kMinFontSizeDelta) {
112 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_delta)); 77 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_delta));
113 --size_delta; 78 --size_delta;
114 } 79 }
115 tri_view->AddView(TriView::Container::START, id_label); 80 tri_view->AddView(TriView::Container::START, id_label);
116 81
117 // The label shows the IME name. 82 // The label shows the IME full name.
118 auto* label_view = TrayPopupUtils::CreateDefaultLabel(); 83 auto* label_view = TrayPopupUtils::CreateDefaultLabel();
119 label_view->SetText(label); 84 label_view->SetText(label);
120 TrayPopupItemStyle style( 85 TrayPopupItemStyle style(
121 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 86 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
122 style.SetupLabel(label_view); 87 style.SetupLabel(label_view);
123 88
124 label_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); 89 label_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
125 tri_view->AddView(TriView::Container::CENTER, label_view); 90 tri_view->AddView(TriView::Container::CENTER, label_view);
126 91
127 if (selected) { 92 if (selected) {
128 // The checked button indicates the IME is selected. 93 // The checked button indicates the IME is selected.
129 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView(); 94 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView();
130 checked_image->SetImage( 95 checked_image->SetImage(
131 gfx::CreateVectorIcon(kCheckCircleIcon, kMenuIconSize, button_color)); 96 gfx::CreateVectorIcon(kCheckCircleIcon, kMenuIconSize, button_color));
132 tri_view->AddView(TriView::Container::END, checked_image); 97 tri_view->AddView(TriView::Container::END, checked_image);
133 } 98 }
134 SetAccessibleName(label_view->text()); 99 SetAccessibleName(label_view->text());
135 } 100 }
136 101
137 ~ImeListItemView() override {} 102 ~ImeListItemView() override {}
138 103
139 // ActionableView: 104 // ActionableView:
140 bool PerformAction(const ui::Event& event) override { 105 bool PerformAction(const ui::Event& event) override {
141 if (ime_list_view_->should_focus_ime_after_selection_with_keyboard() && 106 ime_list_view_->set_last_item_selected_with_keyboard(
142 event.type() == ui::EventType::ET_KEY_PRESSED) { 107 ime_list_view_->should_focus_ime_after_selection_with_keyboard() &&
143 ime_list_view_->set_last_item_selected_with_keyboard(true); 108 event.type() == ui::EventType::ET_KEY_PRESSED);
144 } else {
145 ime_list_view_->set_last_item_selected_with_keyboard(false);
146 }
147
148 ime_list_view_->HandleViewClicked(this); 109 ime_list_view_->HandleViewClicked(this);
149 return true; 110 return true;
150 } 111 }
151 112
152 void OnFocus() override { 113 void OnFocus() override {
153 ActionableView::OnFocus(); 114 ActionableView::OnFocus();
154 if (ime_list_view_ && ime_list_view_->scroll_content()) 115 if (ime_list_view_ && ime_list_view_->scroll_content())
155 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); 116 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds());
156 } 117 }
157 118
158 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { 119 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
159 ActionableView::GetAccessibleNodeData(node_data); 120 ActionableView::GetAccessibleNodeData(node_data);
160 node_data->role = ui::AX_ROLE_CHECK_BOX; 121 node_data->role = ui::AX_ROLE_CHECK_BOX;
161 node_data->AddStateFlag(selected_ ? ui::AX_STATE_CHECKED 122 node_data->AddStateFlag(selected_ ? ui::AX_STATE_CHECKED
162 : ui::AX_STATE_NONE); 123 : ui::AX_STATE_NONE);
163 } 124 }
164 125
165 private: 126 private:
166 ImeListView* ime_list_view_; 127 ImeListView* ime_list_view_;
167 bool selected_; 128 bool selected_;
168 129
169 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); 130 DISALLOW_COPY_AND_ASSIGN(ImeListItemView);
170 }; 131 };
171 132
172 } // namespace 133 } // namespace
173 134
174 // The view that contains a |KeyboardButtonView| and a toggle button. 135 // Contains a toggle button to let the user enable/disable whether the
175 class MaterialKeyboardStatusRowView : public views::View { 136 // on-screen keyboard should be shown when focusing a textfield. This row is
137 // shown only under certain conditions, e.g., when an external keyboard is
138 // attached and the user is in TouchView mode.
139 class KeyboardStatusRow : public views::View {
176 public: 140 public:
177 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) 141 KeyboardStatusRow() {}
178 : listener_(listener), toggle_(nullptr) { 142 ~KeyboardStatusRow() override {}
179 Init();
180 toggle_->SetIsOn(enabled, false);
181 }
182 143
183 ~MaterialKeyboardStatusRowView() override {} 144 views::ToggleButton* toggle() const { return toggle_; }
184
185 views::Button* toggle() const { return toggle_; }
186 bool is_toggled() const { return toggle_->is_on(); } 145 bool is_toggled() const { return toggle_->is_on(); }
187 146
188 protected: 147 void Init(views::ButtonListener* listener) {
189 // views::View:
190 int GetHeightForWidth(int w) const override {
191 return GetPreferredSize().height();
192 }
193
194 private:
195 void Init() {
196 TrayPopupUtils::ConfigureAsStickyHeader(this); 148 TrayPopupUtils::ConfigureAsStickyHeader(this);
197 SetLayoutManager(new views::FillLayout); 149 SetLayoutManager(new views::FillLayout);
198 150
199 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); 151 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
200 AddChildView(tri_view); 152 AddChildView(tri_view);
201 153
202 // The on-screen keyboard image button. 154 // The on-screen keyboard image button.
203 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); 155 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView();
204 keyboard_image->SetImage(gfx::CreateVectorIcon( 156 keyboard_image->SetImage(gfx::CreateVectorIcon(
205 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); 157 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor));
206 tri_view->AddView(TriView::Container::START, keyboard_image); 158 tri_view->AddView(TriView::Container::START, keyboard_image);
207 159
208 // The on-screen keyboard label ('On-screen keyboard'). 160 // The on-screen keyboard label ('On-screen keyboard').
209 auto* label = TrayPopupUtils::CreateDefaultLabel(); 161 auto* label = TrayPopupUtils::CreateDefaultLabel();
210 label->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 162 label->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
211 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); 163 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD));
212 TrayPopupItemStyle style( 164 TrayPopupItemStyle style(
213 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 165 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
214 style.SetupLabel(label); 166 style.SetupLabel(label);
215 tri_view->AddView(TriView::Container::CENTER, label); 167 tri_view->AddView(TriView::Container::CENTER, label);
216 168
217 // The on-screen keyboard toggle button. 169 // The on-screen keyboard toggle button.
218 toggle_ = TrayPopupUtils::CreateToggleButton( 170 toggle_ = TrayPopupUtils::CreateToggleButton(
219 listener_, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); 171 listener, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD);
172 toggle_->SetIsOn(keyboard::IsKeyboardEnabled(), false);
220 tri_view->AddView(TriView::Container::END, toggle_); 173 tri_view->AddView(TriView::Container::END, toggle_);
221 } 174 }
222 175
223 // ButtonListener to notify when |toggle_| is clicked. 176 private:
224 views::ButtonListener* listener_; 177 // ToggleButton to toggle keyboard on or off.
178 views::ToggleButton* toggle_ = nullptr;
225 179
226 // ToggleButton to toggle keyboard on or off. 180 DISALLOW_COPY_AND_ASSIGN(KeyboardStatusRow);
227 views::ToggleButton* toggle_;
228
229 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView);
230 }; 181 };
231 182
232 ImeListView::ImeListView(SystemTrayItem* owner) 183 ImeListView::ImeListView(SystemTrayItem* owner)
233 : TrayDetailsView(owner), 184 : TrayDetailsView(owner),
234 last_item_selected_with_keyboard_(false), 185 last_item_selected_with_keyboard_(false),
235 should_focus_ime_after_selection_with_keyboard_(false), 186 should_focus_ime_after_selection_with_keyboard_(false),
236 current_ime_view_(nullptr) {} 187 current_ime_view_(nullptr) {}
237 188
238 ImeListView::~ImeListView() {} 189 ImeListView::~ImeListView() {}
239 190
240 void ImeListView::Init(bool show_keyboard_toggle, 191 void ImeListView::Init(bool show_keyboard_toggle,
241 SingleImeBehavior single_ime_behavior) { 192 SingleImeBehavior single_ime_behavior) {
242 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 193 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
243 IMEInfoList list; 194 IMEInfoList list;
244 delegate->GetAvailableIMEList(&list); 195 delegate->GetAvailableIMEList(&list);
245 IMEPropertyInfoList property_list; 196 IMEPropertyInfoList property_list;
246 delegate->GetCurrentIMEProperties(&property_list); 197 delegate->GetCurrentIMEProperties(&property_list);
247 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); 198 Update(list, property_list, show_keyboard_toggle, single_ime_behavior);
248 } 199 }
249 200
250 void ImeListView::Update(const IMEInfoList& list, 201 void ImeListView::Update(const IMEInfoList& list,
251 const IMEPropertyInfoList& property_list, 202 const IMEPropertyInfoList& property_list,
252 bool show_keyboard_toggle, 203 bool show_keyboard_toggle,
253 SingleImeBehavior single_ime_behavior) { 204 SingleImeBehavior single_ime_behavior) {
254 ResetImeListView(); 205 ResetImeListView();
255 ime_map_.clear(); 206 ime_map_.clear();
256 property_map_.clear(); 207 property_map_.clear();
257 CreateScrollableList(); 208 CreateScrollableList();
258 209
259 // Appends IME list and IME properties. 210 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1)
260 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { 211 AppendImeListAndProperties(list, property_list);
261 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
262 AppendImeListAndProperties(list, property_list);
263 } else {
264 AppendIMEList(list);
265 if (!property_list.empty())
266 AppendIMEProperties(property_list);
267 }
268 }
269 212
270 if (show_keyboard_toggle) { 213 if (show_keyboard_toggle)
271 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 214 PrependKeyboardStatusRow();
272 PrependMaterialKeyboardStatus();
273 } else {
274 if (list.size() > 1 || !property_list.empty())
275 AddScrollSeparator();
276 AppendKeyboardStatus();
277 }
278 }
279 215
280 Layout(); 216 Layout();
281 SchedulePaint(); 217 SchedulePaint();
282 218
283 if (should_focus_ime_after_selection_with_keyboard_ && 219 if (should_focus_ime_after_selection_with_keyboard_ &&
284 last_item_selected_with_keyboard_) { 220 last_item_selected_with_keyboard_) {
285 FocusCurrentImeIfNeeded(); 221 FocusCurrentImeIfNeeded();
286 } else if (current_ime_view_) { 222 } else if (current_ime_view_) {
287 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds()); 223 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds());
288 } 224 }
289 } 225 }
290 226
291 void ImeListView::ResetImeListView() { 227 void ImeListView::ResetImeListView() {
292 // Children are removed from the view hierarchy and deleted in Reset(). 228 // Children are removed from the view hierarchy and deleted in Reset().
293 Reset(); 229 Reset();
294 material_keyboard_status_view_ = nullptr; 230 keyboard_status_row_ = nullptr;
295 keyboard_status_ = nullptr;
296 current_ime_view_ = nullptr; 231 current_ime_view_ = nullptr;
297 } 232 }
298 233
299 void ImeListView::CloseImeListView() { 234 void ImeListView::CloseImeListView() {
300 last_selected_item_id_.clear(); 235 last_selected_item_id_.clear();
301 current_ime_view_ = nullptr; 236 current_ime_view_ = nullptr;
302 last_item_selected_with_keyboard_ = false; 237 last_item_selected_with_keyboard_ = false;
303 GetWidget()->Close(); 238 GetWidget()->Close();
304 } 239 }
305 240
306 void ImeListView::AppendIMEList(const IMEInfoList& list) {
307 DCHECK(ime_map_.empty());
308 for (size_t i = 0; i < list.size(); i++) {
309 HoverHighlightView* container =
310 new SelectableHoverHighlightView(this, list[i].name, list[i].selected);
311 scroll_content()->AddChildView(container);
312 ime_map_[container] = list[i].id;
313 }
314 }
315
316 void ImeListView::AppendIMEProperties(
317 const IMEPropertyInfoList& property_list) {
318 DCHECK(property_map_.empty());
319 for (size_t i = 0; i < property_list.size(); i++) {
320 HoverHighlightView* container = new SelectableHoverHighlightView(
321 this, property_list[i].name, property_list[i].selected);
322 if (i == 0)
323 container->SetBorder(
324 views::CreateSolidSidedBorder(1, 0, 0, 0, kBorderLightColor));
325 scroll_content()->AddChildView(container);
326 property_map_[container] = property_list[i].key;
327 }
328 }
329
330 void ImeListView::AppendImeListAndProperties( 241 void ImeListView::AppendImeListAndProperties(
331 const IMEInfoList& list, 242 const IMEInfoList& list,
332 const IMEPropertyInfoList& property_list) { 243 const IMEPropertyInfoList& property_list) {
333 DCHECK(ime_map_.empty()); 244 DCHECK(ime_map_.empty());
334 for (size_t i = 0; i < list.size(); i++) { 245 for (size_t i = 0; i < list.size(); i++) {
335 views::View* ime_view = 246 views::View* ime_view =
336 new ImeListItemView(owner(), this, list[i].short_name, list[i].name, 247 new ImeListItemView(owner(), this, list[i].short_name, list[i].name,
337 list[i].selected, gfx::kGoogleGreen700); 248 list[i].selected, gfx::kGoogleGreen700);
338 scroll_content()->AddChildView(ime_view); 249 scroll_content()->AddChildView(ime_view);
339 ime_map_[ime_view] = list[i].id; 250 ime_map_[ime_view] = list[i].id;
340 251
341 if (list[i].selected) 252 if (list[i].selected)
342 current_ime_view_ = ime_view; 253 current_ime_view_ = ime_view;
343 254
344 // In material design, the property items will be added after the current 255 // Add the properties, if any, of the currently-selected IME.
345 // selected IME item.
346 if (list[i].selected && !property_list.empty()) { 256 if (list[i].selected && !property_list.empty()) {
347 // Adds a separator on the top of property items. 257 // Adds a separator on the top of property items.
348 scroll_content()->AddChildView( 258 scroll_content()->AddChildView(
349 TrayPopupUtils::CreateListItemSeparator(true)); 259 TrayPopupUtils::CreateListItemSeparator(true));
350 260
351 // Adds the property items. 261 // Adds the property items.
352 for (size_t i = 0; i < property_list.size(); i++) { 262 for (size_t i = 0; i < property_list.size(); i++) {
353 ImeListItemView* property_view = new ImeListItemView( 263 ImeListItemView* property_view = new ImeListItemView(
354 owner(), this, base::string16(), property_list[i].name, 264 owner(), this, base::string16(), property_list[i].name,
355 property_list[i].selected, kMenuIconColor); 265 property_list[i].selected, kMenuIconColor);
356 scroll_content()->AddChildView(property_view); 266 scroll_content()->AddChildView(property_view);
357 property_map_[property_view] = property_list[i].key; 267 property_map_[property_view] = property_list[i].key;
358 } 268 }
359 269
360 // Adds a separator on the bottom of property items if there are still 270 // Adds a separator on the bottom of property items if there are still
361 // other IMEs under the current one. 271 // other IMEs under the current one.
362 if (i < list.size() - 1) 272 if (i < list.size() - 1)
363 scroll_content()->AddChildView( 273 scroll_content()->AddChildView(
364 TrayPopupUtils::CreateListItemSeparator(true)); 274 TrayPopupUtils::CreateListItemSeparator(true));
365 } 275 }
366 } 276 }
367 } 277 }
368 278
369 void ImeListView::AppendKeyboardStatus() { 279 void ImeListView::PrependKeyboardStatusRow() {
370 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial()); 280 DCHECK(!keyboard_status_row_);
371 HoverHighlightView* container = new HoverHighlightView(this); 281 keyboard_status_row_ = new KeyboardStatusRow;
372 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD 282 keyboard_status_row_->Init(this);
373 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; 283 scroll_content()->AddChildViewAt(keyboard_status_row_, 0);
374 container->AddLabelDeprecated(
375 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id),
376 gfx::ALIGN_LEFT, false /* highlight */);
377 scroll_content()->AddChildView(container);
378 keyboard_status_ = container;
379 }
380
381 void ImeListView::PrependMaterialKeyboardStatus() {
382 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial());
383 DCHECK(!material_keyboard_status_view_);
384 MaterialKeyboardStatusRowView* view =
385 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled());
386 scroll_content()->AddChildViewAt(view, 0);
387 material_keyboard_status_view_ = view;
388 } 284 }
389 285
390 void ImeListView::HandleViewClicked(views::View* view) { 286 void ImeListView::HandleViewClicked(views::View* view) {
391 if (view == keyboard_status_) {
392 WmShell::Get()->ToggleIgnoreExternalKeyboard();
393 last_selected_item_id_.clear();
394 last_item_selected_with_keyboard_ = false;
395 return;
396 }
397
398 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 287 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
399 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); 288 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view);
400 if (ime != ime_map_.end()) { 289 if (ime != ime_map_.end()) {
401 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); 290 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE);
402 std::string ime_id = ime->second; 291 std::string ime_id = ime->second;
403 last_selected_item_id_ = ime_id; 292 last_selected_item_id_ = ime_id;
404 delegate->SwitchIME(ime_id); 293 delegate->SwitchIME(ime_id);
405 } else { 294 } else {
406 std::map<views::View*, std::string>::const_iterator property = 295 std::map<views::View*, std::string>::const_iterator property =
407 property_map_.find(view); 296 property_map_.find(view);
408 if (property == property_map_.end()) 297 if (property == property_map_.end())
409 return; 298 return;
410 const std::string key = property->second; 299 const std::string key = property->second;
411 last_selected_item_id_ = key; 300 last_selected_item_id_ = key;
412 delegate->ActivateIMEProperty(key); 301 delegate->ActivateIMEProperty(key);
413 } 302 }
414 303
415 if (!should_focus_ime_after_selection_with_keyboard_ || 304 if (!should_focus_ime_after_selection_with_keyboard_ ||
416 !last_item_selected_with_keyboard_) { 305 !last_item_selected_with_keyboard_) {
417 CloseImeListView(); 306 CloseImeListView();
418 } 307 }
419 } 308 }
420 309
421 void ImeListView::HandleButtonPressed(views::Button* sender, 310 void ImeListView::HandleButtonPressed(views::Button* sender,
422 const ui::Event& event) { 311 const ui::Event& event) {
423 if (material_keyboard_status_view_ && 312 if (keyboard_status_row_ && sender == keyboard_status_row_->toggle()) {
424 sender == material_keyboard_status_view_->toggle()) {
425 WmShell::Get()->ToggleIgnoreExternalKeyboard(); 313 WmShell::Get()->ToggleIgnoreExternalKeyboard();
426 last_selected_item_id_.clear(); 314 last_selected_item_id_.clear();
427 last_item_selected_with_keyboard_ = false; 315 last_item_selected_with_keyboard_ = false;
428 } 316 }
429 } 317 }
430 318
431 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) { 319 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) {
432 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ && 320 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ &&
433 last_item_selected_with_keyboard_) || 321 last_item_selected_with_keyboard_) ||
434 !current_ime_view_) { 322 !current_ime_view_) {
(...skipping 22 matching lines...) Expand all
457 } 345 }
458 } 346 }
459 } 347 }
460 348
461 ImeListViewTestApi::ImeListViewTestApi(ImeListView* ime_list_view) 349 ImeListViewTestApi::ImeListViewTestApi(ImeListView* ime_list_view)
462 : ime_list_view_(ime_list_view) {} 350 : ime_list_view_(ime_list_view) {}
463 351
464 ImeListViewTestApi::~ImeListViewTestApi() {} 352 ImeListViewTestApi::~ImeListViewTestApi() {}
465 353
466 views::View* ImeListViewTestApi::GetToggleView() const { 354 views::View* ImeListViewTestApi::GetToggleView() const {
467 return ime_list_view_->material_keyboard_status_view_->toggle(); 355 return ime_list_view_->keyboard_status_row_->toggle();
468 } 356 }
469 357
470 } // namespace ash 358 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_list_view.h ('k') | ash/common/system/chromeos/ime_menu/ime_menu_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698