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/nsview_additions.h" | 5 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
6 | 6 |
| 7 #include "base/logging.h" |
| 8 |
7 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 9 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
8 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 10 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
9 | 11 |
10 @interface NSView (LionAPI) | 12 @interface NSView (LionAPI) |
11 - (NSSize)convertSizeFromBacking:(NSSize)size; | 13 - (NSSize)convertSizeFromBacking:(NSSize)size; |
12 @end | 14 @end |
13 | 15 |
14 #endif // 10.7 | 16 #endif // 10.7 |
15 | 17 |
16 @implementation NSView (ChromeAdditions) | 18 @implementation NSView (ChromeAdditions) |
17 | 19 |
18 - (CGFloat)cr_lineWidth { | 20 - (CGFloat)cr_lineWidth { |
19 // All shipping retina macs run at least 10.7. | 21 // All shipping retina macs run at least 10.7. |
20 if (![self respondsToSelector:@selector(convertSizeFromBacking:)]) | 22 if (![self respondsToSelector:@selector(convertSizeFromBacking:)]) |
21 return 1; | 23 return 1; |
22 return [self convertSizeFromBacking:NSMakeSize(1, 1)].width; | 24 return [self convertSizeFromBacking:NSMakeSize(1, 1)].width; |
23 } | 25 } |
24 | 26 |
25 - (BOOL)cr_isMouseInView { | 27 - (BOOL)cr_isMouseInView { |
26 NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; | 28 NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; |
27 mouseLoc = [[self superview] convertPoint:mouseLoc fromView:nil]; | 29 mouseLoc = [[self superview] convertPoint:mouseLoc fromView:nil]; |
28 return [self hitTest:mouseLoc] == self; | 30 return [self hitTest:mouseLoc] == self; |
29 } | 31 } |
30 | 32 |
| 33 - (BOOL)cr_isBelowView:(NSView*)otherView { |
| 34 NSArray* subviews = [[self superview] subviews]; |
| 35 |
| 36 NSUInteger selfIndex = [subviews indexOfObject:self]; |
| 37 DCHECK_NE(NSNotFound, selfIndex); |
| 38 |
| 39 NSUInteger otherIndex = [subviews indexOfObject:otherView]; |
| 40 DCHECK_NE(NSNotFound, otherIndex); |
| 41 |
| 42 return selfIndex < otherIndex; |
| 43 } |
| 44 |
| 45 - (BOOL)cr_isAboveView:(NSView*)otherView { |
| 46 return ![self cr_isBelowView:otherView]; |
| 47 } |
| 48 |
| 49 - (void)cr_ensureSubview:(NSView*)subview |
| 50 isPositioned:(NSWindowOrderingMode)place |
| 51 relativeTo:(NSView *)otherView { |
| 52 DCHECK(place == NSWindowAbove || place == NSWindowBelow); |
| 53 BOOL isAbove = place == NSWindowAbove; |
| 54 if ([[subview superview] isEqual:self] && |
| 55 [subview cr_isAboveView:otherView] == isAbove) { |
| 56 return; |
| 57 } |
| 58 |
| 59 [subview removeFromSuperview]; |
| 60 [self addSubview:subview |
| 61 positioned:place |
| 62 relativeTo:otherView]; |
| 63 } |
| 64 |
31 @end | 65 @end |
OLD | NEW |