| 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" |
| 16 #include "ash/common/system/tray/tray_popup_utils.h" |
| 17 #include "ash/common/system/tray/tri_view.h" |
| 15 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 16 #include "grit/ash_resources.h" | 19 #include "grit/ash_resources.h" |
| 17 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 18 #include "ui/accessibility/ax_node_data.h" | 21 #include "ui/accessibility/ax_node_data.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/color_palette.h" | 24 #include "ui/gfx/color_palette.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 26 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/keyboard/keyboard_util.h" | 27 #include "ui/keyboard/keyboard_util.h" |
| 25 #include "ui/views/border.h" | 28 #include "ui/views/border.h" |
| 26 #include "ui/views/controls/button/label_button.h" | 29 #include "ui/views/controls/button/toggle_button.h" |
| 30 #include "ui/views/controls/image_view.h" |
| 27 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/separator.h" | 32 #include "ui/views/controls/separator.h" |
| 29 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/fill_layout.h" |
| 34 #include "ui/views/painter.h" |
| 35 #include "ui/views/view.h" |
| 30 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 31 | 37 |
| 32 namespace ash { | 38 namespace ash { |
| 33 namespace { | 39 namespace { |
| 34 | 40 |
| 41 const int kKeyboardRowVerticalInset = 4; |
| 42 const int kKeyboardRowSeparatorThickness = 1; |
| 43 const int kMinFontSizeDelta = -10; |
| 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, | 54 kMenuSeparatorVerticalPadding, |
| 43 kMenuExtraMarginFromLeftEdge + kMenuButtonSize, | 55 kMenuExtraMarginFromLeftEdge + kMenuButtonSize, |
| 44 kMenuSeparatorVerticalPadding, 0)); | 56 kMenuSeparatorVerticalPadding, 0)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 67 if (selected_) | 79 if (selected_) |
| 68 node_data->AddStateFlag(ui::AX_STATE_CHECKED); | 80 node_data->AddStateFlag(ui::AX_STATE_CHECKED); |
| 69 } | 81 } |
| 70 | 82 |
| 71 private: | 83 private: |
| 72 bool selected_; | 84 bool selected_; |
| 73 | 85 |
| 74 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); | 86 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); |
| 75 }; | 87 }; |
| 76 | 88 |
| 77 // The view that contains IME short name and the IME label. | |
| 78 class ImeInfoView : public views::View { | |
| 79 public: | |
| 80 ImeInfoView(const base::string16& id, const base::string16& text) { | |
| 81 views::BoxLayout* box_layout = | |
| 82 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 83 SetLayoutManager(box_layout); | |
| 84 | |
| 85 // TODO(azurewei): Use TrayPopupItemStyle for |id_button|. | |
| 86 views::LabelButton* id_button = new views::LabelButton(nullptr, id); | |
| 87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 88 id_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumBoldFont)); | |
| 89 id_button->SetTextColor(views::Button::STATE_NORMAL, kMenuIconColor); | |
| 90 id_button->SetMaxSize(gfx::Size(kMenuButtonSize, kMenuButtonSize)); | |
| 91 id_button->SetMinSize(gfx::Size(kMenuButtonSize, kMenuButtonSize)); | |
| 92 const int button_padding = (kMenuButtonSize - kMenuIconSize) / 2; | |
| 93 id_button->SetBorder(views::Border::CreateEmptyBorder( | |
| 94 button_padding, button_padding, button_padding, button_padding)); | |
| 95 AddChildView(id_button); | |
| 96 | |
| 97 views::Label* text_label = new views::Label(text); | |
| 98 TrayPopupItemStyle style( | |
| 99 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 100 style.SetupLabel(text_label); | |
| 101 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 102 box_layout->set_cross_axis_alignment( | |
| 103 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 104 AddChildView(text_label); | |
| 105 box_layout->SetFlexForView(text_label, 1); | |
| 106 } | |
| 107 | |
| 108 private: | |
| 109 DISALLOW_COPY_AND_ASSIGN(ImeInfoView); | |
| 110 }; | |
| 111 | |
| 112 // The IME list item view used in the material design. It contains IME info | 89 // The IME list item view used in the material design. It contains IME info |
| 113 // (name and label) and a check button if the item is selected. It's also used | 90 // (name and label) and a check button if the item is selected. It's also used |
| 114 // for IME property item, which has no name but label and a gray checked icon. | 91 // for IME property item, which has no name but label and a gray checked icon. |
| 115 class ImeListItemView : public ActionableView { | 92 class ImeListItemView : public ActionableView { |
| 116 public: | 93 public: |
| 117 ImeListItemView(SystemTrayItem* owner, | 94 ImeListItemView(SystemTrayItem* owner, |
| 118 ImeListView* list_view, | 95 ImeListView* list_view, |
| 119 const base::string16& id, | 96 const base::string16& id, |
| 120 const base::string16& label, | 97 const base::string16& label, |
| 121 bool selected, | 98 bool selected, |
| 122 const SkColor button_color) | 99 const SkColor button_color) |
| 123 : ActionableView(owner), ime_list_view_(list_view) { | 100 : ActionableView(owner), ime_list_view_(list_view) { |
| 124 views::BoxLayout* box_layout = | 101 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
| 125 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 102 AddChildView(tri_view); |
| 126 SetLayoutManager(box_layout); | 103 SetLayoutManager(new views::FillLayout); |
| 127 | 104 |
| 128 ImeInfoView* info_view = new ImeInfoView(id, label); | 105 // The id button shows the IME short name. |
| 129 AddChildView(info_view); | 106 views::Label* id_label = new views::Label(id); |
| 130 box_layout->SetFlexForView(info_view, 1); | 107 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 108 const gfx::FontList& base_font_list = |
| 109 rb.GetFontList(ui::ResourceBundle::MediumBoldFont); |
| 110 id_label->SetFontList(base_font_list); |
| 111 |
| 112 // For IMEs whose short name are more than 2 characters (INTL, EXTD, etc.), |
| 113 // |kMenuIconSize| is not enough. The label will trigger eliding as "I..." |
| 114 // or "...". So we shrink the font size until it fits within the bounds. |
| 115 int size_delta = -1; |
| 116 while (id_label->GetPreferredSize().width() > kMenuIconSize && |
| 117 size_delta >= kMinFontSizeDelta) { |
| 118 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_delta)); |
| 119 --size_delta; |
| 120 } |
| 121 tri_view->AddView(TriView::Container::START, id_label); |
| 122 |
| 123 // The label shows the IME name. |
| 124 label_ = new views::Label(label); |
| 125 UpdateStyle(); |
| 126 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 127 tri_view->AddView(TriView::Container::CENTER, label_); |
| 131 | 128 |
| 132 if (selected) { | 129 if (selected) { |
| 133 views::ImageButton* check_button = new views::ImageButton(nullptr); | 130 // The checked button indicates the IME is selected. |
| 134 gfx::ImageSkia icon_image = gfx::CreateVectorIcon( | 131 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView(); |
| 135 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color); | 132 checked_image->SetImage(gfx::CreateVectorIcon( |
| 136 check_button->SetImage(views::CustomButton::STATE_NORMAL, &icon_image); | 133 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); |
| 137 const int button_padding = (kMenuButtonSize - icon_image.width()) / 2; | 134 tri_view->AddView(TriView::Container::END, checked_image); |
| 138 check_button->SetBorder(views::Border::CreateEmptyBorder( | |
| 139 button_padding, button_padding, button_padding, button_padding)); | |
| 140 AddChildView(check_button); | |
| 141 } | 135 } |
| 142 } | 136 } |
| 143 | 137 |
| 144 ~ImeListItemView() override {} | 138 ~ImeListItemView() override {} |
| 145 | 139 |
| 146 // ActionableView: | 140 // ActionableView: |
| 147 bool PerformAction(const ui::Event& event) override { | 141 bool PerformAction(const ui::Event& event) override { |
| 148 ime_list_view_->HandleViewClicked(this); | 142 ime_list_view_->HandleViewClicked(this); |
| 149 return true; | 143 return true; |
| 150 } | 144 } |
| 151 | 145 |
| 146 // views::View: |
| 147 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 148 UpdateStyle(); |
| 149 } |
| 150 |
| 152 private: | 151 private: |
| 152 // Updates the style of |label_| based on the current native theme. |
| 153 void UpdateStyle() { |
| 154 TrayPopupItemStyle style( |
| 155 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 156 style.SetupLabel(label_); |
| 157 } |
| 158 |
| 159 // The label shows the IME name. |
| 160 views::Label* label_; |
| 161 |
| 153 ImeListView* ime_list_view_; | 162 ImeListView* ime_list_view_; |
| 154 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); | 163 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); |
| 155 }; | 164 }; |
| 156 | 165 |
| 157 } // namespace | 166 } // namespace |
| 158 | 167 |
| 168 // The view that contains a |KeyboardButtonView| and a toggle button. |
| 169 class MaterialKeyboardStatusRowView : public views::View { |
| 170 public: |
| 171 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) |
| 172 : listener_(listener), label_(nullptr), toggle_(nullptr) { |
| 173 Init(); |
| 174 SetKeyboardStatusEnabled(enabled); |
| 175 } |
| 176 |
| 177 ~MaterialKeyboardStatusRowView() override {} |
| 178 |
| 179 void SetKeyboardStatusEnabled(bool enabled) { |
| 180 toggle_->SetIsOn(enabled, true); |
| 181 } |
| 182 |
| 183 const views::Button* toggle() const { return toggle_; } |
| 184 bool is_toggled() const { return toggle_->is_on(); } |
| 185 |
| 186 protected: |
| 187 // views::View: |
| 188 gfx::Size GetPreferredSize() const override { |
| 189 gfx::Size size = views::View::GetPreferredSize(); |
| 190 size.set_height(kMenuButtonSize + kKeyboardRowVerticalInset * 2); |
| 191 return size; |
| 192 } |
| 193 |
| 194 int GetHeightForWidth(int w) const override { |
| 195 return GetPreferredSize().height(); |
| 196 } |
| 197 |
| 198 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 199 UpdateStyle(); |
| 200 } |
| 201 |
| 202 private: |
| 203 void Init() { |
| 204 SetBorder(views::Border::CreateSolidSidedBorder( |
| 205 kKeyboardRowSeparatorThickness, 0, 0, 0, kKeyboardRowSeparatorColor)); |
| 206 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
| 207 AddChildView(tri_view); |
| 208 SetLayoutManager(new views::FillLayout); |
| 209 |
| 210 // The on-screen keyboard image button. |
| 211 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); |
| 212 keyboard_image->SetImage(gfx::CreateVectorIcon( |
| 213 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); |
| 214 tri_view->AddView(TriView::Container::START, keyboard_image); |
| 215 |
| 216 // The on-screen keyboard label. |
| 217 label_ = new views::Label( |
| 218 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 219 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); |
| 220 UpdateStyle(); |
| 221 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 222 tri_view->AddView(TriView::Container::CENTER, label_); |
| 223 |
| 224 // The on-screen keyboard toggle button. |
| 225 toggle_ = new views::ToggleButton(listener_); |
| 226 toggle_->SetFocusForPlatform(); |
| 227 toggle_->SetTooltipText( |
| 228 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 229 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); |
| 230 tri_view->AddView(TriView::Container::END, toggle_); |
| 231 } |
| 232 |
| 233 // Updates the style of |label_| based on the current native theme. |
| 234 void UpdateStyle() { |
| 235 TrayPopupItemStyle style( |
| 236 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 237 style.SetupLabel(label_); |
| 238 } |
| 239 |
| 240 // ButtonListener to notify when |toggle_| is clicked. |
| 241 views::ButtonListener* listener_; |
| 242 |
| 243 // Label to with text 'On-screen keyboard'. |
| 244 views::Label* label_; |
| 245 |
| 246 // ToggleButton to toggle keyboard on or off. |
| 247 views::ToggleButton* toggle_; |
| 248 |
| 249 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); |
| 250 }; |
| 251 |
| 159 ImeListView::ImeListView(SystemTrayItem* owner, | 252 ImeListView::ImeListView(SystemTrayItem* owner, |
| 160 bool show_keyboard_toggle, | 253 bool show_keyboard_toggle, |
| 161 SingleImeBehavior single_ime_behavior) | 254 SingleImeBehavior single_ime_behavior) |
| 162 : TrayDetailsView(owner) { | 255 : TrayDetailsView(owner) { |
| 163 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 256 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 164 IMEInfoList list; | 257 IMEInfoList list; |
| 165 delegate->GetAvailableIMEList(&list); | 258 delegate->GetAvailableIMEList(&list); |
| 166 IMEPropertyInfoList property_list; | 259 IMEPropertyInfoList property_list; |
| 167 delegate->GetCurrentIMEProperties(&property_list); | 260 delegate->GetCurrentIMEProperties(&property_list); |
| 168 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 261 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
| 169 } | 262 } |
| 170 | 263 |
| 171 ImeListView::~ImeListView() {} | 264 ImeListView::~ImeListView() {} |
| 172 | 265 |
| 173 void ImeListView::Update(const IMEInfoList& list, | 266 void ImeListView::Update(const IMEInfoList& list, |
| 174 const IMEPropertyInfoList& property_list, | 267 const IMEPropertyInfoList& property_list, |
| 175 bool show_keyboard_toggle, | 268 bool show_keyboard_toggle, |
| 176 SingleImeBehavior single_ime_behavior) { | 269 SingleImeBehavior single_ime_behavior) { |
| 177 Reset(); | 270 ResetImeListView(); |
| 271 if (show_keyboard_toggle && |
| 272 MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 273 AppendMaterialKeyboardStatus(); |
| 274 } |
| 275 |
| 178 ime_map_.clear(); | 276 ime_map_.clear(); |
| 179 property_map_.clear(); | 277 property_map_.clear(); |
| 180 CreateScrollableList(); | 278 CreateScrollableList(); |
| 181 | 279 |
| 182 // Appends IME list and IME properties. | 280 // Appends IME list and IME properties. |
| 183 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { | 281 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { |
| 184 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 282 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 185 AppendImeListAndProperties(list, property_list); | 283 AppendImeListAndProperties(list, property_list); |
| 186 } else { | 284 } else { |
| 187 AppendIMEList(list); | 285 AppendIMEList(list); |
| 188 if (!property_list.empty()) | 286 if (!property_list.empty()) |
| 189 AppendIMEProperties(property_list); | 287 AppendIMEProperties(property_list); |
| 190 } | 288 } |
| 191 } | 289 } |
| 192 | 290 |
| 193 if (show_keyboard_toggle) { | 291 if (show_keyboard_toggle && |
| 292 !MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 194 if (list.size() > 1 || !property_list.empty()) | 293 if (list.size() > 1 || !property_list.empty()) |
| 195 AddScrollSeparator(); | 294 AddScrollSeparator(); |
| 196 AppendKeyboardStatus(); | 295 AppendKeyboardStatus(); |
| 197 } | 296 } |
| 198 | 297 |
| 199 Layout(); | 298 Layout(); |
| 200 SchedulePaint(); | 299 SchedulePaint(); |
| 201 } | 300 } |
| 202 | 301 |
| 302 void ImeListView::ResetImeListView() { |
| 303 // Children are removed from the view hierarchy and deleted in Reset(). |
| 304 Reset(); |
| 305 material_keyboard_statuts_view_ = nullptr; |
| 306 keyboard_status_ = nullptr; |
| 307 } |
| 308 |
| 203 void ImeListView::AppendIMEList(const IMEInfoList& list) { | 309 void ImeListView::AppendIMEList(const IMEInfoList& list) { |
| 204 DCHECK(ime_map_.empty()); | 310 DCHECK(ime_map_.empty()); |
| 205 for (size_t i = 0; i < list.size(); i++) { | 311 for (size_t i = 0; i < list.size(); i++) { |
| 206 HoverHighlightView* container = | 312 HoverHighlightView* container = |
| 207 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); | 313 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); |
| 208 scroll_content()->AddChildView(container); | 314 scroll_content()->AddChildView(container); |
| 209 ime_map_[container] = list[i].id; | 315 ime_map_[container] = list[i].id; |
| 210 } | 316 } |
| 211 } | 317 } |
| 212 | 318 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 358 |
| 253 // Adds a separator on the bottom of property items if there are still | 359 // Adds a separator on the bottom of property items if there are still |
| 254 // other IMEs under the current one. | 360 // other IMEs under the current one. |
| 255 if (i < list.size() - 1) | 361 if (i < list.size() - 1) |
| 256 scroll_content()->AddChildView(CreateListItemSeparator()); | 362 scroll_content()->AddChildView(CreateListItemSeparator()); |
| 257 } | 363 } |
| 258 } | 364 } |
| 259 } | 365 } |
| 260 | 366 |
| 261 void ImeListView::AppendKeyboardStatus() { | 367 void ImeListView::AppendKeyboardStatus() { |
| 368 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial()); |
| 262 HoverHighlightView* container = new HoverHighlightView(this); | 369 HoverHighlightView* container = new HoverHighlightView(this); |
| 263 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | 370 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD |
| 264 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | 371 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; |
| 265 container->AddLabel( | 372 container->AddLabel( |
| 266 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), | 373 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), |
| 267 gfx::ALIGN_LEFT, false /* highlight */); | 374 gfx::ALIGN_LEFT, false /* highlight */); |
| 268 scroll_content()->AddChildView(container); | 375 scroll_content()->AddChildView(container); |
| 269 keyboard_status_ = container; | 376 keyboard_status_ = container; |
| 270 } | 377 } |
| 271 | 378 |
| 379 void ImeListView::AppendMaterialKeyboardStatus() { |
| 380 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial()); |
| 381 if (material_keyboard_statuts_view_) |
| 382 return; |
| 383 MaterialKeyboardStatusRowView* view = |
| 384 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); |
| 385 view->SetKeyboardStatusEnabled(keyboard::IsKeyboardEnabled()); |
| 386 AddChildView(view); |
| 387 material_keyboard_statuts_view_ = view; |
| 388 } |
| 389 |
| 272 void ImeListView::HandleViewClicked(views::View* view) { | 390 void ImeListView::HandleViewClicked(views::View* view) { |
| 273 if (view == keyboard_status_) { | 391 if (view == keyboard_status_) { |
| 274 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 392 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 275 return; | 393 return; |
| 276 } | 394 } |
| 277 | 395 |
| 278 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 396 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 279 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 397 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
| 280 if (ime != ime_map_.end()) { | 398 if (ime != ime_map_.end()) { |
| 281 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 399 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
| 282 std::string ime_id = ime->second; | 400 std::string ime_id = ime->second; |
| 283 delegate->SwitchIME(ime_id); | 401 delegate->SwitchIME(ime_id); |
| 284 } else { | 402 } else { |
| 285 std::map<views::View*, std::string>::const_iterator property = | 403 std::map<views::View*, std::string>::const_iterator property = |
| 286 property_map_.find(view); | 404 property_map_.find(view); |
| 287 if (property == property_map_.end()) | 405 if (property == property_map_.end()) |
| 288 return; | 406 return; |
| 289 const std::string key = property->second; | 407 const std::string key = property->second; |
| 290 delegate->ActivateIMEProperty(key); | 408 delegate->ActivateIMEProperty(key); |
| 291 } | 409 } |
| 292 | 410 |
| 293 GetWidget()->Close(); | 411 GetWidget()->Close(); |
| 294 } | 412 } |
| 295 | 413 |
| 414 void ImeListView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 415 if (material_keyboard_statuts_view_ && |
| 416 sender == material_keyboard_statuts_view_->toggle()) { |
| 417 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 418 } |
| 419 } |
| 420 |
| 296 } // namespace ash | 421 } // namespace ash |
| OLD | NEW |