OLD | NEW |
| (Empty) |
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.h" | |
9 #include "ui/base/events.h" | |
10 #include "ui/gfx/rect.h" | |
11 #include "ui/gfx/screen.h" | |
12 | |
13 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification, | |
14 Profile* profile) { | |
15 Balloon* balloon = new Balloon(notification, profile, this); | |
16 balloon->set_view(new BalloonViewImpl(this)); | |
17 gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height()); | |
18 balloon->set_content_size(size); | |
19 return balloon; | |
20 } | |
21 | |
22 int BalloonCollectionImpl::Layout::InterBalloonMargin() const { | |
23 return 3; | |
24 } | |
25 | |
26 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const { | |
27 return 2; | |
28 } | |
29 | |
30 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const { | |
31 return 0; | |
32 } | |
33 | |
34 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const { | |
35 return placement_ == VERTICALLY_FROM_BOTTOM_LEFT; | |
36 } | |
37 | |
38 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const { | |
39 return placement_ == VERTICALLY_FROM_BOTTOM_RIGHT; | |
40 } | |
41 | |
42 void BalloonCollectionImpl::PositionBalloons(bool reposition) { | |
43 PositionBalloonsInternal(reposition); | |
44 } | |
45 | |
46 base::EventStatus BalloonCollectionImpl::WillProcessEvent( | |
47 const base::NativeEvent& event) { | |
48 return base::EVENT_CONTINUE; | |
49 } | |
50 | |
51 void BalloonCollectionImpl::DidProcessEvent(const base::NativeEvent& event) { | |
52 #if defined(OS_WIN) | |
53 switch (event.message) { | |
54 case WM_MOUSEMOVE: | |
55 case WM_MOUSELEAVE: | |
56 case WM_NCMOUSELEAVE: | |
57 HandleMouseMoveEvent(); | |
58 break; | |
59 } | |
60 #elif defined(USE_AURA) | |
61 // This is deliberately used only in linux. For an aura build on windows, the | |
62 // above block of code is fine. | |
63 switch (ui::EventTypeFromNative(event)) { | |
64 case ui::ET_MOUSE_MOVED: | |
65 case ui::ET_MOUSE_DRAGGED: | |
66 case ui::ET_MOUSE_EXITED: | |
67 HandleMouseMoveEvent(); | |
68 break; | |
69 default: | |
70 break; | |
71 } | |
72 #else | |
73 NOTIMPLEMENTED(); | |
74 #endif | |
75 } | |
76 | |
77 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const { | |
78 #if defined(OS_WIN) | |
79 gfx::Point cursor(GetMessagePos()); | |
80 #else | |
81 // TODO(saintlou): Not sure if this is correct because on Windows at least | |
82 // the following call is GetCursorPos() not GetMessagePos(). | |
83 gfx::Point cursor(gfx::Screen::GetCursorScreenPoint()); | |
84 #endif | |
85 return GetBalloonsBoundingBox().Contains(cursor); | |
86 } | |
87 | |
88 void BalloonCollectionImpl::SetPositionPreference( | |
89 PositionPreference position) { | |
90 if (position == DEFAULT_POSITION) | |
91 position = LOWER_RIGHT; | |
92 | |
93 // All positioning schemes are vertical, and windows | |
94 // uses the normal screen orientation. | |
95 if (position == UPPER_RIGHT) | |
96 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT); | |
97 else if (position == UPPER_LEFT) | |
98 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT); | |
99 else if (position == LOWER_LEFT) | |
100 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT); | |
101 else if (position == LOWER_RIGHT) | |
102 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT); | |
103 else | |
104 NOTREACHED(); | |
105 | |
106 layout_.ComputeOffsetToMoveAbovePanels(gfx::Rect()); | |
107 PositionBalloons(true); | |
108 } | |
109 | |
110 #if !(defined(USE_AURA) && defined(OS_CHROMEOS)) | |
111 // static | |
112 BalloonCollection* BalloonCollection::Create() { | |
113 return new BalloonCollectionImpl(); | |
114 } | |
115 #endif | |
OLD | NEW |