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

Side by Side Diff: chrome/browser/ui/cocoa/apps/titlebar_background_view.mm

Issue 1053303003: [MacViews] Implement colored window frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed a few things. Created 5 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h"
6
7 #import <Cocoa/Cocoa.h>
tapted 2015/05/12 06:15:43 nit: don't need this since it's in the header.
jackhou1 2015/05/14 02:59:13 Done.
8
9 #import "skia/ext/skia_utils_mac.h"
10
11 @interface TitlebarBackgroundView ()
12 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor;
13 @end
14
15 @implementation TitlebarBackgroundView
16
17 + (void)addToNSWindow:(NSWindow*)window
18 activeColor:(SkColor)activeColor
19 inactiveColor:(SkColor)inactiveColor {
20 // AppKit only officially supports adding subviews to the window's
21 // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK
22 // allows adding an NSTitlebarAccessoryViewController to a window, but the
23 // view can only be placed above the window control buttons, so we'd have to
24 // replicate those.
25 NSView* window_view = [[window contentView] superview];
26 CGFloat height =
27 NSHeight([window_view bounds]) - NSHeight([[window contentView] bounds]);
28 base::scoped_nsobject<TitlebarBackgroundView> titlebar_background_view(
29 [[TitlebarBackgroundView alloc]
30 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height,
31 NSWidth([window_view bounds]), height)]);
32 [titlebar_background_view
33 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
34 [window_view addSubview:titlebar_background_view
35 positioned:NSWindowBelow
36 relativeTo:nil];
37
38 [titlebar_background_view setColor:gfx::SkColorToSRGBNSColor(activeColor)
39 inactiveColor:gfx::SkColorToSRGBNSColor(inactiveColor)];
40 }
41
42 - (void)drawRect:(NSRect)rect {
43 // Only the top corners are rounded. For simplicity, round all 4 corners but
44 // draw the bottom corners outside of the visible bounds.
45 CGFloat cornerRadius = 4.0;
46 NSRect roundedRect = [self bounds];
47 roundedRect.origin.y -= cornerRadius;
48 roundedRect.size.height += cornerRadius;
49 [[NSBezierPath bezierPathWithRoundedRect:roundedRect
50 xRadius:cornerRadius
51 yRadius:cornerRadius] addClip];
52 if ([[self window] isMainWindow] || [[self window] isKeyWindow])
53 [color_ set];
54 else
55 [inactiveColor_ set];
56 NSRectFill(rect);
57 }
58
59 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor {
60 color_.reset([color retain]);
61 inactiveColor_.reset([inactiveColor retain]);
62 }
63
64 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698