Chromium Code Reviews| 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/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/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/tray/hover_highlight_view.h" | 8 #include "ash/common/system/tray/hover_highlight_view.h" |
| 9 #include "ash/common/system/tray/ime_info.h" | 9 #include "ash/common/system/tray/ime_info.h" |
| 10 #include "ash/common/system/tray/system_menu_button.h" | |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/system/tray/tray_details_view.h" | 13 #include "ash/common/system/tray/tray_details_view.h" |
| 13 #include "ash/common/system/tray/tray_popup_header_button.h" | 14 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_style.h" | 15 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 15 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 16 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
| 17 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 18 #include "ui/accessibility/ax_view_state.h" | 19 #include "ui/accessibility/ax_view_state.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/color_palette.h" | 22 #include "ui/gfx/color_palette.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" | 23 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 24 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/keyboard/keyboard_util.h" | 25 #include "ui/keyboard/keyboard_util.h" |
| 25 #include "ui/views/border.h" | 26 #include "ui/views/border.h" |
| 26 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
| 28 #include "ui/views/controls/button/toggle_button.h" | |
| 27 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/separator.h" | 30 #include "ui/views/controls/separator.h" |
| 29 #include "ui/views/layout/box_layout.h" | 31 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/layout/fill_layout.h" | |
| 33 #include "ui/views/painter.h" | |
| 34 #include "ui/views/view.h" | |
| 30 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 31 | 36 |
| 32 namespace ash { | 37 namespace ash { |
| 33 namespace { | 38 namespace { |
| 34 | 39 |
| 40 const int kKeyboardRowkVerticalInset = 4; | |
| 41 const int kKeyboardRowSeparatorThickness = 1; | |
| 42 const int kKeyboardRowChildSpacing = 14; | |
| 43 const int kFocusBorderInset = 1; | |
| 44 | |
| 45 const SkColor kKeyboardRowSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F); | |
| 46 | |
| 35 // Creates a separator that will be used between the IME list items. | 47 // Creates a separator that will be used between the IME list items. |
| 36 views::Separator* CreateListItemSeparator() { | 48 views::Separator* CreateListItemSeparator() { |
| 37 views::Separator* separator = | 49 views::Separator* separator = |
| 38 new views::Separator(views::Separator::HORIZONTAL); | 50 new views::Separator(views::Separator::HORIZONTAL); |
| 39 separator->SetColor(kBorderLightColor); | 51 separator->SetColor(kBorderLightColor); |
| 40 separator->SetPreferredSize(kSeparatorWidth); | 52 separator->SetPreferredSize(kSeparatorWidth); |
| 41 separator->SetBorder(views::Border::CreateEmptyBorder( | 53 separator->SetBorder(views::Border::CreateEmptyBorder( |
| 42 kMenuSeparatorVerticalPadding, 0, kMenuSeparatorVerticalPadding, 0)); | 54 kMenuSeparatorVerticalPadding, 0, kMenuSeparatorVerticalPadding, 0)); |
| 43 return separator; | 55 return separator; |
| 44 } | 56 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 bool PerformAction(const ui::Event& event) override { | 157 bool PerformAction(const ui::Event& event) override { |
| 146 ime_list_view_->HandleViewClicked(this); | 158 ime_list_view_->HandleViewClicked(this); |
| 147 return true; | 159 return true; |
| 148 } | 160 } |
| 149 | 161 |
| 150 private: | 162 private: |
| 151 ImeListView* ime_list_view_; | 163 ImeListView* ime_list_view_; |
| 152 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); | 164 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); |
| 153 }; | 165 }; |
| 154 | 166 |
| 167 // The view that contains on-screen keyboard image and label. | |
| 168 class KeyboardButtonView : public views::View { | |
| 169 public: | |
| 170 KeyboardButtonView() { | |
| 171 views::BoxLayout* box_layout = | |
| 172 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 173 SetLayoutManager(box_layout); | |
| 174 | |
| 175 ui::NativeTheme* theme = GetNativeTheme(); | |
| 176 SystemMenuButton* on_screen_keyboard_ = new SystemMenuButton( | |
|
tdanderson
2016/11/01 21:42:11
I checked with Sebastien, and the toggle button is
Azure Wei
2016/11/02 15:01:41
Updated this as ImageButton.
| |
| 177 nullptr, SystemMenuButton::InkDropStyle::SQUARE, | |
| 178 kImeMenuOnScreenKeyboardIcon, | |
| 179 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); | |
|
tdanderson
2016/11/01 21:42:11
In terms of accessibility, the a11y string should
Azure Wei
2016/11/02 15:01:41
Sets the toggle button's a11y text here.
| |
| 180 const SkColor focus_color = | |
| 181 theme->GetSystemColor(ui::NativeTheme::kColorId_FocusedBorderColor); | |
| 182 on_screen_keyboard_->SetFocusForPlatform(); | |
| 183 on_screen_keyboard_->SetFocusPainter( | |
| 184 views::Painter::CreateSolidFocusPainter( | |
| 185 focus_color, gfx::Insets(kFocusBorderInset))); | |
| 186 AddChildView(on_screen_keyboard_); | |
| 187 | |
| 188 views::Label* label_ = new views::Label( | |
| 189 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 190 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); | |
| 191 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 192 AddChildView(label_); | |
| 193 box_layout->SetFlexForView(label_, 1); | |
| 194 } | |
| 195 | |
| 196 ~KeyboardButtonView() override {} | |
| 197 | |
| 198 private: | |
| 199 DISALLOW_COPY_AND_ASSIGN(KeyboardButtonView); | |
| 200 }; | |
| 201 | |
| 155 } // namespace | 202 } // namespace |
| 156 | 203 |
| 204 // The view that contains a |KeyboardButtonView| and a toggle button. | |
| 205 class ImeListView::MaterialKeyboardStatusRowView : public views::View { | |
| 206 public: | |
| 207 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) | |
| 208 : views::View(), listener_(listener), toggle_(nullptr) { | |
| 209 Init(); | |
| 210 SetKeyboardStatusEnabled(enabled); | |
| 211 } | |
| 212 | |
| 213 ~MaterialKeyboardStatusRowView() override {} | |
| 214 | |
| 215 void SetKeyboardStatusEnabled(bool enabled) { | |
| 216 toggle_->SetIsOn(enabled, true); | |
| 217 } | |
| 218 | |
| 219 const views::Button* toggle() const { return toggle_; } | |
| 220 bool is_toggled() const { return toggle_->is_on(); } | |
| 221 | |
| 222 protected: | |
| 223 // views::View: | |
| 224 gfx::Size GetPreferredSize() const override { | |
| 225 gfx::Size size = views::View::GetPreferredSize(); | |
| 226 size.set_height(kMenuButtonSize + kKeyboardRowkVerticalInset * 2); | |
| 227 return size; | |
| 228 } | |
| 229 | |
| 230 int GetHeightForWidth(int w) const override { | |
| 231 return GetPreferredSize().height(); | |
| 232 } | |
| 233 | |
| 234 private: | |
| 235 void Init() { | |
| 236 SetBorder(views::Border::CreateSolidSidedBorder( | |
| 237 kKeyboardRowSeparatorThickness, 0, 0, 0, kKeyboardRowSeparatorColor)); | |
| 238 views::View* container = new views::View; | |
| 239 container->SetBorder(views::Border::CreateEmptyBorder( | |
| 240 kKeyboardRowkVerticalInset, 0, kKeyboardRowkVerticalInset, 0)); | |
| 241 views::FillLayout* layout = new views::FillLayout; | |
| 242 SetLayoutManager(layout); | |
|
tdanderson
2016/11/01 21:42:11
Instead of adding this layout code and introducing
Azure Wei
2016/11/02 15:01:41
Thanks for the detailed advice of using TriView.
I
| |
| 243 AddChildView(container); | |
| 244 | |
| 245 views::BoxLayout* container_layout = new views::BoxLayout( | |
| 246 views::BoxLayout::kHorizontal, 0, 0, kKeyboardRowChildSpacing); | |
| 247 container_layout->set_cross_axis_alignment( | |
| 248 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 249 container->SetLayoutManager(container_layout); | |
| 250 KeyboardButtonView* keyboard_button_view = new KeyboardButtonView(); | |
| 251 container->AddChildView(keyboard_button_view); | |
| 252 container_layout->SetFlexForView(keyboard_button_view, 1); | |
| 253 | |
| 254 toggle_ = new views::ToggleButton(listener_); | |
| 255 toggle_->SetFocusForPlatform(); | |
| 256 container->AddChildView(toggle_); | |
| 257 } | |
| 258 | |
| 259 // ButtonListener to notify when |toggle_| is clicked. | |
| 260 views::ButtonListener* listener_; | |
| 261 | |
| 262 // ToggleButton to toggle keyboard on or off. | |
| 263 views::ToggleButton* toggle_; | |
| 264 | |
| 265 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | |
| 266 }; | |
| 267 | |
| 157 ImeListView::ImeListView(SystemTrayItem* owner, | 268 ImeListView::ImeListView(SystemTrayItem* owner, |
| 158 bool show_keyboard_toggle, | 269 bool show_keyboard_toggle, |
| 159 SingleImeBehavior single_ime_behavior) | 270 SingleImeBehavior single_ime_behavior) |
| 160 : TrayDetailsView(owner) { | 271 : TrayDetailsView(owner) { |
| 161 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 272 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 162 IMEInfoList list; | 273 IMEInfoList list; |
| 163 delegate->GetAvailableIMEList(&list); | 274 delegate->GetAvailableIMEList(&list); |
| 164 IMEPropertyInfoList property_list; | 275 IMEPropertyInfoList property_list; |
| 165 delegate->GetCurrentIMEProperties(&property_list); | 276 delegate->GetCurrentIMEProperties(&property_list); |
| 166 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 277 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
| 167 } | 278 } |
| 168 | 279 |
| 169 ImeListView::~ImeListView() {} | 280 ImeListView::~ImeListView() {} |
| 170 | 281 |
| 171 void ImeListView::Update(const IMEInfoList& list, | 282 void ImeListView::Update(const IMEInfoList& list, |
| 172 const IMEPropertyInfoList& property_list, | 283 const IMEPropertyInfoList& property_list, |
| 173 bool show_keyboard_toggle, | 284 bool show_keyboard_toggle, |
| 174 SingleImeBehavior single_ime_behavior) { | 285 SingleImeBehavior single_ime_behavior) { |
| 175 Reset(); | 286 Reset(); |
| 287 if (show_keyboard_toggle && | |
| 288 MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 289 AppendMaterialKeyboardStatus(); | |
| 290 } | |
| 291 | |
| 176 ime_map_.clear(); | 292 ime_map_.clear(); |
| 177 property_map_.clear(); | 293 property_map_.clear(); |
| 178 CreateScrollableList(); | 294 CreateScrollableList(); |
| 179 | 295 |
| 180 // Appends IME list and IME properties. | 296 // Appends IME list and IME properties. |
| 181 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { | 297 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { |
| 182 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 298 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 183 AppendImeListAndProperties(list, property_list); | 299 AppendImeListAndProperties(list, property_list); |
| 184 } else { | 300 } else { |
| 185 AppendIMEList(list); | 301 AppendIMEList(list); |
| 186 if (!property_list.empty()) | 302 if (!property_list.empty()) |
| 187 AppendIMEProperties(property_list); | 303 AppendIMEProperties(property_list); |
| 188 } | 304 } |
| 189 } | 305 } |
| 190 | 306 |
| 191 if (show_keyboard_toggle) { | 307 if (show_keyboard_toggle && |
| 308 !MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 192 if (list.size() > 1 || !property_list.empty()) | 309 if (list.size() > 1 || !property_list.empty()) |
| 193 AddScrollSeparator(); | 310 AddScrollSeparator(); |
| 194 AppendKeyboardStatus(); | 311 AppendKeyboardStatus(); |
| 195 } | 312 } |
| 196 | 313 |
| 197 Layout(); | 314 Layout(); |
| 198 SchedulePaint(); | 315 SchedulePaint(); |
| 199 } | 316 } |
| 200 | 317 |
| 201 void ImeListView::AppendIMEList(const IMEInfoList& list) { | 318 void ImeListView::AppendIMEList(const IMEInfoList& list) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 HoverHighlightView* container = new HoverHighlightView(this); | 375 HoverHighlightView* container = new HoverHighlightView(this); |
| 259 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | 376 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD |
| 260 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | 377 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; |
| 261 container->AddLabel( | 378 container->AddLabel( |
| 262 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), | 379 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), |
| 263 gfx::ALIGN_LEFT, false /* highlight */); | 380 gfx::ALIGN_LEFT, false /* highlight */); |
| 264 scroll_content()->AddChildView(container); | 381 scroll_content()->AddChildView(container); |
| 265 keyboard_status_ = container; | 382 keyboard_status_ = container; |
| 266 } | 383 } |
| 267 | 384 |
| 385 void ImeListView::AppendMaterialKeyboardStatus() { | |
| 386 MaterialKeyboardStatusRowView* view = | |
| 387 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); | |
| 388 AddChildView(view); | |
| 389 material_keyboard_statuts_view_ = view; | |
| 390 } | |
| 391 | |
| 268 void ImeListView::HandleViewClicked(views::View* view) { | 392 void ImeListView::HandleViewClicked(views::View* view) { |
| 269 if (view == keyboard_status_) { | 393 if (view == keyboard_status_) { |
| 270 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 394 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 271 return; | 395 return; |
| 272 } | 396 } |
| 273 | 397 |
| 274 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 398 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 275 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 399 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
| 276 if (ime != ime_map_.end()) { | 400 if (ime != ime_map_.end()) { |
| 277 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 401 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
| 278 std::string ime_id = ime->second; | 402 std::string ime_id = ime->second; |
| 279 delegate->SwitchIME(ime_id); | 403 delegate->SwitchIME(ime_id); |
| 280 } else { | 404 } else { |
| 281 std::map<views::View*, std::string>::const_iterator property = | 405 std::map<views::View*, std::string>::const_iterator property = |
| 282 property_map_.find(view); | 406 property_map_.find(view); |
| 283 if (property == property_map_.end()) | 407 if (property == property_map_.end()) |
| 284 return; | 408 return; |
| 285 const std::string key = property->second; | 409 const std::string key = property->second; |
| 286 delegate->ActivateIMEProperty(key); | 410 delegate->ActivateIMEProperty(key); |
| 287 } | 411 } |
| 288 | 412 |
| 289 GetWidget()->Close(); | 413 GetWidget()->Close(); |
| 290 } | 414 } |
| 291 | 415 |
| 416 void ImeListView::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 417 if (material_keyboard_statuts_view_ && | |
| 418 sender == material_keyboard_statuts_view_->toggle() && | |
| 419 material_keyboard_statuts_view_->is_toggled()) { | |
| 420 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | |
| 421 } | |
| 422 } | |
| 423 | |
| 292 } // namespace ash | 424 } // namespace ash |
| OLD | NEW |