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

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: tdanderson review + rebase 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 18 matching lines...) Expand all
29 #include "ash/system/user/user_card_view.h" 29 #include "ash/system/user/user_card_view.h"
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/geometry/insets.h" 37 #include "ui/gfx/geometry/insets.h"
38 #include "ui/gfx/paint_vector_icon.h" 38 #include "ui/gfx/paint_vector_icon.h"
39 #include "ui/native_theme/native_theme.h"
39 #include "ui/views/controls/button/label_button.h" 40 #include "ui/views/controls/button/label_button.h"
40 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
41 #include "ui/views/controls/separator.h" 42 #include "ui/views/controls/separator.h"
42 #include "ui/views/layout/fill_layout.h" 43 #include "ui/views/layout/fill_layout.h"
43 #include "ui/views/painter.h" 44 #include "ui/views/painter.h"
44 45
45 namespace ash { 46 namespace ash {
46 namespace tray { 47 namespace tray {
47 48
48 namespace { 49 namespace {
(...skipping 16 matching lines...) Expand all
65 controller->SwitchActiveUser( 66 controller->SwitchActiveUser(
66 controller->GetUserSession(user_index)->account_id); 67 controller->GetUserSession(user_index)->account_id);
67 } 68 }
68 69
69 bool IsMultiProfileSupportedAndUserActive() { 70 bool IsMultiProfileSupportedAndUserActive() {
70 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && 71 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() &&
71 !Shell::Get()->session_controller()->IsUserSessionBlocked(); 72 !Shell::Get()->session_controller()->IsUserSessionBlocked();
72 } 73 }
73 74
74 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). 75 // Creates the view shown in the user switcher popup ("AddUserMenuOption").
75 views::View* CreateAddUserView(AddUserSessionPolicy policy, 76 views::View* CreateAddUserView(AddUserSessionPolicy policy) {
76 views::ButtonListener* listener) {
77 auto* view = new views::View; 77 auto* view = new views::View;
78 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; 78 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2;
79 auto* layout = 79 auto* layout =
80 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 80 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
81 kTrayPopupLabelHorizontalPadding + icon_padding); 81 kTrayPopupLabelHorizontalPadding + icon_padding);
82 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); 82 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
83 view->SetLayoutManager(layout); 83 view->SetLayoutManager(layout);
84 view->set_background( 84 view->set_background(views::Background::CreateThemedSolidBackground(
85 views::Background::CreateSolidBackground(kBackgroundColor)); 85 view, ui::NativeTheme::kColorId_BubbleBackground));
86 86
87 int message_id = 0; 87 int message_id = 0;
88 switch (policy) { 88 switch (policy) {
89 case AddUserSessionPolicy::ALLOWED: { 89 case AddUserSessionPolicy::ALLOWED: {
90 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; 90 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT;
91 91
92 auto* icon = new views::ImageView(); 92 auto* icon = new views::ImageView();
93 icon->SetImage( 93 icon->SetImage(
94 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); 94 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
95 view->AddChildView(icon); 95 view->AddChildView(icon);
(...skipping 20 matching lines...) Expand all
116 if (policy != AddUserSessionPolicy::ALLOWED) { 116 if (policy != AddUserSessionPolicy::ALLOWED) {
117 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION); 117 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION);
118 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); 118 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
119 vertical_padding += kMenuSeparatorVerticalPadding; 119 vertical_padding += kMenuSeparatorVerticalPadding;
120 } 120 }
121 label_style.SetupLabel(command_label); 121 label_style.SetupLabel(command_label);
122 view->AddChildView(command_label); 122 view->AddChildView(command_label);
123 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, 123 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding,
124 vertical_padding, 124 vertical_padding,
125 kTrayPopupLabelHorizontalPadding)); 125 kTrayPopupLabelHorizontalPadding));
126 if (policy == AddUserSessionPolicy::ALLOWED) {
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 126
134 return view; 127 return view;
135 } 128 }
136 129
137 class UserViewMouseWatcherHost : public views::MouseWatcherHost { 130 class UserViewMouseWatcherHost : public views::MouseWatcherHost {
138 public: 131 public:
139 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) 132 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area)
140 : screen_area_(screen_area) {} 133 : screen_area_(screen_area) {}
141 ~UserViewMouseWatcherHost() override {} 134 ~UserViewMouseWatcherHost() override {}
142 135
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 350
358 // Position the widget on top of the user card view (which is still in the 351 // 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 352 // system menu). The top half of the widget will be transparent to allow
360 // the active user to show through. 353 // the active user to show through.
361 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 354 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
362 bounds.set_width(bounds.width() + kSeparatorWidth); 355 bounds.set_width(bounds.width() + kSeparatorWidth);
363 int row_height = bounds.height(); 356 int row_height = bounds.height();
364 357
365 views::View* container = new AddUserWidgetContents( 358 views::View* container = new AddUserWidgetContents(
366 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); 359 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
360 views::View* add_user_view = CreateAddUserView(add_user_policy);
361 const SkColor bg_color = add_user_view->background()->get_color();
367 container->SetBorder(views::CreatePaddedBorder( 362 container->SetBorder(views::CreatePaddedBorder(
368 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, kBackgroundColor), 363 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, bg_color),
369 gfx::Insets(row_height, 0, 0, 0))); 364 gfx::Insets(row_height, 0, 0, 0)));
370 views::View* add_user_padding = new views::View(); 365 views::View* add_user_padding = new views::View();
371 add_user_padding->SetBorder(views::CreateSolidSidedBorder( 366 add_user_padding->SetBorder(views::CreateSolidSidedBorder(
372 kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor)); 367 kMenuSeparatorVerticalPadding, 0, 0, 0, bg_color));
373 views::View* add_user_view = CreateAddUserView(add_user_policy, this); 368 if (add_user_enabled_) {
374 add_user_padding->AddChildView(add_user_view); 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);
Evan Stade 2017/04/19 18:49:07 oops, this will break the button pressed handler.
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