| Index: chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
|
| index cd978fb1db12e2cb354d6576e75c2fb97257a1b4..f8b10ce1a3c43f5e08bade829a1d99f861b27037 100644
|
| --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
|
| +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
|
| @@ -13,7 +13,6 @@
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/cocoa/browser_window_utils.h"
|
| #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
|
| -#import "chrome/browser/ui/cocoa/custom_frame_view.h"
|
| #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h"
|
| #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
|
| #include "chrome/common/chrome_switches.h"
|
| @@ -208,71 +207,29 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
|
|
|
| @end
|
|
|
| -// This is really a method on NSGrayFrame, so it should only be called on the
|
| -// view passed into -[NSWindow drawCustomFrameRect:forView:].
|
| -@interface NSView (PrivateMethods)
|
| -- (CGFloat)roundedCornerRadius;
|
| -@end
|
| -
|
| -// TODO(jamescook): Should these be AppNSWindow to match AppWindow?
|
| -// http://crbug.com/344082
|
| -@interface ShellNSWindow : ChromeEventProcessingWindow
|
| -@end
|
| -@implementation ShellNSWindow
|
| -
|
| -// Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen
|
| -// in menus, Expose, etc.
|
| -- (BOOL)_isTitleHidden {
|
| - return YES;
|
| -}
|
| -
|
| -- (void)drawCustomFrameRect:(NSRect)frameRect forView:(NSView*)view {
|
| - // Make the background color of the content area white. We can't just call
|
| - // -setBackgroundColor as that causes the title bar to be drawn in a solid
|
| - // color.
|
| - NSRect rect = [self contentRectForFrameRect:frameRect];
|
| - [[NSColor whiteColor] set];
|
| - NSRectFill(rect);
|
| -
|
| - // Draw the native title bar. We remove the content area since the native
|
| - // implementation draws a gray background.
|
| - rect.origin.y = NSMaxY(rect);
|
| - rect.size.height = CGFLOAT_MAX;
|
| - rect = NSIntersectionRect(rect, frameRect);
|
| -
|
| - [NSBezierPath clipRect:rect];
|
| - [super drawCustomFrameRect:frameRect
|
| - forView:view];
|
| -}
|
| -
|
| -@end
|
| -
|
| -@interface ShellCustomFrameNSWindow : ShellNSWindow {
|
| +// A view that paints a solid color. Used to change the title bar background.
|
| +@interface TitlebarBackgroundView : NSView {
|
| @private
|
| base::scoped_nsobject<NSColor> color_;
|
| base::scoped_nsobject<NSColor> inactiveColor_;
|
| }
|
| -
|
| - (void)setColor:(NSColor*)color
|
| inactiveColor:(NSColor*)inactiveColor;
|
| -
|
| @end
|
|
|
| -@implementation ShellCustomFrameNSWindow
|
| +@implementation TitlebarBackgroundView
|
|
|
| -- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
|
| - [[NSBezierPath bezierPathWithRect:rect] addClip];
|
| - [[NSColor clearColor] set];
|
| - NSRectFill(rect);
|
| -
|
| - // Set up our clip.
|
| +- (void)drawRect:(NSRect)rect {
|
| + // Only the top corners are rounded. For simplicity, round all 4 corners but
|
| + // draw the bottom corners outside of the visible bounds.
|
| CGFloat cornerRadius = 4.0;
|
| - if ([view respondsToSelector:@selector(roundedCornerRadius)])
|
| - cornerRadius = [view roundedCornerRadius];
|
| - [[NSBezierPath bezierPathWithRoundedRect:[view bounds]
|
| + NSRect roundedRect = [self bounds];
|
| + roundedRect.origin.y -= cornerRadius;
|
| + roundedRect.size.height += cornerRadius;
|
| + [[NSBezierPath bezierPathWithRoundedRect:roundedRect
|
| xRadius:cornerRadius
|
| yRadius:cornerRadius] addClip];
|
| - if ([self isMainWindow] || [self isKeyWindow])
|
| + if ([[self window] isMainWindow] || [[self window] isKeyWindow])
|
| [color_ set];
|
| else
|
| [inactiveColor_ set];
|
| @@ -287,13 +244,26 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
|
|
|
| @end
|
|
|
| +// TODO(jamescook): Should these be AppNSWindow to match AppWindow?
|
| +// http://crbug.com/344082
|
| +@interface ShellNSWindow : ChromeEventProcessingWindow
|
| +@end
|
| +
|
| +@implementation ShellNSWindow
|
| +
|
| +// Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen
|
| +// in menus, Expose, etc.
|
| +- (BOOL)_isTitleHidden {
|
| + return YES;
|
| +}
|
| +
|
| +@end
|
| +
|
| @interface ShellFramelessNSWindow : ShellNSWindow
|
| @end
|
|
|
| @implementation ShellFramelessNSWindow
|
|
|
| -- (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {}
|
| -
|
| + (NSRect)frameRectForContentRect:(NSRect)contentRect
|
| styleMask:(NSUInteger)mask {
|
| return contentRect;
|
| @@ -350,13 +320,8 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
|
| Observe(WebContents());
|
|
|
| base::scoped_nsobject<NSWindow> window;
|
| - Class window_class;
|
| - if (has_frame_) {
|
| - window_class = has_frame_color_ ?
|
| - [ShellCustomFrameNSWindow class] : [ShellNSWindow class];
|
| - } else {
|
| - window_class = [ShellFramelessNSWindow class];
|
| - }
|
| + Class window_class = has_frame_ ?
|
| + [ShellNSWindow class] : [ShellFramelessNSWindow class];
|
|
|
| // Estimate the initial bounds of the window. Once the frame insets are known,
|
| // the window bounds and constraints can be set precisely.
|
| @@ -375,7 +340,23 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
|
| [window setTitle:base::SysUTF8ToNSString(name)];
|
| [[window contentView] setWantsLayer:YES];
|
| if (has_frame_ && has_frame_color_) {
|
| - [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window)
|
| + // AppKit only officially supports adding subviews to the window's
|
| + // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK
|
| + // allows adding an NSTitlebarAccessoryViewController to a window, but the
|
| + // view can only be placed above the window control buttons, so we'd have to
|
| + // replicate those.
|
| + NSView* window_view = [[window contentView] superview];
|
| + CGFloat height = NSHeight([window_view bounds]) -
|
| + NSHeight([[window contentView] bounds]);
|
| + titlebar_background_view_.reset([[TitlebarBackgroundView alloc]
|
| + initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height,
|
| + NSWidth([window_view bounds]), height)]);
|
| + [titlebar_background_view_
|
| + setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
|
| + [window_view addSubview:titlebar_background_view_
|
| + positioned:NSWindowBelow
|
| + relativeTo:nil];
|
| + [titlebar_background_view_
|
| setColor:gfx::SkColorToSRGBNSColor(active_frame_color_)
|
| inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)];
|
| }
|
| @@ -820,6 +801,7 @@ void NativeAppWindowCocoa::WindowWillClose() {
|
| }
|
|
|
| void NativeAppWindowCocoa::WindowDidBecomeKey() {
|
| + [titlebar_background_view_ setNeedsDisplay:YES];
|
| content::RenderWidgetHostView* rwhv =
|
| WebContents()->GetRenderWidgetHostView();
|
| if (rwhv)
|
| @@ -837,6 +819,8 @@ void NativeAppWindowCocoa::WindowDidResignKey() {
|
| if ([NSApp isActive] && ([NSApp keyWindow] == window()))
|
| return;
|
|
|
| + [titlebar_background_view_ setNeedsDisplay:YES];
|
| +
|
| WebContents()->StoreFocus();
|
|
|
| content::RenderWidgetHostView* rwhv =
|
|
|