balloon_collection_win.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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
11Balloon* 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
20int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
21  return 3;
22}
23
24int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
25  return 2;
26}
27
28int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
29  return 0;
30}
31
32void BalloonCollectionImpl::PositionBalloons(bool reposition) {
33  PositionBalloonsInternal(reposition);
34}
35
36void 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
46bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
47  DWORD pos = GetMessagePos();
48  gfx::Point cursor(pos);
49  return GetBalloonsBoundingBox().Contains(cursor);
50}
51
52void 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
74BalloonCollection* BalloonCollection::Create() {
75  return new BalloonCollectionImpl();
76}
77