Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / base / nsDOMWindowUtils.h
blob47ff326b202266b1d7d6af8bdfb72776df8a6a93
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 nsDOMWindowUtils_h_
8 #define nsDOMWindowUtils_h_
10 #include "nsWeakReference.h"
12 #include "nsIDOMWindowUtils.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/BasicEvents.h"
15 #include "mozilla/Result.h"
17 class nsGlobalWindowOuter;
18 class nsIDocShell;
19 class nsIWidget;
20 class nsPresContext;
21 class nsView;
22 struct nsPoint;
24 namespace mozilla {
25 class PresShell;
26 namespace dom {
27 class Document;
28 class Element;
29 } // namespace dom
30 namespace layers {
31 class LayerTransactionChild;
32 class WebRenderBridgeChild;
33 } // namespace layers
34 } // namespace mozilla
36 class nsTranslationNodeList final : public nsITranslationNodeList {
37 public:
38 nsTranslationNodeList() {
39 mNodes.SetCapacity(1000);
40 mNodeIsRoot.SetCapacity(1000);
41 mLength = 0;
44 NS_DECL_ISUPPORTS
45 NS_DECL_NSITRANSLATIONNODELIST
47 void AppendElement(nsINode* aElement, bool aIsRoot) {
48 mNodes.AppendElement(aElement);
49 mNodeIsRoot.AppendElement(aIsRoot);
50 mLength++;
53 private:
54 ~nsTranslationNodeList() = default;
56 nsTArray<nsCOMPtr<nsINode> > mNodes;
57 nsTArray<bool> mNodeIsRoot;
58 uint32_t mLength;
61 class nsDOMWindowUtils final : public nsIDOMWindowUtils,
62 public nsSupportsWeakReference {
63 using TextEventDispatcher = mozilla::widget::TextEventDispatcher;
65 public:
66 explicit nsDOMWindowUtils(nsGlobalWindowOuter* aWindow);
67 NS_DECL_ISUPPORTS
68 NS_DECL_NSIDOMWINDOWUTILS
70 protected:
71 ~nsDOMWindowUtils();
73 nsWeakPtr mWindow;
75 // If aOffset is non-null, it gets filled in with the offset of the root
76 // frame of our window to the nearest widget in the app units of our window.
77 // Add this offset to any event offset we're given to make it relative to the
78 // widget returned by GetWidget.
79 nsIWidget* GetWidget(nsPoint* aOffset = nullptr);
80 nsIWidget* GetWidgetForElement(mozilla::dom::Element* aElement);
82 nsIDocShell* GetDocShell();
83 mozilla::PresShell* GetPresShell();
84 nsPresContext* GetPresContext();
85 mozilla::dom::Document* GetDocument();
86 mozilla::layers::WebRenderBridgeChild* GetWebRenderBridge();
87 mozilla::layers::CompositorBridgeChild* GetCompositorBridge();
89 // Until callers are annotated.
90 MOZ_CAN_RUN_SCRIPT
91 NS_IMETHOD SendMouseEventCommon(
92 const nsAString& aType, float aX, float aY, int32_t aButton,
93 int32_t aClickCount, int32_t aModifiers, bool aIgnoreRootScrollFrame,
94 float aPressure, unsigned short aInputSourceArg, uint32_t aIdentifier,
95 bool aToWindow, bool* aPreventDefault, bool aIsDOMEventSynthesized,
96 bool aIsWidgetEventSynthesized, int32_t aButtons);
98 MOZ_CAN_RUN_SCRIPT
99 nsresult SendTouchEventCommon(
100 const nsAString& aType, const nsTArray<uint32_t>& aIdentifiers,
101 const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
102 const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
103 const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
104 const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
105 const nsTArray<int32_t>& aTwists, int32_t aModifiers,
106 bool aIgnoreRootScrollFrame, bool aIsPen, bool aToWindow,
107 bool* aPreventDefault);
109 void ReportErrorMessageForWindow(const nsAString& aErrorMessage,
110 const char* aClassification,
111 bool aFromChrome);
113 private:
114 enum class CoordsType {
115 Screen,
116 TopLevelWidget,
118 mozilla::Result<mozilla::LayoutDeviceRect, nsresult> ConvertTo(
119 float aX, float aY, float aWidth, float aHeight, CoordsType);
122 #endif