Commit 37a480ae authored by Collin Baker's avatar Collin Baker Committed by Chromium LUCI CQ

Set max width for in-product help bubbles

IPH bubbles can get arbitrarily long with as the body text gets
longer. The text should instead be wrapped at a certain point.

This implements a max width as per
https://docs.google.com/presentation/d/1A9QtE_cxJYLs3E7fQs9-tiCtLfEwxQiYDZUMYkYVHmI/edit#slide=id.g338d2b5135_0_19
beyond which the bubble contents are wrapped.

Bug: None
Change-Id: If3912ec379e52d2244bd3567dd23d14a3c229360
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626189
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarKeren Zhu <kerenzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842817}
parent 94f62be9
...@@ -47,6 +47,9 @@ constexpr base::TimeDelta kDelayDefault = base::TimeDelta::FromSeconds(10); ...@@ -47,6 +47,9 @@ constexpr base::TimeDelta kDelayDefault = base::TimeDelta::FromSeconds(10);
// user stops hovering over it. // user stops hovering over it.
constexpr base::TimeDelta kDelayShort = base::TimeDelta::FromSeconds(3); constexpr base::TimeDelta kDelayShort = base::TimeDelta::FromSeconds(3);
// Maximum width of the bubble. Longer strings will cause wrapping.
constexpr int kBubbleMaxWidthDip = 340;
// The insets from the bubble border to the text inside. // The insets from the bubble border to the text inside.
constexpr gfx::Insets kBubbleContentsInsets(12, 16); constexpr gfx::Insets kBubbleContentsInsets(12, 16);
...@@ -205,9 +208,7 @@ FeaturePromoBubbleView::FeaturePromoBubbleView( ...@@ -205,9 +208,7 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
body_label->SetBackgroundColor(background_color); body_label->SetBackgroundColor(background_color);
body_label->SetEnabledColor(text_color); body_label->SetEnabledColor(text_color);
body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
body_label->SetMultiLine(true);
if (params.preferred_width.has_value())
body_label->SetMultiLine(true);
if (snoozable_) { if (snoozable_) {
auto* button_container = AddChildView(std::make_unique<views::View>()); auto* button_container = AddChildView(std::make_unique<views::View>());
...@@ -330,9 +331,16 @@ gfx::Size FeaturePromoBubbleView::CalculatePreferredSize() const { ...@@ -330,9 +331,16 @@ gfx::Size FeaturePromoBubbleView::CalculatePreferredSize() const {
if (preferred_width_.has_value()) { if (preferred_width_.has_value()) {
return gfx::Size(preferred_width_.value(), return gfx::Size(preferred_width_.value(),
GetHeightForWidth(preferred_width_.value())); GetHeightForWidth(preferred_width_.value()));
} else {
return View::CalculatePreferredSize();
} }
gfx::Size layout_manager_preferred_size = View::CalculatePreferredSize();
// Wrap if the width is larger than |kBubbleMaxWidthDip|.
if (layout_manager_preferred_size.width() > kBubbleMaxWidthDip) {
return gfx::Size(kBubbleMaxWidthDip, GetHeightForWidth(kBubbleMaxWidthDip));
}
return layout_manager_preferred_size;
} }
views::Button* FeaturePromoBubbleView::GetDismissButtonForTesting() const { views::Button* FeaturePromoBubbleView::GetDismissButtonForTesting() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment