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.
5 #include "ui/views/test/widget_test.h"
7 #include "ui/gfx/native_widget_types.h"
8 #include "ui/views/widget/root_view.h"
13 // A widget that assumes mouse capture always works. It won't in testing, so we
15 NativeWidgetCapture::NativeWidgetCapture(
16 internal::NativeWidgetDelegate
* delegate
)
17 : PlatformNativeWidget(delegate
),
18 mouse_capture_(false) {}
20 NativeWidgetCapture::~NativeWidgetCapture() {}
22 void NativeWidgetCapture::SetCapture() {
23 mouse_capture_
= true;
26 void NativeWidgetCapture::ReleaseCapture() {
28 delegate()->OnMouseCaptureLost();
29 mouse_capture_
= false;
32 bool NativeWidgetCapture::HasCapture() const {
33 return mouse_capture_
;
36 WidgetTest::WidgetTest() {}
37 WidgetTest::~WidgetTest() {}
39 NativeWidget
* WidgetTest::CreatePlatformNativeWidget(
40 internal::NativeWidgetDelegate
* delegate
) {
41 return new NativeWidgetCapture(delegate
);
44 Widget
* WidgetTest::CreateTopLevelPlatformWidget() {
45 Widget
* toplevel
= new Widget
;
46 Widget::InitParams toplevel_params
=
47 CreateParams(Widget::InitParams::TYPE_WINDOW
);
48 toplevel_params
.native_widget
= CreatePlatformNativeWidget(toplevel
);
49 toplevel
->Init(toplevel_params
);
53 Widget
* WidgetTest::CreateTopLevelFramelessPlatformWidget() {
54 Widget
* toplevel
= new Widget
;
55 Widget::InitParams toplevel_params
=
56 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS
);
57 toplevel_params
.native_widget
= CreatePlatformNativeWidget(toplevel
);
58 toplevel
->Init(toplevel_params
);
62 Widget
* WidgetTest::CreateChildPlatformWidget(
63 gfx::NativeView parent_native_view
) {
64 Widget
* child
= new Widget
;
65 Widget::InitParams child_params
=
66 CreateParams(Widget::InitParams::TYPE_CONTROL
);
67 child_params
.native_widget
= CreatePlatformNativeWidget(child
);
68 child_params
.parent
= parent_native_view
;
69 child
->Init(child_params
);
70 child
->SetContentsView(new View
);
74 Widget
* WidgetTest::CreateTopLevelNativeWidget() {
75 Widget
* toplevel
= new Widget
;
76 Widget::InitParams params
= CreateParams(Widget::InitParams::TYPE_WINDOW
);
77 toplevel
->Init(params
);
81 Widget
* WidgetTest::CreateChildNativeWidgetWithParent(Widget
* parent
) {
82 Widget
* child
= new Widget
;
83 Widget::InitParams params
= CreateParams(Widget::InitParams::TYPE_CONTROL
);
84 params
.parent
= parent
->GetNativeView();
86 child
->SetContentsView(new View
);
90 Widget
* WidgetTest::CreateChildNativeWidget() {
91 return CreateChildNativeWidgetWithParent(NULL
);
94 View
* WidgetTest::GetMousePressedHandler(internal::RootView
* root_view
) {
95 return root_view
->mouse_pressed_handler_
;
98 View
* WidgetTest::GetMouseMoveHandler(internal::RootView
* root_view
) {
99 return root_view
->mouse_move_handler_
;
102 View
* WidgetTest::GetGestureHandler(internal::RootView
* root_view
) {
103 return root_view
->gesture_handler_
;