Chromium Code Reviews| 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 "ui/gfx/mac/nswindow_frame_controls.h" | 5 #import "ui/gfx/mac/nswindow_frame_controls.h" |
| 6 | 6 |
| 7 #import "base/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
| 8 #import "base/mac/sdk_forward_declarations.h" | 8 #import "base/mac/sdk_forward_declarations.h" |
| 9 #import "skia/ext/skia_utils_mac.h" | |
| 9 #include "ui/gfx/geometry/size.h" | 10 #include "ui/gfx/geometry/size.h" |
| 10 | 11 |
| 12 @implementation TitlebarBackgroundView | |
| 13 | |
| 14 - (void)drawRect:(NSRect)rect { | |
| 15 // Only the top corners are rounded. For simplicity, round all 4 corners but | |
| 16 // draw the bottom corners outside of the visible bounds. | |
| 17 CGFloat cornerRadius = 4.0; | |
| 18 NSRect roundedRect = [self bounds]; | |
| 19 roundedRect.origin.y -= cornerRadius; | |
| 20 roundedRect.size.height += cornerRadius; | |
| 21 [[NSBezierPath bezierPathWithRoundedRect:roundedRect | |
| 22 xRadius:cornerRadius | |
| 23 yRadius:cornerRadius] addClip]; | |
| 24 if ([[self window] isMainWindow] || [[self window] isKeyWindow]) | |
| 25 [color_ set]; | |
| 26 else | |
| 27 [inactiveColor_ set]; | |
| 28 NSRectFill(rect); | |
| 29 } | |
| 30 | |
| 31 - (void)setColor:(NSColor*)color inactiveColor:(NSColor*)inactiveColor { | |
| 32 color_.reset([color retain]); | |
| 33 inactiveColor_.reset([inactiveColor retain]); | |
| 34 } | |
| 35 | |
| 36 @end | |
| 37 | |
| 11 namespace { | 38 namespace { |
| 12 | 39 |
| 13 // The value used to represent an unbounded width or height. | 40 // The value used to represent an unbounded width or height. |
| 14 const int kUnboundedSize = 0; | 41 const int kUnboundedSize = 0; |
| 15 | 42 |
| 16 void SetResizableStyleMask(NSWindow* window, bool resizable) { | 43 void SetResizableStyleMask(NSWindow* window, bool resizable) { |
| 17 NSUInteger style_mask = [window styleMask]; | 44 NSUInteger style_mask = [window styleMask]; |
| 18 if (resizable) | 45 if (resizable) |
| 19 style_mask |= NSResizableWindowMask; | 46 style_mask |= NSResizableWindowMask; |
| 20 else | 47 else |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 80 |
| 54 // Set the window to participate in Lion Fullscreen mode. Setting this flag | 81 // Set the window to participate in Lion Fullscreen mode. Setting this flag |
| 55 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are | 82 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are |
| 56 // only shown for windows that have unbounded size. | 83 // only shown for windows that have unbounded size. |
| 57 if (base::mac::IsOSLionOrLater()) | 84 if (base::mac::IsOSLionOrLater()) |
| 58 SetNSWindowCanFullscreen(window, can_fullscreen); | 85 SetNSWindowCanFullscreen(window, can_fullscreen); |
| 59 | 86 |
| 60 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; | 87 [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; |
| 61 } | 88 } |
| 62 | 89 |
| 90 void AddColoredTitlebarToNSWindow(NSWindow* window, | |
|
tapted
2015/05/06 02:58:29
Can this go in chrome/browser/ui/apps ? I don't th
jackhou1
2015/05/12 05:39:05
Moved to titlebar_background_view.h|mm
| |
| 91 SkColor active_color, | |
| 92 SkColor inactive_color) { | |
| 93 // AppKit only officially supports adding subviews to the window's | |
| 94 // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK | |
| 95 // allows adding an NSTitlebarAccessoryViewController to a window, but the | |
| 96 // view can only be placed above the window control buttons, so we'd have to | |
| 97 // replicate those. | |
| 98 NSView* window_view = [[window contentView] superview]; | |
| 99 CGFloat height = | |
| 100 NSHeight([window_view bounds]) - NSHeight([[window contentView] bounds]); | |
| 101 base::scoped_nsobject<TitlebarBackgroundView> titlebar_background_view( | |
| 102 [[TitlebarBackgroundView alloc] | |
| 103 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height, | |
| 104 NSWidth([window_view bounds]), height)]); | |
| 105 [titlebar_background_view | |
| 106 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | |
| 107 [window_view addSubview:titlebar_background_view | |
| 108 positioned:NSWindowBelow | |
| 109 relativeTo:nil]; | |
| 110 [titlebar_background_view setColor:gfx::SkColorToSRGBNSColor(active_color) | |
| 111 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_color)]; | |
| 112 } | |
| 113 | |
| 63 } // namespace gfx | 114 } // namespace gfx |
| OLD | NEW |