This source file includes following definitions.
- state
- style
- theme_service_
- SetText
- Show
- Hide
- StartTimer
- OnTimer
- CancelTimer
- RestartTimer
- ResetTimer
- StartFade
- StartHiding
- StartShowing
- SetOpacity
- SetStyle
- OnAnimationEnded
- OnPaint
- opacity_end_
- GetCurrentOpacity
- AnimateToState
- AnimationEnded
- expansion_end_
- AnimateToState
- AnimationEnded
- StartExpansion
- GetCurrentBubbleWidth
- SetBubbleWidth
- expand_timer_factory_
- Init
- Reposition
- RepositionPopup
- GetPreferredSize
- SetBounds
- SetStatus
- SetURL
- Hide
- MouseMoved
- UpdateDownloadShelfVisibility
- AvoidMouse
- IsFrameVisible
- IsFrameMaximized
- ExpandBubble
- GetStandardStatusBubbleWidth
- GetMaxStatusBubbleWidth
- SetBubbleWidth
- CancelExpandTimer
#include "chrome/browser/ui/views/status_bubble_views.h"
#include <algorithm>
#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/elide_url.h"
#include "net/base/net_util.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRect.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#endif
#if defined(USE_ASH)
#include "ash/wm/window_state.h"
#endif
static const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0);
static const int kBubbleCornerRadius = 4;
static const int kMousePadding = 20;
static const int kTextPositionX = 3;
static const int kTextHorizPadding = 1;
static const int kShowDelay = 80;
static const int kHideDelay = 250;
static const int kShowFadeDurationMS = 120;
static const int kHideFadeDurationMS = 200;
static const int kFramerate = 25;
static const int kMinExpansionStepDurationMS = 20;
static const int kMaxExpansionStepDurationMS = 150;
class StatusBubbleViews::StatusViewAnimation : public gfx::LinearAnimation,
public gfx::AnimationDelegate {
public:
StatusViewAnimation(StatusView* status_view,
double opacity_start,
double opacity_end);
virtual ~StatusViewAnimation();
double GetCurrentOpacity();
private:
virtual void AnimateToState(double state) OVERRIDE;
virtual void AnimationEnded(const Animation* animation) OVERRIDE;
StatusView* status_view_;
double opacity_start_;
double opacity_end_;
DISALLOW_COPY_AND_ASSIGN(StatusViewAnimation);
};
class StatusBubbleViews::StatusView : public views::View {
public:
enum BubbleState {
BUBBLE_HIDDEN,
BUBBLE_HIDING_FADE,
BUBBLE_HIDING_TIMER,
BUBBLE_SHOWING_TIMER,
BUBBLE_SHOWING_FADE,
BUBBLE_SHOWN
};
enum BubbleStyle {
STYLE_BOTTOM,
STYLE_FLOATING,
STYLE_STANDARD,
STYLE_STANDARD_RIGHT
};
StatusView(StatusBubble* status_bubble,
views::Widget* popup,
ui::ThemeProvider* theme_provider);
virtual ~StatusView();
void SetText(const base::string16& text, bool should_animate_open);
BubbleState state() const { return state_; }
BubbleStyle style() const { return style_; }
void SetStyle(BubbleStyle style);
void Show();
void Hide();
void ResetTimer();
void SetOpacity(double opacity);
void OnAnimationEnded();
private:
class InitialTimer;
void StartTimer(base::TimeDelta time);
void OnTimer();
void CancelTimer();
void RestartTimer(base::TimeDelta delay);
void StartFade(double start, double end, int duration);
void StartHiding();
void StartShowing();
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
BubbleState state_;
BubbleStyle style_;
base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_;
scoped_ptr<StatusViewAnimation> animation_;
StatusBubble* status_bubble_;
views::Widget* popup_;
base::string16 text_;
ui::ThemeProvider* theme_service_;
DISALLOW_COPY_AND_ASSIGN(StatusView);
};
StatusBubbleViews::StatusView::StatusView(StatusBubble* status_bubble,
views::Widget* popup,
ui::ThemeProvider* theme_provider)
: state_(BUBBLE_HIDDEN),
style_(STYLE_STANDARD),
timer_factory_(this),
animation_(new StatusViewAnimation(this, 0, 0)),
status_bubble_(status_bubble),
popup_(popup),
theme_service_(theme_provider) {
}
StatusBubbleViews::StatusView::~StatusView() {
animation_->Stop();
CancelTimer();
}
void StatusBubbleViews::StatusView::SetText(const base::string16& text,
bool should_animate_open) {
if (text.empty()) {
StartHiding();
} else {
if (text != text_) {
text_ = text;
SchedulePaint();
}
if (should_animate_open)
StartShowing();
}
}
void StatusBubbleViews::StatusView::Show() {
animation_->Stop();
CancelTimer();
SetOpacity(1.0);
popup_->ShowInactive();
state_ = BUBBLE_SHOWN;
}
void StatusBubbleViews::StatusView::Hide() {
animation_->Stop();
CancelTimer();
SetOpacity(0.0);
text_.clear();
popup_->Hide();
state_ = BUBBLE_HIDDEN;
}
void StatusBubbleViews::StatusView::StartTimer(base::TimeDelta time) {
if (timer_factory_.HasWeakPtrs())
timer_factory_.InvalidateWeakPtrs();
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&StatusBubbleViews::StatusView::OnTimer,
timer_factory_.GetWeakPtr()),
time);
}
void StatusBubbleViews::StatusView::OnTimer() {
if (state_ == BUBBLE_HIDING_TIMER) {
state_ = BUBBLE_HIDING_FADE;
StartFade(1.0, 0.0, kHideFadeDurationMS);
} else if (state_ == BUBBLE_SHOWING_TIMER) {
state_ = BUBBLE_SHOWING_FADE;
StartFade(0.0, 1.0, kShowFadeDurationMS);
}
}
void StatusBubbleViews::StatusView::CancelTimer() {
if (timer_factory_.HasWeakPtrs())
timer_factory_.InvalidateWeakPtrs();
}
void StatusBubbleViews::StatusView::RestartTimer(base::TimeDelta delay) {
CancelTimer();
StartTimer(delay);
}
void StatusBubbleViews::StatusView::ResetTimer() {
if (state_ == BUBBLE_SHOWING_TIMER) {
RestartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
}
}
void StatusBubbleViews::StatusView::StartFade(double start,
double end,
int duration) {
animation_.reset(new StatusViewAnimation(this, start, end));
animation_->SetDuration(duration);
animation_->Start();
}
void StatusBubbleViews::StatusView::StartHiding() {
if (state_ == BUBBLE_SHOWN) {
state_ = BUBBLE_HIDING_TIMER;
StartTimer(base::TimeDelta::FromMilliseconds(kHideDelay));
} else if (state_ == BUBBLE_SHOWING_TIMER) {
state_ = BUBBLE_HIDDEN;
popup_->Hide();
CancelTimer();
} else if (state_ == BUBBLE_SHOWING_FADE) {
state_ = BUBBLE_HIDING_FADE;
double current_opacity = animation_->GetCurrentOpacity();
StartFade(current_opacity, 0.0,
static_cast<int>(kHideFadeDurationMS * current_opacity));
}
}
void StatusBubbleViews::StatusView::StartShowing() {
if (state_ == BUBBLE_HIDDEN) {
popup_->ShowInactive();
state_ = BUBBLE_SHOWING_TIMER;
StartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
} else if (state_ == BUBBLE_HIDING_TIMER) {
state_ = BUBBLE_SHOWN;
CancelTimer();
} else if (state_ == BUBBLE_HIDING_FADE) {
state_ = BUBBLE_SHOWING_FADE;
double current_opacity = animation_->GetCurrentOpacity();
StartFade(current_opacity, 1.0,
static_cast<int>(kShowFadeDurationMS * current_opacity));
} else if (state_ == BUBBLE_SHOWING_TIMER) {
ResetTimer();
}
}
void StatusBubbleViews::StatusView::SetOpacity(double opacity) {
popup_->SetOpacity(static_cast<unsigned char>(opacity * 255));
}
void StatusBubbleViews::StatusView::SetStyle(BubbleStyle style) {
if (style_ != style) {
style_ = style;
SchedulePaint();
}
}
void StatusBubbleViews::StatusView::OnAnimationEnded() {
if (state_ == BUBBLE_HIDING_FADE) {
state_ = BUBBLE_HIDDEN;
popup_->Hide();
} else if (state_ == BUBBLE_SHOWING_FADE) {
state_ = BUBBLE_SHOWN;
}
}
void StatusBubbleViews::StatusView::OnPaint(gfx::Canvas* canvas) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setAntiAlias(true);
SkColor toolbar_color = theme_service_->GetColor(
ThemeProperties::COLOR_TOOLBAR);
paint.setColor(toolbar_color);
gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
SkScalar rad[8];
if (style_ == STYLE_BOTTOM) {
rad[0] = 0;
rad[1] = 0;
rad[2] = 0;
rad[3] = 0;
} else {
if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) {
rad[0] = SkIntToScalar(kBubbleCornerRadius);
rad[1] = SkIntToScalar(kBubbleCornerRadius);
rad[2] = 0;
rad[3] = 0;
} else {
rad[0] = 0;
rad[1] = 0;
rad[2] = SkIntToScalar(kBubbleCornerRadius);
rad[3] = SkIntToScalar(kBubbleCornerRadius);
}
}
if (style_ == STYLE_STANDARD || style_ == STYLE_STANDARD_RIGHT) {
rad[4] = 0;
rad[5] = 0;
rad[6] = 0;
rad[7] = 0;
} else {
rad[4] = SkIntToScalar(kBubbleCornerRadius);
rad[5] = SkIntToScalar(kBubbleCornerRadius);
rad[6] = SkIntToScalar(kBubbleCornerRadius);
rad[7] = SkIntToScalar(kBubbleCornerRadius);
}
int width = popup_bounds.width();
int height = popup_bounds.height();
SkRect rect(gfx::RectToSkRect(gfx::Rect(popup_bounds.size())));
SkPath shadow_path;
shadow_path.addRoundRect(rect, rad, SkPath::kCW_Direction);
SkPaint shadow_paint;
shadow_paint.setAntiAlias(true);
shadow_paint.setColor(kShadowColor);
canvas->DrawPath(shadow_path, shadow_paint);
rect.set(SkIntToScalar(kShadowThickness),
SkIntToScalar(kShadowThickness),
SkIntToScalar(width - kShadowThickness),
SkIntToScalar(height - kShadowThickness));
SkPath path;
path.addRoundRect(rect, rad, SkPath::kCW_Direction);
canvas->DrawPath(path, paint);
const gfx::FontList font_list;
int text_width = std::min(
gfx::GetStringWidth(text_, font_list),
width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding);
int text_height = height - (kShadowThickness * 2);
gfx::Rect body_bounds(kShadowThickness + kTextPositionX,
kShadowThickness,
std::max(0, text_width),
std::max(0, text_height));
body_bounds.set_x(GetMirroredXForRect(body_bounds));
SkColor text_color =
theme_service_->GetColor(ThemeProperties::COLOR_STATUS_BAR_TEXT);
canvas->DrawStringRect(text_, font_list, text_color, body_bounds);
}
StatusBubbleViews::StatusViewAnimation::StatusViewAnimation(
StatusView* status_view,
double opacity_start,
double opacity_end)
: gfx::LinearAnimation(kFramerate, this),
status_view_(status_view),
opacity_start_(opacity_start),
opacity_end_(opacity_end) {
}
StatusBubbleViews::StatusViewAnimation::~StatusViewAnimation() {
set_delegate(NULL);
}
double StatusBubbleViews::StatusViewAnimation::GetCurrentOpacity() {
return opacity_start_ + (opacity_end_ - opacity_start_) *
gfx::LinearAnimation::GetCurrentValue();
}
void StatusBubbleViews::StatusViewAnimation::AnimateToState(double state) {
status_view_->SetOpacity(GetCurrentOpacity());
}
void StatusBubbleViews::StatusViewAnimation::AnimationEnded(
const gfx::Animation* animation) {
status_view_->SetOpacity(opacity_end_);
status_view_->OnAnimationEnded();
}
class StatusBubbleViews::StatusViewExpander : public gfx::LinearAnimation,
public gfx::AnimationDelegate {
public:
StatusViewExpander(StatusBubbleViews* status_bubble,
StatusView* status_view)
: gfx::LinearAnimation(kFramerate, this),
status_bubble_(status_bubble),
status_view_(status_view),
expansion_start_(0),
expansion_end_(0) {
}
void StartExpansion(const base::string16& expanded_text,
int current_width,
int expansion_end);
void SetExpandedWidth(int expanded_width);
private:
int GetCurrentBubbleWidth();
void SetBubbleWidth(int width);
virtual void AnimateToState(double state) OVERRIDE;
virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
StatusBubbleViews* status_bubble_;
StatusView* status_view_;
base::string16 expanded_text_;
int expansion_start_;
int expansion_end_;
};
void StatusBubbleViews::StatusViewExpander::AnimateToState(double state) {
SetBubbleWidth(GetCurrentBubbleWidth());
}
void StatusBubbleViews::StatusViewExpander::AnimationEnded(
const gfx::Animation* animation) {
SetBubbleWidth(expansion_end_);
status_view_->SetText(expanded_text_, false);
}
void StatusBubbleViews::StatusViewExpander::StartExpansion(
const base::string16& expanded_text,
int expansion_start,
int expansion_end) {
expanded_text_ = expanded_text;
expansion_start_ = expansion_start;
expansion_end_ = expansion_end;
int min_duration = std::max(kMinExpansionStepDurationMS,
static_cast<int>(kMaxExpansionStepDurationMS *
(expansion_end - expansion_start) / 100.0));
SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration));
Start();
}
int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() {
return static_cast<int>(expansion_start_ +
(expansion_end_ - expansion_start_) *
gfx::LinearAnimation::GetCurrentValue());
}
void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) {
status_bubble_->SetBubbleWidth(width);
status_view_->SchedulePaint();
}
const int StatusBubbleViews::kShadowThickness = 1;
StatusBubbleViews::StatusBubbleViews(views::View* base_view)
: contains_mouse_(false),
offset_(0),
opacity_(0),
base_view_(base_view),
view_(NULL),
download_shelf_is_visible_(false),
is_expanded_(false),
expand_timer_factory_(this) {
expand_view_.reset();
}
StatusBubbleViews::~StatusBubbleViews() {
CancelExpandTimer();
if (popup_.get())
popup_->CloseNow();
}
void StatusBubbleViews::Init() {
if (!popup_.get()) {
popup_.reset(new views::Widget);
views::Widget* frame = base_view_->GetWidget();
if (!view_)
view_ = new StatusView(this, popup_.get(), frame->GetThemeProvider());
if (!expand_view_.get())
expand_view_.reset(new StatusViewExpander(this, view_));
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.accept_events = false;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.parent = frame->GetNativeView();
params.context = frame->GetNativeView();
popup_->Init(params);
#if defined(USE_AURA)
popup_->GetNativeView()->SetName("StatusBubbleViews");
#endif
popup_->SetVisibilityChangedAnimationsEnabled(false);
popup_->SetOpacity(0x00);
popup_->SetContentsView(view_);
#if defined(USE_ASH)
ash::wm::GetWindowState(popup_->GetNativeWindow())->
set_ignored_by_shelf(true);
#endif
RepositionPopup();
}
}
void StatusBubbleViews::Reposition() {
int overlap = kShadowThickness;
#if !defined(USE_ASH)
overlap +=
IsFrameMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness;
#endif
int height = GetPreferredSize().height();
int base_view_height = base_view()->bounds().height();
gfx::Point origin(-overlap, base_view_height - height + overlap);
SetBounds(origin.x(), origin.y(), base_view()->bounds().width() / 3, height);
}
void StatusBubbleViews::RepositionPopup() {
if (popup_.get()) {
gfx::Point top_left;
views::View::ConvertPointToScreen(base_view_, &top_left);
popup_->SetBounds(gfx::Rect(top_left.x() + position_.x(),
top_left.y() + position_.y(),
size_.width(), size_.height()));
}
}
gfx::Size StatusBubbleViews::GetPreferredSize() {
return gfx::Size(0, gfx::FontList().GetHeight() + kTotalVerticalPadding);
}
void StatusBubbleViews::SetBounds(int x, int y, int w, int h) {
original_position_.SetPoint(x, y);
position_.SetPoint(base_view_->GetMirroredXWithWidthInView(x, w), y);
size_.SetSize(w, h);
RepositionPopup();
if (popup_.get() && contains_mouse_)
AvoidMouse(last_mouse_moved_location_);
}
void StatusBubbleViews::SetStatus(const base::string16& status_text) {
if (size_.IsEmpty())
return;
if (status_text_ == status_text && !status_text.empty())
return;
if (!IsFrameVisible())
return;
Init();
status_text_ = status_text;
if (!status_text_.empty()) {
view_->SetText(status_text, true);
view_->Show();
} else if (!url_text_.empty()) {
view_->SetText(url_text_, true);
} else {
view_->SetText(base::string16(), true);
}
}
void StatusBubbleViews::SetURL(const GURL& url, const std::string& languages) {
url_ = url;
languages_ = languages;
if (size_.IsEmpty())
return;
Init();
if (url.is_empty() && !status_text_.empty()) {
url_text_ = base::string16();
if (IsFrameVisible())
view_->SetText(status_text_, true);
return;
}
if (view_->state() == StatusView::BUBBLE_HIDDEN) {
is_expanded_ = false;
SetBubbleWidth(GetStandardStatusBubbleWidth());
}
gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
int text_width = static_cast<int>(popup_bounds.width() -
(kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1);
url_text_ = ElideUrl(url, gfx::FontList(), text_width, languages);
url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_);
if (IsFrameVisible()) {
view_->SetText(url_text_, true);
CancelExpandTimer();
if (is_expanded_ && !url.is_empty()) {
ExpandBubble();
} else if (net::FormatUrl(url, languages).length() > url_text_.length()) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&StatusBubbleViews::ExpandBubble,
expand_timer_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS));
}
}
}
void StatusBubbleViews::Hide() {
status_text_ = base::string16();
url_text_ = base::string16();
if (view_)
view_->Hide();
}
void StatusBubbleViews::MouseMoved(const gfx::Point& location,
bool left_content) {
contains_mouse_ = !left_content;
if (left_content) {
RepositionPopup();
return;
}
last_mouse_moved_location_ = location;
if (view_) {
view_->ResetTimer();
if (view_->state() != StatusView::BUBBLE_HIDDEN &&
view_->state() != StatusView::BUBBLE_HIDING_FADE &&
view_->state() != StatusView::BUBBLE_HIDING_TIMER) {
AvoidMouse(location);
}
}
}
void StatusBubbleViews::UpdateDownloadShelfVisibility(bool visible) {
download_shelf_is_visible_ = visible;
}
void StatusBubbleViews::AvoidMouse(const gfx::Point& location) {
gfx::Point top_left;
views::View::ConvertPointToScreen(base_view_, &top_left);
int window_width = base_view_->GetLocalBounds().width();
gfx::Point relative_location = location;
if (base::i18n::IsRTL()) {
int top_right_x = top_left.x() + window_width;
relative_location.set_x(top_right_x - relative_location.x());
} else {
relative_location.set_x(
relative_location.x() - (top_left.x() + position_.x()));
}
relative_location.set_y(
relative_location.y() - (top_left.y() + position_.y()));
if (relative_location.y() > -kMousePadding &&
relative_location.x() < size_.width() + kMousePadding) {
int offset = kMousePadding + relative_location.y();
offset = offset * offset / kMousePadding;
if (relative_location.x() > size_.width()) {
offset = static_cast<int>(static_cast<float>(offset) * (
static_cast<float>(kMousePadding -
(relative_location.x() - size_.width())) /
static_cast<float>(kMousePadding)));
}
if (offset >= size_.height() - kShadowThickness * 2) {
offset = size_.height() - kShadowThickness * 2;
view_->SetStyle(StatusView::STYLE_BOTTOM);
} else if (offset > kBubbleCornerRadius / 2 - kShadowThickness) {
view_->SetStyle(StatusView::STYLE_FLOATING);
} else {
view_->SetStyle(StatusView::STYLE_STANDARD);
}
gfx::NativeView window = base_view_->GetWidget()->GetNativeView();
gfx::Rect monitor_rect = gfx::Screen::GetScreenFor(window)->
GetDisplayNearestWindow(window).work_area();
const int bubble_bottom_y = top_left.y() + position_.y() + size_.height();
if (bubble_bottom_y + offset > monitor_rect.height() ||
(download_shelf_is_visible_ &&
(view_->style() == StatusView::STYLE_FLOATING ||
view_->style() == StatusView::STYLE_BOTTOM))) {
view_->SetStyle(StatusView::STYLE_STANDARD_RIGHT);
offset_ = 0;
int right_position_x = window_width - (position_.x() + size_.width());
popup_->SetBounds(gfx::Rect(top_left.x() + right_position_x,
top_left.y() + position_.y(),
size_.width(), size_.height()));
} else {
offset_ = offset;
popup_->SetBounds(gfx::Rect(top_left.x() + position_.x(),
top_left.y() + position_.y() + offset_,
size_.width(), size_.height()));
}
} else if (offset_ != 0 ||
view_->style() == StatusView::STYLE_STANDARD_RIGHT) {
offset_ = 0;
view_->SetStyle(StatusView::STYLE_STANDARD);
popup_->SetBounds(gfx::Rect(top_left.x() + position_.x(),
top_left.y() + position_.y(),
size_.width(), size_.height()));
}
}
bool StatusBubbleViews::IsFrameVisible() {
views::Widget* frame = base_view_->GetWidget();
if (!frame->IsVisible())
return false;
views::Widget* window = frame->GetTopLevelWidget();
return !window || !window->IsMinimized();
}
bool StatusBubbleViews::IsFrameMaximized() {
views::Widget* frame = base_view_->GetWidget();
views::Widget* window = frame->GetTopLevelWidget();
return window && window->IsMaximized();
}
void StatusBubbleViews::ExpandBubble() {
gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
int max_status_bubble_width = GetMaxStatusBubbleWidth();
const gfx::FontList font_list;
url_text_ = ElideUrl(url_, font_list, max_status_bubble_width, languages_);
int expanded_bubble_width =
std::max(GetStandardStatusBubbleWidth(),
std::min(gfx::GetStringWidth(url_text_, font_list) +
(kShadowThickness * 2) + kTextPositionX +
kTextHorizPadding + 1,
max_status_bubble_width));
is_expanded_ = true;
expand_view_->StartExpansion(url_text_, popup_bounds.width(),
expanded_bubble_width);
}
int StatusBubbleViews::GetStandardStatusBubbleWidth() {
return base_view_->bounds().width() / 3;
}
int StatusBubbleViews::GetMaxStatusBubbleWidth() {
const ui::NativeTheme* theme = base_view_->GetNativeTheme();
return static_cast<int>(std::max(0, base_view_->bounds().width() -
(kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 -
views::NativeScrollBar::GetVerticalScrollBarWidth(theme)));
}
void StatusBubbleViews::SetBubbleWidth(int width) {
size_.set_width(width);
SetBounds(original_position_.x(), original_position_.y(),
size_.width(), size_.height());
}
void StatusBubbleViews::CancelExpandTimer() {
if (expand_timer_factory_.HasWeakPtrs())
expand_timer_factory_.InvalidateWeakPtrs();
}