summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r--chrome/browser/notifications/balloon_collection.cc65
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h7
2 files changed, 52 insertions, 20 deletions
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc
index 52b25fc..d5b92be 100644
--- a/chrome/browser/notifications/balloon_collection.cc
+++ b/chrome/browser/notifications/balloon_collection.cc
@@ -41,9 +41,11 @@ BalloonCollectionImpl::~BalloonCollectionImpl() {
void BalloonCollectionImpl::Add(const Notification& notification,
Profile* profile) {
Balloon* new_balloon = MakeBalloon(notification, profile);
+
+ new_balloon->SetPosition(layout_.OffScreenLocation(), true);
+ new_balloon->Show();
balloons_.push_back(new_balloon);
PositionBalloons(false);
- new_balloon->Show();
// There may be no listener in a unit test.
if (space_change_listener_)
@@ -79,24 +81,8 @@ bool BalloonCollectionImpl::HasSpace() const {
void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon,
const gfx::Size& size) {
- // restrict to the min & max sizes
- gfx::Size real_size(
- std::max(Layout::min_balloon_width(),
- std::min(Layout::max_balloon_width(), size.width())),
- std::max(Layout::min_balloon_height(),
- std::min(Layout::max_balloon_height(), size.height())));
-
- // Don't allow balloons to shrink. This avoids flickering
- // on Mac OS which sometimes rapidly reports alternating sizes. Special
- // case for setting the minimum value.
- gfx::Size old_size = balloon->content_size();
- if (real_size.width() > old_size.width() ||
- real_size.height() > old_size.height() ||
- real_size == gfx::Size(Layout::min_balloon_width(),
- Layout::min_balloon_height())) {
- balloon->set_content_size(real_size);
- PositionBalloons(true);
- }
+ balloon->set_content_size(Layout::ConstrainToSizeLimits(size));
+ PositionBalloons(true);
}
void BalloonCollectionImpl::DisplayChanged() {
@@ -123,7 +109,8 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
void BalloonCollectionImpl::PositionBalloons(bool reposition) {
gfx::Point origin = layout_.GetLayoutOrigin();
for (Balloons::iterator it = balloons_.begin(); it != balloons_.end(); ++it) {
- gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin);
+ gfx::Point upper_left = layout_.NextPosition(
+ Layout::ConstrainToSizeLimits((*it)->GetViewSize()), &origin);
(*it)->SetPosition(upper_left, reposition);
}
}
@@ -219,6 +206,44 @@ gfx::Point BalloonCollectionImpl::Layout::NextPosition(
return gfx::Point(x, y);
}
+gfx::Point BalloonCollectionImpl::Layout::OffScreenLocation() const {
+ int x = 0;
+ int y = 0;
+ switch (placement_) {
+ case HORIZONTALLY_FROM_BOTTOM_LEFT:
+ x = work_area_.x() - kBalloonMaxWidth - HorizontalEdgeMargin();
+ y = work_area_.bottom() - kBalloonMaxHeight - VerticalEdgeMargin();
+ break;
+ case HORIZONTALLY_FROM_BOTTOM_RIGHT:
+ x = work_area_.right() + HorizontalEdgeMargin();
+ y = work_area_.bottom() - kBalloonMaxHeight - VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_TOP_RIGHT:
+ x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
+ y = work_area_.y() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ case VERTICALLY_FROM_BOTTOM_RIGHT:
+ x = work_area_.right() - kBalloonMaxWidth - HorizontalEdgeMargin();
+ y = work_area_.bottom() + kBalloonMaxHeight + VerticalEdgeMargin();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return gfx::Point(x, y);
+}
+
+// static
+gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits(
+ const gfx::Size& size) {
+ // restrict to the min & max sizes
+ return gfx::Size(
+ std::max(min_balloon_width(),
+ std::min(max_balloon_width(), size.width())),
+ std::max(min_balloon_height(),
+ std::min(max_balloon_height(), size.height())));
+}
+
bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
bool changed = false;
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index 1f3403a..262df06 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -51,6 +51,9 @@ class BalloonCollectionImpl : public BalloonCollection {
static int min_balloon_height() { return kBalloonMinHeight; }
static int max_balloon_height() { return kBalloonMaxHeight; }
+ // Utility function constrains the input rectangle to the min and max sizes.
+ static gfx::Size ConstrainToSizeLimits(const gfx::Size& rect);
+
// Returns both the total space available and the maximum
// allowed per balloon.
//
@@ -75,6 +78,10 @@ class BalloonCollectionImpl : public BalloonCollection {
gfx::Point NextPosition(const gfx::Size& balloon_size,
gfx::Point* position_iterator) const;
+ // Return a offscreen location which is offscreen for this layout,
+ // to be used as the initial position for an animation into view.
+ gfx::Point OffScreenLocation() const;
+
private:
enum Placement {
HORIZONTALLY_FROM_BOTTOM_LEFT,