Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef nsBaseWidget_h__ |
michael@0 | 6 | #define nsBaseWidget_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/EventForwards.h" |
michael@0 | 9 | #include "mozilla/WidgetUtils.h" |
michael@0 | 10 | #include "nsRect.h" |
michael@0 | 11 | #include "nsIWidget.h" |
michael@0 | 12 | #include "nsWidgetsCID.h" |
michael@0 | 13 | #include "nsIFile.h" |
michael@0 | 14 | #include "nsString.h" |
michael@0 | 15 | #include "nsCOMPtr.h" |
michael@0 | 16 | #include "nsAutoPtr.h" |
michael@0 | 17 | #include "nsIRollupListener.h" |
michael@0 | 18 | #include "nsIObserver.h" |
michael@0 | 19 | #include "nsIWidgetListener.h" |
michael@0 | 20 | #include "nsPIDOMWindow.h" |
michael@0 | 21 | #include <algorithm> |
michael@0 | 22 | class nsIContent; |
michael@0 | 23 | class nsAutoRollup; |
michael@0 | 24 | class gfxContext; |
michael@0 | 25 | |
michael@0 | 26 | namespace mozilla { |
michael@0 | 27 | #ifdef ACCESSIBILITY |
michael@0 | 28 | namespace a11y { |
michael@0 | 29 | class Accessible; |
michael@0 | 30 | } |
michael@0 | 31 | #endif |
michael@0 | 32 | |
michael@0 | 33 | namespace layers { |
michael@0 | 34 | class BasicLayerManager; |
michael@0 | 35 | class CompositorChild; |
michael@0 | 36 | class CompositorParent; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | namespace base { |
michael@0 | 41 | class Thread; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | // Windows specific constant indicating the maximum number of touch points the |
michael@0 | 45 | // inject api will allow. This also sets the maximum numerical value for touch |
michael@0 | 46 | // ids we can use when injecting touch points on Windows. |
michael@0 | 47 | #define TOUCH_INJECT_MAX_POINTS 256 |
michael@0 | 48 | |
michael@0 | 49 | class nsBaseWidget; |
michael@0 | 50 | |
michael@0 | 51 | class WidgetShutdownObserver MOZ_FINAL : public nsIObserver |
michael@0 | 52 | { |
michael@0 | 53 | public: |
michael@0 | 54 | WidgetShutdownObserver(nsBaseWidget* aWidget) |
michael@0 | 55 | : mWidget(aWidget) |
michael@0 | 56 | { } |
michael@0 | 57 | |
michael@0 | 58 | NS_DECL_ISUPPORTS |
michael@0 | 59 | NS_DECL_NSIOBSERVER |
michael@0 | 60 | |
michael@0 | 61 | nsBaseWidget *mWidget; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Common widget implementation used as base class for native |
michael@0 | 66 | * or crossplatform implementations of Widgets. |
michael@0 | 67 | * All cross-platform behavior that all widgets need to implement |
michael@0 | 68 | * should be placed in this class. |
michael@0 | 69 | * (Note: widget implementations are not required to use this |
michael@0 | 70 | * class, but it gives them a head start.) |
michael@0 | 71 | */ |
michael@0 | 72 | |
michael@0 | 73 | class nsBaseWidget : public nsIWidget |
michael@0 | 74 | { |
michael@0 | 75 | friend class nsAutoRollup; |
michael@0 | 76 | |
michael@0 | 77 | protected: |
michael@0 | 78 | typedef base::Thread Thread; |
michael@0 | 79 | typedef mozilla::layers::BasicLayerManager BasicLayerManager; |
michael@0 | 80 | typedef mozilla::layers::BufferMode BufferMode; |
michael@0 | 81 | typedef mozilla::layers::CompositorChild CompositorChild; |
michael@0 | 82 | typedef mozilla::layers::CompositorParent CompositorParent; |
michael@0 | 83 | typedef mozilla::ScreenRotation ScreenRotation; |
michael@0 | 84 | |
michael@0 | 85 | public: |
michael@0 | 86 | nsBaseWidget(); |
michael@0 | 87 | virtual ~nsBaseWidget(); |
michael@0 | 88 | |
michael@0 | 89 | NS_DECL_ISUPPORTS |
michael@0 | 90 | |
michael@0 | 91 | // nsIWidget interface |
michael@0 | 92 | NS_IMETHOD CaptureMouse(bool aCapture); |
michael@0 | 93 | virtual nsIWidgetListener* GetWidgetListener(); |
michael@0 | 94 | virtual void SetWidgetListener(nsIWidgetListener* alistener); |
michael@0 | 95 | NS_IMETHOD Destroy(); |
michael@0 | 96 | NS_IMETHOD SetParent(nsIWidget* aNewParent); |
michael@0 | 97 | virtual nsIWidget* GetParent(void); |
michael@0 | 98 | virtual nsIWidget* GetTopLevelWidget(); |
michael@0 | 99 | virtual nsIWidget* GetSheetWindowParent(void); |
michael@0 | 100 | virtual float GetDPI(); |
michael@0 | 101 | virtual void AddChild(nsIWidget* aChild); |
michael@0 | 102 | virtual void RemoveChild(nsIWidget* aChild); |
michael@0 | 103 | |
michael@0 | 104 | void SetZIndex(int32_t aZIndex); |
michael@0 | 105 | NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, |
michael@0 | 106 | nsIWidget *aWidget, bool aActivate); |
michael@0 | 107 | |
michael@0 | 108 | NS_IMETHOD SetSizeMode(int32_t aMode); |
michael@0 | 109 | virtual int32_t SizeMode() MOZ_OVERRIDE |
michael@0 | 110 | { |
michael@0 | 111 | return mSizeMode; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | virtual nsCursor GetCursor(); |
michael@0 | 115 | NS_IMETHOD SetCursor(nsCursor aCursor); |
michael@0 | 116 | NS_IMETHOD SetCursor(imgIContainer* aCursor, |
michael@0 | 117 | uint32_t aHotspotX, uint32_t aHotspotY); |
michael@0 | 118 | virtual void SetTransparencyMode(nsTransparencyMode aMode); |
michael@0 | 119 | virtual nsTransparencyMode GetTransparencyMode(); |
michael@0 | 120 | virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects); |
michael@0 | 121 | NS_IMETHOD SetWindowShadowStyle(int32_t aStyle); |
michael@0 | 122 | virtual void SetShowsToolbarButton(bool aShow) {} |
michael@0 | 123 | virtual void SetShowsFullScreenButton(bool aShow) {} |
michael@0 | 124 | virtual void SetWindowAnimationType(WindowAnimationType aType) {} |
michael@0 | 125 | NS_IMETHOD HideWindowChrome(bool aShouldHide); |
michael@0 | 126 | NS_IMETHOD MakeFullScreen(bool aFullScreen); |
michael@0 | 127 | virtual nsDeviceContext* GetDeviceContext(); |
michael@0 | 128 | virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, |
michael@0 | 129 | LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, |
michael@0 | 130 | LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, |
michael@0 | 131 | bool* aAllowRetaining = nullptr); |
michael@0 | 132 | |
michael@0 | 133 | virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight); |
michael@0 | 134 | virtual void CreateCompositor(); |
michael@0 | 135 | virtual void CreateCompositor(int aWidth, int aHeight); |
michael@0 | 136 | virtual void PrepareWindowEffects() {} |
michael@0 | 137 | virtual void CleanupWindowEffects() {} |
michael@0 | 138 | virtual bool PreRender(LayerManagerComposite* aManager) { return true; } |
michael@0 | 139 | virtual void PostRender(LayerManagerComposite* aManager) {} |
michael@0 | 140 | virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect) {} |
michael@0 | 141 | virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) {} |
michael@0 | 142 | virtual mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing(); |
michael@0 | 143 | virtual void EndRemoteDrawing() { }; |
michael@0 | 144 | virtual void CleanupRemoteDrawing() { }; |
michael@0 | 145 | virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) {} |
michael@0 | 146 | virtual gfxASurface* GetThebesSurface(); |
michael@0 | 147 | NS_IMETHOD SetModal(bool aModal); |
michael@0 | 148 | virtual uint32_t GetMaxTouchPoints() const; |
michael@0 | 149 | NS_IMETHOD SetWindowClass(const nsAString& xulWinType); |
michael@0 | 150 | // Return whether this widget interprets parameters to Move and Resize APIs |
michael@0 | 151 | // as "global display pixels" rather than "device pixels", and therefore |
michael@0 | 152 | // applies its GetDefaultScale() value to them before using them as mBounds |
michael@0 | 153 | // etc (which are always stored in device pixels). |
michael@0 | 154 | // Note that APIs that -get- the widget's position/size/bounds, rather than |
michael@0 | 155 | // -setting- them (i.e. moving or resizing the widget) will always return |
michael@0 | 156 | // values in the widget's device pixels. |
michael@0 | 157 | bool BoundsUseDisplayPixels() const { |
michael@0 | 158 | return mWindowType <= eWindowType_popup; |
michael@0 | 159 | } |
michael@0 | 160 | NS_IMETHOD MoveClient(double aX, double aY); |
michael@0 | 161 | NS_IMETHOD ResizeClient(double aWidth, double aHeight, bool aRepaint); |
michael@0 | 162 | NS_IMETHOD ResizeClient(double aX, double aY, double aWidth, double aHeight, bool aRepaint); |
michael@0 | 163 | NS_IMETHOD GetBounds(nsIntRect &aRect); |
michael@0 | 164 | NS_IMETHOD GetClientBounds(nsIntRect &aRect); |
michael@0 | 165 | NS_IMETHOD GetScreenBounds(nsIntRect &aRect); |
michael@0 | 166 | NS_IMETHOD GetNonClientMargins(nsIntMargin &margins); |
michael@0 | 167 | NS_IMETHOD SetNonClientMargins(nsIntMargin &margins); |
michael@0 | 168 | virtual nsIntPoint GetClientOffset(); |
michael@0 | 169 | NS_IMETHOD EnableDragDrop(bool aEnable); |
michael@0 | 170 | NS_IMETHOD GetAttention(int32_t aCycleCount); |
michael@0 | 171 | virtual bool HasPendingInputEvent(); |
michael@0 | 172 | NS_IMETHOD SetIcon(const nsAString &anIconSpec); |
michael@0 | 173 | NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive); |
michael@0 | 174 | virtual void SetDrawsInTitlebar(bool aState) {} |
michael@0 | 175 | virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect); |
michael@0 | 176 | virtual void FreeNativeData(void * data, uint32_t aDataType) {} |
michael@0 | 177 | NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 178 | int32_t aHorizontal, |
michael@0 | 179 | int32_t aVertical); |
michael@0 | 180 | NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent); |
michael@0 | 181 | virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 182 | virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 183 | NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 184 | NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 185 | NS_IMETHOD_(bool) ExecuteNativeKeyBinding( |
michael@0 | 186 | NativeKeyBindingsType aType, |
michael@0 | 187 | const mozilla::WidgetKeyboardEvent& aEvent, |
michael@0 | 188 | DoCommandCallback aCallback, |
michael@0 | 189 | void* aCallbackData) MOZ_OVERRIDE { return false; } |
michael@0 | 190 | NS_IMETHOD SetLayersAcceleration(bool aEnabled); |
michael@0 | 191 | virtual bool GetLayersAcceleration() { return mUseLayersAcceleration; } |
michael@0 | 192 | virtual bool ComputeShouldAccelerate(bool aDefault); |
michael@0 | 193 | NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 194 | virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE { return nsIMEUpdatePreference(); } |
michael@0 | 195 | NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; } |
michael@0 | 196 | NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX, |
michael@0 | 197 | double aOriginalDeltaY, |
michael@0 | 198 | double& aOverriddenDeltaX, |
michael@0 | 199 | double& aOverriddenDeltaY); |
michael@0 | 200 | virtual already_AddRefed<nsIWidget> |
michael@0 | 201 | CreateChild(const nsIntRect &aRect, |
michael@0 | 202 | nsDeviceContext *aContext, |
michael@0 | 203 | nsWidgetInitData *aInitData = nullptr, |
michael@0 | 204 | bool aForceUseIWidgetParent = false); |
michael@0 | 205 | NS_IMETHOD AttachViewToTopLevel(bool aUseAttachedEvents, nsDeviceContext *aContext); |
michael@0 | 206 | virtual nsIWidgetListener* GetAttachedWidgetListener(); |
michael@0 | 207 | virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener); |
michael@0 | 208 | NS_IMETHOD RegisterTouchWindow(); |
michael@0 | 209 | NS_IMETHOD UnregisterTouchWindow(); |
michael@0 | 210 | |
michael@0 | 211 | void NotifyWindowDestroyed(); |
michael@0 | 212 | void NotifySizeMoveDone(); |
michael@0 | 213 | void NotifyWindowMoved(int32_t aX, int32_t aY); |
michael@0 | 214 | |
michael@0 | 215 | // Should be called by derived implementations to notify on system color and |
michael@0 | 216 | // theme changes. |
michael@0 | 217 | void NotifySysColorChanged(); |
michael@0 | 218 | void NotifyThemeChanged(); |
michael@0 | 219 | void NotifyUIStateChanged(UIStateChangeType aShowAccelerators, |
michael@0 | 220 | UIStateChangeType aShowFocusRings); |
michael@0 | 221 | |
michael@0 | 222 | #ifdef ACCESSIBILITY |
michael@0 | 223 | // Get the accessible for the window. |
michael@0 | 224 | mozilla::a11y::Accessible* GetRootAccessible(); |
michael@0 | 225 | #endif |
michael@0 | 226 | |
michael@0 | 227 | nsPopupLevel PopupLevel() { return mPopupLevel; } |
michael@0 | 228 | |
michael@0 | 229 | virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) |
michael@0 | 230 | { |
michael@0 | 231 | return aClientSize; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | // return true if this is a popup widget with a native titlebar |
michael@0 | 235 | bool IsPopupWithTitleBar() const |
michael@0 | 236 | { |
michael@0 | 237 | return (mWindowType == eWindowType_popup && |
michael@0 | 238 | mBorderStyle != eBorderStyle_default && |
michael@0 | 239 | mBorderStyle & eBorderStyle_title); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0; |
michael@0 | 243 | |
michael@0 | 244 | virtual uint32_t GetGLFrameBufferFormat() MOZ_OVERRIDE; |
michael@0 | 245 | |
michael@0 | 246 | virtual const SizeConstraints& GetSizeConstraints() const; |
michael@0 | 247 | virtual void SetSizeConstraints(const SizeConstraints& aConstraints); |
michael@0 | 248 | |
michael@0 | 249 | /** |
michael@0 | 250 | * Use this when GetLayerManager() returns a BasicLayerManager |
michael@0 | 251 | * (nsBaseWidget::GetLayerManager() does). This sets up the widget's |
michael@0 | 252 | * layer manager to temporarily render into aTarget. |
michael@0 | 253 | * |
michael@0 | 254 | * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|. |
michael@0 | 255 | * |aRotation| is the "virtual rotation" to apply when rendering to |
michael@0 | 256 | * the target. When |aRotation| is ROTATION_0, |
michael@0 | 257 | * |aNaturalWidgetBounds| is not used. |
michael@0 | 258 | */ |
michael@0 | 259 | class AutoLayerManagerSetup { |
michael@0 | 260 | public: |
michael@0 | 261 | AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget, |
michael@0 | 262 | BufferMode aDoubleBuffering, |
michael@0 | 263 | ScreenRotation aRotation = mozilla::ROTATION_0); |
michael@0 | 264 | ~AutoLayerManagerSetup(); |
michael@0 | 265 | private: |
michael@0 | 266 | nsBaseWidget* mWidget; |
michael@0 | 267 | nsRefPtr<BasicLayerManager> mLayerManager; |
michael@0 | 268 | }; |
michael@0 | 269 | friend class AutoLayerManagerSetup; |
michael@0 | 270 | |
michael@0 | 271 | class AutoUseBasicLayerManager { |
michael@0 | 272 | public: |
michael@0 | 273 | AutoUseBasicLayerManager(nsBaseWidget* aWidget); |
michael@0 | 274 | ~AutoUseBasicLayerManager(); |
michael@0 | 275 | private: |
michael@0 | 276 | nsBaseWidget* mWidget; |
michael@0 | 277 | bool mPreviousTemporarilyUseBasicLayerManager; |
michael@0 | 278 | }; |
michael@0 | 279 | friend class AutoUseBasicLayerManager; |
michael@0 | 280 | |
michael@0 | 281 | virtual bool ShouldUseOffMainThreadCompositing(); |
michael@0 | 282 | |
michael@0 | 283 | static nsIRollupListener* GetActiveRollupListener(); |
michael@0 | 284 | |
michael@0 | 285 | void Shutdown(); |
michael@0 | 286 | |
michael@0 | 287 | protected: |
michael@0 | 288 | |
michael@0 | 289 | virtual void ResolveIconName(const nsAString &aIconName, |
michael@0 | 290 | const nsAString &aIconSuffix, |
michael@0 | 291 | nsIFile **aResult); |
michael@0 | 292 | virtual void OnDestroy(); |
michael@0 | 293 | virtual void BaseCreate(nsIWidget *aParent, |
michael@0 | 294 | const nsIntRect &aRect, |
michael@0 | 295 | nsDeviceContext *aContext, |
michael@0 | 296 | nsWidgetInitData *aInitData); |
michael@0 | 297 | |
michael@0 | 298 | virtual nsIContent* GetLastRollup() |
michael@0 | 299 | { |
michael@0 | 300 | return mLastRollup; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, |
michael@0 | 304 | int32_t aNativeKeyCode, |
michael@0 | 305 | uint32_t aModifierFlags, |
michael@0 | 306 | const nsAString& aCharacters, |
michael@0 | 307 | const nsAString& aUnmodifiedCharacters) |
michael@0 | 308 | { return NS_ERROR_UNEXPECTED; } |
michael@0 | 309 | |
michael@0 | 310 | virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, |
michael@0 | 311 | uint32_t aNativeMessage, |
michael@0 | 312 | uint32_t aModifierFlags) |
michael@0 | 313 | { return NS_ERROR_UNEXPECTED; } |
michael@0 | 314 | |
michael@0 | 315 | virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) |
michael@0 | 316 | { return NS_ERROR_UNEXPECTED; } |
michael@0 | 317 | |
michael@0 | 318 | virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint, |
michael@0 | 319 | uint32_t aNativeMessage, |
michael@0 | 320 | double aDeltaX, |
michael@0 | 321 | double aDeltaY, |
michael@0 | 322 | double aDeltaZ, |
michael@0 | 323 | uint32_t aModifierFlags, |
michael@0 | 324 | uint32_t aAdditionalFlags) |
michael@0 | 325 | { return NS_ERROR_UNEXPECTED; } |
michael@0 | 326 | |
michael@0 | 327 | virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, |
michael@0 | 328 | TouchPointerState aPointerState, |
michael@0 | 329 | nsIntPoint aPointerScreenPoint, |
michael@0 | 330 | double aPointerPressure, |
michael@0 | 331 | uint32_t aPointerOrientation) |
michael@0 | 332 | { return NS_ERROR_UNEXPECTED; } |
michael@0 | 333 | |
michael@0 | 334 | protected: |
michael@0 | 335 | // Stores the clip rectangles in aRects into mClipRects. Returns true |
michael@0 | 336 | // if the new rectangles are different from the old rectangles. |
michael@0 | 337 | bool StoreWindowClipRegion(const nsTArray<nsIntRect>& aRects); |
michael@0 | 338 | |
michael@0 | 339 | virtual already_AddRefed<nsIWidget> |
michael@0 | 340 | AllocateChildPopupWidget() |
michael@0 | 341 | { |
michael@0 | 342 | static NS_DEFINE_IID(kCPopUpCID, NS_CHILD_CID); |
michael@0 | 343 | nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID); |
michael@0 | 344 | return widget.forget(); |
michael@0 | 345 | } |
michael@0 | 346 | |
michael@0 | 347 | LayerManager* CreateBasicLayerManager(); |
michael@0 | 348 | |
michael@0 | 349 | nsPopupType PopupType() const { return mPopupType; } |
michael@0 | 350 | |
michael@0 | 351 | void NotifyRollupGeometryChange() |
michael@0 | 352 | { |
michael@0 | 353 | // XULPopupManager isn't interested in this notification, so only |
michael@0 | 354 | // send it if gRollupListener is set. |
michael@0 | 355 | if (gRollupListener) { |
michael@0 | 356 | gRollupListener->NotifyGeometryChange(); |
michael@0 | 357 | } |
michael@0 | 358 | } |
michael@0 | 359 | |
michael@0 | 360 | /** |
michael@0 | 361 | * Apply the current size constraints to the given size. |
michael@0 | 362 | * |
michael@0 | 363 | * @param aWidth width to constrain |
michael@0 | 364 | * @param aHeight height to constrain |
michael@0 | 365 | */ |
michael@0 | 366 | void ConstrainSize(int32_t* aWidth, int32_t* aHeight) const |
michael@0 | 367 | { |
michael@0 | 368 | *aWidth = std::max(mSizeConstraints.mMinSize.width, |
michael@0 | 369 | std::min(mSizeConstraints.mMaxSize.width, *aWidth)); |
michael@0 | 370 | *aHeight = std::max(mSizeConstraints.mMinSize.height, |
michael@0 | 371 | std::min(mSizeConstraints.mMaxSize.height, *aHeight)); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | virtual CompositorChild* GetRemoteRenderer() MOZ_OVERRIDE; |
michael@0 | 375 | |
michael@0 | 376 | virtual void GetPreferredCompositorBackends(nsTArray<mozilla::layers::LayersBackend>& aHints); |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Notify the widget that this window is being used with OMTC. |
michael@0 | 380 | */ |
michael@0 | 381 | virtual void WindowUsesOMTC() {} |
michael@0 | 382 | |
michael@0 | 383 | protected: |
michael@0 | 384 | /** |
michael@0 | 385 | * Starts the OMTC compositor destruction sequence. |
michael@0 | 386 | * |
michael@0 | 387 | * When this function returns, the compositor should not be |
michael@0 | 388 | * able to access the opengl context anymore. |
michael@0 | 389 | * It is safe to call it several times if platform implementations |
michael@0 | 390 | * require the compositor to be destroyed before ~nsBaseWidget is |
michael@0 | 391 | * reached (This is the case with gtk2 for instance). |
michael@0 | 392 | */ |
michael@0 | 393 | void DestroyCompositor(); |
michael@0 | 394 | |
michael@0 | 395 | nsIWidgetListener* mWidgetListener; |
michael@0 | 396 | nsIWidgetListener* mAttachedWidgetListener; |
michael@0 | 397 | nsDeviceContext* mContext; |
michael@0 | 398 | nsRefPtr<LayerManager> mLayerManager; |
michael@0 | 399 | nsRefPtr<LayerManager> mBasicLayerManager; |
michael@0 | 400 | nsRefPtr<CompositorChild> mCompositorChild; |
michael@0 | 401 | nsRefPtr<CompositorParent> mCompositorParent; |
michael@0 | 402 | nsRefPtr<WidgetShutdownObserver> mShutdownObserver; |
michael@0 | 403 | nsCursor mCursor; |
michael@0 | 404 | nsBorderStyle mBorderStyle; |
michael@0 | 405 | bool mUseLayersAcceleration; |
michael@0 | 406 | bool mForceLayersAcceleration; |
michael@0 | 407 | bool mTemporarilyUseBasicLayerManager; |
michael@0 | 408 | // Windows with out-of-process tabs always require OMTC. This flag designates |
michael@0 | 409 | // such windows. |
michael@0 | 410 | bool mRequireOffMainThreadCompositing; |
michael@0 | 411 | bool mUseAttachedEvents; |
michael@0 | 412 | bool mContextInitialized; |
michael@0 | 413 | nsIntRect mBounds; |
michael@0 | 414 | nsIntRect* mOriginalBounds; |
michael@0 | 415 | // When this pointer is null, the widget is not clipped |
michael@0 | 416 | nsAutoArrayPtr<nsIntRect> mClipRects; |
michael@0 | 417 | uint32_t mClipRectCount; |
michael@0 | 418 | nsSizeMode mSizeMode; |
michael@0 | 419 | nsPopupLevel mPopupLevel; |
michael@0 | 420 | nsPopupType mPopupType; |
michael@0 | 421 | SizeConstraints mSizeConstraints; |
michael@0 | 422 | |
michael@0 | 423 | static nsIRollupListener* gRollupListener; |
michael@0 | 424 | |
michael@0 | 425 | // the last rolled up popup. Only set this when an nsAutoRollup is in scope, |
michael@0 | 426 | // so it can be cleared automatically. |
michael@0 | 427 | static nsIContent* mLastRollup; |
michael@0 | 428 | |
michael@0 | 429 | #ifdef DEBUG |
michael@0 | 430 | protected: |
michael@0 | 431 | static nsAutoString debug_GuiEventToString(mozilla::WidgetGUIEvent* aGuiEvent); |
michael@0 | 432 | static bool debug_WantPaintFlashing(); |
michael@0 | 433 | |
michael@0 | 434 | static void debug_DumpInvalidate(FILE * aFileOut, |
michael@0 | 435 | nsIWidget * aWidget, |
michael@0 | 436 | const nsIntRect * aRect, |
michael@0 | 437 | const nsAutoCString & aWidgetName, |
michael@0 | 438 | int32_t aWindowID); |
michael@0 | 439 | |
michael@0 | 440 | static void debug_DumpEvent(FILE* aFileOut, |
michael@0 | 441 | nsIWidget* aWidget, |
michael@0 | 442 | mozilla::WidgetGUIEvent* aGuiEvent, |
michael@0 | 443 | const nsAutoCString& aWidgetName, |
michael@0 | 444 | int32_t aWindowID); |
michael@0 | 445 | |
michael@0 | 446 | static void debug_DumpPaintEvent(FILE * aFileOut, |
michael@0 | 447 | nsIWidget * aWidget, |
michael@0 | 448 | const nsIntRegion & aPaintEvent, |
michael@0 | 449 | const nsAutoCString & aWidgetName, |
michael@0 | 450 | int32_t aWindowID); |
michael@0 | 451 | |
michael@0 | 452 | static bool debug_GetCachedBoolPref(const char* aPrefName); |
michael@0 | 453 | #endif |
michael@0 | 454 | }; |
michael@0 | 455 | |
michael@0 | 456 | // A situation can occur when a mouse event occurs over a menu label while the |
michael@0 | 457 | // menu popup is already open. The expected behaviour is to close the popup. |
michael@0 | 458 | // This happens by calling nsIRollupListener::Rollup before the mouse event is |
michael@0 | 459 | // processed. However, in cases where the mouse event is not consumed, this |
michael@0 | 460 | // event will then get targeted at the menu label causing the menu to open |
michael@0 | 461 | // again. To prevent this, we store in mLastRollup a reference to the popup |
michael@0 | 462 | // that was closed during the Rollup call, and prevent this popup from |
michael@0 | 463 | // reopening while processing the mouse event. |
michael@0 | 464 | // mLastRollup should only be set while an nsAutoRollup is in scope; |
michael@0 | 465 | // when it goes out of scope mLastRollup is cleared automatically. |
michael@0 | 466 | // As mLastRollup is static, it can be retrieved by calling |
michael@0 | 467 | // nsIWidget::GetLastRollup on any widget. |
michael@0 | 468 | class nsAutoRollup |
michael@0 | 469 | { |
michael@0 | 470 | bool wasClear; |
michael@0 | 471 | |
michael@0 | 472 | public: |
michael@0 | 473 | |
michael@0 | 474 | nsAutoRollup(); |
michael@0 | 475 | ~nsAutoRollup(); |
michael@0 | 476 | }; |
michael@0 | 477 | |
michael@0 | 478 | #endif // nsBaseWidget_h__ |