widget/android/nsWindow.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial