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

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

Issue 558066: Autofill dialog for the Mac. This is UI only at this point. The UI is not h... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/section_separator_view.h"
6
7 @interface SectionSeparatorView (PrivateMethods)
8 - (void)drawGradientRect:(NSRect)rect;
9 - (void)drawBaseLineRect:(NSRect)rect;
10 - (void)drawTopLineRect:(NSRect)rect;
11 @end
12
13 @implementation SectionSeparatorView
14
15 @synthesize showBaseLine = showBaseLine_;
16 @synthesize baselineSeparatorColor = baselineSeparatorColor_;
17 @synthesize showTopLine = showTopLine_;
18 @synthesize toplineSeparatorColor = toplineSeparatorColor_;
19
20 - (id)initWithFrame:(NSRect)frame {
21 self = [super initWithFrame:frame];
22 if (self) {
23 [self setShowBaseLine:YES];
24 [self setBaselineSeparatorColor:[NSColor grayColor]];
25 [self setShowTopLine:YES];
26 [self setToplineSeparatorColor:[NSColor lightGrayColor]];
27 }
28 return self;
29 }
30
31 - (void)dealloc {
32 [baselineSeparatorColor_ release];
33 [toplineSeparatorColor_ release];
34 [super dealloc];
35 }
36
37 - (void)drawRect:(NSRect)rect {
38 NSRect gradientBounds = [self bounds];
39 NSRect baselineRect = gradientBounds;
40 NSRect toplineRect = gradientBounds;
41 gradientBounds.size.height -= 1;
42 gradientBounds.origin.y += 1;
43 baselineRect.size.height = 1;
44 baselineRect.origin.y = 0;
45 toplineRect.size.height = 1;
46 toplineRect.origin.y = gradientBounds.size.height;
47 [self drawGradientRect:gradientBounds];
48 if ([self showBaseLine])
49 [self drawBaseLineRect:baselineRect];
50 if ([self showTopLine])
51 [self drawTopLineRect:toplineRect];
52 }
53
54 @end
55
56 @implementation SectionSeparatorView (PrivateMethods)
57
58 // This method draws the gradient fill of the "separator" bar. The input
59 // |rect| designates the bounds that will be filled with the the gradient.
60 // The gradient has two stops, lighter gray blending to
61 // darker gray, descending from the top of the |rect| to the bottom.
62 - (void)drawGradientRect:(NSRect)rect {
63 // Compute start and end points where to draw the gradient.
64 CGPoint startPoint = CGPointMake(NSMinX(rect), NSMinY(rect));
65 CGPoint endPoint = CGPointMake(NSMinX(rect), NSMaxY(rect));
66
67 // Setup the context and colorspace.
68 CGContextRef context =
69 (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
70 CGContextSaveGState(context);
71 CGColorSpaceRef colorspace =
72 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
73
74 // Create the gradient.
75 const size_t stopCount = 2;
76 CGFloat stops[stopCount] = { 0.0, 1.0 };
77 CGFloat components[8] = {
78 0.75, 0.75, 0.75, 1.0, // start color
79 0.95, 0.95, 0.95, 1.0 }; // end color
80
81 CGGradientRef gradient = CGGradientCreateWithColorComponents(
82 colorspace, components, stops, stopCount);
83
84 CGContextClipToRect(context, *(CGRect*)&rect);
85 CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
86
87 CGGradientRelease(gradient);
88 CGColorSpaceRelease(colorspace);
89 CGContextRestoreGState(context);
90 }
91
92 // Draws the base line of the separator bar using the |baselineSeparatorColor_|
93 // designated color.
94 - (void)drawBaseLineRect:(NSRect)rect {
95 [baselineSeparatorColor_ set];
96 NSFrameRect(rect);
97 }
98
99 // Draws the top line of the separator bar using the |toplineSeparatorColor_|
100 // designated color.
101 - (void)drawTopLineRect:(NSRect)rect {
102 [toplineSeparatorColor_ set];
103 NSFrameRect(rect);
104 }
105
106 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/section_separator_view.h ('k') | chrome/browser/cocoa/vertical_layout_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698