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..6352f08f955e10a995b5e1c92ff7d09808a69ba1 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 |
@@ -28,4 +30,36 @@ |
return [self hitTest:mouseLoc] == self; |
} |
+- (BOOL)cr_isBelowView:(NSView*)otherView { |
+ NSArray* subviews = [[self superview] subviews]; |
+ |
+ NSUInteger selfIndex = [subviews indexOfObject:self]; |
+ DCHECK_NE(NSNotFound, selfIndex); |
+ |
+ NSUInteger otherIndex = [subviews indexOfObject:otherView]; |
+ DCHECK_NE(NSNotFound, otherIndex); |
+ |
+ return selfIndex < otherIndex; |
+} |
+ |
+- (BOOL)cr_isAboveView:(NSView*)otherView { |
+ return ![self cr_isBelowView:otherView]; |
+} |
+ |
+- (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] && |
+ [subview cr_isAboveView:otherView] == isAbove) { |
+ return; |
+ } |
+ |
+ [subview removeFromSuperview]; |
+ [self addSubview:subview |
+ positioned:place |
+ relativeTo:otherView]; |
+} |
+ |
@end |