diff options
-rw-r--r-- | chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm | 44 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm | 64 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.mm | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h | 27 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/native_app_window_frame_view_mac.mm | 29 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 2 | ||||
-rw-r--r-- | ui/gfx/mac/nswindow_frame_controls.h | 31 | ||||
-rw-r--r-- | ui/gfx/mac/nswindow_frame_controls.mm | 63 | ||||
-rw-r--r-- | ui/views/cocoa/bridged_native_widget.h | 3 | ||||
-rw-r--r-- | ui/views/cocoa/bridged_native_widget.mm | 18 | ||||
-rw-r--r-- | ui/views/widget/native_widget_mac.mm | 4 |
13 files changed, 39 insertions, 255 deletions
diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm index 6744a8c..95b1c8a 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm @@ -22,7 +22,6 @@ #include "extensions/common/extension.h" #include "skia/ext/skia_utils_mac.h" #include "third_party/skia/include/core/SkRegion.h" -#import "ui/gfx/mac/nswindow_frame_controls.h" #include "ui/gfx/skia_util.h" // NOTE: State Before Update. @@ -51,6 +50,15 @@ using extensions::AppWindow; namespace { +void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) { + NSWindowCollectionBehavior behavior = [window collectionBehavior]; + if (allow_fullscreen) + behavior |= NSWindowCollectionBehaviorFullScreenPrimary; + else + behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; + [window setCollectionBehavior:behavior]; +} + void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) { NSWindowCollectionBehavior behavior = [window collectionBehavior]; if (always_visible) @@ -464,7 +472,7 @@ void NativeAppWindowCocoa::SetFullscreen(int fullscreen_types) { // is disabled), temporarily enable it. It will be disabled again on leaving // fullscreen. if (fullscreen && !shows_fullscreen_controls_) - gfx::SetNSWindowCanFullscreen(window(), true); + SetFullScreenCollectionBehavior(window(), true); [window() toggleFullScreen:nil]; return; } @@ -863,7 +871,7 @@ void NativeAppWindowCocoa::WindowDidEnterFullscreen() { void NativeAppWindowCocoa::WindowDidExitFullscreen() { is_fullscreen_ = false; if (!shows_fullscreen_controls_) - gfx::SetNSWindowCanFullscreen(window(), false); + SetFullScreenCollectionBehavior(window(), false); app_window_->Restore(); app_window_->OnNativeWindowChanged(); @@ -914,15 +922,39 @@ void NativeAppWindowCocoa::SetContentSizeConstraints( size_constraints_.set_minimum_size(min_size); size_constraints_.set_maximum_size(max_size); + gfx::Size minimum_size = size_constraints_.GetMinimumSize(); + [window() setContentMinSize:NSMakeSize(minimum_size.width(), + minimum_size.height())]; + + gfx::Size maximum_size = size_constraints_.GetMaximumSize(); + const int kUnboundedSize = extensions::SizeConstraints::kUnboundedSize; + CGFloat max_width = maximum_size.width() == kUnboundedSize ? + CGFLOAT_MAX : maximum_size.width(); + CGFloat max_height = maximum_size.height() == kUnboundedSize ? + CGFLOAT_MAX : maximum_size.height(); + [window() setContentMaxSize:NSMakeSize(max_width, max_height)]; + // Update the window controls. shows_resize_controls_ = is_resizable_ && !size_constraints_.HasFixedSize(); shows_fullscreen_controls_ = is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; - gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size, - shows_resize_controls_, - shows_fullscreen_controls_); + if (!is_fullscreen_) { + [window() setStyleMask:GetWindowStyleMask()]; + + // Set the window to participate in Lion Fullscreen mode. Setting this flag + // has no effect on Snow Leopard or earlier. UI controls for fullscreen are + // only shown for apps that have unbounded size. + if (base::mac::IsOSLionOrLater()) + SetFullScreenCollectionBehavior(window(), shows_fullscreen_controls_); + } + + if (has_frame_) { + [window() setShowsResizeIndicator:shows_resize_controls_]; + [[window() standardWindowButton:NSWindowZoomButton] + setEnabled:shows_fullscreen_controls_]; + } } void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm index 3278955..3992b5f 100644 --- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm +++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm @@ -240,67 +240,3 @@ IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Frameless) { CloseAppWindow(app_window); } - -namespace { - -// Test that resize and fullscreen controls are correctly enabled/disabled. -void TestControls(extensions::AppWindow* app_window) { - NSWindow* ns_window = app_window->GetNativeWindow(); - - // The window is resizable. - EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); - if (base::mac::IsOSSnowLeopard()) - EXPECT_TRUE([ns_window showsResizeIndicator]); - - // Due to this bug: http://crbug.com/362039, which manifests on the Cocoa - // implementation but not the views one, frameless windows should have - // fullscreen controls disabled. - BOOL can_fullscreen = - ![NSStringFromClass([ns_window class]) isEqualTo:@"AppFramelessNSWindow"]; - // The window can fullscreen and maximize. - if (base::mac::IsOSLionOrLater()) - EXPECT_EQ(can_fullscreen, !!([ns_window collectionBehavior] & - NSWindowCollectionBehaviorFullScreenPrimary)); - EXPECT_EQ(can_fullscreen, - [[ns_window standardWindowButton:NSWindowZoomButton] isEnabled]); - - // Set a maximum size. - app_window->SetContentSizeConstraints(gfx::Size(), gfx::Size(200, 201)); - EXPECT_EQ(200, [ns_window contentMaxSize].width); - EXPECT_EQ(201, [ns_window contentMaxSize].height); - NSView* web_contents = app_window->web_contents()->GetNativeView(); - EXPECT_EQ(200, [web_contents frame].size.width); - EXPECT_EQ(201, [web_contents frame].size.height); - - // Still resizable. - EXPECT_TRUE([ns_window styleMask] & NSResizableWindowMask); - if (base::mac::IsOSSnowLeopard()) - EXPECT_TRUE([ns_window showsResizeIndicator]); - - // Fullscreen and maximize are disabled. - if (base::mac::IsOSLionOrLater()) - EXPECT_FALSE([ns_window collectionBehavior] & - NSWindowCollectionBehaviorFullScreenPrimary); - EXPECT_FALSE([[ns_window standardWindowButton:NSWindowZoomButton] isEnabled]); - - // Set a minimum size equal to the maximum size. - app_window->SetContentSizeConstraints(gfx::Size(200, 201), - gfx::Size(200, 201)); - EXPECT_EQ(200, [ns_window contentMinSize].width); - EXPECT_EQ(201, [ns_window contentMinSize].height); - - // No longer resizable. - EXPECT_FALSE([ns_window styleMask] & NSResizableWindowMask); - if (base::mac::IsOSSnowLeopard()) - EXPECT_FALSE([ns_window showsResizeIndicator]); -} - -} // namespace - -IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Controls) { - TestControls(CreateTestAppWindow("{}")); -} - -IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, ControlsFrameless) { - TestControls(CreateTestAppWindow("{\"frame\": \"none\"}")); -} diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h b/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h index ceec2b9..3a88df9 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h @@ -19,7 +19,6 @@ class ChromeNativeAppWindowViewsMac : public ChromeNativeAppWindowViews { const extensions::AppWindow::CreateParams& create_params, views::Widget::InitParams* init_params, views::Widget* widget) override; - views::NonClientFrameView* CreateStandardDesktopAppFrame() override; // ui::BaseWindow implementation. void Show() override; diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.mm b/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.mm index 3356dcb..a90b38d 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.mm +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.mm @@ -6,7 +6,6 @@ #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" #include "chrome/browser/ui/views/apps/app_window_native_widget_mac.h" -#include "chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h" ChromeNativeAppWindowViewsMac::ChromeNativeAppWindowViewsMac() : is_hidden_with_app_(false) { @@ -25,11 +24,6 @@ void ChromeNativeAppWindowViewsMac::OnBeforeWidgetInit( widget); } -views::NonClientFrameView* -ChromeNativeAppWindowViewsMac::CreateStandardDesktopAppFrame() { - return new NativeAppWindowFrameViewMac(widget()); -} - void ChromeNativeAppWindowViewsMac::Show() { if (is_hidden_with_app_) { // If there is a shim to gently request attention, return here. Otherwise diff --git a/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h b/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h deleted file mode 100644 index 0509f5c..0000000 --- a/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_FRAME_VIEW_MAC_H_ -#define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_FRAME_VIEW_MAC_H_ - -#include "ui/views/window/native_frame_view.h" - -class Widget; - -// Provides metrics consistent with a native frame on Mac. The actual frame is -// drawn by NSWindow. -class NativeAppWindowFrameViewMac : public views::NativeFrameView { - public: - explicit NativeAppWindowFrameViewMac(views::Widget* frame); - ~NativeAppWindowFrameViewMac() override; - - // NonClientFrameView: - gfx::Rect GetWindowBoundsForClientBounds( - const gfx::Rect& client_bounds) const override; - - private: - DISALLOW_COPY_AND_ASSIGN(NativeAppWindowFrameViewMac); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_FRAME_VIEW_MAC_H_ diff --git a/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.mm b/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.mm deleted file mode 100644 index 444a6df..0000000 --- a/chrome/browser/ui/views/apps/native_app_window_frame_view_mac.mm +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h" - -#import <Cocoa/Cocoa.h> - -#import "ui/gfx/mac/coordinate_conversion.h" -#include "ui/views/widget/widget.h" - -NativeAppWindowFrameViewMac::NativeAppWindowFrameViewMac(views::Widget* frame) - : views::NativeFrameView(frame) { -} - -NativeAppWindowFrameViewMac::~NativeAppWindowFrameViewMac() { -} - -gfx::Rect NativeAppWindowFrameViewMac::GetWindowBoundsForClientBounds( - const gfx::Rect& client_bounds) const { - NSWindow* ns_window = GetWidget()->GetNativeWindow(); - gfx::Rect window_bounds = gfx::ScreenRectFromNSRect([ns_window - frameRectForContentRect:gfx::ScreenRectToNSRect(client_bounds)]); - // Enforce minimum size (1, 1) in case that |client_bounds| is passed with - // empty size. - if (window_bounds.IsEmpty()) - window_bounds.set_size(gfx::Size(1, 1)); - return window_bounds; -} diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index e3ecfea..bbab248 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2356,8 +2356,6 @@ 'browser/ui/views/apps/chrome_app_window_client_views_mac.mm', 'browser/ui/views/apps/chrome_native_app_window_views_mac.h', 'browser/ui/views/apps/chrome_native_app_window_views_mac.mm', - 'browser/ui/views/apps/native_app_window_frame_view_mac.h', - 'browser/ui/views/apps/native_app_window_frame_view_mac.mm', ], # Windows-only. Assume ash/aura/views. 'chrome_browser_ui_win_sources': [ diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index d69406c..ab501a9 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -220,8 +220,6 @@ 'linux_font_delegate.h', 'mac/coordinate_conversion.h', 'mac/coordinate_conversion.mm', - 'mac/nswindow_frame_controls.h', - 'mac/nswindow_frame_controls.mm', 'mac/scoped_ns_disable_screen_updates.h', 'native_widget_types.h', 'nine_image_painter.cc', diff --git a/ui/gfx/mac/nswindow_frame_controls.h b/ui/gfx/mac/nswindow_frame_controls.h deleted file mode 100644 index 7ec7ab7..0000000 --- a/ui/gfx/mac/nswindow_frame_controls.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_GFX_MAC_NSWINDOW_FRAME_CONTROLS_H_ -#define UI_GFX_MAC_NSWINDOW_FRAME_CONTROLS_H_ - -#include "ui/gfx/gfx_export.h" - -@class NSWindow; - -namespace gfx { - -class Size; - -// Set whether the window can be fullscreened. -GFX_EXPORT void SetNSWindowCanFullscreen(NSWindow* window, - bool allow_fullscreen); - -// Sets the min/max size of the window as well as showing/hiding resize, -// maximize, and fullscreen controls. -// Sizes refer to the content size (inner bounds). -GFX_EXPORT void ApplyNSWindowSizeConstraints(NSWindow* window, - const gfx::Size& min_size, - const gfx::Size& max_size, - bool can_resize, - bool can_fullscreen); - -} // namespace gfx - -#endif // UI_GFX_MAC_NSWINDOW_FRAME_CONTROLS_H_ diff --git a/ui/gfx/mac/nswindow_frame_controls.mm b/ui/gfx/mac/nswindow_frame_controls.mm deleted file mode 100644 index 34f7d26..0000000 --- a/ui/gfx/mac/nswindow_frame_controls.mm +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "ui/gfx/mac/nswindow_frame_controls.h" - -#import "base/mac/mac_util.h" -#import "base/mac/sdk_forward_declarations.h" -#include "ui/gfx/geometry/size.h" - -namespace { - -// The value used to represent an unbounded width or height. -const int kUnboundedSize = 0; - -void SetResizableStyleMask(NSWindow* window, bool resizable) { - NSUInteger style_mask = [window styleMask]; - if (resizable) - style_mask |= NSResizableWindowMask; - else - style_mask &= ~NSResizableWindowMask; - [window setStyleMask:style_mask]; -} - -} // namespace - -namespace gfx { - -void SetNSWindowCanFullscreen(NSWindow* window, bool allow_fullscreen) { - NSWindowCollectionBehavior behavior = [window collectionBehavior]; - if (allow_fullscreen) - behavior |= NSWindowCollectionBehaviorFullScreenPrimary; - else - behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary; - [window setCollectionBehavior:behavior]; -} - -void ApplyNSWindowSizeConstraints(NSWindow* window, - const gfx::Size& min_size, - const gfx::Size& max_size, - bool can_resize, - bool can_fullscreen) { - [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; - - CGFloat max_width = - max_size.width() == kUnboundedSize ? CGFLOAT_MAX : max_size.width(); - CGFloat max_height = - max_size.height() == kUnboundedSize ? CGFLOAT_MAX : max_size.height(); - [window setContentMaxSize:NSMakeSize(max_width, max_height)]; - - SetResizableStyleMask(window, can_resize); - [window setShowsResizeIndicator:can_resize]; - - // Set the window to participate in Lion Fullscreen mode. Setting this flag - // has no effect on Snow Leopard or earlier. UI controls for fullscreen are - // only shown for windows that have unbounded size. - if (base::mac::IsOSLionOrLater()) - SetNSWindowCanFullscreen(window, can_fullscreen); - - [[window standardWindowButton:NSWindowZoomButton] setEnabled:can_fullscreen]; -} - -} // namespace gfx diff --git a/ui/views/cocoa/bridged_native_widget.h b/ui/views/cocoa/bridged_native_widget.h index 3fd1f6e..0e712c9 100644 --- a/ui/views/cocoa/bridged_native_widget.h +++ b/ui/views/cocoa/bridged_native_widget.h @@ -125,9 +125,6 @@ class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate, // Called by the NSWindowDelegate when the window becomes or resigns key. void OnWindowKeyStatusChangedTo(bool is_key); - // Called by NativeWidgetMac when the window size constraints change. - void OnSizeConstraintsChanged(); - // See widget.h for documentation. InputMethod* CreateInputMethod(); ui::InputMethod* GetHostInputMethod(); diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm index 874dce6..74ac56af 100644 --- a/ui/views/cocoa/bridged_native_widget.mm +++ b/ui/views/cocoa/bridged_native_widget.mm @@ -16,7 +16,6 @@ #include "ui/gfx/display.h" #include "ui/gfx/geometry/dip_util.h" #import "ui/gfx/mac/coordinate_conversion.h" -#import "ui/gfx/mac/nswindow_frame_controls.h" #include "ui/gfx/screen.h" #import "ui/views/cocoa/cocoa_mouse_capture.h" #import "ui/views/cocoa/bridged_content_view.h" @@ -28,7 +27,6 @@ #include "ui/views/views_delegate.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_aura_utils.h" -#include "ui/views/widget/widget_delegate.h" // The NSView that hosts the composited CALayer drawing the UI. It fills the // window but is not hittable so that accessibility hit tests always go to the @@ -490,22 +488,6 @@ void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { } } -void BridgedNativeWidget::OnSizeConstraintsChanged() { - NSWindow* window = ns_window(); - Widget* widget = native_widget_mac()->GetWidget(); - gfx::Size min_size = widget->GetMinimumSize(); - gfx::Size max_size = widget->GetMaximumSize(); - bool is_resizable = widget->widget_delegate()->CanResize(); - bool shows_resize_controls = - is_resizable && (min_size.IsEmpty() || min_size != max_size); - bool shows_fullscreen_controls = - is_resizable && widget->widget_delegate()->CanMaximize(); - - gfx::ApplyNSWindowSizeConstraints(window, min_size, max_size, - shows_resize_controls, - shows_fullscreen_controls); -} - InputMethod* BridgedNativeWidget::CreateInputMethod() { if (switches::IsTextInputFocusManagerEnabled()) return new NullInputMethod(); diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm index 961abfa..eaad5c9 100644 --- a/ui/views/widget/native_widget_mac.mm +++ b/ui/views/widget/native_widget_mac.mm @@ -91,8 +91,6 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { delegate_->OnNativeWidgetCreated(true); - OnSizeConstraintsChanged(); - bridge_->SetFocusManager(GetWidget()->GetFocusManager()); DCHECK(GetWidget()->GetRootView()); @@ -528,7 +526,7 @@ bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const { } void NativeWidgetMac::OnSizeConstraintsChanged() { - bridge_->OnSizeConstraintsChanged(); + NOTIMPLEMENTED(); } void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) { |