summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 19:31:02 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 19:31:02 +0000
commit06cb6bad29d699406c69c2ca7a92437fcfb02dde (patch)
tree9cc4676e0ce9d4ba6f053c3c568c5e1b1f6a6653
parent3ab155c9b0b17d7edd376091ed6f2ac6a4695457 (diff)
downloadchromium_src-06cb6bad29d699406c69c2ca7a92437fcfb02dde.zip
chromium_src-06cb6bad29d699406c69c2ca7a92437fcfb02dde.tar.gz
chromium_src-06cb6bad29d699406c69c2ca7a92437fcfb02dde.tar.bz2
Make the balloon bounding box code more generic and not dependent on which layout the notifications are using.
BUG=none TEST=included unit test Review URL: http://codereview.chromium.org/6210001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70921 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/notifications/balloon_collection.cc17
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h3
-rw-r--r--chrome/browser/notifications/balloon_collection_linux.cc14
-rw-r--r--chrome/browser/notifications/balloon_collection_win.cc15
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc33
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.h5
6 files changed, 60 insertions, 27 deletions
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc
index 60c9f2d..ff0fed5 100644
--- a/chrome/browser/notifications/balloon_collection.cc
+++ b/chrome/browser/notifications/balloon_collection.cc
@@ -159,6 +159,23 @@ void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
}
}
+gfx::Rect BalloonCollectionImpl::GetBalloonsBoundingBox() const {
+ // Start from the layout origin.
+ gfx::Rect bounds = gfx::Rect(layout_.GetLayoutOrigin(), gfx::Size(0, 0));
+
+ // For each balloon, extend the rectangle. This approach is indifferent to
+ // the orientation of the balloons.
+ const Balloons& balloons = base_.balloons();
+ Balloons::const_iterator iter;
+ for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
+ gfx::Rect balloon_box = gfx::Rect((*iter)->GetPosition(),
+ (*iter)->GetViewSize());
+ bounds = bounds.Union(balloon_box);
+ }
+
+ return bounds;
+}
+
#if USE_OFFSETS
void BalloonCollectionImpl::AddMessageLoopObserver() {
if (!added_as_message_loop_observer_) {
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index d123717..1c87037 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -142,6 +142,9 @@ class BalloonCollectionImpl : public BalloonCollection
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
+ // Gets a bounding box for all the current balloons in screen coordinates.
+ gfx::Rect GetBalloonsBoundingBox() const;
+
private:
// Adjusts the positions of the balloons (e.g., when one is closed).
// Implemented by each platform for specific UI requirements.
diff --git a/chrome/browser/notifications/balloon_collection_linux.cc b/chrome/browser/notifications/balloon_collection_linux.cc
index 099193c..094c2b0 100644
--- a/chrome/browser/notifications/balloon_collection_linux.cc
+++ b/chrome/browser/notifications/balloon_collection_linux.cc
@@ -46,25 +46,13 @@ void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
- return false;
-
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
- gfx::Point lower_right = layout_.GetLayoutOrigin();
-
- gfx::Rect bounds = gfx::Rect(upper_left.x(),
- upper_left.y(),
- lower_right.x() - upper_left.x(),
- lower_right.y() - upper_left.y());
-
GdkScreen* screen = gdk_screen_get_default();
GdkDisplay* display = gdk_screen_get_display(screen);
gint x, y;
gdk_display_get_pointer(display, NULL, &x, &y, NULL);
gfx::Point cursor(x, y);
- return bounds.Contains(cursor);
+ return GetBalloonsBoundingBox().Contains(cursor);
}
void BalloonCollectionImpl::SetPositionPreference(
diff --git a/chrome/browser/notifications/balloon_collection_win.cc b/chrome/browser/notifications/balloon_collection_win.cc
index 742872b..7a979d9 100644
--- a/chrome/browser/notifications/balloon_collection_win.cc
+++ b/chrome/browser/notifications/balloon_collection_win.cc
@@ -44,22 +44,9 @@ void BalloonCollectionImpl::DidProcessMessage(const MSG& msg) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
- return false;
-
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
- gfx::Point lower_right = layout_.GetLayoutOrigin();
-
- gfx::Rect bounds = gfx::Rect(upper_left.x(),
- upper_left.y(),
- lower_right.x() - upper_left.x(),
- lower_right.y() - upper_left.y());
-
DWORD pos = GetMessagePos();
gfx::Point cursor(pos);
-
- return bounds.Contains(cursor);
+ return GetBalloonsBoundingBox().Contains(cursor);
}
void BalloonCollectionImpl::SetPositionPreference(
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 762990f..a0193f9 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -324,6 +324,39 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) {
EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e"));
}
+TEST_F(DesktopNotificationsTest, TestBoundingBox) {
+ // Create some notifications.
+ ViewHostMsg_ShowNotification_Params params = StandardTestNotification();
+ for (int id = 0; id <= 3; ++id) {
+ params.notification_id = id;
+ EXPECT_TRUE(service_->ShowDesktopNotification(
+ params, 0, 0, DesktopNotificationService::PageNotification));
+ }
+
+ gfx::Rect box = balloon_collection_->GetBalloonsBoundingBox();
+
+ // Try this for all positions.
+ BalloonCollection::PositionPreference pref;
+ for (pref = BalloonCollection::UPPER_RIGHT;
+ pref <= BalloonCollection::LOWER_LEFT;
+ pref = static_cast<BalloonCollection::PositionPreference>(pref + 1)) {
+ // Make sure each balloon's 4 corners are inside the box.
+ std::deque<Balloon*>& balloons = balloon_collection_->balloons();
+ std::deque<Balloon*>::iterator iter;
+ for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
+ int min_x = (*iter)->GetPosition().x();
+ int max_x = min_x + (*iter)->GetViewSize().width() - 1;
+ int min_y = (*iter)->GetPosition().y();
+ int max_y = min_y + (*iter)->GetViewSize().height() - 1;
+
+ EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y)));
+ EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y)));
+ }
+ }
+}
+
TEST_F(DesktopNotificationsTest, TestPositionPreference) {
// Set position preference to lower right.
profile_->GetPrefs()->SetInteger(prefs::kDesktopNotificationPosition,
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h
index 9f556e4..cbd3e4a 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/notifications/desktop_notifications_unittest.h
@@ -59,6 +59,11 @@ class MockBalloonCollection : public BalloonCollectionImpl {
int MinHeight() { return Layout::min_balloon_height(); }
int MaxHeight() { return Layout::max_balloon_height(); }
+ // Returns the bounding box.
+ gfx::Rect GetBalloonsBoundingBox() {
+ return BalloonCollectionImpl::GetBalloonsBoundingBox();
+ }
+
private:
std::deque<Balloon*> balloons_;
};