Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / apps / titlebar_background_view.mm
blob7f0ff7fcedc64366f705c94b1e799dde0f633c09
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.
5 #import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h"
7 #import "skia/ext/skia_utils_mac.h"
9 @interface TitlebarBackgroundView ()
10 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor;
11 @end
13 @implementation TitlebarBackgroundView
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];
36   [titlebar_background_view setColor:gfx::SkColorToSRGBNSColor(activeColor)
37                        inactiveColor:gfx::SkColorToSRGBNSColor(inactiveColor)];
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);
57 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor {
58   color_.reset([color retain]);
59   inactiveColor_.reset([inactiveColor retain]);
62 @end