Commit 9af971cc authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Allow for BridgedNativeWidget to create its own NSWindow

Because BridgedNativeWidget will be living in its own process, it will
be necessary for BridgedNativeWidget to create its own NSWindow, instead
of having one be provided during initialization.

This requires substantial refactoring, and two of the NSWindow classes
that BridgedNativeWidget are provided live in chrome/browser/ui, and
will need moving to a new location.

For the moment, allow either creating a new NSWindow or specifying an
NSWindow via the methods BridgedNativeWidget::CreateWindow and
BridgedNativeWidget::SetWindow. This unblocks cross-process development.

Also, be explicit that BridgedNativeWidget's NSWindow is always a
NativeWidgetMacNSWindow or a sub-class thereof. The only exceptions to
this are in tests, so merge testing functionality into
NativeWidgetMacNSWindow.

Bug: 859152
Change-Id: I61edb34d773fc11dff921da5edb34da1e306105b
Reviewed-on: https://chromium-review.googlesource.com/1175051
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583350}
parent 7e4d7965
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#import "ui/views/cocoa/bridged_native_widget_owner.h" #import "ui/views/cocoa/bridged_native_widget_owner.h"
#import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h"
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#import "ui/views/focus/focus_manager.h" #import "ui/views/focus/focus_manager.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -68,9 +69,17 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -68,9 +69,17 @@ class VIEWS_EXPORT BridgedNativeWidget
BridgedNativeWidget(BridgedNativeWidgetHost* host, NativeWidgetMac* parent); BridgedNativeWidget(BridgedNativeWidgetHost* host, NativeWidgetMac* parent);
~BridgedNativeWidget() override; ~BridgedNativeWidget() override;
// Initialize the bridge, "retains" ownership of |window|. // Create the NSWindow using the specified style mask.
void Init(base::scoped_nsobject<NSWindow> window, void CreateWindow(uint64_t window_style_mask);
const Widget::InitParams& params); // Initialize the NSWindow by taking ownership of the specified object.
// Either CreateWindow or SetWindow maybe used to initialize the NSWindow,
// and the initialization may happen only once.
// TODO(ccameron): When a BridgedNativeWidget is allocated across a process
// boundary, it will not be possible to call SetWindow. Move the relevant
// sub-classes so that they can be allocated via CreateWindow.
void SetWindow(base::scoped_nsobject<NativeWidgetMacNSWindow> window);
// Initialize the bridge (after the NSWindow has been created).
void Init(const Widget::InitParams& params);
// Invoked at the end of Widget::Init(). // Invoked at the end of Widget::Init().
void OnWidgetInitDone(); void OnWidgetInitDone();
...@@ -167,7 +176,7 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -167,7 +176,7 @@ class VIEWS_EXPORT BridgedNativeWidget
NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } NativeWidgetMac* native_widget_mac() { return native_widget_mac_; }
BridgedContentView* ns_view() { return bridged_view_; } BridgedContentView* ns_view() { return bridged_view_; }
NSWindow* ns_window() { return window_; } NativeWidgetMacNSWindow* ns_window() { return window_; }
TooltipManager* tooltip_manager() { return tooltip_manager_.get(); } TooltipManager* tooltip_manager() { return tooltip_manager_.get(); }
...@@ -274,7 +283,7 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -274,7 +283,7 @@ class VIEWS_EXPORT BridgedNativeWidget
BridgedNativeWidgetHost* const host_; // Weak. Owns this. BridgedNativeWidgetHost* const host_; // Weak. Owns this.
NativeWidgetMac* const native_widget_mac_; // Weak. Owns |host_|. NativeWidgetMac* const native_widget_mac_; // Weak. Owns |host_|.
base::scoped_nsobject<NSWindow> window_; base::scoped_nsobject<NativeWidgetMacNSWindow> window_;
base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_;
base::scoped_nsobject<BridgedContentView> bridged_view_; base::scoped_nsobject<BridgedContentView> bridged_view_;
base::scoped_nsobject<ModalShowAnimationWithLayer> show_animation_; base::scoped_nsobject<ModalShowAnimationWithLayer> show_animation_;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/viz/common/surfaces/local_surface_id.h" #include "components/viz/common/surfaces/local_surface_id.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h" #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h" #import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#import "ui/base/cocoa/window_size_constants.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#import "ui/views/cocoa/cocoa_mouse_capture.h" #import "ui/views/cocoa/cocoa_mouse_capture.h"
#import "ui/views/cocoa/cocoa_window_move_loop.h" #import "ui/views/cocoa/cocoa_window_move_loop.h"
#import "ui/views/cocoa/drag_drop_client_mac.h" #import "ui/views/cocoa/drag_drop_client_mac.h"
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#include "ui/views/cocoa/tooltip_manager_mac.h" #include "ui/views/cocoa/tooltip_manager_mac.h"
#import "ui/views/cocoa/views_nswindow_delegate.h" #import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h" #import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
...@@ -247,15 +249,29 @@ BridgedNativeWidget::~BridgedNativeWidget() { ...@@ -247,15 +249,29 @@ BridgedNativeWidget::~BridgedNativeWidget() {
SetRootView(nullptr); SetRootView(nullptr);
} }
void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window, void BridgedNativeWidget::CreateWindow(uint64_t window_style_mask) {
const Widget::InitParams& params) { DCHECK(!window_);
widget_type_ = params.type; window_.reset([[NativeWidgetMacNSWindow alloc]
is_translucent_window_ = initWithContentRect:ui::kWindowSizeDeterminedLater
params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW; styleMask:window_style_mask
backing:NSBackingStoreBuffered
defer:NO]);
[window_ setReleasedWhenClosed:NO]; // Owned by scoped_nsobject.
[window_ setDelegate:window_delegate_];
}
void BridgedNativeWidget::SetWindow(
base::scoped_nsobject<NativeWidgetMacNSWindow> window) {
DCHECK(!window_); DCHECK(!window_);
window_.swap(window); window_ = std::move(window);
[window_ setReleasedWhenClosed:NO]; // Owned by scoped_nsobject.
[window_ setDelegate:window_delegate_]; [window_ setDelegate:window_delegate_];
}
void BridgedNativeWidget::Init(const Widget::InitParams& params) {
widget_type_ = params.type;
is_translucent_window_ =
params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW;
// Register for application hide notifications so that visibility can be // Register for application hide notifications so that visibility can be
// properly tracked. This is not done in the delegate so that the lifetime is // properly tracked. This is not done in the delegate so that the lifetime is
......
...@@ -47,6 +47,16 @@ VIEWS_EXPORT ...@@ -47,6 +47,16 @@ VIEWS_EXPORT
// create one. // create one.
- (void)setWindowTouchBarDelegate:(id<WindowTouchBarDelegate>)delegate; - (void)setWindowTouchBarDelegate:(id<WindowTouchBarDelegate>)delegate;
// Override -[NSWindow toggleFullScreen:] to be a no-op for testing.
- (void)disableToggleFullScreenForTesting;
// Methods to query properties for tests.
// TODO(ccameron): It may be more appropriate to put testing methods into a
// separate subclass.
@property(readonly, nonatomic) int invalidateShadowCountForTesting;
@property(readonly, nonatomic) int orderWindowCountForTesting;
@property(readonly, nonatomic) int toggleFullScreenCountForTesting;
@property(assign, nonatomic) bool* deallocFlagForTesting;
@end @end
#endif // UI_VIEWS_COCOA_NATIVE_WIDGET_MAC_NSWINDOW_H_ #endif // UI_VIEWS_COCOA_NATIVE_WIDGET_MAC_NSWINDOW_H_
...@@ -82,7 +82,18 @@ ...@@ -82,7 +82,18 @@
base::scoped_nsobject<CommandDispatcher> commandDispatcher_; base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_; base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_;
id<WindowTouchBarDelegate> touchBarDelegate_; // Weak. id<WindowTouchBarDelegate> touchBarDelegate_; // Weak.
BOOL toggleFullscreenDisabledForTesting_;
int invalidateShadowCountForTesting_;
int orderWindowCountForTesting_;
int toggleFullScreenCountForTesting_;
bool* deallocFlagForTesting_;
} }
@synthesize invalidateShadowCountForTesting = invalidateShadowCountForTesting_;
@synthesize orderWindowCountForTesting = orderWindowCountForTesting_;
@synthesize toggleFullScreenCountForTesting = toggleFullScreenCountForTesting_;
@synthesize deallocFlagForTesting = deallocFlagForTesting_;
- (instancetype)initWithContentRect:(NSRect)contentRect - (instancetype)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle styleMask:(NSUInteger)windowStyle
...@@ -98,8 +109,13 @@ ...@@ -98,8 +109,13 @@
} }
// This override doesn't do anything, but keeping it helps diagnose lifetime // This override doesn't do anything, but keeping it helps diagnose lifetime
// issues in crash stacktraces by inserting a symbol on NativeWidgetMacNSWindow. // issues in crash stacktraces by inserting a symbol on NativeWidgetMacNSWindow,
// and adds hooks for tests.
- (void)dealloc { - (void)dealloc {
if (deallocFlagForTesting_) {
DCHECK(!*deallocFlagForTesting_);
*deallocFlagForTesting_ = true;
}
[super dealloc]; [super dealloc];
} }
...@@ -124,6 +140,10 @@ ...@@ -124,6 +140,10 @@
touchBarDelegate_ = delegate; touchBarDelegate_ = delegate;
} }
- (void)disableToggleFullScreenForTesting {
toggleFullscreenDisabledForTesting_ = YES;
}
// Private methods. // Private methods.
- (ViewsNSWindowDelegate*)viewsNSWindowDelegate { - (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
...@@ -225,10 +245,36 @@ ...@@ -225,10 +245,36 @@
// when ordering in a window for the first time. // when ordering in a window for the first time.
- (void)orderWindow:(NSWindowOrderingMode)orderingMode - (void)orderWindow:(NSWindowOrderingMode)orderingMode
relativeTo:(NSInteger)otherWindowNumber { relativeTo:(NSInteger)otherWindowNumber {
++orderWindowCountForTesting_;
[super orderWindow:orderingMode relativeTo:otherWindowNumber]; [super orderWindow:orderingMode relativeTo:otherWindowNumber];
[[self viewsNSWindowDelegate] onWindowOrderChanged:nil]; [[self viewsNSWindowDelegate] onWindowOrderChanged:nil];
} }
- (void)invalidateShadow {
++invalidateShadowCountForTesting_;
[super invalidateShadow];
}
- (void)performSelector:(SEL)aSelector
withObject:(id)anArgument
afterDelay:(NSTimeInterval)delay {
if (toggleFullscreenDisabledForTesting_ && aSelector == @selector
(toggleFullScreen:)) {
// This is used in simulations without a message loop. Don't start a message
// loop since that would expose the tests to system notifications and
// potential flakes. Instead, just pretend the message loop is flushed here.
[self toggleFullScreen:anArgument];
} else {
[super performSelector:aSelector withObject:anArgument afterDelay:delay];
}
}
- (void)toggleFullScreen:(id)sender {
++toggleFullScreenCountForTesting_;
if (!toggleFullscreenDisabledForTesting_)
[super toggleFullScreen:sender];
}
// NSResponder implementation. // NSResponder implementation.
- (BOOL)performKeyEquivalent:(NSEvent*)event { - (BOOL)performKeyEquivalent:(NSEvent*)event {
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#import "ui/views/cocoa/bridged_native_widget_host_impl.h" #import "ui/views/cocoa/bridged_native_widget_host_impl.h"
#include "ui/views/cocoa/cocoa_mouse_capture.h" #include "ui/views/cocoa/cocoa_mouse_capture.h"
#import "ui/views/cocoa/drag_drop_client_mac.h" #import "ui/views/cocoa/drag_drop_client_mac.h"
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#import "ui/views/cocoa/views_nswindow_delegate.h" #import "ui/views/cocoa/views_nswindow_delegate.h"
#include "ui/views/widget/drop_helper.h" #include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -129,9 +128,10 @@ int NativeWidgetMac::SheetPositionY() { ...@@ -129,9 +128,10 @@ int NativeWidgetMac::SheetPositionY() {
void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
ownership_ = params.ownership; ownership_ = params.ownership;
name_ = params.name; name_ = params.name;
base::scoped_nsobject<NSWindow> window([CreateNSWindow(params) retain]); base::scoped_nsobject<NativeWidgetMacNSWindow> window(
[window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. [CreateNSWindow(params) retain]);
bridge()->Init(window, params); bridge()->SetWindow(window);
bridge()->Init(params);
// Only set always-on-top here if it is true since setting it may affect how // Only set always-on-top here if it is true since setting it may affect how
// the window is treated by Expose. // the window is treated by Expose.
......
...@@ -56,18 +56,6 @@ ...@@ -56,18 +56,6 @@
- (BOOL)_isTitleHidden; - (BOOL)_isTitleHidden;
@end @end
// Test NSWindow that provides hooks via method overrides to verify behavior.
@interface NativeWidgetMacTestWindow : NativeWidgetMacNSWindow {
@private
int invalidateShadowCount_;
int orderWindowCount_;
bool* deallocFlag_;
}
@property(readonly, nonatomic) int invalidateShadowCount;
@property(readonly, nonatomic) int orderWindowCount;
@property(assign, nonatomic) bool* deallocFlag;
@end
// Used to mock BridgedContentView so that calls to drawRect: can be // Used to mock BridgedContentView so that calls to drawRect: can be
// intercepted. // intercepted.
@interface MockBridgedView : NSView { @interface MockBridgedView : NSView {
...@@ -121,33 +109,6 @@ class BridgedNativeWidgetTestApi { ...@@ -121,33 +109,6 @@ class BridgedNativeWidgetTestApi {
DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTestApi); DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTestApi);
}; };
// Custom native_widget to create a NativeWidgetMacTestWindow.
class TestWindowNativeWidgetMac : public NativeWidgetMac {
public:
explicit TestWindowNativeWidgetMac(Widget* delegate)
: NativeWidgetMac(delegate) {}
protected:
// NativeWidgetMac:
NativeWidgetMacNSWindow* CreateNSWindow(
const Widget::InitParams& params) override {
NSUInteger style_mask = NSBorderlessWindowMask;
if (params.type == Widget::InitParams::TYPE_WINDOW) {
style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask |
NSClosableWindowMask | NSMiniaturizableWindowMask |
NSResizableWindowMask;
}
return [[[NativeWidgetMacTestWindow alloc]
initWithContentRect:ui::kWindowSizeDeterminedLater
styleMask:style_mask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
}
private:
DISALLOW_COPY_AND_ASSIGN(TestWindowNativeWidgetMac);
};
// Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which // Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which
// need access to Cocoa APIs. // need access to Cocoa APIs.
class NativeWidgetMacTest : public WidgetTest { class NativeWidgetMacTest : public WidgetTest {
...@@ -174,14 +135,14 @@ class NativeWidgetMacTest : public WidgetTest { ...@@ -174,14 +135,14 @@ class NativeWidgetMacTest : public WidgetTest {
return MakeNativeParentWithStyle(NSBorderlessWindowMask); return MakeNativeParentWithStyle(NSBorderlessWindowMask);
} }
// Create a Widget backed by the NativeWidgetMacTestWindow NSWindow subclass. // Create a Widget backed by the NativeWidgetMacNSWindow NSWindow subclass.
Widget* CreateWidgetWithTestWindow(Widget::InitParams params, Widget* CreateWidgetWithTestWindow(Widget::InitParams params,
NativeWidgetMacTestWindow** window) { NativeWidgetMacNSWindow** window) {
Widget* widget = new Widget; Widget* widget = new Widget;
params.native_widget = new TestWindowNativeWidgetMac(widget); params.native_widget = new NativeWidgetMac(widget);
widget->Init(params); widget->Init(params);
widget->Show(); widget->Show();
*window = base::mac::ObjCCastStrict<NativeWidgetMacTestWindow>( *window = base::mac::ObjCCastStrict<NativeWidgetMacNSWindow>(
widget->GetNativeWindow()); widget->GetNativeWindow());
EXPECT_TRUE(*window); EXPECT_TRUE(*window);
return widget; return widget;
...@@ -469,8 +430,8 @@ TEST_F(NativeWidgetMacTest, DISABLED_OrderFrontAfterMiniaturize) { ...@@ -469,8 +430,8 @@ TEST_F(NativeWidgetMacTest, DISABLED_OrderFrontAfterMiniaturize) {
// Test that ShowInactive() on already-visible child widgets is ignored, since // Test that ShowInactive() on already-visible child widgets is ignored, since
// it may cause a space transition. See https://crbug.com/866760. // it may cause a space transition. See https://crbug.com/866760.
TEST_F(NativeWidgetMacTest, ShowInactiveOnChildWidget) { TEST_F(NativeWidgetMacTest, ShowInactiveOnChildWidget) {
NativeWidgetMacTestWindow* parent_window; NativeWidgetMacNSWindow* parent_window;
NativeWidgetMacTestWindow* child_window; NativeWidgetMacNSWindow* child_window;
Widget::InitParams init_params = Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW); CreateParams(Widget::InitParams::TYPE_WINDOW);
...@@ -478,28 +439,29 @@ TEST_F(NativeWidgetMacTest, ShowInactiveOnChildWidget) { ...@@ -478,28 +439,29 @@ TEST_F(NativeWidgetMacTest, ShowInactiveOnChildWidget) {
Widget* parent = CreateWidgetWithTestWindow(init_params, &parent_window); Widget* parent = CreateWidgetWithTestWindow(init_params, &parent_window);
// CreateWidgetWithTestWindow calls Show() // CreateWidgetWithTestWindow calls Show()
EXPECT_EQ(1, [parent_window orderWindowCount]); EXPECT_EQ(1, [parent_window orderWindowCountForTesting]);
init_params.parent = parent->GetNativeView(); init_params.parent = parent->GetNativeView();
Widget* child = CreateWidgetWithTestWindow(init_params, &child_window); Widget* child = CreateWidgetWithTestWindow(init_params, &child_window);
// The child is ordered twice, once by Show() and again (by AppKit) when it is // The child is ordered twice, once by Show() and again (by AppKit) when it is
// registered as a child window. // registered as a child window.
EXPECT_EQ(2, [child_window orderWindowCount]); EXPECT_EQ(2, [child_window orderWindowCountForTesting]);
// Parent is unchanged. // Parent is unchanged.
EXPECT_EQ(1, [parent_window orderWindowCount]); EXPECT_EQ(1, [parent_window orderWindowCountForTesting]);
// ShowInactive() on a visible regular window may serve to raise its stacking // ShowInactive() on a visible regular window may serve to raise its stacking
// order without taking focus, so it should invoke -[NSWindow orderWindow:..]. // order without taking focus, so it should invoke -[NSWindow orderWindow:..].
parent->ShowInactive(); parent->ShowInactive();
EXPECT_EQ(2, [parent_window orderWindowCount]); // Increases. EXPECT_EQ(2, [parent_window orderWindowCountForTesting]); // Increases.
// However, ShowInactive() on the child should have no effect. It should // However, ShowInactive() on the child should have no effect. It should
// already be in a correct stacking order and we must avoid a Space switch. // already be in a correct stacking order and we must avoid a Space switch.
child->ShowInactive(); child->ShowInactive();
EXPECT_EQ(2, [child_window orderWindowCount]); // No change. EXPECT_EQ(2, [child_window orderWindowCountForTesting]); // No change.
EXPECT_EQ(2, [parent_window orderWindowCount]); // Parent also unchanged. EXPECT_EQ(
2, [parent_window orderWindowCountForTesting]); // Parent also unchanged.
parent->CloseNow(); parent->CloseNow();
} }
...@@ -876,13 +838,13 @@ TEST_F(NativeWidgetMacTest, NonWidgetParentLastReference) { ...@@ -876,13 +838,13 @@ TEST_F(NativeWidgetMacTest, NonWidgetParentLastReference) {
TestNativeParentWindow* native_parent = MakeNativeParent(); TestNativeParentWindow* native_parent = MakeNativeParent();
[native_parent setDeallocFlag:&native_parent_dealloced]; [native_parent setDeallocFlag:&native_parent_dealloced];
NativeWidgetMacTestWindow* window; NativeWidgetMacNSWindow* window;
Widget::InitParams init_params = Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_POPUP); CreateParams(Widget::InitParams::TYPE_POPUP);
init_params.parent = [native_parent_ contentView]; init_params.parent = [native_parent_ contentView];
init_params.bounds = gfx::Rect(0, 0, 100, 200); init_params.bounds = gfx::Rect(0, 0, 100, 200);
CreateWidgetWithTestWindow(init_params, &window); CreateWidgetWithTestWindow(init_params, &window);
[window setDeallocFlag:&child_dealloced]; [window setDeallocFlagForTesting:&child_dealloced];
} }
{ {
// On 10.11, closing a weak reference on the parent window works, but older // On 10.11, closing a weak reference on the parent window works, but older
...@@ -1795,7 +1757,7 @@ TEST_F(NativeWidgetMacTest, DoesHideTitle) { ...@@ -1795,7 +1757,7 @@ TEST_F(NativeWidgetMacTest, DoesHideTitle) {
// Test calls to invalidate the shadow when composited frames arrive. // Test calls to invalidate the shadow when composited frames arrive.
TEST_F(NativeWidgetMacTest, InvalidateShadow) { TEST_F(NativeWidgetMacTest, InvalidateShadow) {
NativeWidgetMacTestWindow* window; NativeWidgetMacNSWindow* window;
const gfx::Rect rect(0, 0, 100, 200); const gfx::Rect rect(0, 0, 100, 200);
Widget::InitParams init_params = Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
...@@ -1806,7 +1768,7 @@ TEST_F(NativeWidgetMacTest, InvalidateShadow) { ...@@ -1806,7 +1768,7 @@ TEST_F(NativeWidgetMacTest, InvalidateShadow) {
BridgedNativeWidgetTestApi(window).SimulateFrameSwap(rect.size()); BridgedNativeWidgetTestApi(window).SimulateFrameSwap(rect.size());
// Default is an opaque window, so shadow doesn't need to be invalidated. // Default is an opaque window, so shadow doesn't need to be invalidated.
EXPECT_EQ(0, [window invalidateShadowCount]); EXPECT_EQ(0, [window invalidateShadowCountForTesting]);
widget->CloseNow(); widget->CloseNow();
init_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; init_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW;
...@@ -1814,40 +1776,40 @@ TEST_F(NativeWidgetMacTest, InvalidateShadow) { ...@@ -1814,40 +1776,40 @@ TEST_F(NativeWidgetMacTest, InvalidateShadow) {
BridgedNativeWidgetTestApi test_api(window); BridgedNativeWidgetTestApi test_api(window);
// First paint on a translucent window needs to invalidate the shadow. Once. // First paint on a translucent window needs to invalidate the shadow. Once.
EXPECT_EQ(0, [window invalidateShadowCount]); EXPECT_EQ(0, [window invalidateShadowCountForTesting]);
test_api.SimulateFrameSwap(rect.size()); test_api.SimulateFrameSwap(rect.size());
EXPECT_EQ(1, [window invalidateShadowCount]); EXPECT_EQ(1, [window invalidateShadowCountForTesting]);
test_api.SimulateFrameSwap(rect.size()); test_api.SimulateFrameSwap(rect.size());
EXPECT_EQ(1, [window invalidateShadowCount]); EXPECT_EQ(1, [window invalidateShadowCountForTesting]);
// Resizing the window also needs to trigger a shadow invalidation. // Resizing the window also needs to trigger a shadow invalidation.
[window setContentSize:NSMakeSize(123, 456)]; [window setContentSize:NSMakeSize(123, 456)];
// A "late" frame swap at the old size should do nothing. // A "late" frame swap at the old size should do nothing.
test_api.SimulateFrameSwap(rect.size()); test_api.SimulateFrameSwap(rect.size());
EXPECT_EQ(1, [window invalidateShadowCount]); EXPECT_EQ(1, [window invalidateShadowCountForTesting]);
test_api.SimulateFrameSwap(gfx::Size(123, 456)); test_api.SimulateFrameSwap(gfx::Size(123, 456));
EXPECT_EQ(2, [window invalidateShadowCount]); EXPECT_EQ(2, [window invalidateShadowCountForTesting]);
test_api.SimulateFrameSwap(gfx::Size(123, 456)); test_api.SimulateFrameSwap(gfx::Size(123, 456));
EXPECT_EQ(2, [window invalidateShadowCount]); EXPECT_EQ(2, [window invalidateShadowCountForTesting]);
// Hiding the window does not require shadow invalidation. // Hiding the window does not require shadow invalidation.
widget->Hide(); widget->Hide();
test_api.SimulateFrameSwap(gfx::Size(123, 456)); test_api.SimulateFrameSwap(gfx::Size(123, 456));
EXPECT_EQ(2, [window invalidateShadowCount]); EXPECT_EQ(2, [window invalidateShadowCountForTesting]);
// Showing a translucent window after hiding it, should trigger shadow // Showing a translucent window after hiding it, should trigger shadow
// invalidation. // invalidation.
widget->Show(); widget->Show();
test_api.SimulateFrameSwap(gfx::Size(123, 456)); test_api.SimulateFrameSwap(gfx::Size(123, 456));
EXPECT_EQ(3, [window invalidateShadowCount]); EXPECT_EQ(3, [window invalidateShadowCountForTesting]);
widget->CloseNow(); widget->CloseNow();
} }
// Test that the contentView opacity corresponds to the window type. // Test that the contentView opacity corresponds to the window type.
TEST_F(NativeWidgetMacTest, ContentOpacity) { TEST_F(NativeWidgetMacTest, ContentOpacity) {
NativeWidgetMacTestWindow* window; NativeWidgetMacNSWindow* window;
Widget::InitParams init_params = Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
...@@ -2376,33 +2338,6 @@ TEST_F(NativeWidgetMacTest, TouchBar) { ...@@ -2376,33 +2338,6 @@ TEST_F(NativeWidgetMacTest, TouchBar) {
} }
@end @end
@implementation NativeWidgetMacTestWindow
@synthesize invalidateShadowCount = invalidateShadowCount_;
@synthesize orderWindowCount = orderWindowCount_;
@synthesize deallocFlag = deallocFlag_;
- (void)dealloc {
if (deallocFlag_) {
DCHECK(!*deallocFlag_);
*deallocFlag_ = true;
}
[super dealloc];
}
- (void)invalidateShadow {
++invalidateShadowCount_;
[super invalidateShadow];
}
- (void)orderWindow:(NSWindowOrderingMode)orderingMode
relativeTo:(NSInteger)otherWindowNumber {
++orderWindowCount_;
[super orderWindow:orderingMode relativeTo:otherWindowNumber];
}
@end
@implementation MockBridgedView @implementation MockBridgedView
@synthesize drawRectCount = drawRectCount_; @synthesize drawRectCount = drawRectCount_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment