OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/user/user_view.h" | 5 #include "ash/system/user/user_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/multi_profile_uma.h" | 10 #include "ash/multi_profile_uma.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "ash/wm_window.h" | 30 #include "ash/wm_window.h" |
31 #include "base/memory/ptr_util.h" | 31 #include "base/memory/ptr_util.h" |
32 #include "components/signin/core/account_id/account_id.h" | 32 #include "components/signin/core/account_id/account_id.h" |
33 #include "components/user_manager/user_info.h" | 33 #include "components/user_manager/user_info.h" |
34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
37 #include "ui/gfx/color_utils.h" | 37 #include "ui/gfx/color_utils.h" |
38 #include "ui/gfx/geometry/insets.h" | 38 #include "ui/gfx/geometry/insets.h" |
39 #include "ui/gfx/paint_vector_icon.h" | 39 #include "ui/gfx/paint_vector_icon.h" |
| 40 #include "ui/native_theme/native_theme.h" |
40 #include "ui/views/controls/button/label_button.h" | 41 #include "ui/views/controls/button/label_button.h" |
41 #include "ui/views/controls/label.h" | 42 #include "ui/views/controls/label.h" |
42 #include "ui/views/controls/separator.h" | 43 #include "ui/views/controls/separator.h" |
43 #include "ui/views/layout/fill_layout.h" | 44 #include "ui/views/layout/fill_layout.h" |
44 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
45 | 46 |
46 namespace ash { | 47 namespace ash { |
47 namespace tray { | 48 namespace tray { |
48 | 49 |
49 namespace { | 50 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
66 controller->SwitchActiveUser( | 67 controller->SwitchActiveUser( |
67 controller->GetUserSession(user_index)->account_id); | 68 controller->GetUserSession(user_index)->account_id); |
68 } | 69 } |
69 | 70 |
70 bool IsMultiProfileSupportedAndUserActive() { | 71 bool IsMultiProfileSupportedAndUserActive() { |
71 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && | 72 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && |
72 !Shell::Get()->session_controller()->IsUserSessionBlocked(); | 73 !Shell::Get()->session_controller()->IsUserSessionBlocked(); |
73 } | 74 } |
74 | 75 |
75 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). | 76 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). |
76 views::View* CreateAddUserView(AddUserSessionPolicy policy, | 77 views::View* CreateAddUserView(AddUserSessionPolicy policy) { |
77 views::ButtonListener* listener) { | |
78 auto* view = new views::View; | 78 auto* view = new views::View; |
79 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; | 79 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; |
80 auto* layout = | 80 auto* layout = |
81 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 81 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
82 kTrayPopupLabelHorizontalPadding + icon_padding); | 82 kTrayPopupLabelHorizontalPadding + icon_padding); |
83 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); | 83 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
84 view->SetLayoutManager(layout); | 84 view->SetLayoutManager(layout); |
85 view->set_background( | 85 view->set_background(views::Background::CreateThemedSolidBackground( |
86 views::Background::CreateSolidBackground(kBackgroundColor)); | 86 view, ui::NativeTheme::kColorId_BubbleBackground)); |
87 | 87 |
88 int message_id = 0; | 88 int message_id = 0; |
89 switch (policy) { | 89 switch (policy) { |
90 case AddUserSessionPolicy::ALLOWED: { | 90 case AddUserSessionPolicy::ALLOWED: { |
91 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; | 91 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; |
92 | 92 |
93 auto* icon = new views::ImageView(); | 93 auto* icon = new views::ImageView(); |
94 icon->SetImage( | 94 icon->SetImage( |
95 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); | 95 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); |
96 view->AddChildView(icon); | 96 view->AddChildView(icon); |
(...skipping 20 matching lines...) Expand all Loading... |
117 if (policy != AddUserSessionPolicy::ALLOWED) { | 117 if (policy != AddUserSessionPolicy::ALLOWED) { |
118 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION); | 118 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION); |
119 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); | 119 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); |
120 vertical_padding += kMenuSeparatorVerticalPadding; | 120 vertical_padding += kMenuSeparatorVerticalPadding; |
121 } | 121 } |
122 label_style.SetupLabel(command_label); | 122 label_style.SetupLabel(command_label); |
123 view->AddChildView(command_label); | 123 view->AddChildView(command_label); |
124 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, | 124 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, |
125 vertical_padding, | 125 vertical_padding, |
126 kTrayPopupLabelHorizontalPadding)); | 126 kTrayPopupLabelHorizontalPadding)); |
127 if (policy == AddUserSessionPolicy::ALLOWED) { | |
128 auto* button = | |
129 new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS); | |
130 button->SetAccessibleName( | |
131 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | |
132 return button; | |
133 } | |
134 | 127 |
135 return view; | 128 return view; |
136 } | 129 } |
137 | 130 |
138 class UserViewMouseWatcherHost : public views::MouseWatcherHost { | 131 class UserViewMouseWatcherHost : public views::MouseWatcherHost { |
139 public: | 132 public: |
140 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) | 133 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) |
141 : screen_area_(screen_area) {} | 134 : screen_area_(screen_area) {} |
142 ~UserViewMouseWatcherHost() override {} | 135 ~UserViewMouseWatcherHost() override {} |
143 | 136 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 214 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
222 SetLayoutManager(layout); | 215 SetLayoutManager(layout); |
223 layout->set_cross_axis_alignment( | 216 layout->set_cross_axis_alignment( |
224 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 217 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
225 layout->SetFlexForView(user_card_container_, 1); | 218 layout->SetFlexForView(user_card_container_, 1); |
226 | 219 |
227 SetBorder(base::MakeUnique<ActiveUserBorder>()); | 220 SetBorder(base::MakeUnique<ActiveUserBorder>()); |
228 } | 221 } |
229 | 222 |
230 UserView::~UserView() { | 223 UserView::~UserView() { |
231 RemoveAddUserMenuOption(); | 224 HideUserDropdownWidget(); |
232 } | 225 } |
233 | 226 |
234 TrayUser::TestState UserView::GetStateForTest() const { | 227 TrayUser::TestState UserView::GetStateForTest() const { |
235 if (add_menu_option_) | 228 if (user_dropdown_widget_) |
236 return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED; | 229 return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED; |
237 | 230 |
238 // If the container is the user card view itself, there's no ButtonFromView | 231 // If the container is the user card view itself, there's no ButtonFromView |
239 // wrapping it. | 232 // wrapping it. |
240 if (user_card_container_ == user_card_view_) | 233 if (user_card_container_ == user_card_view_) |
241 return TrayUser::SHOWN; | 234 return TrayUser::SHOWN; |
242 | 235 |
243 return static_cast<ButtonFromView*>(user_card_container_) | 236 return static_cast<ButtonFromView*>(user_card_container_) |
244 ->is_hovered_for_test() | 237 ->is_hovered_for_test() |
245 ? TrayUser::HOVERED | 238 ? TrayUser::HOVERED |
246 : TrayUser::SHOWN; | 239 : TrayUser::SHOWN; |
247 } | 240 } |
248 | 241 |
249 gfx::Rect UserView::GetBoundsInScreenOfUserButtonForTest() { | 242 gfx::Rect UserView::GetBoundsInScreenOfUserButtonForTest() { |
250 return user_card_container_->GetBoundsInScreen(); | 243 return user_card_container_->GetBoundsInScreen(); |
251 } | 244 } |
252 | 245 |
253 int UserView::GetHeightForWidth(int width) const { | 246 int UserView::GetHeightForWidth(int width) const { |
254 return GetPreferredSize().height(); | 247 return GetPreferredSize().height(); |
255 } | 248 } |
256 | 249 |
257 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 250 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
258 if (sender == logout_button_) { | 251 if (sender == logout_button_) { |
259 ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT); | 252 ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT); |
260 RemoveAddUserMenuOption(); | 253 HideUserDropdownWidget(); |
261 Shell::Get()->system_tray_controller()->SignOut(); | 254 Shell::Get()->system_tray_controller()->SignOut(); |
262 } else if (sender == user_card_container_ && | 255 } else if (sender == user_card_container_ && |
263 IsMultiProfileSupportedAndUserActive()) { | 256 IsMultiProfileSupportedAndUserActive()) { |
264 ToggleAddUserMenuOption(); | 257 ToggleUserDropdownWidget(); |
265 } else if (add_menu_option_ && | 258 } else if (user_dropdown_widget_ && |
266 sender->GetWidget() == add_menu_option_.get()) { | 259 sender->GetWidget() == user_dropdown_widget_.get()) { |
267 DCHECK_EQ(Shell::Get()->session_controller()->NumberOfLoggedInUsers(), | 260 DCHECK_EQ(Shell::Get()->session_controller()->NumberOfLoggedInUsers(), |
268 sender->parent()->child_count() - 1); | 261 sender->parent()->child_count() - 1); |
269 const int index_in_add_menu = sender->parent()->GetIndexOf(sender); | 262 const int index_in_add_menu = sender->parent()->GetIndexOf(sender); |
270 // The last item is the "sign in another user" row. | 263 // The last item is the "sign in another user" row. |
271 if (index_in_add_menu == sender->parent()->child_count() - 1) { | 264 if (index_in_add_menu == sender->parent()->child_count() - 1) { |
272 MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY); | 265 MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY); |
273 Shell::Get()->system_tray_delegate()->ShowUserLogin(); | 266 Shell::Get()->system_tray_delegate()->ShowUserLogin(); |
274 } else { | 267 } else { |
275 const int user_index = index_in_add_menu; | 268 const int user_index = index_in_add_menu; |
276 SwitchUser(user_index); | 269 SwitchUser(user_index); |
277 } | 270 } |
278 RemoveAddUserMenuOption(); | 271 HideUserDropdownWidget(); |
279 owner_->system_tray()->CloseSystemBubble(); | 272 owner_->system_tray()->CloseSystemBubble(); |
280 } else { | 273 } else { |
281 NOTREACHED(); | 274 NOTREACHED(); |
282 } | 275 } |
283 } | 276 } |
284 | 277 |
285 void UserView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 278 void UserView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
286 if (focused_now) | 279 if (focused_now) |
287 RemoveAddUserMenuOption(); | 280 HideUserDropdownWidget(); |
288 } | 281 } |
289 | 282 |
290 void UserView::OnDidChangeFocus(View* focused_before, View* focused_now) { | 283 void UserView::OnDidChangeFocus(View* focused_before, View* focused_now) { |
291 // Nothing to do here. | 284 // Nothing to do here. |
292 } | 285 } |
293 | 286 |
294 void UserView::AddLogoutButton(LoginStatus login) { | 287 void UserView::AddLogoutButton(LoginStatus login) { |
295 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | 288 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
296 logout_button_ = TrayPopupUtils::CreateTrayPopupBorderlessButton( | 289 logout_button_ = TrayPopupUtils::CreateTrayPopupBorderlessButton( |
297 this, user::GetLocalizedSignOutStringForStatus(login, true)); | 290 this, user::GetLocalizedSignOutStringForStatus(login, true)); |
298 AddChildView(logout_button_); | 291 AddChildView(logout_button_); |
299 } | 292 } |
300 | 293 |
301 void UserView::AddUserCard(LoginStatus login) { | 294 void UserView::AddUserCard(LoginStatus login) { |
302 DCHECK(!user_card_container_); | 295 DCHECK(!user_card_container_); |
303 DCHECK(!user_card_view_); | 296 DCHECK(!user_card_view_); |
304 user_card_view_ = new UserCardView(login, 0); | 297 user_card_view_ = new UserCardView(login, 0); |
305 // The entry is clickable when no system modal dialog is open and the multi | 298 // The entry is clickable when no system modal dialog is open and the multi |
306 // profile option is active. | 299 // profile option is active. |
307 if (!ShellPort::Get()->IsSystemModalWindowOpen() && | 300 if (!ShellPort::Get()->IsSystemModalWindowOpen() && |
308 IsMultiProfileSupportedAndUserActive()) { | 301 IsMultiProfileSupportedAndUserActive()) { |
309 user_card_container_ = new ButtonFromView( | 302 user_card_container_ = new ButtonFromView( |
310 user_card_view_, this, TrayPopupInkDropStyle::INSET_BOUNDS); | 303 user_card_view_, this, TrayPopupInkDropStyle::INSET_BOUNDS); |
311 } else { | 304 } else { |
312 user_card_container_ = user_card_view_; | 305 user_card_container_ = user_card_view_; |
313 } | 306 } |
314 AddChildViewAt(user_card_container_, 0); | 307 AddChildViewAt(user_card_container_, 0); |
315 } | 308 } |
316 | 309 |
317 void UserView::ToggleAddUserMenuOption() { | 310 void UserView::ToggleUserDropdownWidget() { |
318 if (add_menu_option_) { | 311 if (user_dropdown_widget_) { |
319 RemoveAddUserMenuOption(); | 312 HideUserDropdownWidget(); |
320 return; | 313 return; |
321 } | 314 } |
322 | 315 |
323 // Note: We do not need to install a global event handler to delete this | 316 // Note: We do not need to install a global event handler to delete this |
324 // item since it will destroyed automatically before the menu / user menu item | 317 // item since it will destroyed automatically before the menu / user menu item |
325 // gets destroyed.. | 318 // gets destroyed.. |
326 add_menu_option_.reset(new views::Widget); | 319 user_dropdown_widget_.reset(new views::Widget); |
327 views::Widget::InitParams params; | 320 views::Widget::InitParams params; |
328 params.type = views::Widget::InitParams::TYPE_MENU; | 321 params.type = views::Widget::InitParams::TYPE_MENU; |
329 params.keep_on_top = true; | 322 params.keep_on_top = true; |
330 params.accept_events = true; | 323 params.accept_events = true; |
331 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 324 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
332 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 325 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
333 params.name = "AddUserMenuOption"; | 326 params.name = "AddUserMenuOption"; |
334 WmWindow::Get(GetWidget()->GetNativeWindow()) | 327 WmWindow::Get(GetWidget()->GetNativeWindow()) |
335 ->GetRootWindowController() | 328 ->GetRootWindowController() |
336 ->ConfigureWidgetInitParamsForContainer( | 329 ->ConfigureWidgetInitParamsForContainer( |
337 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, | 330 user_dropdown_widget_.get(), |
338 ¶ms); | 331 kShellWindowId_DragImageAndTooltipContainer, ¶ms); |
339 add_menu_option_->Init(params); | 332 user_dropdown_widget_->Init(params); |
340 | 333 |
341 const SessionController* const session_controller = | 334 const SessionController* const session_controller = |
342 Shell::Get()->session_controller(); | 335 Shell::Get()->session_controller(); |
343 const AddUserSessionPolicy add_user_policy = | 336 const AddUserSessionPolicy add_user_policy = |
344 session_controller->GetAddUserPolicy(); | 337 session_controller->GetAddUserPolicy(); |
345 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; | 338 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; |
346 | 339 |
347 // Position the widget on top of the user card view (which is still in the | 340 // Position the widget on top of the user card view (which is still in the |
348 // system menu). The top half of the widget will be transparent to allow | 341 // system menu). The top half of the widget will be transparent to allow |
349 // the active user to show through. | 342 // the active user to show through. |
350 gfx::Rect bounds = user_card_container_->GetBoundsInScreen(); | 343 gfx::Rect bounds = user_card_container_->GetBoundsInScreen(); |
351 bounds.set_width(bounds.width() + kSeparatorWidth); | 344 bounds.set_width(bounds.width() + kSeparatorWidth); |
352 int row_height = bounds.height(); | 345 int row_height = bounds.height(); |
353 | 346 |
354 views::View* container = new UserDropdownWidgetContents( | 347 views::View* container = new UserDropdownWidgetContents( |
355 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); | 348 base::Bind(&UserView::HideUserDropdownWidget, base::Unretained(this))); |
| 349 views::View* add_user_view = CreateAddUserView(add_user_policy); |
| 350 const SkColor bg_color = add_user_view->background()->get_color(); |
356 container->SetBorder(views::CreatePaddedBorder( | 351 container->SetBorder(views::CreatePaddedBorder( |
357 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, kBackgroundColor), | 352 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, bg_color), |
358 gfx::Insets(row_height, 0, 0, 0))); | 353 gfx::Insets(row_height, 0, 0, 0))); |
| 354 |
| 355 // Create the contents aside from the empty window through which the active |
| 356 // user is seen. |
359 views::View* user_dropdown_padding = new views::View(); | 357 views::View* user_dropdown_padding = new views::View(); |
360 user_dropdown_padding->SetBorder(views::CreateSolidSidedBorder( | 358 user_dropdown_padding->SetBorder(views::CreateSolidSidedBorder( |
361 kMenuSeparatorVerticalPadding - kSeparatorWidth, 0, 0, 0, | 359 kMenuSeparatorVerticalPadding - kSeparatorWidth, 0, 0, 0, bg_color)); |
362 kBackgroundColor)); | |
363 user_dropdown_padding->SetLayoutManager( | 360 user_dropdown_padding->SetLayoutManager( |
364 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 361 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
365 views::Separator* separator = new views::Separator(); | 362 views::Separator* separator = new views::Separator(); |
366 separator->SetPreferredHeight(kSeparatorWidth); | 363 separator->SetPreferredHeight(kSeparatorWidth); |
367 separator->SetColor(color_utils::GetResultingPaintColor(kMenuSeparatorColor, | 364 separator->SetColor( |
368 kBackgroundColor)); | 365 color_utils::GetResultingPaintColor(kMenuSeparatorColor, bg_color)); |
369 const int separator_horizontal_padding = | 366 const int separator_horizontal_padding = |
370 (kTrayPopupItemMinStartWidth - kTrayItemSize) / 2; | 367 (kTrayPopupItemMinStartWidth - kTrayItemSize) / 2; |
371 separator->SetBorder(views::CreateSolidSidedBorder( | 368 separator->SetBorder( |
372 0, separator_horizontal_padding, 0, separator_horizontal_padding, | 369 views::CreateSolidSidedBorder(0, separator_horizontal_padding, 0, |
373 kBackgroundColor)); | 370 separator_horizontal_padding, bg_color)); |
374 user_dropdown_padding->AddChildView(separator); | 371 user_dropdown_padding->AddChildView(separator); |
375 | 372 |
| 373 // Add other logged in users. |
376 for (int i = 1; i < session_controller->NumberOfLoggedInUsers(); ++i) { | 374 for (int i = 1; i < session_controller->NumberOfLoggedInUsers(); ++i) { |
377 user_dropdown_padding->AddChildView( | 375 user_dropdown_padding->AddChildView( |
378 new ButtonFromView(new UserCardView(LoginStatus::USER, i), this, | 376 new ButtonFromView(new UserCardView(LoginStatus::USER, i), this, |
379 TrayPopupInkDropStyle::INSET_BOUNDS)); | 377 TrayPopupInkDropStyle::INSET_BOUNDS)); |
380 } | 378 } |
381 | 379 |
382 user_dropdown_padding->AddChildView(CreateAddUserView(add_user_policy, this)); | 380 // Add the "add user" option or the "can't add another user" message. |
| 381 if (add_user_enabled_) { |
| 382 auto* button = new ButtonFromView(add_user_view, this, |
| 383 TrayPopupInkDropStyle::INSET_BOUNDS); |
| 384 button->SetAccessibleName( |
| 385 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
| 386 user_dropdown_padding->AddChildView(button); |
| 387 } else { |
| 388 user_dropdown_padding->AddChildView(add_user_view); |
| 389 } |
| 390 |
383 container->AddChildView(user_dropdown_padding); | 391 container->AddChildView(user_dropdown_padding); |
384 container->SetLayoutManager(new views::FillLayout()); | 392 container->SetLayoutManager(new views::FillLayout()); |
385 add_menu_option_->SetContentsView(container); | 393 user_dropdown_widget_->SetContentsView(container); |
386 | 394 |
387 bounds.set_height(container->GetPreferredSize().height()); | 395 bounds.set_height(container->GetPreferredSize().height()); |
388 add_menu_option_->SetBounds(bounds); | 396 user_dropdown_widget_->SetBounds(bounds); |
389 | 397 |
390 // Suppress the appearance of the collective capture icon while the dropdown | 398 // Suppress the appearance of the collective capture icon while the dropdown |
391 // is open (the icon will appear in the specific user rows). | 399 // is open (the icon will appear in the specific user rows). |
392 user_card_view_->SetSuppressCaptureIcon(true); | 400 user_card_view_->SetSuppressCaptureIcon(true); |
393 | 401 |
394 // Show the content. | 402 // Show the content. |
395 add_menu_option_->SetAlwaysOnTop(true); | 403 user_dropdown_widget_->SetAlwaysOnTop(true); |
396 add_menu_option_->Show(); | 404 user_dropdown_widget_->Show(); |
397 | 405 |
398 // Install a listener to focus changes so that we can remove the card when | 406 // Install a listener to focus changes so that we can remove the card when |
399 // the focus gets changed. When called through the destruction of the bubble, | 407 // the focus gets changed. When called through the destruction of the bubble, |
400 // the FocusManager cannot be determined anymore and we remember it here. | 408 // the FocusManager cannot be determined anymore and we remember it here. |
401 focus_manager_ = user_card_container_->GetFocusManager(); | 409 focus_manager_ = user_card_container_->GetFocusManager(); |
402 focus_manager_->AddFocusChangeListener(this); | 410 focus_manager_->AddFocusChangeListener(this); |
403 } | 411 } |
404 | 412 |
405 void UserView::RemoveAddUserMenuOption() { | 413 void UserView::HideUserDropdownWidget() { |
406 if (!add_menu_option_) | 414 if (!user_dropdown_widget_) |
407 return; | 415 return; |
408 focus_manager_->RemoveFocusChangeListener(this); | 416 focus_manager_->RemoveFocusChangeListener(this); |
409 focus_manager_ = nullptr; | 417 focus_manager_ = nullptr; |
410 if (user_card_container_->GetFocusManager()) | 418 if (user_card_container_->GetFocusManager()) |
411 user_card_container_->GetFocusManager()->ClearFocus(); | 419 user_card_container_->GetFocusManager()->ClearFocus(); |
412 user_card_view_->SetSuppressCaptureIcon(false); | 420 user_card_view_->SetSuppressCaptureIcon(false); |
413 add_menu_option_.reset(); | 421 user_dropdown_widget_.reset(); |
414 } | 422 } |
415 | 423 |
416 } // namespace tray | 424 } // namespace tray |
417 } // namespace ash | 425 } // namespace ash |
OLD | NEW |