blob: 4b5e9ac9265c6744dfd3507127dc639b217656a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#import "chrome/browser/cocoa/location_bar/instant_opt_in_view.h"
#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
namespace {
// How to round off the popup's corners. Goal is to match star and go
// buttons.
const CGFloat kPopupRoundingRadius = 3.5;
// How far from the top of the view to place the horizontal line.
const CGFloat kHorizontalLineTopOffset = 2;
// How far from the sides to inset the horizontal line.
const CGFloat kHorizontalLineInset = 2;
}
@implementation InstantOptInView
- (void)drawRect:(NSRect)rect {
// Round off the bottom corners only.
NSBezierPath* path =
[NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
topLeftCornerRadius:0
topRightCornerRadius:0
bottomLeftCornerRadius:kPopupRoundingRadius
bottomRightCornerRadius:kPopupRoundingRadius];
[NSGraphicsContext saveGraphicsState];
[path addClip];
// Background is white.
[[NSColor whiteColor] set];
NSRectFill(rect);
// Draw a horizontal line 2 px down from the top of the view, inset at the
// sides by 2 px.
CGFloat lineY = NSMaxY([self bounds]) - kHorizontalLineTopOffset;
CGFloat minX = std::min(NSMinX([self bounds]) + kHorizontalLineInset,
NSMaxX([self bounds]));
CGFloat maxX = std::max(NSMaxX([self bounds]) - kHorizontalLineInset,
NSMinX([self bounds]));
[[NSColor lightGrayColor] set];
NSRectFill(NSMakeRect(minX, lineY, maxX - minX, 1));
[NSGraphicsContext restoreGraphicsState];
}
@end
|