| Index: chrome/browser/ui/cocoa/nsview_additions.mm
|
| diff --git a/chrome/browser/ui/cocoa/nsview_additions.mm b/chrome/browser/ui/cocoa/nsview_additions.mm
|
| index 92103309e7ba0c412e23e77cc2828638fcdbc3cf..8256239cddefd8f1336eb180ea469980e4411735 100644
|
| --- a/chrome/browser/ui/cocoa/nsview_additions.mm
|
| +++ b/chrome/browser/ui/cocoa/nsview_additions.mm
|
| @@ -4,6 +4,8 @@
|
|
|
| #import "chrome/browser/ui/cocoa/nsview_additions.h"
|
|
|
| +#include "base/logging.h"
|
| +
|
| #if !defined(MAC_OS_X_VERSION_10_7) || \
|
| MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
|
|
|
| @@ -13,6 +15,23 @@
|
|
|
| #endif // 10.7
|
|
|
| +namespace {
|
| +
|
| +// Returns YES if |firstView| is above |secondView|.
|
| +BOOL IsViewAboveView(NSView* firstView, NSView* secondView) {
|
| + NSArray* subviews = [[firstView superview] subviews];
|
| +
|
| + NSUInteger firstIndex = [subviews indexOfObject:firstView];
|
| + DCHECK_NE(NSNotFound, firstIndex);
|
| +
|
| + NSUInteger secondIndex = [subviews indexOfObject:secondView];
|
| + DCHECK_NE(NSNotFound, secondIndex);
|
| +
|
| + return firstIndex > secondIndex;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| @implementation NSView (ChromeAdditions)
|
|
|
| - (CGFloat)cr_lineWidth {
|
| @@ -28,4 +47,20 @@
|
| return [self hitTest:mouseLoc] == self;
|
| }
|
|
|
| +- (void)cr_ensureSubview:(NSView*)subview
|
| + isPositioned:(NSWindowOrderingMode)place
|
| + relativeTo:(NSView *)otherView {
|
| + DCHECK(place == NSWindowAbove || place == NSWindowBelow);
|
| + BOOL isAbove = place == NSWindowAbove;
|
| + if ([[subview superview] isEqual:self] &&
|
| + IsViewAboveView(subview, otherView) == isAbove) {
|
| + return;
|
| + }
|
| +
|
| + [subview removeFromSuperview];
|
| + [self addSubview:subview
|
| + positioned:place
|
| + relativeTo:otherView];
|
| +}
|
| +
|
| @end
|
|
|