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 "chrome/browser/ui/cocoa/background_gradient_view.h" | 5 #include "chrome/browser/ui/cocoa/background_gradient_view.h" |
6 | 6 |
7 #import "chrome/browser/themes/theme_properties.h" | 7 #import "chrome/browser/themes/theme_properties.h" |
8 #import "chrome/browser/themes/theme_service.h" | 8 #import "chrome/browser/themes/theme_service.h" |
9 #import "chrome/browser/ui/cocoa/themed_window.h" | 9 #import "chrome/browser/ui/cocoa/themed_window.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 if (!isActive && themeProvider->UsingDefaultTheme()) { | 104 if (!isActive && themeProvider->UsingDefaultTheme()) { |
105 NSColor* color = themeProvider->GetNSImageColorNamed( | 105 NSColor* color = themeProvider->GetNSImageColorNamed( |
106 IDR_THEME_TOOLBAR_INACTIVE); | 106 IDR_THEME_TOOLBAR_INACTIVE); |
107 if (color) | 107 if (color) |
108 return color; | 108 return color; |
109 } | 109 } |
110 | 110 |
111 return themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR); | 111 return themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR); |
112 } | 112 } |
113 | 113 |
114 - (void)windowFocusDidChange:(NSNotification*)notification { | 114 - (void)viewDidMoveToWindow { |
Andre
2015/02/03 19:20:37
Views usually call [[self window] isMainWindow] wh
| |
115 // Some child views will indirectly use BackgroundGradientView by calling an | 115 [super viewDidMoveToWindow]; |
116 // ancestor's draw function (e.g, BookmarkButtonView). Call setNeedsDisplay | |
117 // on all descendants to ensure that these views re-draw. | |
118 // TODO(ccameron): Enable these views to listen for focus notifications | |
119 // directly. | |
120 [self cr_recursivelySetNeedsDisplay:YES]; | |
121 } | |
122 | |
123 - (void)viewWillMoveToWindow:(NSWindow*)window { | |
124 if ([self window]) { | 116 if ([self window]) { |
125 [[NSNotificationCenter defaultCenter] | |
126 removeObserver:self | |
127 name:NSWindowDidBecomeKeyNotification | |
128 object:[self window]]; | |
129 [[NSNotificationCenter defaultCenter] | |
130 removeObserver:self | |
131 name:NSWindowDidBecomeMainNotification | |
132 object:[self window]]; | |
133 } | |
134 if (window) { | |
135 [[NSNotificationCenter defaultCenter] | |
136 addObserver:self | |
137 selector:@selector(windowFocusDidChange:) | |
138 name:NSWindowDidBecomeMainNotification | |
139 object:window]; | |
140 [[NSNotificationCenter defaultCenter] | |
141 addObserver:self | |
142 selector:@selector(windowFocusDidChange:) | |
143 name:NSWindowDidResignMainNotification | |
144 object:window]; | |
145 // The new window for the view may have a different focus state than the | 117 // The new window for the view may have a different focus state than the |
146 // last window this view was part of. Force a re-draw to ensure that the | 118 // last window this view was part of. Force a re-draw to ensure that the |
147 // view draws the right state. | 119 // view draws the right state. |
148 [self windowFocusDidChange:nil]; | 120 [self windowDidChangeActive]; |
149 } | 121 } |
150 [super viewWillMoveToWindow:window]; | |
151 } | 122 } |
152 | 123 |
153 - (void)setFrameOrigin:(NSPoint)origin { | 124 - (void)setFrameOrigin:(NSPoint)origin { |
154 // The background color depends on the view's vertical position. This impacts | 125 // The background color depends on the view's vertical position. This impacts |
155 // any child views that draw using this view's functions. | 126 // any child views that draw using this view's functions. |
156 if (NSMinY([self frame]) != origin.y) | 127 if (NSMinY([self frame]) != origin.y) |
157 [self cr_recursivelySetNeedsDisplay:YES]; | 128 [self cr_recursivelySetNeedsDisplay:YES]; |
158 | 129 |
159 [super setFrameOrigin:origin]; | 130 [super setFrameOrigin:origin]; |
160 } | 131 } |
161 | 132 |
133 // ThemedWindowDrawing implementation. | |
134 | |
135 - (void)windowDidChangeTheme { | |
136 [self setNeedsDisplay:YES]; | |
137 } | |
138 | |
139 - (void)windowDidChangeActive { | |
140 [self setNeedsDisplay:YES]; | |
141 } | |
142 | |
162 @end | 143 @end |
OLD | NEW |