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 |
| 27 // Draw a 1px border on the top edge and top corners. |
| 28 if (themed) { |
| 29 CGFloat lineWidth = [self cr_lineWidth]; |
| 30 // Inset the vertical lines by 0.5px so that the top line gets a full pixel. |
| 31 // Outset the horizontal lines by 0.5px so that they are not visible, but |
| 32 // still get the rounded corners to get a border. |
| 33 NSRect strokeRect = NSInsetRect(roundedRect, -lineWidth/2, lineWidth/2); |
| 34 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:strokeRect |
| 35 xRadius:cornerRadius |
| 36 yRadius:cornerRadius]; |
| 37 [path setLineWidth:lineWidth]; |
| 38 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.5] set]; |
| 39 [path stroke]; |
| 40 } |
| 41 } |
| 42 |
| 43 - (void)viewWillMoveToWindow:(NSWindow*)window { |
| 44 if ([self window]) { |
| 45 [[NSNotificationCenter defaultCenter] |
| 46 removeObserver:self |
| 47 name:NSWindowDidBecomeMainNotification |
| 48 object:[self window]]; |
| 49 [[NSNotificationCenter defaultCenter] |
| 50 removeObserver:self |
| 51 name:NSWindowDidResignMainNotification |
| 52 object:[self window]]; |
| 53 } |
| 54 if (window) { |
| 55 [[NSNotificationCenter defaultCenter] |
| 56 addObserver:self |
| 57 selector:@selector(windowFocusDidChange:) |
| 58 name:NSWindowDidBecomeMainNotification |
| 59 object:window]; |
| 60 [[NSNotificationCenter defaultCenter] |
| 61 addObserver:self |
| 62 selector:@selector(windowFocusDidChange:) |
| 63 name:NSWindowDidResignMainNotification |
| 64 object:window]; |
| 65 } |
| 66 } |
| 67 |
| 68 - (void)windowFocusDidChange:(NSNotification*)notification { |
| 69 // The theme image may depend on the window's active state. |
| 70 [self setNeedsDisplay:YES]; |
| 71 } |
| 72 |
| 73 @end |
OLD | NEW |