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

Side by Side Diff: chrome/browser/cocoa/background_gradient_view.mm

Issue 260009: Several background pattern fixes on the Mac.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/cocoa/background_gradient_view.h" 5 #include "chrome/browser/cocoa/background_gradient_view.h"
6 6
7 #define kToolbarTopOffset 12 7 #define kToolbarTopOffset 12
8 #define kToolbarMaxHeight 100 8 #define kToolbarMaxHeight 100
9 9
10 @implementation BackgroundGradientView 10 @implementation BackgroundGradientView
11 @synthesize showsDivider = showsDivider_; 11 @synthesize showsDivider = showsDivider_;
12 12
13 - (id)initWithFrame:(NSRect)frameRect { 13 - (id)initWithFrame:(NSRect)frameRect {
14 self = [super initWithFrame:frameRect]; 14 self = [super initWithFrame:frameRect];
15 if (self != nil) { 15 if (self != nil) {
16 showsDivider_ = YES; 16 showsDivider_ = YES;
17 } 17 }
18 return self; 18 return self;
19 } 19 }
20 20
21 - (void)awakeFromNib { 21 - (void)awakeFromNib {
22 showsDivider_ = YES; 22 showsDivider_ = YES;
23 } 23 }
24 24
25 - (void)setShowsDivider:(BOOL)show { 25 - (void)setShowsDivider:(BOOL)show {
26 showsDivider_ = show; 26 showsDivider_ = show;
27 [self setNeedsDisplay:YES]; 27 [self setNeedsDisplay:YES];
28 } 28 }
29 29
30 // The offset of this pattern to make it line up with the top of the window. 30 - (void)drawBackground {
31 - (NSPoint)patternPhase {
32 NSPoint phase = NSZeroPoint;
33 phase.y += NSHeight([[self window] frame]) - kToolbarTopOffset;
34 return phase;
35 }
36
37 - (void)drawRect:(NSRect)rect {
38 BOOL isKey = [[self window] isKeyWindow]; 31 BOOL isKey = [[self window] isKeyWindow];
39 32 GTMTheme* theme = [self gtm_theme];
40 GTMTheme *theme = [self gtm_theme]; 33 NSImage* backgroundImage =
41 34 [theme backgroundImageForStyle:GTMThemeStyleToolBar
42 NSImage *backgroundImage = [theme backgroundImageForStyle:GTMThemeStyleToolBar 35 state:GTMThemeStateActiveWindow];
43 state:GTMThemeStateActiveWindow];
44 if (backgroundImage) { 36 if (backgroundImage) {
45 NSPoint phase = [self patternPhase]; 37 NSColor* color = [NSColor colorWithPatternImage:backgroundImage];
46 [[NSGraphicsContext currentContext] setPatternPhase:phase];
47
48 NSColor *color = [NSColor colorWithPatternImage:backgroundImage];
49 [color set]; 38 [color set];
50 NSRectFill([self bounds]); 39 NSRectFill([self bounds]);
51 } else { 40 } else {
52 CGFloat winHeight = NSHeight([[self window] frame]); 41 CGFloat winHeight = NSHeight([[self window] frame]);
53 NSGradient *gradient = [theme gradientForStyle:GTMThemeStyleToolBar 42 NSGradient* gradient = [theme gradientForStyle:GTMThemeStyleToolBar
54 state:isKey]; 43 state:isKey];
55 NSPoint startPoint = 44 NSPoint startPoint =
56 [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) 45 [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset)
57 fromView:nil]; 46 fromView:nil];
58 NSPoint endPoint = 47 NSPoint endPoint =
59 [self convertPoint:NSMakePoint(0, winHeight - 48 NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight);
60 kToolbarTopOffset - 49 endPoint = [self convertPoint:endPoint fromView:nil];
61 kToolbarMaxHeight)
62 fromView:nil];
63 50
64 [gradient drawFromPoint:startPoint 51 [gradient drawFromPoint:startPoint
65 toPoint:endPoint 52 toPoint:endPoint
66 options:NSGradientDrawsBeforeStartingLocation | 53 options:(NSGradientDrawsBeforeStartingLocation |
67 NSGradientDrawsAfterEndingLocation]; 54 NSGradientDrawsAfterEndingLocation)];
68 } 55 }
69 56
70 if (showsDivider_) { 57 if (showsDivider_) {
71 // Draw bottom stroke 58 // Draw bottom stroke
72 [[self strokeColor] set]; 59 [[self strokeColor] set];
73 NSRect borderRect, contentRect; 60 NSRect borderRect, contentRect;
74 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); 61 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge);
75 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); 62 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
76 } 63 }
77 } 64 }
78 65
79 - (NSColor*)strokeColor { 66 - (NSColor*)strokeColor {
80 return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar 67 return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar
81 state:[[self window] isKeyWindow]]; 68 state:[[self window] isKeyWindow]];
82 } 69 }
83 70
84 @end 71 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/background_gradient_view.h ('k') | chrome/browser/cocoa/background_gradient_view_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698