StyledLabel: remove GetHeightForWidth overloads.
In StyledLabel, our implementations of CalculatePreferredSize and
GetHeightForWidth are inconsistent. To avoid this problem, we should
first unify the calculation method.
This CL smooths out the differences between CalculatePreferredSize and
GetHeightForWidth. And removes GetHeightForWidth.
Bug: 40232718
Change-Id: I38adf0e4bec2d33ef65e5bdb6d47c61240ad6954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5633161
Commit-Queue: Weidong Liu <weidongliu@chromium.org>
Reviewed-by: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1317395}
diff --git a/chrome/browser/ui/views/page_info/security_information_view.cc b/chrome/browser/ui/views/page_info/security_information_view.cc
index 6826c822..450eb1d7 100644
--- a/chrome/browser/ui/views/page_info/security_information_view.cc
+++ b/chrome/browser/ui/views/page_info/security_information_view.cc
@@ -62,11 +62,11 @@
// The label defaults to a single line, which would force the dialog wider;
// instead give it a width that's the minimum we want it to have. Then the
// TableLayout will stretch it back out into any additional space available.
- const int min_label_width =
+ min_label_width_ =
PageInfoViewFactory::kMinBubbleWidth - side_margin * 2 -
PageInfoViewFactory::GetConnectionSecureIcon().Size().width() -
icon_label_spacing;
- security_summary_label_->SizeToFit(min_label_width);
+ security_summary_label_->SizeToFit(min_label_width_);
auto start_secondary_row = [=]() {
layout->AddRows(1, views::TableLayout::kFixedSize);
@@ -79,7 +79,7 @@
security_details_label_->SetID(
PageInfoViewFactory::VIEW_ID_PAGE_INFO_SECURITY_DETAILS_LABEL);
security_details_label_->SetDefaultTextStyle(views::style::STYLE_SECONDARY);
- security_details_label_->SizeToFit(min_label_width);
+ security_details_label_->SizeToFit(min_label_width_);
start_secondary_row();
reset_decisions_label_container_ =
@@ -249,9 +249,18 @@
// Add padding at the top.
password_reuse_button_container_->SetBorder(
views::CreateEmptyBorder(gfx::Insets::TLBR(8, 0, 0, 0)));
+ int w = password_reuse_button_container_->GetPreferredSize().width();
+ if (w > min_label_width_) {
+ AdjustContentWidth(w);
+ }
InvalidateLayout();
}
+void SecurityInformationView::AdjustContentWidth(int w) {
+ security_summary_label_->SizeToFit(w);
+ security_details_label_->SizeToFit(w);
+}
+
BEGIN_METADATA(SecurityInformationView)
END_METADATA
diff --git a/chrome/browser/ui/views/page_info/security_information_view.h b/chrome/browser/ui/views/page_info/security_information_view.h
index 0b23abe..353e713 100644
--- a/chrome/browser/ui/views/page_info/security_information_view.h
+++ b/chrome/browser/ui/views/page_info/security_information_view.h
@@ -53,7 +53,11 @@
views::Button::PressedCallback password_reuse_callback);
private:
- // The icon that representes the security state for this site. Used for page
+ void AdjustContentWidth(int w);
+
+ int min_label_width_ = 0;
+
+ // The icon that represents the security state for this site. Used for page
// info v2 only.
raw_ptr<NonAccessibleImageView> icon_ = nullptr;
diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc
index 8a32d9c..7c374e0 100644
--- a/ui/views/controls/styled_label.cc
+++ b/ui/views/controls/styled_label.cc
@@ -293,10 +293,6 @@
need_recreate_child_ = true;
}
-int StyledLabel::GetHeightForWidth(int w) const {
- return GetLayoutSizeInfoForWidth(w).total_size.height();
-}
-
void StyledLabel::Layout(PassKey) {
if (!need_recreate_child_) {
return;
diff --git a/ui/views/controls/styled_label.h b/ui/views/controls/styled_label.h
index 6bfcc57..e814e82 100644
--- a/ui/views/controls/styled_label.h
+++ b/ui/views/controls/styled_label.h
@@ -186,7 +186,6 @@
gfx::Size CalculatePreferredSize(
const SizeBounds& available_size) const override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
- int GetHeightForWidth(int w) const override;
void Layout(PassKey) override;
void PreferredSizeChanged() override;