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