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 "nsWeakReference.h" 11 12 #include "nsIDOMWindowUtils.h" 13 #include "mozilla/Attributes.h" 14 #include "mozilla/BasicEvents.h" 15 16 class nsGlobalWindow; 17 class nsIPresShell; 18 class nsIWidget; 19 class nsPresContext; 20 class nsIDocument; 21 class nsView; 22 struct nsPoint; 23 24 namespace mozilla { 25 namespace layers { 26 class LayerTransactionChild; 27 } // namespace layers 28 } // namespace mozilla 29 30 class nsTranslationNodeList final : public nsITranslationNodeList 31 { 32 public: nsTranslationNodeList()33 nsTranslationNodeList() 34 { 35 mNodes.SetCapacity(1000); 36 mNodeIsRoot.SetCapacity(1000); 37 mLength = 0; 38 } 39 40 NS_DECL_ISUPPORTS 41 NS_DECL_NSITRANSLATIONNODELIST 42 AppendElement(nsIDOMNode * aElement,bool aIsRoot)43 void AppendElement(nsIDOMNode* aElement, bool aIsRoot) 44 { 45 mNodes.AppendElement(aElement); 46 mNodeIsRoot.AppendElement(aIsRoot); 47 mLength++; 48 } 49 50 private: ~nsTranslationNodeList()51 ~nsTranslationNodeList() {} 52 53 nsTArray<nsCOMPtr<nsIDOMNode> > mNodes; 54 nsTArray<bool> mNodeIsRoot; 55 uint32_t mLength; 56 }; 57 58 class nsDOMWindowUtils final : public nsIDOMWindowUtils, 59 public nsSupportsWeakReference 60 { 61 typedef mozilla::widget::TextEventDispatcher 62 TextEventDispatcher; 63 public: 64 explicit nsDOMWindowUtils(nsGlobalWindow *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(nsIDOMElement* aElement); 79 80 nsIPresShell* GetPresShell(); 81 nsPresContext* GetPresContext(); 82 nsIDocument* GetDocument(); 83 mozilla::layers::LayerTransactionChild* GetLayerTransaction(); 84 85 NS_IMETHOD SendMouseEventCommon(const nsAString& aType, 86 float aX, 87 float aY, 88 int32_t aButton, 89 int32_t aClickCount, 90 int32_t aModifiers, 91 bool aIgnoreRootScrollFrame, 92 float aPressure, 93 unsigned short aInputSourceArg, 94 bool aToWindow, 95 bool *aPreventDefault, 96 bool aIsDOMEventSynthesized, 97 bool aIsWidgetEventSynthesized, 98 int32_t aButtons); 99 100 NS_IMETHOD SendPointerEventCommon(const nsAString& aType, 101 float aX, 102 float aY, 103 int32_t aButton, 104 int32_t aClickCount, 105 int32_t aModifiers, 106 bool aIgnoreRootScrollFrame, 107 float aPressure, 108 unsigned short aInputSourceArg, 109 int32_t aPointerId, 110 int32_t aWidth, 111 int32_t aHeight, 112 int32_t aTiltX, 113 int32_t aTiltY, 114 bool aIsPrimary, 115 bool aIsSynthesized, 116 uint8_t aOptionalArgCount, 117 bool aToWindow, 118 bool* aPreventDefault); 119 120 NS_IMETHOD SendTouchEventCommon(const nsAString& aType, 121 uint32_t* aIdentifiers, 122 int32_t* aXs, 123 int32_t* aYs, 124 uint32_t* aRxs, 125 uint32_t* aRys, 126 float* aRotationAngles, 127 float* aForces, 128 uint32_t aCount, 129 int32_t aModifiers, 130 bool aIgnoreRootScrollFrame, 131 bool aToWindow, 132 bool* aPreventDefault); 133 }; 134 135 #endif 136