| 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 @interface IsKeyWindowDonor : NSObject | |
| 17 @end | |
| 18 | |
| 19 @implementation IsKeyWindowDonor | |
| 20 - (BOOL)isKeyWindow { | |
| 21 return YES; | |
| 22 } | |
| 23 @end | |
| 24 | |
| 25 namespace views { | 16 namespace views { |
| 26 namespace test { | 17 namespace test { |
| 27 | 18 |
| 28 namespace { | 19 namespace { |
| 29 | 20 |
| 30 class FakeActivationMac : public WidgetTest::FakeActivation { | |
| 31 public: | |
| 32 FakeActivationMac() | |
| 33 : swizzler_([NSWindow class], | |
| 34 [IsKeyWindowDonor class], | |
| 35 @selector(isKeyWindow)) {} | |
| 36 | |
| 37 private: | |
| 38 base::mac::ScopedObjCClassSwizzler swizzler_; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(FakeActivationMac); | |
| 41 }; | |
| 42 | |
| 43 // The NSWindow last activated by SimulateNativeActivate(). It will have a | 21 // The NSWindow last activated by SimulateNativeActivate(). It will have a |
| 44 // simulated deactivate on a subsequent call. | 22 // simulated deactivate on a subsequent call. |
| 45 NSWindow* g_simulated_active_window_ = nil; | 23 NSWindow* g_simulated_active_window_ = nil; |
| 46 | 24 |
| 47 } // namespace | 25 } // namespace |
| 48 | 26 |
| 49 // static | 27 // static |
| 50 void WidgetTest::SimulateNativeDestroy(Widget* widget) { | 28 void WidgetTest::SimulateNativeDestroy(Widget* widget) { |
| 51 // Retain the window while closing it, otherwise the window may lose its last | 29 // Retain the window while closing it, otherwise the window may lose its last |
| 52 // owner before -[NSWindow close] completes (this offends AppKit). Usually | 30 // owner before -[NSWindow close] completes (this offends AppKit). Usually |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 gfx::Size WidgetTest::GetNativeWidgetMinimumContentSize(Widget* widget) { | 78 gfx::Size WidgetTest::GetNativeWidgetMinimumContentSize(Widget* widget) { |
| 101 return gfx::Size([widget->GetNativeWindow() contentMinSize]); | 79 return gfx::Size([widget->GetNativeWindow() contentMinSize]); |
| 102 } | 80 } |
| 103 | 81 |
| 104 // static | 82 // static |
| 105 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { | 83 ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) { |
| 106 return static_cast<internal::RootView*>(widget->GetRootView()); | 84 return static_cast<internal::RootView*>(widget->GetRootView()); |
| 107 } | 85 } |
| 108 | 86 |
| 109 // static | 87 // static |
| 110 scoped_ptr<WidgetTest::FakeActivation> WidgetTest::FakeWidgetIsActiveAlways() { | |
| 111 return make_scoped_ptr(new FakeActivationMac); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget( | 88 ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget( |
| 116 Widget* widget) { | 89 Widget* widget) { |
| 117 return NativeWidgetMac::GetBridgeForNativeWindow(widget->GetNativeWindow()); | 90 return NativeWidgetMac::GetBridgeForNativeWindow(widget->GetNativeWindow()); |
| 118 } | 91 } |
| 119 | 92 |
| 120 } // namespace test | 93 } // namespace test |
| 121 } // namespace views | 94 } // namespace views |
| OLD | NEW |