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

Side by Side Diff: chrome/browser/ui/cocoa/framed_browser_window.mm

Issue 611453004: Mac: Fix theme image drawing when building with >=10.9 SDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for erikchen Created 6 years, 2 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
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/framed_browser_window.h" 5 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/sdk_forward_declarations.h" 8 #include "base/mac/sdk_forward_declarations.h"
9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
(...skipping 10 matching lines...) Expand all
21 21
22 // Implementer's note: Moving the window controls is tricky. When altering the 22 // Implementer's note: Moving the window controls is tricky. When altering the
23 // code, ensure that: 23 // code, ensure that:
24 // - accessibility hit testing works 24 // - accessibility hit testing works
25 // - the accessibility hierarchy is correct 25 // - the accessibility hierarchy is correct
26 // - close/min in the background don't bring the window forward 26 // - close/min in the background don't bring the window forward
27 // - rollover effects work correctly 27 // - rollover effects work correctly
28 28
29 namespace { 29 namespace {
30 30
31 const CGFloat kBrowserFrameViewPaintHeight = 60.0;
32
33 // Size of the gradient. Empirically determined so that the gradient looks 31 // Size of the gradient. Empirically determined so that the gradient looks
34 // like what the heuristic does when there are just a few tabs. 32 // like what the heuristic does when there are just a few tabs.
35 const CGFloat kWindowGradientHeight = 24.0; 33 const CGFloat kWindowGradientHeight = 24.0;
36 34
37 } 35 }
38 36
39 @interface FramedBrowserWindow (Private) 37 @interface FramedBrowserWindow (Private)
40 38
41 - (void)adjustCloseButton:(NSNotification*)notification; 39 - (void)adjustCloseButton:(NSNotification*)notification;
42 - (void)adjustMiniaturizeButton:(NSNotification*)notification; 40 - (void)adjustMiniaturizeButton:(NSNotification*)notification;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 if ([bwc shouldShowAvatar] && ![bwc shouldUseNewAvatarButton]) { 305 if ([bwc shouldShowAvatar] && ![bwc shouldUseNewAvatarButton]) {
308 NSView* avatarButton = [[bwc avatarButtonController] view]; 306 NSView* avatarButton = [[bwc avatarButtonController] view];
309 origin.x = -(NSWidth([avatarButton frame]) + 3); 307 origin.x = -(NSWidth([avatarButton frame]) + 3);
310 } else { 308 } else {
311 origin.x -= 6; 309 origin.x -= 6;
312 } 310 }
313 311
314 return origin; 312 return origin;
315 } 313 }
316 314
317 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
318 // WARNING: There is an obvious optimization opportunity here that you DO NOT
319 // want to take. To save painting cycles, you might think it would be a good
320 // idea to call out to the default implementation only if no theme were
321 // drawn. In reality, however, if you fail to call the default
322 // implementation, or if you call it after a clipping path is set, the
323 // rounded corners at the top of the window will not draw properly. Do not
324 // try to be smart here.
325
326 // Only paint the top of the window.
327 NSRect windowRect = [view convertRect:[self frame] fromView:nil];
328 windowRect.origin = NSZeroPoint;
329
330 NSRect paintRect = windowRect;
331 paintRect.origin.y = NSMaxY(paintRect) - kBrowserFrameViewPaintHeight;
332 paintRect.size.height = kBrowserFrameViewPaintHeight;
333 rect = NSIntersectionRect(paintRect, rect);
334 [super drawCustomFrameRect:rect forView:view];
335
336 // Set up our clip.
337 float cornerRadius = 4.0;
338 if ([view respondsToSelector:@selector(roundedCornerRadius)])
339 cornerRadius = [view roundedCornerRadius];
340 [[NSBezierPath bezierPathWithRoundedRect:windowRect
341 xRadius:cornerRadius
342 yRadius:cornerRadius] addClip];
343 [[NSBezierPath bezierPathWithRect:rect] addClip];
344
345 // Do the theming.
346 BOOL themed = [FramedBrowserWindow
347 drawWindowThemeInDirtyRect:rect
348 forView:view
349 bounds:windowRect
350 forceBlackBackground:NO];
351
352 // If the window needs a title and we painted over the title as drawn by the
353 // default window paint, paint it ourselves.
354 if (themed && [view respondsToSelector:@selector(_titlebarTitleRect)] &&
355 [view respondsToSelector:@selector(_drawTitleStringIn:withColor:)] &&
356 ![self _isTitleHidden]) {
357 [view _drawTitleStringIn:[view _titlebarTitleRect]
358 withColor:[self titleColor]];
359 }
360
361 // Pinstripe the top.
362 if (themed) {
363 CGFloat lineWidth = [view cr_lineWidth];
364
365 windowRect = [view convertRect:[self frame] fromView:nil];
366 windowRect.origin = NSZeroPoint;
367 windowRect.origin.y -= 0.5 * lineWidth;
368 windowRect.origin.x -= 0.5 * lineWidth;
369 windowRect.size.width += lineWidth;
370 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set];
371 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:windowRect
372 xRadius:cornerRadius
373 yRadius:cornerRadius];
374 [path setLineWidth:lineWidth];
375 [path stroke];
376 }
377 }
378
379 + (BOOL)drawWindowThemeInDirtyRect:(NSRect)dirtyRect 315 + (BOOL)drawWindowThemeInDirtyRect:(NSRect)dirtyRect
380 forView:(NSView*)view 316 forView:(NSView*)view
381 bounds:(NSRect)bounds 317 bounds:(NSRect)bounds
382 forceBlackBackground:(BOOL)forceBlackBackground { 318 forceBlackBackground:(BOOL)forceBlackBackground {
383 ui::ThemeProvider* themeProvider = [[view window] themeProvider]; 319 ui::ThemeProvider* themeProvider = [[view window] themeProvider];
384 if (!themeProvider) 320 if (!themeProvider)
385 return NO; 321 return NO;
386 322
387 ThemedWindowStyle windowStyle = [[view window] themedWindowStyle]; 323 ThemedWindowStyle windowStyle = [[view window] themedWindowStyle];
388 324
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 ThemedWindowStyle windowStyle = [self themedWindowStyle]; 423 ThemedWindowStyle windowStyle = [self themedWindowStyle];
488 BOOL incognito = windowStyle & THEMED_INCOGNITO; 424 BOOL incognito = windowStyle & THEMED_INCOGNITO;
489 425
490 if (incognito) 426 if (incognito)
491 return [NSColor whiteColor]; 427 return [NSColor whiteColor];
492 else 428 else
493 return [NSColor windowFrameTextColor]; 429 return [NSColor windowFrameTextColor];
494 } 430 }
495 431
496 @end 432 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698