OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
6 | 6 |
7 #import "base/memory/scoped_nsobject.h" | 7 #import "base/memory/scoped_nsobject.h" |
8 #import "chrome/browser/ui/chrome_style.h" | 8 #import "chrome/browser/ui/chrome_style.h" |
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| 11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
11 | 12 |
12 @implementation ConstrainedWindowCustomWindow | 13 @implementation ConstrainedWindowCustomWindow |
13 | 14 |
14 - (id)initWithContentRect:(NSRect)contentRect { | 15 - (id)initWithContentRect:(NSRect)contentRect { |
15 if ((self = [self initWithContentRect:contentRect | 16 if ((self = [self initWithContentRect:contentRect |
16 styleMask:NSBorderlessWindowMask | 17 styleMask:NSBorderlessWindowMask |
17 backing:NSBackingStoreBuffered | 18 backing:NSBackingStoreBuffered |
18 defer:NO])) { | 19 defer:NO])) { |
19 scoped_nsobject<NSView> contentView( | 20 scoped_nsobject<NSView> contentView( |
20 [[ConstrainedWindowCustomWindowContentView alloc] | 21 [[ConstrainedWindowCustomWindowContentView alloc] |
21 initWithFrame:NSZeroRect]); | 22 initWithFrame:NSZeroRect]); |
22 [self setContentView:contentView]; | 23 [self setContentView:contentView]; |
23 } | 24 } |
24 return self; | 25 return self; |
25 } | 26 } |
26 | 27 |
27 - (id)initWithContentRect:(NSRect)contentRect | 28 - (id)initWithContentRect:(NSRect)contentRect |
28 styleMask:(NSUInteger)windowStyle | 29 styleMask:(NSUInteger)windowStyle |
29 backing:(NSBackingStoreType)bufferingType | 30 backing:(NSBackingStoreType)bufferingType |
30 defer:(BOOL)deferCreation { | 31 defer:(BOOL)deferCreation { |
31 if ((self = [super initWithContentRect:contentRect | 32 if ((self = [super initWithContentRect:contentRect |
32 styleMask:NSBorderlessWindowMask | 33 styleMask:NSBorderlessWindowMask |
33 backing:bufferingType | 34 backing:bufferingType |
34 defer:NO])) { | 35 defer:NO])) { |
35 [self setHasShadow:YES]; | 36 [self setHasShadow:YES]; |
36 [self setBackgroundColor:[NSColor clearColor]]; | 37 [self setBackgroundColor:gfx::SkColorToCalibratedNSColor( |
| 38 chrome_style::GetBackgroundColor())]; |
37 [self setOpaque:NO]; | 39 [self setOpaque:NO]; |
38 [self setReleasedWhenClosed:NO]; | 40 [self setReleasedWhenClosed:NO]; |
39 } | 41 } |
40 return self; | 42 return self; |
41 } | 43 } |
42 | 44 |
43 - (BOOL)canBecomeKeyWindow { | 45 - (BOOL)canBecomeKeyWindow { |
44 return YES; | 46 return YES; |
45 } | 47 } |
46 | 48 |
(...skipping 12 matching lines...) Expand all Loading... |
59 withWindowSize:windowContent.size]; | 61 withWindowSize:windowContent.size]; |
60 frame.size = windowContent.size; | 62 frame.size = windowContent.size; |
61 return frame; | 63 return frame; |
62 } | 64 } |
63 | 65 |
64 @end | 66 @end |
65 | 67 |
66 @implementation ConstrainedWindowCustomWindowContentView | 68 @implementation ConstrainedWindowCustomWindowContentView |
67 | 69 |
68 - (void)drawRect:(NSRect)rect { | 70 - (void)drawRect:(NSRect)rect { |
69 NSBezierPath* path = [NSBezierPath | 71 gfx::ScopedNSGraphicsContextSaveGState state; |
| 72 |
| 73 // Draw symmetric difference between rect path and oval path as "clear". |
| 74 NSBezierPath* ovalPath = [NSBezierPath |
70 bezierPathWithRoundedRect:[self bounds] | 75 bezierPathWithRoundedRect:[self bounds] |
71 xRadius:chrome_style::kBorderRadius | 76 xRadius:chrome_style::kBorderRadius |
72 yRadius:chrome_style::kBorderRadius]; | 77 yRadius:chrome_style::kBorderRadius]; |
73 [gfx::SkColorToCalibratedNSColor( | 78 NSBezierPath* path = [NSBezierPath bezierPathWithRect:[self bounds]]; |
74 chrome_style::GetBackgroundColor()) set]; | 79 [path appendBezierPath:ovalPath]; |
| 80 [path setWindingRule:NSEvenOddWindingRule]; |
| 81 [[NSGraphicsContext currentContext] setCompositingOperation: |
| 82 NSCompositeCopy]; |
| 83 [[NSColor clearColor] set]; |
75 [path fill]; | 84 [path fill]; |
76 | 85 |
77 [[self window] invalidateShadow]; | 86 [[self window] invalidateShadow]; |
78 } | 87 } |
79 | 88 |
80 @end | 89 @end |
OLD | NEW |