Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / nsview_additions.mm
blob00f36aba1e0deb8a3d5a97c82dad71979ce91f41
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/nsview_additions.h"
7 #include "base/logging.h"
9 #if !defined(MAC_OS_X_VERSION_10_7) || \
10     MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
12 @interface NSView (LionAPI)
13 - (NSSize)convertSizeFromBacking:(NSSize)size;
14 @end
16 #endif  // 10.7
18 @implementation NSView (ChromeAdditions)
20 - (CGFloat)cr_lineWidth {
21   // All shipping retina macs run at least 10.7.
22   if (![self respondsToSelector:@selector(convertSizeFromBacking:)])
23     return 1;
24   return [self convertSizeFromBacking:NSMakeSize(1, 1)].width;
27 - (BOOL)cr_isMouseInView {
28   NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream];
29   mouseLoc = [[self superview] convertPoint:mouseLoc fromView:nil];
30   return [self hitTest:mouseLoc] == self;
33 - (BOOL)cr_isBelowView:(NSView*)otherView {
34   NSArray* subviews = [[self superview] subviews];
36   NSUInteger selfIndex = [subviews indexOfObject:self];
37   DCHECK_NE(NSNotFound, selfIndex);
39   NSUInteger otherIndex = [subviews indexOfObject:otherView];
40   DCHECK_NE(NSNotFound, otherIndex);
42   return selfIndex < otherIndex;
45 - (BOOL)cr_isAboveView:(NSView*)otherView {
46   return ![self cr_isBelowView:otherView];
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   }
59   [subview removeFromSuperview];
60   [self addSubview:subview
61         positioned:place
62         relativeTo:otherView];
65 - (NSColor*)cr_keyboardFocusIndicatorColor {
66   return [[NSColor keyboardFocusIndicatorColor]
67       colorWithAlphaComponent:0.5 / [self cr_lineWidth]];
70 - (void)cr_recursivelySetNeedsDisplay:(BOOL)flag {
71   [self setNeedsDisplay:YES];
72   for (NSView* child in [self subviews])
73     [child cr_recursivelySetNeedsDisplay:flag];
76 @end