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 "apps/app_shim/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/mac/foundation_util.h" |
9 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 13 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 14 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
14 #import "chrome/browser/ui/cocoa/custom_frame_view.h" | 15 #import "chrome/browser/ui/cocoa/custom_frame_view.h" |
15 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 16 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
16 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 17 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
17 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 18 #import "chrome/browser/ui/cocoa/nsview_additions.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" |
| 24 #include "skia/ext/skia_utils_mac.h" |
23 #include "third_party/skia/include/core/SkRegion.h" | 25 #include "third_party/skia/include/core/SkRegion.h" |
24 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
25 | 27 |
26 // NOTE: State Before Update. | 28 // NOTE: State Before Update. |
27 // | 29 // |
28 // Internal state, such as |is_maximized_|, must be set before the window | 30 // Internal state, such as |is_maximized_|, must be set before the window |
29 // state is changed so that it is accurate when e.g. a resize results in a call | 31 // state is changed so that it is accurate when e.g. a resize results in a call |
30 // to |OnNativeWindowChanged|. | 32 // to |OnNativeWindowChanged|. |
31 | 33 |
32 // NOTE: Maximize and Zoom. | 34 // NOTE: Maximize and Zoom. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 - (CGFloat)roundedCornerRadius; | 218 - (CGFloat)roundedCornerRadius; |
217 @end | 219 @end |
218 | 220 |
219 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? | 221 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? |
220 // http://crbug.com/344082 | 222 // http://crbug.com/344082 |
221 @interface ShellNSWindow : ChromeEventProcessingWindow | 223 @interface ShellNSWindow : ChromeEventProcessingWindow |
222 @end | 224 @end |
223 @implementation ShellNSWindow | 225 @implementation ShellNSWindow |
224 @end | 226 @end |
225 | 227 |
226 @interface ShellCustomFrameNSWindow : ShellNSWindow | 228 @interface ShellCustomFrameNSWindow : ShellNSWindow { |
| 229 @private |
| 230 base::scoped_nsobject<NSColor> color_; |
| 231 base::scoped_nsobject<NSColor> inactiveColor_; |
| 232 } |
| 233 |
| 234 - (void)setColor:(NSColor*)color |
| 235 inactiveColor:(NSColor*)inactiveColor; |
| 236 |
227 @end | 237 @end |
228 | 238 |
229 @implementation ShellCustomFrameNSWindow | 239 @implementation ShellCustomFrameNSWindow |
230 | 240 |
231 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 241 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
232 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 242 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
233 [[NSColor clearColor] set]; | 243 [[NSColor clearColor] set]; |
234 NSRectFill(rect); | 244 NSRectFill(rect); |
235 | 245 |
236 // Set up our clip. | 246 // Set up our clip. |
237 CGFloat cornerRadius = 4.0; | 247 CGFloat cornerRadius = 4.0; |
238 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 248 if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
239 cornerRadius = [view roundedCornerRadius]; | 249 cornerRadius = [view roundedCornerRadius]; |
240 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 250 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
241 xRadius:cornerRadius | 251 xRadius:cornerRadius |
242 yRadius:cornerRadius] addClip]; | 252 yRadius:cornerRadius] addClip]; |
243 [[NSColor whiteColor] set]; | 253 if ([self isMainWindow] || [self isKeyWindow]) |
| 254 [color_ set]; |
| 255 else |
| 256 [inactiveColor_ set]; |
244 NSRectFill(rect); | 257 NSRectFill(rect); |
245 } | 258 } |
246 | 259 |
| 260 - (void)setColor:(NSColor*)color |
| 261 inactiveColor:(NSColor*)inactiveColor { |
| 262 color_.reset([color retain]); |
| 263 inactiveColor_.reset([inactiveColor retain]); |
| 264 } |
| 265 |
247 @end | 266 @end |
248 | 267 |
249 @interface ShellFramelessNSWindow : ShellNSWindow | 268 @interface ShellFramelessNSWindow : ShellNSWindow |
250 @end | 269 @end |
251 | 270 |
252 @implementation ShellFramelessNSWindow | 271 @implementation ShellFramelessNSWindow |
253 | 272 |
254 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {} | 273 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {} |
255 | 274 |
256 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 275 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 AppWindow* app_window, | 315 AppWindow* app_window, |
297 const AppWindow::CreateParams& params) | 316 const AppWindow::CreateParams& params) |
298 : app_window_(app_window), | 317 : app_window_(app_window), |
299 has_frame_(params.frame == AppWindow::FRAME_CHROME), | 318 has_frame_(params.frame == AppWindow::FRAME_CHROME), |
300 is_hidden_with_app_(false), | 319 is_hidden_with_app_(false), |
301 is_maximized_(false), | 320 is_maximized_(false), |
302 is_fullscreen_(false), | 321 is_fullscreen_(false), |
303 is_resizable_(params.resizable), | 322 is_resizable_(params.resizable), |
304 shows_resize_controls_(true), | 323 shows_resize_controls_(true), |
305 shows_fullscreen_controls_(true), | 324 shows_fullscreen_controls_(true), |
| 325 has_frame_color_(params.has_frame_color), |
| 326 active_frame_color_(params.active_frame_color), |
| 327 inactive_frame_color_(params.inactive_frame_color), |
306 attention_request_id_(0) { | 328 attention_request_id_(0) { |
307 Observe(WebContents()); | 329 Observe(WebContents()); |
308 | 330 |
309 base::scoped_nsobject<NSWindow> window; | 331 base::scoped_nsobject<NSWindow> window; |
310 Class window_class; | 332 Class window_class; |
311 if (has_frame_) { | 333 if (has_frame_) { |
312 bool should_use_native_frame = | 334 window_class = has_frame_color_ ? |
313 CommandLine::ForCurrentProcess()->HasSwitch( | 335 [ShellCustomFrameNSWindow class] : [ShellNSWindow class]; |
314 switches::kAppsUseNativeFrame); | |
315 window_class = should_use_native_frame ? | |
316 [ShellNSWindow class] : [ShellCustomFrameNSWindow class]; | |
317 } else { | 336 } else { |
318 window_class = [ShellFramelessNSWindow class]; | 337 window_class = [ShellFramelessNSWindow class]; |
319 } | 338 } |
320 | 339 |
321 // Estimate the initial bounds of the window. Once the frame insets are known, | 340 // Estimate the initial bounds of the window. Once the frame insets are known, |
322 // the window bounds and constraints can be set precisely. | 341 // the window bounds and constraints can be set precisely. |
323 NSRect cocoa_bounds = GfxToCocoaBounds( | 342 NSRect cocoa_bounds = GfxToCocoaBounds( |
324 params.GetInitialWindowBounds(gfx::Insets())); | 343 params.GetInitialWindowBounds(gfx::Insets())); |
325 window.reset([[window_class alloc] | 344 window.reset([[window_class alloc] |
326 initWithContentRect:cocoa_bounds | 345 initWithContentRect:cocoa_bounds |
327 styleMask:GetWindowStyleMask() | 346 styleMask:GetWindowStyleMask() |
328 backing:NSBackingStoreBuffered | 347 backing:NSBackingStoreBuffered |
329 defer:NO]); | 348 defer:NO]); |
330 | 349 |
331 std::string name; | 350 std::string name; |
332 const extensions::Extension* extension = app_window_->GetExtension(); | 351 const extensions::Extension* extension = app_window_->GetExtension(); |
333 if (extension) | 352 if (extension) |
334 name = extension->name(); | 353 name = extension->name(); |
335 [window setTitle:base::SysUTF8ToNSString(name)]; | 354 [window setTitle:base::SysUTF8ToNSString(name)]; |
336 [[window contentView] cr_setWantsLayer:YES]; | 355 [[window contentView] cr_setWantsLayer:YES]; |
| 356 if (has_frame_ && has_frame_color_) { |
| 357 [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) |
| 358 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) |
| 359 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; |
| 360 } |
337 | 361 |
338 if (base::mac::IsOSSnowLeopard() && | 362 if (base::mac::IsOSSnowLeopard() && |
339 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 363 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
340 [window setBottomCornerRounded:NO]; | 364 [window setBottomCornerRounded:NO]; |
341 | 365 |
342 if (params.always_on_top) | 366 if (params.always_on_top) |
343 [window setLevel:AlwaysOnTopWindowLevel()]; | 367 [window setLevel:AlwaysOnTopWindowLevel()]; |
344 InitCollectionBehavior(window); | 368 InitCollectionBehavior(window); |
345 | 369 |
346 window_controller_.reset( | 370 window_controller_.reset( |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) { | 730 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) { |
707 if (IsActive()) | 731 if (IsActive()) |
708 WebContents()->RestoreFocus(); | 732 WebContents()->RestoreFocus(); |
709 } | 733 } |
710 | 734 |
711 bool NativeAppWindowCocoa::IsFrameless() const { | 735 bool NativeAppWindowCocoa::IsFrameless() const { |
712 return !has_frame_; | 736 return !has_frame_; |
713 } | 737 } |
714 | 738 |
715 bool NativeAppWindowCocoa::HasFrameColor() const { | 739 bool NativeAppWindowCocoa::HasFrameColor() const { |
716 // TODO(benwells): Implement this. | 740 return has_frame_color_; |
717 return false; | |
718 } | 741 } |
719 | 742 |
720 SkColor NativeAppWindowCocoa::ActiveFrameColor() const { | 743 SkColor NativeAppWindowCocoa::ActiveFrameColor() const { |
721 // TODO(benwells): Implement this. | 744 return active_frame_color_; |
722 return SkColor(); | |
723 } | 745 } |
724 | 746 |
725 SkColor NativeAppWindowCocoa::InactiveFrameColor() const { | 747 SkColor NativeAppWindowCocoa::InactiveFrameColor() const { |
726 // TODO(benwells): Implement this. | 748 return inactive_frame_color_; |
727 return SkColor(); | |
728 } | 749 } |
729 | 750 |
730 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { | 751 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { |
731 if (!has_frame_) | 752 if (!has_frame_) |
732 return gfx::Insets(); | 753 return gfx::Insets(); |
733 | 754 |
734 // Flip the coordinates based on the main screen. | 755 // Flip the coordinates based on the main screen. |
735 NSInteger screen_height = | 756 NSInteger screen_height = |
736 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); | 757 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); |
737 | 758 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 is_resizable_ && !size_constraints_.HasFixedSize(); | 932 is_resizable_ && !size_constraints_.HasFixedSize(); |
912 shows_fullscreen_controls_ = | 933 shows_fullscreen_controls_ = |
913 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; | 934 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; |
914 | 935 |
915 if (!is_fullscreen_) { | 936 if (!is_fullscreen_) { |
916 [window() setStyleMask:GetWindowStyleMask()]; | 937 [window() setStyleMask:GetWindowStyleMask()]; |
917 | 938 |
918 // Set the window to participate in Lion Fullscreen mode. Setting this flag | 939 // Set the window to participate in Lion Fullscreen mode. Setting this flag |
919 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are | 940 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are |
920 // only shown for apps that have unbounded size. | 941 // only shown for apps that have unbounded size. |
921 SetFullScreenCollectionBehavior(window(), shows_fullscreen_controls_); | 942 if (base::mac::IsOSLionOrLater()) |
| 943 SetFullScreenCollectionBehavior(window(), shows_fullscreen_controls_); |
922 } | 944 } |
923 | 945 |
924 if (has_frame_) { | 946 if (has_frame_) { |
925 [window() setShowsResizeIndicator:shows_resize_controls_]; | 947 [window() setShowsResizeIndicator:shows_resize_controls_]; |
926 [[window() standardWindowButton:NSWindowZoomButton] | 948 [[window() standardWindowButton:NSWindowZoomButton] |
927 setEnabled:shows_fullscreen_controls_]; | 949 setEnabled:shows_fullscreen_controls_]; |
928 } | 950 } |
929 } | 951 } |
930 | 952 |
931 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { | 953 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { |
(...skipping 15 matching lines...) Expand all Loading... |
947 } | 969 } |
948 | 970 |
949 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 971 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
950 if (IsRestored(*this)) | 972 if (IsRestored(*this)) |
951 restored_bounds_ = [window() frame]; | 973 restored_bounds_ = [window() frame]; |
952 } | 974 } |
953 | 975 |
954 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 976 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
955 [window() orderOut:window_controller_]; | 977 [window() orderOut:window_controller_]; |
956 } | 978 } |
OLD | NEW |