Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / notifications / balloon_collection_views.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/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"
13
14 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
15                                             Profile* profile) {
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);
20   return balloon;
21 }
22
23 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
24   return 3;
25 }
26
27 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
28   return 2;
29 }
30
31 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
32   return 0;
33 }
34
35 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
36   return placement_ == VERTICALLY_FROM_BOTTOM_LEFT;
37 }
38
39 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
40   return placement_ == VERTICALLY_FROM_BOTTOM_RIGHT;
41 }
42
43 void BalloonCollectionImpl::PositionBalloons(bool reposition) {
44   PositionBalloonsInternal(reposition);
45 }
46
47 base::EventStatus BalloonCollectionImpl::WillProcessEvent(
48     const base::NativeEvent& event) {
49   return base::EVENT_CONTINUE;
50 }
51
52 void BalloonCollectionImpl::DidProcessEvent(const base::NativeEvent& event) {
53 #if defined(OS_WIN)
54   switch (event.message) {
55     case WM_MOUSEMOVE:
56     case WM_MOUSELEAVE:
57     case WM_NCMOUSELEAVE:
58       HandleMouseMoveEvent();
59       break;
60   }
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();
69       break;
70     default:
71       break;
72   }
73 #else
74   NOTIMPLEMENTED();
75 #endif
76 }
77
78 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
79 #if defined(OS_WIN)
80   gfx::Point cursor(GetMessagePos());
81 #else
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());
86 #endif
87   return GetBalloonsBoundingBox().Contains(cursor);
88 }
89
90 void BalloonCollectionImpl::SetPositionPreference(
91     PositionPreference position) {
92   if (position == DEFAULT_POSITION)
93     position = LOWER_RIGHT;
94
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);
105   else
106     NOTREACHED();
107
108   layout_.ComputeOffsetToMoveAbovePanels();
109   PositionBalloons(true);
110 }
111
112 // static
113 BalloonCollection* BalloonCollection::Create() {
114   return new BalloonCollectionImpl();
115 }