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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm

Issue 2866963002: mac: Set background color from theme before NSView is added to window (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tab_contents/tab_contents_controller.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
15 #import "chrome/browser/themes/theme_properties.h" 15 #import "chrome/browser/themes/theme_properties.h"
16 #import "chrome/browser/themes/theme_service.h" 16 #import "chrome/browser/themes/theme_service.h"
17 #import "chrome/browser/ui/cocoa/themed_window.h" 17 #import "chrome/browser/ui/cocoa/themed_window.h"
18 #include "chrome/browser/ui/view_ids.h" 18 #include "chrome/browser/ui/view_ids.h"
19 #include "chrome/grit/theme_resources.h"
19 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/render_widget_host.h" 21 #include "content/public/browser/render_widget_host.h"
21 #include "content/public/browser/render_widget_host_view.h" 22 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
24 #include "skia/ext/skia_utils_mac.h" 25 #include "skia/ext/skia_utils_mac.h"
25 #include "ui/base/cocoa/animation_utils.h" 26 #include "ui/base/cocoa/animation_utils.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
27 28
28 using content::WebContents; 29 using content::WebContents;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 @end 84 @end
84 85
85 // An NSView with special-case handling for when the contents view does not 86 // An NSView with special-case handling for when the contents view does not
86 // expand to fill the entire tab contents area. See 'AutoEmbedFullscreen mode' 87 // expand to fill the entire tab contents area. See 'AutoEmbedFullscreen mode'
87 // in header file comments. 88 // in header file comments.
88 @interface TabContentsContainerView : NSView { 89 @interface TabContentsContainerView : NSView {
89 @private 90 @private
90 TabContentsController* delegate_; // weak 91 TabContentsController* delegate_; // weak
91 } 92 }
92 93
93 - (void)updateBackgroundColor; 94 - (void)updateBackgroundColorFromWindowTheme:(NSWindow*)window;
94 @end 95 @end
95 96
96 @implementation TabContentsContainerView 97 @implementation TabContentsContainerView
97 98
98 - (id)initWithDelegate:(TabContentsController*)delegate { 99 - (id)initWithDelegate:(TabContentsController*)delegate {
99 if ((self = [super initWithFrame:NSZeroRect])) { 100 if ((self = [super initWithFrame:NSZeroRect])) {
100 delegate_ = delegate; 101 delegate_ = delegate;
101 ScopedCAActionDisabler disabler; 102 ScopedCAActionDisabler disabler;
102 base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]); 103 base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
103 [self setLayer:layer]; 104 [self setLayer:layer];
104 [self setWantsLayer:YES]; 105 [self setWantsLayer:YES];
105 [self updateBackgroundColor];
106 } 106 }
107 return self; 107 return self;
108 } 108 }
109 109
110 // Called by the delegate during dealloc to invalidate the pointer held by this 110 // Called by the delegate during dealloc to invalidate the pointer held by this
111 // view. 111 // view.
112 - (void)delegateDestroyed { 112 - (void)delegateDestroyed {
113 delegate_ = nil; 113 delegate_ = nil;
114 } 114 }
115 115
(...skipping 12 matching lines...) Expand all
128 return; 128 return;
129 } 129 }
130 130
131 ScopedCAActionDisabler disabler; 131 ScopedCAActionDisabler disabler;
132 [contentsView setFrame:[delegate_ frameForContentsViewIn:self]]; 132 [contentsView setFrame:[delegate_ frameForContentsViewIn:self]];
133 } 133 }
134 134
135 // Update the background layer's color whenever the view needs to repaint. 135 // Update the background layer's color whenever the view needs to repaint.
136 - (void)setNeedsDisplayInRect:(NSRect)rect { 136 - (void)setNeedsDisplayInRect:(NSRect)rect {
137 [super setNeedsDisplayInRect:rect]; 137 [super setNeedsDisplayInRect:rect];
138 [self updateBackgroundColor]; 138 [self updateBackgroundColorFromWindowTheme:[self window]];
139 } 139 }
140 140
141 - (void)updateBackgroundColor { 141 - (void)updateBackgroundColorFromWindowTheme:(NSWindow*)window {
142 // This view is sometimes flashed into visibility (e.g, when closing 142 // This view is sometimes flashed into visibility (e.g, when closing
143 // windows or opening new tabs), so ensure that the flash be the theme 143 // windows or opening new tabs), so ensure that the flash be the theme
144 // background color in those cases. 144 // background color in those cases.
145 SkColor skBackgroundColor = SK_ColorWHITE; 145 const ThemeProvider* theme = [window themeProvider];
146 const ThemeProvider* theme = [[self window] themeProvider]; 146 ThemedWindowStyle windowStyle = [window themedWindowStyle];
147 if (theme) 147 if (!theme)
148 skBackgroundColor = theme->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND); 148 return;
149
150 // This logic and hard-coded color value are duplicated from the function
151 // NTPResourceCache::CreateNewTabIncognitoCSS. This logic should exist in only
152 // one location.
153 // https://crbug.com/719236
154 SkColor skBackgroundColor =
155 theme->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND);
156 bool incognito = windowStyle & THEMED_INCOGNITO;
157 if (incognito && !theme->HasCustomImage(IDR_THEME_NTP_BACKGROUND))
158 skBackgroundColor = SkColorSetRGB(0x32, 0x32, 0x32);
149 159
150 // If the page is in fullscreen tab capture mode, change the background color 160 // If the page is in fullscreen tab capture mode, change the background color
151 // to be a dark tint of the new tab page's background color. 161 // to be a dark tint of the new tab page's background color.
152 if ([delegate_ contentsInFullscreenCaptureMode]) { 162 if ([delegate_ contentsInFullscreenCaptureMode]) {
153 const int kBackgroundDivisor = 5; 163 const int kBackgroundDivisor = 5;
154 skBackgroundColor = skBackgroundColor = SkColorSetARGB( 164 skBackgroundColor = skBackgroundColor = SkColorSetARGB(
155 SkColorGetA(skBackgroundColor), 165 SkColorGetA(skBackgroundColor),
156 SkColorGetR(skBackgroundColor) / kBackgroundDivisor, 166 SkColorGetR(skBackgroundColor) / kBackgroundDivisor,
157 SkColorGetG(skBackgroundColor) / kBackgroundDivisor, 167 SkColorGetG(skBackgroundColor) / kBackgroundDivisor,
158 SkColorGetB(skBackgroundColor) / kBackgroundDivisor); 168 SkColorGetB(skBackgroundColor) / kBackgroundDivisor);
159 } 169 }
160 170
161 ScopedCAActionDisabler disabler; 171 ScopedCAActionDisabler disabler;
162 base::ScopedCFTypeRef<CGColorRef> cgBackgroundColor( 172 base::ScopedCFTypeRef<CGColorRef> cgBackgroundColor(
163 skia::CGColorCreateFromSkColor(skBackgroundColor)); 173 skia::CGColorCreateFromSkColor(skBackgroundColor));
164 [[self layer] setBackgroundColor:cgBackgroundColor]; 174 [[self layer] setBackgroundColor:cgBackgroundColor];
165 } 175 }
166 176
177 - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
178 [self updateBackgroundColorFromWindowTheme:newWindow];
179 }
180
167 - (ViewID)viewID { 181 - (ViewID)viewID {
168 return VIEW_ID_TAB_CONTAINER; 182 return VIEW_ID_TAB_CONTAINER;
169 } 183 }
170 184
171 - (BOOL)acceptsFirstResponder { 185 - (BOOL)acceptsFirstResponder {
172 return [[self subviews] count] > 0 && 186 return [[self subviews] count] > 0 &&
173 [[[self subviews] objectAtIndex:0] acceptsFirstResponder]; 187 [[[self subviews] objectAtIndex:0] acceptsFirstResponder];
174 } 188 }
175 189
176 // When receiving a click-to-focus in the solid color area surrounding the 190 // When receiving a click-to-focus in the solid color area surrounding the
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 392
379 - (BOOL)shouldResizeContentView { 393 - (BOOL)shouldResizeContentView {
380 return !isEmbeddingFullscreenWidget_ || !blockFullscreenResize_; 394 return !isEmbeddingFullscreenWidget_ || !blockFullscreenResize_;
381 } 395 }
382 396
383 - (BOOL)isPopup { 397 - (BOOL)isPopup {
384 return isPopup_; 398 return isPopup_;
385 } 399 }
386 400
387 @end 401 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698