Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Unified Diff: chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm

Issue 916833005: [Mac] Use a custom view to implement colored app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a couple of nits. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cacab46219f9aa2b960632eea8f5d4e513415161 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"
@@ -51,6 +50,8 @@ using extensions::AppWindow;
namespace {
+const CGFloat kTitlebarBackgroundViewPaintHeight = 60.0;
tapted 2015/02/19 03:11:02 nit: comment for this (i.e. why 60 -- does it just
jackhou1 2015/02/19 04:28:58 Done.
+
void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) {
NSWindowCollectionBehavior behavior = [window collectionBehavior];
if (allow_fullscreen)
@@ -208,71 +209,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 +229,33 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
}
- (void)setColor:(NSColor*)color
- inactiveColor:(NSColor*)inactiveColor {
+ inactiveColor:(NSColor*)inactiveColor {
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 +312,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 +332,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];
+ titlebar_background_view_.reset([[TitlebarBackgroundView alloc]
+ initWithFrame:NSMakeRect(0,
+ 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 +789,7 @@ void NativeAppWindowCocoa::WindowWillClose() {
}
void NativeAppWindowCocoa::WindowDidBecomeKey() {
+ [titlebar_background_view_ setNeedsDisplay:YES];
content::RenderWidgetHostView* rwhv =
WebContents()->GetRenderWidgetHostView();
if (rwhv)
@@ -837,6 +807,8 @@ void NativeAppWindowCocoa::WindowDidResignKey() {
if ([NSApp isActive] && ([NSApp keyWindow] == window()))
return;
+ [titlebar_background_view_ setNeedsDisplay:YES];
+
WebContents()->StoreFocus();
content::RenderWidgetHostView* rwhv =
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698