Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/ui/cocoa/nsview_additions.mm

Issue 11876036: Alternate NTP: Don't hide bookmark bar on instant (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
18 namespace {
19
20 // Returns YES if |firstView| is above |secondView|.
21 BOOL IsViewAboveView(NSView* firstView, NSView* secondView) {
22 NSArray* subviews = [[firstView superview] subviews];
23
24 NSUInteger firstIndex = [subviews indexOfObject:firstView];
25 DCHECK_NE(NSNotFound, firstIndex);
26
27 NSUInteger secondIndex = [subviews indexOfObject:secondView];
28 DCHECK_NE(NSNotFound, secondIndex);
29
30 return firstIndex > secondIndex;
31 }
32
33 } // namespace
34
16 @implementation NSView (ChromeAdditions) 35 @implementation NSView (ChromeAdditions)
17 36
18 - (CGFloat)cr_lineWidth { 37 - (CGFloat)cr_lineWidth {
19 // All shipping retina macs run at least 10.7. 38 // All shipping retina macs run at least 10.7.
20 if (![self respondsToSelector:@selector(convertSizeFromBacking:)]) 39 if (![self respondsToSelector:@selector(convertSizeFromBacking:)])
21 return 1; 40 return 1;
22 return [self convertSizeFromBacking:NSMakeSize(1, 1)].width; 41 return [self convertSizeFromBacking:NSMakeSize(1, 1)].width;
23 } 42 }
24 43
25 - (BOOL)cr_isMouseInView { 44 - (BOOL)cr_isMouseInView {
26 NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; 45 NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
27 mouseLoc = [[self superview] convertPoint:mouseLoc fromView:nil]; 46 mouseLoc = [[self superview] convertPoint:mouseLoc fromView:nil];
28 return [self hitTest:mouseLoc] == self; 47 return [self hitTest:mouseLoc] == self;
29 } 48 }
30 49
50 - (void)cr_ensureSubview:(NSView*)subview
51 isPositioned:(NSWindowOrderingMode)place
52 relativeTo:(NSView *)otherView {
53 DCHECK(place == NSWindowAbove || place == NSWindowBelow);
54 BOOL isAbove = place == NSWindowAbove;
55 if ([[subview superview] isEqual:self] &&
56 IsViewAboveView(subview, otherView) == isAbove) {
57 return;
58 }
59
60 [subview removeFromSuperview];
61 [self addSubview:subview
62 positioned:place
63 relativeTo:otherView];
64 }
65
31 @end 66 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698