0

Use box layout for WindowMiniViewHeaderView.

Box layout is ~10x faster than flex layout in this use case.
For most real-world cases, the difference is probably imperceptible,
but the tast test in the bug surfaced this difference.

Video recordings of this tast test before and after this change
are below.
Before:
http://screencast/cast/NDUyMjE2NTc1OTExNTI2NHw3M2FhYTQ1Ny0zYw
After:
http://screencast/cast/NTY2MTc5NTM2Nzc4MDM1Mnw5OTBkMDg3YS1mNA

      Ran ui.SplitViewResizePerf tast test
      Ran with --ui-show-paint-rects to ensure there's not overpainting.

Bug: b:385148375
Test: Tested both short and long window labels.
Change-Id: Ie1417bb1a71b6b6589b80eab6aec3a63fe6e9f48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6137996
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Eric Sum <esum@google.com>
Cr-Commit-Position: refs/heads/main@{#1401919}
This commit is contained in:
Eric Sum
2025-01-03 12:02:20 -08:00
committed by Chromium LUCI CQ
parent caede6efad
commit 1a4a21c8cf
3 changed files with 20 additions and 56 deletions

@ -30,8 +30,6 @@
#include "ui/views/animation/animation_builder.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
@ -93,11 +91,6 @@ OverviewItemView::OverviewItemView(
close_button_->SetPaintToLayer();
close_button_->layer()->SetFillsBoundsOpaquely(false);
close_button_->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification().WithOrder(
WindowMiniViewHeaderView::IconLabelFlexPriorities::
kIconOrCloseButton));
views::InkDrop::Get(close_button_)
->SetMode(views::InkDropHost::InkDropMode::ON_NO_GESTURE_HANDLER);
close_button_->GetViewAccessibility().SetName(

@ -22,8 +22,6 @@
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_observer.h"
@ -65,13 +63,23 @@ WindowMiniViewHeaderView::WindowMiniViewHeaderView(
SetPaintToLayer(ui::LAYER_SOLID_COLOR);
layer()->SetIsFastRoundedCorner(true);
icon_label_view_ = AddChildView(std::make_unique<views::FlexLayoutView>());
icon_label_view_->SetOrientation(views::LayoutOrientation::kHorizontal);
icon_label_view_->SetInteriorMargin(kHeaderInsets);
icon_label_view_->SetDefault(
views::kMarginsKey,
gfx::Insets::TLBR(0, kHeaderPaddingDp, 0, kHeaderPaddingDp));
icon_label_view_->SetCollapseMargins(true);
// Box layout should accomplish the following:
// +------+-------+-------------------------------------------------+--------+
// | icon | label | leftover space | close |
// | | | | button |
// +------+-------+-------------------------------------------------+--------+
// * Note the close button may not be present in some corner cases, so it's
// created outside of `WindowMiniViewHeaderView`.
// 1) The icon and close button get their preferred sizes.
// 2) If the label's preferred size fits between the icon and close button,
// blank space is added between the label and close button until the close
// button is right aligned.
// 3) If the label's preferred size doesn't fit between the icon and close
// button, it gets shrunk until it fits (leftover space above is zero).
icon_label_view_ = AddChildView(std::make_unique<views::BoxLayoutView>());
icon_label_view_->SetOrientation(views::BoxLayout::Orientation::kHorizontal);
icon_label_view_->SetInsideBorderInsets(kHeaderInsets);
icon_label_view_->SetBetweenChildSpacing(kHeaderPaddingDp);
title_label_ = icon_label_view_->AddChildView(std::make_unique<views::Label>(
GetWindowTitle(window_mini_view_->source_window())));
@ -83,31 +91,7 @@ WindowMiniViewHeaderView::WindowMiniViewHeaderView(
title_label_->SetEnabledColorId(cros_tokens::kCrosSysPrimary);
title_label_->SetPaintToLayer();
title_label_->layer()->SetFillsBoundsOpaquely(false);
views::View* leftover_space =
icon_label_view_->AddChildView(std::make_unique<views::View>());
// Flex layout should accomplish the following:
// +------+-------+-------------------------------------------------+--------+
// | icon | label | leftover space | close |
// | | | | button |
// +------+-------+-------------------------------------------------+--------+
// 1) The icon and close button get their preferred sizes.
// 2) If the label's preferred size fits between the icon and close button,
// blank space is added between the label and close button until the close
// button is right aligned.
// 3) If the label's preferred size doesn't fit between the icon and close
// button, it gets shrunk until it fits (leftover space above is zero).
title_label_->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum)
.WithOrder(IconLabelFlexPriorities::kTitleLabel));
leftover_space->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToZero,
views::MaximumFlexSizeRule::kUnbounded)
.WithOrder(IconLabelFlexPriorities::kLeftoverSpace)
.WithWeight(1));
icon_label_view_->SetFlexForView(title_label_, 1);
RefreshHeaderViewRoundedCorners();
@ -135,9 +119,6 @@ void WindowMiniViewHeaderView::UpdateIconView(aura::Window* window) {
std::make_unique<views::ImageView>(), 0);
icon_view_->SetPaintToLayer();
icon_view_->layer()->SetFillsBoundsOpaquely(false);
icon_view_->SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification().WithOrder(
IconLabelFlexPriorities::kIconOrCloseButton));
}
icon_view_->SetImage(gfx::ImageSkiaOperations::CreateResizedImage(

@ -16,7 +16,6 @@ class Window;
} // namespace aura
namespace views {
class FlexLayoutView;
class ImageView;
class Label;
} // namespace views
@ -32,22 +31,13 @@ class ASH_EXPORT WindowMiniViewHeaderView : public views::BoxLayoutView {
METADATA_HEADER(WindowMiniViewHeaderView, views::BoxLayoutView)
public:
// Flex layout priorities for the `icon_label_view()`. The enums are listed
// in highest to lowest priority (high priority has the least flexibility to
// grow/shrink is more likely to get its preferred size).
enum IconLabelFlexPriorities {
kIconOrCloseButton = 1,
kTitleLabel,
kLeftoverSpace
};
explicit WindowMiniViewHeaderView(WindowMiniView* window_mini_view);
WindowMiniViewHeaderView(const WindowMiniViewHeaderView&) = delete;
WindowMiniViewHeaderView& operator=(const WindowMiniViewHeaderView&) = delete;
~WindowMiniViewHeaderView() override;
views::Label* title_label() { return title_label_; }
views::FlexLayoutView* icon_label_view() { return icon_label_view_; }
views::View* icon_label_view() { return icon_label_view_; }
void UpdateIconView(aura::Window* window);
void UpdateTitleLabel(aura::Window* window);
@ -76,7 +66,7 @@ class ASH_EXPORT WindowMiniViewHeaderView : public views::BoxLayoutView {
// A view that wraps up the icon and title label. Owned by the views
// hierarchy.
raw_ptr<views::FlexLayoutView> icon_label_view_;
raw_ptr<views::BoxLayoutView> icon_label_view_;
// Views for the icon and title. Owned by the views hierarchy.
raw_ptr<views::Label> title_label_ = nullptr;