www.fgks.org   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Use kViewIgnoredByLayoutKey everywhere.
Browse files Browse the repository at this point in the history
This removes LayoutManagerBase::*ChildViewIgnoredByLayout(), which is
no longer necessary.

Bug: 1267319
Change-Id: I12f10e5f9865e4a0377911925168bc157e49d432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5263230
Reviewed-by: Scott Violet <sky@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1256278}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Feb 5, 2024
1 parent 7898890 commit 0139cef
Show file tree
Hide file tree
Showing 31 changed files with 149 additions and 215 deletions.
5 changes: 2 additions & 3 deletions ash/app_list/views/app_list_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ AppListBubbleView::AppListBubbleView(
: views::HighlightBorder::Type::kHighlightBorder1,
/*insets_type=*/views::HighlightBorder::InsetsType::kHalfInsets));

views::FillLayout* layout =
SetLayoutManager(std::make_unique<views::FillLayout>());
SetLayoutManager(std::make_unique<views::FillLayout>());
a11y_announcer_ = std::make_unique<AppListA11yAnnouncer>(
AddChildView(std::make_unique<views::View>()));
InitContentsView(drag_and_drop_host);
Expand All @@ -248,7 +247,7 @@ AppListBubbleView::AppListBubbleView(

InitFolderView(drag_and_drop_host);
// Folder view is laid out manually based on its contents.
layout->SetChildViewIgnoredByLayout(folder_view_, true);
folder_view_->SetProperty(views::kViewIgnoredByLayoutKey, true);

AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
AddAccelerator(ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_NONE));
Expand Down
46 changes: 21 additions & 25 deletions ash/app_list/views/continue_task_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/table_layout.h"
#include "ui/views/view_class_properties.h"

using views::BoxLayout;
using views::FlexLayout;
Expand Down Expand Up @@ -125,10 +126,10 @@ ContinueTaskContainerView::ContinueTaskContainerView(
DCHECK(!update_callback_.is_null());

if (tablet_mode_) {
InitializeFlexLayout();
InitializeTabletLayout();
} else {
columns_ = columns;
InitializeTableLayout();
InitializeClamshellLayout();
}
GetViewAccessibility().OverrideRole(ax::mojom::Role::kList);
GetViewAccessibility().OverrideName(
Expand Down Expand Up @@ -481,11 +482,7 @@ void ContinueTaskContainerView::AnimateSlideInSuggestions(

void ContinueTaskContainerView::RemoveViewFromLayout(ContinueTaskView* view) {
view->SetEnabled(false);
if (table_layout_) {
table_layout_->SetChildViewIgnoredByLayout(view, true);
} else if (flex_layout_) {
flex_layout_->SetChildViewIgnoredByLayout(view, true);
}
view->SetProperty(views::kViewIgnoredByLayoutKey, true);
}

void ContinueTaskContainerView::ScheduleUpdate() {
Expand All @@ -498,13 +495,12 @@ void ContinueTaskContainerView::ScheduleUpdate() {
}
}

void ContinueTaskContainerView::InitializeFlexLayout() {
void ContinueTaskContainerView::InitializeTabletLayout() {
DCHECK(tablet_mode_);
DCHECK(!table_layout_);
DCHECK(!columns_);

flex_layout_ = SetLayoutManager(std::make_unique<FlexLayout>());
flex_layout_->SetOrientation(views::LayoutOrientation::kHorizontal)
SetLayoutManager(std::make_unique<FlexLayout>())
->SetOrientation(views::LayoutOrientation::kHorizontal)
.SetMainAxisAlignment(views::LayoutAlignment::kCenter)
.SetDefault(views::kMarginsKey,
gfx::Insets::TLBR(0, kColumnSpacingTablet, 0, 0))
Expand All @@ -514,36 +510,36 @@ void ContinueTaskContainerView::InitializeFlexLayout() {
views::MaximumFlexSizeRule::kScaleToMaximum));
}

void ContinueTaskContainerView::InitializeTableLayout() {
void ContinueTaskContainerView::InitializeClamshellLayout() {
DCHECK(!tablet_mode_);
DCHECK(!flex_layout_);
DCHECK_GT(columns_, 0);

table_layout_ = SetLayoutManager(std::make_unique<views::TableLayout>());
auto* const table_layout =
SetLayoutManager(std::make_unique<views::TableLayout>());
std::vector<size_t> linked_columns;
for (int i = 0; i < columns_; i++) {
if (i == 0) {
table_layout_->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnOuterSpacingClamshell);
table_layout->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnOuterSpacingClamshell);
} else {
table_layout_->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnInnerSpacingClamshell);
table_layout->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnInnerSpacingClamshell);
}
table_layout_->AddColumn(
table_layout->AddColumn(
views::LayoutAlignment::kStretch, views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f, views::TableLayout::ColumnSize::kFixed,
/*fixed_width=*/0, /*min_width=*/0);
linked_columns.push_back(2 * i + 1);
}
table_layout_->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnOuterSpacingClamshell);
table_layout->AddPaddingColumn(views::TableLayout::kFixedSize,
kColumnOuterSpacingClamshell);

table_layout_->LinkColumnSizes(linked_columns);
table_layout->LinkColumnSizes(linked_columns);
// Continue section only shows if there are 3 or more suggestions, so there
// are always 2 rows.
table_layout_->AddRows(1, views::TableLayout::kFixedSize);
table_layout_->AddPaddingRow(views::TableLayout::kFixedSize, kRowSpacing);
table_layout_->AddRows(1, views::TableLayout::kFixedSize);
table_layout->AddRows(1, views::TableLayout::kFixedSize);
table_layout->AddPaddingRow(views::TableLayout::kFixedSize, kRowSpacing);
table_layout->AddRows(1, views::TableLayout::kFixedSize);
}

