Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / notifications / balloon_view.mm
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 #import "chrome/browser/ui/cocoa/notifications/balloon_controller.h"
11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
12
13 namespace {
14
15 const int kRoundedCornerSize = 6;
16
17 }  // namespace
18
19 @implementation BalloonWindow
20 - (id)initWithContentRect:(NSRect)contentRect
21                 styleMask:(NSUInteger)aStyle
22                   backing:(NSBackingStoreType)bufferingType
23                     defer:(BOOL)flag {
24   self = [super initWithContentRect:contentRect
25                           styleMask:NSBorderlessWindowMask
26                             backing:NSBackingStoreBuffered
27                               defer:NO];
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.
33   if (self) {
34     [self setLevel:NSModalPanelWindowLevel];
35     [self setOpaque:NO];
36     [self setBackgroundColor:[NSColor clearColor]];
37   }
38   return self;
39 }
40
41 - (BOOL)canBecomeMainWindow {
42   return NO;
43 }
44 @end
45
46 @implementation BalloonShelfViewCocoa
47 - (void)drawRect:(NSRect)rect {
48   NSBezierPath* path =
49       [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
50                             topLeftCornerRadius:kRoundedCornerSize
51                            topRightCornerRadius:kRoundedCornerSize
52                          bottomLeftCornerRadius:0.0
53                         bottomRightCornerRadius:0.0];
54
55   [[NSColor colorWithCalibratedWhite:0.957 alpha:1.0] set];
56   [path fill];
57
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)];
62 }
63 @end
64
65 @implementation BalloonContentViewCocoa
66 - (void)drawRect:(NSRect)rect {
67   rect = NSInsetRect([self bounds], 0.5, 0.5);
68   NSBezierPath* path =
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];
76   [path stroke];
77 }
78 @end
79
80 @implementation BalloonOverlayViewCocoa
81
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 {
88   return YES;
89 }
90
91 - (void)mouseDown:(NSEvent*)event {
92   [NSApp preventWindowOrdering];
93   // Continue bubbling the event up the chain of responders.
94   [super mouseDown:event];
95 }
96
97 - (BOOL)acceptsFirstMouse:(NSEvent*)event {
98   return YES;
99 }
100 @end