Skip to content

Commit

Permalink
Fix width of status bubbles
Browse files Browse the repository at this point in the history
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: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645300}
  • Loading branch information
AltinaXIV authored and Commit Bot committed Mar 28, 2019
1 parent 442f2a6 commit 03d9d9e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ Georgy Buranov <gburanov@gmail.com>
Gergely Nagy <ngg@ngg.hu>
Getulio Sánchez <valentin2507@gmail.com>
Gideon Pyzer <gjpyzer@gmail.com>
Giovanni Panaro <tsrwebgl@gmail.com>
Girish Kumar M <mck.giri@samsung.com>
Gitanshu Mehndiratta <g.mehndiratt@samsung.com>
Giuseppe Iuculano <giuseppe@iuculano.it>
Expand Down
47 changes: 33 additions & 14 deletions chrome/browser/ui/views/status_bubble_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,14 @@ void StatusBubbleViews::SetBounds(int x, int y, int w, int h) {
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) {
if (size_.IsEmpty())
return; // We have no bounds, don't attempt to show the popup.
Expand Down Expand Up @@ -760,12 +768,6 @@ void StatusBubbleViews::SetURL(const GURL& url) {
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.
int text_width = static_cast<int>(size_.width() - (kShadowThickness * 2) -
kTextPositionX - kTextHorizPadding - 1);
Expand All @@ -776,8 +778,28 @@ void StatusBubbleViews::SetURL(const GURL& url) {
// correctly.
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()) {
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();

Expand All @@ -793,6 +815,7 @@ void StatusBubbleViews::SetURL(const GURL& url) {
expand_timer_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS));
}
view_->SetText(url_text_, true);
}
}

Expand Down Expand Up @@ -937,15 +960,11 @@ bool StatusBubbleViews::IsFrameMaximized() {
void StatusBubbleViews::ExpandBubble() {
// Elide URL to maximum possible size, then check actual length (it may
// still be too long to fit) before expanding bubble.
int max_status_bubble_width = GetMaxStatusBubbleWidth();
const gfx::FontList font_list;
url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width);
url_text_ =
url_formatter::ElideUrl(url_, GetFont(), GetMaxStatusBubbleWidth());
int expanded_bubble_width =
std::max(GetStandardStatusBubbleWidth(),
std::min(gfx::GetStringWidth(url_text_, font_list) +
(kShadowThickness * 2) + kTextPositionX +
kTextHorizPadding + 1,
max_status_bubble_width));
std::min(GetWidthForURL(url_text_), GetMaxStatusBubbleWidth()));
is_expanded_ = true;
expand_view_->StartExpansion(url_text_, size_.width(), expanded_bubble_width);
}
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/views/status_bubble_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class StatusBubbleViews : public StatusBubble {
// Set bubble to new 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:
void SetStatus(const base::string16& status) override;
void SetURL(const GURL& url) override;
Expand Down

0 comments on commit 03d9d9e

Please sign in to comment.