Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef NSWINDOW_H_ |
michael@0 | 7 | #define NSWINDOW_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsBaseWidget.h" |
michael@0 | 10 | #include "gfxPoint.h" |
michael@0 | 11 | #include "nsIIdleServiceInternal.h" |
michael@0 | 12 | #include "nsTArray.h" |
michael@0 | 13 | #include "AndroidJavaWrappers.h" |
michael@0 | 14 | #include "GeneratedJNIWrappers.h" |
michael@0 | 15 | #include "mozilla/EventForwards.h" |
michael@0 | 16 | #include "mozilla/StaticPtr.h" |
michael@0 | 17 | #include "mozilla/TextRange.h" |
michael@0 | 18 | |
michael@0 | 19 | class gfxASurface; |
michael@0 | 20 | |
michael@0 | 21 | struct ANPEvent; |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | class AndroidGeckoEvent; |
michael@0 | 25 | |
michael@0 | 26 | namespace layers { |
michael@0 | 27 | class CompositorParent; |
michael@0 | 28 | class CompositorChild; |
michael@0 | 29 | class LayerManager; |
michael@0 | 30 | class APZCTreeManager; |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | class nsWindow : |
michael@0 | 35 | public nsBaseWidget |
michael@0 | 36 | { |
michael@0 | 37 | public: |
michael@0 | 38 | using nsBaseWidget::GetLayerManager; |
michael@0 | 39 | |
michael@0 | 40 | nsWindow(); |
michael@0 | 41 | virtual ~nsWindow(); |
michael@0 | 42 | |
michael@0 | 43 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 44 | |
michael@0 | 45 | static void OnGlobalAndroidEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 46 | static gfxIntSize GetAndroidScreenBounds(); |
michael@0 | 47 | static nsWindow* TopWindow(); |
michael@0 | 48 | |
michael@0 | 49 | nsWindow* FindWindowForPoint(const nsIntPoint& pt); |
michael@0 | 50 | |
michael@0 | 51 | void OnAndroidEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 52 | void OnDraw(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 53 | bool OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 54 | void OnNativeGestureEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 55 | void OnMouseEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 56 | void OnKeyEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 57 | void OnIMEEvent(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 58 | |
michael@0 | 59 | void OnSizeChanged(const gfxIntSize& aSize); |
michael@0 | 60 | |
michael@0 | 61 | void InitEvent(mozilla::WidgetGUIEvent& event, nsIntPoint* aPoint = 0); |
michael@0 | 62 | |
michael@0 | 63 | // |
michael@0 | 64 | // nsIWidget |
michael@0 | 65 | // |
michael@0 | 66 | |
michael@0 | 67 | NS_IMETHOD Create(nsIWidget *aParent, |
michael@0 | 68 | nsNativeWidget aNativeParent, |
michael@0 | 69 | const nsIntRect &aRect, |
michael@0 | 70 | nsDeviceContext *aContext, |
michael@0 | 71 | nsWidgetInitData *aInitData); |
michael@0 | 72 | NS_IMETHOD Destroy(void); |
michael@0 | 73 | NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&); |
michael@0 | 74 | NS_IMETHOD SetParent(nsIWidget* aNewParent); |
michael@0 | 75 | virtual nsIWidget *GetParent(void); |
michael@0 | 76 | virtual float GetDPI(); |
michael@0 | 77 | virtual double GetDefaultScaleInternal(); |
michael@0 | 78 | NS_IMETHOD Show(bool aState); |
michael@0 | 79 | NS_IMETHOD SetModal(bool aModal); |
michael@0 | 80 | virtual bool IsVisible() const; |
michael@0 | 81 | NS_IMETHOD ConstrainPosition(bool aAllowSlop, |
michael@0 | 82 | int32_t *aX, |
michael@0 | 83 | int32_t *aY); |
michael@0 | 84 | NS_IMETHOD Move(double aX, |
michael@0 | 85 | double aY); |
michael@0 | 86 | NS_IMETHOD Resize(double aWidth, |
michael@0 | 87 | double aHeight, |
michael@0 | 88 | bool aRepaint); |
michael@0 | 89 | NS_IMETHOD Resize(double aX, |
michael@0 | 90 | double aY, |
michael@0 | 91 | double aWidth, |
michael@0 | 92 | double aHeight, |
michael@0 | 93 | bool aRepaint); |
michael@0 | 94 | void SetZIndex(int32_t aZIndex); |
michael@0 | 95 | NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, |
michael@0 | 96 | nsIWidget *aWidget, |
michael@0 | 97 | bool aActivate); |
michael@0 | 98 | NS_IMETHOD SetSizeMode(int32_t aMode); |
michael@0 | 99 | NS_IMETHOD Enable(bool aState); |
michael@0 | 100 | virtual bool IsEnabled() const; |
michael@0 | 101 | NS_IMETHOD Invalidate(const nsIntRect &aRect); |
michael@0 | 102 | NS_IMETHOD SetFocus(bool aRaise = false); |
michael@0 | 103 | NS_IMETHOD GetScreenBounds(nsIntRect &aRect); |
michael@0 | 104 | virtual nsIntPoint WidgetToScreenOffset(); |
michael@0 | 105 | NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 106 | nsEventStatus& aStatus); |
michael@0 | 107 | nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent); |
michael@0 | 108 | NS_IMETHOD MakeFullScreen(bool aFullScreen); |
michael@0 | 109 | NS_IMETHOD SetWindowClass(const nsAString& xulWinType); |
michael@0 | 110 | |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | NS_IMETHOD SetCursor(nsCursor aCursor) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 114 | NS_IMETHOD SetCursor(imgIContainer* aCursor, |
michael@0 | 115 | uint32_t aHotspotX, |
michael@0 | 116 | uint32_t aHotspotY) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 117 | NS_IMETHOD SetHasTransparentBackground(bool aTransparent) { return NS_OK; } |
michael@0 | 118 | NS_IMETHOD GetHasTransparentBackground(bool& aTransparent) { aTransparent = false; return NS_OK; } |
michael@0 | 119 | NS_IMETHOD HideWindowChrome(bool aShouldHide) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 120 | virtual void* GetNativeData(uint32_t aDataType); |
michael@0 | 121 | NS_IMETHOD SetTitle(const nsAString& aTitle) { return NS_OK; } |
michael@0 | 122 | NS_IMETHOD SetIcon(const nsAString& aIconSpec) { return NS_OK; } |
michael@0 | 123 | NS_IMETHOD EnableDragDrop(bool aEnable) { return NS_OK; } |
michael@0 | 124 | NS_IMETHOD CaptureMouse(bool aCapture) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 125 | NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, |
michael@0 | 126 | bool aDoCapture) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 127 | |
michael@0 | 128 | NS_IMETHOD GetAttention(int32_t aCycleCount) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 129 | NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 130 | int32_t aHorizontal, |
michael@0 | 131 | int32_t aVertical) |
michael@0 | 132 | { |
michael@0 | 133 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; |
michael@0 | 137 | NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, |
michael@0 | 138 | const InputContextAction& aAction); |
michael@0 | 139 | NS_IMETHOD_(InputContext) GetInputContext(); |
michael@0 | 140 | |
michael@0 | 141 | nsresult NotifyIMEOfTextChange(const IMENotification& aIMENotification); |
michael@0 | 142 | virtual nsIMEUpdatePreference GetIMEUpdatePreference(); |
michael@0 | 143 | |
michael@0 | 144 | LayerManager* GetLayerManager (PLayerTransactionChild* aShadowManager = nullptr, |
michael@0 | 145 | LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, |
michael@0 | 146 | LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, |
michael@0 | 147 | bool* aAllowRetaining = nullptr); |
michael@0 | 148 | |
michael@0 | 149 | NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); |
michael@0 | 150 | |
michael@0 | 151 | virtual bool NeedsPaint(); |
michael@0 | 152 | virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect); |
michael@0 | 153 | virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect); |
michael@0 | 154 | |
michael@0 | 155 | virtual mozilla::layers::CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) MOZ_OVERRIDE; |
michael@0 | 156 | |
michael@0 | 157 | static void SetCompositor(mozilla::layers::LayerManager* aLayerManager, |
michael@0 | 158 | mozilla::layers::CompositorParent* aCompositorParent, |
michael@0 | 159 | mozilla::layers::CompositorChild* aCompositorChild); |
michael@0 | 160 | static void ScheduleComposite(); |
michael@0 | 161 | static void ScheduleResumeComposition(int width, int height); |
michael@0 | 162 | static void ForceIsFirstPaint(); |
michael@0 | 163 | static float ComputeRenderIntegrity(); |
michael@0 | 164 | static mozilla::layers::APZCTreeManager* GetAPZCTreeManager(); |
michael@0 | 165 | /* RootLayerTreeId() can only be called when GetAPZCTreeManager() returns non-null */ |
michael@0 | 166 | static uint64_t RootLayerTreeId(); |
michael@0 | 167 | |
michael@0 | 168 | virtual bool WidgetPaintsBackground(); |
michael@0 | 169 | |
michael@0 | 170 | protected: |
michael@0 | 171 | void BringToFront(); |
michael@0 | 172 | nsWindow *FindTopLevel(); |
michael@0 | 173 | bool DrawTo(gfxASurface *targetSurface); |
michael@0 | 174 | bool DrawTo(gfxASurface *targetSurface, const nsIntRect &aRect); |
michael@0 | 175 | bool IsTopLevel(); |
michael@0 | 176 | void RemoveIMEComposition(); |
michael@0 | 177 | void PostFlushIMEChanges(); |
michael@0 | 178 | void FlushIMEChanges(); |
michael@0 | 179 | |
michael@0 | 180 | // Call this function when the users activity is the direct cause of an |
michael@0 | 181 | // event (like a keypress or mouse click). |
michael@0 | 182 | void UserActivity(); |
michael@0 | 183 | |
michael@0 | 184 | bool mIsVisible; |
michael@0 | 185 | nsTArray<nsWindow*> mChildren; |
michael@0 | 186 | nsWindow* mParent; |
michael@0 | 187 | nsWindow* mFocus; |
michael@0 | 188 | |
michael@0 | 189 | double mStartDist; |
michael@0 | 190 | double mLastDist; |
michael@0 | 191 | |
michael@0 | 192 | nsCOMPtr<nsIIdleServiceInternal> mIdleService; |
michael@0 | 193 | |
michael@0 | 194 | bool mIMEComposing; |
michael@0 | 195 | bool mIMEMaskSelectionUpdate, mIMEMaskTextUpdate; |
michael@0 | 196 | int32_t mIMEMaskEventsCount; // Mask events when > 0 |
michael@0 | 197 | nsString mIMEComposingText; |
michael@0 | 198 | nsRefPtr<mozilla::TextRangeArray> mIMERanges; |
michael@0 | 199 | bool mIMEUpdatingContext; |
michael@0 | 200 | nsAutoTArray<mozilla::AndroidGeckoEvent, 8> mIMEKeyEvents; |
michael@0 | 201 | |
michael@0 | 202 | struct IMEChange { |
michael@0 | 203 | int32_t mStart, mOldEnd, mNewEnd; |
michael@0 | 204 | |
michael@0 | 205 | IMEChange() : |
michael@0 | 206 | mStart(-1), mOldEnd(-1), mNewEnd(-1) |
michael@0 | 207 | { |
michael@0 | 208 | } |
michael@0 | 209 | IMEChange(const IMENotification& aIMENotification) |
michael@0 | 210 | : mStart(aIMENotification.mTextChangeData.mStartOffset) |
michael@0 | 211 | , mOldEnd(aIMENotification.mTextChangeData.mOldEndOffset) |
michael@0 | 212 | , mNewEnd(aIMENotification.mTextChangeData.mNewEndOffset) |
michael@0 | 213 | { |
michael@0 | 214 | MOZ_ASSERT(aIMENotification.mMessage == |
michael@0 | 215 | mozilla::widget::NOTIFY_IME_OF_TEXT_CHANGE, |
michael@0 | 216 | "IMEChange initialized with wrong notification"); |
michael@0 | 217 | MOZ_ASSERT(aIMENotification.mTextChangeData.IsInInt32Range(), |
michael@0 | 218 | "The text change notification is out of range"); |
michael@0 | 219 | } |
michael@0 | 220 | bool IsEmpty() |
michael@0 | 221 | { |
michael@0 | 222 | return mStart < 0; |
michael@0 | 223 | } |
michael@0 | 224 | }; |
michael@0 | 225 | nsAutoTArray<IMEChange, 4> mIMETextChanges; |
michael@0 | 226 | bool mIMESelectionChanged; |
michael@0 | 227 | |
michael@0 | 228 | InputContext mInputContext; |
michael@0 | 229 | |
michael@0 | 230 | static void DumpWindows(); |
michael@0 | 231 | static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0); |
michael@0 | 232 | static void LogWindow(nsWindow *win, int index, int indent); |
michael@0 | 233 | |
michael@0 | 234 | private: |
michael@0 | 235 | void InitKeyEvent(mozilla::WidgetKeyboardEvent& event, |
michael@0 | 236 | mozilla::AndroidGeckoEvent& key, |
michael@0 | 237 | ANPEvent* pluginEvent); |
michael@0 | 238 | void DispatchMotionEvent(mozilla::WidgetInputEvent &event, |
michael@0 | 239 | mozilla::AndroidGeckoEvent *ae, |
michael@0 | 240 | const nsIntPoint &refPoint); |
michael@0 | 241 | void DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta, |
michael@0 | 242 | const nsIntPoint &refPoint, uint64_t time); |
michael@0 | 243 | void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae); |
michael@0 | 244 | void CreateLayerManager(int aCompositorWidth, int aCompositorHeight); |
michael@0 | 245 | void RedrawAll(); |
michael@0 | 246 | |
michael@0 | 247 | mozilla::AndroidLayerRendererFrame mLayerRendererFrame; |
michael@0 | 248 | |
michael@0 | 249 | static mozilla::StaticRefPtr<mozilla::layers::APZCTreeManager> sApzcTreeManager; |
michael@0 | 250 | static mozilla::StaticRefPtr<mozilla::layers::LayerManager> sLayerManager; |
michael@0 | 251 | static mozilla::StaticRefPtr<mozilla::layers::CompositorParent> sCompositorParent; |
michael@0 | 252 | static mozilla::StaticRefPtr<mozilla::layers::CompositorChild> sCompositorChild; |
michael@0 | 253 | static bool sCompositorPaused; |
michael@0 | 254 | }; |
michael@0 | 255 | |
michael@0 | 256 | #endif /* NSWINDOW_H_ */ |