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

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: Address comments. 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 "skia/ext/skia_utils_mac.h"
8
9 @interface TitlebarBackgroundView ()
10 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor;
11 @end
12
13 @implementation TitlebarBackgroundView
14
15 + (void)addToNSWindow:(NSWindow*)window
16 activeColor:(SkColor)activeColor
17 inactiveColor:(SkColor)inactiveColor {
18 // AppKit only officially supports adding subviews to the window's
19 // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK
20 // allows adding an NSTitlebarAccessoryViewController to a window, but the
21 // view can only be placed above the window control buttons, so we'd have to
22 // replicate those.
23 NSView* window_view = [[window contentView] superview];
24 CGFloat height =
25 NSHeight([window_view bounds]) - NSHeight([[window contentView] bounds]);
26 base::scoped_nsobject<TitlebarBackgroundView> titlebar_background_view(
27 [[TitlebarBackgroundView alloc]
28 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height,
29 NSWidth([window_view bounds]), height)]);
30 [titlebar_background_view
31 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
32 [window_view addSubview:titlebar_background_view
33 positioned:NSWindowBelow
34 relativeTo:nil];
35
36 [titlebar_background_view setColor:gfx::SkColorToSRGBNSColor(activeColor)
37 inactiveColor:gfx::SkColorToSRGBNSColor(inactiveColor)];
38 }
39
40 - (void)drawRect:(NSRect)rect {
41 // Only the top corners are rounded. For simplicity, round all 4 corners but
42 // draw the bottom corners outside of the visible bounds.
43 CGFloat cornerRadius = 4.0;
44 NSRect roundedRect = [self bounds];
45 roundedRect.origin.y -= cornerRadius;
46 roundedRect.size.height += cornerRadius;
47 [[NSBezierPath bezierPathWithRoundedRect:roundedRect
48 xRadius:cornerRadius
49 yRadius:cornerRadius] addClip];
50 if ([[self window] isMainWindow] || [[self window] isKeyWindow])
51 [color_ set];
52 else
53 [inactiveColor_ set];
54 NSRectFill(rect);
55 }
56
57 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor {
58 color_.reset([color retain]);
59 inactiveColor_.reset([inactiveColor retain]);
60 }
61
62 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/apps/titlebar_background_view.h ('k') | chrome/browser/ui/test/scoped_fake_nswindow_main_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698