Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: ui/views/test/native_widget_factory.cc

Issue 2488393003: Changes views_aura_mus_unittests to create DesktopNativeWidgetAura (Closed)
Patch Set: remove this and fix mac Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/test/native_widget_factory.h ('k') | ui/views/test/native_widget_factory_aura_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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/native_widget_factory.h"
6
7 #if defined(USE_AURA)
8 #include "ui/views/widget/native_widget_aura.h"
9 #if !defined(OS_CHROMEOS)
10 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
11 #endif
12 #elif defined(OS_MACOSX)
13 #include "ui/views/widget/native_widget_mac.h"
14 #endif
15
16 namespace views {
17 namespace test {
18
19 #if defined(USE_AURA)
20 using PlatformNativeWidget = NativeWidgetAura;
21 #elif defined(OS_MACOSX)
22 using PlatformNativeWidget = NativeWidgetMac;
23 #endif
24
25 namespace {
26
27 // NativeWidget implementation that adds the following:
28 // . capture can be mocked.
29 // . a boolean is set when the NativeWiget is destroyed.
30 class TestPlatformNativeWidget : public PlatformNativeWidget {
31 public:
32 TestPlatformNativeWidget(internal::NativeWidgetDelegate* delegate,
33 bool mock_capture,
34 bool* destroyed);
35 ~TestPlatformNativeWidget() override;
36
37 void SetCapture() override;
38 void ReleaseCapture() override;
39 bool HasCapture() const override;
40
41 private:
42 bool mouse_capture_;
43 const bool mock_capture_;
44 bool* destroyed_;
45
46 DISALLOW_COPY_AND_ASSIGN(TestPlatformNativeWidget);
47 };
48
49 // A widget that assumes mouse capture always works. It won't in testing, so we
50 // mock it.
51 TestPlatformNativeWidget::TestPlatformNativeWidget(
52 internal::NativeWidgetDelegate* delegate,
53 bool mock_capture,
54 bool* destroyed)
55 : PlatformNativeWidget(delegate),
56 mouse_capture_(false),
57 mock_capture_(mock_capture),
58 destroyed_(destroyed) {}
59
60 TestPlatformNativeWidget::~TestPlatformNativeWidget() {
61 if (destroyed_)
62 *destroyed_ = true;
63 }
64
65 void TestPlatformNativeWidget::SetCapture() {
66 if (mock_capture_)
67 mouse_capture_ = true;
68 else
69 PlatformNativeWidget::SetCapture();
70 }
71
72 void TestPlatformNativeWidget::ReleaseCapture() {
73 if (mock_capture_) {
74 if (mouse_capture_)
75 delegate()->OnMouseCaptureLost();
76 mouse_capture_ = false;
77 } else {
78 PlatformNativeWidget::ReleaseCapture();
79 }
80 }
81
82 bool TestPlatformNativeWidget::HasCapture() const {
83 return mock_capture_ ? mouse_capture_ : PlatformNativeWidget::HasCapture();
84 }
85
86 } // namespace
87
88 // Factory methods ------------------------------------------------------------
89
90 NativeWidget* CreatePlatformNativeWidgetImpl(
91 const Widget::InitParams& init_params,
92 Widget* widget,
93 uint32_t type,
94 bool* destroyed) {
95 return new TestPlatformNativeWidget(widget, type == kStubCapture, destroyed);
96 }
97
98 } // namespace test
99 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/native_widget_factory.h ('k') | ui/views/test/native_widget_factory_aura_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698