1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gtk/nsWindow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,474 @@ 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 "mozilla/ipc/SharedMemorySysV.h" 1.15 + 1.16 +#include "nsAutoPtr.h" 1.17 + 1.18 +#include "mozcontainer.h" 1.19 +#include "nsWeakReference.h" 1.20 + 1.21 +#include "nsIDragService.h" 1.22 +#include "nsITimer.h" 1.23 +#include "nsGkAtoms.h" 1.24 + 1.25 +#include "nsBaseWidget.h" 1.26 +#include <gdk/gdk.h> 1.27 +#include <gtk/gtk.h> 1.28 + 1.29 +#ifdef MOZ_X11 1.30 +#include <gdk/gdkx.h> 1.31 +#endif /* MOZ_X11 */ 1.32 + 1.33 +#ifdef ACCESSIBILITY 1.34 +#include "mozilla/a11y/Accessible.h" 1.35 +#endif 1.36 +#include "mozilla/EventForwards.h" 1.37 + 1.38 +#include "nsGtkIMModule.h" 1.39 + 1.40 +#undef LOG 1.41 +#ifdef MOZ_LOGGING 1.42 + 1.43 +// make sure that logging is enabled before including prlog.h 1.44 +#define FORCE_PR_LOG 1.45 + 1.46 +#include "prlog.h" 1.47 +#include "nsTArray.h" 1.48 + 1.49 +extern PRLogModuleInfo *gWidgetLog; 1.50 +extern PRLogModuleInfo *gWidgetFocusLog; 1.51 +extern PRLogModuleInfo *gWidgetDragLog; 1.52 +extern PRLogModuleInfo *gWidgetDrawLog; 1.53 + 1.54 +#define LOG(args) PR_LOG(gWidgetLog, 4, args) 1.55 +#define LOGFOCUS(args) PR_LOG(gWidgetFocusLog, 4, args) 1.56 +#define LOGDRAG(args) PR_LOG(gWidgetDragLog, 4, args) 1.57 +#define LOGDRAW(args) PR_LOG(gWidgetDrawLog, 4, args) 1.58 + 1.59 +#else 1.60 + 1.61 +#define LOG(args) 1.62 +#define LOGFOCUS(args) 1.63 +#define LOGDRAG(args) 1.64 +#define LOGDRAW(args) 1.65 + 1.66 +#endif /* MOZ_LOGGING */ 1.67 + 1.68 +class gfxASurface; 1.69 +class gfxPattern; 1.70 +class nsDragService; 1.71 +#if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV) 1.72 +# define MOZ_HAVE_SHMIMAGE 1.73 + 1.74 +class nsShmImage; 1.75 +#endif 1.76 + 1.77 +class nsWindow : public nsBaseWidget, public nsSupportsWeakReference 1.78 +{ 1.79 +public: 1.80 + nsWindow(); 1.81 + virtual ~nsWindow(); 1.82 + 1.83 + static void ReleaseGlobals(); 1.84 + 1.85 + NS_DECL_ISUPPORTS_INHERITED 1.86 + 1.87 + void CommonCreate(nsIWidget *aParent, bool aListenForResizes); 1.88 + 1.89 + virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 1.90 + nsEventStatus& aStatus); 1.91 + 1.92 + // called when we are destroyed 1.93 + void OnDestroy(void); 1.94 + 1.95 + // called to check and see if a widget's dimensions are sane 1.96 + bool AreBoundsSane(void); 1.97 + 1.98 + // nsIWidget 1.99 + NS_IMETHOD Create(nsIWidget *aParent, 1.100 + nsNativeWidget aNativeParent, 1.101 + const nsIntRect &aRect, 1.102 + nsDeviceContext *aContext, 1.103 + nsWidgetInitData *aInitData); 1.104 + NS_IMETHOD Destroy(void); 1.105 + virtual nsIWidget *GetParent(); 1.106 + virtual float GetDPI(); 1.107 + virtual nsresult SetParent(nsIWidget* aNewParent); 1.108 + NS_IMETHOD SetModal(bool aModal); 1.109 + virtual bool IsVisible() const; 1.110 + NS_IMETHOD ConstrainPosition(bool aAllowSlop, 1.111 + int32_t *aX, 1.112 + int32_t *aY); 1.113 + virtual void SetSizeConstraints(const SizeConstraints& aConstraints); 1.114 + NS_IMETHOD Move(double aX, 1.115 + double aY); 1.116 + NS_IMETHOD Show (bool aState); 1.117 + NS_IMETHOD Resize (double aWidth, 1.118 + double aHeight, 1.119 + bool aRepaint); 1.120 + NS_IMETHOD Resize (double aX, 1.121 + double aY, 1.122 + double aWidth, 1.123 + double aHeight, 1.124 + bool aRepaint); 1.125 + virtual bool IsEnabled() const; 1.126 + 1.127 + 1.128 + NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, 1.129 + nsIWidget *aWidget, 1.130 + bool aActivate); 1.131 + void SetZIndex(int32_t aZIndex); 1.132 + NS_IMETHOD SetSizeMode(int32_t aMode); 1.133 + NS_IMETHOD Enable(bool aState); 1.134 + NS_IMETHOD SetFocus(bool aRaise = false); 1.135 + NS_IMETHOD GetScreenBounds(nsIntRect &aRect); 1.136 + NS_IMETHOD GetClientBounds(nsIntRect &aRect); 1.137 + virtual nsIntPoint GetClientOffset(); 1.138 + NS_IMETHOD SetCursor(nsCursor aCursor); 1.139 + NS_IMETHOD SetCursor(imgIContainer* aCursor, 1.140 + uint32_t aHotspotX, uint32_t aHotspotY); 1.141 + NS_IMETHOD Invalidate(const nsIntRect &aRect); 1.142 + virtual void* GetNativeData(uint32_t aDataType); 1.143 + NS_IMETHOD SetTitle(const nsAString& aTitle); 1.144 + NS_IMETHOD SetIcon(const nsAString& aIconSpec); 1.145 + NS_IMETHOD SetWindowClass(const nsAString& xulWinType); 1.146 + virtual nsIntPoint WidgetToScreenOffset(); 1.147 + NS_IMETHOD EnableDragDrop(bool aEnable); 1.148 + NS_IMETHOD CaptureMouse(bool aCapture); 1.149 + NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, 1.150 + bool aDoCapture); 1.151 + NS_IMETHOD GetAttention(int32_t aCycleCount); 1.152 + 1.153 + virtual bool HasPendingInputEvent(); 1.154 + 1.155 + NS_IMETHOD MakeFullScreen(bool aFullScreen); 1.156 + NS_IMETHOD HideWindowChrome(bool aShouldHide); 1.157 + 1.158 + /** 1.159 + * GetLastUserInputTime returns a timestamp for the most recent user input 1.160 + * event. This is intended for pointer grab requests (including drags). 1.161 + */ 1.162 + static guint32 GetLastUserInputTime(); 1.163 + 1.164 + // utility method, -1 if no change should be made, otherwise returns a 1.165 + // value that can be passed to gdk_window_set_decorations 1.166 + gint ConvertBorderStyles(nsBorderStyle aStyle); 1.167 + 1.168 + // event callbacks 1.169 +#if (MOZ_WIDGET_GTK == 2) 1.170 + gboolean OnExposeEvent(GdkEventExpose *aEvent); 1.171 +#else 1.172 + gboolean OnExposeEvent(cairo_t *cr); 1.173 +#endif 1.174 + gboolean OnConfigureEvent(GtkWidget *aWidget, 1.175 + GdkEventConfigure *aEvent); 1.176 + void OnContainerUnrealize(); 1.177 + void OnSizeAllocate(GtkAllocation *aAllocation); 1.178 + void OnDeleteEvent(); 1.179 + void OnEnterNotifyEvent(GdkEventCrossing *aEvent); 1.180 + void OnLeaveNotifyEvent(GdkEventCrossing *aEvent); 1.181 + void OnMotionNotifyEvent(GdkEventMotion *aEvent); 1.182 + void OnButtonPressEvent(GdkEventButton *aEvent); 1.183 + void OnButtonReleaseEvent(GdkEventButton *aEvent); 1.184 + void OnContainerFocusInEvent(GdkEventFocus *aEvent); 1.185 + void OnContainerFocusOutEvent(GdkEventFocus *aEvent); 1.186 + gboolean OnKeyPressEvent(GdkEventKey *aEvent); 1.187 + gboolean OnKeyReleaseEvent(GdkEventKey *aEvent); 1.188 + void OnScrollEvent(GdkEventScroll *aEvent); 1.189 + void OnVisibilityNotifyEvent(GdkEventVisibility *aEvent); 1.190 + void OnWindowStateEvent(GtkWidget *aWidget, 1.191 + GdkEventWindowState *aEvent); 1.192 + void OnDragDataReceivedEvent(GtkWidget *aWidget, 1.193 + GdkDragContext *aDragContext, 1.194 + gint aX, 1.195 + gint aY, 1.196 + GtkSelectionData*aSelectionData, 1.197 + guint aInfo, 1.198 + guint aTime, 1.199 + gpointer aData); 1.200 + 1.201 + mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing() MOZ_OVERRIDE; 1.202 + 1.203 +private: 1.204 + void UpdateAlpha(gfxPattern* aPattern, nsIntRect aBoundsRect); 1.205 + 1.206 + void NativeResize(int32_t aWidth, 1.207 + int32_t aHeight, 1.208 + bool aRepaint); 1.209 + 1.210 + void NativeResize(int32_t aX, 1.211 + int32_t aY, 1.212 + int32_t aWidth, 1.213 + int32_t aHeight, 1.214 + bool aRepaint); 1.215 + 1.216 + void NativeShow (bool aAction); 1.217 + void SetHasMappedToplevel(bool aState); 1.218 + nsIntSize GetSafeWindowSize(nsIntSize aSize); 1.219 + 1.220 + void EnsureGrabs (void); 1.221 + void GrabPointer (guint32 aTime); 1.222 + void ReleaseGrabs (void); 1.223 + 1.224 +public: 1.225 + enum PluginType { 1.226 + PluginType_NONE = 0, /* do not have any plugin */ 1.227 + PluginType_XEMBED, /* the plugin support xembed */ 1.228 + PluginType_NONXEMBED /* the plugin does not support xembed */ 1.229 + }; 1.230 + 1.231 + void SetPluginType(PluginType aPluginType); 1.232 +#ifdef MOZ_X11 1.233 + void SetNonXEmbedPluginFocus(void); 1.234 + void LoseNonXEmbedPluginFocus(void); 1.235 +#endif /* MOZ_X11 */ 1.236 + 1.237 + void ThemeChanged(void); 1.238 + 1.239 +#ifdef MOZ_X11 1.240 + Window mOldFocusWindow; 1.241 +#endif /* MOZ_X11 */ 1.242 + 1.243 + static guint32 sLastButtonPressTime; 1.244 + 1.245 + NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, 1.246 + int32_t aHorizontal, 1.247 + int32_t aVertical); 1.248 + NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent); 1.249 + 1.250 + MozContainer* GetMozContainer() { return mContainer; } 1.251 + // GetMozContainerWidget returns the MozContainer even for undestroyed 1.252 + // descendant windows 1.253 + GtkWidget* GetMozContainerWidget(); 1.254 + GdkWindow* GetGdkWindow() { return mGdkWindow; } 1.255 + bool IsDestroyed() { return mIsDestroyed; } 1.256 + 1.257 + void DispatchDragEvent(uint32_t aMsg, 1.258 + const nsIntPoint& aRefPoint, 1.259 + guint aTime); 1.260 + static void UpdateDragStatus (GdkDragContext *aDragContext, 1.261 + nsIDragService *aDragService); 1.262 + // If this dispatched the keydown event actually, this returns TRUE, 1.263 + // otherwise, FALSE. 1.264 + bool DispatchKeyDownEvent(GdkEventKey *aEvent, 1.265 + bool *aIsCancelled); 1.266 + 1.267 + NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; 1.268 + NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, 1.269 + const InputContextAction& aAction); 1.270 + NS_IMETHOD_(InputContext) GetInputContext(); 1.271 + NS_IMETHOD_(bool) ExecuteNativeKeyBinding( 1.272 + NativeKeyBindingsType aType, 1.273 + const mozilla::WidgetKeyboardEvent& aEvent, 1.274 + DoCommandCallback aCallback, 1.275 + void* aCallbackData) MOZ_OVERRIDE; 1.276 + NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState); 1.277 + 1.278 + // These methods are for toplevel windows only. 1.279 + void ResizeTransparencyBitmap(); 1.280 + void ApplyTransparencyBitmap(); 1.281 + void ClearTransparencyBitmap(); 1.282 + 1.283 + virtual void SetTransparencyMode(nsTransparencyMode aMode); 1.284 + virtual nsTransparencyMode GetTransparencyMode(); 1.285 + virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations); 1.286 + nsresult UpdateTranslucentWindowAlphaInternal(const nsIntRect& aRect, 1.287 + uint8_t* aAlphas, int32_t aStride); 1.288 + 1.289 +#if (MOZ_WIDGET_GTK == 2) 1.290 + gfxASurface *GetThebesSurface(); 1.291 + 1.292 + static already_AddRefed<gfxASurface> GetSurfaceForGdkDrawable(GdkDrawable* aDrawable, 1.293 + const nsIntSize& aSize); 1.294 +#else 1.295 + gfxASurface *GetThebesSurface(cairo_t *cr); 1.296 +#endif 1.297 + NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); 1.298 + 1.299 + virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, 1.300 + uint32_t aNativeMessage, 1.301 + uint32_t aModifierFlags); 1.302 + 1.303 + virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) 1.304 + { return SynthesizeNativeMouseEvent(aPoint, GDK_MOTION_NOTIFY, 0); } 1.305 + 1.306 +protected: 1.307 + // event handling code 1.308 + void DispatchActivateEvent(void); 1.309 + void DispatchDeactivateEvent(void); 1.310 + void DispatchResized(int32_t aWidth, int32_t aHeight); 1.311 + 1.312 + // Helper for SetParent and ReparentNativeWidget. 1.313 + void ReparentNativeWidgetInternal(nsIWidget* aNewParent, 1.314 + GtkWidget* aNewContainer, 1.315 + GdkWindow* aNewParentWindow, 1.316 + GtkWidget* aOldContainer); 1.317 + nsCOMPtr<nsIWidget> mParent; 1.318 + // Is this a toplevel window? 1.319 + bool mIsTopLevel; 1.320 + // Has this widget been destroyed yet? 1.321 + bool mIsDestroyed; 1.322 + 1.323 + // This is a flag that tracks if we need to resize a widget or 1.324 + // window when we show it. 1.325 + bool mNeedsResize; 1.326 + // This is a flag that tracks if we need to move a widget or 1.327 + // window when we show it. 1.328 + bool mNeedsMove; 1.329 + // Should we send resize events on all resizes? 1.330 + bool mListenForResizes; 1.331 + // This flag tracks if we're hidden or shown. 1.332 + bool mIsShown; 1.333 + bool mNeedsShow; 1.334 + // is this widget enabled? 1.335 + bool mEnabled; 1.336 + // has the native window for this been created yet? 1.337 + bool mCreated; 1.338 + 1.339 +private: 1.340 + void DestroyChildWindows(); 1.341 + GtkWidget *GetToplevelWidget(); 1.342 + nsWindow *GetContainerWindow(); 1.343 + void SetUrgencyHint(GtkWidget *top_window, bool state); 1.344 + void *SetupPluginPort(void); 1.345 + void SetDefaultIcon(void); 1.346 + void InitButtonEvent(mozilla::WidgetMouseEvent& aEvent, 1.347 + GdkEventButton* aGdkEvent); 1.348 + bool DispatchCommandEvent(nsIAtom* aCommand); 1.349 + bool DispatchContentCommandEvent(int32_t aMsg); 1.350 + void SetWindowClipRegion(const nsTArray<nsIntRect>& aRects, 1.351 + bool aIntersectWithExisting); 1.352 + bool CheckForRollup(gdouble aMouseX, gdouble aMouseY, 1.353 + bool aIsWheel, bool aAlwaysRollup); 1.354 + bool GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent, 1.355 + GdkWindow** aWindow, gint* aButton, 1.356 + gint* aRootX, gint* aRootY); 1.357 + void ClearCachedResources(); 1.358 + 1.359 + GtkWidget *mShell; 1.360 + MozContainer *mContainer; 1.361 + GdkWindow *mGdkWindow; 1.362 + 1.363 + uint32_t mHasMappedToplevel : 1, 1.364 + mIsFullyObscured : 1, 1.365 + mRetryPointerGrab : 1; 1.366 + nsSizeMode mSizeState; 1.367 + PluginType mPluginType; 1.368 + 1.369 + int32_t mTransparencyBitmapWidth; 1.370 + int32_t mTransparencyBitmapHeight; 1.371 + 1.372 +#ifdef MOZ_HAVE_SHMIMAGE 1.373 + // If we're using xshm rendering, mThebesSurface wraps mShmImage 1.374 + nsRefPtr<nsShmImage> mShmImage; 1.375 +#endif 1.376 + nsRefPtr<gfxASurface> mThebesSurface; 1.377 + 1.378 +#ifdef ACCESSIBILITY 1.379 + nsRefPtr<mozilla::a11y::Accessible> mRootAccessible; 1.380 + 1.381 + /** 1.382 + * Request to create the accessible for this window if it is top level. 1.383 + */ 1.384 + void CreateRootAccessible(); 1.385 + 1.386 + /** 1.387 + * Dispatch accessible event for the top level window accessible. 1.388 + * 1.389 + * @param aEventType [in] the accessible event type to dispatch 1.390 + */ 1.391 + void DispatchEventToRootAccessible(uint32_t aEventType); 1.392 + 1.393 + /** 1.394 + * Dispatch accessible window activate event for the top level window 1.395 + * accessible. 1.396 + */ 1.397 + void DispatchActivateEventAccessible(); 1.398 + 1.399 + /** 1.400 + * Dispatch accessible window deactivate event for the top level window 1.401 + * accessible. 1.402 + */ 1.403 + void DispatchDeactivateEventAccessible(); 1.404 + 1.405 + /** 1.406 + * Dispatch accessible window maximize event for the top level window 1.407 + * accessible. 1.408 + */ 1.409 + void DispatchMaximizeEventAccessible(); 1.410 + 1.411 + /** 1.412 + * Dispatch accessible window minize event for the top level window 1.413 + * accessible. 1.414 + */ 1.415 + void DispatchMinimizeEventAccessible(); 1.416 + 1.417 + /** 1.418 + * Dispatch accessible window restore event for the top level window 1.419 + * accessible. 1.420 + */ 1.421 + void DispatchRestoreEventAccessible(); 1.422 +#endif 1.423 + 1.424 + // The cursor cache 1.425 + static GdkCursor *gsGtkCursorCache[eCursorCount]; 1.426 + 1.427 + // Transparency 1.428 + bool mIsTransparent; 1.429 + // This bitmap tracks which pixels are transparent. We don't support 1.430 + // full translucency at this time; each pixel is either fully opaque 1.431 + // or fully transparent. 1.432 + gchar* mTransparencyBitmap; 1.433 + 1.434 + // all of our DND stuff 1.435 + void InitDragEvent(mozilla::WidgetDragEvent& aEvent); 1.436 + 1.437 + float mLastMotionPressure; 1.438 + 1.439 + // Remember the last sizemode so that we can restore it when 1.440 + // leaving fullscreen 1.441 + nsSizeMode mLastSizeMode; 1.442 + 1.443 + static bool DragInProgress(void); 1.444 + 1.445 + void DispatchMissedButtonReleases(GdkEventCrossing *aGdkEvent); 1.446 + 1.447 + // nsBaseWidget 1.448 + virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, 1.449 + LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 1.450 + LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, 1.451 + bool* aAllowRetaining = nullptr) MOZ_OVERRIDE; 1.452 + 1.453 + void CleanLayerManagerRecursive(); 1.454 + 1.455 + /** 1.456 + * |mIMModule| takes all IME related stuff. 1.457 + * 1.458 + * This is owned by the top-level nsWindow or the topmost child 1.459 + * nsWindow embedded in a non-Gecko widget. 1.460 + * 1.461 + * The instance is created when the top level widget is created. And when 1.462 + * the widget is destroyed, it's released. All child windows refer its 1.463 + * ancestor widget's instance. So, one set of IM contexts is created for 1.464 + * all windows in a hierarchy. If the children are released after the top 1.465 + * level window is released, the children still have a valid pointer, 1.466 + * however, IME doesn't work at that time. 1.467 + */ 1.468 + nsRefPtr<nsGtkIMModule> mIMModule; 1.469 +}; 1.470 + 1.471 +class nsChildWindow : public nsWindow { 1.472 +public: 1.473 + nsChildWindow(); 1.474 + ~nsChildWindow(); 1.475 +}; 1.476 + 1.477 +#endif /* __nsWindow_h__ */