Home | History | Annotate | Download | only in notifications
      1 // Copyright (c) 2011 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/ui/cocoa/notifications/balloon_view.h"
      6 
      7 #import <Cocoa/Cocoa.h>
      8 
      9 #include "base/basictypes.h"
     10 #include "base/memory/scoped_nsobject.h"
     11 #import "chrome/browser/ui/cocoa/notifications/balloon_controller.h"
     12 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
     13 
     14 namespace {
     15 
     16 const int kRoundedCornerSize = 6;
     17 
     18 }  // namespace
     19 
     20 @implementation BalloonWindow
     21 - (id)initWithContentRect:(NSRect)contentRect
     22                 styleMask:(unsigned int)aStyle
     23                   backing:(NSBackingStoreType)bufferingType
     24                     defer:(BOOL)flag {
     25   self = [super initWithContentRect:contentRect
     26                           styleMask:NSBorderlessWindowMask
     27                             backing:NSBackingStoreBuffered
     28                               defer:NO];
     29   if (self) {
     30     [self setLevel:NSStatusWindowLevel];
     31     [self setOpaque:NO];
     32     [self setBackgroundColor:[NSColor clearColor]];
     33   }
     34   return self;
     35 }
     36 
     37 - (BOOL)canBecomeMainWindow {
     38   return NO;
     39 }
     40 @end
     41 
     42 @implementation BalloonShelfViewCocoa
     43 - (void)drawRect:(NSRect)rect {
     44   NSBezierPath* path =
     45       [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
     46                             topLeftCornerRadius:kRoundedCornerSize
     47                            topRightCornerRadius:kRoundedCornerSize
     48                          bottomLeftCornerRadius:0.0
     49                         bottomRightCornerRadius:0.0];
     50 
     51   [[NSColor colorWithCalibratedWhite:0.957 alpha:1.0] set];
     52   [path fill];
     53 
     54   [[NSColor colorWithCalibratedWhite:0.8 alpha:1.0] set];
     55   NSPoint origin = [self bounds].origin;
     56   [NSBezierPath strokeLineFromPoint:origin
     57       toPoint:NSMakePoint(origin.x + NSWidth([self bounds]), origin.y)];
     58 }
     59 @end
     60 
     61 @implementation BalloonContentViewCocoa
     62 - (void)drawRect:(NSRect)rect {
     63   rect = NSInsetRect([self bounds], 0.5, 0.5);
     64   NSBezierPath* path =
     65       [NSBezierPath gtm_bezierPathWithRoundRect:rect
     66                             topLeftCornerRadius:0.0
     67                            topRightCornerRadius:0.0
     68                          bottomLeftCornerRadius:kRoundedCornerSize
     69                         bottomRightCornerRadius:kRoundedCornerSize];
     70   [[NSColor whiteColor] set];
     71   [path setLineWidth:3];
     72   [path stroke];
     73 }
     74 @end
     75 
     76 @implementation BalloonOverlayViewCocoa
     77 
     78 // We do not want to bring chrome window to foreground when we click on any
     79 // part of the notification balloon. To do this, we first postpone the window
     80 // reorder here (shouldDelayWindowOrderingForEvent is called during mouseDown)
     81 // and then complete canceling the reorder by [NSApp preventWindowOrdering] in
     82 // mouseDown handler of this view.
     83 - (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)theEvent {
     84   return YES;
     85 }
     86 
     87 - (void)mouseDown:(NSEvent*)event {
     88   [NSApp preventWindowOrdering];
     89   // Continue bubbling the event up the chain of responders.
     90   [super mouseDown:event];
     91 }
     92 @end
     93