1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/views/test/widget_test.h" 6 7 #include "ui/gfx/native_widget_types.h" 8 #include "ui/views/widget/root_view.h" 9 10 namespace views { 11 namespace test { 12 13 // A widget that assumes mouse capture always works. It won't on Aura in 14 // testing, so we mock it. 15 #if defined(USE_AURA) 16 NativeWidgetCapture::NativeWidgetCapture( 17 internal::NativeWidgetDelegate* delegate) 18 : NativeWidgetPlatform(delegate), 19 mouse_capture_(false) {} 20 NativeWidgetCapture::~NativeWidgetCapture() {} 21 22 void NativeWidgetCapture::SetCapture() { 23 mouse_capture_ = true; 24 } 25 26 void NativeWidgetCapture::ReleaseCapture() { 27 if (mouse_capture_) 28 delegate()->OnMouseCaptureLost(); 29 mouse_capture_ = false; 30 } 31 32 bool NativeWidgetCapture::HasCapture() const { 33 return mouse_capture_; 34 } 35 #endif 36 37 WidgetTest::WidgetTest() {} 38 WidgetTest::~WidgetTest() {} 39 40 NativeWidget* WidgetTest::CreatePlatformNativeWidget( 41 internal::NativeWidgetDelegate* delegate) { 42 return new NativeWidgetPlatformForTest(delegate); 43 } 44 45 Widget* WidgetTest::CreateTopLevelPlatformWidget() { 46 Widget* toplevel = new Widget; 47 Widget::InitParams toplevel_params = 48 CreateParams(Widget::InitParams::TYPE_WINDOW); 49 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel); 50 toplevel->Init(toplevel_params); 51 return toplevel; 52 } 53 54 Widget* WidgetTest::CreateTopLevelFramelessPlatformWidget() { 55 Widget* toplevel = new Widget; 56 Widget::InitParams toplevel_params = 57 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 58 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel); 59 toplevel->Init(toplevel_params); 60 return toplevel; 61 } 62 63 Widget* WidgetTest::CreateChildPlatformWidget( 64 gfx::NativeView parent_native_view) { 65 Widget* child = new Widget; 66 Widget::InitParams child_params = 67 CreateParams(Widget::InitParams::TYPE_CONTROL); 68 child_params.native_widget = CreatePlatformNativeWidget(child); 69 child_params.parent = parent_native_view; 70 child->Init(child_params); 71 child->SetContentsView(new View); 72 return child; 73 } 74 75 #if defined(OS_WIN) && !defined(USE_AURA) 76 // On Windows, it is possible for us to have a child window that is 77 // TYPE_POPUP. 78 Widget* WidgetTest::CreateChildPopupPlatformWidget( 79 gfx::NativeView parent_native_view) { 80 Widget* child = new Widget; 81 Widget::InitParams child_params = 82 CreateParams(Widget::InitParams::TYPE_POPUP); 83 child_params.child = true; 84 child_params.native_widget = CreatePlatformNativeWidget(child); 85 child_params.parent = parent_native_view; 86 child->Init(child_params); 87 child->SetContentsView(new View); 88 return child; 89 } 90 #endif 91 92 Widget* WidgetTest::CreateTopLevelNativeWidget() { 93 Widget* toplevel = new Widget; 94 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 95 toplevel->Init(params); 96 return toplevel; 97 } 98 99 Widget* WidgetTest::CreateChildNativeWidgetWithParent(Widget* parent) { 100 Widget* child = new Widget; 101 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL); 102 params.parent = parent->GetNativeView(); 103 child->Init(params); 104 child->SetContentsView(new View); 105 return child; 106 } 107 108 Widget* WidgetTest::CreateChildNativeWidget() { 109 return CreateChildNativeWidgetWithParent(NULL); 110 } 111 112 View* WidgetTest::GetMousePressedHandler(internal::RootView* root_view) { 113 return root_view->mouse_pressed_handler_; 114 } 115 116 View* WidgetTest::GetMouseMoveHandler(internal::RootView* root_view) { 117 return root_view->mouse_move_handler_; 118 } 119 120 View* WidgetTest::GetGestureHandler(internal::RootView* root_view) { 121 return root_view->gesture_handler_; 122 } 123 124 } // namespace test 125 } // namespace views 126