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