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/gtk/notifications/balloon_view_gtk.h"
9 #include "ui/gfx/size.h"
11 Balloon
* BalloonCollectionImpl::MakeBalloon(const Notification
& notification
,
13 Balloon
* balloon
= new Balloon(notification
, profile
, this);
15 balloon
->set_view(new BalloonViewImpl(this));
16 gfx::Size
size(layout_
.min_balloon_width(), layout_
.min_balloon_height());
17 balloon
->set_content_size(size
);
21 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
25 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
29 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
33 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
34 return placement_
== VERTICALLY_FROM_BOTTOM_LEFT
;
37 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
38 return placement_
== VERTICALLY_FROM_BOTTOM_RIGHT
;
41 void BalloonCollectionImpl::PositionBalloons(bool reposition
) {
42 PositionBalloonsInternal(reposition
);
45 void BalloonCollectionImpl::WillProcessEvent(GdkEvent
* event
) {
48 void BalloonCollectionImpl::DidProcessEvent(GdkEvent
* event
) {
49 switch (event
->type
) {
50 case GDK_MOTION_NOTIFY
:
51 case GDK_LEAVE_NOTIFY
:
52 HandleMouseMoveEvent();
59 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
60 GdkScreen
* screen
= gdk_screen_get_default();
61 GdkDisplay
* display
= gdk_screen_get_display(screen
);
63 gdk_display_get_pointer(display
, NULL
, &x
, &y
, NULL
);
65 return GetBalloonsBoundingBox().Contains(gfx::Point(x
, y
));
68 void BalloonCollectionImpl::SetPositionPreference(
69 PositionPreference position
) {
70 if (position
== DEFAULT_POSITION
)
71 position
= LOWER_RIGHT
;
73 // All positioning schemes are vertical, and linux
74 // uses the normal screen orientation.
75 if (position
== UPPER_RIGHT
)
76 layout_
.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT
);
77 else if (position
== UPPER_LEFT
)
78 layout_
.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT
);
79 else if (position
== LOWER_LEFT
)
80 layout_
.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT
);
81 else if (position
== LOWER_RIGHT
)
82 layout_
.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT
);
86 layout_
.ComputeOffsetToMoveAbovePanels();
87 PositionBalloons(true);
91 BalloonCollection
* BalloonCollection::Create() {
92 return new BalloonCollectionImpl();