| OLD | NEW |
| 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" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 - (BOOL)handledByExtensionCommand:(NSEvent*)event | 193 - (BOOL)handledByExtensionCommand:(NSEvent*)event |
| 194 priority:(ui::AcceleratorManager::HandlerPriority)priority { | 194 priority:(ui::AcceleratorManager::HandlerPriority)priority { |
| 195 if (appWindow_) | 195 if (appWindow_) |
| 196 return appWindow_->HandledByExtensionCommand(event, priority); | 196 return appWindow_->HandledByExtensionCommand(event, priority); |
| 197 return NO; | 197 return NO; |
| 198 } | 198 } |
| 199 | 199 |
| 200 @end | 200 @end |
| 201 | 201 |
| 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 | 202 @interface AppNSWindow : ChromeEventProcessingWindow |
| 242 @end | 203 @end |
| 243 | 204 |
| 244 @implementation AppNSWindow | 205 @implementation AppNSWindow |
| 245 | 206 |
| 246 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen | 207 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen |
| 247 // in menus, Expose, etc. | 208 // in menus, Expose, etc. |
| 248 - (BOOL)_isTitleHidden { | 209 - (BOOL)_isTitleHidden { |
| 249 return YES; | 210 return YES; |
| 250 } | 211 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 backing:NSBackingStoreBuffered | 286 backing:NSBackingStoreBuffered |
| 326 defer:NO]); | 287 defer:NO]); |
| 327 | 288 |
| 328 std::string name; | 289 std::string name; |
| 329 const extensions::Extension* extension = app_window_->GetExtension(); | 290 const extensions::Extension* extension = app_window_->GetExtension(); |
| 330 if (extension) | 291 if (extension) |
| 331 name = extension->name(); | 292 name = extension->name(); |
| 332 [window setTitle:base::SysUTF8ToNSString(name)]; | 293 [window setTitle:base::SysUTF8ToNSString(name)]; |
| 333 [[window contentView] setWantsLayer:YES]; | 294 [[window contentView] setWantsLayer:YES]; |
| 334 if (has_frame_ && has_frame_color_) { | 295 if (has_frame_ && has_frame_color_) { |
| 335 // AppKit only officially supports adding subviews to the window's | 296 gfx::AddColoredTitlebarToNSWindow(window, active_frame_color_, |
| 336 // contentView and not its superview (an NSNextStepFrame). The 10.10 SDK | 297 inactive_frame_color_); |
| 337 // allows adding an NSTitlebarAccessoryViewController to a window, but the | |
| 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 } | 298 } |
| 355 | 299 |
| 356 if (base::mac::IsOSSnowLeopard() && | 300 if (base::mac::IsOSSnowLeopard() && |
| 357 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 301 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 358 [window setBottomCornerRounded:NO]; | 302 [window setBottomCornerRounded:NO]; |
| 359 | 303 |
| 360 if (params.always_on_top) | 304 if (params.always_on_top) |
| 361 [window setLevel:AlwaysOnTopWindowLevel()]; | 305 [window setLevel:AlwaysOnTopWindowLevel()]; |
| 362 InitCollectionBehavior(window); | 306 InitCollectionBehavior(window); |
| 363 | 307 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 NOTIMPLEMENTED(); | 730 NOTIMPLEMENTED(); |
| 787 } | 731 } |
| 788 | 732 |
| 789 void NativeAppWindowCocoa::WindowWillClose() { | 733 void NativeAppWindowCocoa::WindowWillClose() { |
| 790 [window_controller_ setAppWindow:NULL]; | 734 [window_controller_ setAppWindow:NULL]; |
| 791 app_window_->OnNativeWindowChanged(); | 735 app_window_->OnNativeWindowChanged(); |
| 792 app_window_->OnNativeClose(); | 736 app_window_->OnNativeClose(); |
| 793 } | 737 } |
| 794 | 738 |
| 795 void NativeAppWindowCocoa::WindowDidBecomeKey() { | 739 void NativeAppWindowCocoa::WindowDidBecomeKey() { |
| 796 [titlebar_background_view_ setNeedsDisplay:YES]; | |
| 797 content::RenderWidgetHostView* rwhv = | 740 content::RenderWidgetHostView* rwhv = |
| 798 WebContents()->GetRenderWidgetHostView(); | 741 WebContents()->GetRenderWidgetHostView(); |
| 799 if (rwhv) | 742 if (rwhv) |
| 800 rwhv->SetActive(true); | 743 rwhv->SetActive(true); |
| 801 app_window_->OnNativeWindowActivated(); | 744 app_window_->OnNativeWindowActivated(); |
| 802 | 745 |
| 803 WebContents()->RestoreFocus(); | 746 WebContents()->RestoreFocus(); |
| 804 } | 747 } |
| 805 | 748 |
| 806 void NativeAppWindowCocoa::WindowDidResignKey() { | 749 void NativeAppWindowCocoa::WindowDidResignKey() { |
| 807 // If our app is still active and we're still the key window, ignore this | 750 // If our app is still active and we're still the key window, ignore this |
| 808 // message, since it just means that a menu extra (on the "system status bar") | 751 // message, since it just means that a menu extra (on the "system status bar") |
| 809 // was activated; we'll get another |-windowDidResignKey| if we ever really | 752 // was activated; we'll get another |-windowDidResignKey| if we ever really |
| 810 // lose key window status. | 753 // lose key window status. |
| 811 if ([NSApp isActive] && ([NSApp keyWindow] == window())) | 754 if ([NSApp isActive] && ([NSApp keyWindow] == window())) |
| 812 return; | 755 return; |
| 813 | 756 |
| 814 [titlebar_background_view_ setNeedsDisplay:YES]; | |
| 815 | |
| 816 WebContents()->StoreFocus(); | 757 WebContents()->StoreFocus(); |
| 817 | 758 |
| 818 content::RenderWidgetHostView* rwhv = | 759 content::RenderWidgetHostView* rwhv = |
| 819 WebContents()->GetRenderWidgetHostView(); | 760 WebContents()->GetRenderWidgetHostView(); |
| 820 if (rwhv) | 761 if (rwhv) |
| 821 rwhv->SetActive(false); | 762 rwhv->SetActive(false); |
| 822 } | 763 } |
| 823 | 764 |
| 824 void NativeAppWindowCocoa::WindowDidFinishResize() { | 765 void NativeAppWindowCocoa::WindowDidFinishResize() { |
| 825 // Update |is_maximized_| if needed: | 766 // Update |is_maximized_| if needed: |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 894 } |
| 954 | 895 |
| 955 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 896 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
| 956 if (IsRestored(*this)) | 897 if (IsRestored(*this)) |
| 957 restored_bounds_ = [window() frame]; | 898 restored_bounds_ = [window() frame]; |
| 958 } | 899 } |
| 959 | 900 |
| 960 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 901 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
| 961 [window() orderOut:window_controller_]; | 902 [window() orderOut:window_controller_]; |
| 962 } | 903 } |
| OLD | NEW |