| 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_menu_button.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // or "...". So we shrink the font size until it fits within the bounds. | 113 // or "...". So we shrink the font size until it fits within the bounds. |
| 114 int size_delta = -1; | 114 int size_delta = -1; |
| 115 while (id_label->GetPreferredSize().width() > kMenuIconSize && | 115 while (id_label->GetPreferredSize().width() > kMenuIconSize && |
| 116 size_delta >= kMinFontSizeDelta) { | 116 size_delta >= kMinFontSizeDelta) { |
| 117 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_delta)); | 117 id_label->SetFontList(base_font_list.DeriveWithSizeDelta(size_delta)); |
| 118 --size_delta; | 118 --size_delta; |
| 119 } | 119 } |
| 120 tri_view->AddView(TriView::Container::START, id_label); | 120 tri_view->AddView(TriView::Container::START, id_label); |
| 121 | 121 |
| 122 // The label shows the IME name. | 122 // The label shows the IME name. |
| 123 label_ = TrayPopupUtils::CreateDefaultLabel(); | 123 auto label_view = TrayPopupUtils::CreateDefaultLabel(); |
| 124 label_->SetText(label); | 124 label_view->SetText(label); |
| 125 UpdateStyle(); | 125 TrayPopupItemStyle style( |
| 126 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 127 tri_view->AddView(TriView::Container::CENTER, label_); | 127 style.SetupLabel(label_view); |
| 128 |
| 129 label_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 130 tri_view->AddView(TriView::Container::CENTER, label_view); |
| 128 | 131 |
| 129 if (selected) { | 132 if (selected) { |
| 130 // The checked button indicates the IME is selected. | 133 // The checked button indicates the IME is selected. |
| 131 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView(); | 134 views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView(); |
| 132 checked_image->SetImage(gfx::CreateVectorIcon( | 135 checked_image->SetImage(gfx::CreateVectorIcon( |
| 133 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); | 136 gfx::VectorIconId::CHECK_CIRCLE, kMenuIconSize, button_color)); |
| 134 tri_view->AddView(TriView::Container::END, checked_image); | 137 tri_view->AddView(TriView::Container::END, checked_image); |
| 135 } | 138 } |
| 136 SetAccessibleName(label_->text()); | 139 SetAccessibleName(label_view->text()); |
| 137 } | 140 } |
| 138 | 141 |
| 139 ~ImeListItemView() override {} | 142 ~ImeListItemView() override {} |
| 140 | 143 |
| 141 // ActionableView: | 144 // ActionableView: |
| 142 bool PerformAction(const ui::Event& event) override { | 145 bool PerformAction(const ui::Event& event) override { |
| 143 if (ime_list_view_->should_focus_ime_after_selection_with_keyboard() && | 146 if (ime_list_view_->should_focus_ime_after_selection_with_keyboard() && |
| 144 event.type() == ui::EventType::ET_KEY_PRESSED) { | 147 event.type() == ui::EventType::ET_KEY_PRESSED) { |
| 145 ime_list_view_->set_last_item_selected_with_keyboard(true); | 148 ime_list_view_->set_last_item_selected_with_keyboard(true); |
| 146 } else { | 149 } else { |
| 147 ime_list_view_->set_last_item_selected_with_keyboard(false); | 150 ime_list_view_->set_last_item_selected_with_keyboard(false); |
| 148 } | 151 } |
| 149 | 152 |
| 150 ime_list_view_->HandleViewClicked(this); | 153 ime_list_view_->HandleViewClicked(this); |
| 151 return true; | 154 return true; |
| 152 } | 155 } |
| 153 | 156 |
| 154 void OnFocus() override { | 157 void OnFocus() override { |
| 155 ActionableView::OnFocus(); | 158 ActionableView::OnFocus(); |
| 156 if (ime_list_view_ && ime_list_view_->scroll_content()) | 159 if (ime_list_view_ && ime_list_view_->scroll_content()) |
| 157 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); | 160 ime_list_view_->scroll_content()->ScrollRectToVisible(bounds()); |
| 158 } | 161 } |
| 159 | 162 |
| 160 // views::View: | |
| 161 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | |
| 162 UpdateStyle(); | |
| 163 } | |
| 164 | |
| 165 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { | 163 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| 166 ActionableView::GetAccessibleNodeData(node_data); | 164 ActionableView::GetAccessibleNodeData(node_data); |
| 167 node_data->role = ui::AX_ROLE_CHECK_BOX; | 165 node_data->role = ui::AX_ROLE_CHECK_BOX; |
| 168 node_data->AddStateFlag(selected_ ? ui::AX_STATE_CHECKED | 166 node_data->AddStateFlag(selected_ ? ui::AX_STATE_CHECKED |
| 169 : ui::AX_STATE_NONE); | 167 : ui::AX_STATE_NONE); |
| 170 } | 168 } |
| 171 | 169 |
| 172 private: | 170 private: |
| 173 // Updates the style of |label_| based on the current native theme. | |
| 174 void UpdateStyle() { | |
| 175 TrayPopupItemStyle style( | |
| 176 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 177 style.SetupLabel(label_); | |
| 178 } | |
| 179 | |
| 180 // The label shows the IME name. | |
| 181 views::Label* label_; | |
| 182 ImeListView* ime_list_view_; | 171 ImeListView* ime_list_view_; |
| 183 bool selected_; | 172 bool selected_; |
| 184 | 173 |
| 185 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); | 174 DISALLOW_COPY_AND_ASSIGN(ImeListItemView); |
| 186 }; | 175 }; |
| 187 | 176 |
| 188 } // namespace | 177 } // namespace |
| 189 | 178 |
| 190 // The view that contains a |KeyboardButtonView| and a toggle button. | 179 // The view that contains a |KeyboardButtonView| and a toggle button. |
| 191 class MaterialKeyboardStatusRowView : public views::View { | 180 class MaterialKeyboardStatusRowView : public views::View { |
| 192 public: | 181 public: |
| 193 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) | 182 MaterialKeyboardStatusRowView(views::ButtonListener* listener, bool enabled) |
| 194 : listener_(listener), label_(nullptr), toggle_(nullptr) { | 183 : listener_(listener), toggle_(nullptr) { |
| 195 Init(); | 184 Init(); |
| 196 toggle_->SetIsOn(enabled, false); | 185 toggle_->SetIsOn(enabled, false); |
| 197 } | 186 } |
| 198 | 187 |
| 199 ~MaterialKeyboardStatusRowView() override {} | 188 ~MaterialKeyboardStatusRowView() override {} |
| 200 | 189 |
| 201 const views::Button* toggle() const { return toggle_; } | 190 const views::Button* toggle() const { return toggle_; } |
| 202 bool is_toggled() const { return toggle_->is_on(); } | 191 bool is_toggled() const { return toggle_->is_on(); } |
| 203 | 192 |
| 204 protected: | 193 protected: |
| 205 // views::View: | 194 // views::View: |
| 206 int GetHeightForWidth(int w) const override { | 195 int GetHeightForWidth(int w) const override { |
| 207 return GetPreferredSize().height(); | 196 return GetPreferredSize().height(); |
| 208 } | 197 } |
| 209 | 198 |
| 210 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | |
| 211 UpdateStyle(); | |
| 212 } | |
| 213 | |
| 214 private: | 199 private: |
| 215 void Init() { | 200 void Init() { |
| 216 TrayPopupUtils::ConfigureAsStickyHeader(this); | 201 TrayPopupUtils::ConfigureAsStickyHeader(this); |
| 217 SetLayoutManager(new views::FillLayout); | 202 SetLayoutManager(new views::FillLayout); |
| 218 | 203 |
| 219 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 204 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
| 220 AddChildView(tri_view); | 205 AddChildView(tri_view); |
| 221 | 206 |
| 222 // The on-screen keyboard image button. | 207 // The on-screen keyboard image button. |
| 223 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); | 208 views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView(); |
| 224 keyboard_image->SetImage(gfx::CreateVectorIcon( | 209 keyboard_image->SetImage(gfx::CreateVectorIcon( |
| 225 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); | 210 kImeMenuOnScreenKeyboardIcon, kMenuIconSize, kMenuIconColor)); |
| 226 tri_view->AddView(TriView::Container::START, keyboard_image); | 211 tri_view->AddView(TriView::Container::START, keyboard_image); |
| 227 | 212 |
| 228 // The on-screen keyboard label. | 213 // The on-screen keyboard label ('On-screen keyboard'). |
| 229 label_ = TrayPopupUtils::CreateDefaultLabel(); | 214 auto label = TrayPopupUtils::CreateDefaultLabel(); |
| 230 label_->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 215 label->SetText(ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 231 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); | 216 IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD)); |
| 232 UpdateStyle(); | 217 TrayPopupItemStyle style( |
| 233 tri_view->AddView(TriView::Container::CENTER, label_); | 218 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 219 style.SetupLabel(label); |
| 220 tri_view->AddView(TriView::Container::CENTER, label); |
| 234 | 221 |
| 235 // The on-screen keyboard toggle button. | 222 // The on-screen keyboard toggle button. |
| 236 toggle_ = TrayPopupUtils::CreateToggleButton( | 223 toggle_ = TrayPopupUtils::CreateToggleButton( |
| 237 listener_, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); | 224 listener_, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD); |
| 238 tri_view->AddView(TriView::Container::END, toggle_); | 225 tri_view->AddView(TriView::Container::END, toggle_); |
| 239 } | 226 } |
| 240 | 227 |
| 241 // Updates the style of |label_| based on the current native theme. | |
| 242 void UpdateStyle() { | |
| 243 TrayPopupItemStyle style( | |
| 244 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 245 style.SetupLabel(label_); | |
| 246 } | |
| 247 | |
| 248 // ButtonListener to notify when |toggle_| is clicked. | 228 // ButtonListener to notify when |toggle_| is clicked. |
| 249 views::ButtonListener* listener_; | 229 views::ButtonListener* listener_; |
| 250 | 230 |
| 251 // Label to with text 'On-screen keyboard'. | |
| 252 views::Label* label_; | |
| 253 | |
| 254 // ToggleButton to toggle keyboard on or off. | 231 // ToggleButton to toggle keyboard on or off. |
| 255 views::ToggleButton* toggle_; | 232 views::ToggleButton* toggle_; |
| 256 | 233 |
| 257 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); | 234 DISALLOW_COPY_AND_ASSIGN(MaterialKeyboardStatusRowView); |
| 258 }; | 235 }; |
| 259 | 236 |
| 260 ImeListView::ImeListView(SystemTrayItem* owner, | 237 ImeListView::ImeListView(SystemTrayItem* owner, |
| 261 bool show_keyboard_toggle, | 238 bool show_keyboard_toggle, |
| 262 SingleImeBehavior single_ime_behavior) | 239 SingleImeBehavior single_ime_behavior) |
| 263 : TrayDetailsView(owner), | 240 : TrayDetailsView(owner), |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 456 |
| 480 for (auto property_map : property_map_) { | 457 for (auto property_map : property_map_) { |
| 481 if (property_map.second == last_selected_item_id_) { | 458 if (property_map.second == last_selected_item_id_) { |
| 482 (property_map.first)->RequestFocus(); | 459 (property_map.first)->RequestFocus(); |
| 483 return; | 460 return; |
| 484 } | 461 } |
| 485 } | 462 } |
| 486 } | 463 } |
| 487 | 464 |
| 488 } // namespace ash | 465 } // namespace ash |
| OLD | NEW |