OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ | 5 #ifndef IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ |
6 #define IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ | 6 #define IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ |
7 | 7 |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 // Sets temporary key window and returns it via Get method. Saves the current | 10 // Sets temporary key window and returns it via Get method. Saves the current |
11 // key window and restores it on destruction. | 11 // key window and restores it on destruction. |
12 class ScopedKeyWindow { | 12 class ScopedKeyWindow { |
13 public: | 13 public: |
14 explicit ScopedKeyWindow() | 14 explicit ScopedKeyWindow() |
15 : current_key_window_( | 15 : current_key_window_( |
16 [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]), | 16 [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]), |
17 original_key_window_([UIApplication sharedApplication].keyWindow) { | 17 original_key_window_([UIApplication sharedApplication].keyWindow) { |
18 [current_key_window_ makeKeyAndVisible]; | 18 [current_key_window_ makeKeyAndVisible]; |
19 } | 19 } |
20 ~ScopedKeyWindow() { [original_key_window_ makeKeyAndVisible]; } | 20 ~ScopedKeyWindow() { [original_key_window_ makeKeyAndVisible]; } |
21 UIWindow* Get() { return current_key_window_; } | 21 UIWindow* Get() { return current_key_window_; } |
22 | 22 |
23 private: | 23 private: |
24 UIWindow* current_key_window_; | 24 __strong UIWindow* current_key_window_; |
25 UIWindow* original_key_window_; | 25 __strong UIWindow* original_key_window_; |
26 }; | 26 }; |
27 | 27 |
28 #endif // IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ | 28 #endif // IOS_CHROME_TEST_SCOPED_KEY_WINDOW_H_ |
OLD | NEW |