| 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_frame_controls.h" | |
| 26 #include "ui/gfx/skia_util.h" | 25 #include "ui/gfx/skia_util.h" |
| 27 | 26 |
| 28 // NOTE: State Before Update. | 27 // NOTE: State Before Update. |
| 29 // | 28 // |
| 30 // 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 |
| 31 // 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 |
| 32 // to |OnNativeWindowChanged|. | 31 // to |OnNativeWindowChanged|. |
| 33 | 32 |
| 34 // NOTE: Maximize and Zoom. | 33 // NOTE: Maximize and Zoom. |
| 35 // | 34 // |
| 36 // Zooming is implemented manually in order to implement maximize functionality | 35 // Zooming is implemented manually in order to implement maximize functionality |
| 37 // and to support non resizable windows. The window will be resized explicitly | 36 // and to support non resizable windows. The window will be resized explicitly |
| 38 // in the |WindowWillZoom| call. | 37 // in the |WindowWillZoom| call. |
| 39 // | 38 // |
| 40 // Attempting maximize and restore functionality with non resizable windows | 39 // Attempting maximize and restore functionality with non resizable windows |
| 41 // using the native zoom method did not work, even with | 40 // using the native zoom method did not work, even with |
| 42 // windowWillUseStandardFrame, as the window would not restore back to the | 41 // windowWillUseStandardFrame, as the window would not restore back to the |
| 43 // desired size. | 42 // desired size. |
| 44 | 43 |
| 45 using extensions::AppWindow; | 44 using extensions::AppWindow; |
| 46 | 45 |
| 47 @interface NSWindow (NSPrivateApis) | 46 @interface NSWindow (NSPrivateApis) |
| 48 - (void)setBottomCornerRounded:(BOOL)rounded; | 47 - (void)setBottomCornerRounded:(BOOL)rounded; |
| 49 - (BOOL)_isTitleHidden; | 48 - (BOOL)_isTitleHidden; |
| 50 @end | 49 @end |
| 51 | 50 |
| 52 namespace { | 51 namespace { |
| 53 | 52 |
| 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 |
| 54 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { | 62 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { |
| 55 NSWindowCollectionBehavior behavior = [window collectionBehavior]; | 63 NSWindowCollectionBehavior behavior = [window collectionBehavior]; |
| 56 if (always_visible) | 64 if (always_visible) |
| 57 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; | 65 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; |
| 58 else | 66 else |
| 59 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; | 67 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces; |
| 60 [window setCollectionBehavior:behavior]; | 68 [window setCollectionBehavior:behavior]; |
| 61 } | 69 } |
| 62 | 70 |
| 63 void InitCollectionBehavior(NSWindow* window) { | 71 void InitCollectionBehavior(NSWindow* window) { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 bool fullscreen = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | 465 bool fullscreen = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| 458 if (fullscreen == is_fullscreen_) | 466 if (fullscreen == is_fullscreen_) |
| 459 return; | 467 return; |
| 460 is_fullscreen_ = fullscreen; | 468 is_fullscreen_ = fullscreen; |
| 461 | 469 |
| 462 if (base::mac::IsOSLionOrLater()) { | 470 if (base::mac::IsOSLionOrLater()) { |
| 463 // If going fullscreen, but the window is constrained (fullscreen UI control | 471 // If going fullscreen, but the window is constrained (fullscreen UI control |
| 464 // is disabled), temporarily enable it. It will be disabled again on leaving | 472 // is disabled), temporarily enable it. It will be disabled again on leaving |
| 465 // fullscreen. | 473 // fullscreen. |
| 466 if (fullscreen && !shows_fullscreen_controls_) | 474 if (fullscreen && !shows_fullscreen_controls_) |
| 467 gfx::SetNSWindowCanFullscreen(window(), true); | 475 SetFullScreenCollectionBehavior(window(), true); |
| 468 [window() toggleFullScreen:nil]; | 476 [window() toggleFullScreen:nil]; |
| 469 return; | 477 return; |
| 470 } | 478 } |
| 471 | 479 |
| 472 DCHECK(base::mac::IsOSSnowLeopard()); | 480 DCHECK(base::mac::IsOSSnowLeopard()); |
| 473 | 481 |
| 474 // Fade to black. | 482 // Fade to black. |
| 475 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; | 483 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; |
| 476 bool did_fade_out = false; | 484 bool did_fade_out = false; |
| 477 CGDisplayFadeReservationToken token; | 485 CGDisplayFadeReservationToken token; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 864 |
| 857 void NativeAppWindowCocoa::WindowDidEnterFullscreen() { | 865 void NativeAppWindowCocoa::WindowDidEnterFullscreen() { |
| 858 is_fullscreen_ = true; | 866 is_fullscreen_ = true; |
| 859 app_window_->OSFullscreen(); | 867 app_window_->OSFullscreen(); |
| 860 app_window_->OnNativeWindowChanged(); | 868 app_window_->OnNativeWindowChanged(); |
| 861 } | 869 } |
| 862 | 870 |
| 863 void NativeAppWindowCocoa::WindowDidExitFullscreen() { | 871 void NativeAppWindowCocoa::WindowDidExitFullscreen() { |
| 864 is_fullscreen_ = false; | 872 is_fullscreen_ = false; |
| 865 if (!shows_fullscreen_controls_) | 873 if (!shows_fullscreen_controls_) |
| 866 gfx::SetNSWindowCanFullscreen(window(), false); | 874 SetFullScreenCollectionBehavior(window(), false); |
| 867 | 875 |
| 868 app_window_->Restore(); | 876 app_window_->Restore(); |
| 869 app_window_->OnNativeWindowChanged(); | 877 app_window_->OnNativeWindowChanged(); |
| 870 } | 878 } |
| 871 | 879 |
| 872 void NativeAppWindowCocoa::WindowWillZoom() { | 880 void NativeAppWindowCocoa::WindowWillZoom() { |
| 873 // See top of file NOTE: Maximize and Zoom. | 881 // See top of file NOTE: Maximize and Zoom. |
| 874 if (IsMaximized()) | 882 if (IsMaximized()) |
| 875 Restore(); | 883 Restore(); |
| 876 else | 884 else |
| (...skipping 30 matching lines...) Expand all Loading... |
| 907 gfx::Size NativeAppWindowCocoa::GetContentMaximumSize() const { | 915 gfx::Size NativeAppWindowCocoa::GetContentMaximumSize() const { |
| 908 return size_constraints_.GetMaximumSize(); | 916 return size_constraints_.GetMaximumSize(); |
| 909 } | 917 } |
| 910 | 918 |
| 911 void NativeAppWindowCocoa::SetContentSizeConstraints( | 919 void NativeAppWindowCocoa::SetContentSizeConstraints( |
| 912 const gfx::Size& min_size, const gfx::Size& max_size) { | 920 const gfx::Size& min_size, const gfx::Size& max_size) { |
| 913 // Update the size constraints. | 921 // Update the size constraints. |
| 914 size_constraints_.set_minimum_size(min_size); | 922 size_constraints_.set_minimum_size(min_size); |
| 915 size_constraints_.set_maximum_size(max_size); | 923 size_constraints_.set_maximum_size(max_size); |
| 916 | 924 |
| 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 |
| 917 // Update the window controls. | 937 // Update the window controls. |
| 918 shows_resize_controls_ = | 938 shows_resize_controls_ = |
| 919 is_resizable_ && !size_constraints_.HasFixedSize(); | 939 is_resizable_ && !size_constraints_.HasFixedSize(); |
| 920 shows_fullscreen_controls_ = | 940 shows_fullscreen_controls_ = |
| 921 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; | 941 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; |
| 922 | 942 |
| 923 gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size, | 943 if (!is_fullscreen_) { |
| 924 shows_resize_controls_, | 944 [window() setStyleMask:GetWindowStyleMask()]; |
| 925 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 } |
| 926 } | 958 } |
| 927 | 959 |
| 928 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { | 960 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { |
| 929 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : | 961 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : |
| 930 NSNormalWindowLevel)]; | 962 NSNormalWindowLevel)]; |
| 931 } | 963 } |
| 932 | 964 |
| 933 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { | 965 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { |
| 934 SetWorkspacesCollectionBehavior(window(), always_visible); | 966 SetWorkspacesCollectionBehavior(window(), always_visible); |
| 935 } | 967 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 953 } | 985 } |
| 954 | 986 |
| 955 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 987 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
| 956 if (IsRestored(*this)) | 988 if (IsRestored(*this)) |
| 957 restored_bounds_ = [window() frame]; | 989 restored_bounds_ = [window() frame]; |
| 958 } | 990 } |
| 959 | 991 |
| 960 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 992 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
| 961 [window() orderOut:window_controller_]; | 993 [window() orderOut:window_controller_]; |
| 962 } | 994 } |
| OLD | NEW |