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 #import <Cocoa/Cocoa.h>
9 #include "chrome/browser/ui/cocoa/notifications/balloon_view_bridge.h"
11 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
13 Balloon* balloon = new Balloon(notification, profile, this);
14 balloon->set_view(new BalloonViewBridge());
15 gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height());
16 balloon->set_content_size(size);
21 gfx::Rect BalloonCollectionImpl::GetMacWorkArea() {
22 NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
23 return gfx::Rect(NSRectToCGRect([primary visibleFrame]));
26 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
30 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
34 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
38 bool BalloonCollectionImpl::Layout::NeedToMoveAboveLeftSidePanels() const {
39 return placement_ == VERTICALLY_FROM_TOP_LEFT;
42 bool BalloonCollectionImpl::Layout::NeedToMoveAboveRightSidePanels() const {
43 return placement_ == VERTICALLY_FROM_TOP_RIGHT;
46 void BalloonCollectionImpl::PositionBalloons(bool reposition) {
47 // Use an animation context so that all the balloons animate together.
48 [NSAnimationContext beginGrouping];
49 [[NSAnimationContext currentContext] setDuration:0.1f];
50 PositionBalloonsInternal(reposition);
51 [NSAnimationContext endGrouping];
54 void BalloonCollectionImpl::SetPositionPreference(
55 PositionPreference position) {
56 if (position == DEFAULT_POSITION)
57 position = UPPER_RIGHT;
59 // All positioning schemes are vertical, but mac
60 // uses a vertically reversed screen orientation.
61 if (position == UPPER_RIGHT)
62 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT);
63 else if (position == UPPER_LEFT)
64 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT);
65 else if (position == LOWER_LEFT)
66 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT);
67 else if (position == LOWER_RIGHT)
68 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT);
72 layout_.ComputeOffsetToMoveAbovePanels();
73 PositionBalloons(true);
77 BalloonCollection* BalloonCollection::Create() {
78 return new BalloonCollectionImpl();