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.
5 #include "chrome/browser/ui/cocoa/notifications/balloon_view.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/basictypes.h"
10 #import "chrome/browser/ui/cocoa/notifications/balloon_controller.h"
11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
15 const int kRoundedCornerSize = 6;
19 @implementation BalloonWindow
20 - (id)initWithContentRect:(NSRect)contentRect
21 styleMask:(NSUInteger)aStyle
22 backing:(NSBackingStoreType)bufferingType
24 self = [super initWithContentRect:contentRect
25 styleMask:NSBorderlessWindowMask
26 backing:NSBackingStoreBuffered
28 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25)
29 // ensures notification balloons on top of regular windows, but below
30 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight
31 // drop-out, which is at NSStatusWindowLevel-2 (23) for OSX 10.6/7.
32 // See http://crbug.com/59878.
34 [self setLevel:NSModalPanelWindowLevel];
36 [self setBackgroundColor:[NSColor clearColor]];
41 - (BOOL)canBecomeMainWindow {
46 @implementation BalloonShelfViewCocoa
47 - (void)drawRect:(NSRect)rect {
49 [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
50 topLeftCornerRadius:kRoundedCornerSize
51 topRightCornerRadius:kRoundedCornerSize
52 bottomLeftCornerRadius:0.0
53 bottomRightCornerRadius:0.0];
55 [[NSColor colorWithCalibratedWhite:0.957 alpha:1.0] set];
58 [[NSColor colorWithCalibratedWhite:0.8 alpha:1.0] set];
59 NSPoint origin = [self bounds].origin;
60 [NSBezierPath strokeLineFromPoint:origin
61 toPoint:NSMakePoint(origin.x + NSWidth([self bounds]), origin.y)];
65 @implementation BalloonContentViewCocoa
66 - (void)drawRect:(NSRect)rect {
67 rect = NSInsetRect([self bounds], 0.5, 0.5);
69 [NSBezierPath gtm_bezierPathWithRoundRect:rect
70 topLeftCornerRadius:0.0
71 topRightCornerRadius:0.0
72 bottomLeftCornerRadius:kRoundedCornerSize
73 bottomRightCornerRadius:kRoundedCornerSize];
74 [[NSColor whiteColor] set];
75 [path setLineWidth:3];
80 @implementation BalloonOverlayViewCocoa
82 // We do not want to bring chrome window to foreground when we click on any
83 // part of the notification balloon. To do this, we first postpone the window
84 // reorder here (shouldDelayWindowOrderingForEvent is called during mouseDown)
85 // and then complete canceling the reorder by [NSApp preventWindowOrdering] in
86 // mouseDown handler of this view.
87 - (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)theEvent {
91 - (void)mouseDown:(NSEvent*)event {
92 [NSApp preventWindowOrdering];
93 // Continue bubbling the event up the chain of responders.
94 [super mouseDown:event];
97 - (BOOL)acceptsFirstMouse:(NSEvent*)event {