Commit 03d9d9e6 authored by tsrwebgl's avatar tsrwebgl Committed by Commit Bot

Fix width of status bubbles

Status bubbles for short URLs now match the width of the URL

Tested by mousing over various links to make the status bubble appear.

Bug: 936144
Change-Id: Ia6e4735a84e4d02f560b860b93e6dbc2066ff63e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529187
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645300}
parent 442f2a64
...@@ -297,6 +297,7 @@ Georgy Buranov <gburanov@gmail.com> ...@@ -297,6 +297,7 @@ Georgy Buranov <gburanov@gmail.com>
Gergely Nagy <ngg@ngg.hu> Gergely Nagy <ngg@ngg.hu>
Getulio Sánchez <valentin2507@gmail.com> Getulio Sánchez <valentin2507@gmail.com>
Gideon Pyzer <gjpyzer@gmail.com> Gideon Pyzer <gjpyzer@gmail.com>
Giovanni Panaro <tsrwebgl@gmail.com>
Girish Kumar M <mck.giri@samsung.com> Girish Kumar M <mck.giri@samsung.com>
Gitanshu Mehndiratta <g.mehndiratt@samsung.com> Gitanshu Mehndiratta <g.mehndiratt@samsung.com>
Giuseppe Iuculano <giuseppe@iuculano.it> Giuseppe Iuculano <giuseppe@iuculano.it>
......
...@@ -721,6 +721,14 @@ void StatusBubbleViews::SetBounds(int x, int y, int w, int h) { ...@@ -721,6 +721,14 @@ void StatusBubbleViews::SetBounds(int x, int y, int w, int h) {
AvoidMouse(last_mouse_moved_location_); AvoidMouse(last_mouse_moved_location_);
} }
int StatusBubbleViews::GetWidthForURL(const base::string16& url_string) {
// Get the width of the elided url
int elided_url_width = gfx::GetStringWidth(url_string, GetFont());
// Add proper paddings
return elided_url_width + (kShadowThickness * 2) + kTextPositionX +
kTextHorizPadding + 1;
}
void StatusBubbleViews::SetStatus(const base::string16& status_text) { void StatusBubbleViews::SetStatus(const base::string16& status_text) {
if (size_.IsEmpty()) if (size_.IsEmpty())
return; // We have no bounds, don't attempt to show the popup. return; // We have no bounds, don't attempt to show the popup.
...@@ -760,12 +768,6 @@ void StatusBubbleViews::SetURL(const GURL& url) { ...@@ -760,12 +768,6 @@ void StatusBubbleViews::SetURL(const GURL& url) {
return; return;
} }
// Reset expansion state only when bubble is completely hidden.
if (view_->state() == StatusView::BUBBLE_HIDDEN) {
is_expanded_ = false;
SetBubbleWidth(GetStandardStatusBubbleWidth());
}
// Set Elided Text corresponding to the GURL object. // Set Elided Text corresponding to the GURL object.
int text_width = static_cast<int>(size_.width() - (kShadowThickness * 2) - int text_width = static_cast<int>(size_.width() - (kShadowThickness * 2) -
kTextPositionX - kTextHorizPadding - 1); kTextPositionX - kTextHorizPadding - 1);
...@@ -776,8 +778,28 @@ void StatusBubbleViews::SetURL(const GURL& url) { ...@@ -776,8 +778,28 @@ void StatusBubbleViews::SetURL(const GURL& url) {
// correctly. // correctly.
url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_);
// Get the width of the URL if the bubble width is the maximum size.
base::string16 full_size_elided_url =
url_formatter::ElideUrl(url, GetFont(), GetMaxStatusBubbleWidth());
int url_width = GetWidthForURL(full_size_elided_url);
// Get the width for the url if it is unexpanded.
int unexpanded_width = std::min(url_width, GetStandardStatusBubbleWidth());
// Reset expansion state only when bubble is completely hidden.
if (view_->state() == StatusView::BUBBLE_HIDDEN) {
is_expanded_ = false;
url_text_ = url_formatter::ElideUrl(url, GetFont(), unexpanded_width);
SetBubbleWidth(unexpanded_width);
}
if (IsFrameVisible()) { if (IsFrameVisible()) {
view_->SetText(url_text_, true); // If bubble is not expanded & not empty, make it fit properly in the
// unexpanded bubble
if (!is_expanded_ & !url.is_empty()) {
url_text_ = url_formatter::ElideUrl(url, GetFont(), unexpanded_width);
SetBubbleWidth(unexpanded_width);
}
CancelExpandTimer(); CancelExpandTimer();
...@@ -793,6 +815,7 @@ void StatusBubbleViews::SetURL(const GURL& url) { ...@@ -793,6 +815,7 @@ void StatusBubbleViews::SetURL(const GURL& url) {
expand_timer_factory_.GetWeakPtr()), expand_timer_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS));
} }
view_->SetText(url_text_, true);
} }
} }
...@@ -937,15 +960,11 @@ bool StatusBubbleViews::IsFrameMaximized() { ...@@ -937,15 +960,11 @@ bool StatusBubbleViews::IsFrameMaximized() {
void StatusBubbleViews::ExpandBubble() { void StatusBubbleViews::ExpandBubble() {
// Elide URL to maximum possible size, then check actual length (it may // Elide URL to maximum possible size, then check actual length (it may
// still be too long to fit) before expanding bubble. // still be too long to fit) before expanding bubble.
int max_status_bubble_width = GetMaxStatusBubbleWidth(); url_text_ =
const gfx::FontList font_list; url_formatter::ElideUrl(url_, GetFont(), GetMaxStatusBubbleWidth());
url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width);
int expanded_bubble_width = int expanded_bubble_width =
std::max(GetStandardStatusBubbleWidth(), std::max(GetStandardStatusBubbleWidth(),
std::min(gfx::GetStringWidth(url_text_, font_list) + std::min(GetWidthForURL(url_text_), GetMaxStatusBubbleWidth()));
(kShadowThickness * 2) + kTextPositionX +
kTextHorizPadding + 1,
max_status_bubble_width));
is_expanded_ = true; is_expanded_ = true;
expand_view_->StartExpansion(url_text_, size_.width(), expanded_bubble_width); expand_view_->StartExpansion(url_text_, size_.width(), expanded_bubble_width);
} }
......
...@@ -58,6 +58,9 @@ class StatusBubbleViews : public StatusBubble { ...@@ -58,6 +58,9 @@ class StatusBubbleViews : public StatusBubble {
// Set bubble to new width. // Set bubble to new width.
void SetBubbleWidth(int width); void SetBubbleWidth(int width);
// Gets the width that a bubble should be for a given string
int GetWidthForURL(const base::string16& url_string);
// Overridden from StatusBubble: // Overridden from StatusBubble:
void SetStatus(const base::string16& status) override; void SetStatus(const base::string16& status) override;
void SetURL(const GURL& url) override; void SetURL(const GURL& url) override;
......
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