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" | |
10 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
14 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
15 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 14 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
16 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 15 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
17 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 16 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
18 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
19 #include "content/public/browser/native_web_keyboard_event.h" | 18 #include "content/public/browser/native_web_keyboard_event.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_view.h" | 21 #include "content/public/browser/web_contents_view.h" |
23 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
24 #include "skia/ext/skia_utils_mac.h" | |
25 #include "third_party/skia/include/core/SkRegion.h" | 23 #include "third_party/skia/include/core/SkRegion.h" |
26 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
27 | 25 |
28 // NOTE: State Before Update. | 26 // NOTE: State Before Update. |
29 // | 27 // |
30 // Internal state, such as |is_maximized_|, must be set before the window | 28 // Internal state, such as |is_maximized_|, must be set before the window |
31 // state is changed so that it is accurate when e.g. a resize results in a call | 29 // state is changed so that it is accurate when e.g. a resize results in a call |
32 // to |OnNativeWindowChanged|. | 30 // to |OnNativeWindowChanged|. |
33 | 31 |
34 // NOTE: Maximize and Zoom. | 32 // NOTE: Maximize and Zoom. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 - (CGFloat)roundedCornerRadius; | 216 - (CGFloat)roundedCornerRadius; |
219 @end | 217 @end |
220 | 218 |
221 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? | 219 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? |
222 // http://crbug.com/344082 | 220 // http://crbug.com/344082 |
223 @interface ShellNSWindow : ChromeEventProcessingWindow | 221 @interface ShellNSWindow : ChromeEventProcessingWindow |
224 @end | 222 @end |
225 @implementation ShellNSWindow | 223 @implementation ShellNSWindow |
226 @end | 224 @end |
227 | 225 |
228 @interface ShellCustomFrameNSWindow : ShellNSWindow { | 226 @interface ShellCustomFrameNSWindow : ShellNSWindow |
229 @private | |
230 base::scoped_nsobject<NSColor> color_; | |
231 base::scoped_nsobject<NSColor> inactiveColor_; | |
232 } | |
233 | 227 |
234 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | 228 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; |
235 - (void)setColor:(NSColor*)color | |
236 inactiveColor:(NSColor*)inactiveColor; | |
237 | 229 |
238 @end | 230 @end |
239 | 231 |
240 @implementation ShellCustomFrameNSWindow | 232 @implementation ShellCustomFrameNSWindow |
241 | 233 |
242 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 234 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
243 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 235 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
244 [[NSColor clearColor] set]; | 236 [[NSColor clearColor] set]; |
245 NSRectFill(rect); | 237 NSRectFill(rect); |
246 | 238 |
247 // Set up our clip. | 239 // Set up our clip. |
248 CGFloat cornerRadius = 4.0; | 240 CGFloat cornerRadius = 4.0; |
249 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 241 if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
250 cornerRadius = [view roundedCornerRadius]; | 242 cornerRadius = [view roundedCornerRadius]; |
251 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 243 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
252 xRadius:cornerRadius | 244 xRadius:cornerRadius |
253 yRadius:cornerRadius] addClip]; | 245 yRadius:cornerRadius] addClip]; |
254 if ([self isMainWindow] || [self isKeyWindow]) | 246 [[NSColor whiteColor] set]; |
255 [color_ set]; | |
256 else | |
257 [inactiveColor_ set]; | |
258 NSRectFill(rect); | 247 NSRectFill(rect); |
259 } | 248 } |
260 | 249 |
261 - (void)setColor:(NSColor*)color | |
262 inactiveColor:(NSColor*)inactiveColor { | |
263 color_.reset([color retain]); | |
264 inactiveColor_.reset([inactiveColor retain]); | |
265 } | |
266 | |
267 @end | 250 @end |
268 | 251 |
269 @interface ShellFramelessNSWindow : ShellNSWindow | 252 @interface ShellFramelessNSWindow : ShellCustomFrameNSWindow |
270 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | 253 |
271 @end | 254 @end |
272 | 255 |
273 @implementation ShellFramelessNSWindow | 256 @implementation ShellFramelessNSWindow |
274 | 257 |
275 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | |
276 } | |
277 | |
278 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 258 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
279 styleMask:(NSUInteger)mask { | 259 styleMask:(NSUInteger)mask { |
280 return contentRect; | 260 return contentRect; |
281 } | 261 } |
282 | 262 |
283 + (NSRect)contentRectForFrameRect:(NSRect)frameRect | 263 + (NSRect)contentRectForFrameRect:(NSRect)frameRect |
284 styleMask:(NSUInteger)mask { | 264 styleMask:(NSUInteger)mask { |
285 return frameRect; | 265 return frameRect; |
286 } | 266 } |
287 | 267 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 const AppWindow::CreateParams& params) | 299 const AppWindow::CreateParams& params) |
320 : app_window_(app_window), | 300 : app_window_(app_window), |
321 has_frame_(params.frame == AppWindow::FRAME_CHROME), | 301 has_frame_(params.frame == AppWindow::FRAME_CHROME), |
322 is_hidden_(false), | 302 is_hidden_(false), |
323 is_hidden_with_app_(false), | 303 is_hidden_with_app_(false), |
324 is_maximized_(false), | 304 is_maximized_(false), |
325 is_fullscreen_(false), | 305 is_fullscreen_(false), |
326 is_resizable_(params.resizable), | 306 is_resizable_(params.resizable), |
327 shows_resize_controls_(true), | 307 shows_resize_controls_(true), |
328 shows_fullscreen_controls_(true), | 308 shows_fullscreen_controls_(true), |
329 has_frame_color_(params.has_frame_color), | |
330 active_frame_color_(params.active_frame_color), | |
331 inactive_frame_color_(params.inactive_frame_color), | |
332 attention_request_id_(0) { | 309 attention_request_id_(0) { |
333 Observe(web_contents()); | 310 Observe(web_contents()); |
334 | 311 |
335 base::scoped_nsobject<NSWindow> window; | 312 base::scoped_nsobject<NSWindow> window; |
336 Class window_class; | 313 Class window_class; |
337 if (has_frame_) { | 314 if (has_frame_) { |
338 window_class = has_frame_color_ ? | 315 bool should_use_native_frame = |
339 [ShellCustomFrameNSWindow class] : [ShellNSWindow class]; | 316 CommandLine::ForCurrentProcess()->HasSwitch( |
| 317 switches::kAppsUseNativeFrame); |
| 318 window_class = should_use_native_frame ? |
| 319 [ShellNSWindow class] : [ShellCustomFrameNSWindow class]; |
340 } else { | 320 } else { |
341 window_class = [ShellFramelessNSWindow class]; | 321 window_class = [ShellFramelessNSWindow class]; |
342 } | 322 } |
343 | 323 |
344 // Estimate the initial bounds of the window. Once the frame insets are known, | 324 // Estimate the initial bounds of the window. Once the frame insets are known, |
345 // the window bounds and constraints can be set precisely. | 325 // the window bounds and constraints can be set precisely. |
346 NSRect cocoa_bounds = GfxToCocoaBounds( | 326 NSRect cocoa_bounds = GfxToCocoaBounds( |
347 params.GetInitialWindowBounds(gfx::Insets())); | 327 params.GetInitialWindowBounds(gfx::Insets())); |
348 window.reset([[window_class alloc] | 328 window.reset([[window_class alloc] |
349 initWithContentRect:cocoa_bounds | 329 initWithContentRect:cocoa_bounds |
350 styleMask:GetWindowStyleMask() | 330 styleMask:GetWindowStyleMask() |
351 backing:NSBackingStoreBuffered | 331 backing:NSBackingStoreBuffered |
352 defer:NO]); | 332 defer:NO]); |
353 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; | 333 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; |
354 [[window contentView] cr_setWantsLayer:YES]; | 334 [[window contentView] cr_setWantsLayer:YES]; |
355 if (has_frame_ && has_frame_color_) { | |
356 [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) | |
357 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) | |
358 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; | |
359 } | |
360 | 335 |
361 if (base::mac::IsOSSnowLeopard() && | 336 if (base::mac::IsOSSnowLeopard() && |
362 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 337 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
363 [window setBottomCornerRounded:NO]; | 338 [window setBottomCornerRounded:NO]; |
364 | 339 |
365 if (params.always_on_top) | 340 if (params.always_on_top) |
366 [window setLevel:AlwaysOnTopWindowLevel()]; | 341 [window setLevel:AlwaysOnTopWindowLevel()]; |
367 InitCollectionBehavior(window); | 342 InitCollectionBehavior(window); |
368 | 343 |
369 window_controller_.reset( | 344 window_controller_.reset( |
(...skipping 21 matching lines...) Expand all Loading... |
391 window, | 366 window, |
392 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 367 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
393 NULL)); | 368 NULL)); |
394 } | 369 } |
395 | 370 |
396 NSUInteger NativeAppWindowCocoa::GetWindowStyleMask() const { | 371 NSUInteger NativeAppWindowCocoa::GetWindowStyleMask() const { |
397 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 372 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
398 NSMiniaturizableWindowMask; | 373 NSMiniaturizableWindowMask; |
399 if (shows_resize_controls_) | 374 if (shows_resize_controls_) |
400 style_mask |= NSResizableWindowMask; | 375 style_mask |= NSResizableWindowMask; |
401 if (!has_frame_) | 376 if (!has_frame_ || |
| 377 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 378 switches::kAppsUseNativeFrame)) { |
402 style_mask |= NSTexturedBackgroundWindowMask; | 379 style_mask |= NSTexturedBackgroundWindowMask; |
| 380 } |
403 return style_mask; | 381 return style_mask; |
404 } | 382 } |
405 | 383 |
406 void NativeAppWindowCocoa::InstallView() { | 384 void NativeAppWindowCocoa::InstallView() { |
407 NSView* view = web_contents()->GetView()->GetNativeView(); | 385 NSView* view = web_contents()->GetView()->GetNativeView(); |
408 if (has_frame_) { | 386 if (has_frame_) { |
409 [view setFrame:[[window() contentView] bounds]]; | 387 [view setFrame:[[window() contentView] bounds]]; |
410 [[window() contentView] addSubview:view]; | 388 [[window() contentView] addSubview:view]; |
411 if (!shows_fullscreen_controls_) | 389 if (!shows_fullscreen_controls_) |
412 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; | 390 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 bool NativeAppWindowCocoa::IsFrameless() const { | 717 bool NativeAppWindowCocoa::IsFrameless() const { |
740 return !has_frame_; | 718 return !has_frame_; |
741 } | 719 } |
742 | 720 |
743 bool NativeAppWindowCocoa::HasFrameColor() const { | 721 bool NativeAppWindowCocoa::HasFrameColor() const { |
744 // TODO(benwells): Implement this. | 722 // TODO(benwells): Implement this. |
745 return false; | 723 return false; |
746 } | 724 } |
747 | 725 |
748 SkColor NativeAppWindowCocoa::ActiveFrameColor() const { | 726 SkColor NativeAppWindowCocoa::ActiveFrameColor() const { |
749 return active_frame_color_; | 727 // TODO(benwells): Implement this. |
| 728 return SkColor(); |
750 } | 729 } |
751 | 730 |
752 SkColor NativeAppWindowCocoa::InactiveFrameColor() const { | 731 SkColor NativeAppWindowCocoa::InactiveFrameColor() const { |
753 return inactive_frame_color_; | 732 // TODO(benwells): Implement this. |
| 733 return SkColor(); |
754 } | 734 } |
755 | 735 |
756 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { | 736 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { |
757 if (!has_frame_) | 737 if (!has_frame_) |
758 return gfx::Insets(); | 738 return gfx::Insets(); |
759 | 739 |
760 // Flip the coordinates based on the main screen. | 740 // Flip the coordinates based on the main screen. |
761 NSInteger screen_height = | 741 NSInteger screen_height = |
762 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); | 742 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); |
763 | 743 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 } | 941 } |
962 | 942 |
963 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 943 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
964 if (IsRestored(*this)) | 944 if (IsRestored(*this)) |
965 restored_bounds_ = [window() frame]; | 945 restored_bounds_ = [window() frame]; |
966 } | 946 } |
967 | 947 |
968 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 948 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
969 [window() orderOut:window_controller_]; | 949 [window() orderOut:window_controller_]; |
970 } | 950 } |
OLD | NEW |