0

views: use CalculatePreferredSize(SizeBounds) in //ash/app_menu.

In order to ensure implementation consistency and avoid oversights, we
should unify CalculatePreferredSize() and GetHeightForWidth(). Replace
them with the CalculatePreferredSize(SizeBounds) overload.

Bug: 40232718
Change-Id: Ib78be70c8e511b3069b2e051c877c613b37f822c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5468009
Commit-Queue: Weidong Liu <weidongliu@chromium.org>
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1290993}
This commit is contained in:
weidongliu
2024-04-23 00:35:01 +00:00
committed by Chromium LUCI CQ
parent 448ecf9959
commit 5fb59ccf79
8 changed files with 25 additions and 22 deletions

@ -110,7 +110,8 @@ void NotificationItemView::UpdateContents(const std::u16string& title,
proportional_icon_view_->SetImage(icon, kProportionalIconViewSize);
}
gfx::Size NotificationItemView::CalculatePreferredSize() const {
gfx::Size NotificationItemView::CalculatePreferredSize(
const views::SizeBounds& available_size) const {
return gfx::Size(views::MenuConfig::instance().touchable_menu_min_width -
kBorderStrokeWidth,
kNotificationItemViewHeight);

@ -58,7 +58,8 @@ class APP_MENU_EXPORT NotificationItemView : public views::View {
const ui::ImageModel& icon);
// views::View overrides:
gfx::Size CalculatePreferredSize() const override;
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
void Layout(PassKey) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;

@ -57,27 +57,23 @@ void NotificationMenuHeaderView::UpdateCounter(int number_of_notifications) {
counter_->SetText(base::NumberToString16(number_of_notifications_));
}
gfx::Size NotificationMenuHeaderView::CalculatePreferredSize() const {
return gfx::Size(
views::MenuConfig::instance().touchable_menu_min_width,
GetInsets().height() + notification_title_
->GetPreferredSize(views::SizeBounds(
notification_title_->width(), {}))
.height());
gfx::Size NotificationMenuHeaderView::CalculatePreferredSize(
const views::SizeBounds& available_size) const {
return gfx::Size(views::MenuConfig::instance().touchable_menu_min_width,
GetInsets().height() +
notification_title_->GetPreferredSize({}).height());
}
void NotificationMenuHeaderView::Layout(PassKey) {
const gfx::Insets insets = GetInsets();
const gfx::Size notification_title_preferred_size =
notification_title_->GetPreferredSize(
views::SizeBounds(notification_title_->width(), {}));
notification_title_->GetPreferredSize({});
notification_title_->SetBounds(insets.left(), insets.top(),
notification_title_preferred_size.width(),
notification_title_preferred_size.height());
const gfx::Size counter_preferred_size =
counter_->GetPreferredSize(views::SizeBounds(counter_->width(), {}));
const gfx::Size counter_preferred_size = counter_->GetPreferredSize({});
counter_->SetBounds(width() - counter_preferred_size.width() - insets.right(),
insets.top(), counter_preferred_size.width(),
counter_preferred_size.height());

@ -31,8 +31,9 @@ class NotificationMenuHeaderView : public views::View {
void UpdateCounter(int number_of_notifications);
// Overidden from views::View:
gfx::Size CalculatePreferredSize() const override;
// Overridden from views::View:
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
void Layout(PassKey) override;
private:

@ -41,11 +41,12 @@ NotificationMenuView::NotificationMenuView(
NotificationMenuView::~NotificationMenuView() = default;
gfx::Size NotificationMenuView::CalculatePreferredSize() const {
gfx::Size NotificationMenuView::CalculatePreferredSize(
const views::SizeBounds& available_size) const {
return gfx::Size(
views::MenuConfig::instance().touchable_menu_min_width,
double_separator_->GetPreferredSize().height() +
header_view_->GetPreferredSize().height() +
header_view_->GetPreferredSize({}).height() +
kNotificationItemViewHeight +
(overflow_view_ ? overflow_view_->GetPreferredSize().height() : 0));
}
@ -59,8 +60,8 @@ void NotificationMenuView::Layout(PassKey) {
y += double_separator_->GetPreferredSize().height();
header_view_->SetBoundsRect(
gfx::Rect(gfx::Point(0, y), header_view_->GetPreferredSize()));
y += header_view_->GetPreferredSize().height();
gfx::Rect(gfx::Point(0, y), header_view_->GetPreferredSize({})));
y += header_view_->height();
auto* item = GetDisplayedNotificationItemView();
if (item) {

@ -58,7 +58,8 @@ class APP_MENU_EXPORT NotificationMenuView : public views::View {
~NotificationMenuView() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
void Layout(PassKey) override;
// Whether |notifications_for_this_app_| is empty.

@ -139,7 +139,8 @@ void NotificationOverflowView::Layout(PassKey) {
}
}
gfx::Size NotificationOverflowView::CalculatePreferredSize() const {
gfx::Size NotificationOverflowView::CalculatePreferredSize(
const views::SizeBounds& available_size) const {
// This view is the last element in a MenuItemView, which means it has extra
// padding on the bottom due to the corner radius of the root MenuItemView. If
// the corner radius changes, |kOverflowSeparatorToIconPadding| must be

@ -46,7 +46,8 @@ class APP_MENU_EXPORT NotificationOverflowView : public views::View {
// views::View overrides:
void Layout(PassKey) override;
gfx::Size CalculatePreferredSize() const override;
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
// Whether this has notifications to show.
bool is_empty() const { return image_views_.empty(); }