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++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=4:tabstop=4: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef __nsWindow_h__ |
michael@0 | 9 | #define __nsWindow_h__ |
michael@0 | 10 | |
michael@0 | 11 | #include <QPointF> |
michael@0 | 12 | |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | #include "nsBaseWidget.h" |
michael@0 | 15 | #include "mozilla/EventForwards.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "nsWeakReference.h" |
michael@0 | 18 | |
michael@0 | 19 | #include "nsGkAtoms.h" |
michael@0 | 20 | #include "nsIIdleServiceInternal.h" |
michael@0 | 21 | #include "nsIRunnable.h" |
michael@0 | 22 | #include "nsThreadUtils.h" |
michael@0 | 23 | |
michael@0 | 24 | #ifdef MOZ_LOGGING |
michael@0 | 25 | |
michael@0 | 26 | // make sure that logging is enabled before including prlog.h |
michael@0 | 27 | #define FORCE_PR_LOG |
michael@0 | 28 | |
michael@0 | 29 | #include "prlog.h" |
michael@0 | 30 | #include "nsTArray.h" |
michael@0 | 31 | |
michael@0 | 32 | extern PRLogModuleInfo *gWidgetLog; |
michael@0 | 33 | extern PRLogModuleInfo *gWidgetFocusLog; |
michael@0 | 34 | extern PRLogModuleInfo *gWidgetIMLog; |
michael@0 | 35 | extern PRLogModuleInfo *gWidgetDrawLog; |
michael@0 | 36 | |
michael@0 | 37 | #define LOG(args) PR_LOG(gWidgetLog, 4, args) |
michael@0 | 38 | #define LOGFOCUS(args) PR_LOG(gWidgetFocusLog, 4, args) |
michael@0 | 39 | #define LOGIM(args) PR_LOG(gWidgetIMLog, 4, args) |
michael@0 | 40 | #define LOGDRAW(args) PR_LOG(gWidgetDrawLog, 4, args) |
michael@0 | 41 | |
michael@0 | 42 | #else |
michael@0 | 43 | |
michael@0 | 44 | #ifdef DEBUG_WIDGETS |
michael@0 | 45 | |
michael@0 | 46 | #define PR_LOG2(_args) \ |
michael@0 | 47 | PR_BEGIN_MACRO \ |
michael@0 | 48 | qDebug _args; \ |
michael@0 | 49 | PR_END_MACRO |
michael@0 | 50 | |
michael@0 | 51 | #define LOG(args) PR_LOG2(args) |
michael@0 | 52 | #define LOGFOCUS(args) PR_LOG2(args) |
michael@0 | 53 | #define LOGIM(args) PR_LOG2(args) |
michael@0 | 54 | #define LOGDRAW(args) PR_LOG2(args) |
michael@0 | 55 | |
michael@0 | 56 | #else |
michael@0 | 57 | |
michael@0 | 58 | #define LOG(args) |
michael@0 | 59 | #define LOGFOCUS(args) |
michael@0 | 60 | #define LOGIM(args) |
michael@0 | 61 | #define LOGDRAW(args) |
michael@0 | 62 | |
michael@0 | 63 | #endif |
michael@0 | 64 | |
michael@0 | 65 | #endif /* MOZ_LOGGING */ |
michael@0 | 66 | |
michael@0 | 67 | class nsIdleService; |
michael@0 | 68 | class QCloseEvent; |
michael@0 | 69 | class QFocusEvent; |
michael@0 | 70 | class QHideEvent; |
michael@0 | 71 | class QKeyEvent; |
michael@0 | 72 | class QMouseEvent; |
michael@0 | 73 | class QMoveEvent; |
michael@0 | 74 | class QResizeEvent; |
michael@0 | 75 | class QShowEvent; |
michael@0 | 76 | class QTabletEvent; |
michael@0 | 77 | class QTouchEvent; |
michael@0 | 78 | class QWheelEvent; |
michael@0 | 79 | |
michael@0 | 80 | namespace mozilla { |
michael@0 | 81 | namespace widget { |
michael@0 | 82 | class MozQWidget; |
michael@0 | 83 | class nsWindow : public nsBaseWidget, |
michael@0 | 84 | public nsSupportsWeakReference |
michael@0 | 85 | { |
michael@0 | 86 | public: |
michael@0 | 87 | nsWindow(); |
michael@0 | 88 | virtual ~nsWindow(); |
michael@0 | 89 | |
michael@0 | 90 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 91 | |
michael@0 | 92 | // |
michael@0 | 93 | // nsIWidget |
michael@0 | 94 | // |
michael@0 | 95 | NS_IMETHOD Create(nsIWidget *aParent, |
michael@0 | 96 | nsNativeWidget aNativeParent, |
michael@0 | 97 | const nsIntRect &aRect, |
michael@0 | 98 | nsDeviceContext *aContext, |
michael@0 | 99 | nsWidgetInitData *aInitData); |
michael@0 | 100 | NS_IMETHOD Destroy(void); |
michael@0 | 101 | |
michael@0 | 102 | NS_IMETHOD Show(bool aState); |
michael@0 | 103 | virtual bool IsVisible() const; |
michael@0 | 104 | NS_IMETHOD ConstrainPosition(bool aAllowSlop, |
michael@0 | 105 | int32_t *aX, |
michael@0 | 106 | int32_t *aY); |
michael@0 | 107 | NS_IMETHOD Move(double aX, |
michael@0 | 108 | double aY); |
michael@0 | 109 | NS_IMETHOD Resize(double aWidth, |
michael@0 | 110 | double aHeight, |
michael@0 | 111 | bool aRepaint); |
michael@0 | 112 | NS_IMETHOD Resize(double aX, |
michael@0 | 113 | double aY, |
michael@0 | 114 | double aWidth, |
michael@0 | 115 | double aHeight, |
michael@0 | 116 | bool aRepaint); |
michael@0 | 117 | NS_IMETHOD Enable(bool aState); |
michael@0 | 118 | // Some of the nsIWidget methods |
michael@0 | 119 | virtual bool IsEnabled() const; |
michael@0 | 120 | NS_IMETHOD SetFocus(bool aRaise = false); |
michael@0 | 121 | NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&); |
michael@0 | 122 | NS_IMETHOD Invalidate(const nsIntRect &aRect); |
michael@0 | 123 | virtual void* GetNativeData(uint32_t aDataType); |
michael@0 | 124 | NS_IMETHOD SetTitle(const nsAString& aTitle); |
michael@0 | 125 | NS_IMETHOD SetCursor(nsCursor aCursor); |
michael@0 | 126 | NS_IMETHOD SetCursor(imgIContainer* aCursor, |
michael@0 | 127 | uint32_t aHotspotX, uint32_t aHotspotY) |
michael@0 | 128 | { |
michael@0 | 129 | return NS_OK; |
michael@0 | 130 | } |
michael@0 | 131 | virtual nsIntPoint WidgetToScreenOffset(); |
michael@0 | 132 | NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 133 | nsEventStatus& aStatus); |
michael@0 | 134 | NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, |
michael@0 | 135 | bool aDoCapture) |
michael@0 | 136 | { |
michael@0 | 137 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 138 | } |
michael@0 | 139 | NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); |
michael@0 | 140 | |
michael@0 | 141 | NS_IMETHOD MakeFullScreen(bool aFullScreen); |
michael@0 | 142 | virtual mozilla::layers::LayerManager* |
michael@0 | 143 | GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, |
michael@0 | 144 | LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, |
michael@0 | 145 | LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, |
michael@0 | 146 | bool* aAllowRetaining = nullptr); |
michael@0 | 147 | |
michael@0 | 148 | NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, |
michael@0 | 149 | const InputContextAction& aAction); |
michael@0 | 150 | NS_IMETHOD_(InputContext) GetInputContext(); |
michael@0 | 151 | |
michael@0 | 152 | virtual uint32_t GetGLFrameBufferFormat() MOZ_OVERRIDE; |
michael@0 | 153 | |
michael@0 | 154 | // Widget notifications |
michael@0 | 155 | virtual void OnPaint(); |
michael@0 | 156 | virtual nsEventStatus focusInEvent(QFocusEvent* aEvent); |
michael@0 | 157 | virtual nsEventStatus focusOutEvent(QFocusEvent* aEvent); |
michael@0 | 158 | virtual nsEventStatus hideEvent(QHideEvent* aEvent); |
michael@0 | 159 | virtual nsEventStatus showEvent(QShowEvent* aEvent); |
michael@0 | 160 | virtual nsEventStatus keyPressEvent(QKeyEvent* aEvent); |
michael@0 | 161 | virtual nsEventStatus keyReleaseEvent(QKeyEvent* aEvent); |
michael@0 | 162 | virtual nsEventStatus mouseDoubleClickEvent(QMouseEvent* aEvent); |
michael@0 | 163 | virtual nsEventStatus mouseMoveEvent(QMouseEvent* aEvent); |
michael@0 | 164 | virtual nsEventStatus mousePressEvent(QMouseEvent* aEvent); |
michael@0 | 165 | virtual nsEventStatus mouseReleaseEvent(QMouseEvent* aEvent); |
michael@0 | 166 | virtual nsEventStatus moveEvent(QMoveEvent* aEvent); |
michael@0 | 167 | virtual nsEventStatus resizeEvent(QResizeEvent* aEvent); |
michael@0 | 168 | virtual nsEventStatus touchEvent(QTouchEvent* aEvent); |
michael@0 | 169 | virtual nsEventStatus wheelEvent(QWheelEvent* aEvent); |
michael@0 | 170 | virtual nsEventStatus tabletEvent(QTabletEvent* event); |
michael@0 | 171 | |
michael@0 | 172 | protected: |
michael@0 | 173 | nsWindow* mParent; |
michael@0 | 174 | bool mVisible; |
michael@0 | 175 | InputContext mInputContext; |
michael@0 | 176 | nsCOMPtr<nsIIdleServiceInternal> mIdleService; |
michael@0 | 177 | MozQWidget* mWidget; |
michael@0 | 178 | |
michael@0 | 179 | private: |
michael@0 | 180 | void InitButtonEvent(mozilla::WidgetMouseEvent& event, |
michael@0 | 181 | QMouseEvent* aEvent, |
michael@0 | 182 | int aClickCount = 1); |
michael@0 | 183 | |
michael@0 | 184 | // event handling code |
michael@0 | 185 | nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent); |
michael@0 | 186 | void DispatchActivateEvent(void); |
michael@0 | 187 | void DispatchDeactivateEvent(void); |
michael@0 | 188 | void DispatchActivateEventOnTopLevelWindow(void); |
michael@0 | 189 | void DispatchDeactivateEventOnTopLevelWindow(void); |
michael@0 | 190 | void DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus); |
michael@0 | 191 | |
michael@0 | 192 | // Remember the last sizemode so that we can restore it when |
michael@0 | 193 | // leaving fullscreen |
michael@0 | 194 | nsSizeMode mLastSizeMode; |
michael@0 | 195 | // is this widget enabled? |
michael@0 | 196 | bool mEnabled; |
michael@0 | 197 | |
michael@0 | 198 | // Call this function when the users activity is the direct cause of an |
michael@0 | 199 | // event (like a keypress or mouse click). |
michael@0 | 200 | void UserActivity(); |
michael@0 | 201 | MozQWidget* createQWidget(MozQWidget* parent, |
michael@0 | 202 | nsWidgetInitData* aInitData); |
michael@0 | 203 | |
michael@0 | 204 | public: |
michael@0 | 205 | // Old QtWidget only |
michael@0 | 206 | NS_IMETHOD SetParent(nsIWidget* aNewParent); |
michael@0 | 207 | virtual nsIWidget *GetParent(void); |
michael@0 | 208 | virtual float GetDPI(); |
michael@0 | 209 | NS_IMETHOD SetModal(bool aModal); |
michael@0 | 210 | NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, |
michael@0 | 211 | nsIWidget *aWidget, |
michael@0 | 212 | bool aActivate); |
michael@0 | 213 | NS_IMETHOD SetSizeMode(int32_t aMode); |
michael@0 | 214 | NS_IMETHOD GetScreenBounds(nsIntRect &aRect); |
michael@0 | 215 | NS_IMETHOD SetHasTransparentBackground(bool aTransparent); |
michael@0 | 216 | NS_IMETHOD GetHasTransparentBackground(bool& aTransparent); |
michael@0 | 217 | NS_IMETHOD HideWindowChrome(bool aShouldHide); |
michael@0 | 218 | NS_IMETHOD SetIcon(const nsAString& aIconSpec); |
michael@0 | 219 | NS_IMETHOD CaptureMouse(bool aCapture); |
michael@0 | 220 | NS_IMETHOD SetWindowClass(const nsAString& xulWinType); |
michael@0 | 221 | NS_IMETHOD GetAttention(int32_t aCycleCount); |
michael@0 | 222 | NS_IMETHOD_(bool) HasGLContext(); |
michael@0 | 223 | |
michael@0 | 224 | // |
michael@0 | 225 | // utility methods |
michael@0 | 226 | // |
michael@0 | 227 | void QWidgetDestroyed(); |
michael@0 | 228 | // called when we are destroyed |
michael@0 | 229 | void OnDestroy(void); |
michael@0 | 230 | // called to check and see if a widget's dimensions are sane |
michael@0 | 231 | bool AreBoundsSane(void); |
michael@0 | 232 | private: |
michael@0 | 233 | // Is this a toplevel window? |
michael@0 | 234 | bool mIsTopLevel; |
michael@0 | 235 | // Has this widget been destroyed yet? |
michael@0 | 236 | bool mIsDestroyed; |
michael@0 | 237 | // This flag tracks if we're hidden or shown. |
michael@0 | 238 | bool mIsShown; |
michael@0 | 239 | // Has anyone set an x/y location for this widget yet? Toplevels |
michael@0 | 240 | // shouldn't be automatically set to 0,0 for first show. |
michael@0 | 241 | bool mPlaced; |
michael@0 | 242 | /** |
michael@0 | 243 | * Event handlers (proxied from the actual qwidget). |
michael@0 | 244 | * They follow normal Qt widget semantics. |
michael@0 | 245 | */ |
michael@0 | 246 | void Initialize(MozQWidget *widget); |
michael@0 | 247 | virtual nsEventStatus OnCloseEvent(QCloseEvent *); |
michael@0 | 248 | void NativeResize(int32_t aWidth, |
michael@0 | 249 | int32_t aHeight, |
michael@0 | 250 | bool aRepaint); |
michael@0 | 251 | void NativeResize(int32_t aX, |
michael@0 | 252 | int32_t aY, |
michael@0 | 253 | int32_t aWidth, |
michael@0 | 254 | int32_t aHeight, |
michael@0 | 255 | bool aRepaint); |
michael@0 | 256 | void NativeShow (bool aAction); |
michael@0 | 257 | |
michael@0 | 258 | private: |
michael@0 | 259 | typedef struct { |
michael@0 | 260 | QPointF pos; |
michael@0 | 261 | Qt::KeyboardModifiers modifiers; |
michael@0 | 262 | bool needDispatch; |
michael@0 | 263 | } MozCachedMoveEvent; |
michael@0 | 264 | |
michael@0 | 265 | bool CheckForRollup(double aMouseX, double aMouseY, bool aIsWheel); |
michael@0 | 266 | void* SetupPluginPort(void); |
michael@0 | 267 | nsresult SetWindowIconList(const nsTArray<nsCString> &aIconList); |
michael@0 | 268 | void SetDefaultIcon(void); |
michael@0 | 269 | |
michael@0 | 270 | nsEventStatus DispatchCommandEvent(nsIAtom* aCommand); |
michael@0 | 271 | nsEventStatus DispatchContentCommandEvent(int32_t aMsg); |
michael@0 | 272 | void SetSoftwareKeyboardState(bool aOpen, const InputContextAction& aAction); |
michael@0 | 273 | void ClearCachedResources(); |
michael@0 | 274 | |
michael@0 | 275 | uint32_t mActivatePending : 1; |
michael@0 | 276 | int32_t mSizeState; |
michael@0 | 277 | |
michael@0 | 278 | bool mIsTransparent; |
michael@0 | 279 | |
michael@0 | 280 | // all of our DND stuff |
michael@0 | 281 | // this is the last window that had a drag event happen on it. |
michael@0 | 282 | void InitDragEvent(mozilla::WidgetMouseEvent& aEvent); |
michael@0 | 283 | |
michael@0 | 284 | // this is everything we need to be able to fire motion events |
michael@0 | 285 | // repeatedly |
michael@0 | 286 | uint32_t mKeyDownFlags[8]; |
michael@0 | 287 | |
michael@0 | 288 | /* Helper methods for DOM Key Down event suppression. */ |
michael@0 | 289 | uint32_t* GetFlagWord32(uint32_t aKeyCode, uint32_t* aMask) { |
michael@0 | 290 | /* Mozilla DOM Virtual Key Code is from 0 to 224. */ |
michael@0 | 291 | NS_ASSERTION((aKeyCode <= 0xFF), "Invalid DOM Key Code"); |
michael@0 | 292 | aKeyCode &= 0xFF; |
michael@0 | 293 | |
michael@0 | 294 | /* 32 = 2^5 = 0x20 */ |
michael@0 | 295 | *aMask = uint32_t(1) << (aKeyCode & 0x1F); |
michael@0 | 296 | return &mKeyDownFlags[(aKeyCode >> 5)]; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | bool IsKeyDown(uint32_t aKeyCode) { |
michael@0 | 300 | uint32_t mask; |
michael@0 | 301 | uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
michael@0 | 302 | return ((*flag) & mask) != 0; |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | void SetKeyDownFlag(uint32_t aKeyCode) { |
michael@0 | 306 | uint32_t mask; |
michael@0 | 307 | uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
michael@0 | 308 | *flag |= mask; |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | void ClearKeyDownFlag(uint32_t aKeyCode) { |
michael@0 | 312 | uint32_t mask; |
michael@0 | 313 | uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
michael@0 | 314 | *flag &= ~mask; |
michael@0 | 315 | } |
michael@0 | 316 | int32_t mQCursor; |
michael@0 | 317 | |
michael@0 | 318 | |
michael@0 | 319 | void ProcessMotionEvent(); |
michael@0 | 320 | |
michael@0 | 321 | void DispatchMotionToMainThread() { |
michael@0 | 322 | if (!mTimerStarted) { |
michael@0 | 323 | nsCOMPtr<nsIRunnable> event = |
michael@0 | 324 | NS_NewRunnableMethod(this, &nsWindow::ProcessMotionEvent); |
michael@0 | 325 | NS_DispatchToMainThread(event); |
michael@0 | 326 | mTimerStarted = true; |
michael@0 | 327 | } |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | bool mNeedsResize; |
michael@0 | 331 | bool mNeedsMove; |
michael@0 | 332 | bool mListenForResizes; |
michael@0 | 333 | bool mNeedsShow; |
michael@0 | 334 | MozCachedMoveEvent mMoveEvent; |
michael@0 | 335 | bool mTimerStarted; |
michael@0 | 336 | }; |
michael@0 | 337 | |
michael@0 | 338 | }} |
michael@0 | 339 | |
michael@0 | 340 | #endif /* __nsWindow_h__ */ |