Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 :
7 : #ifndef HEADLESSWIDGET_H
8 : #define HEADLESSWIDGET_H
9 :
10 : #include "mozilla/widget/InProcessCompositorWidget.h"
11 : #include "nsBaseWidget.h"
12 :
13 : namespace mozilla {
14 : namespace widget {
15 :
16 : class HeadlessWidget : public nsBaseWidget
17 : {
18 : public:
19 0 : HeadlessWidget() {}
20 :
21 : NS_DECL_ISUPPORTS_INHERITED
22 :
23 0 : void* GetNativeData(uint32_t aDataType) override
24 : {
25 : // Headless widgets have no native data.
26 0 : return nullptr;
27 : }
28 :
29 : virtual nsresult Create(nsIWidget* aParent,
30 : nsNativeWidget aNativeParent,
31 : const LayoutDeviceIntRect& aRect,
32 : nsWidgetInitData* aInitData = nullptr) override;
33 : using nsBaseWidget::Create; // for Create signature not overridden here
34 : virtual already_AddRefed<nsIWidget> CreateChild(const LayoutDeviceIntRect& aRect,
35 : nsWidgetInitData* aInitData = nullptr,
36 : bool aForceUseIWidgetParent = false) override;
37 :
38 : virtual void Show(bool aState) override;
39 : virtual bool IsVisible() const override;
40 : virtual void Move(double aX, double aY) override;
41 : virtual void Resize(double aWidth,
42 : double aHeight,
43 : bool aRepaint) override;
44 : virtual void Resize(double aX,
45 : double aY,
46 : double aWidth,
47 : double aHeight,
48 : bool aRepaint) override;
49 : virtual void SetSizeMode(nsSizeMode aMode) override;
50 : virtual nsresult MakeFullScreen(bool aFullScreen,
51 : nsIScreen* aTargetScreen = nullptr) override;
52 : virtual void Enable(bool aState) override;
53 : virtual bool IsEnabled() const override;
54 : virtual nsresult SetFocus(bool aRaise) override;
55 0 : virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override
56 : {
57 0 : MOZ_ASSERT_UNREACHABLE("Headless widgets do not support configuring children.");
58 : return NS_ERROR_FAILURE;
59 : }
60 0 : virtual void Invalidate(const LayoutDeviceIntRect& aRect) override
61 : {
62 : // TODO: see if we need to do anything here.
63 0 : }
64 0 : virtual nsresult SetTitle(const nsAString& title) override {
65 : // Headless widgets have no title, so just ignore it.
66 0 : return NS_OK;
67 : }
68 : virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
69 0 : virtual void SetInputContext(const InputContext& aContext,
70 : const InputContextAction& aAction) override
71 : {
72 0 : mInputContext = aContext;
73 0 : }
74 0 : virtual InputContext GetInputContext() override
75 : {
76 0 : return mInputContext;
77 : }
78 :
79 : virtual LayerManager*
80 : GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
81 : LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
82 : LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;
83 :
84 : virtual nsresult DispatchEvent(WidgetGUIEvent* aEvent,
85 : nsEventStatus& aStatus) override;
86 :
87 : private:
88 0 : ~HeadlessWidget() {}
89 : bool mEnabled;
90 : bool mVisible;
91 : // The size mode before entering fullscreen mode.
92 : nsSizeMode mLastSizeMode;
93 : InputContext mInputContext;
94 : // In headless there is no window manager to track window bounds
95 : // across size mode changes, so we must track it to emulate.
96 : LayoutDeviceIntRect mRestoreBounds;
97 : void SendSetZLevelEvent();
98 : };
99 :
100 : } // namespace widget
101 : } // namespace mozilla
102 :
103 : #endif
|