Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef UI_VIEWS_TEST_TEST_PLATFORM_NATIVE_WIDGET_H_ | |
| 6 #define UI_VIEWS_TEST_TEST_PLATFORM_NATIVE_WIDGET_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "ui/views/view.h" | |
| 11 | |
| 12 namespace views { | |
| 13 namespace internal { | |
| 14 class NativeWidgetDelegate; | |
| 15 } | |
| 16 namespace test { | |
| 17 | |
| 18 // NativeWidget implementation that adds the following: | |
| 19 // . capture can be mocked. | |
| 20 // . a boolean is set when the NativeWidget is destroyed. | |
| 21 // Don't create directly, instead go through functions in | |
| 22 // native_widget_factory.h that create the appropriate platform specific | |
| 23 // implementation. | |
| 24 template <typename PlatformNativeWidget> | |
| 25 class TestPlatformNativeWidget : public PlatformNativeWidget { | |
| 26 public: | |
| 27 TestPlatformNativeWidget(internal::NativeWidgetDelegate* delegate, | |
| 28 bool mock_capture, | |
| 29 bool* destroyed) | |
| 30 : PlatformNativeWidget(delegate), | |
| 31 mouse_capture_(false), | |
| 32 mock_capture_(mock_capture), | |
| 33 destroyed_(destroyed) {} | |
| 34 | |
| 35 ~TestPlatformNativeWidget() override { | |
| 36 if (destroyed_) | |
| 37 *destroyed_ = true; | |
| 38 } | |
| 39 | |
| 40 // PlatformNativeWidget: | |
| 41 void SetCapture() override { | |
| 42 if (mock_capture_) | |
| 43 mouse_capture_ = true; | |
| 44 else | |
| 45 PlatformNativeWidget::SetCapture(); | |
| 46 } | |
| 47 | |
| 48 void ReleaseCapture() override { | |
| 49 if (mock_capture_) { | |
| 50 if (mouse_capture_) | |
| 51 this->GetWidget()->OnMouseCaptureLost(); | |
|
msw
2016/11/11 01:25:40
nit: remove |this->|?
sky
2016/11/11 04:28:46
It's necessary. I changed it to PlatformNativeWidg
| |
| 52 mouse_capture_ = false; | |
| 53 } else { | |
| 54 PlatformNativeWidget::ReleaseCapture(); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 bool HasCapture() const override { | |
| 59 return mock_capture_ ? mouse_capture_ : PlatformNativeWidget::HasCapture(); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 bool mouse_capture_; | |
| 64 const bool mock_capture_; | |
| 65 bool* destroyed_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(TestPlatformNativeWidget); | |
| 68 }; | |
| 69 | |
| 70 } // namespace test | |
| 71 } // namespace views | |
| 72 | |
| 73 #endif // UI_VIEWS_TEST_TEST_PLATFORM_NATIVE_WIDGET_H_ | |
| OLD | NEW |