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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/balloon_collection_impl.h"
7 #include "chrome/browser/notifications/balloon.h"
8 #include "chrome/browser/ui/views/notifications/balloon_view_views.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/event_utils.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/screen.h"
14 Balloon
* BalloonCollectionImpl::MakeBalloon(const Notification
& notification
,
16 Balloon
* balloon
= new Balloon(notification
, profile
, this);
17 balloon
->set_view(new BalloonViewImpl(this));
18 gfx::Size
size(layout_
.min_balloon_width(), layout_
.min_balloon_height());
19 balloon
->set_content_size(size
);
23 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
27 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
31 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
35 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
36 return placement_
== VERTICALLY_FROM_BOTTOM_LEFT
;
39 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
40 return placement_
== VERTICALLY_FROM_BOTTOM_RIGHT
;
43 void BalloonCollectionImpl::PositionBalloons(bool reposition
) {
44 PositionBalloonsInternal(reposition
);
47 base::EventStatus
BalloonCollectionImpl::WillProcessEvent(
48 const base::NativeEvent
& event
) {
49 return base::EVENT_CONTINUE
;
52 void BalloonCollectionImpl::DidProcessEvent(const base::NativeEvent
& event
) {
54 switch (event
.message
) {
58 HandleMouseMoveEvent();
61 #elif defined(USE_AURA)
62 // This is deliberately used only in linux. For an aura build on windows, the
63 // above block of code is fine.
64 switch (ui::EventTypeFromNative(event
)) {
65 case ui::ET_MOUSE_MOVED
:
66 case ui::ET_MOUSE_DRAGGED
:
67 case ui::ET_MOUSE_EXITED
:
68 HandleMouseMoveEvent();
78 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
80 gfx::Point
cursor(GetMessagePos());
82 // TODO(saintlou): Not sure if this is correct because on Windows at least
83 // the following call is GetCursorPos() not GetMessagePos().
84 // TODO(scottmg): NativeScreen might be wrong. http://crbug.com/133312
85 gfx::Point
cursor(gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
87 return GetBalloonsBoundingBox().Contains(cursor
);
90 void BalloonCollectionImpl::SetPositionPreference(
91 PositionPreference position
) {
92 if (position
== DEFAULT_POSITION
)
93 position
= LOWER_RIGHT
;
95 // All positioning schemes are vertical, and windows
96 // uses the normal screen orientation.
97 if (position
== UPPER_RIGHT
)
98 layout_
.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT
);
99 else if (position
== UPPER_LEFT
)
100 layout_
.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT
);
101 else if (position
== LOWER_LEFT
)
102 layout_
.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT
);
103 else if (position
== LOWER_RIGHT
)
104 layout_
.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT
);
108 layout_
.ComputeOffsetToMoveAbovePanels();
109 PositionBalloons(true);
113 BalloonCollection
* BalloonCollection::Create() {
114 return new BalloonCollectionImpl();