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 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 - (NSColor*)computeBackgroundColor; | 81 - (NSColor*)computeBackgroundColor; |
82 @end | 82 @end |
83 | 83 |
84 @implementation TabContentsContainerView | 84 @implementation TabContentsContainerView |
85 | 85 |
86 - (id)initWithDelegate:(TabContentsController*)delegate { | 86 - (id)initWithDelegate:(TabContentsController*)delegate { |
87 if ((self = [super initWithFrame:NSZeroRect])) { | 87 if ((self = [super initWithFrame:NSZeroRect])) { |
88 delegate_ = delegate; | 88 delegate_ = delegate; |
89 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 89 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
90 switches::kDisableCoreAnimation)) { | 90 switches::kDisableCoreAnimation)) { |
| 91 // TODO(ccameron): Remove the -drawRect: method once the |
| 92 // kDisableCoreAnimation switch is removed. |
91 ScopedCAActionDisabler disabler; | 93 ScopedCAActionDisabler disabler; |
92 base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]); | 94 base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]); |
93 [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 95 [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
94 [self setLayer:layer]; | 96 [self setLayer:layer]; |
95 [self setWantsLayer:YES]; | 97 [self setWantsLayer:YES]; |
96 } | 98 } |
97 } | 99 } |
98 return self; | 100 return self; |
99 } | 101 } |
100 | 102 |
(...skipping 10 matching lines...) Expand all Loading... |
111 return [NSColor whiteColor]; | 113 return [NSColor whiteColor]; |
112 | 114 |
113 // Fill with a dark tint of the new tab page's background color. This is | 115 // Fill with a dark tint of the new tab page's background color. This is |
114 // only seen when the subview is sized specially for fullscreen tab capture. | 116 // only seen when the subview is sized specially for fullscreen tab capture. |
115 NSColor* bgColor = nil; | 117 NSColor* bgColor = nil; |
116 ThemeService* const theme = | 118 ThemeService* const theme = |
117 static_cast<ThemeService*>([[self window] themeProvider]); | 119 static_cast<ThemeService*>([[self window] themeProvider]); |
118 if (theme) | 120 if (theme) |
119 bgColor = theme->GetNSColor(ThemeProperties::COLOR_NTP_BACKGROUND); | 121 bgColor = theme->GetNSColor(ThemeProperties::COLOR_NTP_BACKGROUND); |
120 if (!bgColor) | 122 if (!bgColor) |
121 bgColor = [[self window] backgroundColor]; | 123 bgColor = [NSColor whiteColor]; |
122 const float kDarknessFraction = 0.80f; | 124 const float kDarknessFraction = 0.80f; |
123 return [bgColor blendedColorWithFraction:kDarknessFraction | 125 return [bgColor blendedColorWithFraction:kDarknessFraction |
124 ofColor:[NSColor blackColor]]; | 126 ofColor:[NSColor blackColor]]; |
125 } | 127 } |
126 | 128 |
127 // Override -drawRect to fill the view with a solid color outside of the | 129 // Override -drawRect to fill the view with a solid color outside of the |
128 // subview's frame. | 130 // subview's frame. |
| 131 // |
| 132 // Note: This method is never called when CoreAnimation is enabled. |
129 - (void)drawRect:(NSRect)dirtyRect { | 133 - (void)drawRect:(NSRect)dirtyRect { |
130 NSView* const contentsView = | 134 NSView* const contentsView = |
131 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil; | 135 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil; |
132 if (!contentsView || !NSContainsRect([contentsView frame], dirtyRect)) { | 136 if (!contentsView || !NSContainsRect([contentsView frame], dirtyRect)) { |
133 [[self computeBackgroundColor] setFill]; | 137 [[self computeBackgroundColor] setFill]; |
134 NSRectFill(dirtyRect); | 138 NSRectFill(dirtyRect); |
135 } | 139 } |
136 [super drawRect:dirtyRect]; | 140 [super drawRect:dirtyRect]; |
137 } | 141 } |
138 | 142 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 [contentsNativeView setFrame:[self frameForContentsView]]; | 230 [contentsNativeView setFrame:[self frameForContentsView]]; |
227 if ([subviews count] == 0) { | 231 if ([subviews count] == 0) { |
228 [contentsContainer addSubview:contentsNativeView]; | 232 [contentsContainer addSubview:contentsNativeView]; |
229 } else if ([subviews objectAtIndex:0] != contentsNativeView) { | 233 } else if ([subviews objectAtIndex:0] != contentsNativeView) { |
230 [contentsContainer replaceSubview:[subviews objectAtIndex:0] | 234 [contentsContainer replaceSubview:[subviews objectAtIndex:0] |
231 with:contentsNativeView]; | 235 with:contentsNativeView]; |
232 } | 236 } |
233 [contentsNativeView setAutoresizingMask:NSViewWidthSizable| | 237 [contentsNativeView setAutoresizingMask:NSViewWidthSizable| |
234 NSViewHeightSizable]; | 238 NSViewHeightSizable]; |
235 | 239 |
236 // TODO(miu): The following can be removed once we use a CALayer in | |
237 // TabContentsContainerView. http://crbug.com/354598 | |
238 [contentsContainer setNeedsDisplay:YES]; | 240 [contentsContainer setNeedsDisplay:YES]; |
239 | 241 |
240 // The rendering path with overlapping views disabled causes bugs when | 242 // The rendering path with overlapping views disabled causes bugs when |
241 // transitioning between composited and non-composited mode. | 243 // transitioning between composited and non-composited mode. |
242 // http://crbug.com/279472 | 244 // http://crbug.com/279472 |
243 if (!fullscreenView) | 245 if (!fullscreenView) |
244 contents_->SetAllowOverlappingViews(true); | 246 contents_->SetAllowOverlappingViews(true); |
245 } | 247 } |
246 | 248 |
247 - (void)changeWebContents:(WebContents*)newContents { | 249 - (void)changeWebContents:(WebContents*)newContents { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } else { | 358 } else { |
357 rect.ClampToCenteredSize(gfx::Size( | 359 rect.ClampToCenteredSize(gfx::Size( |
358 static_cast<int>(x / captureSize.height()), rect.height())); | 360 static_cast<int>(x / captureSize.height()), rect.height())); |
359 } | 361 } |
360 } | 362 } |
361 | 363 |
362 return NSRectFromCGRect(rect.ToCGRect()); | 364 return NSRectFromCGRect(rect.ToCGRect()); |
363 } | 365 } |
364 | 366 |
365 @end | 367 @end |
OLD | NEW |