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..219372121594dd39f2732594225b6195d3152545 100644 |
| --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm |
| @@ -127,21 +127,40 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions( |
| } // namespace |
| +@interface NativeAppWindowController (Private) |
|
tapted
2015/02/12 05:56:04
(Private) -> ()
jackhou1
2015/02/13 00:04:33
Done.
|
| +- (void)didChangeActive; |
| +@end |
| + |
| @implementation NativeAppWindowController |
| @synthesize appWindow = appWindow_; |
| +- (void)didChangeActive { |
| + [base::mac::ObjCCastStrict<ShellNSWindow>([self window]) |
| + didChangeActive]; |
| +} |
| + |
| - (void)windowWillClose:(NSNotification*)notification { |
| if (appWindow_) |
| appWindow_->WindowWillClose(); |
| } |
| +- (void)windowDidBecomeMain:(NSNotification*)notification { |
|
tapted
2015/02/12 05:56:04
the FooMain methods should be able to be removed -
jackhou1
2015/02/13 00:04:33
Done.
|
| + [self didChangeActive]; |
| +} |
| + |
| +- (void)windowDidResignMain:(NSNotification*)notification { |
| + [self didChangeActive]; |
| +} |
| + |
| - (void)windowDidBecomeKey:(NSNotification*)notification { |
| + [self didChangeActive]; |
| if (appWindow_) |
| appWindow_->WindowDidBecomeKey(); |
| } |
| - (void)windowDidResignKey:(NSNotification*)notification { |
| + [self didChangeActive]; |
| if (appWindow_) |
| appWindow_->WindowDidResignKey(); |
| } |
| @@ -208,71 +227,28 @@ 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 { |
| +@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 { |
| +- (void)drawRect:(NSRect)rect { |
| [[NSBezierPath bezierPathWithRect:rect] addClip]; |
| [[NSColor clearColor] set]; |
| NSRectFill(rect); |
| // Set up our clip. |
| CGFloat cornerRadius = 4.0; |
| - if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
| - cornerRadius = [view roundedCornerRadius]; |
| - [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
| + [[NSBezierPath bezierPathWithRoundedRect:[self bounds] |
| xRadius:cornerRadius |
| yRadius:cornerRadius] addClip]; |
| - if ([self isMainWindow] || [self isKeyWindow]) |
| + if ([[self window] isMainWindow] || [[self window] isKeyWindow]) |
| [color_ set]; |
| else |
| [inactiveColor_ set]; |
| @@ -287,13 +263,57 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions( |
| @end |
| +// TODO(jamescook): Should these be AppNSWindow to match AppWindow? |
| +// http://crbug.com/344082 |
| +@interface ShellNSWindow : ChromeEventProcessingWindow { |
| + @private |
| + base::scoped_nsobject<TitleBarBackgroundView> titleBarBackgroundView_; |
| +} |
| +- (void)didChangeActive; |
| +- (void)setColor:(NSColor*)color |
| + inactiveColor:(NSColor*)inactiveColor; |
| +@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)didChangeActive { |
| + [titleBarBackgroundView_ setNeedsDisplay:YES]; |
| +} |
| + |
| +- (void)setColor:(NSColor*)color |
| + inactiveColor:(NSColor*)inactiveColor { |
| + if (!titleBarBackgroundView_) { |
| + NSView* windowView = [[self contentView] superview]; |
|
tapted
2015/02/12 05:56:04
Mavericks has (officially) banned the practice of
jackhou1
2015/02/13 00:04:33
Yes, and looking around forums it seems like addin
jackhou1
2015/02/18 04:35:09
Tested this out on 10.10 linking with both 10.6 an
|
| + titleBarBackgroundView_.reset([[TitleBarBackgroundView alloc] |
| + initWithFrame:NSMakeRect(0, |
| + NSMaxY([windowView bounds]) - |
| + 60.0, |
| + NSWidth([windowView bounds]), |
| + 60.0)]); |
| + [titleBarBackgroundView_ |
| + setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| + [windowView addSubview:titleBarBackgroundView_ |
| + positioned:NSWindowBelow |
| + relativeTo:nil]; |
| + } |
| + |
| + [titleBarBackgroundView_ setColor:color |
| + inactiveColor:inactiveColor]; |
| +} |
| + |
| +@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 +370,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 +390,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa( |
| [window setTitle:base::SysUTF8ToNSString(name)]; |
| [[window contentView] setWantsLayer:YES]; |
| if (has_frame_ && has_frame_color_) { |
| - [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) |
| + [base::mac::ObjCCastStrict<ShellNSWindow>(window) |
| setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) |
| inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; |
| } |