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

Unified Diff: ash/common/system/user/user_view.cc

Issue 2678353005: Remove pre-MD code related to tray/menu user profiles. (Closed)
Patch Set: back out a11y changes and rebase Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/system/user/user_view.h ('k') | ash/resources/ash_resources.grd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/system/user/user_view.cc
diff --git a/ash/common/system/user/user_view.cc b/ash/common/system/user/user_view.cc
index 0810d2ce43baef7fa271fb58a3b57b78175e8bb4..c5c238e1159731f02623a14081db69195ecddf3a 100644
--- a/ash/common/system/user/user_view.cc
+++ b/ash/common/system/user/user_view.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include <utility>
-#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/multi_profile_uma.h"
#include "ash/common/popup_message.h"
#include "ash/common/session/session_state_delegate.h"
@@ -42,7 +41,6 @@
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/fill_layout.h"
-#include "ui/views/mouse_watcher_view_host.h"
#include "ui/views/painter.h"
namespace ash {
@@ -50,17 +48,6 @@ namespace tray {
namespace {
-bool UseMd() {
- return MaterialDesignController::IsSystemTrayMenuMaterial();
-}
-
-// When a hover border is used, it is starting this many pixels before the icon
-// position.
-const int kTrayUserTileHoverBorderInset = 10;
-
-// Offsetting the popup message relative to the tray menu.
-const int kPopupMessageOffset = 25;
-
// Switch to a user with the given |user_index|.
void SwitchUser(UserIndex user_index) {
// Do not switch users when the log screen is presented.
@@ -82,7 +69,6 @@ bool IsMultiProfileSupportedAndUserActive() {
// Creates the view shown in the user switcher popup ("AddUserMenuOption").
views::View* CreateAddUserView(AddUserSessionPolicy policy,
views::ButtonListener* listener) {
- DCHECK(UseMd());
auto view = new views::View;
const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2;
auto layout =
@@ -135,8 +121,7 @@ views::View* CreateAddUserView(AddUserSessionPolicy policy,
kTrayPopupLabelHorizontalPadding));
if (policy == AddUserSessionPolicy::ALLOWED) {
auto button =
- new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS,
- false, gfx::Insets());
+ new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS);
button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
return button;
@@ -191,78 +176,6 @@ class AddUserWidgetContents : public views::View {
DISALLOW_COPY_AND_ASSIGN(AddUserWidgetContents);
};
-// The menu item view which gets shown when the user clicks in multi profile
-// mode onto the user item.
-class AddUserView : public views::View {
- public:
- // The |owner| is the view for which this view gets created.
- AddUserView(ButtonFromView* owner);
- ~AddUserView() override;
-
- // Get the anchor view for a message.
- views::View* anchor() { return anchor_; }
-
- private:
- // Overridden from views::View.
- gfx::Size GetPreferredSize() const override;
-
- // Create the additional client content for this item.
- void AddContent();
-
- // This is the content we create and show.
- views::View* add_user_;
-
- // This is the owner view of this item.
- ButtonFromView* owner_;
-
- // The anchor view for targetted bubble messages.
- views::View* anchor_;
-
- DISALLOW_COPY_AND_ASSIGN(AddUserView);
-};
-
-AddUserView::AddUserView(ButtonFromView* owner)
- : add_user_(nullptr), owner_(owner), anchor_(nullptr) {
- DCHECK(!UseMd());
- AddContent();
- owner_->ForceBorderVisible(true);
-}
-
-AddUserView::~AddUserView() {
- owner_->ForceBorderVisible(false);
-}
-
-gfx::Size AddUserView::GetPreferredSize() const {
- return owner_->bounds().size();
-}
-
-void AddUserView::AddContent() {
- SetLayoutManager(new views::FillLayout());
- set_background(views::Background::CreateSolidBackground(kBackgroundColor));
-
- add_user_ = new views::View;
- add_user_->SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
- AddChildViewAt(add_user_, 0);
-
- // Add the icon which is also the anchor for messages.
- add_user_->SetBorder(
- views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
- RoundedImageView* icon = new RoundedImageView(kTrayRoundedBorderRadius, true);
- anchor_ = icon;
- icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
- .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER)
- .ToImageSkia(),
- gfx::Size(kTrayItemSize, kTrayItemSize));
- add_user_->AddChildView(icon);
-
- // Add the command text.
- views::Label* command_label = new views::Label(
- l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
- command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- add_user_->AddChildView(command_label);
-}
-
// This border reserves 4dp above and 8dp below and paints a horizontal
// separator 3dp below the host view.
class ActiveUserBorder : public views::Border {
@@ -302,11 +215,6 @@ UserView::UserView(SystemTrayItem* owner, LoginStatus login, UserIndex index)
add_user_enabled_(true),
focus_manager_(nullptr) {
CHECK_NE(LoginStatus::NOT_LOGGED_IN, login);
- if (!UseMd() && !index && login == LoginStatus::PUBLIC) {
- // Public user gets a yellow bg.
- set_background(views::Background::CreateSolidBackground(
- kPublicAccountBackgroundColor));
- }
// The logout button must be added before the user card so that the user card
// can correctly calculate the remaining available width.
// Note that only the current multiprofile user gets a button.
@@ -314,27 +222,20 @@ UserView::UserView(SystemTrayItem* owner, LoginStatus login, UserIndex index)
AddLogoutButton(login);
AddUserCard(login);
- if (UseMd()) {
- auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
- SetLayoutManager(layout);
- layout->set_cross_axis_alignment(
- views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
- layout->SetFlexForView(user_card_view_, 1);
+ auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
+ SetLayoutManager(layout);
+ layout->set_cross_axis_alignment(
+ views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ layout->SetFlexForView(user_card_view_, 1);
- if (IsActiveUser())
- SetBorder(base::MakeUnique<ActiveUserBorder>());
- }
+ if (IsActiveUser())
+ SetBorder(base::MakeUnique<ActiveUserBorder>());
}
UserView::~UserView() {
RemoveAddUserMenuOption();
}
-void UserView::MouseMovedOutOfHost() {
- DCHECK(!UseMd());
- RemoveAddUserMenuOption();
-}
-
TrayUser::TestState UserView::GetStateForTest() const {
if (add_menu_option_.get()) {
return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED;
@@ -357,75 +258,10 @@ bool UserView::IsActiveUser() const {
return user_index_ == 0;
}
-gfx::Size UserView::GetPreferredSize() const {
- // MD uses a layout manager.
- if (UseMd())
- return View::GetPreferredSize();
-
- // The width is more or less ignored (set by other rows in the system menu).
- gfx::Size size = user_card_view_->GetPreferredSize();
- if (logout_button_)
- size.SetToMax(logout_button_->GetPreferredSize());
- // Only the active user panel will be forced to a certain height.
- if (IsActiveUser()) {
- size.set_height(std::max(
- size.height(),
- GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT) + GetInsets().height()));
- }
- return size;
-}
-
int UserView::GetHeightForWidth(int width) const {
return GetPreferredSize().height();
}
-void UserView::Layout() {
- // MD uses a layout manager.
- if (UseMd())
- return views::View::Layout();
-
- gfx::Rect contents_area(GetContentsBounds());
- if (logout_button_) {
- // Give the logout button the space it requests.
- gfx::Rect logout_area = contents_area;
- logout_area.ClampToCenteredSize(logout_button_->GetPreferredSize());
- logout_area.set_x(contents_area.right() - logout_area.width());
-
- // Give the remaining space to the user card.
- gfx::Rect user_card_area = contents_area;
- int remaining_width = contents_area.width() - logout_area.width();
- if (IsMultiProfileSupportedAndUserActive()) {
- // In multiprofile case |user_card_view_| and |logout_button_| have to
- // have the same height.
- int y = std::min(user_card_area.y(), logout_area.y());
- int height = std::max(user_card_area.height(), logout_area.height());
- logout_area.set_y(y);
- logout_area.set_height(height);
- user_card_area.set_y(y);
- user_card_area.set_height(height);
-
- // In multiprofile mode we have also to increase the size of the card by
- // the size of the border to make it overlap with the logout button.
- user_card_area.set_width(std::max(0, remaining_width + 1));
-
- // To make the logout button symmetrical with the user card we also make
- // the button longer by the same size the hover area in front of the icon
- // got inset.
- logout_area.set_width(logout_area.width() +
- kTrayUserTileHoverBorderInset);
- } else {
- // In all other modes we have to make sure that there is enough spacing
- // between the two.
- remaining_width -= kTrayPopupPaddingBetweenItems;
- }
- user_card_area.set_width(remaining_width);
- user_card_view_->SetBoundsRect(user_card_area);
- logout_button_->SetBoundsRect(logout_area);
- } else {
- user_card_view_->SetBoundsRect(contents_area);
- }
-}
-
void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
if (sender == logout_button_) {
WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT);
@@ -471,67 +307,6 @@ void UserView::AddLogoutButton(LoginStatus login) {
}
void UserView::AddUserCard(LoginStatus login) {
- if (UseMd())
- return AddUserCardMd(login);
-
- // Add padding around the panel.
- const int kSidePadding = kTrayPopupPaddingHorizontal;
- SetBorder(views::CreateEmptyBorder(
- kTrayPopupUserCardVerticalPadding, kSidePadding,
- kTrayPopupUserCardVerticalPadding, kSidePadding));
-
- views::TrayBubbleView* bubble_view =
- owner_->system_tray()->GetSystemBubble()->bubble_view();
- int max_card_width = bubble_view->GetMaximumSize().width() -
- (2 * kSidePadding + kTrayPopupPaddingBetweenItems);
- if (logout_button_)
- max_card_width -= logout_button_->GetPreferredSize().width();
- user_card_view_ = new UserCardView(login, max_card_width, user_index_);
- // The entry is clickable when no system modal dialog is open and the multi
- // profile option is active.
- bool clickable = !WmShell::Get()->IsSystemModalWindowOpen() &&
- IsMultiProfileSupportedAndUserActive();
- if (clickable) {
- // To allow the border to start before the icon, reduce the size before and
- // add an inset to the icon to get the spacing.
- if (IsActiveUser()) {
- SetBorder(views::CreateEmptyBorder(
- kTrayPopupUserCardVerticalPadding,
- kSidePadding - kTrayUserTileHoverBorderInset,
- kTrayPopupUserCardVerticalPadding, kSidePadding));
- user_card_view_->SetBorder(
- views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
- }
- gfx::Insets insets = gfx::Insets(1, 1, 1, 1);
- views::View* contents_view = user_card_view_;
- if (!IsActiveUser()) {
- // Since the activation border needs to be drawn around the tile, we
- // have to put the tile into another view which fills the menu panel,
- // but keeping the offsets of the content.
- contents_view = new views::View();
- contents_view->SetBorder(views::CreateEmptyBorder(
- kTrayPopupUserCardVerticalPadding, kSidePadding,
- kTrayPopupUserCardVerticalPadding, kSidePadding));
- contents_view->SetLayoutManager(new views::FillLayout());
- SetBorder(nullptr);
- contents_view->AddChildView(user_card_view_);
- insets = gfx::Insets(1, 1, 1, 3);
- }
- auto* button = new ButtonFromView(contents_view, this,
- // This parameter is ignored in non-md.
- TrayPopupInkDropStyle::FILL_BOUNDS,
- IsActiveUser(), insets);
- user_card_view_ = button;
- is_user_card_button_ = true;
- }
- AddChildViewAt(user_card_view_, 0);
- // Card for supervised user can consume more space than currently
- // available. In that case we should increase system bubble's width.
- if (login == LoginStatus::PUBLIC)
- bubble_view->SetWidth(GetPreferredSize().width());
-}
-
-void UserView::AddUserCardMd(LoginStatus login) {
user_card_view_ = new UserCardView(login, -1, user_index_);
// The entry is clickable when no system modal dialog is open and the multi
// profile option is active.
@@ -542,8 +317,7 @@ void UserView::AddUserCardMd(LoginStatus login) {
auto* button =
new ButtonFromView(contents_view, this,
IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS
- : TrayPopupInkDropStyle::FILL_BOUNDS,
- false, gfx::Insets());
+ : TrayPopupInkDropStyle::FILL_BOUNDS);
user_card_view_ = button;
is_user_card_button_ = true;
}
@@ -565,8 +339,6 @@ void UserView::ToggleAddUserMenuOption() {
params.keep_on_top = true;
params.accept_events = true;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- if (!UseMd())
- params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.name = "AddUserMenuOption";
WmLookup::Get()
@@ -583,104 +355,41 @@ void UserView::ToggleAddUserMenuOption() {
delegate->GetAddUserSessionPolicy();
add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED;
- if (UseMd()) {
- // Position the widget on top of the user card view (which is still in the
- // system menu). The top half of the widget will be transparent to allow
- // the active user to show through.
- gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
- bounds.set_width(bounds.width() + kSeparatorWidth);
- int row_height = bounds.height();
-
- views::View* container = new AddUserWidgetContents(
- base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
- container->SetBorder(views::CreatePaddedBorder(
- views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth,
- kBackgroundColor),
- gfx::Insets(row_height, 0, 0, 0)));
- views::View* add_user_padding = new views::View();
- add_user_padding->SetBorder(views::CreateSolidSidedBorder(
- kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor));
- views::View* add_user_view = CreateAddUserView(add_user_policy, this);
- add_user_padding->AddChildView(add_user_view);
- add_user_padding->SetLayoutManager(new views::FillLayout());
- container->AddChildView(add_user_padding);
- container->SetLayoutManager(new views::FillLayout());
- add_menu_option_->SetContentsView(container);
-
- bounds.set_height(container->GetPreferredSize().height());
- add_menu_option_->SetBounds(bounds);
-
- // Show the content.
- add_menu_option_->SetAlwaysOnTop(true);
- add_menu_option_->Show();
-
- // We activate the entry automatically if invoked with focus.
- if (add_user_enabled_ && user_card_view_->HasFocus()) {
- add_user_view->GetFocusManager()->SetFocusedView(add_user_view);
- user_card_view_->GetFocusManager()->SetFocusedView(add_user_view);
- }
- } else {
- AddUserView* add_user_view =
- new AddUserView(static_cast<ButtonFromView*>(user_card_view_));
- ButtonFromView* button = new ButtonFromView(
- add_user_view, add_user_enabled_ ? this : nullptr,
- // Ignored in non-md.
- TrayPopupInkDropStyle::INSET_BOUNDS, add_user_enabled_, gfx::Insets(1));
- button->SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
- button->ForceBorderVisible(true);
-
- add_menu_option_->SetOpacity(1.f);
- add_menu_option_->SetContentsView(button);
- // Position it below our user card.
- gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
- bounds.set_y(bounds.y() + bounds.height());
- add_menu_option_->SetBounds(bounds);
-
- // Show the content.
- add_menu_option_->SetAlwaysOnTop(true);
- add_menu_option_->Show();
-
- if (add_user_enabled_) {
- // We activate the entry automatically if invoked with focus.
- if (user_card_view_->HasFocus()) {
- button->GetFocusManager()->SetFocusedView(button);
- user_card_view_->GetFocusManager()->SetFocusedView(button);
- }
- } else {
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- int message_id = 0;
- switch (add_user_policy) {
- case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER:
- message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
- break;
- case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED:
- message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
- break;
- case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS:
- message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
- break;
- default:
- NOTREACHED() << "Unknown adding user policy "
- << static_cast<int>(add_user_policy);
- }
-
- popup_message_.reset(new PopupMessage(
- bundle.GetLocalizedString(
- IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
- bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING,
- add_user_view->anchor(), views::BubbleBorder::TOP_LEFT,
- gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
- 2 * kPopupMessageOffset));
- }
- // Find the screen area which encloses both elements and sets then a mouse
- // watcher which will close the "menu".
- gfx::Rect area = user_card_view_->GetBoundsInScreen();
- area.set_height(2 * area.height());
- mouse_watcher_.reset(
- new views::MouseWatcher(new UserViewMouseWatcherHost(area), this));
- mouse_watcher_->Start();
+ // Position the widget on top of the user card view (which is still in the
+ // system menu). The top half of the widget will be transparent to allow
+ // the active user to show through.
+ gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
+ bounds.set_width(bounds.width() + kSeparatorWidth);
+ int row_height = bounds.height();
+
+ views::View* container = new AddUserWidgetContents(
+ base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
+ container->SetBorder(views::CreatePaddedBorder(
+ views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, kBackgroundColor),
+ gfx::Insets(row_height, 0, 0, 0)));
+ views::View* add_user_padding = new views::View();
+ add_user_padding->SetBorder(views::CreateSolidSidedBorder(
+ kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor));
+ views::View* add_user_view = CreateAddUserView(add_user_policy, this);
+ add_user_padding->AddChildView(add_user_view);
+ add_user_padding->SetLayoutManager(new views::FillLayout());
+ container->AddChildView(add_user_padding);
+ container->SetLayoutManager(new views::FillLayout());
+ add_menu_option_->SetContentsView(container);
+
+ bounds.set_height(container->GetPreferredSize().height());
+ add_menu_option_->SetBounds(bounds);
+
+ // Show the content.
+ add_menu_option_->SetAlwaysOnTop(true);
+ add_menu_option_->Show();
+
+ // We activate the entry automatically if invoked with focus.
+ if (add_user_enabled_ && user_card_view_->HasFocus()) {
+ add_user_view->GetFocusManager()->SetFocusedView(add_user_view);
+ user_card_view_->GetFocusManager()->SetFocusedView(add_user_view);
}
+
// Install a listener to focus changes so that we can remove the card when
// the focus gets changed. When called through the destruction of the bubble,
// the FocusManager cannot be determined anymore and we remember it here.
@@ -696,7 +405,6 @@ void UserView::RemoveAddUserMenuOption() {
if (user_card_view_->GetFocusManager())
user_card_view_->GetFocusManager()->ClearFocus();
popup_message_.reset();
- mouse_watcher_.reset();
add_menu_option_.reset();
}
« no previous file with comments | « ash/common/system/user/user_view.h ('k') | ash/resources/ash_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698