OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/balloon_collection.h" | 5 #include "chrome/browser/notifications/balloon_collection.h" |
6 | 6 |
7 #include "base/gfx/rect.h" | 7 #include "base/gfx/rect.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "chrome/browser/notifications/balloon.h" | 10 #include "chrome/browser/notifications/balloon.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 Balloon* new_balloon = MakeBalloon(notification, profile); | 38 Balloon* new_balloon = MakeBalloon(notification, profile); |
39 balloons_.push_back(new_balloon); | 39 balloons_.push_back(new_balloon); |
40 PositionBalloons(false); | 40 PositionBalloons(false); |
41 new_balloon->Show(); | 41 new_balloon->Show(); |
42 | 42 |
43 // There may be no listener in a unit test. | 43 // There may be no listener in a unit test. |
44 if (space_change_listener_) | 44 if (space_change_listener_) |
45 space_change_listener_->OnBalloonSpaceChanged(); | 45 space_change_listener_->OnBalloonSpaceChanged(); |
46 } | 46 } |
47 | 47 |
| 48 bool BalloonCollectionImpl::Remove(const Notification& notification) { |
| 49 Balloons::iterator iter; |
| 50 for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { |
| 51 if (notification.IsSame((*iter)->notification())) { |
| 52 // Balloon.CloseByScript() will cause OnBalloonClosed() to be called on |
| 53 // this object, which will remove it from the collection and free it. |
| 54 (*iter)->CloseByScript(); |
| 55 return true; |
| 56 } |
| 57 } |
| 58 return false; |
| 59 } |
| 60 |
48 bool BalloonCollectionImpl::HasSpace() const { | 61 bool BalloonCollectionImpl::HasSpace() const { |
49 if (count() < kMinAllowedBalloonCount) | 62 if (count() < kMinAllowedBalloonCount) |
50 return true; | 63 return true; |
51 | 64 |
52 int max_balloon_size = 0; | 65 int max_balloon_size = 0; |
53 int total_size = 0; | 66 int total_size = 0; |
54 layout_.GetMaxLinearSize(&max_balloon_size, &total_size); | 67 layout_.GetMaxLinearSize(&max_balloon_size, &total_size); |
55 | 68 |
56 int current_max_size = max_balloon_size * count(); | 69 int current_max_size = max_balloon_size * count(); |
57 int max_allowed_size = static_cast<int>(total_size * | 70 int max_allowed_size = static_cast<int>(total_size * |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 position_iterator->set_y(position_iterator->y() - balloon_size.height()); | 176 position_iterator->set_y(position_iterator->y() - balloon_size.height()); |
164 x = position_iterator->x() - balloon_size.width(); | 177 x = position_iterator->x() - balloon_size.width(); |
165 y = position_iterator->y(); | 178 y = position_iterator->y(); |
166 break; | 179 break; |
167 default: | 180 default: |
168 NOTREACHED(); | 181 NOTREACHED(); |
169 break; | 182 break; |
170 } | 183 } |
171 return gfx::Point(x, y); | 184 return gfx::Point(x, y); |
172 } | 185 } |
OLD | NEW |