balloon_collection_mac.mm revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2009 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#import <Cocoa/Cocoa.h>
8
9#include "chrome/browser/cocoa/notifications/balloon_view_bridge.h"
10
11Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
12                                            Profile* profile) {
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);
17  return balloon;
18}
19
20// static
21gfx::Rect BalloonCollectionImpl::GetMacWorkArea() {
22  NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
23  return gfx::Rect(NSRectToCGRect([primary visibleFrame]));
24}
25
26int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
27  return 5;
28}
29
30int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
31  return 5;
32}
33
34int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
35  return 0;
36}
37
38void BalloonCollectionImpl::PositionBalloons(bool reposition) {
39  // Use an animation context so that all the balloons animate together.
40  [NSAnimationContext beginGrouping];
41  [[NSAnimationContext currentContext] setDuration:0.1f];
42  PositionBalloonsInternal(reposition);
43  [NSAnimationContext endGrouping];
44}
45
46// static
47BalloonCollection* BalloonCollection::Create() {
48  return new BalloonCollectionImpl();
49}
50