| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h" | 5 #import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "skia/ext/skia_utils_mac.h" | 8 #import "skia/ext/skia_utils_mac.h" |
| 9 | 9 |
| 10 @interface TitlebarBackgroundView () | 10 @interface TitlebarBackgroundView () |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::scoped_nsobject<TitlebarBackgroundView> titlebar_background_view( | 28 base::scoped_nsobject<TitlebarBackgroundView> titlebar_background_view( |
| 29 [[TitlebarBackgroundView alloc] | 29 [[TitlebarBackgroundView alloc] |
| 30 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height, | 30 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height, |
| 31 NSWidth([window_view bounds]), height)]); | 31 NSWidth([window_view bounds]), height)]); |
| 32 [titlebar_background_view | 32 [titlebar_background_view |
| 33 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | 33 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 34 [window_view addSubview:titlebar_background_view | 34 [window_view addSubview:titlebar_background_view |
| 35 positioned:NSWindowBelow | 35 positioned:NSWindowBelow |
| 36 relativeTo:nil]; | 36 relativeTo:nil]; |
| 37 | 37 |
| 38 [titlebar_background_view setColor:gfx::SkColorToSRGBNSColor(activeColor) | 38 [titlebar_background_view setColor:skia::SkColorToSRGBNSColor(activeColor) |
| 39 inactiveColor:gfx::SkColorToSRGBNSColor(inactiveColor)]; | 39 inactiveColor:skia::SkColorToSRGBNSColor(inactiveColor)]; |
| 40 return titlebar_background_view.autorelease(); | 40 return titlebar_background_view.autorelease(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 - (void)drawRect:(NSRect)rect { | 43 - (void)drawRect:(NSRect)rect { |
| 44 // Only the top corners are rounded. For simplicity, round all 4 corners but | 44 // Only the top corners are rounded. For simplicity, round all 4 corners but |
| 45 // draw the bottom corners outside of the visible bounds. | 45 // draw the bottom corners outside of the visible bounds. |
| 46 CGFloat cornerRadius = 4.0; | 46 CGFloat cornerRadius = 4.0; |
| 47 NSRect roundedRect = [self bounds]; | 47 NSRect roundedRect = [self bounds]; |
| 48 roundedRect.origin.y -= cornerRadius; | 48 roundedRect.origin.y -= cornerRadius; |
| 49 roundedRect.size.height += cornerRadius; | 49 roundedRect.size.height += cornerRadius; |
| 50 [[NSBezierPath bezierPathWithRoundedRect:roundedRect | 50 [[NSBezierPath bezierPathWithRoundedRect:roundedRect |
| 51 xRadius:cornerRadius | 51 xRadius:cornerRadius |
| 52 yRadius:cornerRadius] addClip]; | 52 yRadius:cornerRadius] addClip]; |
| 53 if ([[self window] isMainWindow] || [[self window] isKeyWindow]) | 53 if ([[self window] isMainWindow] || [[self window] isKeyWindow]) |
| 54 [color_ set]; | 54 [color_ set]; |
| 55 else | 55 else |
| 56 [inactiveColor_ set]; | 56 [inactiveColor_ set]; |
| 57 NSRectFill(rect); | 57 NSRectFill(rect); |
| 58 } | 58 } |
| 59 | 59 |
| 60 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor { | 60 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor { |
| 61 color_.reset([color retain]); | 61 color_.reset([color retain]); |
| 62 inactiveColor_.reset([inactiveColor retain]); | 62 inactiveColor_.reset([inactiveColor retain]); |
| 63 } | 63 } |
| 64 | 64 |
| 65 @end | 65 @end |
| OLD | NEW |