widget/qt/nsWindow.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/qt/nsWindow.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,340 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef __nsWindow_h__
    1.12 +#define __nsWindow_h__
    1.13 +
    1.14 +#include <QPointF>
    1.15 +
    1.16 +#include "nsAutoPtr.h"
    1.17 +#include "nsBaseWidget.h"
    1.18 +#include "mozilla/EventForwards.h"
    1.19 +
    1.20 +#include "nsWeakReference.h"
    1.21 +
    1.22 +#include "nsGkAtoms.h"
    1.23 +#include "nsIIdleServiceInternal.h"
    1.24 +#include "nsIRunnable.h"
    1.25 +#include "nsThreadUtils.h"
    1.26 +
    1.27 +#ifdef MOZ_LOGGING
    1.28 +
    1.29 +// make sure that logging is enabled before including prlog.h
    1.30 +#define FORCE_PR_LOG
    1.31 +
    1.32 +#include "prlog.h"
    1.33 +#include "nsTArray.h"
    1.34 +
    1.35 +extern PRLogModuleInfo *gWidgetLog;
    1.36 +extern PRLogModuleInfo *gWidgetFocusLog;
    1.37 +extern PRLogModuleInfo *gWidgetIMLog;
    1.38 +extern PRLogModuleInfo *gWidgetDrawLog;
    1.39 +
    1.40 +#define LOG(args) PR_LOG(gWidgetLog, 4, args)
    1.41 +#define LOGFOCUS(args) PR_LOG(gWidgetFocusLog, 4, args)
    1.42 +#define LOGIM(args) PR_LOG(gWidgetIMLog, 4, args)
    1.43 +#define LOGDRAW(args) PR_LOG(gWidgetDrawLog, 4, args)
    1.44 +
    1.45 +#else
    1.46 +
    1.47 +#ifdef DEBUG_WIDGETS
    1.48 +
    1.49 +#define PR_LOG2(_args)         \
    1.50 +    PR_BEGIN_MACRO             \
    1.51 +      qDebug _args;            \
    1.52 +    PR_END_MACRO
    1.53 +
    1.54 +#define LOG(args) PR_LOG2(args)
    1.55 +#define LOGFOCUS(args) PR_LOG2(args)
    1.56 +#define LOGIM(args) PR_LOG2(args)
    1.57 +#define LOGDRAW(args) PR_LOG2(args)
    1.58 +
    1.59 +#else
    1.60 +
    1.61 +#define LOG(args)
    1.62 +#define LOGFOCUS(args)
    1.63 +#define LOGIM(args)
    1.64 +#define LOGDRAW(args)
    1.65 +
    1.66 +#endif
    1.67 +
    1.68 +#endif /* MOZ_LOGGING */
    1.69 +
    1.70 +class nsIdleService;
    1.71 +class QCloseEvent;
    1.72 +class QFocusEvent;
    1.73 +class QHideEvent;
    1.74 +class QKeyEvent;
    1.75 +class QMouseEvent;
    1.76 +class QMoveEvent;
    1.77 +class QResizeEvent;
    1.78 +class QShowEvent;
    1.79 +class QTabletEvent;
    1.80 +class QTouchEvent;
    1.81 +class QWheelEvent;
    1.82 +
    1.83 +namespace mozilla {
    1.84 +namespace widget {
    1.85 +class MozQWidget;
    1.86 +class nsWindow : public nsBaseWidget,
    1.87 +                 public nsSupportsWeakReference
    1.88 +{
    1.89 +public:
    1.90 +    nsWindow();
    1.91 +    virtual ~nsWindow();
    1.92 +
    1.93 +    NS_DECL_ISUPPORTS_INHERITED
    1.94 +
    1.95 +    //
    1.96 +    // nsIWidget
    1.97 +    //
    1.98 +    NS_IMETHOD Create(nsIWidget        *aParent,
    1.99 +                      nsNativeWidget   aNativeParent,
   1.100 +                      const nsIntRect  &aRect,
   1.101 +                      nsDeviceContext *aContext,
   1.102 +                      nsWidgetInitData *aInitData);
   1.103 +    NS_IMETHOD Destroy(void);
   1.104 +
   1.105 +    NS_IMETHOD Show(bool aState);
   1.106 +    virtual bool IsVisible() const;
   1.107 +    NS_IMETHOD ConstrainPosition(bool aAllowSlop,
   1.108 +                                 int32_t *aX,
   1.109 +                                 int32_t *aY);
   1.110 +    NS_IMETHOD Move(double aX,
   1.111 +                    double aY);
   1.112 +    NS_IMETHOD Resize(double aWidth,
   1.113 +                      double aHeight,
   1.114 +                      bool   aRepaint);
   1.115 +    NS_IMETHOD Resize(double aX,
   1.116 +                      double aY,
   1.117 +                      double aWidth,
   1.118 +                      double aHeight,
   1.119 +                      bool   aRepaint);
   1.120 +    NS_IMETHOD Enable(bool aState);
   1.121 +    // Some of the nsIWidget methods
   1.122 +    virtual bool IsEnabled() const;
   1.123 +    NS_IMETHOD SetFocus(bool aRaise = false);
   1.124 +    NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&);
   1.125 +    NS_IMETHOD         Invalidate(const nsIntRect &aRect);
   1.126 +    virtual void*      GetNativeData(uint32_t aDataType);
   1.127 +    NS_IMETHOD         SetTitle(const nsAString& aTitle);
   1.128 +    NS_IMETHOD         SetCursor(nsCursor aCursor);
   1.129 +    NS_IMETHOD         SetCursor(imgIContainer* aCursor,
   1.130 +                                 uint32_t aHotspotX, uint32_t aHotspotY)
   1.131 +    {
   1.132 +        return NS_OK;
   1.133 +    }
   1.134 +    virtual nsIntPoint WidgetToScreenOffset();
   1.135 +    NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
   1.136 +                             nsEventStatus& aStatus);
   1.137 +    NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener,
   1.138 +                                   bool aDoCapture)
   1.139 +    {
   1.140 +        return NS_ERROR_NOT_IMPLEMENTED;
   1.141 +    }
   1.142 +    NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
   1.143 +
   1.144 +    NS_IMETHOD MakeFullScreen(bool aFullScreen);
   1.145 +    virtual mozilla::layers::LayerManager*
   1.146 +        GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
   1.147 +                        LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
   1.148 +                        LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
   1.149 +                        bool* aAllowRetaining = nullptr);
   1.150 +
   1.151 +    NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
   1.152 +                                      const InputContextAction& aAction);
   1.153 +    NS_IMETHOD_(InputContext) GetInputContext();
   1.154 +
   1.155 +    virtual uint32_t GetGLFrameBufferFormat() MOZ_OVERRIDE;
   1.156 +
   1.157 +    // Widget notifications
   1.158 +    virtual void OnPaint();
   1.159 +    virtual nsEventStatus focusInEvent(QFocusEvent* aEvent);
   1.160 +    virtual nsEventStatus focusOutEvent(QFocusEvent* aEvent);
   1.161 +    virtual nsEventStatus hideEvent(QHideEvent* aEvent);
   1.162 +    virtual nsEventStatus showEvent(QShowEvent* aEvent);
   1.163 +    virtual nsEventStatus keyPressEvent(QKeyEvent* aEvent);
   1.164 +    virtual nsEventStatus keyReleaseEvent(QKeyEvent* aEvent);
   1.165 +    virtual nsEventStatus mouseDoubleClickEvent(QMouseEvent* aEvent);
   1.166 +    virtual nsEventStatus mouseMoveEvent(QMouseEvent* aEvent);
   1.167 +    virtual nsEventStatus mousePressEvent(QMouseEvent* aEvent);
   1.168 +    virtual nsEventStatus mouseReleaseEvent(QMouseEvent* aEvent);
   1.169 +    virtual nsEventStatus moveEvent(QMoveEvent* aEvent);
   1.170 +    virtual nsEventStatus resizeEvent(QResizeEvent* aEvent);
   1.171 +    virtual nsEventStatus touchEvent(QTouchEvent* aEvent);
   1.172 +    virtual nsEventStatus wheelEvent(QWheelEvent* aEvent);
   1.173 +    virtual nsEventStatus tabletEvent(QTabletEvent* event);
   1.174 +
   1.175 +protected:
   1.176 +    nsWindow* mParent;
   1.177 +    bool  mVisible;
   1.178 +    InputContext mInputContext;
   1.179 +    nsCOMPtr<nsIIdleServiceInternal> mIdleService;
   1.180 +    MozQWidget* mWidget;
   1.181 +
   1.182 +private:
   1.183 +    void InitButtonEvent(mozilla::WidgetMouseEvent& event,
   1.184 +                         QMouseEvent* aEvent,
   1.185 +                         int aClickCount = 1);
   1.186 +
   1.187 +    // event handling code
   1.188 +    nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
   1.189 +    void DispatchActivateEvent(void);
   1.190 +    void DispatchDeactivateEvent(void);
   1.191 +    void DispatchActivateEventOnTopLevelWindow(void);
   1.192 +    void DispatchDeactivateEventOnTopLevelWindow(void);
   1.193 +    void DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus);
   1.194 +
   1.195 +    // Remember the last sizemode so that we can restore it when
   1.196 +    // leaving fullscreen
   1.197 +    nsSizeMode mLastSizeMode;
   1.198 +    // is this widget enabled?
   1.199 +    bool mEnabled;
   1.200 +
   1.201 +    // Call this function when the users activity is the direct cause of an
   1.202 +    // event (like a keypress or mouse click).
   1.203 +    void UserActivity();
   1.204 +    MozQWidget* createQWidget(MozQWidget* parent,
   1.205 +                              nsWidgetInitData* aInitData);
   1.206 +
   1.207 +public:
   1.208 +    // Old QtWidget only
   1.209 +    NS_IMETHOD         SetParent(nsIWidget* aNewParent);
   1.210 +    virtual nsIWidget *GetParent(void);
   1.211 +    virtual float      GetDPI();
   1.212 +    NS_IMETHOD         SetModal(bool aModal);
   1.213 +    NS_IMETHOD         PlaceBehind(nsTopLevelWidgetZPlacement  aPlacement,
   1.214 +                                   nsIWidget                  *aWidget,
   1.215 +                                   bool                        aActivate);
   1.216 +    NS_IMETHOD         SetSizeMode(int32_t aMode);
   1.217 +    NS_IMETHOD         GetScreenBounds(nsIntRect &aRect);
   1.218 +    NS_IMETHOD         SetHasTransparentBackground(bool aTransparent);
   1.219 +    NS_IMETHOD         GetHasTransparentBackground(bool& aTransparent);
   1.220 +    NS_IMETHOD         HideWindowChrome(bool aShouldHide);
   1.221 +    NS_IMETHOD         SetIcon(const nsAString& aIconSpec);
   1.222 +    NS_IMETHOD         CaptureMouse(bool aCapture);
   1.223 +    NS_IMETHOD         SetWindowClass(const nsAString& xulWinType);
   1.224 +    NS_IMETHOD         GetAttention(int32_t aCycleCount);
   1.225 +    NS_IMETHOD_(bool)  HasGLContext();
   1.226 +
   1.227 +    //
   1.228 +    // utility methods
   1.229 +    //
   1.230 +    void               QWidgetDestroyed();
   1.231 +    // called when we are destroyed
   1.232 +    void OnDestroy(void);
   1.233 +    // called to check and see if a widget's dimensions are sane
   1.234 +    bool AreBoundsSane(void);
   1.235 +private:
   1.236 +    // Is this a toplevel window?
   1.237 +    bool                mIsTopLevel;
   1.238 +    // Has this widget been destroyed yet?
   1.239 +    bool                mIsDestroyed;
   1.240 +    // This flag tracks if we're hidden or shown.
   1.241 +    bool                mIsShown;
   1.242 +    // Has anyone set an x/y location for this widget yet? Toplevels
   1.243 +    // shouldn't be automatically set to 0,0 for first show.
   1.244 +    bool                mPlaced;
   1.245 +    /**
   1.246 +     * Event handlers (proxied from the actual qwidget).
   1.247 +     * They follow normal Qt widget semantics.
   1.248 +     */
   1.249 +    void Initialize(MozQWidget *widget);
   1.250 +    virtual nsEventStatus OnCloseEvent(QCloseEvent *);
   1.251 +    void               NativeResize(int32_t aWidth,
   1.252 +                                    int32_t aHeight,
   1.253 +                                    bool    aRepaint);
   1.254 +    void               NativeResize(int32_t aX,
   1.255 +                                    int32_t aY,
   1.256 +                                    int32_t aWidth,
   1.257 +                                    int32_t aHeight,
   1.258 +                                    bool    aRepaint);
   1.259 +    void               NativeShow  (bool    aAction);
   1.260 +
   1.261 +private:
   1.262 +    typedef struct {
   1.263 +        QPointF pos;
   1.264 +        Qt::KeyboardModifiers modifiers;
   1.265 +        bool needDispatch;
   1.266 +    } MozCachedMoveEvent;
   1.267 +
   1.268 +    bool               CheckForRollup(double aMouseX, double aMouseY, bool aIsWheel);
   1.269 +    void*              SetupPluginPort(void);
   1.270 +    nsresult           SetWindowIconList(const nsTArray<nsCString> &aIconList);
   1.271 +    void               SetDefaultIcon(void);
   1.272 +
   1.273 +    nsEventStatus      DispatchCommandEvent(nsIAtom* aCommand);
   1.274 +    nsEventStatus      DispatchContentCommandEvent(int32_t aMsg);
   1.275 +    void               SetSoftwareKeyboardState(bool aOpen, const InputContextAction& aAction);
   1.276 +    void               ClearCachedResources();
   1.277 +
   1.278 +    uint32_t           mActivatePending : 1;
   1.279 +    int32_t            mSizeState;
   1.280 +
   1.281 +    bool         mIsTransparent;
   1.282 +
   1.283 +    // all of our DND stuff
   1.284 +    // this is the last window that had a drag event happen on it.
   1.285 +    void   InitDragEvent(mozilla::WidgetMouseEvent& aEvent);
   1.286 +
   1.287 +    // this is everything we need to be able to fire motion events
   1.288 +    // repeatedly
   1.289 +    uint32_t mKeyDownFlags[8];
   1.290 +
   1.291 +    /* Helper methods for DOM Key Down event suppression. */
   1.292 +    uint32_t* GetFlagWord32(uint32_t aKeyCode, uint32_t* aMask) {
   1.293 +        /* Mozilla DOM Virtual Key Code is from 0 to 224. */
   1.294 +        NS_ASSERTION((aKeyCode <= 0xFF), "Invalid DOM Key Code");
   1.295 +        aKeyCode &= 0xFF;
   1.296 +
   1.297 +        /* 32 = 2^5 = 0x20 */
   1.298 +        *aMask = uint32_t(1) << (aKeyCode & 0x1F);
   1.299 +        return &mKeyDownFlags[(aKeyCode >> 5)];
   1.300 +    }
   1.301 +
   1.302 +    bool IsKeyDown(uint32_t aKeyCode) {
   1.303 +        uint32_t mask;
   1.304 +        uint32_t* flag = GetFlagWord32(aKeyCode, &mask);
   1.305 +        return ((*flag) & mask) != 0;
   1.306 +    }
   1.307 +
   1.308 +    void SetKeyDownFlag(uint32_t aKeyCode) {
   1.309 +        uint32_t mask;
   1.310 +        uint32_t* flag = GetFlagWord32(aKeyCode, &mask);
   1.311 +        *flag |= mask;
   1.312 +    }
   1.313 +
   1.314 +    void ClearKeyDownFlag(uint32_t aKeyCode) {
   1.315 +        uint32_t mask;
   1.316 +        uint32_t* flag = GetFlagWord32(aKeyCode, &mask);
   1.317 +        *flag &= ~mask;
   1.318 +    }
   1.319 +    int32_t mQCursor;
   1.320 +
   1.321 +
   1.322 +    void ProcessMotionEvent();
   1.323 +
   1.324 +    void DispatchMotionToMainThread() {
   1.325 +        if (!mTimerStarted) {
   1.326 +            nsCOMPtr<nsIRunnable> event =
   1.327 +                NS_NewRunnableMethod(this, &nsWindow::ProcessMotionEvent);
   1.328 +            NS_DispatchToMainThread(event);
   1.329 +            mTimerStarted = true;
   1.330 +        }
   1.331 +    }
   1.332 +
   1.333 +    bool mNeedsResize;
   1.334 +    bool mNeedsMove;
   1.335 +    bool mListenForResizes;
   1.336 +    bool mNeedsShow;
   1.337 +    MozCachedMoveEvent mMoveEvent;
   1.338 +    bool mTimerStarted;
   1.339 +};
   1.340 +
   1.341 +}}
   1.342 +
   1.343 +#endif /* __nsWindow_h__ */

mercurial