Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / test / widget_test.cc
blob57fc8c3765e5e953dea3572bbcd93a7077c367f0
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 {
12 namespace {
14 // Helper to encapsulate common parts of the WidgetTest::Create* methods,
15 template <class NativeWidgetType>
16 Widget* CreateHelper(Widget::InitParams params) {
17 Widget* widget = new Widget;
18 params.native_widget = new NativeWidgetType(widget);
19 widget->Init(params);
20 return widget;
23 Widget* CreateHelper(Widget::InitParams params) {
24 return CreateHelper<NativeWidgetCapture>(params);
27 } // namespace
29 // A widget that assumes mouse capture always works. It won't in testing, so we
30 // mock it.
31 NativeWidgetCapture::NativeWidgetCapture(
32 internal::NativeWidgetDelegate* delegate)
33 : PlatformNativeWidget(delegate),
34 mouse_capture_(false) {}
36 NativeWidgetCapture::~NativeWidgetCapture() {}
38 void NativeWidgetCapture::SetCapture() {
39 mouse_capture_ = true;
42 void NativeWidgetCapture::ReleaseCapture() {
43 if (mouse_capture_)
44 delegate()->OnMouseCaptureLost();
45 mouse_capture_ = false;
48 bool NativeWidgetCapture::HasCapture() const {
49 return mouse_capture_;
52 WidgetTest::WidgetTest() {}
53 WidgetTest::~WidgetTest() {}
55 Widget* WidgetTest::CreateTopLevelPlatformWidget() {
56 return CreateHelper(CreateParams(Widget::InitParams::TYPE_WINDOW));
59 Widget* WidgetTest::CreateTopLevelFramelessPlatformWidget() {
60 return CreateHelper(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS));
63 Widget* WidgetTest::CreateChildPlatformWidget(
64 gfx::NativeView parent_native_view) {
65 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL);
66 params.parent = parent_native_view;
67 Widget* child = CreateHelper(params);
68 child->SetContentsView(new View);
69 return child;
72 Widget* WidgetTest::CreateTopLevelNativeWidget() {
73 Widget* toplevel = new Widget;
74 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
75 toplevel->Init(params);
76 return toplevel;
79 Widget* WidgetTest::CreateChildNativeWidgetWithParent(Widget* parent) {
80 Widget* child = new Widget;
81 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL);
82 params.parent = parent->GetNativeView();
83 child->Init(params);
84 child->SetContentsView(new View);
85 return child;
88 Widget* WidgetTest::CreateChildNativeWidget() {
89 return CreateChildNativeWidgetWithParent(NULL);
92 Widget* WidgetTest::CreateNativeDesktopWidget() {
93 #if defined(OS_CHROMEOS)
94 return CreateHelper<PlatformNativeWidget>(
95 CreateParams(Widget::InitParams::TYPE_WINDOW));
96 #else
97 return CreateHelper<PlatformDesktopNativeWidget>(
98 CreateParams(Widget::InitParams::TYPE_WINDOW));
99 #endif
102 View* WidgetTest::GetMousePressedHandler(internal::RootView* root_view) {
103 return root_view->mouse_pressed_handler_;
106 View* WidgetTest::GetMouseMoveHandler(internal::RootView* root_view) {
107 return root_view->mouse_move_handler_;
110 View* WidgetTest::GetGestureHandler(internal::RootView* root_view) {
111 return root_view->gesture_handler_;
114 } // namespace test
115 } // namespace views