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_menu_tray.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.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/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | 11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
| 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 13 #include "ash/common/system/tray/hover_highlight_view.h" | 13 #include "ash/common/system/tray/hover_highlight_view.h" |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 15 #include "ash/common/system/tray/system_tray_notifier.h" | 15 #include "ash/common/system/tray/system_tray_notifier.h" |
| 16 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
| 17 #include "ash/common/system/tray/tray_popup_header_button.h" | 17 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 18 #include "ash/common/system/tray/tray_utils.h" | 18 #include "ash/common/system/tray/tray_utils.h" |
| 19 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
| 20 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
| 21 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
| 22 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
| 25 #include "grit/ash_strings.h" | 25 #include "grit/ash_strings.h" |
| 26 #include "ui/base/ime/chromeos/input_method_manager.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
| 29 #include "ui/views/layout/box_layout.h" | 30 #include "ui/views/layout/box_layout.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Returns the max height of ImeListView. | 36 // Returns the max height of ImeListView. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, | 77 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, |
| 77 kBorderDarkColor)); | 78 kBorderDarkColor)); |
| 78 return button; | 79 return button; |
| 79 } | 80 } |
| 80 | 81 |
| 81 // The view that contains buttons shown on the bottom of IME menu. | 82 // The view that contains buttons shown on the bottom of IME menu. |
| 82 class ImeButtonsView : public views::View, | 83 class ImeButtonsView : public views::View, |
| 83 public views::ButtonListener, | 84 public views::ButtonListener, |
| 84 public ViewClickListener { | 85 public ViewClickListener { |
| 85 public: | 86 public: |
| 86 ImeButtonsView(bool show_emoji_button, | 87 ImeButtonsView(ImeMenuTray* ime_menu_tray, |
| 88 bool show_emoji_button, | |
| 87 bool show_voice_button, | 89 bool show_voice_button, |
| 88 bool show_handwriting_button, | 90 bool show_handwriting_button, |
| 89 bool show_settings_button) { | 91 bool show_settings_button) |
| 92 : ime_menu_tray_(ime_menu_tray) { | |
| 90 SetBorder( | 93 SetBorder( |
|
James Cook
2016/09/12 03:21:54
nit: DCHECK(ime_menu_tray_) helps the reader under
Azure Wei
2016/09/12 13:12:56
Done.
| |
| 91 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); | 94 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); |
| 92 | 95 |
| 93 // If there's only one settings button, the bottom should be a label with | 96 // If there's only one settings button, the bottom should be a label with |
| 94 // normal background. Otherwise, show button icons with header background. | 97 // normal background. Otherwise, show button icons with header background. |
| 95 if (show_settings_button && !show_emoji_button && !show_voice_button && | 98 if (show_settings_button && !show_emoji_button && !show_voice_button && |
| 96 !show_handwriting_button) { | 99 !show_handwriting_button) { |
| 97 ShowOneSettingButton(); | 100 ShowOneSettingButton(); |
| 98 } else { | 101 } else { |
| 99 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, | 102 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, |
| 100 show_settings_button); | 103 show_settings_button); |
| 101 } | 104 } |
| 102 // TODO(azurewei): Add logic of switching between the two states when the | 105 // TODO(azurewei): Add logic of switching between the two states when the |
| 103 // menu is shown. | 106 // menu is shown. |
| 104 } | 107 } |
| 105 | 108 |
| 106 ~ImeButtonsView() override {} | 109 ~ImeButtonsView() override {} |
| 107 | 110 |
| 108 // views::View: | 111 // views::View: |
| 109 gfx::Size GetPreferredSize() const override { | 112 gfx::Size GetPreferredSize() const override { |
| 110 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); | 113 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); |
| 111 return gfx::Size(size, size); | 114 return gfx::Size(size, size); |
| 112 } | 115 } |
| 113 int GetHeightForWidth(int width) const override { | 116 int GetHeightForWidth(int width) const override { |
| 114 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); | 117 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); |
| 115 } | 118 } |
| 116 | 119 |
| 117 // views::ButtonListener: | 120 // views::ButtonListener: |
| 118 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 121 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 122 if (settings_button_ && sender == settings_button_) { | |
|
James Cook
2016/09/12 03:21:54
nit: |sender| should never be null, so you don't n
Azure Wei
2016/09/12 13:12:56
Done. Thanks.
| |
| 123 ime_menu_tray_->HideImeMenuBubble(); | |
| 124 ShowIMESettings(); | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 std::string appended_url; | |
|
James Cook
2016/09/12 03:21:54
nit: This isn't a URL. It should be called somethi
Azure Wei
2016/09/12 13:12:56
Done. Renamed as keyset.
| |
| 119 if (emoji_button_ && sender == emoji_button_) { | 129 if (emoji_button_ && sender == emoji_button_) { |
|
James Cook
2016/09/12 03:21:54
nit: {} not needed for single-line if()
Azure Wei
2016/09/12 13:12:57
Done.
| |
| 120 // TODO(azurewei): Opens emoji palette. | 130 appended_url = "emoji"; |
| 121 } else if (voice_button_ && sender == voice_button_) { | 131 } else if (voice_button_ && sender == voice_button_) { |
| 122 // TODO(azurewei): Brings virtual keyboard for emoji input. | 132 appended_url = "voice"; |
| 123 } else if (handwriting_button_ && sender == handwriting_button_) { | 133 } else if (handwriting_button_ && sender == handwriting_button_) { |
| 124 // TODO(azurewei): Brings virtual keyboard for handwriting input. | 134 appended_url = "handwriting"; |
| 125 } else if (settings_button_ && sender == settings_button_) { | |
| 126 ShowIMESettings(); | |
| 127 } | 135 } |
| 136 if (appended_url.empty()) | |
|
James Cook
2016/09/12 03:21:54
nit: This should never happen. I would do:
else
Azure Wei
2016/09/12 13:12:57
Done.
| |
| 137 return; | |
| 138 ime_menu_tray_->HideImeMenuBubble(); | |
| 139 chromeos::input_method::InputMethodManager::Get()->ShowInputViewWithUrl( | |
|
James Cook
2016/09/12 03:21:54
I think it would be better for this function to ta
Azure Wei
2016/09/12 13:12:56
Done.
| |
| 140 "&keyboard=" + appended_url); | |
| 128 } | 141 } |
| 129 | 142 |
| 130 // ViewClickListener: | 143 // ViewClickListener: |
| 131 void OnViewClicked(views::View* sender) override { | 144 void OnViewClicked(views::View* sender) override { |
| 132 if (one_settings_button_view_ && sender == one_settings_button_view_) { | 145 if (one_settings_button_view_ && sender == one_settings_button_view_) { |
| 146 ime_menu_tray_->HideImeMenuBubble(); | |
| 133 ShowIMESettings(); | 147 ShowIMESettings(); |
| 134 } | 148 } |
| 135 } | 149 } |
| 136 | 150 |
| 137 private: | 151 private: |
| 138 // Shows the UI of one settings button. | 152 // Shows the UI of one settings button. |
| 139 void ShowOneSettingButton() { | 153 void ShowOneSettingButton() { |
| 140 auto* box_layout = | 154 auto* box_layout = |
| 141 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 155 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 142 box_layout->SetDefaultFlex(1); | 156 box_layout->SetDefaultFlex(1); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 156 bool show_settings_button) { | 170 bool show_settings_button) { |
| 157 set_background( | 171 set_background( |
| 158 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | 172 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); |
| 159 auto* box_layout = new views::BoxLayout( | 173 auto* box_layout = new views::BoxLayout( |
| 160 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, | 174 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, |
| 161 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); | 175 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); |
| 162 box_layout->SetDefaultFlex(1); | 176 box_layout->SetDefaultFlex(1); |
| 163 SetLayoutManager(box_layout); | 177 SetLayoutManager(box_layout); |
| 164 | 178 |
| 165 if (show_emoji_button) { | 179 if (show_emoji_button) { |
| 166 // TODO(azurewei): Creates the proper button with icons. | 180 // TODO(azurewei): Creates the proper button with icons. |
|
James Cook
2016/09/12 03:21:54
How did you test this without creating buttons? Co
Azure Wei
2016/09/12 13:12:57
Added codes to show the buttons if features::kEHVI
| |
| 167 } | 181 } |
| 168 | 182 |
| 169 if (show_voice_button) { | 183 if (show_voice_button) { |
| 170 // TODO(azurewei): Creates the proper button with icons. | 184 // TODO(azurewei): Creates the proper button with icons. |
| 171 } | 185 } |
| 172 | 186 |
| 173 if (show_handwriting_button) { | 187 if (show_handwriting_button) { |
| 174 // TODO(azurewei): Creates the proper button with icons. | 188 // TODO(azurewei): Creates the proper button with icons. |
| 175 } | 189 } |
| 176 | 190 |
| 177 if (show_settings_button) { | 191 if (show_settings_button) { |
| 178 settings_button_ = CreateImeMenuButton( | 192 settings_button_ = CreateImeMenuButton( |
| 179 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | 193 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, |
| 180 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | 194 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, |
| 181 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); | 195 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); |
| 182 AddChildView(settings_button_); | 196 AddChildView(settings_button_); |
| 183 } | 197 } |
| 184 } | 198 } |
| 185 | 199 |
| 200 ImeMenuTray* ime_menu_tray_; | |
| 186 TrayPopupHeaderButton* emoji_button_; | 201 TrayPopupHeaderButton* emoji_button_; |
| 187 TrayPopupHeaderButton* voice_button_; | 202 TrayPopupHeaderButton* voice_button_; |
| 188 TrayPopupHeaderButton* handwriting_button_; | 203 TrayPopupHeaderButton* handwriting_button_; |
| 189 TrayPopupHeaderButton* settings_button_; | 204 TrayPopupHeaderButton* settings_button_; |
| 190 HoverHighlightView* one_settings_button_view_; | 205 HoverHighlightView* one_settings_button_view_; |
| 191 | 206 |
| 192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); | 207 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); |
| 193 }; | 208 }; |
| 194 | 209 |
| 195 } // namespace | 210 } // namespace |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 ime_list_view_->scroller()->SetFixedSize( | 243 ime_list_view_->scroller()->SetFixedSize( |
| 229 gfx::Size(kTrayPopupMaxWidth, GetImeListViewMaxHeight())); | 244 gfx::Size(kTrayPopupMaxWidth, GetImeListViewMaxHeight())); |
| 230 } | 245 } |
| 231 bubble_view->AddChildView(ime_list_view_); | 246 bubble_view->AddChildView(ime_list_view_); |
| 232 | 247 |
| 233 // Adds IME buttons to the bubble if needed. | 248 // Adds IME buttons to the bubble if needed. |
| 234 LoginStatus login = | 249 LoginStatus login = |
| 235 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); | 250 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); |
| 236 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && | 251 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && |
| 237 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | 252 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) |
| 238 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); | 253 bubble_view->AddChildView( |
| 254 new ImeButtonsView(this, false, false, false, true)); | |
| 239 | 255 |
| 240 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); | 256 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
| 241 SetDrawBackgroundAsActive(true); | 257 SetDrawBackgroundAsActive(true); |
| 242 } | 258 } |
| 243 | 259 |
| 260 void ImeMenuTray::HideImeMenuBubble() { | |
| 261 bubble_.reset(); | |
| 262 ime_list_view_ = nullptr; | |
| 263 SetDrawBackgroundAsActive(false); | |
| 264 } | |
| 265 | |
| 244 bool ImeMenuTray::IsImeMenuBubbleShown() { | 266 bool ImeMenuTray::IsImeMenuBubbleShown() { |
| 245 return !!bubble_; | 267 return !!bubble_; |
| 246 } | 268 } |
| 247 | 269 |
| 248 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { | 270 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 249 TrayBackgroundView::SetShelfAlignment(alignment); | 271 TrayBackgroundView::SetShelfAlignment(alignment); |
| 250 if (!MaterialDesignController::IsShelfMaterial()) | 272 if (!MaterialDesignController::IsShelfMaterial()) |
| 251 tray_container()->SetBorder(views::Border::NullBorder()); | 273 tray_container()->SetBorder(views::Border::NullBorder()); |
| 252 } | 274 } |
| 253 | 275 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 void ImeMenuTray::UpdateTrayLabel() { | 365 void ImeMenuTray::UpdateTrayLabel() { |
| 344 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); | 366 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); |
| 345 | 367 |
| 346 // Updates the tray label based on the current input method. | 368 // Updates the tray label based on the current input method. |
| 347 if (current_ime_.third_party) | 369 if (current_ime_.third_party) |
| 348 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | 370 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); |
| 349 else | 371 else |
| 350 label_->SetText(current_ime_.short_name); | 372 label_->SetText(current_ime_.short_name); |
| 351 } | 373 } |
| 352 | 374 |
| 353 void ImeMenuTray::HideImeMenuBubble() { | |
| 354 bubble_.reset(); | |
| 355 ime_list_view_ = nullptr; | |
| 356 SetDrawBackgroundAsActive(false); | |
| 357 } | |
| 358 | |
| 359 } // namespace ash | 375 } // namespace ash |
| OLD | NEW |