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/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 12 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 14 #import "chrome/browser/ui/cocoa/custom_frame_view.h" |
14 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 15 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
15 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 16 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
16 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 17 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
19 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "third_party/skia/include/core/SkRegion.h" | 23 #include "third_party/skia/include/core/SkRegion.h" |
23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 @end | 217 @end |
217 | 218 |
218 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? | 219 // TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow? |
219 // http://crbug.com/344082 | 220 // http://crbug.com/344082 |
220 @interface ShellNSWindow : ChromeEventProcessingWindow | 221 @interface ShellNSWindow : ChromeEventProcessingWindow |
221 @end | 222 @end |
222 @implementation ShellNSWindow | 223 @implementation ShellNSWindow |
223 @end | 224 @end |
224 | 225 |
225 @interface ShellCustomFrameNSWindow : ShellNSWindow | 226 @interface ShellCustomFrameNSWindow : ShellNSWindow |
226 | |
227 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | |
228 | |
229 @end | 227 @end |
230 | 228 |
231 @implementation ShellCustomFrameNSWindow | 229 @implementation ShellCustomFrameNSWindow |
232 | 230 |
233 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 231 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
234 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 232 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
235 [[NSColor clearColor] set]; | 233 [[NSColor clearColor] set]; |
236 NSRectFill(rect); | 234 NSRectFill(rect); |
237 | 235 |
238 // Set up our clip. | 236 // Set up our clip. |
239 CGFloat cornerRadius = 4.0; | 237 CGFloat cornerRadius = 4.0; |
240 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 238 if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
241 cornerRadius = [view roundedCornerRadius]; | 239 cornerRadius = [view roundedCornerRadius]; |
242 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 240 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
243 xRadius:cornerRadius | 241 xRadius:cornerRadius |
244 yRadius:cornerRadius] addClip]; | 242 yRadius:cornerRadius] addClip]; |
245 [[NSColor whiteColor] set]; | 243 [[NSColor whiteColor] set]; |
246 NSRectFill(rect); | 244 NSRectFill(rect); |
247 } | 245 } |
248 | 246 |
249 @end | 247 @end |
250 | 248 |
251 @interface ShellFramelessNSWindow : ShellCustomFrameNSWindow | 249 @interface ShellFramelessNSWindow : ShellNSWindow |
252 | |
253 @end | 250 @end |
254 | 251 |
255 @implementation ShellFramelessNSWindow | 252 @implementation ShellFramelessNSWindow |
256 | 253 |
| 254 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {} |
| 255 |
257 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 256 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
258 styleMask:(NSUInteger)mask { | 257 styleMask:(NSUInteger)mask { |
259 return contentRect; | 258 return contentRect; |
260 } | 259 } |
261 | 260 |
262 + (NSRect)contentRectForFrameRect:(NSRect)frameRect | 261 + (NSRect)contentRectForFrameRect:(NSRect)frameRect |
263 styleMask:(NSUInteger)mask { | 262 styleMask:(NSUInteger)mask { |
264 return frameRect; | 263 return frameRect; |
265 } | 264 } |
266 | 265 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 365 |
367 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( | 366 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( |
368 Profile::FromBrowserContext(app_window_->browser_context()), | 367 Profile::FromBrowserContext(app_window_->browser_context()), |
369 window, | 368 window, |
370 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 369 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
371 NULL)); | 370 NULL)); |
372 } | 371 } |
373 | 372 |
374 NSUInteger NativeAppWindowCocoa::GetWindowStyleMask() const { | 373 NSUInteger NativeAppWindowCocoa::GetWindowStyleMask() const { |
375 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 374 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
376 NSMiniaturizableWindowMask; | 375 NSMiniaturizableWindowMask | |
| 376 NSTexturedBackgroundWindowMask; |
377 if (shows_resize_controls_) | 377 if (shows_resize_controls_) |
378 style_mask |= NSResizableWindowMask; | 378 style_mask |= NSResizableWindowMask; |
379 if (!has_frame_ || | |
380 !CommandLine::ForCurrentProcess()->HasSwitch( | |
381 switches::kAppsUseNativeFrame)) { | |
382 style_mask |= NSTexturedBackgroundWindowMask; | |
383 } | |
384 return style_mask; | 379 return style_mask; |
385 } | 380 } |
386 | 381 |
387 void NativeAppWindowCocoa::InstallView() { | 382 void NativeAppWindowCocoa::InstallView() { |
388 NSView* view = WebContents()->GetNativeView(); | 383 NSView* view = WebContents()->GetNativeView(); |
389 if (has_frame_) { | 384 if (has_frame_) { |
390 [view setFrame:[[window() contentView] bounds]]; | 385 [view setFrame:[[window() contentView] bounds]]; |
391 [[window() contentView] addSubview:view]; | 386 [[window() contentView] addSubview:view]; |
392 if (!shows_fullscreen_controls_) | 387 if (!shows_fullscreen_controls_) |
393 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; | 388 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 } | 947 } |
953 | 948 |
954 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 949 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
955 if (IsRestored(*this)) | 950 if (IsRestored(*this)) |
956 restored_bounds_ = [window() frame]; | 951 restored_bounds_ = [window() frame]; |
957 } | 952 } |
958 | 953 |
959 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 954 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
960 [window() orderOut:window_controller_]; | 955 [window() orderOut:window_controller_]; |
961 } | 956 } |
OLD | NEW |