Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ash/system/user/user_view.cc

Issue 2816193002: Introduce a type of View background that stays in sync with its host (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 controller->SwitchActiveUser( 65 controller->SwitchActiveUser(
66 controller->GetUserSession(user_index)->account_id); 66 controller->GetUserSession(user_index)->account_id);
67 } 67 }
68 68
69 bool IsMultiProfileSupportedAndUserActive() { 69 bool IsMultiProfileSupportedAndUserActive() {
70 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && 70 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() &&
71 !Shell::Get()->session_controller()->IsUserSessionBlocked(); 71 !Shell::Get()->session_controller()->IsUserSessionBlocked();
72 } 72 }
73 73
74 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). 74 // Creates the view shown in the user switcher popup ("AddUserMenuOption").
75 views::View* CreateAddUserView(AddUserSessionPolicy policy, 75 views::View* CreateAddUserView(AddUserSessionPolicy policy) {
76 views::ButtonListener* listener) {
77 auto* view = new views::View; 76 auto* view = new views::View;
78 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; 77 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2;
79 auto* layout = 78 auto* layout =
80 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 79 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
81 kTrayPopupLabelHorizontalPadding + icon_padding); 80 kTrayPopupLabelHorizontalPadding + icon_padding);
82 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); 81 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
83 view->SetLayoutManager(layout); 82 view->SetLayoutManager(layout);
84 view->set_background( 83 view->set_background(views::Background::CreateThemedSolidBackground(
85 views::Background::CreateSolidBackground(kBackgroundColor)); 84 view, ui::NativeTheme::kColorId_BubbleBackground));
86 85
87 int message_id = 0; 86 int message_id = 0;
88 switch (policy) { 87 switch (policy) {
89 case AddUserSessionPolicy::ALLOWED: { 88 case AddUserSessionPolicy::ALLOWED: {
90 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; 89 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT;
91 90
92 auto* icon = new views::ImageView(); 91 auto* icon = new views::ImageView();
93 icon->SetImage( 92 icon->SetImage(
94 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); 93 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
95 view->AddChildView(icon); 94 view->AddChildView(icon);
(...skipping 20 matching lines...) Expand all
116 if (policy != AddUserSessionPolicy::ALLOWED) { 115 if (policy != AddUserSessionPolicy::ALLOWED) {
117 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION); 116 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION);
118 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); 117 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
119 vertical_padding += kMenuSeparatorVerticalPadding; 118 vertical_padding += kMenuSeparatorVerticalPadding;
120 } 119 }
121 label_style.SetupLabel(command_label); 120 label_style.SetupLabel(command_label);
122 view->AddChildView(command_label); 121 view->AddChildView(command_label);
123 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, 122 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding,
124 vertical_padding, 123 vertical_padding,
125 kTrayPopupLabelHorizontalPadding)); 124 kTrayPopupLabelHorizontalPadding));
126 if (policy == AddUserSessionPolicy::ALLOWED) {
msw 2017/04/17 18:04:53 What are these changes? They seem unrelated...
Evan Stade 2017/04/17 19:40:05 I refactored the wrap-the-view-in-a-button bit to
msw 2017/04/17 20:05:40 Okay, I'll leave review here to tdanderson@
tdanderson 2017/04/18 19:14:46 This looks good to me.
127 auto* button =
128 new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS);
129 button->SetAccessibleName(
130 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
131 return button;
132 }
133 125
134 return view; 126 return view;
135 } 127 }
136 128
137 class UserViewMouseWatcherHost : public views::MouseWatcherHost { 129 class UserViewMouseWatcherHost : public views::MouseWatcherHost {
138 public: 130 public:
139 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) 131 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area)
140 : screen_area_(screen_area) {} 132 : screen_area_(screen_area) {}
141 ~UserViewMouseWatcherHost() override {} 133 ~UserViewMouseWatcherHost() override {}
142 134
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 349
358 // Position the widget on top of the user card view (which is still in the 350 // Position the widget on top of the user card view (which is still in the
359 // system menu). The top half of the widget will be transparent to allow 351 // system menu). The top half of the widget will be transparent to allow
360 // the active user to show through. 352 // the active user to show through.
361 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 353 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
362 bounds.set_width(bounds.width() + kSeparatorWidth); 354 bounds.set_width(bounds.width() + kSeparatorWidth);
363 int row_height = bounds.height(); 355 int row_height = bounds.height();
364 356
365 views::View* container = new AddUserWidgetContents( 357 views::View* container = new AddUserWidgetContents(
366 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); 358 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
359 views::View* add_user_view = CreateAddUserView(add_user_policy);
367 container->SetBorder(views::CreatePaddedBorder( 360 container->SetBorder(views::CreatePaddedBorder(
368 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, kBackgroundColor), 361 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth,
362 add_user_view->background()->get_color()),
tdanderson 2017/04/18 19:14:46 nit: optional: consider giving add_user_view->back
Evan Stade 2017/04/19 15:59:01 Done.
369 gfx::Insets(row_height, 0, 0, 0))); 363 gfx::Insets(row_height, 0, 0, 0)));
370 views::View* add_user_padding = new views::View(); 364 views::View* add_user_padding = new views::View();
371 add_user_padding->SetBorder(views::CreateSolidSidedBorder( 365 add_user_padding->SetBorder(
372 kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor)); 366 views::CreateSolidSidedBorder(kMenuSeparatorVerticalPadding, 0, 0, 0,
373 views::View* add_user_view = CreateAddUserView(add_user_policy, this); 367 add_user_view->background()->get_color()));
374 add_user_padding->AddChildView(add_user_view); 368 if (add_user_enabled_) {
369 auto* button = new ButtonFromView(add_user_view, this,
370 TrayPopupInkDropStyle::INSET_BOUNDS);
371 button->SetAccessibleName(
372 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
373 add_user_padding->AddChildView(button);
374 } else {
375 add_user_padding->AddChildView(add_user_view);
376 }
375 add_user_padding->SetLayoutManager(new views::FillLayout()); 377 add_user_padding->SetLayoutManager(new views::FillLayout());
376 container->AddChildView(add_user_padding); 378 container->AddChildView(add_user_padding);
377 container->SetLayoutManager(new views::FillLayout()); 379 container->SetLayoutManager(new views::FillLayout());
378 add_menu_option_->SetContentsView(container); 380 add_menu_option_->SetContentsView(container);
379 381
380 bounds.set_height(container->GetPreferredSize().height()); 382 bounds.set_height(container->GetPreferredSize().height());
381 add_menu_option_->SetBounds(bounds); 383 add_menu_option_->SetBounds(bounds);
382 384
383 // Show the content. 385 // Show the content.
384 add_menu_option_->SetAlwaysOnTop(true); 386 add_menu_option_->SetAlwaysOnTop(true);
(...skipping 11 matching lines...) Expand all
396 return; 398 return;
397 focus_manager_->RemoveFocusChangeListener(this); 399 focus_manager_->RemoveFocusChangeListener(this);
398 focus_manager_ = nullptr; 400 focus_manager_ = nullptr;
399 if (user_card_view_->GetFocusManager()) 401 if (user_card_view_->GetFocusManager())
400 user_card_view_->GetFocusManager()->ClearFocus(); 402 user_card_view_->GetFocusManager()->ClearFocus();
401 add_menu_option_.reset(); 403 add_menu_option_.reset();
402 } 404 }
403 405
404 } // namespace tray 406 } // namespace tray
405 } // namespace ash 407 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698