Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/browser_frame_view.h" | 5 #import "chrome/browser/cocoa/browser_frame_view.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #import <Carbon/Carbon.h> | 8 #import <Carbon/Carbon.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 123 |
| 124 // WARNING: There is an obvious optimization opportunity here that you DO NOT | 124 // WARNING: There is an obvious optimization opportunity here that you DO NOT |
| 125 // want to take. To save painting cycles, you might think it would be a good | 125 // want to take. To save painting cycles, you might think it would be a good |
| 126 // idea to call out to -drawRectOriginal: only if no theme were drawn. In | 126 // idea to call out to -drawRectOriginal: only if no theme were drawn. In |
| 127 // reality, however, if you fail to call -drawRectOriginal:, or if you call it | 127 // reality, however, if you fail to call -drawRectOriginal:, or if you call it |
| 128 // after a clipping path is set, the rounded corners at the top of the window | 128 // after a clipping path is set, the rounded corners at the top of the window |
| 129 // will not draw properly. Do not try to be smart here. | 129 // will not draw properly. Do not try to be smart here. |
| 130 | 130 |
| 131 // Only paint the top of the window. | 131 // Only paint the top of the window. |
| 132 NSWindow* window = [self window]; | 132 NSWindow* window = [self window]; |
| 133 NSRect windowRect = [window frame]; | 133 NSRect windowRect = [self convertRect:[window frame] fromView:nil]; |
| 134 windowRect.origin = NSMakePoint(0, 0); | 134 windowRect.origin = NSMakePoint(0, 0); |
| 135 | 135 |
| 136 NSRect paintRect = windowRect; | 136 NSRect paintRect = windowRect; |
| 137 paintRect.origin.y = NSMaxY(paintRect) - kBrowserFrameViewPaintHeight; | 137 paintRect.origin.y = NSMaxY(paintRect) - kBrowserFrameViewPaintHeight; |
| 138 paintRect.size.height = kBrowserFrameViewPaintHeight; | 138 paintRect.size.height = kBrowserFrameViewPaintHeight; |
| 139 rect = NSIntersectionRect(paintRect, rect); | 139 rect = NSIntersectionRect(paintRect, rect); |
| 140 [self drawRectOriginal:rect]; | 140 [self drawRectOriginal:rect]; |
| 141 | 141 |
| 142 // Set up our clip. | 142 // Set up our clip. |
| 143 float cornerRadius = 4.0; | 143 float cornerRadius = 4.0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 155 | 155 |
| 156 // If the window needs a title and we painted over the title as drawn by the | 156 // If the window needs a title and we painted over the title as drawn by the |
| 157 // default window paint, paint it ourselves. | 157 // default window paint, paint it ourselves. |
| 158 if (themed && gCanDrawTitle && ![[self window] _isTitleHidden]) { | 158 if (themed && gCanDrawTitle && ![[self window] _isTitleHidden]) { |
| 159 [self _drawTitleStringIn:[self _titlebarTitleRect] | 159 [self _drawTitleStringIn:[self _titlebarTitleRect] |
| 160 withColor:[BrowserFrameView titleColorForThemeView:self]]; | 160 withColor:[BrowserFrameView titleColorForThemeView:self]]; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Pinstripe the top. | 163 // Pinstripe the top. |
| 164 if (themed) { | 164 if (themed) { |
| 165 windowRect = [window frame]; | 165 NSSize windowPixel = [self convertSizeFromBase:NSMakeSize(1, 1)]; |
| 166 | |
| 167 windowRect = [self convertRect:[window frame] fromView:nil]; | |
| 166 windowRect.origin = NSMakePoint(0, 0); | 168 windowRect.origin = NSMakePoint(0, 0); |
| 167 windowRect.origin.y -= 0.5; | 169 windowRect.origin.y -= 0.5 * windowPixel.height; |
| 168 windowRect.origin.x -= 0.5; | 170 windowRect.origin.x -= 0.5 * windowPixel.width; |
| 169 windowRect.size.width += 1.0; | 171 windowRect.size.width += windowPixel.width; |
| 170 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set]; | 172 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set]; |
| 171 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:windowRect | 173 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:windowRect |
| 172 xRadius:cornerRadius | 174 xRadius:cornerRadius |
| 173 yRadius:cornerRadius]; | 175 yRadius:cornerRadius]; |
| 174 [path setLineWidth:1.0]; | 176 [path setLineWidth:windowPixel.width]; |
| 175 [path stroke]; | 177 [path stroke]; |
| 176 } | 178 } |
| 177 } | 179 } |
| 178 | 180 |
| 179 + (BOOL)drawWindowThemeInDirtyRect:(NSRect)dirtyRect | 181 + (BOOL)drawWindowThemeInDirtyRect:(NSRect)dirtyRect |
| 180 forView:(NSView*)view | 182 forView:(NSView*)view |
| 181 bounds:(NSRect)bounds { | 183 bounds:(NSRect)bounds { |
| 182 ThemeProvider* themeProvider = [[view window] themeProvider]; | 184 ThemeProvider* themeProvider = [[view window] themeProvider]; |
| 183 if (!themeProvider) | 185 if (!themeProvider) |
| 184 return NO; | 186 return NO; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 // patterns, we have to shift the pattern slightly, rather than simply | 227 // patterns, we have to shift the pattern slightly, rather than simply |
| 226 // drawing it from the top left corner. The offset below was empirically | 228 // drawing it from the top left corner. The offset below was empirically |
| 227 // determined in order to line these patterns up. | 229 // determined in order to line these patterns up. |
| 228 // | 230 // |
| 229 // This will make the themes look slightly different than in Windows/Linux | 231 // This will make the themes look slightly different than in Windows/Linux |
| 230 // because of the differing heights between window top and tab top, but this | 232 // because of the differing heights between window top and tab top, but this |
| 231 // has been approved by UI. | 233 // has been approved by UI. |
| 232 NSPoint phase = kBrowserFrameViewPatternPhaseOffset; | 234 NSPoint phase = kBrowserFrameViewPatternPhaseOffset; |
| 233 phase.y += NSHeight(bounds); | 235 phase.y += NSHeight(bounds); |
| 234 | 236 |
| 235 phase = [view convertPoint:phase toView:nil]; | 237 // Align the phase to physical pixels so resizing the window under HiDPI |
| 238 // doesn't cause wiggling of the theme. | |
| 239 phase = [view convertPointToBase:phase]; | |
| 240 phase.x = floor(phase.x); | |
| 241 phase.y = floor(phase.y); | |
| 242 phase = [view convertPointFromBase:phase]; | |
|
Nico
2010/03/11 23:38:32
:-)
| |
| 236 | 243 |
| 237 [[NSGraphicsContext currentContext] setPatternPhase:phase]; | 244 [[NSGraphicsContext currentContext] setPatternPhase:phase]; |
| 238 [themeImageColor set]; | 245 [themeImageColor set]; |
| 239 NSRectFill(dirtyRect); | 246 NSRectFill(dirtyRect); |
| 240 themed = YES; | 247 themed = YES; |
| 241 } else if (gradient) { | 248 } else if (gradient) { |
| 242 NSPoint startPoint = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); | 249 NSPoint startPoint = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); |
| 243 NSPoint endPoint = startPoint; | 250 NSPoint endPoint = startPoint; |
| 244 endPoint.y -= kBrowserFrameViewPaintHeight; | 251 endPoint.y -= kBrowserFrameViewPaintHeight; |
| 245 [gradient drawFromPoint:startPoint toPoint:endPoint options:0]; | 252 [gradient drawFromPoint:startPoint toPoint:endPoint options:0]; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 - (void)updateTrackingAreas { | 317 - (void)updateTrackingAreas { |
| 311 [super updateTrackingAreas]; | 318 [super updateTrackingAreas]; |
| 312 if ([[self window] isKindOfClass:[ChromeBrowserWindow class]]) { | 319 if ([[self window] isKindOfClass:[ChromeBrowserWindow class]]) { |
| 313 ChromeBrowserWindow* window = | 320 ChromeBrowserWindow* window = |
| 314 static_cast<ChromeBrowserWindow*>([self window]); | 321 static_cast<ChromeBrowserWindow*>([self window]); |
| 315 [window updateTrackingAreas]; | 322 [window updateTrackingAreas]; |
| 316 } | 323 } |
| 317 } | 324 } |
| 318 | 325 |
| 319 @end | 326 @end |
| OLD | NEW |