Chromium Code Reviews| Index: ui/views/bubble/info_bubble.cc |
| diff --git a/chrome/browser/ui/views/autofill/info_bubble.cc b/ui/views/bubble/info_bubble.cc |
| similarity index 66% |
| rename from chrome/browser/ui/views/autofill/info_bubble.cc |
| rename to ui/views/bubble/info_bubble.cc |
| index ecc7bc152cf3f8c21a847705eee0453baec543ad..1a8909d536def6fe682d1193c2dc830c24bdf210 100644 |
| --- a/chrome/browser/ui/views/autofill/info_bubble.cc |
| +++ b/ui/views/bubble/info_bubble.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/views/autofill/info_bubble.h" |
| +#include "ui/views/bubble/info_bubble.h" |
| #include "base/i18n/rtl.h" |
|
msw
2017/02/15 21:06:38
nit: remove
vasilii
2017/02/16 14:28:06
Done.
|
| #include "base/macros.h" |
|
msw
2017/02/15 21:06:38
nit: remove
vasilii
2017/02/16 14:28:06
Done.
|
| @@ -18,7 +18,7 @@ |
| #include "ui/views/layout/layout_constants.h" |
|
msw
2017/02/15 21:06:38
nit: remove?
vasilii
2017/02/16 14:28:06
Done.
|
| #include "ui/views/widget/widget.h" |
| -namespace autofill { |
| +namespace views { |
| namespace { |
| @@ -29,12 +29,22 @@ const int kBubbleBorderVisibleWidth = 1; |
| const int kInfoBubbleHorizontalMargin = 14; |
| const int kInfoBubbleVerticalMargin = 12; |
| +gfx::Insets GetPreferredInsets(const View* view) { |
|
msw
2017/02/15 21:06:38
nit: add a comment or inline in the one caller
vasilii
2017/02/16 14:28:06
Acknowledged.
|
| + gfx::Size pref_size = view->GetPreferredSize(); |
| + gfx::Rect local_bounds = view->GetLocalBounds(); |
| + gfx::Point origin = local_bounds.CenterPoint(); |
|
msw
2017/02/15 21:06:38
I'm confused by this function; what is it trying t
vasilii
2017/02/16 14:28:06
Looks like the function does nothing. The insets a
|
| + origin.Offset(-pref_size.width() / 2, -pref_size.height() / 2); |
| + return gfx::Insets(origin.y(), origin.x(), |
| + local_bounds.bottom() - (origin.y() + pref_size.height()), |
| + local_bounds.right() - (origin.x() + pref_size.width())); |
| +} |
| + |
| } // namespace |
| -class InfoBubbleFrame : public views::BubbleFrameView { |
| +class InfoBubbleFrame : public BubbleFrameView { |
| public: |
| explicit InfoBubbleFrame(const gfx::Insets& content_margins) |
| - : views::BubbleFrameView(gfx::Insets(), content_margins) {} |
| + : BubbleFrameView(gfx::Insets(), content_margins) {} |
| ~InfoBubbleFrame() override {} |
| gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { |
| @@ -52,24 +62,22 @@ class InfoBubbleFrame : public views::BubbleFrameView { |
| DISALLOW_COPY_AND_ASSIGN(InfoBubbleFrame); |
| }; |
| -InfoBubble::InfoBubble(views::View* anchor, |
| - const base::string16& message) |
| +InfoBubble::InfoBubble(View* anchor, const base::string16& message) |
| : anchor_(anchor), |
| frame_(NULL), |
| align_to_anchor_edge_(false), |
| - preferred_width_(233), |
| + preferred_width_(0), |
| show_above_anchor_(false) { |
| DCHECK(anchor_); |
| SetAnchorView(anchor_); |
| - set_margins(gfx::Insets(kInfoBubbleVerticalMargin, |
| - kInfoBubbleHorizontalMargin, |
| - kInfoBubbleVerticalMargin, |
| - kInfoBubbleHorizontalMargin)); |
| + set_margins( |
| + gfx::Insets(kInfoBubbleVerticalMargin, kInfoBubbleHorizontalMargin, |
|
msw
2017/02/15 21:06:38
nit: use two-arg ctor
vasilii
2017/02/16 14:28:06
Done.
|
| + kInfoBubbleVerticalMargin, kInfoBubbleHorizontalMargin)); |
| set_can_activate(false); |
| - SetLayoutManager(new views::FillLayout); |
| - views::Label* label = new views::Label(message); |
| + SetLayoutManager(new FillLayout); |
| + Label* label = new Label(message); |
| label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| label->SetMultiLine(true); |
| AddChildView(label); |
| @@ -84,22 +92,22 @@ void InfoBubble::Show() { |
| // this might happen and adjust |show_above_anchor_| accordingly. This is not |
| // that big of deal because it rarely happens in practice. |
| if (show_above_anchor_) |
| - set_arrow(views::BubbleBorder::vertical_mirror(arrow())); |
| + set_arrow(BubbleBorder::vertical_mirror(arrow())); |
| - widget_ = views::BubbleDialogDelegateView::CreateBubble(this); |
| + widget_ = BubbleDialogDelegateView::CreateBubble(this); |
| if (align_to_anchor_edge_) { |
| // The frame adjusts its arrow before the bubble's alignment can be changed. |
| // Set the created bubble border back to the original arrow and re-adjust. |
| frame_->bubble_border()->set_arrow(arrow()); |
| - SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| + SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| } |
| UpdatePosition(); |
| } |
| void InfoBubble::Hide() { |
| - views::Widget* widget = GetWidget(); |
| + Widget* widget = GetWidget(); |
| if (widget && !widget->IsClosed()) |
| widget->Close(); |
| } |
| @@ -118,31 +126,33 @@ void InfoBubble::UpdatePosition() { |
| } |
| } |
| -views::NonClientFrameView* InfoBubble::CreateNonClientFrameView( |
| - views::Widget* widget) { |
| +NonClientFrameView* InfoBubble::CreateNonClientFrameView(Widget* widget) { |
| DCHECK(!frame_); |
| frame_ = new InfoBubbleFrame(margins()); |
| frame_->set_available_bounds(anchor_widget()->GetWindowBoundsInScreen()); |
| - frame_->SetBubbleBorder(std::unique_ptr<views::BubbleBorder>( |
| - new views::BubbleBorder(arrow(), shadow(), color()))); |
| + frame_->SetBubbleBorder(std::unique_ptr<BubbleBorder>( |
| + new BubbleBorder(arrow(), shadow(), color()))); |
| return frame_; |
| } |
| gfx::Size InfoBubble::GetPreferredSize() const { |
| + if (!preferred_width_) |
|
msw
2017/02/15 21:06:38
nit: if |preferred_width_ <= 0| (or ==)
vasilii
2017/02/16 14:28:06
Done.
|
| + return BubbleDialogDelegateView::GetPreferredSize(); |
| + |
| int pref_width = preferred_width_; |
| pref_width -= frame_->GetInsets().width(); |
| pref_width -= 2 * kBubbleBorderVisibleWidth; |
| return gfx::Size(pref_width, GetHeightForWidth(pref_width)); |
| } |
| -void InfoBubble::OnWidgetDestroyed(views::Widget* widget) { |
| +void InfoBubble::OnWidgetDestroyed(Widget* widget) { |
| if (widget == widget_) |
| widget_ = NULL; |
| } |
| -void InfoBubble::OnWidgetBoundsChanged(views::Widget* widget, |
| +void InfoBubble::OnWidgetBoundsChanged(Widget* widget, |
| const gfx::Rect& new_bounds) { |
| - views::BubbleDialogDelegateView::OnWidgetBoundsChanged(widget, new_bounds); |
| + BubbleDialogDelegateView::OnWidgetBoundsChanged(widget, new_bounds); |
| if (anchor_widget() == widget) |
| frame_->set_available_bounds(widget->GetWindowBoundsInScreen()); |
| } |
| @@ -151,4 +161,10 @@ int InfoBubble::GetDialogButtons() const { |
| return ui::DIALOG_BUTTON_NONE; |
| } |
| -} // namespace autofill |
| +gfx::Rect InfoBubble::GetAnchorRect() const { |
| + gfx::Rect bounds = BubbleDialogDelegateView::GetAnchorRect(); |
| + bounds.Inset(GetPreferredInsets(anchor())); |
| + return bounds; |
| +} |
| + |
| +} // namespace views |