OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base/test/scoped_fake_nswindow_fullscreen.h" | 5 #import "ui/base/test/scoped_fake_nswindow_fullscreen.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
11 #import "base/mac/mac_util.h" | 11 #import "base/mac/mac_util.h" |
12 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
13 #import "base/mac/scoped_objc_class_swizzler.h" | 13 #import "base/mac/scoped_objc_class_swizzler.h" |
14 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" |
18 | 19 |
19 // This method exists on NSWindowDelegate on 10.7+. | 20 // This method exists on NSWindowDelegate on 10.7+. |
20 // To build on 10.6, we just need to declare it somewhere. We'll test | 21 // To build on 10.6, we just need to declare it somewhere. We'll test |
21 // -[NSObject respondsToSelector] before calling it. | 22 // -[NSObject respondsToSelector] before calling it. |
22 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 23 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
23 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 | 24 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 |
24 @protocol NSWindowDelegateLion | 25 @protocol NSWindowDelegateLion |
25 - (NSSize)window:(NSWindow*)window | 26 - (NSSize)window:(NSWindow*)window |
26 willUseFullScreenContentSize:(NSSize)proposedSize; | 27 willUseFullScreenContentSize:(NSSize)proposedSize; |
27 @end | 28 @end |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 fullscreen_content_size = [delegate window:window | 110 fullscreen_content_size = [delegate window:window |
110 willUseFullScreenContentSize:fullscreen_content_size]; | 111 willUseFullScreenContentSize:fullscreen_content_size]; |
111 } | 112 } |
112 [[NSNotificationCenter defaultCenter] | 113 [[NSNotificationCenter defaultCenter] |
113 postNotificationName:NSWindowWillEnterFullScreenNotification | 114 postNotificationName:NSWindowWillEnterFullScreenNotification |
114 object:window]; | 115 object:window]; |
115 // Starting with 10.11, OSX also posts LiveResize notifications. | 116 // Starting with 10.11, OSX also posts LiveResize notifications. |
116 [[NSNotificationCenter defaultCenter] | 117 [[NSNotificationCenter defaultCenter] |
117 postNotificationName:NSWindowWillStartLiveResizeNotification | 118 postNotificationName:NSWindowWillStartLiveResizeNotification |
118 object:window]; | 119 object:window]; |
119 base::MessageLoopForUI::current()->PostTask( | 120 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 121 base::ThreadTaskRunnerHandle::Get()->PostTask( |
120 FROM_HERE, base::Bind(&Impl::FinishEnterFullscreen, | 122 FROM_HERE, base::Bind(&Impl::FinishEnterFullscreen, |
121 base::Unretained(this), fullscreen_content_size)); | 123 base::Unretained(this), fullscreen_content_size)); |
122 } | 124 } |
123 | 125 |
124 void FinishEnterFullscreen(NSSize fullscreen_content_size) { | 126 void FinishEnterFullscreen(NSSize fullscreen_content_size) { |
125 // The frame should not have changed during the transition. | 127 // The frame should not have changed during the transition. |
126 DCHECK(NSEqualRects(frame_before_fullscreen_, [window_ frame])); | 128 DCHECK(NSEqualRects(frame_before_fullscreen_, [window_ frame])); |
127 | 129 |
128 // Style mask must be set first because -[NSWindow frame] may be different | 130 // Style mask must be set first because -[NSWindow frame] may be different |
129 // depending on NSFullScreenWindowMask. Don't call -[NSWindow setStyleMask:] | 131 // depending on NSFullScreenWindowMask. Don't call -[NSWindow setStyleMask:] |
(...skipping 17 matching lines...) Expand all Loading... |
147 frame_during_fullscreen_ = [window_ frame]; | 149 frame_during_fullscreen_ = [window_ frame]; |
148 is_in_transition_ = false; | 150 is_in_transition_ = false; |
149 } | 151 } |
150 | 152 |
151 void StartExitFullscreen() { | 153 void StartExitFullscreen() { |
152 is_in_transition_ = true; | 154 is_in_transition_ = true; |
153 [[NSNotificationCenter defaultCenter] | 155 [[NSNotificationCenter defaultCenter] |
154 postNotificationName:NSWindowWillExitFullScreenNotification | 156 postNotificationName:NSWindowWillExitFullScreenNotification |
155 object:window_]; | 157 object:window_]; |
156 | 158 |
157 base::MessageLoopForUI::current()->PostTask( | 159 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 160 base::ThreadTaskRunnerHandle::Get()->PostTask( |
158 FROM_HERE, | 161 FROM_HERE, |
159 base::Bind(&Impl::FinishExitFullscreen, base::Unretained(this))); | 162 base::Bind(&Impl::FinishExitFullscreen, base::Unretained(this))); |
160 } | 163 } |
161 | 164 |
162 void FinishExitFullscreen() { | 165 void FinishExitFullscreen() { |
163 // The bounds may have changed during the transition. Check for this before | 166 // The bounds may have changed during the transition. Check for this before |
164 // setting the style mask because -[NSWindow frame] may be different | 167 // setting the style mask because -[NSWindow frame] may be different |
165 // depending on NSFullScreenWindowMask. | 168 // depending on NSFullScreenWindowMask. |
166 bool no_frame_change_during_fullscreen = | 169 bool no_frame_change_during_fullscreen = |
167 NSEqualRects(frame_during_fullscreen_, [window_ frame]); | 170 NSEqualRects(frame_during_fullscreen_, [window_ frame]); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if ((newMask ^ currentMask) & NSFullScreenWindowMask) { | 240 if ((newMask ^ currentMask) & NSFullScreenWindowMask) { |
238 // Since 10.11, OSX triggers fullscreen transitions via setStyleMask, but | 241 // Since 10.11, OSX triggers fullscreen transitions via setStyleMask, but |
239 // the faker doesn't attempt to fake them yet. | 242 // the faker doesn't attempt to fake them yet. |
240 NOTREACHED() << "Can't set NSFullScreenWindowMask while faking fullscreen."; | 243 NOTREACHED() << "Can't set NSFullScreenWindowMask while faking fullscreen."; |
241 } | 244 } |
242 newMask &= ~NSFullScreenWindowMask; | 245 newMask &= ~NSFullScreenWindowMask; |
243 g_fake_fullscreen_impl->SetStyleMaskImplementation()(self, _cmd, newMask); | 246 g_fake_fullscreen_impl->SetStyleMaskImplementation()(self, _cmd, newMask); |
244 } | 247 } |
245 | 248 |
246 @end | 249 @end |
OLD | NEW |