1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/android/nsWindow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,256 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NSWINDOW_H_ 1.10 +#define NSWINDOW_H_ 1.11 + 1.12 +#include "nsBaseWidget.h" 1.13 +#include "gfxPoint.h" 1.14 +#include "nsIIdleServiceInternal.h" 1.15 +#include "nsTArray.h" 1.16 +#include "AndroidJavaWrappers.h" 1.17 +#include "GeneratedJNIWrappers.h" 1.18 +#include "mozilla/EventForwards.h" 1.19 +#include "mozilla/StaticPtr.h" 1.20 +#include "mozilla/TextRange.h" 1.21 + 1.22 +class gfxASurface; 1.23 + 1.24 +struct ANPEvent; 1.25 + 1.26 +namespace mozilla { 1.27 + class AndroidGeckoEvent; 1.28 + 1.29 + namespace layers { 1.30 + class CompositorParent; 1.31 + class CompositorChild; 1.32 + class LayerManager; 1.33 + class APZCTreeManager; 1.34 + } 1.35 +} 1.36 + 1.37 +class nsWindow : 1.38 + public nsBaseWidget 1.39 +{ 1.40 +public: 1.41 + using nsBaseWidget::GetLayerManager; 1.42 + 1.43 + nsWindow(); 1.44 + virtual ~nsWindow(); 1.45 + 1.46 + NS_DECL_ISUPPORTS_INHERITED 1.47 + 1.48 + static void OnGlobalAndroidEvent(mozilla::AndroidGeckoEvent *ae); 1.49 + static gfxIntSize GetAndroidScreenBounds(); 1.50 + static nsWindow* TopWindow(); 1.51 + 1.52 + nsWindow* FindWindowForPoint(const nsIntPoint& pt); 1.53 + 1.54 + void OnAndroidEvent(mozilla::AndroidGeckoEvent *ae); 1.55 + void OnDraw(mozilla::AndroidGeckoEvent *ae); 1.56 + bool OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae); 1.57 + void OnNativeGestureEvent(mozilla::AndroidGeckoEvent *ae); 1.58 + void OnMouseEvent(mozilla::AndroidGeckoEvent *ae); 1.59 + void OnKeyEvent(mozilla::AndroidGeckoEvent *ae); 1.60 + void OnIMEEvent(mozilla::AndroidGeckoEvent *ae); 1.61 + 1.62 + void OnSizeChanged(const gfxIntSize& aSize); 1.63 + 1.64 + void InitEvent(mozilla::WidgetGUIEvent& event, nsIntPoint* aPoint = 0); 1.65 + 1.66 + // 1.67 + // nsIWidget 1.68 + // 1.69 + 1.70 + NS_IMETHOD Create(nsIWidget *aParent, 1.71 + nsNativeWidget aNativeParent, 1.72 + const nsIntRect &aRect, 1.73 + nsDeviceContext *aContext, 1.74 + nsWidgetInitData *aInitData); 1.75 + NS_IMETHOD Destroy(void); 1.76 + NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&); 1.77 + NS_IMETHOD SetParent(nsIWidget* aNewParent); 1.78 + virtual nsIWidget *GetParent(void); 1.79 + virtual float GetDPI(); 1.80 + virtual double GetDefaultScaleInternal(); 1.81 + NS_IMETHOD Show(bool aState); 1.82 + NS_IMETHOD SetModal(bool aModal); 1.83 + virtual bool IsVisible() const; 1.84 + NS_IMETHOD ConstrainPosition(bool aAllowSlop, 1.85 + int32_t *aX, 1.86 + int32_t *aY); 1.87 + NS_IMETHOD Move(double aX, 1.88 + double aY); 1.89 + NS_IMETHOD Resize(double aWidth, 1.90 + double aHeight, 1.91 + bool aRepaint); 1.92 + NS_IMETHOD Resize(double aX, 1.93 + double aY, 1.94 + double aWidth, 1.95 + double aHeight, 1.96 + bool aRepaint); 1.97 + void SetZIndex(int32_t aZIndex); 1.98 + NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, 1.99 + nsIWidget *aWidget, 1.100 + bool aActivate); 1.101 + NS_IMETHOD SetSizeMode(int32_t aMode); 1.102 + NS_IMETHOD Enable(bool aState); 1.103 + virtual bool IsEnabled() const; 1.104 + NS_IMETHOD Invalidate(const nsIntRect &aRect); 1.105 + NS_IMETHOD SetFocus(bool aRaise = false); 1.106 + NS_IMETHOD GetScreenBounds(nsIntRect &aRect); 1.107 + virtual nsIntPoint WidgetToScreenOffset(); 1.108 + NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 1.109 + nsEventStatus& aStatus); 1.110 + nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent); 1.111 + NS_IMETHOD MakeFullScreen(bool aFullScreen); 1.112 + NS_IMETHOD SetWindowClass(const nsAString& xulWinType); 1.113 + 1.114 + 1.115 + 1.116 + NS_IMETHOD SetCursor(nsCursor aCursor) { return NS_ERROR_NOT_IMPLEMENTED; } 1.117 + NS_IMETHOD SetCursor(imgIContainer* aCursor, 1.118 + uint32_t aHotspotX, 1.119 + uint32_t aHotspotY) { return NS_ERROR_NOT_IMPLEMENTED; } 1.120 + NS_IMETHOD SetHasTransparentBackground(bool aTransparent) { return NS_OK; } 1.121 + NS_IMETHOD GetHasTransparentBackground(bool& aTransparent) { aTransparent = false; return NS_OK; } 1.122 + NS_IMETHOD HideWindowChrome(bool aShouldHide) { return NS_ERROR_NOT_IMPLEMENTED; } 1.123 + virtual void* GetNativeData(uint32_t aDataType); 1.124 + NS_IMETHOD SetTitle(const nsAString& aTitle) { return NS_OK; } 1.125 + NS_IMETHOD SetIcon(const nsAString& aIconSpec) { return NS_OK; } 1.126 + NS_IMETHOD EnableDragDrop(bool aEnable) { return NS_OK; } 1.127 + NS_IMETHOD CaptureMouse(bool aCapture) { return NS_ERROR_NOT_IMPLEMENTED; } 1.128 + NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, 1.129 + bool aDoCapture) { return NS_ERROR_NOT_IMPLEMENTED; } 1.130 + 1.131 + NS_IMETHOD GetAttention(int32_t aCycleCount) { return NS_ERROR_NOT_IMPLEMENTED; } 1.132 + NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, 1.133 + int32_t aHorizontal, 1.134 + int32_t aVertical) 1.135 + { 1.136 + return NS_ERROR_NOT_IMPLEMENTED; 1.137 + } 1.138 + 1.139 + NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; 1.140 + NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, 1.141 + const InputContextAction& aAction); 1.142 + NS_IMETHOD_(InputContext) GetInputContext(); 1.143 + 1.144 + nsresult NotifyIMEOfTextChange(const IMENotification& aIMENotification); 1.145 + virtual nsIMEUpdatePreference GetIMEUpdatePreference(); 1.146 + 1.147 + LayerManager* GetLayerManager (PLayerTransactionChild* aShadowManager = nullptr, 1.148 + LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 1.149 + LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, 1.150 + bool* aAllowRetaining = nullptr); 1.151 + 1.152 + NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); 1.153 + 1.154 + virtual bool NeedsPaint(); 1.155 + virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect); 1.156 + virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect); 1.157 + 1.158 + virtual mozilla::layers::CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) MOZ_OVERRIDE; 1.159 + 1.160 + static void SetCompositor(mozilla::layers::LayerManager* aLayerManager, 1.161 + mozilla::layers::CompositorParent* aCompositorParent, 1.162 + mozilla::layers::CompositorChild* aCompositorChild); 1.163 + static void ScheduleComposite(); 1.164 + static void ScheduleResumeComposition(int width, int height); 1.165 + static void ForceIsFirstPaint(); 1.166 + static float ComputeRenderIntegrity(); 1.167 + static mozilla::layers::APZCTreeManager* GetAPZCTreeManager(); 1.168 + /* RootLayerTreeId() can only be called when GetAPZCTreeManager() returns non-null */ 1.169 + static uint64_t RootLayerTreeId(); 1.170 + 1.171 + virtual bool WidgetPaintsBackground(); 1.172 + 1.173 +protected: 1.174 + void BringToFront(); 1.175 + nsWindow *FindTopLevel(); 1.176 + bool DrawTo(gfxASurface *targetSurface); 1.177 + bool DrawTo(gfxASurface *targetSurface, const nsIntRect &aRect); 1.178 + bool IsTopLevel(); 1.179 + void RemoveIMEComposition(); 1.180 + void PostFlushIMEChanges(); 1.181 + void FlushIMEChanges(); 1.182 + 1.183 + // Call this function when the users activity is the direct cause of an 1.184 + // event (like a keypress or mouse click). 1.185 + void UserActivity(); 1.186 + 1.187 + bool mIsVisible; 1.188 + nsTArray<nsWindow*> mChildren; 1.189 + nsWindow* mParent; 1.190 + nsWindow* mFocus; 1.191 + 1.192 + double mStartDist; 1.193 + double mLastDist; 1.194 + 1.195 + nsCOMPtr<nsIIdleServiceInternal> mIdleService; 1.196 + 1.197 + bool mIMEComposing; 1.198 + bool mIMEMaskSelectionUpdate, mIMEMaskTextUpdate; 1.199 + int32_t mIMEMaskEventsCount; // Mask events when > 0 1.200 + nsString mIMEComposingText; 1.201 + nsRefPtr<mozilla::TextRangeArray> mIMERanges; 1.202 + bool mIMEUpdatingContext; 1.203 + nsAutoTArray<mozilla::AndroidGeckoEvent, 8> mIMEKeyEvents; 1.204 + 1.205 + struct IMEChange { 1.206 + int32_t mStart, mOldEnd, mNewEnd; 1.207 + 1.208 + IMEChange() : 1.209 + mStart(-1), mOldEnd(-1), mNewEnd(-1) 1.210 + { 1.211 + } 1.212 + IMEChange(const IMENotification& aIMENotification) 1.213 + : mStart(aIMENotification.mTextChangeData.mStartOffset) 1.214 + , mOldEnd(aIMENotification.mTextChangeData.mOldEndOffset) 1.215 + , mNewEnd(aIMENotification.mTextChangeData.mNewEndOffset) 1.216 + { 1.217 + MOZ_ASSERT(aIMENotification.mMessage == 1.218 + mozilla::widget::NOTIFY_IME_OF_TEXT_CHANGE, 1.219 + "IMEChange initialized with wrong notification"); 1.220 + MOZ_ASSERT(aIMENotification.mTextChangeData.IsInInt32Range(), 1.221 + "The text change notification is out of range"); 1.222 + } 1.223 + bool IsEmpty() 1.224 + { 1.225 + return mStart < 0; 1.226 + } 1.227 + }; 1.228 + nsAutoTArray<IMEChange, 4> mIMETextChanges; 1.229 + bool mIMESelectionChanged; 1.230 + 1.231 + InputContext mInputContext; 1.232 + 1.233 + static void DumpWindows(); 1.234 + static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0); 1.235 + static void LogWindow(nsWindow *win, int index, int indent); 1.236 + 1.237 +private: 1.238 + void InitKeyEvent(mozilla::WidgetKeyboardEvent& event, 1.239 + mozilla::AndroidGeckoEvent& key, 1.240 + ANPEvent* pluginEvent); 1.241 + void DispatchMotionEvent(mozilla::WidgetInputEvent &event, 1.242 + mozilla::AndroidGeckoEvent *ae, 1.243 + const nsIntPoint &refPoint); 1.244 + void DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta, 1.245 + const nsIntPoint &refPoint, uint64_t time); 1.246 + void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae); 1.247 + void CreateLayerManager(int aCompositorWidth, int aCompositorHeight); 1.248 + void RedrawAll(); 1.249 + 1.250 + mozilla::AndroidLayerRendererFrame mLayerRendererFrame; 1.251 + 1.252 + static mozilla::StaticRefPtr<mozilla::layers::APZCTreeManager> sApzcTreeManager; 1.253 + static mozilla::StaticRefPtr<mozilla::layers::LayerManager> sLayerManager; 1.254 + static mozilla::StaticRefPtr<mozilla::layers::CompositorParent> sCompositorParent; 1.255 + static mozilla::StaticRefPtr<mozilla::layers::CompositorChild> sCompositorChild; 1.256 + static bool sCompositorPaused; 1.257 +}; 1.258 + 1.259 +#endif /* NSWINDOW_H_ */