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 #include "base/command_line.h" | |
6 #include "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
7 #include "base/mac/sdk_forward_declarations.h" | 6 #include "base/mac/sdk_forward_declarations.h" |
8 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 7 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
9 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
10 #include "ui/base/ui_base_switches.h" | |
11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 9 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
12 | 10 |
13 #include "base/logging.h" | 11 #include "base/logging.h" |
14 | 12 |
15 @implementation NSView (ChromeAdditions) | 13 @implementation NSView (ChromeAdditions) |
16 | 14 |
17 - (CGFloat)cr_lineWidth { | 15 - (CGFloat)cr_lineWidth { |
18 // All shipping retina macs run at least 10.7. | 16 // All shipping retina macs run at least 10.7. |
19 if (![self respondsToSelector:@selector(convertSizeFromBacking:)]) | 17 if (![self respondsToSelector:@selector(convertSizeFromBacking:)]) |
20 return 1; | 18 return 1; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return [[NSColor keyboardFocusIndicatorColor] | 61 return [[NSColor keyboardFocusIndicatorColor] |
64 colorWithAlphaComponent:0.5 / [self cr_lineWidth]]; | 62 colorWithAlphaComponent:0.5 / [self cr_lineWidth]]; |
65 } | 63 } |
66 | 64 |
67 - (void)cr_recursivelySetNeedsDisplay:(BOOL)flag { | 65 - (void)cr_recursivelySetNeedsDisplay:(BOOL)flag { |
68 [self setNeedsDisplay:YES]; | 66 [self setNeedsDisplay:YES]; |
69 for (NSView* child in [self subviews]) | 67 for (NSView* child in [self subviews]) |
70 [child cr_recursivelySetNeedsDisplay:flag]; | 68 [child cr_recursivelySetNeedsDisplay:flag]; |
71 } | 69 } |
72 | 70 |
73 - (void)cr_setWantsLayer:(BOOL)wantsLayer { | |
74 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
75 switches::kDisableCoreAnimation)) | |
76 return; | |
77 | |
78 // Dynamically removing layers on SnowLeopard will sometimes result in | |
79 // crashes. Once a view has a layer on SnowLeopard, it is stuck with it. | |
80 // http://crbug.com/348328 | |
81 if (!wantsLayer && base::mac::IsOSSnowLeopard()) | |
82 return; | |
83 | |
84 [self setWantsLayer:wantsLayer]; | |
85 } | |
86 | |
87 static NSView* g_ancestorBeingDrawnFrom = nil; | 71 static NSView* g_ancestorBeingDrawnFrom = nil; |
88 static NSView* g_childBeingDrawnTo = nil; | 72 static NSView* g_childBeingDrawnTo = nil; |
89 | 73 |
90 - (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)rect { | 74 - (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)rect { |
91 gfx::ScopedNSGraphicsContextSaveGState scopedGSState; | 75 gfx::ScopedNSGraphicsContextSaveGState scopedGSState; |
92 NSRect frame = [self convertRect:[self bounds] toView:ancestorView]; | 76 NSRect frame = [self convertRect:[self bounds] toView:ancestorView]; |
93 NSAffineTransform* transform = [NSAffineTransform transform]; | 77 NSAffineTransform* transform = [NSAffineTransform transform]; |
94 if ([self isFlipped] == [ancestorView isFlipped]) { | 78 if ([self isFlipped] == [ancestorView isFlipped]) { |
95 [transform translateXBy:-NSMinX(frame) yBy:-NSMinY(frame)]; | 79 [transform translateXBy:-NSMinX(frame) yBy:-NSMinY(frame)]; |
96 } else { | 80 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
109 } | 93 } |
110 | 94 |
111 - (NSView*)cr_viewBeingDrawnTo { | 95 - (NSView*)cr_viewBeingDrawnTo { |
112 if (!g_ancestorBeingDrawnFrom) | 96 if (!g_ancestorBeingDrawnFrom) |
113 return self; | 97 return self; |
114 DCHECK(g_ancestorBeingDrawnFrom == self); | 98 DCHECK(g_ancestorBeingDrawnFrom == self); |
115 return g_childBeingDrawnTo; | 99 return g_childBeingDrawnTo; |
116 } | 100 } |
117 | 101 |
118 @end | 102 @end |
OLD | NEW |