OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ui/views/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 @interface ConstrainedWindowAnimationBase (TestingAPI) | 39 @interface ConstrainedWindowAnimationBase (TestingAPI) |
40 - (void)setWindowStateForEnd; | 40 - (void)setWindowStateForEnd; |
41 @end | 41 @end |
42 | 42 |
43 @interface NSWindow (PrivateAPI) | 43 @interface NSWindow (PrivateAPI) |
44 - (BOOL)_isTitleHidden; | 44 - (BOOL)_isTitleHidden; |
45 @end | 45 @end |
46 | 46 |
47 // Test NSWindow that provides hooks via method overrides to verify behavior. | 47 // Test NSWindow that provides hooks via method overrides to verify behavior. |
48 @interface NativeWidetMacTestWindow : NativeWidgetMacNSWindow { | 48 @interface NativeWidgetMacTestWindow : NativeWidgetMacNSWindow { |
49 @private | 49 @private |
50 int invalidateShadowCount_; | 50 int invalidateShadowCount_; |
51 } | 51 } |
52 @property(readonly, nonatomic) int invalidateShadowCount; | 52 @property(readonly, nonatomic) int invalidateShadowCount; |
53 @end | 53 @end |
54 | 54 |
55 namespace views { | 55 namespace views { |
56 namespace test { | 56 namespace test { |
57 | 57 |
58 // BridgedNativeWidget friend to access private members. | 58 // BridgedNativeWidget friend to access private members. |
(...skipping 21 matching lines...) Expand all Loading... |
80 }; | 80 }; |
81 | 81 |
82 // Custom native_widget to create a NativeWidgetMacTestWindow. | 82 // Custom native_widget to create a NativeWidgetMacTestWindow. |
83 class TestWindowNativeWidgetMac : public NativeWidgetMac { | 83 class TestWindowNativeWidgetMac : public NativeWidgetMac { |
84 public: | 84 public: |
85 explicit TestWindowNativeWidgetMac(Widget* delegate) | 85 explicit TestWindowNativeWidgetMac(Widget* delegate) |
86 : NativeWidgetMac(delegate) {} | 86 : NativeWidgetMac(delegate) {} |
87 | 87 |
88 protected: | 88 protected: |
89 // NativeWidgetMac: | 89 // NativeWidgetMac: |
90 gfx::NativeWindow CreateNSWindow(const Widget::InitParams& params) override { | 90 NativeWidgetMacNSWindow* CreateNSWindow( |
| 91 const Widget::InitParams& params) override { |
91 NSUInteger style_mask = NSBorderlessWindowMask; | 92 NSUInteger style_mask = NSBorderlessWindowMask; |
92 if (params.type == Widget::InitParams::TYPE_WINDOW) { | 93 if (params.type == Widget::InitParams::TYPE_WINDOW) { |
93 style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask | | 94 style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask | |
94 NSClosableWindowMask | NSMiniaturizableWindowMask | | 95 NSClosableWindowMask | NSMiniaturizableWindowMask | |
95 NSResizableWindowMask; | 96 NSResizableWindowMask; |
96 } | 97 } |
97 return [[[NativeWidetMacTestWindow alloc] | 98 return [[[NativeWidgetMacTestWindow alloc] |
98 initWithContentRect:ui::kWindowSizeDeterminedLater | 99 initWithContentRect:ui::kWindowSizeDeterminedLater |
99 styleMask:style_mask | 100 styleMask:style_mask |
100 backing:NSBackingStoreBuffered | 101 backing:NSBackingStoreBuffered |
101 defer:NO] autorelease]; | 102 defer:NO] autorelease]; |
102 } | 103 } |
103 | 104 |
104 private: | 105 private: |
105 DISALLOW_COPY_AND_ASSIGN(TestWindowNativeWidgetMac); | 106 DISALLOW_COPY_AND_ASSIGN(TestWindowNativeWidgetMac); |
106 }; | 107 }; |
107 | 108 |
(...skipping 11 matching lines...) Expand all Loading... |
119 native_parent_.reset( | 120 native_parent_.reset( |
120 [[NSWindow alloc] initWithContentRect:ParentRect() | 121 [[NSWindow alloc] initWithContentRect:ParentRect() |
121 styleMask:NSBorderlessWindowMask | 122 styleMask:NSBorderlessWindowMask |
122 backing:NSBackingStoreBuffered | 123 backing:NSBackingStoreBuffered |
123 defer:NO]); | 124 defer:NO]); |
124 [native_parent_ setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | 125 [native_parent_ setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
125 [native_parent_ makeKeyAndOrderFront:nil]; | 126 [native_parent_ makeKeyAndOrderFront:nil]; |
126 return native_parent_; | 127 return native_parent_; |
127 } | 128 } |
128 | 129 |
129 // Create a Widget backed by the NativeWidetMacTestWindow NSWindow subclass. | 130 // Create a Widget backed by the NativeWidgetMacTestWindow NSWindow subclass. |
130 Widget* CreateWidgetWithTestWindow(Widget::InitParams params, | 131 Widget* CreateWidgetWithTestWindow(Widget::InitParams params, |
131 NativeWidetMacTestWindow** window) { | 132 NativeWidgetMacTestWindow** window) { |
132 Widget* widget = new Widget; | 133 Widget* widget = new Widget; |
133 params.native_widget = new TestWindowNativeWidgetMac(widget); | 134 params.native_widget = new TestWindowNativeWidgetMac(widget); |
134 widget->Init(params); | 135 widget->Init(params); |
135 widget->Show(); | 136 widget->Show(); |
136 *window = base::mac::ObjCCastStrict<NativeWidetMacTestWindow>( | 137 *window = base::mac::ObjCCastStrict<NativeWidgetMacTestWindow>( |
137 widget->GetNativeWindow()); | 138 widget->GetNativeWindow()); |
138 EXPECT_TRUE(*window); | 139 EXPECT_TRUE(*window); |
139 return widget; | 140 return widget; |
140 } | 141 } |
141 | 142 |
142 private: | 143 private: |
143 base::scoped_nsobject<NSWindow> native_parent_; | 144 base::scoped_nsobject<NSWindow> native_parent_; |
144 | 145 |
145 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacTest); | 146 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacTest); |
146 }; | 147 }; |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 // With our magic setting, the window with a title should look the | 917 // With our magic setting, the window with a title should look the |
917 // same as the window with an empty title. | 918 // same as the window with an empty title. |
918 EXPECT_TRUE([ns_window _isTitleHidden]); | 919 EXPECT_TRUE([ns_window _isTitleHidden]); |
919 EXPECT_TRUE([empty_title_data isEqualToData:hidden_title_data]); | 920 EXPECT_TRUE([empty_title_data isEqualToData:hidden_title_data]); |
920 | 921 |
921 widget->CloseNow(); | 922 widget->CloseNow(); |
922 } | 923 } |
923 | 924 |
924 // Test calls to invalidate the shadow when composited frames arrive. | 925 // Test calls to invalidate the shadow when composited frames arrive. |
925 TEST_F(NativeWidgetMacTest, InvalidateShadow) { | 926 TEST_F(NativeWidgetMacTest, InvalidateShadow) { |
926 NativeWidetMacTestWindow* window; | 927 NativeWidgetMacTestWindow* window; |
927 const gfx::Rect rect(0, 0, 100, 200); | 928 const gfx::Rect rect(0, 0, 100, 200); |
928 Widget::InitParams init_params = | 929 Widget::InitParams init_params = |
929 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 930 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
930 init_params.bounds = rect; | 931 init_params.bounds = rect; |
931 Widget* widget = CreateWidgetWithTestWindow(init_params, &window); | 932 Widget* widget = CreateWidgetWithTestWindow(init_params, &window); |
932 | 933 |
933 // Simulate the initial paint. | 934 // Simulate the initial paint. |
934 BridgedNativeWidgetTestApi(window).SimulateFrameSwap(rect.size()); | 935 BridgedNativeWidgetTestApi(window).SimulateFrameSwap(rect.size()); |
935 | 936 |
936 // Default is an opaque window, so shadow doesn't need to be invalidated. | 937 // Default is an opaque window, so shadow doesn't need to be invalidated. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 | 986 |
986 } // namespace test | 987 } // namespace test |
987 } // namespace views | 988 } // namespace views |
988 | 989 |
989 @implementation TestStopAnimationWaiter | 990 @implementation TestStopAnimationWaiter |
990 - (void)setWindowStateForEnd { | 991 - (void)setWindowStateForEnd { |
991 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); | 992 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); |
992 } | 993 } |
993 @end | 994 @end |
994 | 995 |
995 @implementation NativeWidetMacTestWindow | 996 @implementation NativeWidgetMacTestWindow |
996 | 997 |
997 @synthesize invalidateShadowCount = invalidateShadowCount_; | 998 @synthesize invalidateShadowCount = invalidateShadowCount_; |
998 | 999 |
999 - (void)invalidateShadow { | 1000 - (void)invalidateShadow { |
1000 ++invalidateShadowCount_; | 1001 ++invalidateShadowCount_; |
1001 [super invalidateShadow]; | 1002 [super invalidateShadow]; |
1002 } | 1003 } |
1003 | 1004 |
1004 @end | 1005 @end |
OLD | NEW |