void ContinueTaskContainerView::MoveFocusUp() {
Expand Down
32 changes: 8 additions & 24 deletions ash/app_list/views/continue_task_container_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
#include "ui/compositor/layer_animator.h"
#include "ui/views/view.h"

namespace views {
class FlexLayout;
class TableLayout;
} // namespace views

namespace ash {

class AppListViewDelegate;
Expand Down Expand Up @@ -93,18 +88,15 @@ class ASH_EXPORT ContinueTaskContainerView : public ui::ListModelObserver,
// manager, and disables the view.
void RemoveViewFromLayout(ContinueTaskView* view);

// Initializes the view's layout manager to use |flex_layout_|. FlexLayout is
// used in tablet mode only. Views will be laid out in a single row centered
// in the container. Number of items displayed will depend on available space.
// This will not enforce any number of `columns_`.
void InitializeFlexLayout();
// Lays out children in a single row centered in the container. Number of
// items displayed will depend on available space. This will not enforce any
// number of `columns_`.
void InitializeTabletLayout();

// Initializes the view's layout manager to use |table_layout_|. TableLayout
// is used in clamshell mode only. Views are laid out in a table with a
// specific number of `columns_`. This displays views to stretch as to use
// all vertical space available in the container. Extra views are added in
// multiple rows.
void InitializeTableLayout();
// Lays out children in a table with a specific number of `columns_`. This
// displays views to stretch as to use all vertical space available in the
// container. Extra views are added in multiple rows.
void InitializeClamshellLayout();

// Describes how old task views should animate when the set of tasks shown in
// the container updates.
Expand Down Expand Up @@ -172,14 +164,6 @@ class ASH_EXPORT ContinueTaskContainerView : public ui::ListModelObserver,
raw_ptr<SearchModel::SearchResults> results_ =
nullptr; // Owned by SearchModel.

// Only one of the layouts is to be set.
// `flex_layout_` aligns the views as a single row centered in the container.
// Used in tablet mode.
raw_ptr<views::FlexLayout> flex_layout_ = nullptr;
// `table_layout_` aligns the views as a table with multiple rows stretched
// to fill the container. Used in clamshell mode.
raw_ptr<views::TableLayout> table_layout_ = nullptr;

// The list of tasks views for the container.
std::vector<raw_ptr<ContinueTaskView, VectorExperimental>>
suggestion_tasks_views_;
Expand Down
31 changes: 15 additions & 16 deletions ash/assistant/ui/main_stage/assistant_onboarding_suggestion_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,21 @@ void AssistantOnboardingSuggestionView::InitLayout(
AddChildView(std::make_unique<views::InkDropContainerView>());

// Layout.
auto& layout =
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetCollapseMargins(true)
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
.SetDefault(views::kFlexBehaviorKey, views::FlexSpecification())
.SetDefault(views::kMarginsKey, gfx::Insets::VH(0, 2 * kSpacingDip))
.SetInteriorMargin(gfx::Insets::VH(0, 2 * kMarginDip))
.SetOrientation(views::LayoutOrientation::kHorizontal);

// NOTE: Our |layout| ignores the view for drawing focus as it is a special
// view which lays out itself. Removing this would cause it *not* to paint.
layout.SetChildViewIgnoredByLayout(views::FocusRing::Get(this), true);

// NOTE: Our |ink_drop_container_| serves only to hold reference to ink drop
// layers for painting purposes. It can be completely ignored by our |layout|.
layout.SetChildViewIgnoredByLayout(ink_drop_container_, true);
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetCollapseMargins(true)
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
.SetDefault(views::kFlexBehaviorKey, views::FlexSpecification())
.SetDefault(views::kMarginsKey, gfx::Insets::VH(0, 2 * kSpacingDip))
.SetInteriorMargin(gfx::Insets::VH(0, 2 * kMarginDip))
.SetOrientation(views::LayoutOrientation::kHorizontal);

// Ignore the focus ring, which lays out itself.
views::FocusRing::Get(this)->SetProperty(views::kViewIgnoredByLayoutKey,
true);

// Ignore the `ink_drop_container_`, which serves only to hold reference to
// ink drop layers for painting purposes.
ink_drop_container_->SetProperty(views::kViewIgnoredByLayoutKey, true);

// Icon.
icon_ = AddChildView(std::make_unique<views::ImageView>());
Expand Down
8 changes: 4 additions & 4 deletions ash/glanceables/classroom/glanceables_classroom_item_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ GlanceablesClassroomItemView::GlanceablesClassroomItemView(
: views::Button(std::move(pressed_callback)) {
CHECK(assignment);

auto* const layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetCrossAxisAlignment(views::LayoutAlignment::kStart);
layout->SetInteriorMargin(kInteriorMargin);
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetCrossAxisAlignment(views::LayoutAlignment::kStart)
.SetInteriorMargin(kInteriorMargin);

const gfx::RoundedCornersF corner_radii =
GetRoundedCorners(item_index, last_item_index);
Expand Down Expand Up @@ -282,7 +282,7 @@ GlanceablesClassroomItemView::GlanceablesClassroomItemView(

// Prevent the layout manager from setting the focus ring to a default hidden
// visibility.
layout->SetChildViewIgnoredByLayout(focus_ring, true);
focus_ring->SetProperty(views::kViewIgnoredByLayoutKey, true);
}

GlanceablesClassroomItemView::~GlanceablesClassroomItemView() = default;
Expand Down
5 changes: 2 additions & 3 deletions ash/login/ui/login_user_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ void LoginUserView::UpdateOpacity() {
}

void LoginUserView::SetLargeLayout() {
auto* layout = SetLayoutManager(std::make_unique<views::TableLayout>());
layout
SetLayoutManager(std::make_unique<views::TableLayout>())
->AddColumn(views::LayoutAlignment::kEnd, views::LayoutAlignment::kCenter,
1.0f, views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
.AddPaddingColumn(views::TableLayout::kFixedSize,
Expand All @@ -714,7 +713,7 @@ void LoginUserView::SetLargeLayout() {
.AddRows(1, views::TableLayout::kFixedSize);

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

AddChildView(user_image_.get());
user_image_->SetProperty(views::kTableColAndRowSpanKey, gfx::Size(5, 1));
Expand Down
8 changes: 4 additions & 4 deletions ash/style/combobox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ Combobox::Combobox(ui::ComboboxModel* model)
OnComboboxModelChanged(model_);

// Set up layout.
auto* const layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetInteriorMargin(kComboboxBorderInsets);
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetInteriorMargin(kComboboxBorderInsets);
// Allow `title_` to shrink and elide, so that `drop_down_arrow_` on the
// right always remains visible.
title_->SetProperty(
Expand All @@ -373,8 +373,8 @@ Combobox::Combobox(ui::ComboboxModel* model)
StyleUtil::InstallRoundedCornerHighlightPathGenerator(
this, kComboboxRoundedCorners);
StyleUtil::SetUpInkDropForButton(this);
layout->SetChildViewIgnoredByLayout(views::FocusRing::Get(this),
/*ignored=*/true);
views::FocusRing::Get(this)->SetProperty(views::kViewIgnoredByLayoutKey,
/*ignored=*/true);

event_handler_ = std::make_unique<ComboboxEventHandler>(this);

Expand Down
8 changes: 4 additions & 4 deletions ash/style/drop_down_checkbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ DropDownCheckbox::DropDownCheckbox(const std::u16string& title,
model_->AddObserver(selection_model_.get());

// Set up layout.
auto* const layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetInteriorMargin(kDropDownCheckboxBorderInsets);
SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetInteriorMargin(kDropDownCheckboxBorderInsets);
// Allow `title_` to shrink and elide, so that `drop_down_arrow_` on the
// right always remains visible.
title_->SetProperty(
Expand All @@ -299,8 +299,8 @@ DropDownCheckbox::DropDownCheckbox(const std::u16string& title,
views::InstallRoundRectHighlightPathGenerator(
this, gfx::Insets(), kDropDownCheckboxRoundedCorners);
StyleUtil::SetUpInkDropForButton(this);
layout->SetChildViewIgnoredByLayout(views::FocusRing::Get(this),
/*ignored=*/true);
views::FocusRing::Get(this)->SetProperty(views::kViewIgnoredByLayoutKey,
/*ignored=*/true);

event_handler_ = std::make_unique<EventHandler>(this);

Expand Down
5 changes: 1 addition & 4 deletions ash/style/tab_slider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ TabSlider::TabSlider(size_t max_tab_num, const InitParams& params)

Init();

// Explicitly mark this view as ignored because
// `views::kViewIgnoredByLayoutKey` is not supported by `views::TableLayout`.
static_cast<views::TableLayout*>(GetLayoutManager())
->SetChildViewIgnoredByLayout(selector_view_, /*ignored=*/true);
selector_view_->SetProperty(views::kViewIgnoredByLayoutKey, true);

enabled_changed_subscription_ = AddEnabledChangedCallback(base::BindRepeating(
&TabSlider::OnEnabledStateChanged, base::Unretained(this)));
Expand Down
14 changes: 8 additions & 6 deletions ash/system/holding_space/holding_space_drag_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_manager_base.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"

namespace ash {
Expand Down Expand Up @@ -453,9 +454,9 @@ class DragImageView : public views::View {
}

void InitLayout(const std::vector<const HoldingSpaceItem*>& items) {
auto* layout = SetLayoutManager(std::make_unique<views::FillLayout>());
SetLayoutManager(std::make_unique<views::FillLayout>());
AddDragImageItemViews(items);
AddDragImageOverflowBadge(layout, items.size());
AddDragImageOverflowBadge(items.size());
}

void AddDragImageItemViews(
Expand Down Expand Up @@ -490,16 +491,17 @@ class DragImageView : public views::View {
first_drag_image_item_view_ = container->children()[0].get();
}

void AddDragImageOverflowBadge(views::FillLayout* layout, size_t count) {
void AddDragImageOverflowBadge(size_t count) {
if (count <= kDragImageViewMaxItemsToPaint)
return;

drag_image_overflow_badge_ = AddChildView(
std::make_unique<DragImageOverflowBadge>(count, color_provider_));

// This view's `layout` manager ignores `drag_image_overflow_badge_` as it
// is manually positioned relative to the `first_drag_image_item_view_`.
layout->SetChildViewIgnoredByLayout(drag_image_overflow_badge_, true);
// `drag_image_overflow_badge_` is manually positioned relative to the
// `first_drag_image_item_view_`.
drag_image_overflow_badge_->SetProperty(views::kViewIgnoredByLayoutKey,
true);
}

const raw_ptr<const ui::ColorProvider> color_provider_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#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"
#include "ui/views/widget/widget.h"

namespace ash {
Expand Down Expand Up @@ -491,7 +492,7 @@ void NotifierSettingsView::NotifierButton::GridChanged() {
// constructor, and replace TableLayout with BoxLayout. Toggle the visibility
// of the policy icon dynamically as needed.

auto* layout = SetLayoutManager(std::make_unique<views::TableLayout>());
auto* const layout = SetLayoutManager(std::make_unique<views::TableLayout>());
layout
// Add a column for the checkbox.
->AddPaddingColumn(views::TableLayout::kFixedSize,
Expand Down Expand Up @@ -523,7 +524,8 @@ void NotifierSettingsView::NotifierButton::GridChanged() {
.AddRows(1, views::TableLayout::kFixedSize);

// FocusRing is a child of Button. Ignore it.
layout->SetChildViewIgnoredByLayout(views::FocusRing::Get(this), true);
views::FocusRing::Get(this)->SetProperty(views::kViewIgnoredByLayoutKey,
true);

if (!GetEnabled()) {
auto policy_enforced_icon = std::make_unique<views::ImageView>();
Expand Down
Loading

0 comments on commit 0139cef

Please sign in to comment.