OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/ui/cocoa/tabs/tab_strip_background_view.h" | |
6 | |
7 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | |
8 #import "ui/base/cocoa/nsview_additions.h" | |
9 | |
10 @implementation TabStripBackgroundView | |
11 | |
12 - (void)drawRect:(NSRect)dirtyRect { | |
13 // Only the top corners are rounded. For simplicity, round all 4 corners but | |
14 // draw the bottom corners outside of the visible bounds. | |
15 float cornerRadius = 4.0; | |
16 NSRect roundedRect = [self bounds]; | |
17 roundedRect.origin.y -= cornerRadius; | |
18 roundedRect.size.height += cornerRadius; | |
19 [[NSBezierPath bezierPathWithRoundedRect:roundedRect | |
20 xRadius:cornerRadius | |
21 yRadius:cornerRadius] addClip]; | |
22 BOOL themed = [FramedBrowserWindow drawWindowThemeInDirtyRect:dirtyRect | |
23 forView:self | |
24 bounds:roundedRect | |
25 forceBlackBackground:NO]; | |
26 // Pinstripe the top. | |
27 if (themed) { | |
28 CGFloat lineWidth = [self cr_lineWidth]; | |
29 NSRect strokeRect = NSInsetRect(roundedRect, -lineWidth/2, lineWidth/2); | |
erikchen
2014/09/27 00:23:33
I see that this logic is just copied from framed_b
Andre
2014/09/27 18:17:02
A path's stroke is drawn right on the line instead
Andre
2014/09/27 18:47:00
Uploaded a new patch to add this as comment.
| |
30 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:strokeRect | |
31 xRadius:cornerRadius | |
32 yRadius:cornerRadius]; | |
33 [path setLineWidth:lineWidth]; | |
34 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set]; | |
35 [path stroke]; | |
36 } | |
37 } | |
38 | |
39 - (void)viewWillMoveToWindow:(NSWindow*)window { | |
40 if ([self window]) { | |
41 [[NSNotificationCenter defaultCenter] | |
42 removeObserver:self | |
43 name:NSWindowDidBecomeMainNotification | |
44 object:[self window]]; | |
45 [[NSNotificationCenter defaultCenter] | |
46 removeObserver:self | |
47 name:NSWindowDidResignMainNotification | |
48 object:[self window]]; | |
49 } | |
50 if (window) { | |
51 [[NSNotificationCenter defaultCenter] | |
52 addObserver:self | |
53 selector:@selector(windowFocusDidChange:) | |
54 name:NSWindowDidBecomeMainNotification | |
55 object:window]; | |
56 [[NSNotificationCenter defaultCenter] | |
57 addObserver:self | |
58 selector:@selector(windowFocusDidChange:) | |
59 name:NSWindowDidResignMainNotification | |
60 object:window]; | |
61 } | |
62 } | |
63 | |
64 - (void)windowFocusDidChange:(NSNotification*)notification { | |
65 // The theme image may depend on the window's active state. | |
66 [self setNeedsDisplay:YES]; | |
67 } | |
68 | |
69 @end | |
OLD | NEW |