Chromium Code Reviews| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 // on all descendants to ensure that these views re-draw. | 117 // on all descendants to ensure that these views re-draw. |
| 118 // TODO(ccameron): Enable these views to listen for focus notifications | 118 // TODO(ccameron): Enable these views to listen for focus notifications |
| 119 // directly. | 119 // directly. |
| 120 [self cr_recursivelySetNeedsDisplay:YES]; | 120 [self cr_recursivelySetNeedsDisplay:YES]; |
| 121 } | 121 } |
| 122 | 122 |
| 123 - (void)viewWillMoveToWindow:(NSWindow*)window { | 123 - (void)viewWillMoveToWindow:(NSWindow*)window { |
| 124 if ([self window]) { | 124 if ([self window]) { |
| 125 [[NSNotificationCenter defaultCenter] | 125 [[NSNotificationCenter defaultCenter] |
| 126 removeObserver:self | 126 removeObserver:self |
| 127 name:NSWindowDidBecomeKeyNotification | |
| 128 object:[self window]]; | |
| 129 [[NSNotificationCenter defaultCenter] | |
| 130 removeObserver:self | |
|
Andre
2015/01/31 01:00:48
This looks like a bug.
| |
| 131 name:NSWindowDidBecomeMainNotification | 127 name:NSWindowDidBecomeMainNotification |
| 132 object:[self window]]; | 128 object:[self window]]; |
| 129 [[NSNotificationCenter defaultCenter] | |
| 130 removeObserver:self | |
| 131 name:NSWindowDidResignMainNotification | |
| 132 object:[self window]]; | |
| 133 } | 133 } |
| 134 if (window) { | 134 if (window) { |
| 135 [[NSNotificationCenter defaultCenter] | 135 [[NSNotificationCenter defaultCenter] |
| 136 addObserver:self | 136 addObserver:self |
| 137 selector:@selector(windowFocusDidChange:) | 137 selector:@selector(windowFocusDidChange:) |
| 138 name:NSWindowDidBecomeMainNotification | 138 name:NSWindowDidBecomeMainNotification |
| 139 object:window]; | 139 object:window]; |
| 140 [[NSNotificationCenter defaultCenter] | 140 [[NSNotificationCenter defaultCenter] |
| 141 addObserver:self | 141 addObserver:self |
| 142 selector:@selector(windowFocusDidChange:) | 142 selector:@selector(windowFocusDidChange:) |
| 143 name:NSWindowDidResignMainNotification | 143 name:NSWindowDidResignMainNotification |
| 144 object:window]; | 144 object:window]; |
| 145 // The new window for the view may have a different focus state than the | 145 // 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 | 146 // last window this view was part of. Force a re-draw to ensure that the |
| 147 // view draws the right state. | 147 // view draws the right state. |
| 148 [self windowFocusDidChange:nil]; | 148 [self windowFocusDidChange:nil]; |
| 149 } | 149 } |
| 150 [super viewWillMoveToWindow:window]; | 150 [super viewWillMoveToWindow:window]; |
| 151 } | 151 } |
| 152 | 152 |
| 153 - (void)viewWillStartLiveResize { | |
| 154 [super viewWillStartLiveResize]; | |
| 155 | |
| 156 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | |
| 157 if (themeProvider && themeProvider->UsingSystemTheme()) { | |
| 158 // The default theme's background image is a subtle texture pattern that | |
| 159 // we can scale without being easily noticed. Optimize this case by | |
| 160 // skipping redraws during live resize. | |
| 161 [self setLayerContentsRedrawPolicy: | |
| 162 NSViewLayerContentsRedrawOnSetNeedsDisplay]; | |
|
Robert Sesek
2015/02/02 19:32:16
nit: over-indented
Andre
2015/02/02 21:40:08
Done.
| |
| 163 } | |
| 164 } | |
| 165 | |
| 166 - (void)viewDidEndLiveResize { | |
| 167 [super viewDidEndLiveResize]; | |
| 168 | |
| 169 if ([self layerContentsRedrawPolicy] != | |
| 170 NSViewLayerContentsRedrawDuringViewResize) { | |
| 171 // If we have been scaling the layer during live resize, now is the time to | |
| 172 // redraw the layer. | |
| 173 [self setLayerContentsRedrawPolicy: | |
| 174 NSViewLayerContentsRedrawDuringViewResize]; | |
| 175 [self setNeedsDisplay:YES]; | |
| 176 } | |
| 177 } | |
| 178 | |
| 153 - (void)setFrameOrigin:(NSPoint)origin { | 179 - (void)setFrameOrigin:(NSPoint)origin { |
| 154 // The background color depends on the view's vertical position. This impacts | 180 // The background color depends on the view's vertical position. This impacts |
| 155 // any child views that draw using this view's functions. | 181 // any child views that draw using this view's functions. |
| 156 if (NSMinY([self frame]) != origin.y) | 182 // When resizing the window, the view's vertical position (NSMinY) may change |
| 183 // even though our relative position to the nearest window edge is still the | |
| 184 // same. Don't redraw unnecessarily in this case. | |
| 185 if (![self inLiveResize] && NSMinY([self frame]) != origin.y) | |
| 157 [self cr_recursivelySetNeedsDisplay:YES]; | 186 [self cr_recursivelySetNeedsDisplay:YES]; |
| 158 | 187 |
| 159 [super setFrameOrigin:origin]; | 188 [super setFrameOrigin:origin]; |
| 160 } | 189 } |
| 161 | 190 |
| 162 @end | 191 @end |
| OLD | NEW |