diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 18:56:01 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-27 18:56:01 +0000 |
commit | a2f00ee6301f053e0c071ef59592acc871406d87 (patch) | |
tree | ad51cb6a747c44d51d6f2f52cce5044bce9bc8cd | |
parent | d2f05d07a90cf5c5bad814b603175acaefa254b5 (diff) | |
download | chromium_src-a2f00ee6301f053e0c071ef59592acc871406d87.zip chromium_src-a2f00ee6301f053e0c071ef59592acc871406d87.tar.gz chromium_src-a2f00ee6301f053e0c071ef59592acc871406d87.tar.bz2 |
For desktop notifications, only use offsets when the layout calls for them.
BUG=69098
TEST=try notifications in all corners, verify correct layout after close
Review URL: http://codereview.chromium.org/6307013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72847 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/notifications/balloon_collection.cc | 53 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection_impl.h | 4 |
2 files changed, 39 insertions, 18 deletions
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc index ff0fed5..0dc643d 100644 --- a/chrome/browser/notifications/balloon_collection.cc +++ b/chrome/browser/notifications/balloon_collection.cc @@ -53,7 +53,7 @@ void BalloonCollectionImpl::Add(const Notification& notification, new_balloon->Show(); #if USE_OFFSETS int count = base_.count(); - if (count > 0) + if (count > 0 && layout_.RequiresOffsets()) new_balloon->set_offset(base_.balloons()[count - 1]->offset()); #endif base_.Add(new_balloon); @@ -112,26 +112,28 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) { Balloons::const_iterator it = balloons.begin(); #if USE_OFFSETS - gfx::Point offset; - bool apply_offset = false; - while (it != balloons.end()) { - if (*it == source) { - ++it; - if (it != balloons.end()) { - apply_offset = true; - offset.set_y((source)->offset().y() - (*it)->offset().y() + - (*it)->content_size().height() - source->content_size().height()); + if (layout_.RequiresOffsets()) { + gfx::Point offset; + bool apply_offset = false; + while (it != balloons.end()) { + if (*it == source) { + ++it; + if (it != balloons.end()) { + apply_offset = true; + offset.set_y((source)->offset().y() - (*it)->offset().y() + + (*it)->content_size().height() - source->content_size().height()); + } + } else { + if (apply_offset) + (*it)->add_offset(offset); + ++it; } - } else { - if (apply_offset) - (*it)->add_offset(offset); - ++it; } + // Start listening for UI events so we cancel the offset when the mouse + // leaves the balloon area. + if (apply_offset) + AddMessageLoopObserver(); } - // Start listening for UI events so we cancel the offset when the mouse - // leaves the balloon area. - if (apply_offset) - AddMessageLoopObserver(); #endif base_.Remove(source); @@ -330,6 +332,21 @@ gfx::Point BalloonCollectionImpl::Layout::OffScreenLocation() const { return gfx::Point(x, y); } +bool BalloonCollectionImpl::Layout::RequiresOffsets() const { + // Layout schemes that grow up from the bottom require offsets; + // schemes that grow down do not require offsets. + bool offsets = (placement_ == VERTICALLY_FROM_BOTTOM_LEFT || + placement_ == VERTICALLY_FROM_BOTTOM_RIGHT); + +#if defined(OS_MACOSX) + // These schemes are in screen-coordinates, and top and bottom + // are inverted on Mac. + offsets = !offsets; +#endif + + return offsets; +} + // static gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits( const gfx::Size& size) { diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h index 1c87037..bb4525d 100644 --- a/chrome/browser/notifications/balloon_collection_impl.h +++ b/chrome/browser/notifications/balloon_collection_impl.h @@ -120,6 +120,10 @@ class BalloonCollectionImpl : public BalloonCollection // to be used as the initial position for an animation into view. gfx::Point OffScreenLocation() const; + // Returns true if the layout requires offsetting for keeping the close + // buttons under the cursor during rapid-close interaction. + bool RequiresOffsets() const; + private: // Layout parameters int VerticalEdgeMargin() const; |