Skip to content

Commit

Permalink
Allow clicks on the user dropdown to open it.
Browse files Browse the repository at this point in the history
(cherry picked from commit 06b4aec)

Bug: 1315505
Change-Id: Ic4797122c6f446f4f24ed1707ecfa9dcf768e167
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3594208
Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#994134}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3600744
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Denis Kuznetsov <antrim@chromium.org>
Cr-Commit-Position: refs/branch-heads/5005@{#87}
Cr-Branched-From: 5b4d945-refs/heads/main@{#992738}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Apr 21, 2022
1 parent 2d05f4d commit 26e1f21
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
73 changes: 40 additions & 33 deletions ash/login/ui/login_user_view.cc
Expand Up @@ -39,6 +39,7 @@
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/table_layout.h"
#include "ui/views/painter.h"
#include "ui/views/view_class_properties.h"

Expand Down Expand Up @@ -599,9 +600,14 @@ void LoginUserView::OnThemeChanged() {

views::View::Views LoginUserView::GetChildrenInZOrder() {
auto children = views::View::GetChildrenInZOrder();
auto tap_button_iter = base::ranges::find(children, tap_button_);
DCHECK(tap_button_iter != children.end());
std::rotate(tap_button_iter, tap_button_iter + 1, children.end());
const auto move_child_to_top = [&](View* child) {
auto it = base::ranges::find(children, child);
DCHECK(it != children.end());
std::rotate(it, it + 1, children.end());
};
move_child_to_top(tap_button_);
if (dropdown_)
move_child_to_top(dropdown_);
return children;
}

Expand Down Expand Up @@ -704,41 +710,42 @@ void LoginUserView::UpdateOpacity() {
}

void LoginUserView::SetLargeLayout() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
kVerticalSpacingBetweenEntriesDp));
auto* layout = SetLayoutManager(std::make_unique<views::TableLayout>());
layout
->AddColumn(views::LayoutAlignment::kEnd, views::LayoutAlignment::kCenter,
1.0f, views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
.AddPaddingColumn(views::TableLayout::kFixedSize,
kDistanceBetweenUsernameAndDropdownDp)
.AddColumn(views::LayoutAlignment::kCenter,
views::LayoutAlignment::kCenter,
views::TableLayout::kFixedSize,
views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
.AddPaddingColumn(views::TableLayout::kFixedSize,
kDistanceBetweenUsernameAndDropdownDp)
.AddColumn(views::LayoutAlignment::kStart,
views::LayoutAlignment::kCenter, 1.0f,
views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
.AddRows(1, views::TableLayout::kFixedSize)
.AddPaddingRow(views::TableLayout::kFixedSize,
kVerticalSpacingBetweenEntriesDp)
.AddRows(1, views::TableLayout::kFixedSize);

AddChildView(tap_button_);
tap_button_->SetProperty(views::kViewIgnoredByLayoutKey, true);
layout->SetChildViewIgnoredByLayout(tap_button_, true);

// Centered user image.
auto* image_row = AddChildView(std::make_unique<NonAccessibleView>());
auto* image_layout =
image_row->SetLayoutManager(std::make_unique<views::BoxLayout>());
image_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kCenter);
image_row->AddChildView(user_image_);

// User name, menu dropdown.
auto* label_row = AddChildView(std::make_unique<NonAccessibleView>());
auto* label_layout =
label_row->SetLayoutManager(std::make_unique<views::BoxLayout>());
label_layout->set_between_child_spacing(
kDistanceBetweenUsernameAndDropdownDp);
label_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kCenter);

// Add an empty view that has the same size as the dropdown so we center on
// `user_label_`. This is simpler than doing manual size calculation to take
// into account the extra offset.
if (dropdown_) {
label_row->AddChildView(std::make_unique<NonAccessibleView>())
->SetPreferredSize(dropdown_->GetPreferredSize());
}
AddChildView(user_image_);
user_image_->SetProperty(views::kTableColAndRowSpanKey, gfx::Size(5, 1));
user_image_->SetProperty(views::kTableHorizAlignKey,
views::LayoutAlignment::kCenter);

label_row->AddChildView(user_label_);
auto* skip_column = AddChildView(std::make_unique<NonAccessibleView>());
if (dropdown_)
skip_column->SetPreferredSize(dropdown_->GetPreferredSize());

AddChildView(user_label_);

if (dropdown_)
label_row->AddChildView(dropdown_);
AddChildView(dropdown_);
}

void LoginUserView::SetSmallishLayout() {
Expand Down
3 changes: 3 additions & 0 deletions ui/views/view_class_properties.h
Expand Up @@ -62,6 +62,9 @@ VIEWS_EXPORT extern const ui::ClassProperty<LayoutAlignment*>* const
kCrossAxisAlignmentKey;

// TableLayout-specific properties:
// Note that col/row span counts padding columns, so if you want to span a
// region consisting of <column><padding column><column>, it's a column span of
// 3, not 2.
VIEWS_EXPORT extern const ui::ClassProperty<gfx::Size*>* const
kTableColAndRowSpanKey;
VIEWS_EXPORT extern const ui::ClassProperty<LayoutAlignment*>* const
Expand Down

0 comments on commit 26e1f21

Please sign in to comment.