balloon_collection_linux.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2009 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/views/notifications/balloon_view.h"
9#include "gfx/size.h"
10
11Balloon* 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
21int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
22  return 5;
23}
24
25int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
26  return 5;
27}
28
29int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
30  return 5;
31}
32
33void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) {
34  switch (event->type) {
35    case GDK_MOTION_NOTIFY:
36    case GDK_LEAVE_NOTIFY:
37      HandleMouseMoveEvent();
38      break;
39    default:
40      break;
41  }
42}
43
44bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
45  if (balloons_.empty())
46    return false;
47
48  gfx::Point upper_left = balloons_[balloons_.size() - 1]->GetPosition();
49  gfx::Point lower_right = layout_.GetLayoutOrigin();
50
51  gfx::Rect bounds = gfx::Rect(upper_left.x(),
52                               upper_left.y(),
53                               lower_right.x() - upper_left.x(),
54                               lower_right.y() - upper_left.y());
55
56  GdkScreen* screen = gdk_screen_get_default();
57  GdkDisplay* display = gdk_screen_get_display(screen);
58  gint x, y;
59  gdk_display_get_pointer(display, NULL, &x, &y, NULL);
60  gfx::Point cursor(x, y);
61
62  return bounds.Contains(cursor);
63}
64
65// static
66BalloonCollection* BalloonCollection::Create() {
67  return new BalloonCollectionImpl();
68}
69