diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 22:33:56 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 22:33:56 +0000 |
commit | 37c1cfb34294b31a47711b8bdb87165a91478eb6 (patch) | |
tree | 8ee5ef58f97bff47db03b17239173451f9a390d0 /chrome/browser/views | |
parent | 09d46b7984480d74ec8a0d9163a6072757f2056b (diff) | |
download | chromium_src-37c1cfb34294b31a47711b8bdb87165a91478eb6.zip chromium_src-37c1cfb34294b31a47711b8bdb87165a91478eb6.tar.gz chromium_src-37c1cfb34294b31a47711b8bdb87165a91478eb6.tar.bz2 |
Adding a way to pin the info bubble arrow.
It is useful with the app launcher that should
always stay at the same location.
BUG=43754
TEST=Open the app launcher with the Chrome window at the bottom of
the screen. The app launcher bubble should be displayed in the browser,
with the app launcher location bar aligned with the browser's one.
Review URL: http://codereview.chromium.org/2000005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 47 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/pinned_contents_info_bubble.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/pinned_contents_info_bubble.h | 1 |
4 files changed, 34 insertions, 26 deletions
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 63dc590..5bfb822 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -41,6 +41,7 @@ void BorderContents::Init() { void BorderContents::SizeAndGetBounds( const gfx::Rect& position_relative_to, BubbleBorder::ArrowLocation arrow_location, + bool allow_bubble_offscreen, const gfx::Size& contents_size, gfx::Rect* contents_bounds, gfx::Rect* window_bounds) { @@ -60,26 +61,28 @@ void BorderContents::SizeAndGetBounds( *window_bounds = bubble_border_->GetBounds(position_relative_to, local_contents_size); - // See if those bounds will fit on the monitor. - scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_provider( - WindowSizer::CreateDefaultMonitorInfoProvider()); - gfx::Rect monitor_bounds( - monitor_provider->GetMonitorWorkAreaMatching(position_relative_to)); - if (!monitor_bounds.IsEmpty() && !monitor_bounds.Contains(*window_bounds)) { - // The bounds don't fit. Move the arrow to try and improve things. - if (window_bounds->bottom() > monitor_bounds.bottom()) - arrow_location = BubbleBorder::horizontal_mirror(arrow_location); - else if (BubbleBorder::is_arrow_on_left(arrow_location) ? - (window_bounds->right() > monitor_bounds.right()) : - (window_bounds->x() < monitor_bounds.x())) { - arrow_location = BubbleBorder::rtl_mirror(arrow_location); + if (!allow_bubble_offscreen) { + // See if those bounds will fit on the monitor. + scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_provider( + WindowSizer::CreateDefaultMonitorInfoProvider()); + gfx::Rect monitor_bounds( + monitor_provider->GetMonitorWorkAreaMatching(position_relative_to)); + if (!monitor_bounds.IsEmpty() && !monitor_bounds.Contains(*window_bounds)) { + // The bounds don't fit. Move the arrow to try and improve things. + if (window_bounds->bottom() > monitor_bounds.bottom()) + arrow_location = BubbleBorder::horizontal_mirror(arrow_location); + else if (BubbleBorder::is_arrow_on_left(arrow_location) ? + (window_bounds->right() > monitor_bounds.right()) : + (window_bounds->x() < monitor_bounds.x())) { + arrow_location = BubbleBorder::rtl_mirror(arrow_location); + } + + bubble_border_->set_arrow_location(arrow_location); + + // Now get the recalculated bounds. + *window_bounds = bubble_border_->GetBounds(position_relative_to, + local_contents_size); } - - bubble_border_->set_arrow_location(arrow_location); - - // Now get the recalculated bounds. - *window_bounds = bubble_border_->GetBounds(position_relative_to, - local_contents_size); } // Calculate the bounds of the contained contents (in window coordinates) by @@ -143,7 +146,7 @@ gfx::Rect BorderWidget::SizeAndGetBounds( gfx::Rect contents_bounds; gfx::Rect window_bounds; border_contents_->SizeAndGetBounds(position_relative_to, arrow_location, - contents_size, &contents_bounds, + false, contents_size, &contents_bounds, &window_bounds); SetBounds(window_bounds); @@ -271,7 +274,7 @@ void InfoBubble::Init(views::Widget* parent, border_contents_->Init(); gfx::Rect contents_bounds; border_contents_->SizeAndGetBounds(position_relative_to, - arrow_location, contents->GetPreferredSize(), + arrow_location, false, contents->GetPreferredSize(), &contents_bounds, &window_bounds); // This new view must be added before |contents| so it will paint under it. contents_view->AddChildView(0, border_contents_); @@ -318,7 +321,7 @@ void InfoBubble::SizeToContents() { #else gfx::Rect contents_bounds; border_contents_->SizeAndGetBounds(position_relative_to_, - arrow_location_, contents_->GetPreferredSize(), + arrow_location_, false, contents_->GetPreferredSize(), &contents_bounds, &window_bounds); // |contents_view| has no layout manager, so we have to explicitly position // its children. diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h index fa15bf7..f6d774d 100644 --- a/chrome/browser/views/info_bubble.h +++ b/chrome/browser/views/info_bubble.h @@ -49,11 +49,13 @@ class BorderContents : public views::View { // Given the size of the contents and the rect to point at, returns the bounds // of both the border and the contents inside the bubble. // |arrow_location| specifies the preferred location for the arrow - // anchor. If the bubble does not fit on the monitor, the arrow location may - // changed so it can. In case of RTL arrow is mirrored. + // anchor. If the bubble does not fit on the monitor and + // |allow_bubble_offscreen| is false, the arrow location may change so the + // bubble shows entirely. virtual void SizeAndGetBounds( const gfx::Rect& position_relative_to, // In screen coordinates BubbleBorder::ArrowLocation arrow_location, + bool allow_bubble_offscreen, const gfx::Size& contents_size, gfx::Rect* contents_bounds, // Returned in window coordinates gfx::Rect* window_bounds); // Returned in screen coordinates diff --git a/chrome/browser/views/pinned_contents_info_bubble.cc b/chrome/browser/views/pinned_contents_info_bubble.cc index 8f6c1636..532dcdf 100644 --- a/chrome/browser/views/pinned_contents_info_bubble.cc +++ b/chrome/browser/views/pinned_contents_info_bubble.cc @@ -12,6 +12,7 @@ void PinnedContentsBorderContents::SizeAndGetBounds( const gfx::Rect& position_relative_to, BubbleBorder::ArrowLocation arrow_location, + bool allow_bubble_offscreen, const gfx::Size& contents_size, gfx::Rect* contents_bounds, gfx::Rect* window_bounds) { @@ -25,8 +26,9 @@ void PinnedContentsBorderContents::SizeAndGetBounds( bubble_border_->SetArrowOffset(offset, contents_size); BorderContents::SizeAndGetBounds( - position_relative_to, arrow_location, contents_size, - contents_bounds, window_bounds); + position_relative_to, arrow_location, + true, // Don't move the bubble around if it does not fit on the screen. + contents_size, contents_bounds, window_bounds); // Now move the y position to make sure the bubble contents overlap the view. window_bounds->Offset(0, -(kTopMargin + 1)); diff --git a/chrome/browser/views/pinned_contents_info_bubble.h b/chrome/browser/views/pinned_contents_info_bubble.h index d93b0e2..87d2a9d 100644 --- a/chrome/browser/views/pinned_contents_info_bubble.h +++ b/chrome/browser/views/pinned_contents_info_bubble.h @@ -19,6 +19,7 @@ class PinnedContentsBorderContents : public BorderContents { virtual void SizeAndGetBounds( const gfx::Rect& position_relative_to, // In screen coordinates BubbleBorder::ArrowLocation arrow_location, + bool allow_bubble_offscreen, const gfx::Size& contents_size, gfx::Rect* contents_bounds, // Returned in window coordinates gfx::Rect* window_bounds); // Returned in screen coordinates |