OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "chrome/browser/notifications/balloon_collection_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/notifications/balloon.h" | 10 #include "chrome/browser/notifications/balloon.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 (*iter)->GetViewSize()); | 228 (*iter)->GetViewSize()); |
229 bounds.Union(balloon_box); | 229 bounds.Union(balloon_box); |
230 } | 230 } |
231 | 231 |
232 return bounds; | 232 return bounds; |
233 } | 233 } |
234 | 234 |
235 #if USE_OFFSETS | 235 #if USE_OFFSETS |
236 void BalloonCollectionImpl::AddMessageLoopObserver() { | 236 void BalloonCollectionImpl::AddMessageLoopObserver() { |
237 if (!added_as_message_loop_observer_) { | 237 if (!added_as_message_loop_observer_) { |
238 MessageLoopForUI::current()->AddObserver(this); | 238 base::MessageLoopForUI::current()->AddObserver(this); |
239 added_as_message_loop_observer_ = true; | 239 added_as_message_loop_observer_ = true; |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 void BalloonCollectionImpl::RemoveMessageLoopObserver() { | 243 void BalloonCollectionImpl::RemoveMessageLoopObserver() { |
244 if (added_as_message_loop_observer_) { | 244 if (added_as_message_loop_observer_) { |
245 MessageLoopForUI::current()->RemoveObserver(this); | 245 base::MessageLoopForUI::current()->RemoveObserver(this); |
246 added_as_message_loop_observer_ = false; | 246 added_as_message_loop_observer_ = false; |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 void BalloonCollectionImpl::CancelOffsets() { | 250 void BalloonCollectionImpl::CancelOffsets() { |
251 reposition_factory_.InvalidateWeakPtrs(); | 251 reposition_factory_.InvalidateWeakPtrs(); |
252 | 252 |
253 // Unhook from listening to all UI events. | 253 // Unhook from listening to all UI events. |
254 RemoveMessageLoopObserver(); | 254 RemoveMessageLoopObserver(); |
255 | 255 |
256 const Balloons& balloons = base_.balloons(); | 256 const Balloons& balloons = base_.balloons(); |
257 for (Balloons::const_iterator it = balloons.begin(); | 257 for (Balloons::const_iterator it = balloons.begin(); |
258 it != balloons.end(); | 258 it != balloons.end(); |
259 ++it) | 259 ++it) |
260 (*it)->set_offset(gfx::Vector2d()); | 260 (*it)->set_offset(gfx::Vector2d()); |
261 | 261 |
262 PositionBalloons(true); | 262 PositionBalloons(true); |
263 } | 263 } |
264 | 264 |
265 void BalloonCollectionImpl::HandleMouseMoveEvent() { | 265 void BalloonCollectionImpl::HandleMouseMoveEvent() { |
266 if (!IsCursorInBalloonCollection()) { | 266 if (!IsCursorInBalloonCollection()) { |
267 // Mouse has left the region. Schedule a reposition after | 267 // Mouse has left the region. Schedule a reposition after |
268 // a short delay. | 268 // a short delay. |
269 if (!reposition_factory_.HasWeakPtrs()) { | 269 if (!reposition_factory_.HasWeakPtrs()) { |
270 MessageLoop::current()->PostDelayedTask( | 270 base::MessageLoop::current()->PostDelayedTask( |
271 FROM_HERE, | 271 FROM_HERE, |
272 base::Bind(&BalloonCollectionImpl::CancelOffsets, | 272 base::Bind(&BalloonCollectionImpl::CancelOffsets, |
273 reposition_factory_.GetWeakPtr()), | 273 reposition_factory_.GetWeakPtr()), |
274 base::TimeDelta::FromMilliseconds(kRepositionDelayMs)); | 274 base::TimeDelta::FromMilliseconds(kRepositionDelayMs)); |
275 } | 275 } |
276 } else { | 276 } else { |
277 // Mouse moved back into the region. Cancel the reposition. | 277 // Mouse moved back into the region. Cancel the reposition. |
278 reposition_factory_.InvalidateWeakPtrs(); | 278 reposition_factory_.InvalidateWeakPtrs(); |
279 } | 279 } |
280 } | 280 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 478 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
479 #endif | 479 #endif |
480 if (work_area_ != new_work_area) { | 480 if (work_area_ != new_work_area) { |
481 work_area_.SetRect(new_work_area.x(), new_work_area.y(), | 481 work_area_.SetRect(new_work_area.x(), new_work_area.y(), |
482 new_work_area.width(), new_work_area.height()); | 482 new_work_area.width(), new_work_area.height()); |
483 changed = true; | 483 changed = true; |
484 } | 484 } |
485 | 485 |
486 return changed; | 486 return changed; |
487 } | 487 } |
OLD | NEW |