Chromium Code Reviews| 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..9dc6c7638b7b25c33ded1254aefdf6470d72fe8d 100644 |
| --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm |
| @@ -51,6 +51,8 @@ using extensions::AppWindow; |
| namespace { |
| +const CGFloat kTitlebarBackgroundViewPaintHeight = 60.0; |
| + |
| void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) { |
| NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
| if (allow_fullscreen) |
| @@ -208,71 +210,19 @@ 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 { |
| - @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]; |
| @@ -280,20 +230,33 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions( |
| } |
| - (void)setColor:(NSColor*)color |
| - inactiveColor:(NSColor*)inactiveColor { |
| + inactiveColor:(NSColor*)inactiveColor { |
|
tapted
2015/02/19 03:11:02
nit: 4 space indent
jackhou1
2015/02/19 04:28:58
Done.
|
| color_.reset([color retain]); |
| inactiveColor_.reset([inactiveColor retain]); |
| } |
| @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 +313,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 +333,19 @@ NativeAppWindowCocoa::NativeAppWindowCocoa( |
| [window setTitle:base::SysUTF8ToNSString(name)]; |
| [[window contentView] setWantsLayer:YES]; |
| if (has_frame_ && has_frame_color_) { |
| - [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) |
| + NSView* window_view = [[window contentView] superview]; |
|
tapted
2015/02/19 03:11:02
can you add a comment here? Something to the effec
tapted
2015/02/19 03:11:02
nit: window_view -> frame_view ?
jackhou1
2015/02/19 04:28:58
Done.
jackhou1
2015/02/19 04:28:58
Done.
|
| + titlebar_background_view_.reset([[TitlebarBackgroundView alloc] |
| + initWithFrame:NSMakeRect(0, |
|
tapted
2015/02/19 03:11:02
since it's autoresized, can you just pass 0 for th
jackhou1
2015/02/19 04:28:58
Doesn't seem to work.
|
| + NSMaxY([window_view bounds]) - |
| + kTitlebarBackgroundViewPaintHeight, |
| + NSWidth([window_view bounds]), |
| + kTitlebarBackgroundViewPaintHeight)]); |
| + [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 +790,7 @@ void NativeAppWindowCocoa::WindowWillClose() { |
| } |
| void NativeAppWindowCocoa::WindowDidBecomeKey() { |
| + [titlebar_background_view_ setNeedsDisplay:YES]; |
| content::RenderWidgetHostView* rwhv = |
| WebContents()->GetRenderWidgetHostView(); |
| if (rwhv) |
| @@ -837,6 +808,8 @@ void NativeAppWindowCocoa::WindowDidResignKey() { |
| if ([NSApp isActive] && ([NSApp keyWindow] == window())) |
| return; |
| + [titlebar_background_view_ setNeedsDisplay:YES]; |
| + |
| WebContents()->StoreFocus(); |
| content::RenderWidgetHostView* rwhv = |