Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / notifications / balloon_collection_views.cc
blob8da6940b277f105270ee98ca18579e610ab1654f
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.
5 #include "chrome/browser/notifications/balloon_collection_impl.h"
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"
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;
23 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
24 return 3;
27 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
28 return 2;
31 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
32 return 0;
35 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
36 return placement_ == VERTICALLY_FROM_BOTTOM_LEFT;
39 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
40 return placement_ == VERTICALLY_FROM_BOTTOM_RIGHT;
43 void BalloonCollectionImpl::PositionBalloons(bool reposition) {
44 PositionBalloonsInternal(reposition);
47 base::EventStatus BalloonCollectionImpl::WillProcessEvent(
48 const base::NativeEvent& event) {
49 return base::EVENT_CONTINUE;
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;
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;
73 #else
74 NOTIMPLEMENTED();
75 #endif
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);
90 void BalloonCollectionImpl::SetPositionPreference(
91 PositionPreference position) {
92 if (position == DEFAULT_POSITION)
93 position = LOWER_RIGHT;
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();
108 layout_.ComputeOffsetToMoveAbovePanels();
109 PositionBalloons(true);
112 // static
113 BalloonCollection* BalloonCollection::Create() {
114 return new BalloonCollectionImpl();