| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, | 47 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, |
| 48 int enabled_resource_id, | 48 int enabled_resource_id, |
| 49 int disabled_resource_id, | 49 int disabled_resource_id, |
| 50 int enabled_resource_id_hover, | 50 int enabled_resource_id_hover, |
| 51 int disabled_resource_id_hover, | 51 int disabled_resource_id_hover, |
| 52 int accessible_name_id, | 52 int accessible_name_id, |
| 53 int message_id, | 53 int message_id, |
| 54 int right_border) { | 54 int right_border) { |
| 55 TrayPopupHeaderButton* button = new ash::TrayPopupHeaderButton( | 55 TrayPopupHeaderButton* button = |
| 56 listener, enabled_resource_id, disabled_resource_id, | 56 new TrayPopupHeaderButton(listener, enabled_resource_id, |
| 57 enabled_resource_id_hover, disabled_resource_id_hover, | 57 disabled_resource_id, enabled_resource_id_hover, |
| 58 accessible_name_id); | 58 disabled_resource_id_hover, accessible_name_id); |
| 59 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); | 59 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); |
| 60 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, | 60 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, |
| 61 kBorderDarkColor)); | 61 kBorderDarkColor)); |
| 62 return button; | 62 return button; |
| 63 } | 63 } |
| 64 | 64 |
| 65 class ImeButtonsView : public views::View, public views::ButtonListener { | 65 class ImeButtonsView : public views::View, public views::ButtonListener { |
| 66 public: | 66 public: |
| 67 ImeButtonsView(bool show_emoji_button, | 67 ImeButtonsView(bool show_emoji_button, |
| 68 bool show_voice_button, | 68 bool show_voice_button, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 SetContentsBackground(); | 145 SetContentsBackground(); |
| 146 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); | 146 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); |
| 147 } | 147 } |
| 148 | 148 |
| 149 ImeMenuTray::~ImeMenuTray() { | 149 ImeMenuTray::~ImeMenuTray() { |
| 150 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); | 150 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { | 153 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 154 TrayBackgroundView::SetShelfAlignment(alignment); | 154 TrayBackgroundView::SetShelfAlignment(alignment); |
| 155 if (!ash::MaterialDesignController::IsShelfMaterial()) | 155 if (!MaterialDesignController::IsShelfMaterial()) |
| 156 tray_container()->SetBorder(views::Border::NullBorder()); | 156 tray_container()->SetBorder(views::Border::NullBorder()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | 159 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
| 160 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 160 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 163 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
| 164 if (bubble_->bubble_view() == bubble_view) | 164 if (bubble_->bubble_view() == bubble_view) |
| 165 HideImeMenuBubble(); | 165 HideImeMenuBubble(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void ImeMenuTray::ClickedOutsideBubble() { | 168 void ImeMenuTray::ClickedOutsideBubble() { |
| 169 HideImeMenuBubble(); | 169 HideImeMenuBubble(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool ImeMenuTray::PerformAction(const ui::Event& event) { | 172 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
| 173 if (bubble_) | 173 if (bubble_) |
| 174 HideImeMenuBubble(); | 174 HideImeMenuBubble(); |
| 175 else | 175 else |
| 176 ShowImeMenuBubble(); | 176 ShowImeMenuBubble(); |
| 177 return true; | 177 return true; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void ImeMenuTray::OnIMERefresh() { | 180 void ImeMenuTray::OnIMERefresh() { |
| 181 UpdateTrayLabel(); | 181 UpdateTrayLabel(); |
| 182 if (bubble_ && ime_list_view_) { |
| 183 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 184 IMEInfoList list; |
| 185 delegate->GetAvailableIMEList(&list); |
| 186 IMEPropertyInfoList property_list; |
| 187 delegate->GetCurrentIMEProperties(&property_list); |
| 188 ime_list_view_->Update(list, property_list, false, |
| 189 ImeListView::SHOW_SINGLE_IME); |
| 190 } |
| 182 } | 191 } |
| 183 | 192 |
| 184 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | 193 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { |
| 185 SetVisible(is_activated); | 194 SetVisible(is_activated); |
| 186 if (is_activated) | 195 if (is_activated) |
| 187 UpdateTrayLabel(); | 196 UpdateTrayLabel(); |
| 188 else | 197 else |
| 189 HideImeMenuBubble(); | 198 HideImeMenuBubble(); |
| 190 } | 199 } |
| 191 | 200 |
| 192 void ImeMenuTray::BubbleViewDestroyed() { | 201 void ImeMenuTray::BubbleViewDestroyed() { |
| 193 SetDrawBackgroundAsActive(false); | |
| 194 } | 202 } |
| 195 | 203 |
| 196 void ImeMenuTray::OnMouseEnteredView() {} | 204 void ImeMenuTray::OnMouseEnteredView() {} |
| 197 | 205 |
| 198 void ImeMenuTray::OnMouseExitedView() {} | 206 void ImeMenuTray::OnMouseExitedView() {} |
| 199 | 207 |
| 200 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { | 208 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { |
| 201 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 209 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 202 } | 210 } |
| 203 | 211 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 init_params.first_item_has_no_margin = true; | 262 init_params.first_item_has_no_margin = true; |
| 255 init_params.can_activate = true; | 263 init_params.can_activate = true; |
| 256 init_params.close_on_deactivate = true; | 264 init_params.close_on_deactivate = true; |
| 257 | 265 |
| 258 views::TrayBubbleView* bubble_view = | 266 views::TrayBubbleView* bubble_view = |
| 259 views::TrayBubbleView::Create(tray_container(), this, &init_params); | 267 views::TrayBubbleView::Create(tray_container(), this, &init_params); |
| 260 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); | 268 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); |
| 261 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 269 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 262 | 270 |
| 263 // Adds IME list to the bubble. | 271 // Adds IME list to the bubble. |
| 264 bubble_view->AddChildView( | 272 ime_list_view_ = |
| 265 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME)); | 273 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME); |
| 274 bubble_view->AddChildView(ime_list_view_); |
| 266 | 275 |
| 267 // Adds IME buttons to the bubble if needed. | 276 // Adds IME buttons to the bubble if needed. |
| 268 LoginStatus login = | 277 LoginStatus login = |
| 269 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); | 278 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); |
| 270 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && | 279 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && |
| 271 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | 280 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) |
| 272 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); | 281 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); |
| 273 | 282 |
| 274 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | 283 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
| 275 SetDrawBackgroundAsActive(true); | 284 SetDrawBackgroundAsActive(true); |
| 276 } | 285 } |
| 277 | 286 |
| 278 void ImeMenuTray::HideImeMenuBubble() { | 287 void ImeMenuTray::HideImeMenuBubble() { |
| 279 bubble_.reset(); | 288 bubble_.reset(); |
| 289 ime_list_view_ = nullptr; |
| 280 SetDrawBackgroundAsActive(false); | 290 SetDrawBackgroundAsActive(false); |
| 281 } | 291 } |
| 282 | 292 |
| 283 } // namespace ash | 293 } // namespace ash |
| OLD | NEW |