Home | History | Annotate | Download | only in notifications
      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/ui/cocoa/notifications/balloon_view_bridge.h"
     10 
     11 Balloon* 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
     21 gfx::Rect BalloonCollectionImpl::GetMacWorkArea() {
     22   NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
     23   return gfx::Rect(NSRectToCGRect([primary visibleFrame]));
     24 }
     25 
     26 int BalloonCollectionImpl::Layout::InterBalloonMargin() const {
     27   return 5;
     28 }
     29 
     30 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const {
     31   return 5;
     32 }
     33 
     34 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const {
     35   return 0;
     36 }
     37 
     38 void 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 void BalloonCollectionImpl::SetPositionPreference(
     47     PositionPreference position) {
     48   if (position == DEFAULT_POSITION)
     49     position = UPPER_RIGHT;
     50 
     51   // All positioning schemes are vertical, but mac
     52   // uses a vertically reversed screen orientation.
     53   if (position == UPPER_RIGHT)
     54     layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT);
     55   else if (position == UPPER_LEFT)
     56     layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT);
     57   else if (position == LOWER_LEFT)
     58     layout_.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT);
     59   else if (position == LOWER_RIGHT)
     60     layout_.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT);
     61   else
     62     NOTREACHED();
     63 
     64   PositionBalloons(true);
     65 }
     66 
     67 // static
     68 BalloonCollection* BalloonCollection::Create() {
     69   return new BalloonCollectionImpl();
     70 }
     71