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

Side by Side 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: Address comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" 12 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #import "chrome/browser/ui/cocoa/apps/titlebar_background_view.h"
14 #include "chrome/browser/ui/cocoa/browser_window_utils.h" 15 #include "chrome/browser/ui/cocoa/browser_window_utils.h"
15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" 16 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
16 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" 17 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h"
17 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" 18 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "content/public/browser/native_web_keyboard_event.h" 20 #include "content/public/browser/native_web_keyboard_event.h"
20 #include "content/public/browser/render_widget_host_view.h" 21 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
23 #include "skia/ext/skia_utils_mac.h" 24 #include "skia/ext/skia_utils_mac.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 193
193 - (BOOL)handledByExtensionCommand:(NSEvent*)event 194 - (BOOL)handledByExtensionCommand:(NSEvent*)event
194 priority:(ui::AcceleratorManager::HandlerPriority)priority { 195 priority:(ui::AcceleratorManager::HandlerPriority)priority {
195 if (appWindow_) 196 if (appWindow_)
196 return appWindow_->HandledByExtensionCommand(event, priority); 197 return appWindow_->HandledByExtensionCommand(event, priority);
197 return NO; 198 return NO;
198 } 199 }
199 200
200 @end 201 @end
201 202
202 // A view that paints a solid color. Used to change the title bar background.
203 @interface TitlebarBackgroundView : NSView {
204 @private
205 base::scoped_nsobject<NSColor> color_;
206 base::scoped_nsobject<NSColor> inactiveColor_;
207 }
208 - (void)setColor:(NSColor*)color
209 inactiveColor:(NSColor*)inactiveColor;
210 @end
211
212 @implementation TitlebarBackgroundView
213
214 - (void)drawRect:(NSRect)rect {
215 // Only the top corners are rounded. For simplicity, round all 4 corners but
216 // draw the bottom corners outside of the visible bounds.
217 CGFloat cornerRadius = 4.0;
218 NSRect roundedRect = [self bounds];
219 roundedRect.origin.y -= cornerRadius;
220 roundedRect.size.height += cornerRadius;
221 [[NSBezierPath bezierPathWithRoundedRect:roundedRect
222 xRadius:cornerRadius
223 yRadius:cornerRadius] addClip];
224 if ([[self window] isMainWindow] || [[self window] isKeyWindow])
225 [color_ set];
226 else
227 [inactiveColor_ set];
228 NSRectFill(rect);
229 }
230
231 - (void)setColor:(NSColor*)color
232 inactiveColor:(NSColor*)inactiveColor {
233 color_.reset([color retain]);
234 inactiveColor_.reset([inactiveColor retain]);
235 }
236
237 @end
238
239 // TODO(jamescook): Should these be AppNSWindow to match AppWindow?
240 // http://crbug.com/344082
241 @interface AppNSWindow : ChromeEventProcessingWindow 203 @interface AppNSWindow : ChromeEventProcessingWindow
242 @end 204 @end
243 205
244 @implementation AppNSWindow 206 @implementation AppNSWindow
245 207
246 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen 208 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen
247 // in menus, Expose, etc. 209 // in menus, Expose, etc.
248 - (BOOL)_isTitleHidden { 210 - (BOOL)_isTitleHidden {
249 return YES; 211 return YES;
250 } 212 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 backing:NSBackingStoreBuffered 287 backing:NSBackingStoreBuffered
326 defer:NO]); 288 defer:NO]);
327 289
328 std::string name; 290 std::string name;
329 const extensions::Extension* extension = app_window_->GetExtension(); 291 const extensions::Extension* extension = app_window_->GetExtension();
330 if (extension) 292 if (extension)
331 name = extension->name(); 293 name = extension->name();
332 [window setTitle:base::SysUTF8ToNSString(name)]; 294 [window setTitle:base::SysUTF8ToNSString(name)];
333 [[window contentView] setWantsLayer:YES]; 295 [[window contentView] setWantsLayer:YES];
334 if (has_frame_ && has_frame_color_) { 296 if (has_frame_ && has_frame_color_) {
335 // AppKit only officially supports adding subviews to the window's 297 [TitlebarBackgroundView addToNSWindow:window
336 // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK 298 activeColor:active_frame_color_
337 // allows adding an NSTitlebarAccessoryViewController to a window, but the 299 inactiveColor:inactive_frame_color_];
338 // view can only be placed above the window control buttons, so we'd have to
339 // replicate those.
340 NSView* window_view = [[window contentView] superview];
341 CGFloat height = NSHeight([window_view bounds]) -
342 NSHeight([[window contentView] bounds]);
343 titlebar_background_view_.reset([[TitlebarBackgroundView alloc]
344 initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds]) - height,
345 NSWidth([window_view bounds]), height)]);
346 [titlebar_background_view_
347 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
348 [window_view addSubview:titlebar_background_view_
349 positioned:NSWindowBelow
350 relativeTo:nil];
351 [titlebar_background_view_
352 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_)
353 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)];
354 } 300 }
355 301
356 if (base::mac::IsOSSnowLeopard() && 302 if (base::mac::IsOSSnowLeopard() &&
357 [window respondsToSelector:@selector(setBottomCornerRounded:)]) 303 [window respondsToSelector:@selector(setBottomCornerRounded:)])
358 [window setBottomCornerRounded:NO]; 304 [window setBottomCornerRounded:NO];
359 305
360 if (params.always_on_top) 306 if (params.always_on_top)
361 [window setLevel:AlwaysOnTopWindowLevel()]; 307 [window setLevel:AlwaysOnTopWindowLevel()];
362 InitCollectionBehavior(window); 308 InitCollectionBehavior(window);
363 309
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 NOTIMPLEMENTED(); 727 NOTIMPLEMENTED();
782 } 728 }
783 729
784 void NativeAppWindowCocoa::WindowWillClose() { 730 void NativeAppWindowCocoa::WindowWillClose() {
785 [window_controller_ setAppWindow:NULL]; 731 [window_controller_ setAppWindow:NULL];
786 app_window_->OnNativeWindowChanged(); 732 app_window_->OnNativeWindowChanged();
787 app_window_->OnNativeClose(); 733 app_window_->OnNativeClose();
788 } 734 }
789 735
790 void NativeAppWindowCocoa::WindowDidBecomeKey() { 736 void NativeAppWindowCocoa::WindowDidBecomeKey() {
791 [titlebar_background_view_ setNeedsDisplay:YES];
792 content::RenderWidgetHostView* rwhv = 737 content::RenderWidgetHostView* rwhv =
793 WebContents()->GetRenderWidgetHostView(); 738 WebContents()->GetRenderWidgetHostView();
794 if (rwhv) 739 if (rwhv)
795 rwhv->SetActive(true); 740 rwhv->SetActive(true);
796 app_window_->OnNativeWindowActivated(); 741 app_window_->OnNativeWindowActivated();
797 742
798 WebContents()->RestoreFocus(); 743 WebContents()->RestoreFocus();
799 } 744 }
800 745
801 void NativeAppWindowCocoa::WindowDidResignKey() { 746 void NativeAppWindowCocoa::WindowDidResignKey() {
802 // If our app is still active and we're still the key window, ignore this 747 // If our app is still active and we're still the key window, ignore this
803 // message, since it just means that a menu extra (on the "system status bar") 748 // message, since it just means that a menu extra (on the "system status bar")
804 // was activated; we'll get another |-windowDidResignKey| if we ever really 749 // was activated; we'll get another |-windowDidResignKey| if we ever really
805 // lose key window status. 750 // lose key window status.
806 if ([NSApp isActive] && ([NSApp keyWindow] == window())) 751 if ([NSApp isActive] && ([NSApp keyWindow] == window()))
807 return; 752 return;
808 753
809 [titlebar_background_view_ setNeedsDisplay:YES];
810
811 WebContents()->StoreFocus(); 754 WebContents()->StoreFocus();
812 755
813 content::RenderWidgetHostView* rwhv = 756 content::RenderWidgetHostView* rwhv =
814 WebContents()->GetRenderWidgetHostView(); 757 WebContents()->GetRenderWidgetHostView();
815 if (rwhv) 758 if (rwhv)
816 rwhv->SetActive(false); 759 rwhv->SetActive(false);
817 } 760 }
818 761
819 void NativeAppWindowCocoa::WindowDidFinishResize() { 762 void NativeAppWindowCocoa::WindowDidFinishResize() {
820 // Update |is_maximized_| if needed: 763 // Update |is_maximized_| if needed:
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 893 }
951 894
952 void NativeAppWindowCocoa::UpdateRestoredBounds() { 895 void NativeAppWindowCocoa::UpdateRestoredBounds() {
953 if (IsRestored(*this)) 896 if (IsRestored(*this))
954 restored_bounds_ = [window() frame]; 897 restored_bounds_ = [window() frame];
955 } 898 }
956 899
957 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { 900 void NativeAppWindowCocoa::HideWithoutMarkingHidden() {
958 [window() orderOut:window_controller_]; 901 [window() orderOut:window_controller_];
959 } 902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698