| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| 11 #include "chrome/browser/window_sizer.h" | 11 #include "chrome/browser/window_sizer.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Portion of the screen allotted for notifications. When notification balloons | 15 // Portion of the screen allotted for notifications. When notification balloons |
| 16 // extend over this, no new notifications are shown until some are closed. | 16 // extend over this, no new notifications are shown until some are closed. |
| 17 const double kPercentBalloonFillFactor = 0.7; | 17 const double kPercentBalloonFillFactor = 0.7; |
| 18 | 18 |
| 19 // Allow at least this number of balloons on the screen. | 19 // Allow at least this number of balloons on the screen. |
| 20 const int kMinAllowedBalloonCount = 2; | 20 const int kMinAllowedBalloonCount = 2; |
| 21 | 21 |
| 22 // Margin from the edge of the work area | |
| 23 const int kVerticalEdgeMargin = 5; | |
| 24 const int kHorizontalEdgeMargin = 5; | |
| 25 | |
| 26 // Space between balloons. | |
| 27 const int kInterBalloonMargin = 5; | |
| 28 | |
| 29 } // namespace | 22 } // namespace |
| 30 | 23 |
| 31 // static | 24 // static |
| 32 #if defined(OS_MACOSX) | 25 // Note that on MacOS, since the coordinate system is inverted vertically from |
| 33 BalloonCollectionImpl::Layout::Placement | 26 // the others, this actually produces notifications coming from the TOP right, |
| 34 BalloonCollectionImpl::Layout::placement_ = | 27 // which is what is desired. |
| 35 Layout::VERTICALLY_FROM_TOP_RIGHT; | |
| 36 #else | |
| 37 BalloonCollectionImpl::Layout::Placement | 28 BalloonCollectionImpl::Layout::Placement |
| 38 BalloonCollectionImpl::Layout::placement_ = | 29 BalloonCollectionImpl::Layout::placement_ = |
| 39 Layout::VERTICALLY_FROM_BOTTOM_RIGHT; | 30 Layout::VERTICALLY_FROM_BOTTOM_RIGHT; |
| 40 #endif | |
| 41 | 31 |
| 42 BalloonCollectionImpl::BalloonCollectionImpl() | 32 BalloonCollectionImpl::BalloonCollectionImpl() |
| 43 : space_change_listener_(NULL) { | 33 : space_change_listener_(NULL) { |
| 44 } | 34 } |
| 45 | 35 |
| 46 BalloonCollectionImpl::~BalloonCollectionImpl() { | 36 BalloonCollectionImpl::~BalloonCollectionImpl() { |
| 47 STLDeleteElements(&balloons_); | 37 STLDeleteElements(&balloons_); |
| 48 } | 38 } |
| 49 | 39 |
| 50 void BalloonCollectionImpl::Add(const Notification& notification, | 40 void BalloonCollectionImpl::Add(const Notification& notification, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 NOTREACHED(); | 136 NOTREACHED(); |
| 147 break; | 137 break; |
| 148 } | 138 } |
| 149 } | 139 } |
| 150 | 140 |
| 151 gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const { | 141 gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const { |
| 152 int x = 0; | 142 int x = 0; |
| 153 int y = 0; | 143 int y = 0; |
| 154 switch (placement_) { | 144 switch (placement_) { |
| 155 case HORIZONTALLY_FROM_BOTTOM_LEFT: | 145 case HORIZONTALLY_FROM_BOTTOM_LEFT: |
| 156 x = work_area_.x() + kHorizontalEdgeMargin; | 146 x = work_area_.x() + HorizontalEdgeMargin(); |
| 157 y = work_area_.bottom() - kVerticalEdgeMargin; | 147 y = work_area_.bottom() - VerticalEdgeMargin(); |
| 158 break; | 148 break; |
| 159 case HORIZONTALLY_FROM_BOTTOM_RIGHT: | 149 case HORIZONTALLY_FROM_BOTTOM_RIGHT: |
| 160 x = work_area_.right() - kHorizontalEdgeMargin; | 150 x = work_area_.right() - HorizontalEdgeMargin(); |
| 161 y = work_area_.bottom() - kVerticalEdgeMargin; | 151 y = work_area_.bottom() - VerticalEdgeMargin(); |
| 162 break; | 152 break; |
| 163 case VERTICALLY_FROM_TOP_RIGHT: | 153 case VERTICALLY_FROM_TOP_RIGHT: |
| 164 x = work_area_.right() - kHorizontalEdgeMargin; | 154 x = work_area_.right() - HorizontalEdgeMargin(); |
| 165 y = work_area_.y() + kVerticalEdgeMargin; | 155 y = work_area_.y() + VerticalEdgeMargin(); |
| 166 break; | 156 break; |
| 167 case VERTICALLY_FROM_BOTTOM_RIGHT: | 157 case VERTICALLY_FROM_BOTTOM_RIGHT: |
| 168 x = work_area_.right() - kHorizontalEdgeMargin; | 158 x = work_area_.right() - HorizontalEdgeMargin(); |
| 169 y = work_area_.bottom() - kVerticalEdgeMargin; | 159 y = work_area_.bottom() - VerticalEdgeMargin(); |
| 170 break; | 160 break; |
| 171 default: | 161 default: |
| 172 NOTREACHED(); | 162 NOTREACHED(); |
| 173 break; | 163 break; |
| 174 } | 164 } |
| 175 return gfx::Point(x, y); | 165 return gfx::Point(x, y); |
| 176 } | 166 } |
| 177 | 167 |
| 178 gfx::Point BalloonCollectionImpl::Layout::NextPosition( | 168 gfx::Point BalloonCollectionImpl::Layout::NextPosition( |
| 179 const gfx::Size& balloon_size, | 169 const gfx::Size& balloon_size, |
| 180 gfx::Point* position_iterator) const { | 170 gfx::Point* position_iterator) const { |
| 181 DCHECK(position_iterator); | 171 DCHECK(position_iterator); |
| 182 | 172 |
| 183 int x = 0; | 173 int x = 0; |
| 184 int y = 0; | 174 int y = 0; |
| 185 switch (placement_) { | 175 switch (placement_) { |
| 186 case HORIZONTALLY_FROM_BOTTOM_LEFT: | 176 case HORIZONTALLY_FROM_BOTTOM_LEFT: |
| 187 x = position_iterator->x(); | 177 x = position_iterator->x(); |
| 188 y = position_iterator->y() - balloon_size.height(); | 178 y = position_iterator->y() - balloon_size.height(); |
| 189 position_iterator->set_x(position_iterator->x() + balloon_size.width() + | 179 position_iterator->set_x(position_iterator->x() + balloon_size.width() + |
| 190 kInterBalloonMargin); | 180 InterBalloonMargin()); |
| 191 break; | 181 break; |
| 192 case HORIZONTALLY_FROM_BOTTOM_RIGHT: | 182 case HORIZONTALLY_FROM_BOTTOM_RIGHT: |
| 193 position_iterator->set_x(position_iterator->x() - balloon_size.width() - | 183 position_iterator->set_x(position_iterator->x() - balloon_size.width() - |
| 194 kInterBalloonMargin); | 184 InterBalloonMargin()); |
| 195 x = position_iterator->x(); | 185 x = position_iterator->x(); |
| 196 y = position_iterator->y() - balloon_size.height(); | 186 y = position_iterator->y() - balloon_size.height(); |
| 197 break; | 187 break; |
| 198 case VERTICALLY_FROM_TOP_RIGHT: | 188 case VERTICALLY_FROM_TOP_RIGHT: |
| 199 x = position_iterator->x() - balloon_size.width(); | 189 x = position_iterator->x() - balloon_size.width(); |
| 200 y = position_iterator->y(); | 190 y = position_iterator->y(); |
| 201 position_iterator->set_y(position_iterator->y() + balloon_size.height() + | 191 position_iterator->set_y(position_iterator->y() + balloon_size.height() + |
| 202 kInterBalloonMargin); | 192 InterBalloonMargin()); |
| 203 break; | 193 break; |
| 204 case VERTICALLY_FROM_BOTTOM_RIGHT: | 194 case VERTICALLY_FROM_BOTTOM_RIGHT: |
| 205 position_iterator->set_y(position_iterator->y() - balloon_size.height() - | 195 position_iterator->set_y(position_iterator->y() - balloon_size.height() - |
| 206 kInterBalloonMargin); | 196 InterBalloonMargin()); |
| 207 x = position_iterator->x() - balloon_size.width(); | 197 x = position_iterator->x() - balloon_size.width(); |
| 208 y = position_iterator->y(); | 198 y = position_iterator->y(); |
| 209 break; | 199 break; |
| 210 default: | 200 default: |
| 211 NOTREACHED(); | 201 NOTREACHED(); |
| 212 break; | 202 break; |
| 213 } | 203 } |
| 214 return gfx::Point(x, y); | 204 return gfx::Point(x, y); |
| 215 } | 205 } |
| 216 | 206 |
| 217 bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() { | 207 bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() { |
| 218 bool changed = false; | 208 bool changed = false; |
| 219 | 209 |
| 220 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( | 210 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( |
| 221 WindowSizer::CreateDefaultMonitorInfoProvider()); | 211 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 222 | 212 |
| 223 gfx::Rect new_work_area = info_provider->GetPrimaryMonitorWorkArea(); | 213 gfx::Rect new_work_area = info_provider->GetPrimaryMonitorWorkArea(); |
| 224 if (!work_area_.Equals(new_work_area)) { | 214 if (!work_area_.Equals(new_work_area)) { |
| 225 work_area_.SetRect(new_work_area.x(), new_work_area.y(), | 215 work_area_.SetRect(new_work_area.x(), new_work_area.y(), |
| 226 new_work_area.width(), new_work_area.height()); | 216 new_work_area.width(), new_work_area.height()); |
| 227 changed = true; | 217 changed = true; |
| 228 } | 218 } |
| 229 | 219 |
| 230 return changed; | 220 return changed; |
| 231 } | 221 } |
| OLD | NEW |