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" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" | 12 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 14 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
16 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 16 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
17 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 17 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 #include "skia/ext/skia_utils_mac.h" | 23 #include "skia/ext/skia_utils_mac.h" |
24 #include "third_party/skia/include/core/SkRegion.h" | 24 #include "third_party/skia/include/core/SkRegion.h" |
| 25 #import "ui/gfx/mac/nswindow_util.h" |
25 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
26 | 27 |
27 // NOTE: State Before Update. | 28 // NOTE: State Before Update. |
28 // | 29 // |
29 // 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 |
30 // 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 |
31 // to |OnNativeWindowChanged|. | 32 // to |OnNativeWindowChanged|. |
32 | 33 |
33 // NOTE: Maximize and Zoom. | 34 // NOTE: Maximize and Zoom. |
34 // | 35 // |
35 // Zooming is implemented manually in order to implement maximize functionality | 36 // Zooming is implemented manually in order to implement maximize functionality |
36 // and to support non resizable windows. The window will be resized explicitly | 37 // and to support non resizable windows. The window will be resized explicitly |
37 // in the |WindowWillZoom| call. | 38 // in the |WindowWillZoom| call. |
38 // | 39 // |
39 // Attempting maximize and restore functionality with non resizable windows | 40 // Attempting maximize and restore functionality with non resizable windows |
40 // using the native zoom method did not work, even with | 41 // using the native zoom method did not work, even with |
41 // windowWillUseStandardFrame, as the window would not restore back to the | 42 // windowWillUseStandardFrame, as the window would not restore back to the |
42 // desired size. | 43 // desired size. |
43 | 44 |
44 using extensions::AppWindow; | 45 using extensions::AppWindow; |
45 | 46 |
46 @interface NSWindow (NSPrivateApis) | 47 @interface NSWindow (NSPrivateApis) |
47 - (void)setBottomCornerRounded:(BOOL)rounded; | 48 - (void)setBottomCornerRounded:(BOOL)rounded; |
48 - (BOOL)_isTitleHidden; | 49 - (BOOL)_isTitleHidden; |
49 @end | 50 @end |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) { | |
54 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | |
55 if (allow_fullscreen) | |
56 behavior |= NSWindowCollectionBehaviorFullScreenPrimary; | |
57 else | |
58 behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; | |
59 [window setCollectionBehavior:behavior]; | |
60 } | |
61 | |
62 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { | 54 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { |
63 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | 55 NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
64 if (always_visible) | 56 if (always_visible) |
65 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; | 57 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; |
66 else | 58 else |
67 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; | 59 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; |
68 [window setCollectionBehavior:behavior]; | 60 [window setCollectionBehavior:behavior]; |
69 } | 61 } |
70 | 62 |
71 void InitCollectionBehavior(NSWindow* window) { | 63 void InitCollectionBehavior(NSWindow* window) { |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 gfx::Size NativeAppWindowCocoa::GetContentMaximumSize() const { | 907 gfx::Size NativeAppWindowCocoa::GetContentMaximumSize() const { |
916 return size_constraints_.GetMaximumSize(); | 908 return size_constraints_.GetMaximumSize(); |
917 } | 909 } |
918 | 910 |
919 void NativeAppWindowCocoa::SetContentSizeConstraints( | 911 void NativeAppWindowCocoa::SetContentSizeConstraints( |
920 const gfx::Size& min_size, const gfx::Size& max_size) { | 912 const gfx::Size& min_size, const gfx::Size& max_size) { |
921 // Update the size constraints. | 913 // Update the size constraints. |
922 size_constraints_.set_minimum_size(min_size); | 914 size_constraints_.set_minimum_size(min_size); |
923 size_constraints_.set_maximum_size(max_size); | 915 size_constraints_.set_maximum_size(max_size); |
924 | 916 |
925 gfx::Size minimum_size = size_constraints_.GetMinimumSize(); | |
926 [window() setContentMinSize:NSMakeSize(minimum_size.width(), | |
927 minimum_size.height())]; | |
928 | |
929 gfx::Size maximum_size = size_constraints_.GetMaximumSize(); | |
930 const int kUnboundedSize = extensions::SizeConstraints::kUnboundedSize; | |
931 CGFloat max_width = maximum_size.width() == kUnboundedSize ? | |
932 CGFLOAT_MAX : maximum_size.width(); | |
933 CGFloat max_height = maximum_size.height() == kUnboundedSize ? | |
934 CGFLOAT_MAX : maximum_size.height(); | |
935 [window() setContentMaxSize:NSMakeSize(max_width, max_height)]; | |
936 | |
937 // Update the window controls. | 917 // Update the window controls. |
938 shows_resize_controls_ = | 918 shows_resize_controls_ = |
939 is_resizable_ && !size_constraints_.HasFixedSize(); | 919 is_resizable_ && !size_constraints_.HasFixedSize(); |
940 shows_fullscreen_controls_ = | 920 shows_fullscreen_controls_ = |
941 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; | 921 is_resizable_ && !size_constraints_.HasMaximumSize(); |
942 | 922 |
943 if (!is_fullscreen_) { | 923 ApplySizeConstraints(window(), min_size, max_size, shows_resize_controls_, |
944 [window() setStyleMask:GetWindowStyleMask()]; | 924 shows_fullscreen_controls_); |
945 | |
946 // Set the window to participate in Lion Fullscreen mode. Setting this flag | |
947 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are | |
948 // only shown for apps that have unbounded size. | |
949 if (base::mac::IsOSLionOrLater()) | |
950 SetFullScreenCollectionBehavior(window(), shows_fullscreen_controls_); | |
951 } | |
952 | |
953 if (has_frame_) { | |
954 [window() setShowsResizeIndicator:shows_resize_controls_]; | |
955 [[window() standardWindowButton:NSWindowZoomButton] | |
956 setEnabled:shows_fullscreen_controls_]; | |
957 } | |
958 } | 925 } |
959 | 926 |
960 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { | 927 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { |
961 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : | 928 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : |
962 NSNormalWindowLevel)]; | 929 NSNormalWindowLevel)]; |
963 } | 930 } |
964 | 931 |
965 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { | 932 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { |
966 SetWorkspacesCollectionBehavior(window(), always_visible); | 933 SetWorkspacesCollectionBehavior(window(), always_visible); |
967 } | 934 } |
(...skipping 17 matching lines...) Expand all Loading... |
985 } | 952 } |
986 | 953 |
987 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 954 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
988 if (IsRestored(*this)) | 955 if (IsRestored(*this)) |
989 restored_bounds_ = [window() frame]; | 956 restored_bounds_ = [window() frame]; |
990 } | 957 } |
991 | 958 |
992 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 959 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
993 [window() orderOut:window_controller_]; | 960 [window() orderOut:window_controller_]; |
994 } | 961 } |
OLD | NEW |