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" |
| 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_view_state.h" | 21 #include "ui/accessibility/ax_view_state.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 kKeyboardRowkVerticalInset = 4; | |
|
tdanderson
2016/11/03 21:17:06
nit: 'kKeyboardRowVerticalInset' instead of 'kKeyb
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 42 const int kKeyboardRowSeparatorThickness = 1; | |
| 43 // const int kFocusBorderInset = 1; | |
|
tdanderson
2016/11/03 21:17:06
Don't forget to delete this line if it's no longer
Azure Wei
2016/11/04 01:28:34
Done. Sorry about the silly mistake.
| |
| 44 const int kMaxReduceFontSize = -10; | |
|
tdanderson
2016/11/03 21:17:05
nit: I would instead call this something with 'min
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 45 | |
| 46 const SkColor kKeyboardRowSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F); | |
| 47 | |
| 35 // Creates a separator that will be used between the IME list items. | 48 // Creates a separator that will be used between the IME list items. |
| 36 views::Separator* CreateListItemSeparator() { | 49 views::Separator* CreateListItemSeparator() { |
| 37 views::Separator* separator = | 50 views::Separator* separator = |
| 38 new views::Separator(views::Separator::HORIZONTAL); | 51 new views::Separator(views::Separator::HORIZONTAL); |
| 39 separator->SetColor(kBorderLightColor); | 52 separator->SetColor(kBorderLightColor); |
| 40 separator->SetPreferredSize(kSeparatorWidth); | 53 separator->SetPreferredSize(kSeparatorWidth); |
| 41 separator->SetBorder(views::Border::CreateEmptyBorder( | 54 separator->SetBorder(views::Border::CreateEmptyBorder( |
| 42 kMenuSeparatorVerticalPadding, 0, kMenuSeparatorVerticalPadding, 0)); | 55 kMenuSeparatorVerticalPadding, 0, kMenuSeparatorVerticalPadding, 0)); |
| 43 return separator; | 56 return separator; |
| 44 } | 57 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 65 if (selected_) | 78 if (selected_) |
| 66 state->AddStateFlag(ui::AX_STATE_CHECKED); | 79 state->AddStateFlag(ui::AX_STATE_CHECKED); |
| 67 } | 80 } |
| 68 | 81 |
| 69 private: | 82 private: |
| 70 bool selected_; | 83 bool selected_; |
| 71 | 84 |
| 72 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); | 85 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); |
| 73 }; | 86 }; |
| 74 | 87 |
| 75 // The view that contains IME short name and the IME label. | |
| 76 class ImeInfoView : public views::View { | |
| 77 public: | |
| 78 ImeInfoView(const base::string16& id, const base::string16& text) { | |
| 79 views::BoxLayout* box_layout = | |
| 80 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 81 SetLayoutManager(box_layout); | |
| 82 | |
| 83 // TODO(azurewei): Use TrayPopupItemStyle for |id_button|. | |
| 84 views::LabelButton* id_button = new views::LabelButton(nullptr, id); | |
| 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 86 id_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumBoldFont)); | |
| 87 id_button->SetTextColor(views::Button::STATE_NORMAL, kMenuIconColor); | |
| 88 id_button->SetMaxSize(gfx::Size(kMenuButtonSize, kMenuButtonSize)); | |
| 89 id_button->SetMinSize(gfx::Size(kMenuButtonSize, kMenuButtonSize)); | |
| 90 const int button_padding = (kMenuButtonSize - kMenuIconSize) / 2; | |
| 91 id_button->SetBorder(views::Border::CreateEmptyBorder( | |
| 92 button_padding, button_padding, button_padding, button_padding)); | |
| 93 AddChildView(id_button); | |
| 94 | |
| 95 views::Label* text_label = new views::Label(text); | |
| 96 TrayPopupItemStyle style( | |
| 97 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 98 style.SetupLabel(text_label); | |
| 99 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 100 box_layout->set_cross_axis_alignment( | |
| 101 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 102 AddChildView(text_label); | |
| 103 box_layout->SetFlexForView(text_label, 1); | |
| 104 } | |
| 105 | |
| 106 private: | |
| 107 DISALLOW_COPY_AND_ASSIGN(ImeInfoView); | |
| 108 }; | |
| 109 | |
| 110 // The IME list item view used in the material design. It contains IME info | 88 // The IME list item view used in the material design. It contains IME info |
| 111 // (name and label) and a check button if the item is selected. It's also used | 89 // (name and label) and a check button if the item is selected. It's also used |
| 112 // for IME property item, which has no name but label and a gray checked icon. | 90 // for IME property item, which has no name but label and a gray checked icon. |
| 113 class ImeListItemView : public ActionableView { | 91 class ImeListItemView : public ActionableView { |
| 114 public: | 92 public: |
| 115 ImeListItemView(SystemTrayItem* owner, | 93 ImeListItemView(SystemTrayItem* owner, |
| 116 ImeListView* list_view, | 94 ImeListView* list_view, |
| 117 const base::string16& id, | 95 const base::string16& id, |
| 118 const base::string16& label, | 96 const base::string16& label, |
| 119 bool selected, | 97 bool selected, |
| 120 const SkColor button_color) | 98 const SkColor button_color) |
| 121 : ActionableView(owner), ime_list_view_(list_view) { | 99 : ActionableView(owner), ime_list_view_(list_view) { |
| 122 views::BoxLayout* box_layout = | 100 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
| 123 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 101 AddChildView(tri_view); |
| 124 SetLayoutManager(box_layout); | 102 SetLayoutManager(new views::FillLayout); |
| 125 | 103 |
| 126 ImeInfoView* info_view = new ImeInfoView(id, label); | 104 // The id button shows the IME short name. |
| 127 AddChildView(info_view); | 105 views::Label* id_label = new views::Label(id); |
| 128 box_layout->SetFlexForView(info_view, 1); | 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 107 const gfx::FontList& base_font_list = | |
| 108 rb.GetFontList(ui::ResourceBundle::MediumBoldFont); | |
| 109 id_label->SetFontList(base_font_list); | |
| 110 id_label->SizeToFit(kMenuIconSize); | |
| 111 id_label->SetMaximumWidth(kMenuIconSize); | |
| 112 int size_deta = -1; | |
|
tdanderson
2016/11/03 21:17:05
nit: 'size_delta' instead of 'size_deta'
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 113 while (id_label->GetPreferredSize().width() > kMenuIconSize) { | |
|
tdanderson
2016/11/03 21:17:05
nit: please include a comment to explain what you'
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 114 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_deta)); | |
| 115 --size_deta; | |
| 116 // In case we don't run into endless loop. | |
| 117 if (size_deta < kMaxReduceFontSize) | |
|
tdanderson
2016/11/03 21:17:06
Instead of this break, can you instead just put it
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 118 break; | |
| 119 } | |
| 120 tri_view->AddView(TriView::Container::START, id_label); | |
| 121 | |
| 122 // The label shows the IME name. | |
| 123 views::Label* text_label = new views::Label(label); | |
| 124 TrayPopupItemStyle style( | |
| 125 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 126 style.SetupLabel(text_label); | |
| 127 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 128 tri_view->AddView(TriView::Container::CENTER, text_label); | |
| 129 | 129 |
| 130 if (selected) { | 130 if (selected) { |
| 131 views::ImageButton* check_button = new views::ImageButton(nullptr); | 131 // The checked button indicates the IME is selected. |
| 132 gfx::ImageSkia icon_image = gfx::CreateVectorIcon( | 132 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView(); |
| 133 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color); | 133 checked_image->SetImage(gfx::CreateVectorIcon( |
| 134 check_button->SetImage(views::CustomButton::STATE_NORMAL, &icon_image); | 134 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); |
| 135 const int button_padding = (kMenuButtonSize - icon_image.width()) / 2; | 135 tri_view->AddView(TriView::Container::END, checked_image); |
| 136 check_button->SetBorder(views::Border::CreateEmptyBorder( | |
| 137 button_padding, button_padding, button_padding, button_padding)); | |
| 138 AddChildView(check_button); | |
| 139 } | 136 } |
| 140 } | 137 } |
| 141 | 138 |
| 142 ~ImeListItemView() override {} | 139 ~ImeListItemView() override {} |
| 143 | 140 |
| 144 // ActionableView: | 141 // ActionableView: |
| 145 bool PerformAction(const ui::Event& event) override { | 142 bool PerformAction(const ui::Event& event) override { |
| 146 ime_list_view_->HandleViewClicked(this); | 143 ime_list_view_->HandleViewClicked(this); |
| 147 return true; | 144 return true; |
| 148 } | 145 } |
| 149 | 146 |
| 150 private: | 147 private: |
| 151 ImeListView* ime_list_view_; | 148 ImeListView* ime_list_view_; |
| 152 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); | 149 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); |
| 153 }; | 150 }; |
| 154 | 151 |
| 155 } // namespace | 152 } // namespace |
| 156 | 153 |
| 154 // The view that contains a |KeyboardButtonView| and a toggle button. | |
| 155 class ImeListView::MaterialKeyboardStatusRowView : public views::View { | |
| 156 public: | |
| 157 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) | |
| 158 : views::View(), listener_(listener), toggle_(nullptr) { | |
|
tdanderson
2016/11/03 21:17:06
I don't know if you need the call up to views::Vie
Azure Wei
2016/11/04 01:28:34
Should be unnecessary. Removed.
| |
| 159 Init(); | |
| 160 SetKeyboardStatusEnabled(enabled); | |
| 161 } | |
| 162 | |
| 163 ~MaterialKeyboardStatusRowView() override {} | |
| 164 | |
| 165 void SetKeyboardStatusEnabled(bool enabled) { | |
| 166 toggle_->SetIsOn(enabled, true); | |
| 167 SetKeyboardToggleText(); | |
| 168 } | |
| 169 | |
| 170 void SetKeyboardToggleText() { | |
| 171 toggle_->SetTooltipText( | |
| 172 toggle_->is_on() | |
| 173 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD) | |
|
tdanderson
2016/11/03 21:17:06
This is fine to land, but FYI we will eventually w
Azure Wei
2016/11/04 01:28:34
The 'on/off switch' will be automatically appended
tdanderson
2016/11/04 19:01:04
Yes, that's right. The change actually just landed
| |
| 174 : l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD)); | |
| 175 } | |
| 176 | |
| 177 const views::Button* toggle() const { return toggle_; } | |
| 178 bool is_toggled() const { return toggle_->is_on(); } | |
| 179 | |
| 180 protected: | |
| 181 // views::View: | |
| 182 gfx::Size GetPreferredSize() const override { | |
| 183 gfx::Size size = views::View::GetPreferredSize(); | |
| 184 size.set_height(kMenuButtonSize + kKeyboardRowkVerticalInset * 2); | |
| 185 return size; | |
| 186 } | |
| 187 | |
| 188 int GetHeightForWidth(int w) const override { | |
| 189 return GetPreferredSize().height(); | |
| 190 } | |
| 191 | |
| 192 private: | |
| 193 void Init() { | |
| 194 SetBorder(views::Border::CreateSolidSidedBorder( | |
| 195 kKeyboardRowSeparatorThickness, 0, 0, 0, kKeyboardRowSeparatorColor)); | |
| 196 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | |
| 197 AddChildView(tri_view); | |
| 198 SetLayoutManager(new views::FillLayout); | |
| 199 | |
| 200 // The on-screen keyboard image button. | |
| 201 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); | |
| 202 keyboard_image->SetImage(gfx::CreateVectorIcon( | |
| 203 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); | |
| 204 tri_view->AddView(TriView::Container::START, keyboard_image); | |
| 205 | |
| 206 // The on-screen keyboard label. | |
| 207 views::Label* label = new views::Label( | |
| 208 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 209 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); | |
| 210 TrayPopupItemStyle style( | |
|
tdanderson
2016/11/03 21:17:05
Sorry, I should have mentioned something in a prev
Azure Wei
2016/11/04 01:28:34
Updated this and lines 124-126 by using UpdateStyl
| |
| 211 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 212 style.SetupLabel(label); | |
| 213 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 214 tri_view->AddView(TriView::Container::CENTER, label); | |
| 215 | |
| 216 // The on-screen keyboard toggle button. | |
| 217 toggle_ = new views::ToggleButton(listener_); | |
| 218 toggle_->SetFocusForPlatform(); | |
| 219 toggle_->SetTooltipText( | |
|
tdanderson
2016/11/03 21:17:05
I think you want to call into SetKeyboardToggleTex
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 220 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD)); | |
| 221 tri_view->AddView(TriView::Container::END, toggle_); | |
| 222 } | |
| 223 | |
| 224 // ButtonListener to notify when |toggle_| is clicked. | |
| 225 views::ButtonListener* listener_; | |
| 226 | |
| 227 // ToggleButton to toggle keyboard on or off. | |
| 228 views::ToggleButton* toggle_; | |
| 229 | |
| 230 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | |
| 231 }; | |
| 232 | |
| 157 ImeListView::ImeListView(SystemTrayItem* owner, | 233 ImeListView::ImeListView(SystemTrayItem* owner, |
| 158 bool show_keyboard_toggle, | 234 bool show_keyboard_toggle, |
| 159 SingleImeBehavior single_ime_behavior) | 235 SingleImeBehavior single_ime_behavior) |
| 160 : TrayDetailsView(owner) { | 236 : TrayDetailsView(owner) { |
| 161 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 237 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 162 IMEInfoList list; | 238 IMEInfoList list; |
| 163 delegate->GetAvailableIMEList(&list); | 239 delegate->GetAvailableIMEList(&list); |
| 164 IMEPropertyInfoList property_list; | 240 IMEPropertyInfoList property_list; |
| 165 delegate->GetCurrentIMEProperties(&property_list); | 241 delegate->GetCurrentIMEProperties(&property_list); |
| 166 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 242 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
| 167 } | 243 } |
| 168 | 244 |
| 169 ImeListView::~ImeListView() {} | 245 ImeListView::~ImeListView() { |
| 246 material_keyboard_statuts_view_ = nullptr; | |
| 247 keyboard_status_ = nullptr; | |
|
tdanderson
2016/11/03 21:17:06
Can you clarify why you are setting these to null
Azure Wei
2016/11/04 01:28:34
Nulling the two items are only needed in ResetImeL
| |
| 248 } | |
| 170 | 249 |
| 171 void ImeListView::Update(const IMEInfoList& list, | 250 void ImeListView::Update(const IMEInfoList& list, |
| 172 const IMEPropertyInfoList& property_list, | 251 const IMEPropertyInfoList& property_list, |
| 173 bool show_keyboard_toggle, | 252 bool show_keyboard_toggle, |
| 174 SingleImeBehavior single_ime_behavior) { | 253 SingleImeBehavior single_ime_behavior) { |
| 175 Reset(); | 254 ResetImeListView(); |
| 255 if (show_keyboard_toggle && | |
| 256 MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 257 AppendMaterialKeyboardStatus(); | |
| 258 } | |
| 259 | |
| 176 ime_map_.clear(); | 260 ime_map_.clear(); |
| 177 property_map_.clear(); | 261 property_map_.clear(); |
| 178 CreateScrollableList(); | 262 CreateScrollableList(); |
| 179 | 263 |
| 180 // Appends IME list and IME properties. | 264 // Appends IME list and IME properties. |
| 181 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { | 265 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { |
| 182 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 266 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 183 AppendImeListAndProperties(list, property_list); | 267 AppendImeListAndProperties(list, property_list); |
| 184 } else { | 268 } else { |
| 185 AppendIMEList(list); | 269 AppendIMEList(list); |
| 186 if (!property_list.empty()) | 270 if (!property_list.empty()) |
| 187 AppendIMEProperties(property_list); | 271 AppendIMEProperties(property_list); |
| 188 } | 272 } |
| 189 } | 273 } |
| 190 | 274 |
| 191 if (show_keyboard_toggle) { | 275 if (show_keyboard_toggle && |
| 276 !MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 192 if (list.size() > 1 || !property_list.empty()) | 277 if (list.size() > 1 || !property_list.empty()) |
| 193 AddScrollSeparator(); | 278 AddScrollSeparator(); |
| 194 AppendKeyboardStatus(); | 279 AppendKeyboardStatus(); |
|
tdanderson
2016/11/03 21:17:05
Can you add a DCHECK at the top of AppendKeyboardS
Azure Wei
2016/11/04 01:28:34
Done.
The previous change should be bug. Shouldn't
| |
| 195 } | 280 } |
| 196 | 281 |
| 197 Layout(); | 282 Layout(); |
| 198 SchedulePaint(); | 283 SchedulePaint(); |
| 199 } | 284 } |
| 200 | 285 |
| 286 void ImeListView::ResetImeListView() { | |
| 287 Reset(); | |
| 288 material_keyboard_statuts_view_ = nullptr; | |
|
tdanderson
2016/11/03 21:17:05
optional nit: When I first saw this it seemed as t
Azure Wei
2016/11/04 01:28:33
Done.
| |
| 289 keyboard_status_ = nullptr; | |
| 290 } | |
| 291 | |
| 201 void ImeListView::AppendIMEList(const IMEInfoList& list) { | 292 void ImeListView::AppendIMEList(const IMEInfoList& list) { |
| 202 DCHECK(ime_map_.empty()); | 293 DCHECK(ime_map_.empty()); |
| 203 for (size_t i = 0; i < list.size(); i++) { | 294 for (size_t i = 0; i < list.size(); i++) { |
| 204 HoverHighlightView* container = | 295 HoverHighlightView* container = |
| 205 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); | 296 new SelectableHoverHighlightView(this, list[i].name, list[i].selected); |
| 206 scroll_content()->AddChildView(container); | 297 scroll_content()->AddChildView(container); |
| 207 ime_map_[container] = list[i].id; | 298 ime_map_[container] = list[i].id; |
| 208 } | 299 } |
| 209 } | 300 } |
| 210 | 301 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 HoverHighlightView* container = new HoverHighlightView(this); | 349 HoverHighlightView* container = new HoverHighlightView(this); |
| 259 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | 350 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD |
| 260 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | 351 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; |
| 261 container->AddLabel( | 352 container->AddLabel( |
| 262 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), | 353 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), |
| 263 gfx::ALIGN_LEFT, false /* highlight */); | 354 gfx::ALIGN_LEFT, false /* highlight */); |
| 264 scroll_content()->AddChildView(container); | 355 scroll_content()->AddChildView(container); |
| 265 keyboard_status_ = container; | 356 keyboard_status_ = container; |
| 266 } | 357 } |
| 267 | 358 |
| 359 void ImeListView::AppendMaterialKeyboardStatus() { | |
|
tdanderson
2016/11/03 21:17:05
Can you add a DCHECK at the top of this function t
Azure Wei
2016/11/04 01:28:34
Done.
| |
| 360 if (material_keyboard_statuts_view_) | |
| 361 return; | |
| 362 MaterialKeyboardStatusRowView* view = | |
| 363 new MaterialKeyboardStatusRowView(this, keyboard::IsKeyboardEnabled()); | |
| 364 view->SetKeyboardStatusEnabled(keyboard::IsKeyboardEnabled()); | |
| 365 AddChildView(view); | |
| 366 material_keyboard_statuts_view_ = view; | |
| 367 } | |
| 368 | |
| 268 void ImeListView::HandleViewClicked(views::View* view) { | 369 void ImeListView::HandleViewClicked(views::View* view) { |
| 269 if (view == keyboard_status_) { | 370 if (view == keyboard_status_) { |
| 270 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 371 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 271 return; | 372 return; |
| 272 } | 373 } |
| 273 | 374 |
| 274 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 375 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 275 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 376 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
| 276 if (ime != ime_map_.end()) { | 377 if (ime != ime_map_.end()) { |
| 277 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 378 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
| 278 std::string ime_id = ime->second; | 379 std::string ime_id = ime->second; |
| 279 delegate->SwitchIME(ime_id); | 380 delegate->SwitchIME(ime_id); |
| 280 } else { | 381 } else { |
| 281 std::map<views::View*, std::string>::const_iterator property = | 382 std::map<views::View*, std::string>::const_iterator property = |
| 282 property_map_.find(view); | 383 property_map_.find(view); |
| 283 if (property == property_map_.end()) | 384 if (property == property_map_.end()) |
| 284 return; | 385 return; |
| 285 const std::string key = property->second; | 386 const std::string key = property->second; |
| 286 delegate->ActivateIMEProperty(key); | 387 delegate->ActivateIMEProperty(key); |
| 287 } | 388 } |
| 288 | 389 |
| 289 GetWidget()->Close(); | 390 GetWidget()->Close(); |
| 290 } | 391 } |
| 291 | 392 |
| 393 void ImeListView::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 394 if (material_keyboard_statuts_view_ && | |
| 395 sender == material_keyboard_statuts_view_->toggle()) { | |
| 396 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | |
| 397 // Set the toggle's a11y text. | |
| 398 material_keyboard_statuts_view_->SetKeyboardToggleText(); | |
| 399 } | |
| 400 } | |
| 401 | |
| 292 } // namespace ash | 402 } // namespace ash |
| OLD | NEW |