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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 using extensions::AppWindow; | 45 using extensions::AppWindow; |
46 | 46 |
47 @interface NSWindow (NSPrivateApis) | 47 @interface NSWindow (NSPrivateApis) |
48 - (void)setBottomCornerRounded:(BOOL)rounded; | 48 - (void)setBottomCornerRounded:(BOOL)rounded; |
49 - (BOOL)_isTitleHidden; | 49 - (BOOL)_isTitleHidden; |
50 @end | 50 @end |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { | |
55 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
56 if (always_visible) | |
57 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; | |
58 else | |
59 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; | |
60 [window setCollectionBehavior:behavior]; | |
61 } | |
62 | |
63 void InitCollectionBehavior(NSWindow* window) { | |
64 // Since always-on-top windows have a higher window level | |
65 // than NSNormalWindowLevel, they will default to | |
66 // NSWindowCollectionBehaviorTransient. Set the value | |
67 // explicitly here to match normal windows. | |
68 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
69 behavior |= NSWindowCollectionBehaviorManaged; | |
70 [window setCollectionBehavior:behavior]; | |
71 } | |
72 | |
73 // Returns the level for windows that are configured to be always on top. | |
74 // This is not a constant because NSFloatingWindowLevel is a macro defined | |
75 // as a function call. | |
76 NSInteger AlwaysOnTopWindowLevel() { | |
77 return NSFloatingWindowLevel; | |
78 } | |
79 | |
80 NSRect GfxToCocoaBounds(gfx::Rect bounds) { | 54 NSRect GfxToCocoaBounds(gfx::Rect bounds) { |
81 typedef AppWindow::BoundsSpecification BoundsSpecification; | 55 typedef AppWindow::BoundsSpecification BoundsSpecification; |
82 | 56 |
83 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; | 57 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; |
84 | 58 |
85 // If coordinates are unspecified, center window on primary screen. | 59 // If coordinates are unspecified, center window on primary screen. |
86 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition) | 60 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition) |
87 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2)); | 61 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2)); |
88 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition) | 62 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition) |
89 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2)); | 63 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2)); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 [titlebar_background_view_ | 325 [titlebar_background_view_ |
352 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) | 326 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) |
353 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; | 327 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; |
354 } | 328 } |
355 | 329 |
356 if (base::mac::IsOSSnowLeopard() && | 330 if (base::mac::IsOSSnowLeopard() && |
357 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 331 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
358 [window setBottomCornerRounded:NO]; | 332 [window setBottomCornerRounded:NO]; |
359 | 333 |
360 if (params.always_on_top) | 334 if (params.always_on_top) |
361 [window setLevel:AlwaysOnTopWindowLevel()]; | 335 gfx::SetNSWindowAlwaysOnTop(window, true, false); |
362 InitCollectionBehavior(window); | |
363 | 336 |
364 SetWorkspacesCollectionBehavior(window, params.visible_on_all_workspaces); | 337 gfx::SetNSWindowVisibleOnAllWorkspaces(window, |
| 338 params.visible_on_all_workspaces); |
365 | 339 |
366 window_controller_.reset( | 340 window_controller_.reset( |
367 [[NativeAppWindowController alloc] initWithWindow:window.release()]); | 341 [[NativeAppWindowController alloc] initWithWindow:window.release()]); |
368 | 342 |
369 NSView* view = WebContents()->GetNativeView(); | 343 NSView* view = WebContents()->GetNativeView(); |
370 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 344 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
371 | 345 |
372 InstallView(); | 346 InstallView(); |
373 | 347 |
374 [[window_controller_ window] setDelegate:window_controller_]; | 348 [[window_controller_ window] setDelegate:window_controller_]; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 681 } |
708 | 682 |
709 void NativeAppWindowCocoa::FlashFrame(bool flash) { | 683 void NativeAppWindowCocoa::FlashFrame(bool flash) { |
710 apps::ExtensionAppShimHandler::RequestUserAttentionForWindow( | 684 apps::ExtensionAppShimHandler::RequestUserAttentionForWindow( |
711 app_window_, | 685 app_window_, |
712 flash ? apps::APP_SHIM_ATTENTION_CRITICAL | 686 flash ? apps::APP_SHIM_ATTENTION_CRITICAL |
713 : apps::APP_SHIM_ATTENTION_CANCEL); | 687 : apps::APP_SHIM_ATTENTION_CANCEL); |
714 } | 688 } |
715 | 689 |
716 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { | 690 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { |
717 return [window() level] == AlwaysOnTopWindowLevel(); | 691 return gfx::IsNSWindowAlwaysOnTop(window()); |
718 } | 692 } |
719 | 693 |
720 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) { | 694 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) { |
721 if (IsActive()) | 695 if (IsActive()) |
722 WebContents()->RestoreFocus(); | 696 WebContents()->RestoreFocus(); |
723 } | 697 } |
724 | 698 |
725 bool NativeAppWindowCocoa::IsFrameless() const { | 699 bool NativeAppWindowCocoa::IsFrameless() const { |
726 return !has_frame_; | 700 return !has_frame_; |
727 } | 701 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 is_resizable_ && !size_constraints_.HasFixedSize(); | 893 is_resizable_ && !size_constraints_.HasFixedSize(); |
920 shows_fullscreen_controls_ = | 894 shows_fullscreen_controls_ = |
921 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; | 895 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; |
922 | 896 |
923 gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size, | 897 gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size, |
924 shows_resize_controls_, | 898 shows_resize_controls_, |
925 shows_fullscreen_controls_); | 899 shows_fullscreen_controls_); |
926 } | 900 } |
927 | 901 |
928 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { | 902 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { |
929 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : | 903 gfx::SetNSWindowAlwaysOnTop(window(), always_on_top, false); |
930 NSNormalWindowLevel)]; | |
931 } | 904 } |
932 | 905 |
933 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { | 906 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { |
934 SetWorkspacesCollectionBehavior(window(), always_visible); | 907 gfx::SetNSWindowVisibleOnAllWorkspaces(window(), always_visible); |
935 } | 908 } |
936 | 909 |
937 void NativeAppWindowCocoa::SetInterceptAllKeys(bool want_all_key) { | 910 void NativeAppWindowCocoa::SetInterceptAllKeys(bool want_all_key) { |
938 // TODO(sriramsr): implement for OSX (http://crbug.com/166928). | 911 // TODO(sriramsr): implement for OSX (http://crbug.com/166928). |
939 NOTIMPLEMENTED(); | 912 NOTIMPLEMENTED(); |
940 } | 913 } |
941 | 914 |
942 NativeAppWindowCocoa::~NativeAppWindowCocoa() { | 915 NativeAppWindowCocoa::~NativeAppWindowCocoa() { |
943 } | 916 } |
944 | 917 |
945 AppNSWindow* NativeAppWindowCocoa::window() const { | 918 AppNSWindow* NativeAppWindowCocoa::window() const { |
946 NSWindow* window = [window_controller_ window]; | 919 NSWindow* window = [window_controller_ window]; |
947 CHECK(!window || [window isKindOfClass:[AppNSWindow class]]); | 920 CHECK(!window || [window isKindOfClass:[AppNSWindow class]]); |
948 return static_cast<AppNSWindow*>(window); | 921 return static_cast<AppNSWindow*>(window); |
949 } | 922 } |
950 | 923 |
951 content::WebContents* NativeAppWindowCocoa::WebContents() const { | 924 content::WebContents* NativeAppWindowCocoa::WebContents() const { |
952 return app_window_->web_contents(); | 925 return app_window_->web_contents(); |
953 } | 926 } |
954 | 927 |
955 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 928 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
956 if (IsRestored(*this)) | 929 if (IsRestored(*this)) |
957 restored_bounds_ = [window() frame]; | 930 restored_bounds_ = [window() frame]; |
958 } | 931 } |
959 | 932 |
960 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 933 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
961 [window() orderOut:window_controller_]; | 934 [window() orderOut:window_controller_]; |
962 } | 935 } |
OLD | NEW |