michael@0: /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NSWINDOW_H_ michael@0: #define NSWINDOW_H_ michael@0: michael@0: #include "nsBaseWidget.h" michael@0: #include "gfxPoint.h" michael@0: #include "nsIIdleServiceInternal.h" michael@0: #include "nsTArray.h" michael@0: #include "AndroidJavaWrappers.h" michael@0: #include "GeneratedJNIWrappers.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "mozilla/StaticPtr.h" michael@0: #include "mozilla/TextRange.h" michael@0: michael@0: class gfxASurface; michael@0: michael@0: struct ANPEvent; michael@0: michael@0: namespace mozilla { michael@0: class AndroidGeckoEvent; michael@0: michael@0: namespace layers { michael@0: class CompositorParent; michael@0: class CompositorChild; michael@0: class LayerManager; michael@0: class APZCTreeManager; michael@0: } michael@0: } michael@0: michael@0: class nsWindow : michael@0: public nsBaseWidget michael@0: { michael@0: public: michael@0: using nsBaseWidget::GetLayerManager; michael@0: michael@0: nsWindow(); michael@0: virtual ~nsWindow(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: static void OnGlobalAndroidEvent(mozilla::AndroidGeckoEvent *ae); michael@0: static gfxIntSize GetAndroidScreenBounds(); michael@0: static nsWindow* TopWindow(); michael@0: michael@0: nsWindow* FindWindowForPoint(const nsIntPoint& pt); michael@0: michael@0: void OnAndroidEvent(mozilla::AndroidGeckoEvent *ae); michael@0: void OnDraw(mozilla::AndroidGeckoEvent *ae); michael@0: bool OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae); michael@0: void OnNativeGestureEvent(mozilla::AndroidGeckoEvent *ae); michael@0: void OnMouseEvent(mozilla::AndroidGeckoEvent *ae); michael@0: void OnKeyEvent(mozilla::AndroidGeckoEvent *ae); michael@0: void OnIMEEvent(mozilla::AndroidGeckoEvent *ae); michael@0: michael@0: void OnSizeChanged(const gfxIntSize& aSize); michael@0: michael@0: void InitEvent(mozilla::WidgetGUIEvent& event, nsIntPoint* aPoint = 0); michael@0: michael@0: // michael@0: // nsIWidget michael@0: // michael@0: michael@0: NS_IMETHOD Create(nsIWidget *aParent, michael@0: nsNativeWidget aNativeParent, michael@0: const nsIntRect &aRect, michael@0: nsDeviceContext *aContext, michael@0: nsWidgetInitData *aInitData); michael@0: NS_IMETHOD Destroy(void); michael@0: NS_IMETHOD ConfigureChildren(const nsTArray&); michael@0: NS_IMETHOD SetParent(nsIWidget* aNewParent); michael@0: virtual nsIWidget *GetParent(void); michael@0: virtual float GetDPI(); michael@0: virtual double GetDefaultScaleInternal(); michael@0: NS_IMETHOD Show(bool aState); michael@0: NS_IMETHOD SetModal(bool aModal); michael@0: virtual bool IsVisible() const; michael@0: NS_IMETHOD ConstrainPosition(bool aAllowSlop, michael@0: int32_t *aX, michael@0: int32_t *aY); michael@0: NS_IMETHOD Move(double aX, michael@0: double aY); michael@0: NS_IMETHOD Resize(double aWidth, michael@0: double aHeight, michael@0: bool aRepaint); michael@0: NS_IMETHOD Resize(double aX, michael@0: double aY, michael@0: double aWidth, michael@0: double aHeight, michael@0: bool aRepaint); michael@0: void SetZIndex(int32_t aZIndex); michael@0: NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, michael@0: nsIWidget *aWidget, michael@0: bool aActivate); michael@0: NS_IMETHOD SetSizeMode(int32_t aMode); michael@0: NS_IMETHOD Enable(bool aState); michael@0: virtual bool IsEnabled() const; michael@0: NS_IMETHOD Invalidate(const nsIntRect &aRect); michael@0: NS_IMETHOD SetFocus(bool aRaise = false); michael@0: NS_IMETHOD GetScreenBounds(nsIntRect &aRect); michael@0: virtual nsIntPoint WidgetToScreenOffset(); michael@0: NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus& aStatus); michael@0: nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent); michael@0: NS_IMETHOD MakeFullScreen(bool aFullScreen); michael@0: NS_IMETHOD SetWindowClass(const nsAString& xulWinType); michael@0: michael@0: michael@0: michael@0: NS_IMETHOD SetCursor(nsCursor aCursor) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: NS_IMETHOD SetCursor(imgIContainer* aCursor, michael@0: uint32_t aHotspotX, michael@0: uint32_t aHotspotY) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: NS_IMETHOD SetHasTransparentBackground(bool aTransparent) { return NS_OK; } michael@0: NS_IMETHOD GetHasTransparentBackground(bool& aTransparent) { aTransparent = false; return NS_OK; } michael@0: NS_IMETHOD HideWindowChrome(bool aShouldHide) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: virtual void* GetNativeData(uint32_t aDataType); michael@0: NS_IMETHOD SetTitle(const nsAString& aTitle) { return NS_OK; } michael@0: NS_IMETHOD SetIcon(const nsAString& aIconSpec) { return NS_OK; } michael@0: NS_IMETHOD EnableDragDrop(bool aEnable) { return NS_OK; } michael@0: NS_IMETHOD CaptureMouse(bool aCapture) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, michael@0: bool aDoCapture) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: michael@0: NS_IMETHOD GetAttention(int32_t aCycleCount) { return NS_ERROR_NOT_IMPLEMENTED; } michael@0: NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, michael@0: int32_t aHorizontal, michael@0: int32_t aVertical) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; michael@0: NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, michael@0: const InputContextAction& aAction); michael@0: NS_IMETHOD_(InputContext) GetInputContext(); michael@0: michael@0: nsresult NotifyIMEOfTextChange(const IMENotification& aIMENotification); michael@0: virtual nsIMEUpdatePreference GetIMEUpdatePreference(); michael@0: michael@0: LayerManager* GetLayerManager (PLayerTransactionChild* aShadowManager = nullptr, michael@0: LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, michael@0: LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, michael@0: bool* aAllowRetaining = nullptr); michael@0: michael@0: NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); michael@0: michael@0: virtual bool NeedsPaint(); michael@0: virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect); michael@0: virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect); michael@0: michael@0: virtual mozilla::layers::CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) MOZ_OVERRIDE; michael@0: michael@0: static void SetCompositor(mozilla::layers::LayerManager* aLayerManager, michael@0: mozilla::layers::CompositorParent* aCompositorParent, michael@0: mozilla::layers::CompositorChild* aCompositorChild); michael@0: static void ScheduleComposite(); michael@0: static void ScheduleResumeComposition(int width, int height); michael@0: static void ForceIsFirstPaint(); michael@0: static float ComputeRenderIntegrity(); michael@0: static mozilla::layers::APZCTreeManager* GetAPZCTreeManager(); michael@0: /* RootLayerTreeId() can only be called when GetAPZCTreeManager() returns non-null */ michael@0: static uint64_t RootLayerTreeId(); michael@0: michael@0: virtual bool WidgetPaintsBackground(); michael@0: michael@0: protected: michael@0: void BringToFront(); michael@0: nsWindow *FindTopLevel(); michael@0: bool DrawTo(gfxASurface *targetSurface); michael@0: bool DrawTo(gfxASurface *targetSurface, const nsIntRect &aRect); michael@0: bool IsTopLevel(); michael@0: void RemoveIMEComposition(); michael@0: void PostFlushIMEChanges(); michael@0: void FlushIMEChanges(); michael@0: michael@0: // Call this function when the users activity is the direct cause of an michael@0: // event (like a keypress or mouse click). michael@0: void UserActivity(); michael@0: michael@0: bool mIsVisible; michael@0: nsTArray mChildren; michael@0: nsWindow* mParent; michael@0: nsWindow* mFocus; michael@0: michael@0: double mStartDist; michael@0: double mLastDist; michael@0: michael@0: nsCOMPtr mIdleService; michael@0: michael@0: bool mIMEComposing; michael@0: bool mIMEMaskSelectionUpdate, mIMEMaskTextUpdate; michael@0: int32_t mIMEMaskEventsCount; // Mask events when > 0 michael@0: nsString mIMEComposingText; michael@0: nsRefPtr mIMERanges; michael@0: bool mIMEUpdatingContext; michael@0: nsAutoTArray mIMEKeyEvents; michael@0: michael@0: struct IMEChange { michael@0: int32_t mStart, mOldEnd, mNewEnd; michael@0: michael@0: IMEChange() : michael@0: mStart(-1), mOldEnd(-1), mNewEnd(-1) michael@0: { michael@0: } michael@0: IMEChange(const IMENotification& aIMENotification) michael@0: : mStart(aIMENotification.mTextChangeData.mStartOffset) michael@0: , mOldEnd(aIMENotification.mTextChangeData.mOldEndOffset) michael@0: , mNewEnd(aIMENotification.mTextChangeData.mNewEndOffset) michael@0: { michael@0: MOZ_ASSERT(aIMENotification.mMessage == michael@0: mozilla::widget::NOTIFY_IME_OF_TEXT_CHANGE, michael@0: "IMEChange initialized with wrong notification"); michael@0: MOZ_ASSERT(aIMENotification.mTextChangeData.IsInInt32Range(), michael@0: "The text change notification is out of range"); michael@0: } michael@0: bool IsEmpty() michael@0: { michael@0: return mStart < 0; michael@0: } michael@0: }; michael@0: nsAutoTArray mIMETextChanges; michael@0: bool mIMESelectionChanged; michael@0: michael@0: InputContext mInputContext; michael@0: michael@0: static void DumpWindows(); michael@0: static void DumpWindows(const nsTArray& wins, int indent = 0); michael@0: static void LogWindow(nsWindow *win, int index, int indent); michael@0: michael@0: private: michael@0: void InitKeyEvent(mozilla::WidgetKeyboardEvent& event, michael@0: mozilla::AndroidGeckoEvent& key, michael@0: ANPEvent* pluginEvent); michael@0: void DispatchMotionEvent(mozilla::WidgetInputEvent &event, michael@0: mozilla::AndroidGeckoEvent *ae, michael@0: const nsIntPoint &refPoint); michael@0: void DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta, michael@0: const nsIntPoint &refPoint, uint64_t time); michael@0: void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae); michael@0: void CreateLayerManager(int aCompositorWidth, int aCompositorHeight); michael@0: void RedrawAll(); michael@0: michael@0: mozilla::AndroidLayerRendererFrame mLayerRendererFrame; michael@0: michael@0: static mozilla::StaticRefPtr sApzcTreeManager; michael@0: static mozilla::StaticRefPtr sLayerManager; michael@0: static mozilla::StaticRefPtr sCompositorParent; michael@0: static mozilla::StaticRefPtr sCompositorChild; michael@0: static bool sCompositorPaused; michael@0: }; michael@0: michael@0: #endif /* NSWINDOW_H_ */