1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/test/native_widget_factory.h"
#if defined(USE_AURA)
#include "ui/views/widget/native_widget_aura.h"
#if !defined(OS_CHROMEOS)
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#endif
#elif defined(OS_MACOSX)
#include "ui/views/widget/native_widget_mac.h"
#endif
namespace views {
namespace test {
#if defined(USE_AURA)
using PlatformNativeWidget = NativeWidgetAura;
#elif defined(OS_MACOSX)
using PlatformNativeWidget = NativeWidgetMac;
#endif
namespace {
// NativeWidget implementation that adds the following:
// . capture can be mocked.
// . a boolean is set when the NativeWiget is destroyed.
class TestPlatformNativeWidget : public PlatformNativeWidget {
public:
TestPlatformNativeWidget(internal::NativeWidgetDelegate* delegate,
bool mock_capture,
bool* destroyed);
~TestPlatformNativeWidget() override;
void SetCapture() override;
void ReleaseCapture() override;
bool HasCapture() const override;
private:
bool mouse_capture_;
const bool mock_capture_;
bool* destroyed_;
DISALLOW_COPY_AND_ASSIGN(TestPlatformNativeWidget);
};
// A widget that assumes mouse capture always works. It won't in testing, so we
// mock it.
TestPlatformNativeWidget::TestPlatformNativeWidget(
internal::NativeWidgetDelegate* delegate,
bool mock_capture,
bool* destroyed)
: PlatformNativeWidget(delegate),
mouse_capture_(false),
mock_capture_(mock_capture),
destroyed_(destroyed) {}
TestPlatformNativeWidget::~TestPlatformNativeWidget() {
if (destroyed_)
*destroyed_ = true;
}
void TestPlatformNativeWidget::SetCapture() {
if (mock_capture_)
mouse_capture_ = true;
else
PlatformNativeWidget::SetCapture();
}
void TestPlatformNativeWidget::ReleaseCapture() {
if (mock_capture_) {
if (mouse_capture_)
delegate()->OnMouseCaptureLost();
mouse_capture_ = false;
} else {
PlatformNativeWidget::ReleaseCapture();
}
}
bool TestPlatformNativeWidget::HasCapture() const {
return mock_capture_ ? mouse_capture_ : PlatformNativeWidget::HasCapture();
}
} // namespace
// Factory methods ------------------------------------------------------------
NativeWidget* CreatePlatformNativeWidgetImpl(
const Widget::InitParams& init_params,
Widget* widget,
uint32_t type,
bool* destroyed) {
return new TestPlatformNativeWidget(widget, type == kStubCapture, destroyed);
}
} // namespace test
} // namespace views
|