Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / gfx / tests / gtest / MockWidget.h
bloba8cbaf770277ae17a9f462c1b1da8b7bd2c67002
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/. */
7 #ifndef GTEST_MOCKWIDGET_H
8 #define GTEST_MOCKWIDGET_H
10 #include "mozilla/gfx/Point.h"
11 #include "mozilla/widget/InProcessCompositorWidget.h"
12 #include "nsBaseWidget.h"
13 #include "GLContext.h"
14 #include "GLContextProvider.h"
16 using mozilla::gl::CreateContextFlags;
17 using mozilla::gl::GLContext;
18 using mozilla::gl::GLContextProvider;
20 using mozilla::gfx::IntSize;
22 class MockWidget : public nsBaseWidget {
23 public:
24 MockWidget() : mCompWidth(0), mCompHeight(0) {}
25 MockWidget(int aWidth, int aHeight)
26 : mCompWidth(aWidth), mCompHeight(aHeight) {}
27 NS_DECL_ISUPPORTS_INHERITED
29 virtual LayoutDeviceIntRect GetClientBounds() override {
30 return LayoutDeviceIntRect(0, 0, mCompWidth, mCompHeight);
32 virtual LayoutDeviceIntRect GetBounds() override { return GetClientBounds(); }
34 void* GetNativeData(uint32_t aDataType) override {
35 if (aDataType == NS_NATIVE_OPENGL_CONTEXT) {
36 nsCString discardFailureId;
37 RefPtr<GLContext> context = GLContextProvider::CreateHeadless(
38 {CreateContextFlags::REQUIRE_COMPAT_PROFILE}, &discardFailureId);
39 if (!context) {
40 return nullptr;
42 if (!context->CreateOffscreenDefaultFb({mCompWidth, mCompHeight})) {
43 return nullptr;
45 return context.forget().take();
47 return nullptr;
50 virtual nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
51 const LayoutDeviceIntRect& aRect,
52 InitData* aInitData = nullptr) override {
53 return NS_OK;
55 virtual nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
56 const DesktopIntRect& aRect,
57 InitData* aInitData = nullptr) override {
58 return NS_OK;
60 virtual void Show(bool aState) override {}
61 virtual bool IsVisible() const override { return true; }
62 virtual void Move(double aX, double aY) override {}
63 virtual void Resize(double aWidth, double aHeight, bool aRepaint) override {}
64 virtual void Resize(double aX, double aY, double aWidth, double aHeight,
65 bool aRepaint) override {}
67 virtual void Enable(bool aState) override {}
68 virtual bool IsEnabled() const override { return true; }
70 virtual nsSizeMode SizeMode() override { return mSizeMode; }
71 virtual void SetSizeMode(nsSizeMode aMode) override { mSizeMode = aMode; }
73 virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override {}
74 virtual void Invalidate(const LayoutDeviceIntRect& aRect) override {}
75 virtual nsresult SetTitle(const nsAString& title) override { return NS_OK; }
76 virtual LayoutDeviceIntPoint WidgetToScreenOffset() override {
77 return LayoutDeviceIntPoint(0, 0);
79 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
80 nsEventStatus& aStatus) override {
81 return NS_OK;
83 virtual void SetInputContext(const InputContext& aContext,
84 const InputContextAction& aAction) override {}
85 virtual InputContext GetInputContext() override { abort(); }
87 private:
88 ~MockWidget() = default;
90 nsSizeMode mSizeMode = nsSizeMode_Normal;
92 int mCompWidth;
93 int mCompHeight;
96 #endif