tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsDOMWindowUtils.h (3465B)


      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 #ifndef nsDOMWindowUtils_h_
      8 #define nsDOMWindowUtils_h_
      9 
     10 #include "mozilla/Attributes.h"
     11 #include "mozilla/BasicEvents.h"
     12 #include "mozilla/Result.h"
     13 #include "nsIDOMWindowUtils.h"
     14 #include "nsWeakReference.h"
     15 
     16 class nsGlobalWindowOuter;
     17 class nsIDocShell;
     18 class nsIWidget;
     19 class nsPresContext;
     20 struct nsPoint;
     21 
     22 namespace mozilla {
     23 class PresShell;
     24 namespace dom {
     25 class Document;
     26 class Element;
     27 }  // namespace dom
     28 namespace layers {
     29 class LayerTransactionChild;
     30 class WebRenderBridgeChild;
     31 }  // namespace layers
     32 }  // namespace mozilla
     33 
     34 class nsTranslationNodeList final : public nsITranslationNodeList {
     35 public:
     36  nsTranslationNodeList() {
     37    mNodes.SetCapacity(1000);
     38    mNodeIsRoot.SetCapacity(1000);
     39    mLength = 0;
     40  }
     41 
     42  NS_DECL_ISUPPORTS
     43  NS_DECL_NSITRANSLATIONNODELIST
     44 
     45  void AppendElement(nsINode* aElement, bool aIsRoot) {
     46    mNodes.AppendElement(aElement);
     47    mNodeIsRoot.AppendElement(aIsRoot);
     48    mLength++;
     49  }
     50 
     51 private:
     52  ~nsTranslationNodeList() = default;
     53 
     54  nsTArray<nsCOMPtr<nsINode> > mNodes;
     55  nsTArray<bool> mNodeIsRoot;
     56  uint32_t mLength;
     57 };
     58 
     59 class nsDOMWindowUtils final : public nsIDOMWindowUtils,
     60                               public nsSupportsWeakReference {
     61  using TextEventDispatcher = mozilla::widget::TextEventDispatcher;
     62 
     63 public:
     64  explicit nsDOMWindowUtils(nsGlobalWindowOuter* aWindow);
     65  NS_DECL_ISUPPORTS
     66  NS_DECL_NSIDOMWINDOWUTILS
     67 
     68 protected:
     69  ~nsDOMWindowUtils();
     70 
     71  nsWeakPtr mWindow;
     72 
     73  // If aOffset is non-null, it gets filled in with the offset of the root
     74  // frame of our window to the nearest widget in the app units of our window.
     75  // Add this offset to any event offset we're given to make it relative to the
     76  // widget returned by GetWidget.
     77  nsIWidget* GetWidget(nsPoint* aOffset = nullptr);
     78  nsIWidget* GetWidgetForElement(mozilla::dom::Element* aElement,
     79                                 nsPoint* aOffset = nullptr);
     80 
     81  nsIDocShell* GetDocShell();
     82  mozilla::PresShell* GetPresShell();
     83  nsPresContext* GetPresContext();
     84  mozilla::dom::Document* GetDocument();
     85  mozilla::layers::WebRenderBridgeChild* GetWebRenderBridge();
     86  mozilla::layers::CompositorBridgeChild* GetCompositorBridge();
     87 
     88  MOZ_CAN_RUN_SCRIPT
     89  nsresult SendTouchEventCommon(
     90      const nsAString& aType, const nsTArray<uint32_t>& aIdentifiers,
     91      const nsTArray<int32_t>& aXs, const nsTArray<int32_t>& aYs,
     92      const nsTArray<uint32_t>& aRxs, const nsTArray<uint32_t>& aRys,
     93      const nsTArray<float>& aRotationAngles, const nsTArray<float>& aForces,
     94      const nsTArray<int32_t>& aTiltXs, const nsTArray<int32_t>& aTiltYs,
     95      const nsTArray<int32_t>& aTwists, int32_t aModifiers, bool aIsPen,
     96      bool aToWindow, AsyncEnabledOption aAsyncEnabled, bool* aPreventDefault);
     97 
     98  void ReportErrorMessageForWindow(const nsAString& aErrorMessage,
     99                                   const char* aClassification,
    100                                   bool aFromChrome);
    101 
    102 private:
    103  enum class CoordsType {
    104    Screen,
    105    TopLevelWidget,
    106  };
    107  mozilla::Result<mozilla::LayoutDeviceRect, nsresult> ConvertTo(
    108      float aX, float aY, float aWidth, float aHeight, CoordsType);
    109 };
    110 
    111 #endif