• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/notifications/balloon_collection_impl.h"
6 
7 #include "chrome/browser/notifications/balloon.h"
8 #include "chrome/browser/ui/views/notifications/balloon_view.h"
9 #include "ui/gfx/rect.h"
10 
MakeBalloon(const Notification & notification,Profile * profile)11 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
12                                             Profile* profile) {
13   Balloon* balloon = new Balloon(notification, profile, this);
14   balloon->set_view(new BalloonViewImpl(this));
15   gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height());
16   balloon->set_content_size(size);
17   return balloon;
18 }
19 
InterBalloonMargin() const20 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
21   return 3;
22 }
23 
HorizontalEdgeMargin() const24 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
25   return 2;
26 }
27 
VerticalEdgeMargin() const28 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
29   return 0;
30 }
31 
PositionBalloons(bool reposition)32 void BalloonCollectionImpl::PositionBalloons(bool reposition) {
33   PositionBalloonsInternal(reposition);
34 }
35 
DidProcessMessage(const MSG & msg)36 void BalloonCollectionImpl::DidProcessMessage(const MSG& msg) {
37   switch (msg.message) {
38     case WM_MOUSEMOVE:
39     case WM_MOUSELEAVE:
40     case WM_NCMOUSELEAVE:
41       HandleMouseMoveEvent();
42       break;
43   }
44 }
45 
IsCursorInBalloonCollection() const46 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
47   DWORD pos = GetMessagePos();
48   gfx::Point cursor(pos);
49   return GetBalloonsBoundingBox().Contains(cursor);
50 }
51 
SetPositionPreference(PositionPreference position)52 void BalloonCollectionImpl::SetPositionPreference(
53     PositionPreference position) {
54   if (position == DEFAULT_POSITION)
55     position = LOWER_RIGHT;
56 
57   // All positioning schemes are vertical, and windows
58   // uses the normal screen orientation.
59   if (position == UPPER_RIGHT)
60     layout_.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT);
61   else if (position == UPPER_LEFT)
62     layout_.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT);
63   else if (position == LOWER_LEFT)
64     layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT);
65   else if (position == LOWER_RIGHT)
66     layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT);
67   else
68     NOTREACHED();
69 
70   PositionBalloons(true);
71 }
72 
73 // static
Create()74 BalloonCollection* BalloonCollection::Create() {
75   return new BalloonCollectionImpl();
76 }
77