Roll src/third_party/WebKit 6f84130:7353389 (svn 184386:184391)
[chromium-blink-merge.git] / ui / views / test / widget_test.cc
blob4f2705d3bd951557069293bca029c30769f57803
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"
10 namespace views {
11 namespace test {
13 // A widget that assumes mouse capture always works. It won't in testing, so we
14 // mock it.
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() {
27 if (mouse_capture_)
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);
50 return toplevel;
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);
59 return toplevel;
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);
71 return child;
74 Widget* WidgetTest::CreateTopLevelNativeWidget() {
75 Widget* toplevel = new Widget;
76 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
77 toplevel->Init(params);
78 return toplevel;
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();
85 child->Init(params);
86 child->SetContentsView(new View);
87 return child;
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_;
106 } // namespace test
107 } // namespace views