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

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

Issue 1053303003: [MacViews] Implement colored window frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed a few things. Created 5 years, 7 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
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 e823f1903b4ef27fc5c72236a2a54173c97dc7aa..1d3c9f4dff8470e7e6f120c83c5904657426cde3 100644
--- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
@@ -11,6 +11,7 @@
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
#include "chrome/browser/profiles/profile.h"
+#import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h"
#include "chrome/browser/ui/cocoa/browser_window_utils.h"
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h"
@@ -199,45 +200,6 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
@end
-// 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 TitlebarBackgroundView
-
-- (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;
- NSRect roundedRect = [self bounds];
- roundedRect.origin.y -= cornerRadius;
- roundedRect.size.height += cornerRadius;
- [[NSBezierPath bezierPathWithRoundedRect:roundedRect
- xRadius:cornerRadius
- yRadius:cornerRadius] addClip];
- if ([[self window] isMainWindow] || [[self window] isKeyWindow])
- [color_ set];
- else
- [inactiveColor_ set];
- NSRectFill(rect);
-}
-
-- (void)setColor:(NSColor*)color
- 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 AppNSWindow : ChromeEventProcessingWindow
@end
@@ -332,25 +294,9 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
[window setTitle:base::SysUTF8ToNSString(name)];
[[window contentView] setWantsLayer:YES];
if (has_frame_ && has_frame_color_) {
- // 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_)];
+ [TitlebarBackgroundView addToNSWindow:window
+ activeColor:active_frame_color_
+ inactiveColor:inactive_frame_color_];
}
if (base::mac::IsOSSnowLeopard() &&
@@ -788,7 +734,6 @@ void NativeAppWindowCocoa::WindowWillClose() {
}
void NativeAppWindowCocoa::WindowDidBecomeKey() {
- [titlebar_background_view_ setNeedsDisplay:YES];
tapted 2015/05/12 06:15:43 why isn't this needed any more (also in *Resign)
jackhou1 2015/05/14 02:59:13 I think it was redundant. The -[NSView drawRect:]
tapted 2015/05/14 04:23:50 So is something in NSWindow already setting setNee
jackhou1 2015/05/14 06:20:40 Yeah, it happens whenever the window changes focus
content::RenderWidgetHostView* rwhv =
WebContents()->GetRenderWidgetHostView();
if (rwhv)
@@ -806,8 +751,6 @@ void NativeAppWindowCocoa::WindowDidResignKey() {
if ([NSApp isActive] && ([NSApp keyWindow] == window()))
return;
- [titlebar_background_view_ setNeedsDisplay:YES];
-
WebContents()->StoreFocus();
content::RenderWidgetHostView* rwhv =

Powered by Google App Engine
This is Rietveld 408576698