- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / notifications / balloon_collection_gtk.cc
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.
4
5 #include "chrome/browser/notifications/balloon_collection_impl.h"
6
7 #include "chrome/browser/notifications/balloon.h"
8 #include "chrome/browser/ui/gtk/notifications/balloon_view_gtk.h"
9 #include "ui/gfx/size.h"
10
11 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
12                                             Profile* profile) {
13   Balloon* balloon = new Balloon(notification, profile, this);
14
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);
18   return balloon;
19 }
20
21 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
22   return 5;
23 }
24
25 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
26   return 5;
27 }
28
29 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
30   return 5;
31 }
32
33 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
34   return placement_ == VERTICALLY_FROM_BOTTOM_LEFT;
35 }
36
37 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
38   return placement_ == VERTICALLY_FROM_BOTTOM_RIGHT;
39 }
40
41 void BalloonCollectionImpl::PositionBalloons(bool reposition) {
42   PositionBalloonsInternal(reposition);
43 }
44
45 void BalloonCollectionImpl::WillProcessEvent(GdkEvent* event) {
46 }
47
48 void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) {
49   switch (event->type) {
50     case GDK_MOTION_NOTIFY:
51     case GDK_LEAVE_NOTIFY:
52       HandleMouseMoveEvent();
53       break;
54     default:
55       break;
56   }
57 }
58
59 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
60   GdkScreen* screen = gdk_screen_get_default();
61   GdkDisplay* display = gdk_screen_get_display(screen);
62   gint x, y;
63   gdk_display_get_pointer(display, NULL, &x, &y, NULL);
64
65   return GetBalloonsBoundingBox().Contains(gfx::Point(x, y));
66 }
67
68 void BalloonCollectionImpl::SetPositionPreference(
69     PositionPreference position) {
70   if (position == DEFAULT_POSITION)
71     position = LOWER_RIGHT;
72
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);
83   else
84     NOTREACHED();
85
86   layout_.ComputeOffsetToMoveAbovePanels();
87   PositionBalloons(true);
88 }
89
90 // static
91 BalloonCollection* BalloonCollection::Create() {
92   return new BalloonCollectionImpl();
93 }