/src/mozilla-central/gfx/tests/gtest/MockWidget.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | |
8 | | #ifndef GTEST_MOCKWIDGET_H |
9 | | #define GTEST_MOCKWIDGET_H |
10 | | |
11 | | #include "mozilla/widget/InProcessCompositorWidget.h" |
12 | | #include "nsBaseWidget.h" |
13 | | #include "GLContext.h" |
14 | | #include "GLContextProvider.h" |
15 | | |
16 | | using mozilla::gl::CreateContextFlags; |
17 | | using mozilla::gl::GLContext; |
18 | | using mozilla::gl::GLContextProvider; |
19 | | |
20 | | class MockWidget : public nsBaseWidget |
21 | | { |
22 | | public: |
23 | 0 | MockWidget() : mCompWidth(0), mCompHeight(0) {} |
24 | | MockWidget(int aWidth, int aHeight) : mCompWidth(aWidth), mCompHeight(aHeight) |
25 | 0 | { |
26 | 0 | } |
27 | | NS_DECL_ISUPPORTS_INHERITED |
28 | | |
29 | 0 | virtual LayoutDeviceIntRect GetClientBounds() override { |
30 | 0 | return LayoutDeviceIntRect(0, 0, mCompWidth, mCompHeight); |
31 | 0 | } |
32 | 0 | virtual LayoutDeviceIntRect GetBounds() override { |
33 | 0 | return GetClientBounds(); |
34 | 0 | } |
35 | | |
36 | 0 | void* GetNativeData(uint32_t aDataType) override { |
37 | 0 | if (aDataType == NS_NATIVE_OPENGL_CONTEXT) { |
38 | 0 | mozilla::gl::SurfaceCaps caps = mozilla::gl::SurfaceCaps::ForRGB(); |
39 | 0 | caps.preserve = false; |
40 | 0 | caps.bpp16 = false; |
41 | 0 | nsCString discardFailureId; |
42 | 0 | RefPtr<GLContext> context = GLContextProvider::CreateOffscreen( |
43 | 0 | IntSize(mCompWidth, mCompHeight), caps, |
44 | 0 | CreateContextFlags::REQUIRE_COMPAT_PROFILE, |
45 | 0 | &discardFailureId); |
46 | 0 | return context.forget().take(); |
47 | 0 | } |
48 | 0 | return nullptr; |
49 | 0 | } |
50 | | |
51 | | virtual nsresult Create(nsIWidget* aParent, |
52 | | nsNativeWidget aNativeParent, |
53 | | const LayoutDeviceIntRect& aRect, |
54 | 0 | nsWidgetInitData* aInitData = nullptr) override { return NS_OK; } |
55 | | virtual nsresult Create(nsIWidget* aParent, |
56 | | nsNativeWidget aNativeParent, |
57 | | const DesktopIntRect& aRect, |
58 | 0 | nsWidgetInitData* aInitData = nullptr) override { return NS_OK; } |
59 | 0 | virtual void Show(bool aState) override {} |
60 | 0 | virtual bool IsVisible() const override { return true; } |
61 | 0 | virtual void Move(double aX, double aY) override {} |
62 | 0 | virtual void Resize(double aWidth, double aHeight, bool aRepaint) override {} |
63 | | virtual void Resize(double aX, double aY, |
64 | 0 | double aWidth, double aHeight, bool aRepaint) override {} |
65 | | |
66 | 0 | virtual void Enable(bool aState) override {} |
67 | 0 | virtual bool IsEnabled() const override { return true; } |
68 | 0 | virtual nsresult SetFocus(bool aRaise) override { return NS_OK; } |
69 | 0 | virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override { return NS_OK; } |
70 | 0 | virtual void Invalidate(const LayoutDeviceIntRect& aRect) override {} |
71 | 0 | virtual nsresult SetTitle(const nsAString& title) override { return NS_OK; } |
72 | 0 | virtual LayoutDeviceIntPoint WidgetToScreenOffset() override { return LayoutDeviceIntPoint(0, 0); } |
73 | | virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent, |
74 | 0 | nsEventStatus& aStatus) override { return NS_OK; } |
75 | | virtual void SetInputContext(const InputContext& aContext, |
76 | 0 | const InputContextAction& aAction) override {} |
77 | 0 | virtual InputContext GetInputContext() override { abort(); } |
78 | | |
79 | | private: |
80 | 0 | ~MockWidget() {} |
81 | | |
82 | | int mCompWidth; |
83 | | int mCompHeight; |
84 | | }; |
85 | | |
86 | | #endif |