diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 18:59:57 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 18:59:57 +0000 |
commit | 9a85f4cde6f4b702cb249768ba0a18dbc1766907 (patch) | |
tree | 4f34b1bab489172125eecaf5f2207ebca106c002 /ui/views/bubble | |
parent | 2916b4038bb7f3ca203f32039145bc8cdd3bf735 (diff) | |
download | chromium_src-9a85f4cde6f4b702cb249768ba0a18dbc1766907.zip chromium_src-9a85f4cde6f4b702cb249768ba0a18dbc1766907.tar.gz chromium_src-9a85f4cde6f4b702cb249768ba0a18dbc1766907.tar.bz2 |
Fix alignment of avatar bubbles in the NTP
BUG=105014
TEST=
Review URL: http://codereview.chromium.org/8863009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/bubble')
-rw-r--r-- | ui/views/bubble/bubble_delegate.cc | 19 | ||||
-rw-r--r-- | ui/views/bubble/bubble_delegate.h | 7 | ||||
-rw-r--r-- | ui/views/bubble/bubble_frame_view.cc | 16 | ||||
-rw-r--r-- | ui/views/bubble/bubble_frame_view.h | 4 |
4 files changed, 33 insertions, 13 deletions
diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_delegate.cc index 1abae30..10aeddf 100644 --- a/ui/views/bubble/bubble_delegate.cc +++ b/ui/views/bubble/bubble_delegate.cc @@ -160,12 +160,12 @@ void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, } } -gfx::Point BubbleDelegateView::GetAnchorPoint() { +gfx::Rect BubbleDelegateView::GetAnchorRect() { if (!anchor_view()) - return gfx::Point(); + return gfx::Rect(); BubbleBorder::ArrowLocation location = GetArrowLocation(); - gfx::Point anchor(anchor_view()->bounds().CenterPoint()); + gfx::Point anchor; // By default, pick the middle of |anchor_view_|'s edge opposite the arrow. if (BubbleBorder::is_arrow_on_horizontal(location)) { anchor.SetPoint(anchor_view()->width() / 2, @@ -174,9 +174,11 @@ gfx::Point BubbleDelegateView::GetAnchorPoint() { anchor.SetPoint( BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0, anchor_view_->height() / 2); + } else { + anchor = anchor_view()->bounds().CenterPoint(); } View::ConvertPointToScreen(anchor_view(), &anchor); - return anchor; + return gfx::Rect(anchor, gfx::Size()); } BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { @@ -217,6 +219,11 @@ void BubbleDelegateView::ResetFade() { GetWidget()->SetOpacity(original_opacity_); } +void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { + GetBubbleFrameView()->bubble_border()->set_alignment(alignment); + SizeToContents(); +} + bool BubbleDelegateView::AcceleratorPressed( const ui::Accelerator& accelerator) { if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) @@ -278,8 +285,8 @@ BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { gfx::Rect BubbleDelegateView::GetBubbleBounds() { // The argument rect has its origin at the bubble's arrow anchor point; // its size is the preferred size of the bubble's client view (this view). - return GetBubbleFrameView()->GetWindowBoundsForClientBounds( - gfx::Rect(GetAnchorPoint(), GetPreferredSize())); + return GetBubbleFrameView()->GetWindowBoundsForAnchorAndClientSize( + GetAnchorRect(), GetPreferredSize()); } #if defined(OS_WIN) && !defined(USE_AURA) diff --git a/ui/views/bubble/bubble_delegate.h b/ui/views/bubble/bubble_delegate.h index 3211a3e..01bd518 100644 --- a/ui/views/bubble/bubble_delegate.h +++ b/ui/views/bubble/bubble_delegate.h @@ -72,8 +72,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, use_focusless_ = use_focusless; } - // Get the arrow's anchor point in screen space. - virtual gfx::Point GetAnchorPoint(); + // Get the arrow's anchor rect in screen space. + virtual gfx::Rect GetAnchorRect(); // Get the arrow's location on the bubble. virtual BubbleBorder::ArrowLocation GetArrowLocation() const; @@ -89,6 +89,9 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, // bubble to the setting before StartFade() was called. void ResetFade(); + // Sets the bubble alignment relative to the anchor. + void SetAlignment(BubbleBorder::BubbleAlignment alignment); + protected: // View overrides: virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; diff --git a/ui/views/bubble/bubble_frame_view.cc b/ui/views/bubble/bubble_frame_view.cc index 11d1b20..4e73155 100644 --- a/ui/views/bubble/bubble_frame_view.cc +++ b/ui/views/bubble/bubble_frame_view.cc @@ -26,8 +26,8 @@ BubbleFrameView::BubbleFrameView(BubbleBorder::ArrowLocation location, bubble_border()->set_background_color(color); SetLayoutManager(new views::FillLayout()); AddChildView(border_contents_); - gfx::Rect bounds(gfx::Point(), client_size); - gfx::Rect windows_bounds = GetWindowBoundsForClientBounds(bounds); + gfx::Rect windows_bounds = + GetWindowBoundsForAnchorAndClientSize(gfx::Rect(), client_size); border_contents_->SetBoundsRect( gfx::Rect(gfx::Point(), windows_bounds.size())); SetBoundsRect(windows_bounds); @@ -48,14 +48,20 @@ gfx::Rect BubbleFrameView::GetBoundsForClientView() const { gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const { // The |client_bounds| origin is the bubble arrow anchor point. - gfx::Rect position_relative_to(client_bounds.origin(), gfx::Size()); + gfx::Rect anchor(client_bounds.origin(), gfx::Size()); // The |client_bounds| size is the bubble client view size. + return GetWindowBoundsForAnchorAndClientSize(anchor, client_bounds.size()); +} + +gfx::Rect BubbleFrameView::GetWindowBoundsForAnchorAndClientSize( + const gfx::Rect& anchor, + const gfx::Size& client_size) const { gfx::Rect content_bounds; gfx::Rect window_bounds; - border_contents_->SizeAndGetBounds(position_relative_to, + border_contents_->SizeAndGetBounds(anchor, location_, allow_bubble_offscreen_, - client_bounds.size(), + client_size, &content_bounds, &window_bounds); return window_bounds; diff --git a/ui/views/bubble/bubble_frame_view.h b/ui/views/bubble/bubble_frame_view.h index 47861eb..5a8661d 100644 --- a/ui/views/bubble/bubble_frame_view.h +++ b/ui/views/bubble/bubble_frame_view.h @@ -41,6 +41,10 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView { // Accessor for bubble border inside border contents. BubbleBorder* bubble_border() const; + gfx::Rect GetWindowBoundsForAnchorAndClientSize( + const gfx::Rect& anchor, + const gfx::Size& client_size) const; + private: FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewBasicTest, GetBoundsForClientView); |