| 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 #include "ui/views/test/widget_test.h" | 5 #include "ui/views/test/widget_test.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #import "base/mac/scoped_objc_class_swizzler.h" | 10 #import "base/mac/scoped_objc_class_swizzler.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #import "ui/views/cocoa/bridged_native_widget.h" | 12 #import "ui/views/cocoa/bridged_native_widget.h" |
| 13 #include "ui/views/widget/native_widget_mac.h" | 13 #include "ui/views/widget/native_widget_mac.h" |
| 14 #include "ui/views/widget/root_view.h" | 14 #include "ui/views/widget/root_view.h" |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 namespace test { | 17 namespace test { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // The NSWindow last activated by SimulateNativeActivate(). It will have a | 21 // The NSWindow last activated by SimulateNativeActivate(). It will have a |
| 22 // simulated deactivate on a subsequent call. | 22 // simulated deactivate on a subsequent call. |
| 23 NSWindow* g_simulated_active_window_ = nil; | 23 NSWindow* g_simulated_active_window_ = nil; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 void WidgetTest::SimulateNativeDestroy(Widget* widget) { | |
| 29 // Retain the window while closing it, otherwise the window may lose its last | |
| 30 // owner before -[NSWindow close] completes (this offends AppKit). Usually | |
| 31 // this reference will exist on an event delivered to the runloop. | |
| 32 base::scoped_nsobject<NSWindow> window([widget->GetNativeWindow() retain]); | |
| 33 [window close]; | |
| 34 } | |
| 35 | |
| 36 // static | |
| 37 void WidgetTest::SimulateNativeActivate(Widget* widget) { | 28 void WidgetTest::SimulateNativeActivate(Widget* widget) { |
| 38 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 29 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 39 if (g_simulated_active_window_) { | 30 if (g_simulated_active_window_) { |
| 40 [center postNotificationName:NSWindowDidResignKeyNotification | 31 [center postNotificationName:NSWindowDidResignKeyNotification |
| 41 object:g_simulated_active_window_]; | 32 object:g_simulated_active_window_]; |
| 42 } | 33 } |
| 43 | 34 |
| 44 g_simulated_active_window_ = widget->GetNativeWindow(); | 35 g_simulated_active_window_ = widget->GetNativeWindow(); |
| 45 DCHECK(g_simulated_active_window_); | 36 DCHECK(g_simulated_active_window_); |
| 46 | 37 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return NativeWidgetMac::GetBridgeForNativeWindow(widget->GetNativeWindow()); | 80 return NativeWidgetMac::GetBridgeForNativeWindow(widget->GetNativeWindow()); |
| 90 } | 81 } |
| 91 | 82 |
| 92 // static | 83 // static |
| 93 bool WidgetTest::IsNativeWindowTransparent(gfx::NativeWindow window) { | 84 bool WidgetTest::IsNativeWindowTransparent(gfx::NativeWindow window) { |
| 94 return ![window isOpaque]; | 85 return ![window isOpaque]; |
| 95 } | 86 } |
| 96 | 87 |
| 97 } // namespace test | 88 } // namespace test |
| 98 } // namespace views | 89 } // namespace views |
| OLD | NEW |