| 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 "ui/base/cocoa/underlay_opengl_hosting_window.h" | 5 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/mac/scoped_nsautorelease_pool.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
| 12 #include "base/memory/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 | 13 |
| 14 @interface NSWindow (UndocumentedAPI) | 14 @interface NSWindow (UndocumentedAPI) |
| 15 // Normally, punching a hole in a window by painting a subview with a | 15 // Normally, punching a hole in a window by painting a subview with a |
| 16 // transparent color causes the shadow for that area to also not be present. | 16 // transparent color causes the shadow for that area to also not be present. |
| 17 // That feature is "content has shadow", which means that shadows are effective | 17 // That feature is "content has shadow", which means that shadows are effective |
| 18 // even in the content area of the window. If, however, "content has shadow" is | 18 // even in the content area of the window. If, however, "content has shadow" is |
| 19 // turned off, then the transparent area of the content casts a shadow. The one | 19 // turned off, then the transparent area of the content casts a shadow. The one |
| 20 // tricky part is that even if "content has shadow" is turned off, "the content" | 20 // tricky part is that even if "content has shadow" is turned off, "the content" |
| 21 // is defined as being the scanline from the leftmost opaque part to the | 21 // is defined as being the scanline from the leftmost opaque part to the |
| 22 // rightmost opaque part. Therefore, to force the entire window to have a | 22 // rightmost opaque part. Therefore, to force the entire window to have a |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 NSView* rootView = [[self contentView] superview]; | 115 NSView* rootView = [[self contentView] superview]; |
| 116 const NSRect rootBounds = [rootView bounds]; | 116 const NSRect rootBounds = [rootView bounds]; |
| 117 | 117 |
| 118 // On 10.7/8, the bottom corners of the window are rounded by magic at a | 118 // On 10.7/8, the bottom corners of the window are rounded by magic at a |
| 119 // deeper level than the NSThemeFrame, so it is OK to have the opaques | 119 // deeper level than the NSThemeFrame, so it is OK to have the opaques |
| 120 // go all the way to the bottom. | 120 // go all the way to the bottom. |
| 121 const CGFloat kTopEdgeInset = 16; | 121 const CGFloat kTopEdgeInset = 16; |
| 122 const CGFloat kAlphaValueJustOpaqueEnough = 0.005; | 122 const CGFloat kAlphaValueJustOpaqueEnough = 0.005; |
| 123 | 123 |
| 124 scoped_nsobject<NSView> leftOpaque([[OpaqueView alloc] initWithFrame: | 124 base::scoped_nsobject<NSView> leftOpaque([[OpaqueView alloc] |
| 125 NSMakeRect(NSMinX(rootBounds), NSMinY(rootBounds), | 125 initWithFrame:NSMakeRect(NSMinX(rootBounds), |
| 126 1, NSHeight(rootBounds) - kTopEdgeInset)]); | 126 NSMinY(rootBounds), |
| 127 1, |
| 128 NSHeight(rootBounds) - kTopEdgeInset)]); |
| 127 [leftOpaque setAutoresizingMask:NSViewMaxXMargin | | 129 [leftOpaque setAutoresizingMask:NSViewMaxXMargin | |
| 128 NSViewHeightSizable]; | 130 NSViewHeightSizable]; |
| 129 [leftOpaque setAlphaValue:kAlphaValueJustOpaqueEnough]; | 131 [leftOpaque setAlphaValue:kAlphaValueJustOpaqueEnough]; |
| 130 [rootView addSubview:leftOpaque]; | 132 [rootView addSubview:leftOpaque]; |
| 131 | 133 |
| 132 scoped_nsobject<NSView> rightOpaque([[OpaqueView alloc] initWithFrame: | 134 base::scoped_nsobject<NSView> rightOpaque([[OpaqueView alloc] |
| 133 NSMakeRect(NSMaxX(rootBounds) - 1, NSMinY(rootBounds), | 135 initWithFrame:NSMakeRect(NSMaxX(rootBounds) - 1, |
| 134 1, NSHeight(rootBounds) - kTopEdgeInset)]); | 136 NSMinY(rootBounds), |
| 137 1, |
| 138 NSHeight(rootBounds) - kTopEdgeInset)]); |
| 135 [rightOpaque setAutoresizingMask:NSViewMinXMargin | | 139 [rightOpaque setAutoresizingMask:NSViewMinXMargin | |
| 136 NSViewHeightSizable]; | 140 NSViewHeightSizable]; |
| 137 [rightOpaque setAlphaValue:kAlphaValueJustOpaqueEnough]; | 141 [rightOpaque setAlphaValue:kAlphaValueJustOpaqueEnough]; |
| 138 [rootView addSubview:rightOpaque]; | 142 [rootView addSubview:rightOpaque]; |
| 139 } | 143 } |
| 140 } | 144 } |
| 141 | 145 |
| 142 return self; | 146 return self; |
| 143 } | 147 } |
| 144 | 148 |
| 145 @end | 149 @end |
| OLD | NEW |