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/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 AddLabel(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 on touch. |
| 137 class KeyboardStatusRow : public views::View { | |
|
Evan Stade
2017/04/04 23:40:47
where does this actually show up? I can't find a t
tdanderson
2017/04/05 17:54:42
Yes that specific call site always passes in false
Evan Stade
2017/04/05 18:02:56
"and it seems like that probably always gets calle
| |
| 176 public: | 138 public: |
| 177 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) | 139 KeyboardStatusRow() {} |
| 178 : listener_(listener), toggle_(nullptr) { | 140 ~KeyboardStatusRow() override {} |
| 179 Init(); | |
| 180 toggle_->SetIsOn(enabled, false); | |
| 181 } | |
| 182 | 141 |
| 183 ~MaterialKeyboardStatusRowView() override {} | 142 views::ToggleButton* toggle() const { return toggle_; } |
| 184 | |
| 185 views::Button* toggle() const { return toggle_; } | |
| 186 bool is_toggled() const { return toggle_->is_on(); } | 143 bool is_toggled() const { return toggle_->is_on(); } |
| 187 | 144 |
| 188 protected: | 145 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); | 146 TrayPopupUtils::ConfigureAsStickyHeader(this); |
| 197 SetLayoutManager(new views::FillLayout); | 147 SetLayoutManager(new views::FillLayout); |
| 198 | 148 |
| 199 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 149 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
| 200 AddChildView(tri_view); | 150 AddChildView(tri_view); |
| 201 | 151 |
| 202 // The on-screen keyboard image button. | 152 // The on-screen keyboard image button. |
| 203 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); | 153 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); |
| 204 keyboard_image->SetImage(gfx::CreateVectorIcon( | 154 keyboard_image->SetImage(gfx::CreateVectorIcon( |
| 205 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); | 155 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); |
| 206 tri_view->AddView(TriView::Container::START, keyboard_image); | 156 tri_view->AddView(TriView::Container::START, keyboard_image); |
| 207 | 157 |
| 208 // The on-screen keyboard label ('On-screen keyboard'). | 158 // The on-screen keyboard label ('On-screen keyboard'). |
| 209 auto* label = TrayPopupUtils::CreateDefaultLabel(); | 159 auto* label = TrayPopupUtils::CreateDefaultLabel(); |
| 210 label->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 160 label->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 211 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); | 161 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); |
| 212 TrayPopupItemStyle style( | 162 TrayPopupItemStyle style( |
| 213 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 163 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 214 style.SetupLabel(label); | 164 style.SetupLabel(label); |
| 215 tri_view->AddView(TriView::Container::CENTER, label); | 165 tri_view->AddView(TriView::Container::CENTER, label); |
| 216 | 166 |
| 217 // The on-screen keyboard toggle button. | 167 // The on-screen keyboard toggle button. |
| 218 toggle_ = TrayPopupUtils::CreateToggleButton( | 168 toggle_ = TrayPopupUtils::CreateToggleButton( |
| 219 listener_, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); | 169 listener, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); |
| 220 tri_view->AddView(TriView::Container::END, toggle_); | 170 tri_view->AddView(TriView::Container::END, toggle_); |
| 221 } | 171 } |
| 222 | 172 |
| 223 // ButtonListener to notify when |toggle_| is clicked. | 173 protected: |
| 224 views::ButtonListener* listener_; | 174 // views::View: |
| 175 int GetHeightForWidth(int w) const override { | |
| 176 return GetPreferredSize().height(); | |
| 177 } | |
| 225 | 178 |
| 179 private: | |
| 226 // ToggleButton to toggle keyboard on or off. | 180 // ToggleButton to toggle keyboard on or off. |
| 227 views::ToggleButton* toggle_; | 181 views::ToggleButton* toggle_ = nullptr; |
| 228 | 182 |
| 229 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | 183 DISALLOW_COPY_AND_ASSIGN(KeyboardStatusRow); |
| 230 }; | 184 }; |
| 231 | 185 |
| 232 ImeListView::ImeListView(SystemTrayItem* owner) | 186 ImeListView::ImeListView(SystemTrayItem* owner) |
| 233 : TrayDetailsView(owner), | 187 : TrayDetailsView(owner), |
| 234 last_item_selected_with_keyboard_(false), | 188 last_item_selected_with_keyboard_(false), |
| 235 should_focus_ime_after_selection_with_keyboard_(false), | 189 should_focus_ime_after_selection_with_keyboard_(false), |
| 236 current_ime_view_(nullptr) {} | 190 current_ime_view_(nullptr) {} |
| 237 | 191 |
| 238 ImeListView::~ImeListView() {} | 192 ImeListView::~ImeListView() {} |
| 239 | 193 |
| 240 void ImeListView::Init(bool show_keyboard_toggle, | 194 void ImeListView::Init(bool show_keyboard_toggle, |
| 241 SingleImeBehavior single_ime_behavior) { | 195 SingleImeBehavior single_ime_behavior) { |
| 242 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); | 196 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); |
| 243 IMEInfoList list; | 197 IMEInfoList list; |
| 244 delegate->GetAvailableIMEList(&list); | 198 delegate->GetAvailableIMEList(&list); |
| 245 IMEPropertyInfoList property_list; | 199 IMEPropertyInfoList property_list; |
| 246 delegate->GetCurrentIMEProperties(&property_list); | 200 delegate->GetCurrentIMEProperties(&property_list); |
| 247 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); | 201 Update(list, property_list, show_keyboard_toggle, single_ime_behavior); |
| 248 } | 202 } |
| 249 | 203 |
| 250 void ImeListView::Update(const IMEInfoList& list, | 204 void ImeListView::Update(const IMEInfoList& list, |
| 251 const IMEPropertyInfoList& property_list, | 205 const IMEPropertyInfoList& property_list, |
| 252 bool show_keyboard_toggle, | 206 bool show_keyboard_toggle, |
| 253 SingleImeBehavior single_ime_behavior) { | 207 SingleImeBehavior single_ime_behavior) { |
| 254 ResetImeListView(); | 208 ResetImeListView(); |
| 255 ime_map_.clear(); | 209 ime_map_.clear(); |
| 256 property_map_.clear(); | 210 property_map_.clear(); |
| 257 CreateScrollableList(); | 211 CreateScrollableList(); |
| 258 | 212 |
| 259 // Appends IME list and IME properties. | 213 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) |
| 260 if (single_ime_behavior == ImeListView::SHOW_SINGLE_IME || list.size() > 1) { | 214 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 | 215 |
| 270 if (show_keyboard_toggle) { | 216 if (show_keyboard_toggle) |
| 271 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 217 PrependKeyboardStatusRow(); |
| 272 PrependMaterialKeyboardStatus(); | |
| 273 } else { | |
| 274 if (list.size() > 1 || !property_list.empty()) | |
| 275 AddScrollSeparator(); | |
| 276 AppendKeyboardStatus(); | |
| 277 } | |
| 278 } | |
| 279 | 218 |
| 280 Layout(); | 219 Layout(); |
| 281 SchedulePaint(); | 220 SchedulePaint(); |
| 282 | 221 |
| 283 if (should_focus_ime_after_selection_with_keyboard_ && | 222 if (should_focus_ime_after_selection_with_keyboard_ && |
| 284 last_item_selected_with_keyboard_) { | 223 last_item_selected_with_keyboard_) { |
| 285 FocusCurrentImeIfNeeded(); | 224 FocusCurrentImeIfNeeded(); |
| 286 } else if (current_ime_view_) { | 225 } else if (current_ime_view_) { |
| 287 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds()); | 226 scroll_content()->ScrollRectToVisible(current_ime_view_->bounds()); |
| 288 } | 227 } |
| 289 } | 228 } |
| 290 | 229 |
| 291 void ImeListView::ResetImeListView() { | 230 void ImeListView::ResetImeListView() { |
| 292 // Children are removed from the view hierarchy and deleted in Reset(). | 231 // Children are removed from the view hierarchy and deleted in Reset(). |
| 293 Reset(); | 232 Reset(); |
| 294 material_keyboard_status_view_ = nullptr; | 233 keyboard_status_row_ = nullptr; |
| 295 keyboard_status_ = nullptr; | |
| 296 current_ime_view_ = nullptr; | 234 current_ime_view_ = nullptr; |
| 297 } | 235 } |
| 298 | 236 |
| 299 void ImeListView::CloseImeListView() { | 237 void ImeListView::CloseImeListView() { |
| 300 last_selected_item_id_.clear(); | 238 last_selected_item_id_.clear(); |
| 301 current_ime_view_ = nullptr; | 239 current_ime_view_ = nullptr; |
| 302 last_item_selected_with_keyboard_ = false; | 240 last_item_selected_with_keyboard_ = false; |
| 303 GetWidget()->Close(); | 241 GetWidget()->Close(); |
| 304 } | 242 } |
| 305 | 243 |
| 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( | 244 void ImeListView::AppendImeListAndProperties( |
| 331 const IMEInfoList& list, | 245 const IMEInfoList& list, |
| 332 const IMEPropertyInfoList& property_list) { | 246 const IMEPropertyInfoList& property_list) { |
| 333 DCHECK(ime_map_.empty()); | 247 DCHECK(ime_map_.empty()); |
| 334 for (size_t i = 0; i < list.size(); i++) { | 248 for (size_t i = 0; i < list.size(); i++) { |
| 335 views::View* ime_view = | 249 views::View* ime_view = |
| 336 new ImeListItemView(owner(), this, list[i].short_name, list[i].name, | 250 new ImeListItemView(owner(), this, list[i].short_name, list[i].name, |
| 337 list[i].selected, gfx::kGoogleGreen700); | 251 list[i].selected, gfx::kGoogleGreen700); |
| 338 scroll_content()->AddChildView(ime_view); | 252 scroll_content()->AddChildView(ime_view); |
| 339 ime_map_[ime_view] = list[i].id; | 253 ime_map_[ime_view] = list[i].id; |
| 340 | 254 |
| 341 if (list[i].selected) | 255 if (list[i].selected) |
| 342 current_ime_view_ = ime_view; | 256 current_ime_view_ = ime_view; |
| 343 | 257 |
| 344 // In material design, the property items will be added after the current | 258 // Add the properties, if any, of the currently-selected IME. |
| 345 // selected IME item. | |
| 346 if (list[i].selected && !property_list.empty()) { | 259 if (list[i].selected && !property_list.empty()) { |
| 347 // Adds a separator on the top of property items. | 260 // Adds a separator on the top of property items. |
| 348 scroll_content()->AddChildView( | 261 scroll_content()->AddChildView( |
| 349 TrayPopupUtils::CreateListItemSeparator(true)); | 262 TrayPopupUtils::CreateListItemSeparator(true)); |
| 350 | 263 |
| 351 // Adds the property items. | 264 // Adds the property items. |
| 352 for (size_t i = 0; i < property_list.size(); i++) { | 265 for (size_t i = 0; i < property_list.size(); i++) { |
| 353 ImeListItemView* property_view = new ImeListItemView( | 266 ImeListItemView* property_view = new ImeListItemView( |
| 354 owner(), this, base::string16(), property_list[i].name, | 267 owner(), this, base::string16(), property_list[i].name, |
| 355 property_list[i].selected, kMenuIconColor); | 268 property_list[i].selected, kMenuIconColor); |
| 356 scroll_content()->AddChildView(property_view); | 269 scroll_content()->AddChildView(property_view); |
| 357 property_map_[property_view] = property_list[i].key; | 270 property_map_[property_view] = property_list[i].key; |
| 358 } | 271 } |
| 359 | 272 |
| 360 // Adds a separator on the bottom of property items if there are still | 273 // Adds a separator on the bottom of property items if there are still |
| 361 // other IMEs under the current one. | 274 // other IMEs under the current one. |
| 362 if (i < list.size() - 1) | 275 if (i < list.size() - 1) |
| 363 scroll_content()->AddChildView( | 276 scroll_content()->AddChildView( |
| 364 TrayPopupUtils::CreateListItemSeparator(true)); | 277 TrayPopupUtils::CreateListItemSeparator(true)); |
| 365 } | 278 } |
| 366 } | 279 } |
| 367 } | 280 } |
| 368 | 281 |
| 369 void ImeListView::AppendKeyboardStatus() { | 282 void ImeListView::PrependKeyboardStatusRow() { |
| 370 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial()); | 283 DCHECK(!keyboard_status_row_); |
| 371 HoverHighlightView* container = new HoverHighlightView(this); | 284 keyboard_status_row_ = new KeyboardStatusRow; |
| 372 int id = keyboard::IsKeyboardEnabled() ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | 285 keyboard_status_row_->Init(this); |
| 373 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | 286 keyboard_status_row_->toggle()->SetIsOn(keyboard::IsKeyboardEnabled(), false); |
|
Evan Stade
2017/04/04 23:40:47
this should probably be in KeyboardStatusRow::Init
tdanderson
2017/04/05 17:54:42
Done.
| |
| 374 container->AddLabel( | 287 scroll_content()->AddChildViewAt(keyboard_status_row_, 0); |
| 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 } | 288 } |
| 389 | 289 |
| 390 void ImeListView::HandleViewClicked(views::View* view) { | 290 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(); | 291 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); |
| 399 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); | 292 std::map<views::View*, std::string>::const_iterator ime = ime_map_.find(view); |
| 400 if (ime != ime_map_.end()) { | 293 if (ime != ime_map_.end()) { |
| 401 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); | 294 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SWITCH_MODE); |
| 402 std::string ime_id = ime->second; | 295 std::string ime_id = ime->second; |
| 403 last_selected_item_id_ = ime_id; | 296 last_selected_item_id_ = ime_id; |
| 404 delegate->SwitchIME(ime_id); | 297 delegate->SwitchIME(ime_id); |
| 405 } else { | 298 } else { |
| 406 std::map<views::View*, std::string>::const_iterator property = | 299 std::map<views::View*, std::string>::const_iterator property = |
| 407 property_map_.find(view); | 300 property_map_.find(view); |
| 408 if (property == property_map_.end()) | 301 if (property == property_map_.end()) |
| 409 return; | 302 return; |
| 410 const std::string key = property->second; | 303 const std::string key = property->second; |
| 411 last_selected_item_id_ = key; | 304 last_selected_item_id_ = key; |
| 412 delegate->ActivateIMEProperty(key); | 305 delegate->ActivateIMEProperty(key); |
| 413 } | 306 } |
| 414 | 307 |
| 415 if (!should_focus_ime_after_selection_with_keyboard_ || | 308 if (!should_focus_ime_after_selection_with_keyboard_ || |
| 416 !last_item_selected_with_keyboard_) { | 309 !last_item_selected_with_keyboard_) { |
| 417 CloseImeListView(); | 310 CloseImeListView(); |
| 418 } | 311 } |
| 419 } | 312 } |
| 420 | 313 |
| 421 void ImeListView::HandleButtonPressed(views::Button* sender, | 314 void ImeListView::HandleButtonPressed(views::Button* sender, |
| 422 const ui::Event& event) { | 315 const ui::Event& event) { |
| 423 if (material_keyboard_status_view_ && | 316 if (keyboard_status_row_ && sender == keyboard_status_row_->toggle()) { |
| 424 sender == material_keyboard_status_view_->toggle()) { | |
| 425 WmShell::Get()->ToggleIgnoreExternalKeyboard(); | 317 WmShell::Get()->ToggleIgnoreExternalKeyboard(); |
| 426 last_selected_item_id_.clear(); | 318 last_selected_item_id_.clear(); |
| 427 last_item_selected_with_keyboard_ = false; | 319 last_item_selected_with_keyboard_ = false; |
| 428 } | 320 } |
| 429 } | 321 } |
| 430 | 322 |
| 431 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) { | 323 void ImeListView::VisibilityChanged(View* starting_from, bool is_visible) { |
| 432 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ && | 324 if (!is_visible || (should_focus_ime_after_selection_with_keyboard_ && |
| 433 last_item_selected_with_keyboard_) || | 325 last_item_selected_with_keyboard_) || |
| 434 !current_ime_view_) { | 326 !current_ime_view_) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 457 } | 349 } |
| 458 } | 350 } |
| 459 } | 351 } |
| 460 | 352 |
| 461 ImeListViewTestApi::ImeListViewTestApi(ImeListView* ime_list_view) | 353 ImeListViewTestApi::ImeListViewTestApi(ImeListView* ime_list_view) |
| 462 : ime_list_view_(ime_list_view) {} | 354 : ime_list_view_(ime_list_view) {} |
| 463 | 355 |
| 464 ImeListViewTestApi::~ImeListViewTestApi() {} | 356 ImeListViewTestApi::~ImeListViewTestApi() {} |
| 465 | 357 |
| 466 views::View* ImeListViewTestApi::GetToggleView() const { | 358 views::View* ImeListViewTestApi::GetToggleView() const { |
| 467 return ime_list_view_->material_keyboard_status_view_->toggle(); | 359 return ime_list_view_->keyboard_status_row_->toggle(); |
| 468 } | 360 } |
| 469 | 361 |
| 470 } // namespace ash | 362 } // namespace ash |
| OLD | NEW |