2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2010-02-09 11:02:11 -08:00
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
2010-03-31 21:38:51 -07:00
|
|
|
// needed to include hildon parts in gtk.h
|
2008-09-10 09:12:58 -07:00
|
|
|
#define MAEMO_CHANGES
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prlink.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
#include "nsGTKToolkit.h"
|
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
|
|
|
|
#include "nsWidgetsCID.h"
|
2009-04-20 17:54:46 -07:00
|
|
|
#include "nsDragService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsGtkKeyUtils.h"
|
|
|
|
#include "nsGtkCursors.h"
|
|
|
|
|
2009-01-02 23:37:52 -08:00
|
|
|
#include <gtk/gtk.h>
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK3)
|
|
|
|
#include <gtk/gtkx.h>
|
|
|
|
#endif
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <gdk/gdkx.h>
|
2010-03-31 21:38:51 -07:00
|
|
|
#include <X11/Xatom.h>
|
2010-09-23 18:00:06 -07:00
|
|
|
#include <X11/extensions/XShm.h>
|
2011-05-10 21:54:12 -07:00
|
|
|
#include <X11/extensions/shape.h>
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK3)
|
|
|
|
#include <gdk/gdkkeysyms-compat.h>
|
|
|
|
#endif
|
2010-03-28 08:50:39 -07:00
|
|
|
|
|
|
|
#ifdef AIX
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#else
|
2008-08-06 16:24:13 -07:00
|
|
|
#include <X11/XF86keysym.h>
|
2010-03-28 08:50:39 -07:00
|
|
|
#endif
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#include "gtk2xtbin.h"
|
|
|
|
#endif /* MOZ_X11 */
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-07-21 17:44:55 -07:00
|
|
|
#include <gtk/gtkprivate.h>
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
#include "gtk2compat.h"
|
|
|
|
#endif
|
2008-02-06 13:56:02 -08:00
|
|
|
|
2011-10-14 11:11:22 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_STARTUP_NOTIFICATION
|
|
|
|
#define SN_API_NOT_YET_FROZEN
|
|
|
|
#include <startup-notification-1.0/libsn/sn.h>
|
|
|
|
#endif
|
|
|
|
|
2011-05-28 00:03:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPrefService.h"
|
2011-11-26 11:48:55 -08:00
|
|
|
#include "nsIGConfService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
2009-09-25 09:52:11 -07:00
|
|
|
#include "nsIObserverService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-06 11:47:46 -07:00
|
|
|
#include "nsIdleService.h"
|
2010-04-01 06:58:42 -07:00
|
|
|
#include "nsIPropertyBag2.h"
|
2009-10-06 11:47:46 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-01-04 17:54:17 -08:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-05-11 23:47:35 -07:00
|
|
|
#include "nsIAccessibleDocument.h"
|
2011-05-28 00:03:00 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* For SetIcon */
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsILocalFile.h"
|
|
|
|
|
|
|
|
/* SetCursor(imgIContainer*) */
|
|
|
|
#include <gdk/gdk.h>
|
2009-09-25 09:52:11 -07:00
|
|
|
#include <wchar.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsImageToPixbuf.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2009-12-13 13:01:33 -08:00
|
|
|
extern "C" {
|
2011-11-22 17:42:57 -08:00
|
|
|
#define PIXMAN_DONT_DEFINE_STDINT
|
2009-12-13 13:01:33 -08:00
|
|
|
#include "pixman.h"
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2011-01-25 22:26:37 -08:00
|
|
|
#include "gfxUtils.h"
|
2010-06-17 14:23:00 -07:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "GLContextProvider.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "gfxXlibSurface.h"
|
2011-09-22 13:58:07 -07:00
|
|
|
#include "cairo-xlib.h"
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif
|
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
#include "nsShmImage.h"
|
|
|
|
|
2010-09-23 18:00:06 -07:00
|
|
|
using namespace mozilla;
|
2011-11-28 12:35:19 -08:00
|
|
|
using namespace mozilla::widget;
|
2010-06-23 16:37:00 -07:00
|
|
|
using mozilla::gl::GLContext;
|
|
|
|
using mozilla::layers::LayerManagerOGL;
|
|
|
|
|
2009-02-15 17:10:24 -08:00
|
|
|
// Don't put more than this many rects in the dirty region, just fluff
|
|
|
|
// out to the bounding-box if there are more
|
|
|
|
#define MAX_RECTS_IN_REGION 100
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* utility functions */
|
2012-02-01 18:11:06 -08:00
|
|
|
static bool check_for_rollup(gdouble aMouseX, gdouble aMouseY,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsWheel, bool aAlwaysRollup);
|
|
|
|
static bool is_mouse_in_window(GdkWindow* aWindow,
|
2007-03-22 10:30:00 -07:00
|
|
|
gdouble aMouseX, gdouble aMouseY);
|
|
|
|
static nsWindow *get_window_for_gtk_widget(GtkWidget *widget);
|
|
|
|
static nsWindow *get_window_for_gdk_window(GdkWindow *window);
|
|
|
|
static GtkWidget *get_gtk_widget_for_gdk_window(GdkWindow *window);
|
|
|
|
static GdkCursor *get_gtk_cursor(nsCursor aCursor);
|
|
|
|
|
|
|
|
static GdkWindow *get_inner_gdk_window (GdkWindow *aWindow,
|
|
|
|
gint x, gint y,
|
|
|
|
gint *retx, gint *rety);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool is_context_menu_key(const nsKeyEvent& inKeyEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static int is_parent_ungrab_enter(GdkEventCrossing *aEvent);
|
|
|
|
static int is_parent_grab_leave(GdkEventCrossing *aEvent);
|
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
static void GetBrandName(nsXPIDLString& brandName);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* callbacks from widgets */
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
static gboolean expose_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
static gboolean expose_event_cb (GtkWidget *widget,
|
|
|
|
cairo_t *rect);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
static gboolean configure_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventConfigure *event);
|
2009-05-14 19:14:45 -07:00
|
|
|
static void container_unrealize_cb (GtkWidget *widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
static void size_allocate_cb (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean delete_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventAny *event);
|
|
|
|
static gboolean enter_notify_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
static gboolean leave_notify_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
static gboolean motion_notify_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event);
|
|
|
|
static gboolean button_press_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean button_release_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean focus_in_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventFocus *event);
|
|
|
|
static gboolean focus_out_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventFocus *event);
|
|
|
|
static gboolean key_press_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventKey *event);
|
|
|
|
static gboolean key_release_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventKey *event);
|
|
|
|
static gboolean scroll_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event);
|
|
|
|
static gboolean visibility_notify_event_cb(GtkWidget *widget,
|
|
|
|
GdkEventVisibility *event);
|
2009-11-01 18:03:12 -08:00
|
|
|
static void hierarchy_changed_cb (GtkWidget *widget,
|
|
|
|
GtkWidget *previous_toplevel);
|
2007-03-22 10:30:00 -07:00
|
|
|
static gboolean window_state_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventWindowState *event);
|
|
|
|
static void theme_changed_cb (GtkSettings *settings,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
nsWindow *data);
|
2007-12-13 23:00:44 -08:00
|
|
|
static nsWindow* GetFirstNSWindowForGDKWindow (GdkWindow *aGdkWindow);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-06-17 18:15:03 -07:00
|
|
|
static GdkFilterReturn popup_take_focus_filter (GdkXEvent *gdk_xevent,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data);
|
2007-03-22 10:30:00 -07:00
|
|
|
static GdkFilterReturn plugin_window_filter_func (GdkXEvent *gdk_xevent,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data);
|
|
|
|
static GdkFilterReturn plugin_client_message_filter (GdkXEvent *xevent,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data);
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
static gboolean drag_motion_event_cb (GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData);
|
|
|
|
static void drag_leave_event_cb (GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData);
|
|
|
|
static gboolean drag_drop_event_cb (GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
guint aTime,
|
2011-05-19 03:51:11 -07:00
|
|
|
gpointer aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
static void drag_data_received_event_cb(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
GtkSelectionData *aSelectionData,
|
|
|
|
guint aInfo,
|
|
|
|
guint32 aTime,
|
|
|
|
gpointer aData);
|
|
|
|
|
|
|
|
/* initialization static functions */
|
|
|
|
static nsresult initialize_prefs (void);
|
|
|
|
|
2012-02-13 12:19:59 -08:00
|
|
|
static guint32 sLastUserInputTime = GDK_CURRENT_TIME;
|
2012-02-01 18:12:26 -08:00
|
|
|
static guint32 sRetryGrabTime;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
// The window from which the focus manager asks us to dispatch key events.
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsWindow *gFocusWindow = NULL;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gBlockActivateEvent = false;
|
|
|
|
static bool gGlobalsInitialized = false;
|
|
|
|
static bool gRaiseWindows = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsWindow *gPluginFocusWindow = NULL;
|
|
|
|
|
2009-12-22 15:49:33 -08:00
|
|
|
static nsIRollupListener* gRollupListener;
|
2008-01-14 01:40:45 -08:00
|
|
|
static nsWeakPtr gRollupWindow;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gConsumeRollupEvent;
|
2008-01-14 01:40:45 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_WINDOW_TITLE_MAX_LENGTH 4095
|
|
|
|
|
|
|
|
// If after selecting profile window, the startup fail, please refer to
|
|
|
|
// http://bugzilla.gnome.org/show_bug.cgi?id=88940
|
|
|
|
|
|
|
|
// needed for imgIContainer cursors
|
|
|
|
// GdkDisplay* was added in 2.2
|
|
|
|
typedef struct _GdkDisplay GdkDisplay;
|
|
|
|
|
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
|
|
|
// cursor cache
|
|
|
|
static GdkCursor *gCursorCache[eCursorCount];
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
static GtkWidget *gInvisibleContainer = NULL;
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
// Sometimes this actually also includes the state of the modifier keys, but
|
|
|
|
// only the button state bits are used.
|
|
|
|
static guint gButtonState;
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
// Some gobject functions expect functions for gpointer arguments.
|
|
|
|
// gpointer is void* but C++ doesn't like casting functions to void*.
|
2010-03-23 20:37:06 -07:00
|
|
|
template<class T> static inline gpointer
|
2009-11-01 18:03:12 -08:00
|
|
|
FuncToGpointer(T aFunction)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<gpointer>
|
|
|
|
(reinterpret_cast<uintptr_t>
|
|
|
|
// This cast just provides a warning if T is not a function.
|
|
|
|
(reinterpret_cast<void (*)()>(aFunction)));
|
|
|
|
}
|
|
|
|
|
2009-12-13 13:01:33 -08:00
|
|
|
// nsAutoRef<pixman_region32> uses nsSimpleRef<> to know how to automatically
|
|
|
|
// destroy regions.
|
|
|
|
template <>
|
|
|
|
class nsSimpleRef<pixman_region32> : public pixman_region32 {
|
|
|
|
protected:
|
|
|
|
typedef pixman_region32 RawRef;
|
|
|
|
|
|
|
|
nsSimpleRef() { data = nsnull; }
|
|
|
|
nsSimpleRef(const RawRef &aRawRef) : pixman_region32(aRawRef) { }
|
|
|
|
|
|
|
|
static void Release(pixman_region32& region) {
|
|
|
|
pixman_region32_fini(®ion);
|
|
|
|
}
|
|
|
|
// Whether this needs to be released:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HaveResource() const { return data != nsnull; }
|
2009-12-13 13:01:33 -08:00
|
|
|
|
|
|
|
pixman_region32& get() { return *this; }
|
|
|
|
};
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
static inline PRInt32
|
|
|
|
GetBitmapStride(PRInt32 width)
|
|
|
|
{
|
|
|
|
#if defined(MOZ_X11) || defined(MOZ_WIDGET_GTK2)
|
|
|
|
return (width+7)/8;
|
|
|
|
#else
|
|
|
|
return cairo_format_stride_for_width(CAIRO_FORMAT_A1, width);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-02-13 12:19:59 -08:00
|
|
|
static inline bool TimestampIsNewerThan(guint32 a, guint32 b)
|
|
|
|
{
|
|
|
|
// Timestamps are just the least significant bits of a monotonically
|
|
|
|
// increasing function, and so the use of unsigned overflow arithmetic.
|
|
|
|
return a - b <= G_MAXUINT32/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
UpdateLastInputEventTime(void *aGdkEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIdleService> idleService =
|
|
|
|
do_GetService("@mozilla.org/widget/idleservice;1");
|
|
|
|
if (idleService) {
|
|
|
|
idleService->ResetIdleTimeOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
guint timestamp = gdk_event_get_time(static_cast<GdkEvent*>(aGdkEvent));
|
|
|
|
if (timestamp == GDK_CURRENT_TIME)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sLastUserInputTime = timestamp;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsTopLevel = false;
|
|
|
|
mIsDestroyed = false;
|
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
|
|
|
mListenForResizes = false;
|
|
|
|
mIsShown = false;
|
|
|
|
mNeedsShow = false;
|
|
|
|
mEnabled = true;
|
|
|
|
mCreated = false;
|
2008-10-18 18:13:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mContainer = nsnull;
|
2009-07-26 18:39:36 -07:00
|
|
|
mGdkWindow = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
mShell = nsnull;
|
|
|
|
mWindowGroup = nsnull;
|
2011-10-03 00:56:21 -07:00
|
|
|
mHasMappedToplevel = false;
|
|
|
|
mIsFullyObscured = false;
|
|
|
|
mRetryPointerGrab = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mTransientParent = nsnull;
|
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2009-08-26 17:09:47 -07:00
|
|
|
mLastSizeMode = nsSizeMode_Normal;
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
mOldFocusWindow = 0;
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
mPluginType = PluginType_NONE;
|
|
|
|
|
|
|
|
if (!gGlobalsInitialized) {
|
2011-10-03 00:56:21 -07:00
|
|
|
gGlobalsInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// It's OK if either of these fail, but it may not be one day.
|
|
|
|
initialize_prefs();
|
|
|
|
}
|
|
|
|
|
2008-12-11 15:55:15 -08:00
|
|
|
mLastMotionPressure = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
mRootAccessible = nsnull;
|
|
|
|
#endif
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsTransparent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mTransparencyBitmap = nsnull;
|
|
|
|
|
|
|
|
mTransparencyBitmapWidth = 0;
|
|
|
|
mTransparencyBitmapHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::~nsWindow() [%p]\n", (void *)this));
|
|
|
|
|
|
|
|
delete[] mTransparencyBitmap;
|
|
|
|
mTransparencyBitmap = nsnull;
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsWindow::ReleaseGlobals()
|
|
|
|
{
|
2011-10-10 22:50:08 -07:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(gCursorCache); ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (gCursorCache[i]) {
|
|
|
|
gdk_cursor_unref(gCursorCache[i]);
|
|
|
|
gCursorCache[i] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsBaseWidget,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::CommonCreate(nsIWidget *aParent, bool aListenForResizes)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
|
|
|
mParent = aParent;
|
|
|
|
mListenForResizes = aListenForResizes;
|
2011-10-03 00:56:21 -07:00
|
|
|
mCreated = true;
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-14 19:27:09 -08:00
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
2008-10-18 18:13:27 -07:00
|
|
|
|
|
|
|
event.windowSize = &aRect;
|
|
|
|
event.refPoint.x = aRect.x;
|
|
|
|
event.refPoint.y = aRect.y;
|
|
|
|
event.mWinWidth = aRect.width;
|
|
|
|
event.mWinHeight = aRect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
2009-02-27 17:47:40 -08:00
|
|
|
DispatchEvent(&event, status);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
|
|
|
{
|
2009-09-15 19:01:09 -07:00
|
|
|
NS_ASSERTION(mContainer || mIsDestroyed,
|
|
|
|
"DispatchActivateEvent only intended for container windows");
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
DispatchActivateEventAccessible();
|
|
|
|
#endif //ACCESSIBILITY
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_ACTIVATE, this);
|
2008-10-18 18:13:27 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_DEACTIVATE, this);
|
2008-10-18 18:13:27 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
DispatchDeactivateEventAccessible();
|
|
|
|
#endif //ACCESSIBILITY
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-03-07 09:08:51 -08:00
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, aEvent->widget, aEvent,
|
|
|
|
nsCAutoString("something"), 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// send it to the standard callback
|
|
|
|
if (mEventCallback)
|
|
|
|
aStatus = (* mEventCallback)(aEvent);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mOnDestroyCalled = true;
|
2010-03-24 20:29:14 -07:00
|
|
|
|
|
|
|
// Prevent deletion.
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
2008-10-18 18:13:27 -07:00
|
|
|
|
|
|
|
// release references to children, device context, toolkit + app shell
|
2010-03-24 20:29:14 -07:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// Remove association between this object and its parent and siblings.
|
|
|
|
nsBaseWidget::Destroy();
|
2008-10-18 18:13:27 -07:00
|
|
|
mParent = nsnull;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_DESTROY, this);
|
2008-10-18 18:13:27 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-10-18 18:13:27 -07:00
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
|
|
|
if (mBounds.width > 0 && mBounds.height > 0)
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2008-10-18 18:13:27 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
static GtkWidget*
|
|
|
|
EnsureInvisibleContainer()
|
|
|
|
{
|
|
|
|
if (!gInvisibleContainer) {
|
|
|
|
// GtkWidgets need to be anchored to a GtkWindow to be realized (to
|
|
|
|
// have a window). Using GTK_WINDOW_POPUP rather than
|
|
|
|
// GTK_WINDOW_TOPLEVEL in the hope that POPUP results in less
|
|
|
|
// initialization and window manager interaction.
|
|
|
|
GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
|
|
|
|
gInvisibleContainer = moz_container_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), gInvisibleContainer);
|
|
|
|
gtk_widget_realize(gInvisibleContainer);
|
|
|
|
|
|
|
|
}
|
|
|
|
return gInvisibleContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CheckDestroyInvisibleContainer()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(gInvisibleContainer, "oh, no");
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
if (!gdk_window_peek_children(gtk_widget_get_window(gInvisibleContainer))) {
|
2009-05-14 19:14:45 -07:00
|
|
|
// No children, so not in use.
|
|
|
|
// Make sure to destroy the GtkWindow also.
|
2011-09-22 13:58:07 -07:00
|
|
|
gtk_widget_destroy(gtk_widget_get_parent(gInvisibleContainer));
|
2009-05-14 19:14:45 -07:00
|
|
|
gInvisibleContainer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the containing GtkWidget on a sub-hierarchy of GdkWindows belonging
|
|
|
|
// to aOldWidget and rooted at aWindow, and reparent any child GtkWidgets of
|
2009-11-10 13:57:25 -08:00
|
|
|
// the GdkWindow hierarchy to aNewWidget.
|
2009-05-14 19:14:45 -07:00
|
|
|
static void
|
|
|
|
SetWidgetForHierarchy(GdkWindow *aWindow,
|
|
|
|
GtkWidget *aOldWidget,
|
|
|
|
GtkWidget *aNewWidget)
|
|
|
|
{
|
|
|
|
gpointer data;
|
|
|
|
gdk_window_get_user_data(aWindow, &data);
|
|
|
|
|
|
|
|
if (data != aOldWidget) {
|
|
|
|
if (!GTK_IS_WIDGET(data))
|
|
|
|
return;
|
|
|
|
|
|
|
|
GtkWidget* widget = static_cast<GtkWidget*>(data);
|
2011-09-22 13:58:07 -07:00
|
|
|
if (gtk_widget_get_parent(widget) != aOldWidget)
|
2009-05-14 19:14:45 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// This window belongs to a child widget, which will no longer be a
|
|
|
|
// child of aOldWidget.
|
2009-11-10 13:57:25 -08:00
|
|
|
gtk_widget_reparent(widget, aNewWidget);
|
2009-05-14 19:14:45 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-16 03:20:19 -07:00
|
|
|
GList *children = gdk_window_get_children(aWindow);
|
|
|
|
for(GList *list = children; list; list = list->next) {
|
2009-05-14 19:14:45 -07:00
|
|
|
SetWidgetForHierarchy(GDK_WINDOW(list->data), aOldWidget, aNewWidget);
|
|
|
|
}
|
2009-05-16 03:20:19 -07:00
|
|
|
g_list_free(children);
|
2009-05-14 19:14:45 -07:00
|
|
|
|
|
|
|
gdk_window_set_user_data(aWindow, aNewWidget);
|
|
|
|
}
|
|
|
|
|
2009-11-10 13:57:25 -08:00
|
|
|
// Walk the list of child windows and call destroy on them.
|
|
|
|
void
|
|
|
|
nsWindow::DestroyChildWindows()
|
|
|
|
{
|
|
|
|
if (!mGdkWindow)
|
|
|
|
return;
|
|
|
|
|
2009-11-12 20:20:23 -08:00
|
|
|
while (GList *children = gdk_window_peek_children(mGdkWindow)) {
|
2009-11-10 13:57:25 -08:00
|
|
|
GdkWindow *child = GDK_WINDOW(children->data);
|
|
|
|
nsWindow *kid = get_window_for_gdk_window(child);
|
|
|
|
if (kid) {
|
|
|
|
kid->Destroy();
|
|
|
|
} else {
|
|
|
|
// This child is not an nsWindow.
|
|
|
|
// Destroy the child GtkWidget.
|
|
|
|
gpointer data;
|
|
|
|
gdk_window_get_user_data(child, &data);
|
|
|
|
if (GTK_IS_WIDGET(data)) {
|
|
|
|
gtk_widget_destroy(static_cast<GtkWidget*>(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
|
|
|
if (mIsDestroyed || !mCreated)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsDestroyed = true;
|
|
|
|
mCreated = false;
|
2008-09-17 14:15:52 -07:00
|
|
|
|
2010-06-23 16:37:00 -07:00
|
|
|
/** Need to clean our LayerManager up while still alive */
|
2010-08-06 22:09:18 -07:00
|
|
|
if (mLayerManager) {
|
|
|
|
nsRefPtr<GLContext> gl = nsnull;
|
|
|
|
if (mLayerManager->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
|
|
|
LayerManagerOGL *ogllm = static_cast<LayerManagerOGL*>(mLayerManager.get());
|
|
|
|
gl = ogllm->gl();
|
|
|
|
}
|
|
|
|
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
|
|
|
|
if (gl) {
|
|
|
|
gl->MarkDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mLayerManager = nsnull;
|
2010-06-23 16:37:00 -07:00
|
|
|
|
2012-05-23 07:17:44 -07:00
|
|
|
// It is safe to call DestroyeCompositor several times (here and
|
|
|
|
// in the parent class) since it will take effect only once.
|
|
|
|
// The reason we call it here is because on gtk platforms we need
|
|
|
|
// to destroy the compositor before we destroy the gdk window (which
|
|
|
|
// destroys the the gl context attached to it).
|
|
|
|
DestroyCompositor();
|
|
|
|
|
2011-01-21 13:45:23 -08:00
|
|
|
ClearCachedResources();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
g_signal_handlers_disconnect_by_func(gtk_settings_get_default(),
|
2009-11-01 18:03:12 -08:00
|
|
|
FuncToGpointer(theme_changed_cb),
|
2007-03-22 10:30:00 -07:00
|
|
|
this);
|
|
|
|
|
|
|
|
// ungrab if required
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
2007-07-08 00:08:04 -07:00
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget.get()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (gRollupListener)
|
2011-11-08 11:59:07 -08:00
|
|
|
gRollupListener->Rollup(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
|
|
|
}
|
|
|
|
|
2012-05-03 20:34:50 -07:00
|
|
|
// dragService will be null after shutdown of the service manager.
|
2012-04-18 23:18:31 -07:00
|
|
|
nsDragService *dragService = nsDragService::GetInstance();
|
2012-05-03 20:34:50 -07:00
|
|
|
if (dragService && this == dragService->GetMostRecentDestWindow()) {
|
2012-04-18 23:18:31 -07:00
|
|
|
dragService->ScheduleLeaveEvent();
|
|
|
|
}
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
NativeShow(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-18 21:21:16 -07:00
|
|
|
if (mIMModule) {
|
|
|
|
mIMModule->OnDestroyWindow(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// make sure that we remove ourself as the focus window
|
|
|
|
if (gFocusWindow == this) {
|
|
|
|
LOGFOCUS(("automatically losing focus...\n"));
|
|
|
|
gFocusWindow = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_X11)
|
2007-03-22 10:30:00 -07:00
|
|
|
// make sure that we remove ourself as the plugin focus window
|
|
|
|
if (gPluginFocusWindow == this) {
|
|
|
|
gPluginFocusWindow->LoseNonXEmbedPluginFocus();
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif /* MOZ_X11 && MOZ_WIDGET_GTK2 */
|
|
|
|
|
2007-10-07 22:02:38 -07:00
|
|
|
if (mWindowGroup) {
|
2011-05-11 06:10:36 -07:00
|
|
|
g_object_unref(mWindowGroup);
|
2007-10-07 22:02:38 -07:00
|
|
|
mWindowGroup = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Destroy thebes surface now. Badness can happen if we destroy
|
|
|
|
// the surface after its X Window.
|
|
|
|
mThebesSurface = nsnull;
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
GtkWidget *owningWidget = GetMozContainerWidget();
|
|
|
|
if (mShell) {
|
|
|
|
gtk_widget_destroy(mShell);
|
|
|
|
mShell = nsnull;
|
|
|
|
mContainer = nsnull;
|
2009-07-26 18:40:46 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mGdkWindow,
|
|
|
|
"mGdkWindow should be NULL when mContainer is destroyed");
|
2009-05-14 19:14:45 -07:00
|
|
|
}
|
|
|
|
else if (mContainer) {
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(mContainer));
|
|
|
|
mContainer = nsnull;
|
2009-07-26 18:40:46 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mGdkWindow,
|
|
|
|
"mGdkWindow should be NULL when mContainer is destroyed");
|
2009-05-14 19:14:45 -07:00
|
|
|
}
|
2009-07-26 18:40:46 -07:00
|
|
|
else if (mGdkWindow) {
|
2009-11-10 13:57:25 -08:00
|
|
|
// Destroy child windows to ensure that their mThebesSurfaces are
|
|
|
|
// released and to remove references from GdkWindows back to their
|
|
|
|
// container widget. (OnContainerUnrealize() does this when the
|
|
|
|
// MozContainer widget is destroyed.)
|
|
|
|
DestroyChildWindows();
|
2009-05-14 19:14:45 -07:00
|
|
|
|
2009-11-10 13:57:25 -08:00
|
|
|
gdk_window_set_user_data(mGdkWindow, NULL);
|
2009-07-26 18:40:46 -07:00
|
|
|
g_object_set_data(G_OBJECT(mGdkWindow), "nsWindow", NULL);
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_destroy(mGdkWindow);
|
|
|
|
mGdkWindow = nsnull;
|
2008-08-27 19:04:06 -07:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
if (gInvisibleContainer && owningWidget == gInvisibleContainer) {
|
|
|
|
CheckDestroyInvisibleContainer();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2010-03-24 20:29:14 -07:00
|
|
|
if (mRootAccessible) {
|
|
|
|
mRootAccessible = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2010-03-24 20:29:14 -07:00
|
|
|
// Save until last because OnDestroy() may cause us to be deleted.
|
|
|
|
OnDestroy();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
nsIWidget *
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:57:55 -07:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
2010-11-18 11:19:39 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
|
|
|
static float sDPI = 0;
|
|
|
|
|
|
|
|
if (!sDPI) {
|
|
|
|
// X on Maemo does not report true DPI: https://bugs.maemo.org/show_bug.cgi?id=4825
|
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
|
|
|
|
NS_ASSERTION(infoService, "Could not find a system info service");
|
|
|
|
|
|
|
|
nsCString deviceType;
|
|
|
|
infoService->GetPropertyAsACString(NS_LITERAL_STRING("device"), deviceType);
|
|
|
|
if (deviceType.EqualsLiteral("Nokia N900")) {
|
|
|
|
sDPI = 265.0f;
|
|
|
|
} else if (deviceType.EqualsLiteral("Nokia N8xx")) {
|
|
|
|
sDPI = 225.0f;
|
|
|
|
} else {
|
|
|
|
// Fall back to something sane.
|
|
|
|
NS_WARNING("Unknown device - using default DPI");
|
|
|
|
sDPI = 96.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sDPI;
|
|
|
|
#else
|
2011-09-22 13:58:07 -07:00
|
|
|
Display *dpy = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
2010-08-13 02:57:55 -07:00
|
|
|
int defaultScreen = DefaultScreen(dpy);
|
2010-08-13 02:57:57 -07:00
|
|
|
double heightInches = DisplayHeightMM(dpy, defaultScreen)/MM_PER_INCH_FLOAT;
|
2010-08-13 02:57:55 -07:00
|
|
|
if (heightInches < 0.25) {
|
|
|
|
// Something's broken, but we'd better not crash.
|
|
|
|
return 96.0f;
|
|
|
|
}
|
|
|
|
return float(DisplayHeight(dpy, defaultScreen)/heightInches);
|
2010-11-18 11:19:39 -08:00
|
|
|
#endif
|
2010-08-13 02:57:55 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
2011-11-21 12:15:38 -08:00
|
|
|
if (mContainer || !mGdkWindow) {
|
|
|
|
NS_NOTREACHED("nsWindow::SetParent called illegally");
|
2009-05-14 19:14:45 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_ASSERTION(!mTransientParent, "child widget with transient parent");
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
2011-11-21 12:15:38 -08:00
|
|
|
if (mParent) {
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
mParent = aNewParent;
|
|
|
|
|
|
|
|
GtkWidget* oldContainer = GetMozContainerWidget();
|
|
|
|
if (!oldContainer) {
|
|
|
|
// The GdkWindows have been destroyed so there is nothing else to
|
|
|
|
// reparent.
|
2011-09-22 13:58:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(gdk_window_is_destroyed(mGdkWindow),
|
2009-05-14 19:14:45 -07:00
|
|
|
"live GdkWindow with no widget");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNewParent) {
|
2010-09-18 04:28:50 -07:00
|
|
|
aNewParent->AddChild(this);
|
2010-09-18 04:28:50 -07:00
|
|
|
ReparentNativeWidget(aNewParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-05-14 19:14:45 -07:00
|
|
|
// aNewParent is NULL, but reparent to a hidden window to avoid
|
|
|
|
// destroying the GdkWindow and its descendants.
|
|
|
|
// An invisible container widget is needed to hold descendant
|
|
|
|
// GtkWidgets.
|
2010-09-18 04:28:50 -07:00
|
|
|
GtkWidget* newContainer = EnsureInvisibleContainer();
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow* newParentWindow = gtk_widget_get_window(newContainer);
|
2010-09-18 04:28:50 -07:00
|
|
|
ReparentNativeWidgetInternal(aNewParent, newContainer, newParentWindow,
|
|
|
|
oldContainer);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
NS_ASSERTION(!mIsDestroyed, "");
|
|
|
|
NS_ASSERTION(!static_cast<nsWindow*>(aNewParent)->mIsDestroyed, "");
|
|
|
|
|
|
|
|
GtkWidget* oldContainer = GetMozContainerWidget();
|
|
|
|
if (!oldContainer) {
|
|
|
|
// The GdkWindows have been destroyed so there is nothing else to
|
|
|
|
// reparent.
|
2011-09-22 13:58:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(gdk_window_is_destroyed(mGdkWindow),
|
2010-09-18 04:28:50 -07:00
|
|
|
"live GdkWindow with no widget");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!gdk_window_is_destroyed(mGdkWindow),
|
2010-09-18 04:28:50 -07:00
|
|
|
"destroyed GdkWindow with widget");
|
|
|
|
|
|
|
|
nsWindow* newParent = static_cast<nsWindow*>(aNewParent);
|
|
|
|
GdkWindow* newParentWindow = newParent->mGdkWindow;
|
|
|
|
GtkWidget* newContainer = NULL;
|
|
|
|
if (newParentWindow) {
|
|
|
|
newContainer = get_gtk_widget_for_gdk_window(newParentWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTransientParent) {
|
|
|
|
GtkWindow* topLevelParent =
|
|
|
|
GTK_WINDOW(gtk_widget_get_toplevel(newContainer));
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent);
|
|
|
|
mTransientParent = topLevelParent;
|
|
|
|
if (mWindowGroup) {
|
2011-05-11 06:10:36 -07:00
|
|
|
g_object_unref(mWindowGroup);
|
2010-09-18 04:28:50 -07:00
|
|
|
mWindowGroup = NULL;
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
if (gtk_window_get_group(mTransientParent)) {
|
|
|
|
gtk_window_group_add_window(gtk_window_get_group(mTransientParent),
|
2010-09-18 04:28:50 -07:00
|
|
|
GTK_WINDOW(mShell));
|
2011-09-22 13:58:07 -07:00
|
|
|
mWindowGroup = gtk_window_get_group(mTransientParent);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_object_ref(mWindowGroup);
|
2010-09-18 04:28:50 -07:00
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
else if (gtk_window_get_group(GTK_WINDOW(mShell))) {
|
|
|
|
gtk_window_group_remove_window(gtk_window_get_group(GTK_WINDOW(mShell)),
|
2010-09-18 04:28:50 -07:00
|
|
|
GTK_WINDOW(mShell));
|
|
|
|
}
|
2009-05-14 19:14:45 -07:00
|
|
|
}
|
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
ReparentNativeWidgetInternal(aNewParent, newContainer, newParentWindow,
|
|
|
|
oldContainer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ReparentNativeWidgetInternal(nsIWidget* aNewParent,
|
|
|
|
GtkWidget* aNewContainer,
|
|
|
|
GdkWindow* aNewParentWindow,
|
|
|
|
GtkWidget* aOldContainer)
|
|
|
|
{
|
|
|
|
if (!aNewContainer) {
|
2009-05-14 19:14:45 -07:00
|
|
|
// The new parent GdkWindow has been destroyed.
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_ABORT_IF_FALSE(!aNewParentWindow ||
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_is_destroyed(aNewParentWindow),
|
2009-05-14 19:14:45 -07:00
|
|
|
"live GdkWindow with no widget");
|
|
|
|
Destroy();
|
|
|
|
} else {
|
2010-09-18 04:28:50 -07:00
|
|
|
if (aNewContainer != aOldContainer) {
|
2011-09-22 13:58:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!gdk_window_is_destroyed(aNewParentWindow),
|
2009-05-14 19:14:45 -07:00
|
|
|
"destroyed GdkWindow with widget");
|
2010-09-18 04:28:50 -07:00
|
|
|
SetWidgetForHierarchy(mGdkWindow, aOldContainer, aNewContainer);
|
2011-11-21 12:15:38 -08:00
|
|
|
|
|
|
|
if (aOldContainer == gInvisibleContainer) {
|
|
|
|
CheckDestroyInvisibleContainer();
|
|
|
|
}
|
2009-05-14 19:14:45 -07:00
|
|
|
}
|
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
if (!mIsTopLevel) {
|
|
|
|
gdk_window_reparent(mGdkWindow, aNewParentWindow, mBounds.x,
|
|
|
|
mBounds.y);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-05-14 19:14:45 -07:00
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
nsWindow* newParent = static_cast<nsWindow*>(aNewParent);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool parentHasMappedToplevel =
|
2009-11-01 18:03:12 -08:00
|
|
|
newParent && newParent->mHasMappedToplevel;
|
|
|
|
if (mHasMappedToplevel != parentHasMappedToplevel) {
|
|
|
|
SetHasMappedToplevel(parentHasMappedToplevel);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetModal(bool aModal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::SetModal [%p] %d\n", (void *)this, aModal));
|
2010-06-01 16:33:28 -07:00
|
|
|
if (mIsDestroyed)
|
|
|
|
return aModal ? NS_ERROR_NOT_AVAILABLE : NS_OK;
|
|
|
|
if (!mIsTopLevel || !mShell)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-06-01 16:33:28 -07:00
|
|
|
gtk_window_set_modal(GTK_WINDOW(mShell), aModal ? TRUE : FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:28:05 -07:00
|
|
|
// nsIWidget method, which means IsShown.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::IsVisible(bool& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-26 18:28:05 -07:00
|
|
|
aState = mIsShown;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop, PRInt32 *aX, PRInt32 *aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mIsTopLevel && mShell) {
|
|
|
|
PRInt32 screenWidth = gdk_screen_width();
|
|
|
|
PRInt32 screenHeight = gdk_screen_height();
|
|
|
|
if (aAllowSlop) {
|
|
|
|
if (*aX < (kWindowPositionSlop - mBounds.width))
|
|
|
|
*aX = kWindowPositionSlop - mBounds.width;
|
|
|
|
if (*aX > (screenWidth - kWindowPositionSlop))
|
|
|
|
*aX = screenWidth - kWindowPositionSlop;
|
|
|
|
if (*aY < (kWindowPositionSlop - mBounds.height))
|
|
|
|
*aY = kWindowPositionSlop - mBounds.height;
|
|
|
|
if (*aY > (screenHeight - kWindowPositionSlop))
|
|
|
|
*aY = screenHeight - kWindowPositionSlop;
|
|
|
|
} else {
|
|
|
|
if (*aX < 0)
|
|
|
|
*aX = 0;
|
|
|
|
if (*aX > (screenWidth - mBounds.width))
|
|
|
|
*aX = screenWidth - mBounds.width;
|
|
|
|
if (*aY < 0)
|
|
|
|
*aY = 0;
|
|
|
|
if (*aY > (screenHeight - mBounds.height))
|
|
|
|
*aY = screenHeight - mBounds.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Show(bool aState)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
2009-11-01 18:03:12 -08:00
|
|
|
if (aState == mIsShown)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-01-21 13:45:23 -08:00
|
|
|
// Clear our cached resources when the window is hidden.
|
|
|
|
if (mIsShown && !aState) {
|
|
|
|
ClearCachedResources();
|
|
|
|
}
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
mIsShown = aState;
|
|
|
|
|
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
if (aState) {
|
|
|
|
// Now that this window is shown, mHasMappedToplevel needs to be
|
|
|
|
// tracked on viewable descendants.
|
|
|
|
SetHasMappedToplevel(mHasMappedToplevel);
|
|
|
|
}
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
// Ok, someone called show on a window that isn't sized to a sane
|
|
|
|
// value. Mark this window as needing to have Show() called on it
|
|
|
|
// and return.
|
|
|
|
if ((aState && !AreBoundsSane()) || !mCreated) {
|
|
|
|
LOG(("\tbounds are insane or window hasn't been created yet\n"));
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsShow = true;
|
2008-10-18 18:13:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If someone is hiding this widget, clear any needing show flag.
|
|
|
|
if (!aState)
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsShow = false;
|
2008-10-18 18:13:27 -07:00
|
|
|
|
|
|
|
// If someone is showing this window and it needs a resize then
|
|
|
|
// resize the widget.
|
|
|
|
if (aState) {
|
|
|
|
if (mNeedsMove) {
|
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
2011-10-03 00:56:21 -07:00
|
|
|
false);
|
2008-10-18 18:13:27 -07:00
|
|
|
} else if (mNeedsResize) {
|
2011-10-03 00:56:21 -07:00
|
|
|
NativeResize(mBounds.width, mBounds.height, false);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-28 02:26:56 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-01-04 17:54:17 -08:00
|
|
|
if (aState && a11y::ShouldA11yBeEnabled())
|
2011-05-28 02:26:56 -07:00
|
|
|
CreateRootAccessible();
|
|
|
|
#endif
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
NativeShow(aState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
2011-07-07 20:14:27 -07:00
|
|
|
// For top-level windows, aWidth and aHeight should possibly be
|
|
|
|
// interpreted as frame bounds, but NativeResize treats these as window
|
|
|
|
// bounds (Bug 581866).
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
mBounds.SizeTo(GetSafeWindowSize(nsIntSize(aWidth, aHeight)));
|
2008-10-18 18:13:27 -07:00
|
|
|
|
|
|
|
if (!mCreated)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// There are several cases here that we need to handle, based on a
|
|
|
|
// matrix of the visibility of the widget, the sanity of this resize
|
|
|
|
// and whether or not the widget was previously sane.
|
|
|
|
|
|
|
|
// Has this widget been set to visible?
|
|
|
|
if (mIsShown) {
|
|
|
|
// Are the bounds sane?
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
// Yep? Resize the window
|
|
|
|
//Maybe, the toplevel has moved
|
|
|
|
|
2010-12-20 18:45:58 -08:00
|
|
|
// Note that if the widget needs to be positioned because its
|
|
|
|
// size was previously insane in Resize(x,y,w,h), then we need
|
2008-10-18 18:13:27 -07:00
|
|
|
// to set the x and y here too, because the widget wasn't
|
|
|
|
// moved back then
|
2010-12-20 18:45:58 -08:00
|
|
|
if (mNeedsMove)
|
2008-10-18 18:13:27 -07:00
|
|
|
NativeResize(mBounds.x, mBounds.y,
|
|
|
|
mBounds.width, mBounds.height, aRepaint);
|
|
|
|
else
|
|
|
|
NativeResize(mBounds.width, mBounds.height, aRepaint);
|
|
|
|
|
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow)
|
2011-10-03 00:56:21 -07:00
|
|
|
NativeShow(true);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If someone has set this so that the needs show flag is false
|
|
|
|
// and it needs to be hidden, update the flag and hide the
|
|
|
|
// window. This flag will be cleared the next time someone
|
|
|
|
// hides the window or shows it. It also prevents us from
|
2011-10-03 00:56:21 -07:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2008-10-18 18:13:27 -07:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the widget hasn't been shown, mark the widget as needing to be
|
|
|
|
// resized before it is shown.
|
|
|
|
else {
|
|
|
|
if (AreBoundsSane() && mListenForResizes) {
|
|
|
|
// For widgets that we listen for resizes for (widgets created
|
|
|
|
// with native parents) we apparently _always_ have to resize. I
|
|
|
|
// dunno why, but apparently we're lame like that.
|
|
|
|
NativeResize(aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsResize = true;
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 17:50:42 -07:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
// synthesize a resize event if this isn't a toplevel
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect rect(mBounds.x, mBounds.y, aWidth, aHeight);
|
2008-10-18 18:13:27 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
2009-01-14 19:27:09 -08:00
|
|
|
mBounds.SizeTo(GetSafeWindowSize(nsIntSize(aWidth, aHeight)));
|
2008-10-18 18:13:27 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsMove = true;
|
2008-10-18 18:13:27 -07:00
|
|
|
|
|
|
|
if (!mCreated)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// There are several cases here that we need to handle, based on a
|
|
|
|
// matrix of the visibility of the widget, the sanity of this resize
|
|
|
|
// and whether or not the widget was previously sane.
|
|
|
|
|
|
|
|
// Has this widget been set to visible?
|
|
|
|
if (mIsShown) {
|
|
|
|
// Are the bounds sane?
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
// Yep? Resize the window
|
|
|
|
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow)
|
2011-10-03 00:56:21 -07:00
|
|
|
NativeShow(true);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If someone has set this so that the needs show flag is false
|
|
|
|
// and it needs to be hidden, update the flag and hide the
|
|
|
|
// window. This flag will be cleared the next time someone
|
|
|
|
// hides the window or shows it. It also prevents us from
|
2011-10-03 00:56:21 -07:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2008-10-18 18:13:27 -07:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the widget hasn't been shown, mark the widget as needing to be
|
|
|
|
// resized before it is shown
|
|
|
|
else {
|
|
|
|
if (AreBoundsSane() && mListenForResizes){
|
|
|
|
// For widgets that we listen for resizes for (widgets created
|
|
|
|
// with native parents) we apparently _always_ have to resize. I
|
|
|
|
// dunno why, but apparently we're lame like that.
|
|
|
|
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsResize = true;
|
2008-10-18 18:13:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 17:50:42 -07:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
|
|
|
|
2008-10-18 18:13:27 -07:00
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
// synthesize a resize event
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect rect(aX, aY, aWidth, aHeight);
|
2008-10-18 18:13:27 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Enable(bool aState)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
|
|
|
mEnabled = aState;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::IsEnabled(bool *aState)
|
2008-10-18 18:13:27 -07:00
|
|
|
{
|
|
|
|
*aState = mEnabled;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Move(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::Move [%p] %d %d\n", (void *)this,
|
|
|
|
aX, aY));
|
|
|
|
|
2009-11-02 11:10:07 -08:00
|
|
|
if (mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog) {
|
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Since a popup window's x/y coordinates are in relation to to
|
|
|
|
// the parent, the parent might have moved so we always move a
|
|
|
|
// popup window.
|
|
|
|
if (aX == mBounds.x && aY == mBounds.y &&
|
|
|
|
mWindowType != eWindowType_popup)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// XXX Should we do some AreBoundsSane check here?
|
|
|
|
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
|
|
|
|
if (!mCreated)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsMove = false;
|
2010-12-20 18:45:58 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mIsTopLevel) {
|
2007-11-28 12:18:11 -08:00
|
|
|
gtk_window_move(GTK_WINDOW(mShell), aX, aY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-26 18:39:36 -07:00
|
|
|
else if (mGdkWindow) {
|
|
|
|
gdk_window_move(mGdkWindow, aX, aY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 17:50:42 -07:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-05-05 16:44:18 -07:00
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aActivate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetZIndex(PRInt32 aZIndex)
|
|
|
|
{
|
|
|
|
nsIWidget* oldPrev = GetPrevSibling();
|
|
|
|
|
|
|
|
nsBaseWidget::SetZIndex(aZIndex);
|
|
|
|
|
|
|
|
if (GetPrevSibling() == oldPrev) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mContainer, "Expected Mozilla child widget");
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
// We skip the nsWindows that don't have mGdkWindows.
|
2007-03-22 10:30:00 -07:00
|
|
|
// These are probably in the process of being destroyed.
|
|
|
|
|
|
|
|
if (!GetNextSibling()) {
|
|
|
|
// We're to be on top.
|
2009-07-26 18:39:36 -07:00
|
|
|
if (mGdkWindow)
|
|
|
|
gdk_window_raise(mGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-02-27 17:47:40 -08:00
|
|
|
// All the siblings before us need to be below our widget.
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsWindow* w = this; w;
|
2007-07-08 00:08:04 -07:00
|
|
|
w = static_cast<nsWindow*>(w->GetPrevSibling())) {
|
2009-07-26 18:39:36 -07:00
|
|
|
if (w->mGdkWindow)
|
|
|
|
gdk_window_lower(w->mGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
|
|
|
|
|
|
|
// Save the requested state.
|
|
|
|
rv = nsBaseWidget::SetSizeMode(aMode);
|
|
|
|
|
|
|
|
// return if there's no shell or our current state is the same as
|
|
|
|
// the mode we were just set to.
|
|
|
|
if (!mShell || mSizeState == mSizeMode) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
|
|
|
gtk_window_maximize(GTK_WINDOW(mShell));
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
gtk_window_iconify(GTK_WINDOW(mShell));
|
|
|
|
break;
|
2009-08-14 12:56:56 -07:00
|
|
|
case nsSizeMode_Fullscreen:
|
2011-10-03 00:56:21 -07:00
|
|
|
MakeFullScreen(true);
|
2009-08-14 12:56:56 -07:00
|
|
|
break;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
|
|
|
if (mSizeState == nsSizeMode_Minimized)
|
|
|
|
gtk_window_deiconify(GTK_WINDOW(mShell));
|
|
|
|
else if (mSizeState == nsSizeMode_Maximized)
|
|
|
|
gtk_window_unmaximize(GTK_WINDOW(mShell));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (* SetUserTimeFunc)(GdkWindow* aWindow, guint32 aTimestamp);
|
|
|
|
|
|
|
|
// This will become obsolete when new GTK APIs are widely supported,
|
|
|
|
// as described here: http://bugzilla.gnome.org/show_bug.cgi?id=347375
|
|
|
|
static void
|
|
|
|
SetUserTimeAndStartupIDForActivatedWindow(GtkWidget* aWindow)
|
|
|
|
{
|
2011-10-25 08:05:32 -07:00
|
|
|
nsGTKToolkit* GTKToolkit = nsGTKToolkit::GetToolkit();
|
|
|
|
if (!GTKToolkit)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsCAutoString desktopStartupID;
|
|
|
|
GTKToolkit->GetDesktopStartupID(&desktopStartupID);
|
|
|
|
if (desktopStartupID.IsEmpty()) {
|
|
|
|
// We don't have the data we need. Fall back to an
|
|
|
|
// approximation ... using the timestamp of the remote command
|
|
|
|
// being received as a guess for the timestamp of the user event
|
|
|
|
// that triggered it.
|
|
|
|
PRUint32 timestamp = GTKToolkit->GetFocusTimestamp();
|
|
|
|
if (timestamp) {
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_focus(gtk_widget_get_window(aWindow), timestamp);
|
2007-03-22 10:30:00 -07:00
|
|
|
GTKToolkit->SetFocusTimestamp(0);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_ENABLE_STARTUP_NOTIFICATION)
|
|
|
|
GdkWindow* gdkWindow = gtk_widget_get_window(aWindow);
|
|
|
|
|
|
|
|
GdkScreen* screen = gdk_window_get_screen(gdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
SnDisplay* snd =
|
2011-09-22 13:58:07 -07:00
|
|
|
sn_display_new(gdk_x11_display_get_xdisplay(gdk_window_get_display(gdkWindow)),
|
|
|
|
nsnull, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!snd)
|
|
|
|
return;
|
|
|
|
SnLauncheeContext* ctx =
|
|
|
|
sn_launchee_context_new(snd, gdk_screen_get_number(screen),
|
|
|
|
desktopStartupID.get());
|
|
|
|
if (!ctx) {
|
|
|
|
sn_display_unref(snd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sn_launchee_context_get_id_has_timestamp(ctx)) {
|
|
|
|
PRLibrary* gtkLibrary;
|
|
|
|
SetUserTimeFunc setUserTimeFunc = (SetUserTimeFunc)
|
|
|
|
PR_FindFunctionSymbolAndLibrary("gdk_x11_window_set_user_time", >kLibrary);
|
|
|
|
if (setUserTimeFunc) {
|
2011-09-22 13:58:07 -07:00
|
|
|
setUserTimeFunc(gdkWindow, sn_launchee_context_get_timestamp(ctx));
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_UnloadLibrary(gtkLibrary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
sn_launchee_context_setup_window(ctx, gdk_x11_window_get_xid(gdkWindow));
|
2007-03-22 10:30:00 -07:00
|
|
|
sn_launchee_context_complete(ctx);
|
|
|
|
|
|
|
|
sn_launchee_context_unref(ctx);
|
|
|
|
sn_display_unref(snd);
|
|
|
|
#endif
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2012-02-16 02:23:34 -08:00
|
|
|
// If we used the startup ID, that already contains the focus timestamp;
|
|
|
|
// we don't want to reuse the timestamp next time we raise the window
|
|
|
|
GTKToolkit->SetFocusTimestamp(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
GTKToolkit->SetDesktopStartupID(EmptyCString());
|
2009-02-27 17:47:40 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-01 18:12:26 -08:00
|
|
|
/* static */ guint32
|
2012-02-13 12:19:59 -08:00
|
|
|
nsWindow::GetLastUserInputTime()
|
|
|
|
{
|
|
|
|
// gdk_x11_display_get_user_time tracks button and key presses,
|
|
|
|
// DESKTOP_STARTUP_ID used to start the app, drop events from external
|
|
|
|
// drags, WM_DELETE_WINDOW delete events, but not usually mouse motion nor
|
|
|
|
// button and key releases. Therefore use the most recent of
|
|
|
|
// gdk_x11_display_get_user_time and the last time that we have seen.
|
|
|
|
guint32 timestamp =
|
|
|
|
gdk_x11_display_get_user_time(gdk_display_get_default());
|
|
|
|
if (sLastUserInputTime != GDK_CURRENT_TIME &&
|
|
|
|
TimestampIsNewerThan(sLastUserInputTime, timestamp)) {
|
|
|
|
return sLastUserInputTime;
|
2012-02-01 18:12:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Make sure that our owning widget has focus. If it doesn't try to
|
|
|
|
// grab it. Note that we don't set our focus flag in this case.
|
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
LOGFOCUS((" SetFocus %d [%p]\n", aRaise, (void *)this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *owningWidget = GetMozContainerWidget();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!owningWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
// Raise the window if someone passed in true and the prefs are
|
2007-03-22 10:30:00 -07:00
|
|
|
// set properly.
|
|
|
|
GtkWidget *toplevelWidget = gtk_widget_get_toplevel(owningWidget);
|
|
|
|
|
|
|
|
if (gRaiseWindows && aRaise && toplevelWidget &&
|
2011-09-22 13:58:07 -07:00
|
|
|
!gtk_widget_has_focus(owningWidget) &&
|
|
|
|
!gtk_widget_has_focus(toplevelWidget)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
GtkWidget* top_window = nsnull;
|
|
|
|
GetToplevelWidget(&top_window);
|
2011-09-22 13:58:07 -07:00
|
|
|
if (top_window && (gtk_widget_get_visible(top_window)))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_show_unraised(gtk_widget_get_window(top_window));
|
2007-03-22 10:30:00 -07:00
|
|
|
// Unset the urgency hint if possible.
|
2011-10-03 00:56:21 -07:00
|
|
|
SetUrgencyHint(top_window, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> owningWindow = get_window_for_gtk_widget(owningWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!owningWindow)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
if (aRaise) {
|
2011-10-03 00:56:21 -07:00
|
|
|
// aRaise == true means request toplevel activation.
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
// This is asynchronous.
|
|
|
|
// If and when the window manager accepts the request, then the focus
|
|
|
|
// widget will get a focus-in-event signal.
|
|
|
|
if (gRaiseWindows && owningWindow->mIsShown && owningWindow->mShell &&
|
|
|
|
!gtk_window_is_active(GTK_WINDOW(owningWindow->mShell))) {
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2012-02-16 02:23:34 -08:00
|
|
|
PRUint32 timestamp = GDK_CURRENT_TIME;
|
|
|
|
|
|
|
|
nsGTKToolkit* GTKToolkit = nsGTKToolkit::GetToolkit();
|
|
|
|
if (GTKToolkit)
|
|
|
|
timestamp = GTKToolkit->GetFocusTimestamp();
|
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
LOGFOCUS((" requesting toplevel activation [%p]\n", (void *)this));
|
|
|
|
NS_ASSERTION(owningWindow->mWindowType != eWindowType_popup
|
|
|
|
|| mParent,
|
|
|
|
"Presenting an override-redirect window");
|
2012-02-16 02:23:34 -08:00
|
|
|
gtk_window_present_with_time(GTK_WINDOW(owningWindow->mShell), timestamp);
|
|
|
|
|
|
|
|
if (GTKToolkit)
|
|
|
|
GTKToolkit->SetFocusTimestamp(0);
|
2010-06-02 20:50:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
// aRaise == false means that keyboard events should be dispatched
|
2010-06-02 20:50:49 -07:00
|
|
|
// from this widget.
|
|
|
|
|
|
|
|
// Ensure owningWidget is the focused GtkWidget within its toplevel window.
|
|
|
|
//
|
|
|
|
// For eWindowType_popup, this GtkWidget may not actually be the one that
|
|
|
|
// receives the key events as it may be the parent window that is active.
|
|
|
|
if (!gtk_widget_is_focus(owningWidget)) {
|
|
|
|
// This is synchronous. It takes focus from a plugin or from a widget
|
|
|
|
// in an embedder. The focus manager already knows that this window
|
|
|
|
// is active so gBlockActivateEvent avoids another (unnecessary)
|
|
|
|
// NS_ACTIVATE event.
|
2011-10-03 00:56:21 -07:00
|
|
|
gBlockActivateEvent = true;
|
2010-06-02 20:50:49 -07:00
|
|
|
gtk_widget_grab_focus(owningWidget);
|
2011-10-03 00:56:21 -07:00
|
|
|
gBlockActivateEvent = false;
|
2010-06-02 20:50:49 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If this is the widget that already has focus, return.
|
|
|
|
if (gFocusWindow == this) {
|
|
|
|
LOGFOCUS((" already have focus [%p]\n", (void *)this));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// Set this window to be the focused child window
|
2007-03-22 10:30:00 -07:00
|
|
|
gFocusWindow = this;
|
|
|
|
|
2010-03-18 21:21:16 -07:00
|
|
|
if (mIMModule) {
|
|
|
|
mIMModule->OnFocusWindow(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-22 18:18:39 -07:00
|
|
|
LOGFOCUS((" widget now has focus in SetFocus() [%p]\n",
|
2007-03-22 10:30:00 -07:00
|
|
|
(void *)this));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-14 19:27:09 -08:00
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-27 06:38:04 -07:00
|
|
|
if (mIsTopLevel && mContainer) {
|
|
|
|
// use the point including window decorations
|
|
|
|
gint x, y;
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_get_root_origin(gtk_widget_get_window(GTK_WIDGET(mContainer)), &x, &y);
|
2010-07-27 06:38:04 -07:00
|
|
|
aRect.MoveTo(x, y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRect.MoveTo(WidgetToScreenOffset());
|
|
|
|
}
|
2011-07-07 20:14:27 -07:00
|
|
|
// mBounds.Size() is the window bounds, not the window-manager frame
|
|
|
|
// bounds (bug 581863). gdk_window_get_frame_extents would give the
|
|
|
|
// frame bounds, but mBounds.Size() is returned here for consistency
|
|
|
|
// with Resize.
|
2010-07-27 06:38:04 -07:00
|
|
|
aRect.SizeTo(mBounds.Size());
|
2011-07-07 20:14:27 -07:00
|
|
|
LOG(("GetScreenBounds %d,%d | %dx%d\n",
|
|
|
|
aRect.x, aRect.y, aRect.width, aRect.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetClientBounds(nsIntRect &aRect)
|
|
|
|
{
|
|
|
|
// GetBounds returns a rect whose top left represents the top left of the
|
|
|
|
// outer bounds, but whose width/height represent the size of the inner
|
|
|
|
// bounds (which is messed up).
|
|
|
|
GetBounds(aRect);
|
|
|
|
aRect.MoveBy(GetClientOffset());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
|
|
|
nsWindow::GetClientOffset()
|
|
|
|
{
|
|
|
|
if (!mIsTopLevel) {
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL);
|
|
|
|
|
|
|
|
GdkAtom type_returned;
|
|
|
|
int format_returned;
|
|
|
|
int length_returned;
|
|
|
|
long *frame_extents;
|
2012-05-27 15:39:57 -07:00
|
|
|
GdkWindow* window;
|
2011-12-01 13:35:42 -08:00
|
|
|
|
2012-05-27 15:39:57 -07:00
|
|
|
if (!mShell || !(window = gtk_widget_get_window(mShell)) ||
|
|
|
|
!gdk_property_get(window,
|
2011-12-01 13:35:42 -08:00
|
|
|
gdk_atom_intern ("_NET_FRAME_EXTENTS", FALSE),
|
|
|
|
cardinal_atom,
|
|
|
|
0, // offset
|
|
|
|
4*4, // length
|
|
|
|
FALSE, // delete
|
|
|
|
&type_returned,
|
|
|
|
&format_returned,
|
|
|
|
&length_returned,
|
|
|
|
(guchar **) &frame_extents) ||
|
|
|
|
length_returned/sizeof(glong) != 4) {
|
|
|
|
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// data returned is in the order left, right, top, bottom
|
|
|
|
PRInt32 left = PRInt32(frame_extents[0]);
|
|
|
|
PRInt32 top = PRInt32(frame_extents[2]);
|
|
|
|
|
|
|
|
g_free(frame_extents);
|
|
|
|
|
|
|
|
return nsIntPoint(left, top);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetForegroundColor(const nscolor &aColor)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetBackgroundColor(const nscolor &aColor)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
|
|
|
// if we're not the toplevel window pass up the cursor request to
|
|
|
|
// the toplevel window to handle it.
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mContainer && mGdkWindow) {
|
2009-02-19 18:07:08 -08:00
|
|
|
nsWindow *window = GetContainerWindow();
|
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return window->SetCursor(aCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only change cursor if it's actually been changed
|
|
|
|
if (aCursor != mCursor) {
|
|
|
|
GdkCursor *newCursor = NULL;
|
|
|
|
|
|
|
|
newCursor = get_gtk_cursor(aCursor);
|
|
|
|
|
|
|
|
if (nsnull != newCursor) {
|
|
|
|
mCursor = aCursor;
|
|
|
|
|
|
|
|
if (!mContainer)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(mContainer)), newCursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(imgIContainer* aCursor,
|
|
|
|
PRUint32 aHotspotX, PRUint32 aHotspotY)
|
|
|
|
{
|
|
|
|
// if we're not the toplevel window pass up the cursor request to
|
|
|
|
// the toplevel window to handle it.
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mContainer && mGdkWindow) {
|
2009-02-19 18:07:08 -08:00
|
|
|
nsWindow *window = GetContainerWindow();
|
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return window->SetCursor(aCursor, aHotspotX, aHotspotY);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCursor = nsCursor(-1);
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
// Get the image's current frame
|
|
|
|
GdkPixbuf* pixbuf = nsImageToPixbuf::ImageToPixbuf(aCursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!pixbuf)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
int width = gdk_pixbuf_get_width(pixbuf);
|
|
|
|
int height = gdk_pixbuf_get_height(pixbuf);
|
|
|
|
// Reject cursors greater than 128 pixels in some direction, to prevent
|
|
|
|
// spoofing.
|
|
|
|
// XXX ideally we should rescale. Also, we could modify the API to
|
|
|
|
// allow trusted content to set larger cursors.
|
2007-10-10 05:21:29 -07:00
|
|
|
if (width > 128 || height > 128) {
|
2009-02-02 09:49:58 -08:00
|
|
|
g_object_unref(pixbuf);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2007-10-10 05:21:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Looks like all cursors need an alpha channel (tested on Gtk 2.4.4). This
|
|
|
|
// is of course not documented anywhere...
|
|
|
|
// So add one if there isn't one yet
|
|
|
|
if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
|
|
|
|
GdkPixbuf* alphaBuf = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
|
2009-02-02 09:49:58 -08:00
|
|
|
g_object_unref(pixbuf);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!alphaBuf) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
pixbuf = alphaBuf;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkCursor* cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
|
|
|
|
pixbuf,
|
|
|
|
aHotspotX, aHotspotY);
|
2009-02-02 09:49:58 -08:00
|
|
|
g_object_unref(pixbuf);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (cursor) {
|
|
|
|
if (mContainer) {
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(mContainer)), cursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
gdk_cursor_unref(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-23 19:52:21 -08:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-01 18:03:12 -08:00
|
|
|
if (!mGdkWindow)
|
2009-07-26 18:28:05 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 18:28:05 -07:00
|
|
|
GdkRectangle rect;
|
2007-03-22 10:30:00 -07:00
|
|
|
rect.x = aRect.x;
|
|
|
|
rect.y = aRect.y;
|
|
|
|
rect.width = aRect.width;
|
|
|
|
rect.height = aRect.height;
|
|
|
|
|
2011-12-23 19:52:21 -08:00
|
|
|
LOGDRAW(("Invalidate (rect) [%p]: %d %d %d %d\n", (void *)this,
|
|
|
|
rect.x, rect.y, rect.width, rect.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_invalidate_rect(mGdkWindow, &rect, FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
return mGdkWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
return SetupPluginPort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_DISPLAY:
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2011-09-22 13:58:07 -07:00
|
|
|
return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
2008-08-06 13:48:55 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC: {
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2011-10-25 08:05:32 -07:00
|
|
|
nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
|
|
|
|
NS_ASSERTION(nsnull != toolkit, "NULL toolkit, unable to get a GC");
|
|
|
|
return toolkit->GetSharedGC();
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_SHELLWIDGET:
|
|
|
|
return (void *) mShell;
|
|
|
|
|
2011-08-31 12:01:38 -07:00
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW:
|
|
|
|
return (void *) GDK_WINDOW_XID(gdk_window_get_toplevel(mGdkWindow));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// convert the string into utf8 and set the title.
|
|
|
|
#define UTF8_FOLLOWBYTE(ch) (((ch) & 0xC0) == 0x80)
|
|
|
|
NS_ConvertUTF16toUTF8 titleUTF8(aTitle);
|
|
|
|
if (titleUTF8.Length() > NS_WINDOW_TITLE_MAX_LENGTH) {
|
|
|
|
// Truncate overlong titles (bug 167315). Make sure we chop after a
|
|
|
|
// complete sequence by making sure the next char isn't a follow-byte.
|
|
|
|
PRUint32 len = NS_WINDOW_TITLE_MAX_LENGTH;
|
|
|
|
while(UTF8_FOLLOWBYTE(titleUTF8[len]))
|
|
|
|
--len;
|
|
|
|
titleUTF8.Truncate(len);
|
|
|
|
}
|
|
|
|
gtk_window_set_title(GTK_WINDOW(mShell), (const char *)titleUTF8.get());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
nsCAutoString iconName;
|
|
|
|
|
|
|
|
if (aIconSpec.EqualsLiteral("default")) {
|
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
|
|
|
AppendUTF16toUTF8(brandName, iconName);
|
|
|
|
ToLowerCase(iconName);
|
|
|
|
} else {
|
|
|
|
AppendUTF16toUTF8(aIconSpec, iconName);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsILocalFile> iconFile;
|
|
|
|
nsCAutoString path;
|
|
|
|
|
2012-01-10 18:41:28 -08:00
|
|
|
gint *iconSizes =
|
|
|
|
gtk_icon_theme_get_icon_sizes(gtk_icon_theme_get_default(),
|
|
|
|
iconName.get());
|
|
|
|
bool foundIcon = (iconSizes[0] != 0);
|
|
|
|
g_free(iconSizes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
if (!foundIcon) {
|
|
|
|
// Look for icons with the following suffixes appended to the base name
|
|
|
|
// The last two entries (for the old XPM format) will be ignored unless
|
|
|
|
// no icons are found using other suffixes. XPM icons are deprecated.
|
2008-01-09 22:04:51 -08:00
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
|
|
|
|
".xpm", "16.xpm" };
|
2008-01-09 22:04:51 -08:00
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(extensions); i++) {
|
|
|
|
// Don't bother looking for XPM versions if we found a PNG.
|
|
|
|
if (i == ArrayLength(extensions) - 2 && foundIcon)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
|
|
|
|
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
|
|
|
GdkPixbuf *icon = gdk_pixbuf_new_from_file(path.get(), NULL);
|
|
|
|
if (icon){
|
|
|
|
gtk_icon_theme_add_builtin_icon(iconName.get(),
|
|
|
|
gdk_pixbuf_get_height(icon),
|
|
|
|
icon);
|
|
|
|
g_object_unref(icon);
|
|
|
|
foundIcon = true;
|
|
|
|
}
|
|
|
|
}
|
2008-01-09 22:04:51 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// leave the default icon intact if no matching icons were found
|
2011-12-14 02:22:15 -08:00
|
|
|
if (foundIcon) {
|
|
|
|
gtk_window_set_icon_name(GTK_WINDOW(mShell), iconName.get());
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:22:15 -08:00
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
gint x = 0, y = 0;
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
if (mGdkWindow) {
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_get_origin(mGdkWindow, &x, &y);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
return nsIntPoint(x, y);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::EnableDragDrop(bool aEnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::CaptureMouse(bool aCapture)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *widget = GetMozContainerWidget();
|
2009-02-19 18:07:08 -08:00
|
|
|
if (!widget)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aCapture) {
|
|
|
|
gtk_grab_add(widget);
|
2012-02-13 12:19:59 -08:00
|
|
|
GrabPointer(GetLastUserInputTime());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ReleaseGrabs();
|
|
|
|
gtk_grab_remove(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoCapture,
|
|
|
|
bool aConsumeRollupEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *widget = GetMozContainerWidget();
|
2009-02-19 18:07:08 -08:00
|
|
|
if (!widget)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOG(("CaptureRollupEvents %p\n", (void *)this));
|
|
|
|
|
|
|
|
if (aDoCapture) {
|
2008-01-14 01:40:45 -08:00
|
|
|
gConsumeRollupEvent = aConsumeRollupEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
gRollupListener = aListener;
|
2007-07-08 00:08:04 -07:00
|
|
|
gRollupWindow = do_GetWeakReference(static_cast<nsIWidget*>
|
|
|
|
(this));
|
2007-03-22 10:30:00 -07:00
|
|
|
// real grab is only done when there is no dragging
|
|
|
|
if (!nsWindow::DragInProgress()) {
|
|
|
|
gtk_grab_add(widget);
|
2012-02-13 12:19:59 -08:00
|
|
|
GrabPointer(GetLastUserInputTime());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!nsWindow::DragInProgress()) {
|
|
|
|
ReleaseGrabs();
|
|
|
|
}
|
2011-02-16 12:10:54 -08:00
|
|
|
// There may not have been a drag in process when aDoCapture was set,
|
|
|
|
// so make sure to remove any added grab. This is a no-op if the grab
|
|
|
|
// was not added to this widget.
|
|
|
|
gtk_grab_remove(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
gRollupListener = nsnull;
|
|
|
|
gRollupWindow = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetAttention(PRInt32 aCycleCount)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
|
|
|
|
|
|
|
GtkWidget* top_window = nsnull;
|
|
|
|
GtkWidget* top_focused_window = nsnull;
|
|
|
|
GetToplevelWidget(&top_window);
|
|
|
|
if (gFocusWindow)
|
|
|
|
gFocusWindow->GetToplevelWidget(&top_focused_window);
|
|
|
|
|
|
|
|
// Don't get attention if the window is focused anyway.
|
2011-09-22 13:58:07 -07:00
|
|
|
if (top_window && (gtk_widget_get_visible(top_window)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
top_window != top_focused_window) {
|
2011-10-03 00:56:21 -07:00
|
|
|
SetUrgencyHint(top_window, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-04-21 16:53:52 -07:00
|
|
|
nsWindow::HasPendingInputEvent()
|
|
|
|
{
|
|
|
|
// This sucks, but gtk/gdk has no way to answer the question we want while
|
|
|
|
// excluding paint events, and there's no X API that will let us peek
|
|
|
|
// without blocking or removing. To prevent event reordering, peek
|
|
|
|
// anything except expose events. Reordering expose and others should be
|
|
|
|
// ok, hopefully.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveEvent;
|
2009-04-21 16:53:52 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
XEvent ev;
|
2011-09-22 13:58:07 -07:00
|
|
|
Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
2009-04-21 16:53:52 -07:00
|
|
|
haveEvent =
|
2011-09-22 13:58:07 -07:00
|
|
|
XCheckMaskEvent(display,
|
2009-04-21 16:53:52 -07:00
|
|
|
KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
|
|
|
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
|
|
|
|
PointerMotionMask | PointerMotionHintMask |
|
|
|
|
Button1MotionMask | Button2MotionMask |
|
|
|
|
Button3MotionMask | Button4MotionMask |
|
|
|
|
Button5MotionMask | ButtonMotionMask | KeymapStateMask |
|
|
|
|
VisibilityChangeMask | StructureNotifyMask |
|
|
|
|
ResizeRedirectMask | SubstructureNotifyMask |
|
|
|
|
SubstructureRedirectMask | FocusChangeMask |
|
|
|
|
PropertyChangeMask | ColormapChangeMask |
|
|
|
|
OwnerGrabButtonMask, &ev);
|
|
|
|
if (haveEvent) {
|
2011-09-22 13:58:07 -07:00
|
|
|
XPutBackEvent(display, &ev);
|
2009-04-21 16:53:52 -07:00
|
|
|
}
|
|
|
|
#else
|
2011-10-03 00:56:21 -07:00
|
|
|
haveEvent = false;
|
2009-04-21 16:53:52 -07:00
|
|
|
#endif
|
|
|
|
return haveEvent;
|
|
|
|
}
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
#if 0
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2008-08-27 19:04:06 -07:00
|
|
|
// Paint flashing code (disabled for cairo - see below)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define CAPS_LOCK_IS_ON \
|
2012-02-21 23:34:31 -08:00
|
|
|
(KeymapWrapper::AreModifiersCurrentlyActive(KeymapWrapper::CAPS_LOCK))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define WANT_PAINT_FLASHING \
|
|
|
|
(debug_WantPaintFlashing() && CAPS_LOCK_IS_ON)
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
static void
|
|
|
|
gdk_window_flash(GdkWindow * aGdkWindow,
|
|
|
|
unsigned int aTimes,
|
|
|
|
unsigned int aInterval, // Milliseconds
|
|
|
|
GdkRegion * aRegion)
|
|
|
|
{
|
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
guint i;
|
|
|
|
GdkGC * gc = 0;
|
|
|
|
GdkColor white;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
gdk_window_get_geometry(aGdkWindow,NULL,NULL,&width,&height,NULL);
|
|
|
|
#else
|
|
|
|
gdk_window_get_geometry(aGdkWindow,NULL,NULL,&width,&height);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gdk_window_get_origin (aGdkWindow,
|
|
|
|
&x,
|
|
|
|
&y);
|
|
|
|
|
|
|
|
gc = gdk_gc_new(GDK_ROOT_PARENT());
|
|
|
|
|
|
|
|
white.pixel = WhitePixel(gdk_display,DefaultScreen(gdk_display));
|
|
|
|
|
|
|
|
gdk_gc_set_foreground(gc,&white);
|
|
|
|
gdk_gc_set_function(gc,GDK_XOR);
|
|
|
|
gdk_gc_set_subwindow(gc,GDK_INCLUDE_INFERIORS);
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gdk_region_offset(aRegion, x, y);
|
|
|
|
gdk_gc_set_clip_region(gc, aRegion);
|
|
|
|
|
|
|
|
/*
|
2009-02-27 17:47:40 -08:00
|
|
|
* Need to do this twice so that the XOR effect can replace
|
2007-03-22 10:30:00 -07:00
|
|
|
* the original window contents.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < aTimes * 2; i++)
|
|
|
|
{
|
|
|
|
gdk_draw_rectangle(GDK_ROOT_PARENT(),
|
|
|
|
gc,
|
|
|
|
TRUE,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
|
|
|
|
gdk_flush();
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_Sleep(PR_MillisecondsToInterval(aInterval));
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_gc_destroy(gc);
|
|
|
|
|
|
|
|
gdk_region_offset(aRegion, -x, -y);
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // DEBUG
|
2008-08-27 19:04:06 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-25 22:26:37 -08:00
|
|
|
static void
|
|
|
|
DispatchDidPaint(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-03 00:56:21 -07:00
|
|
|
nsPaintEvent didPaintEvent(true, NS_DID_PAINT, aWidget);
|
2011-01-25 22:26:37 -08:00
|
|
|
aWidget->DispatchEvent(&didPaintEvent, status);
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
gboolean
|
|
|
|
nsWindow::OnExposeEvent(GdkEventExpose *aEvent)
|
|
|
|
#else
|
2007-03-22 10:30:00 -07:00
|
|
|
gboolean
|
2011-09-22 13:58:07 -07:00
|
|
|
nsWindow::OnExposeEvent(cairo_t *cr)
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mIsDestroyed) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
// Windows that are not visible will be painted after they become visible.
|
|
|
|
if (!mGdkWindow || mIsFullyObscured || !mHasMappedToplevel)
|
2007-03-22 10:30:00 -07:00
|
|
|
return FALSE;
|
|
|
|
|
2011-01-25 22:26:37 -08:00
|
|
|
// Dispatch WILL_PAINT to allow scripts etc. to run before we
|
|
|
|
// dispatch PAINT
|
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-03 00:56:21 -07:00
|
|
|
nsPaintEvent willPaintEvent(true, NS_WILL_PAINT, this);
|
|
|
|
willPaintEvent.willSendDidPaint = true;
|
2011-01-25 22:26:37 -08:00
|
|
|
DispatchEvent(&willPaintEvent, status);
|
2011-05-01 13:33:16 -07:00
|
|
|
|
|
|
|
// If the window has been destroyed during WILL_PAINT, there is
|
|
|
|
// nothing left to do.
|
|
|
|
if (!mGdkWindow)
|
|
|
|
return TRUE;
|
2011-01-25 22:26:37 -08:00
|
|
|
}
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
|
|
|
event.willSendDidPaint = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
GdkRectangle *rects;
|
|
|
|
gint nrects;
|
|
|
|
gdk_region_get_rectangles(aEvent->region, &rects, &nrects);
|
2007-07-11 17:59:37 -07:00
|
|
|
if (NS_UNLIKELY(!rects)) // OOM
|
|
|
|
return FALSE;
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
#ifdef cairo_copy_clip_rectangle_list
|
|
|
|
#error "Looks like we're including Mozilla's cairo instead of system cairo"
|
|
|
|
#else
|
|
|
|
cairo_rectangle_list_t *rects;
|
|
|
|
rects = cairo_copy_clip_rectangle_list(cr);
|
|
|
|
if (NS_UNLIKELY(rects->status != CAIRO_STATUS_SUCCESS)) {
|
|
|
|
NS_WARNING("Failed to obtain cairo rectangle list.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2007-07-11 17:59:37 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
// GTK3 TODO?
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-02-15 17:10:24 -08:00
|
|
|
if (nrects > MAX_RECTS_IN_REGION) {
|
|
|
|
// Just use the bounding box
|
|
|
|
rects[0] = aEvent->area;
|
|
|
|
nrects = 1;
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif
|
2009-02-15 17:10:24 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOGDRAW(("sending expose event [%p] %p 0x%lx (rects follow):\n",
|
2011-09-22 13:58:07 -07:00
|
|
|
(void *)this, (void *)mGdkWindow,
|
|
|
|
gdk_x11_window_get_xid(mGdkWindow)));
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
GdkRectangle *r = rects;
|
2007-03-22 10:30:00 -07:00
|
|
|
GdkRectangle *r_end = rects + nrects;
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_rectangle_t *r = rects->rectangles;
|
|
|
|
cairo_rectangle_t *r_end = r + rects->num_rectangles;
|
|
|
|
#endif
|
|
|
|
for (; r < r_end; ++r) {
|
2010-03-01 00:03:49 -08:00
|
|
|
event.region.Or(event.region, nsIntRect(r->x, r->y, r->width, r->height));
|
2007-03-22 10:30:00 -07:00
|
|
|
LOGDRAW(("\t%d %d %d %d\n", r->x, r->y, r->width, r->height));
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:26:37 -08:00
|
|
|
// Our bounds may have changed after dispatching WILL_PAINT. Clip
|
|
|
|
// to the new bounds here. The event region is relative to this
|
|
|
|
// window.
|
|
|
|
event.region.And(event.region,
|
|
|
|
nsIntRect(0, 0, mBounds.width, mBounds.height));
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool translucent = eTransparencyTransparent == GetTransparencyMode();
|
2009-07-21 17:44:55 -07:00
|
|
|
if (!translucent) {
|
|
|
|
GList *children =
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_peek_children(mGdkWindow);
|
2009-07-21 17:44:55 -07:00
|
|
|
while (children) {
|
|
|
|
GdkWindow *gdkWin = GDK_WINDOW(children->data);
|
|
|
|
nsWindow *kid = get_window_for_gdk_window(gdkWin);
|
2009-07-23 19:08:07 -07:00
|
|
|
if (kid && gdk_window_is_visible(gdkWin)) {
|
2009-07-21 17:44:55 -07:00
|
|
|
nsAutoTArray<nsIntRect,1> clipRects;
|
|
|
|
kid->GetWindowClipRegion(&clipRects);
|
|
|
|
nsIntRect bounds;
|
|
|
|
kid->GetBounds(bounds);
|
|
|
|
for (PRUint32 i = 0; i < clipRects.Length(); ++i) {
|
|
|
|
nsIntRect r = clipRects[i] + bounds.TopLeft();
|
2010-03-01 00:03:49 -08:00
|
|
|
event.region.Sub(event.region, r);
|
2009-07-21 17:44:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
children = children->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
if (event.region.IsEmpty()) {
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-07-21 17:44:55 -07:00
|
|
|
g_free(rects);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_rectangle_list_destroy(rects);
|
|
|
|
#endif
|
2009-07-21 17:44:55 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-05-04 10:07:34 -07:00
|
|
|
// If this widget uses OMTC...
|
|
|
|
if (GetLayerManager()->AsShadowForwarder() && GetLayerManager()->AsShadowForwarder()->HasShadowManager()) {
|
|
|
|
nsEventStatus status;
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(GetThebesSurface());
|
|
|
|
#else
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(GetThebesSurface(cr));
|
|
|
|
#endif
|
|
|
|
nsBaseWidget::AutoLayerManagerSetup
|
|
|
|
setupLayerManager(this, ctx, BasicLayerManager::BUFFER_NONE);
|
|
|
|
DispatchEvent(&event, status);
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2012-05-04 10:07:34 -07:00
|
|
|
g_free(rects);
|
|
|
|
|
|
|
|
DispatchDidPaint(this);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} else if (GetLayerManager()->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
2011-03-25 08:03:35 -07:00
|
|
|
LayerManagerOGL *manager = static_cast<LayerManagerOGL*>(GetLayerManager());
|
2010-06-17 14:23:00 -07:00
|
|
|
manager->SetClippingRegion(event.region);
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2011-01-25 22:26:37 -08:00
|
|
|
|
2010-06-17 14:23:00 -07:00
|
|
|
g_free(rects);
|
2011-01-25 22:26:37 -08:00
|
|
|
|
|
|
|
DispatchDidPaint(this);
|
|
|
|
|
2010-06-17 14:23:00 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2010-03-01 00:03:49 -08:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(GetThebesSurface());
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(GetThebesSurface(cr));
|
|
|
|
#endif
|
2008-08-06 13:48:55 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2010-07-15 14:08:09 -07:00
|
|
|
nsIntRect boundsRect; // for translucent only
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ctx->NewPath();
|
|
|
|
if (translucent) {
|
|
|
|
// Collapse update area to the bounding box. This is so we only have to
|
|
|
|
// call UpdateTranslucentWindowAlpha once. After we have dropped
|
|
|
|
// support for non-Thebes graphics, UpdateTranslucentWindowAlpha will be
|
|
|
|
// our private interface so we can rework things to avoid this.
|
2010-07-15 14:08:09 -07:00
|
|
|
boundsRect = event.region.GetBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
ctx->Rectangle(gfxRect(boundsRect.x, boundsRect.y,
|
|
|
|
boundsRect.width, boundsRect.height));
|
|
|
|
} else {
|
2011-01-25 22:26:37 -08:00
|
|
|
gfxUtils::PathFromRegion(ctx, event.region);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
ctx->Clip();
|
|
|
|
|
2010-07-15 14:08:09 -07:00
|
|
|
BasicLayerManager::BufferMode layerBuffering;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (translucent) {
|
2010-07-15 14:08:09 -07:00
|
|
|
// The double buffering is done here to extract the shape mask.
|
|
|
|
// (The shape mask won't be necessary when a visual with an alpha
|
|
|
|
// channel is used on compositing window managers.)
|
|
|
|
layerBuffering = BasicLayerManager::BUFFER_NONE;
|
2007-03-22 10:30:00 -07:00
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2010-09-23 18:00:06 -07:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
2010-10-26 21:56:31 -07:00
|
|
|
} else if (nsShmImage::UseShm()) {
|
2010-09-23 18:00:06 -07:00
|
|
|
// We're using an xshm mapping as a back buffer.
|
|
|
|
layerBuffering = BasicLayerManager::BUFFER_NONE;
|
|
|
|
#endif // MOZ_HAVE_SHMIMAGE
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-07-15 14:08:09 -07:00
|
|
|
// Get the layer manager to do double buffering (if necessary).
|
|
|
|
layerBuffering = BasicLayerManager::BUFFER_BUFFERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-06-15 19:13:52 -07:00
|
|
|
#if 0
|
2007-03-22 10:30:00 -07:00
|
|
|
// NOTE: Paint flashing region would be wrong for cairo, since
|
|
|
|
// cairo inflates the update region, etc. So don't paint flash
|
|
|
|
// for cairo.
|
2007-06-15 19:13:52 -07:00
|
|
|
#ifdef DEBUG
|
2011-01-25 22:26:37 -08:00
|
|
|
// XXX aEvent->region may refer to a newly-invalid area. FIXME
|
2011-09-22 13:58:07 -07:00
|
|
|
if (0 && WANT_PAINT_FLASHING && gtk_widget_get_window(aEvent))
|
|
|
|
gdk_window_flash(mGdkWindow, 1, 100, aEvent->region);
|
2007-06-15 19:13:52 -07:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif // MOZ_X11
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status;
|
2010-03-01 00:03:49 -08:00
|
|
|
{
|
2010-07-15 14:08:09 -07:00
|
|
|
AutoLayerManagerSetup setupLayerManager(this, ctx, layerBuffering);
|
2010-03-01 00:03:49 -08:00
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-04-29 17:46:47 -07:00
|
|
|
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
|
|
|
|
// operations below if that happened - it will lead to XError and exit().
|
2010-07-15 14:08:09 -07:00
|
|
|
if (translucent) {
|
|
|
|
if (NS_LIKELY(!mIsDestroyed)) {
|
|
|
|
if (status != nsEventStatus_eIgnore) {
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<gfxPattern> pattern = ctx->PopGroup();
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> img =
|
|
|
|
new gfxImageSurface(gfxIntSize(boundsRect.width, boundsRect.height),
|
|
|
|
gfxImageSurface::ImageFormatA8);
|
2007-07-11 17:59:37 -07:00
|
|
|
if (img && !img->CairoStatus()) {
|
|
|
|
img->SetDeviceOffset(gfxPoint(-boundsRect.x, -boundsRect.y));
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2007-07-11 17:59:37 -07:00
|
|
|
nsRefPtr<gfxContext> imgCtx = new gfxContext(img);
|
|
|
|
if (imgCtx) {
|
|
|
|
imgCtx->SetPattern(pattern);
|
|
|
|
imgCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
imgCtx->Paint();
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
UpdateTranslucentWindowAlphaInternal(nsIntRect(boundsRect.x, boundsRect.y,
|
|
|
|
boundsRect.width, boundsRect.height),
|
2007-07-11 17:59:37 -07:00
|
|
|
img->Data(), img->Stride());
|
|
|
|
}
|
2011-05-12 17:05:05 -07:00
|
|
|
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx->SetPattern(pattern);
|
|
|
|
ctx->Paint();
|
2007-04-29 17:46:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-29 17:46:47 -07:00
|
|
|
}
|
2010-09-23 18:00:06 -07:00
|
|
|
# ifdef MOZ_HAVE_SHMIMAGE
|
2010-10-26 21:56:31 -07:00
|
|
|
if (nsShmImage::UseShm() && NS_LIKELY(!mIsDestroyed)) {
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2010-09-23 18:00:06 -07:00
|
|
|
mShmImage->Put(mGdkWindow, rects, r_end);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
mShmImage->Put(mGdkWindow, rects);
|
|
|
|
#endif
|
2010-09-23 18:00:06 -07:00
|
|
|
}
|
|
|
|
# endif // MOZ_HAVE_SHMIMAGE
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif // MOZ_X11
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
g_free(rects);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_rectangle_list_destroy(rects);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-25 22:26:37 -08:00
|
|
|
DispatchDidPaint(this);
|
2010-07-15 14:08:08 -07:00
|
|
|
|
|
|
|
// Synchronously flush any new dirty areas
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2010-07-15 14:08:08 -07:00
|
|
|
GdkRegion* dirtyArea = gdk_window_get_update_area(mGdkWindow);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_region_t* dirtyArea = gdk_window_get_update_area(mGdkWindow);
|
|
|
|
#endif
|
|
|
|
|
2010-07-15 14:08:08 -07:00
|
|
|
if (dirtyArea) {
|
2011-10-03 00:56:21 -07:00
|
|
|
gdk_window_invalidate_region(mGdkWindow, dirtyArea, false);
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2010-07-15 14:08:08 -07:00
|
|
|
gdk_region_destroy(dirtyArea);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_region_destroy(dirtyArea);
|
|
|
|
#endif
|
2011-10-03 00:56:21 -07:00
|
|
|
gdk_window_process_updates(mGdkWindow, false);
|
2010-07-15 14:08:08 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// check the return value!
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
nsWindow::OnConfigureEvent(GtkWidget *aWidget, GdkEventConfigure *aEvent)
|
|
|
|
{
|
2011-07-07 20:14:27 -07:00
|
|
|
// These events are only received on toplevel windows.
|
|
|
|
//
|
|
|
|
// GDK ensures that the coordinates are the client window top-left wrt the
|
|
|
|
// root window.
|
|
|
|
//
|
|
|
|
// GDK calculates the cordinates for real ConfigureNotify events on
|
|
|
|
// managed windows (that would normally be relative to the parent
|
|
|
|
// window).
|
|
|
|
//
|
|
|
|
// Synthetic ConfigureNotify events are from the window manager and
|
|
|
|
// already relative to the root window. GDK creates all X windows with
|
|
|
|
// border_width = 0, so synthetic events also indicate the top-left of
|
|
|
|
// the client window.
|
|
|
|
//
|
|
|
|
// Override-redirect windows are children of the root window so parent
|
|
|
|
// coordinates are root coordinates.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG(("configure event [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aEvent->x, aEvent->y, aEvent->width, aEvent->height));
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
nsIntRect screenBounds;
|
|
|
|
GetScreenBounds(screenBounds);
|
2011-08-07 22:28:06 -07:00
|
|
|
|
2010-09-16 04:24:08 -07:00
|
|
|
if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog) {
|
2011-12-01 13:35:42 -08:00
|
|
|
// This check avoids unwanted rollup on spurious configure events from
|
|
|
|
// Cygwin/X (bug 672103).
|
|
|
|
if (mBounds.x != screenBounds.x ||
|
|
|
|
mBounds.y != screenBounds.y) {
|
2012-02-01 18:11:06 -08:00
|
|
|
check_for_rollup(0, 0, false, true);
|
2011-12-01 13:35:42 -08:00
|
|
|
}
|
2010-09-16 04:24:08 -07:00
|
|
|
}
|
|
|
|
|
2011-07-07 20:14:27 -07:00
|
|
|
// This event indicates that the window position may have changed.
|
|
|
|
// mBounds.Size() is updated in OnSizeAllocate().
|
|
|
|
|
|
|
|
// (The gtk_window_get_window_type() function is only available from
|
|
|
|
// version 2.20.)
|
|
|
|
NS_ASSERTION(GTK_IS_WINDOW(aWidget),
|
|
|
|
"Configure event on widget that is not a GtkWindow");
|
|
|
|
gint type;
|
|
|
|
g_object_get(aWidget, "type", &type, NULL);
|
|
|
|
if (type == GTK_WINDOW_POPUP) {
|
|
|
|
// Override-redirect window
|
|
|
|
//
|
|
|
|
// These windows should not be moved by the window manager, and so any
|
|
|
|
// change in position is a result of our direction. mBounds has
|
|
|
|
// already been set in Move() or Resize(), and that is more
|
|
|
|
// up-to-date than the position in the ConfigureNotify event if the
|
|
|
|
// event is from an earlier window move.
|
|
|
|
//
|
|
|
|
// Skipping the NS_MOVE dispatch saves context menus from an infinite
|
|
|
|
// loop when nsXULPopupManager::PopupMoved moves the window to the new
|
|
|
|
// position and nsMenuPopupFrame::SetPopupPosition adds
|
|
|
|
// offsetForContextMenu on each iteration.
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
mBounds.MoveTo(screenBounds.TopLeft());
|
2011-07-07 20:14:27 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_MOVE, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-07 20:14:27 -07:00
|
|
|
event.refPoint = mBounds.TopLeft();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX mozilla will invalidate the entire window after this move
|
|
|
|
// complete. wtf?
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:14:45 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnContainerUnrealize(GtkWidget *aWidget)
|
|
|
|
{
|
|
|
|
// The GdkWindows are about to be destroyed (but not deleted), so remove
|
|
|
|
// their references back to their container widget while the GdkWindow
|
|
|
|
// hierarchy is still available.
|
|
|
|
|
|
|
|
NS_ASSERTION(mContainer == MOZ_CONTAINER(aWidget),
|
|
|
|
"unexpected \"unrealize\" signal");
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (mGdkWindow) {
|
2009-11-10 13:57:25 -08:00
|
|
|
DestroyChildWindows();
|
2009-07-26 18:40:46 -07:00
|
|
|
|
|
|
|
g_object_set_data(G_OBJECT(mGdkWindow), "nsWindow", NULL);
|
|
|
|
mGdkWindow = NULL;
|
2009-05-14 19:14:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnSizeAllocate(GtkWidget *aWidget, GtkAllocation *aAllocation)
|
|
|
|
{
|
|
|
|
LOG(("size_allocate [%p] %d %d %d %d\n",
|
|
|
|
(void *)this, aAllocation->x, aAllocation->y,
|
|
|
|
aAllocation->width, aAllocation->height));
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect rect(aAllocation->x, aAllocation->y,
|
|
|
|
aAllocation->width, aAllocation->height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ResizeTransparencyBitmap(rect.width, rect.height);
|
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mTransparencyBitmap) {
|
|
|
|
ApplyTransparencyBitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent (rect, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDeleteEvent(GtkWidget *aWidget, GdkEventAny *aEvent)
|
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_XUL_CLOSE, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnEnterNotifyEvent(GtkWidget *aWidget, GdkEventCrossing *aEvent)
|
|
|
|
{
|
2010-03-23 20:37:06 -07:00
|
|
|
// This skips NotifyVirtual and NotifyNonlinearVirtual enter notify events
|
|
|
|
// when the pointer enters a child window. If the destination window is a
|
|
|
|
// Gecko window then we'll catch the corresponding event on that window,
|
|
|
|
// but we won't notice when the pointer directly enters a foreign (plugin)
|
|
|
|
// child window without passing over a visible portion of a Gecko window.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEvent->subwindow != NULL)
|
|
|
|
return;
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
// Check before is_parent_ungrab_enter() as the button state may have
|
|
|
|
// changed while a non-Gecko ancestor window had a pointer grab.
|
|
|
|
DispatchMissedButtonReleases(aEvent);
|
|
|
|
|
|
|
|
if (is_parent_ungrab_enter(aEvent))
|
|
|
|
return;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_ENTER, this, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
|
|
|
|
|
|
|
event.time = aEvent->time;
|
|
|
|
|
|
|
|
LOG(("OnEnterNotify: %p\n", (void *)this));
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
// XXX Is this the right test for embedding cases?
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-03-12 15:44:45 -07:00
|
|
|
is_top_level_mouse_exit(GdkWindow* aWindow, GdkEventCrossing *aEvent)
|
|
|
|
{
|
|
|
|
gint x = gint(aEvent->x_root);
|
|
|
|
gint y = gint(aEvent->y_root);
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkDisplay* display = gdk_window_get_display(aWindow);
|
2008-03-12 15:44:45 -07:00
|
|
|
GdkWindow* winAtPt = gdk_display_get_window_at_pointer(display, &x, &y);
|
|
|
|
if (!winAtPt)
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2008-03-12 15:44:45 -07:00
|
|
|
GdkWindow* topLevelAtPt = gdk_window_get_toplevel(winAtPt);
|
|
|
|
GdkWindow* topLevelWidget = gdk_window_get_toplevel(aWindow);
|
|
|
|
return topLevelAtPt != topLevelWidget;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnLeaveNotifyEvent(GtkWidget *aWidget, GdkEventCrossing *aEvent)
|
|
|
|
{
|
2010-03-23 20:37:06 -07:00
|
|
|
// This ignores NotifyVirtual and NotifyNonlinearVirtual leave notify
|
|
|
|
// events when the pointer leaves a child window. If the destination
|
|
|
|
// window is a Gecko window then we'll catch the corresponding event on
|
|
|
|
// that window.
|
|
|
|
//
|
|
|
|
// XXXkt However, we will miss toplevel exits when the pointer directly
|
|
|
|
// leaves a foreign (plugin) child window without passing over a visible
|
|
|
|
// portion of a Gecko window.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEvent->subwindow != NULL)
|
|
|
|
return;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_EXIT, this, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
|
|
|
|
|
|
|
event.time = aEvent->time;
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
event.exit = is_top_level_mouse_exit(mGdkWindow, aEvent)
|
2008-03-12 15:44:45 -07:00
|
|
|
? nsMouseEvent::eTopLevel : nsMouseEvent::eChild;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG(("OnLeaveNotify: %p\n", (void *)this));
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent)
|
|
|
|
{
|
|
|
|
// see if we can compress this event
|
2008-10-19 18:25:26 -07:00
|
|
|
// XXXldb Why skip every other motion event when we have multiple,
|
|
|
|
// but not more than that?
|
2011-09-28 23:19:26 -07:00
|
|
|
bool synthEvent = false;
|
2008-10-19 18:25:26 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
XEvent xevent;
|
2008-10-17 15:38:49 -07:00
|
|
|
|
2008-10-19 18:25:26 -07:00
|
|
|
while (XPending (GDK_WINDOW_XDISPLAY(aEvent->window))) {
|
|
|
|
XEvent peeked;
|
|
|
|
XPeekEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &peeked);
|
2011-09-22 13:58:07 -07:00
|
|
|
if (peeked.xany.window != gdk_x11_window_get_xid(aEvent->window)
|
2008-10-19 18:25:26 -07:00
|
|
|
|| peeked.type != MotionNotify)
|
2008-10-12 19:32:56 -07:00
|
|
|
break;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
synthEvent = true;
|
2008-10-19 18:25:26 -07:00
|
|
|
XNextEvent (GDK_WINDOW_XDISPLAY(aEvent->window), &xevent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
// if plugins still keeps the focus, get it back
|
|
|
|
if (gPluginFocusWindow && gPluginFocusWindow != this) {
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
gPluginFocusWindow->LoseNonXEmbedPluginFocus();
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif /* MOZ_WIDGET_GTK2 */
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_MOVE, this, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-11 15:55:15 -08:00
|
|
|
gdouble pressure = 0;
|
|
|
|
gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure);
|
|
|
|
// Sometime gdk generate 0 pressure value between normal values
|
|
|
|
// We have to ignore that and use last valid value
|
|
|
|
if (pressure)
|
|
|
|
mLastMotionPressure = pressure;
|
|
|
|
event.pressure = mLastMotionPressure;
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
guint modifierState;
|
2008-10-19 18:25:26 -07:00
|
|
|
if (synthEvent) {
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
event.refPoint.x = nscoord(xevent.xmotion.x);
|
|
|
|
event.refPoint.y = nscoord(xevent.xmotion.y);
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
modifierState = xevent.xmotion.state;
|
2008-10-19 18:25:26 -07:00
|
|
|
|
|
|
|
event.time = xevent.xmotion.time;
|
|
|
|
#else
|
2008-08-06 13:48:55 -07:00
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
modifierState = aEvent->state;
|
2008-10-19 18:25:26 -07:00
|
|
|
|
|
|
|
event.time = aEvent->time;
|
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-19 18:25:26 -07:00
|
|
|
else {
|
|
|
|
// XXX see OnScrollEvent()
|
2009-07-26 18:39:36 -07:00
|
|
|
if (aEvent->window == mGdkWindow) {
|
2008-10-19 18:25:26 -07:00
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
|
|
|
} else {
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
|
|
|
|
event.refPoint = point - WidgetToScreenOffset();
|
2008-10-19 18:25:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
modifierState = aEvent->state;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-19 18:25:26 -07:00
|
|
|
event.time = aEvent->time;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitInputEvent(event, modifierState);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
// If the automatic pointer grab on ButtonPress has deactivated before
|
|
|
|
// ButtonRelease, and the mouse button is released while the pointer is not
|
|
|
|
// over any a Gecko window, then the ButtonRelease event will not be received.
|
|
|
|
// (A similar situation exists when the pointer is grabbed with owner_events
|
|
|
|
// True as the ButtonRelease may be received on a foreign [plugin] window).
|
|
|
|
// Use this method to check for released buttons when the pointer returns to a
|
|
|
|
// Gecko window.
|
|
|
|
void
|
|
|
|
nsWindow::DispatchMissedButtonReleases(GdkEventCrossing *aGdkEvent)
|
|
|
|
{
|
|
|
|
guint changed = aGdkEvent->state ^ gButtonState;
|
|
|
|
// Only consider button releases.
|
|
|
|
// (Ignore button presses that occurred outside Gecko.)
|
|
|
|
guint released = changed & gButtonState;
|
|
|
|
gButtonState = aGdkEvent->state;
|
|
|
|
|
|
|
|
// Loop over each button, excluding mouse wheel buttons 4 and 5 for which
|
|
|
|
// GDK ignores releases.
|
|
|
|
for (guint buttonMask = GDK_BUTTON1_MASK;
|
|
|
|
buttonMask <= GDK_BUTTON3_MASK;
|
|
|
|
buttonMask <<= 1) {
|
|
|
|
|
|
|
|
if (released & buttonMask) {
|
|
|
|
PRInt16 buttonType;
|
|
|
|
switch (buttonMask) {
|
|
|
|
case GDK_BUTTON1_MASK:
|
|
|
|
buttonType = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
case GDK_BUTTON2_MASK:
|
|
|
|
buttonType = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(buttonMask == GDK_BUTTON3_MASK,
|
|
|
|
"Unexpected button mask");
|
|
|
|
buttonType = nsMouseEvent::eRightButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("Synthesized button %u release on %p\n",
|
|
|
|
guint(buttonType + 1), (void *)this));
|
|
|
|
|
|
|
|
// Dispatch a synthesized button up event to tell Gecko about the
|
|
|
|
// change in state. This event is marked as synthesized so that
|
|
|
|
// it is not dispatched as a DOM event, because we don't know the
|
|
|
|
// position, widget, modifiers, or time/order.
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent synthEvent(true, NS_MOUSE_BUTTON_UP, this,
|
2010-03-23 20:37:06 -07:00
|
|
|
nsMouseEvent::eSynthesized);
|
|
|
|
synthEvent.button = buttonType;
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&synthEvent, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-13 23:00:44 -08:00
|
|
|
void
|
|
|
|
nsWindow::InitButtonEvent(nsMouseEvent &aEvent,
|
|
|
|
GdkEventButton *aGdkEvent)
|
|
|
|
{
|
|
|
|
// XXX see OnScrollEvent()
|
2009-07-26 18:39:36 -07:00
|
|
|
if (aGdkEvent->window == mGdkWindow) {
|
2007-12-13 23:00:44 -08:00
|
|
|
aEvent.refPoint.x = nscoord(aGdkEvent->x);
|
|
|
|
aEvent.refPoint.y = nscoord(aGdkEvent->y);
|
|
|
|
} else {
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint point(NSToIntFloor(aGdkEvent->x_root), NSToIntFloor(aGdkEvent->y_root));
|
|
|
|
aEvent.refPoint = point - WidgetToScreenOffset();
|
2007-12-13 23:00:44 -08:00
|
|
|
}
|
|
|
|
|
2012-04-24 20:00:01 -07:00
|
|
|
guint modifierState = aGdkEvent->state;
|
|
|
|
// aEvent's state doesn't include this event's information. Therefore,
|
|
|
|
// if aEvent is mouse button down event, we need to set it manually.
|
|
|
|
// Note that we cannot do same thing for NS_MOUSE_BUTTON_UP because
|
|
|
|
// system may have two or more mice and same button of another mouse
|
|
|
|
// may be still pressed.
|
|
|
|
if (aGdkEvent->type != GDK_BUTTON_RELEASE) {
|
|
|
|
switch (aGdkEvent->button) {
|
|
|
|
case 1:
|
|
|
|
modifierState |= GDK_BUTTON1_MASK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
modifierState |= GDK_BUTTON2_MASK;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
modifierState |= GDK_BUTTON3_MASK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KeymapWrapper::InitInputEvent(aEvent, modifierState);
|
2007-12-13 23:00:44 -08:00
|
|
|
|
|
|
|
aEvent.time = aGdkEvent->time;
|
|
|
|
|
|
|
|
switch (aGdkEvent->type) {
|
|
|
|
case GDK_2BUTTON_PRESS:
|
|
|
|
aEvent.clickCount = 2;
|
|
|
|
break;
|
|
|
|
case GDK_3BUTTON_PRESS:
|
|
|
|
aEvent.clickCount = 3;
|
|
|
|
break;
|
|
|
|
// default is one click
|
|
|
|
default:
|
|
|
|
aEvent.clickCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
static guint ButtonMaskFromGDKButton(guint button)
|
|
|
|
{
|
|
|
|
return GDK_BUTTON1_MASK << (button - 1);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent)
|
|
|
|
{
|
2010-03-23 20:37:06 -07:00
|
|
|
LOG(("Button %u press on %p\n", aEvent->button, (void *)this));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
// If you double click in GDK, it will actually generate a second
|
|
|
|
// GDK_BUTTON_PRESS before sending the GDK_2BUTTON_PRESS, and this is
|
2007-03-22 10:30:00 -07:00
|
|
|
// different than the DOM spec. GDK puts this in the queue
|
|
|
|
// programatically, so it's safe to assume that if there's a
|
|
|
|
// double click in the queue, it was generated so we can just drop
|
|
|
|
// this click.
|
|
|
|
GdkEvent *peekedEvent = gdk_event_peek();
|
|
|
|
if (peekedEvent) {
|
|
|
|
GdkEventType type = peekedEvent->any.type;
|
|
|
|
gdk_event_free(peekedEvent);
|
|
|
|
if (type == GDK_2BUTTON_PRESS || type == GDK_3BUTTON_PRESS)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-19 18:07:08 -08:00
|
|
|
nsWindow *containerWindow = GetContainerWindow();
|
|
|
|
if (!gFocusWindow && containerWindow) {
|
2009-07-22 18:18:39 -07:00
|
|
|
containerWindow->DispatchActivateEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-14 01:40:45 -08:00
|
|
|
|
2009-07-22 18:18:39 -07:00
|
|
|
// check to see if we should rollup
|
2012-02-01 18:11:06 -08:00
|
|
|
bool rolledUp =
|
|
|
|
check_for_rollup(aEvent->x_root, aEvent->y_root, false, false);
|
2008-01-14 01:40:45 -08:00
|
|
|
if (gConsumeRollupEvent && rolledUp)
|
2010-09-16 04:24:08 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-11 15:55:15 -08:00
|
|
|
gdouble pressure = 0;
|
|
|
|
gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure);
|
|
|
|
mLastMotionPressure = pressure;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint16 domButton;
|
|
|
|
switch (aEvent->button) {
|
2007-07-25 14:26:16 -07:00
|
|
|
case 1:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case 2:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
2008-03-18 12:36:09 -07:00
|
|
|
// These are mapped to horizontal scroll
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseScrollEvent event(true, NS_MOUSE_SCROLL, this);
|
2008-12-11 15:55:15 -08:00
|
|
|
event.pressure = mLastMotionPressure;
|
2008-03-18 12:36:09 -07:00
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
|
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
2009-09-24 03:58:04 -07:00
|
|
|
// XXX Why is this delta value different from the scroll event?
|
2008-03-18 12:36:09 -07:00
|
|
|
event.delta = (aEvent->button == 6) ? -2 : 2;
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitInputEvent(event, aEvent->state);
|
2008-03-18 12:36:09 -07:00
|
|
|
|
|
|
|
event.time = aEvent->time;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Map buttons 8-9 to back/forward
|
2008-02-20 02:10:08 -08:00
|
|
|
case 8:
|
2011-10-14 11:11:22 -07:00
|
|
|
DispatchCommandEvent(nsGkAtoms::Back);
|
2008-02-20 02:10:08 -08:00
|
|
|
return;
|
|
|
|
case 9:
|
2011-10-14 11:11:22 -07:00
|
|
|
DispatchCommandEvent(nsGkAtoms::Forward);
|
2008-02-20 02:10:08 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
2007-07-25 14:26:16 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
gButtonState |= ButtonMaskFromGDKButton(aEvent->button);
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.button = domButton;
|
|
|
|
InitButtonEvent(event, aEvent);
|
2008-12-11 15:55:15 -08:00
|
|
|
event.pressure = mLastMotionPressure;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
// right menu click on linux should also pop up a context menu
|
2007-04-29 17:46:47 -07:00
|
|
|
if (domButton == nsMouseEvent::eRightButton &&
|
|
|
|
NS_LIKELY(!mIsDestroyed)) {
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eReal);
|
|
|
|
InitButtonEvent(contextMenuEvent, aEvent);
|
2008-12-11 15:55:15 -08:00
|
|
|
contextMenuEvent.pressure = mLastMotionPressure;
|
2007-03-22 10:30:00 -07:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnButtonReleaseEvent(GtkWidget *aWidget, GdkEventButton *aEvent)
|
|
|
|
{
|
2010-03-23 20:37:06 -07:00
|
|
|
LOG(("Button %u release on %p\n", aEvent->button, (void *)this));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint16 domButton;
|
|
|
|
switch (aEvent->button) {
|
2007-07-25 14:26:16 -07:00
|
|
|
case 1:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case 2:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
2007-07-25 14:26:16 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-23 20:37:06 -07:00
|
|
|
gButtonState &= ~ButtonMaskFromGDKButton(aEvent->button);
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.button = domButton;
|
|
|
|
InitButtonEvent(event, aEvent);
|
2008-12-11 15:55:15 -08:00
|
|
|
gdouble pressure = 0;
|
|
|
|
gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure);
|
|
|
|
event.pressure = pressure ? pressure : mLastMotionPressure;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2008-12-11 15:55:15 -08:00
|
|
|
mLastMotionPressure = pressure;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnContainerFocusInEvent(GtkWidget *aWidget, GdkEventFocus *aEvent)
|
|
|
|
{
|
2010-06-17 18:15:03 -07:00
|
|
|
NS_ASSERTION(mWindowType != eWindowType_popup,
|
|
|
|
"Unexpected focus on a popup window");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
LOGFOCUS(("OnContainerFocusInEvent [%p]\n", (void *)this));
|
|
|
|
|
|
|
|
// Unset the urgency hint, if possible
|
|
|
|
GtkWidget* top_window = nsnull;
|
|
|
|
GetToplevelWidget(&top_window);
|
2011-09-22 13:58:07 -07:00
|
|
|
if (top_window && (gtk_widget_get_visible(top_window)))
|
2011-10-03 00:56:21 -07:00
|
|
|
SetUrgencyHint(top_window, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-02 20:50:49 -07:00
|
|
|
// Return if being called within SetFocus because the focus manager
|
|
|
|
// already knows that the window is active.
|
|
|
|
if (gBlockActivateEvent) {
|
|
|
|
LOGFOCUS(("NS_ACTIVATE event is blocked [%p]\n", (void *)this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is not usually the correct window for dispatching key events,
|
|
|
|
// but the focus manager will call SetFocus to set the correct window if
|
|
|
|
// keyboard input will be accepted. Setting a non-NULL value here
|
|
|
|
// prevents OnButtonPressEvent() from dispatching NS_ACTIVATE if the
|
|
|
|
// widget is already active.
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
gFocusWindow = this;
|
2010-06-02 20:50:49 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
DispatchActivateEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnContainerFocusOutEvent(GtkWidget *aWidget, GdkEventFocus *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnContainerFocusOutEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-09-16 04:24:08 -07:00
|
|
|
if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog) {
|
2010-12-31 11:20:00 -08:00
|
|
|
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession;
|
|
|
|
dragService->GetCurrentSession(getter_AddRefs(dragSession));
|
|
|
|
|
|
|
|
// Rollup popups when a window is focused out unless a drag is occurring.
|
|
|
|
// This check is because drags grab the keyboard and cause a focus out on
|
|
|
|
// versions of GTK before 2.18.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldRollup = !dragSession;
|
2010-12-31 11:20:00 -08:00
|
|
|
if (!shouldRollup) {
|
|
|
|
// we also roll up when a drag is from a different application
|
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
|
|
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
|
|
|
|
shouldRollup = (sourceNode == nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldRollup) {
|
2012-02-01 18:11:06 -08:00
|
|
|
check_for_rollup(0, 0, false, true);
|
2010-12-31 11:20:00 -08:00
|
|
|
}
|
2010-09-16 04:24:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_X11)
|
2007-03-22 10:30:00 -07:00
|
|
|
// plugin lose focus
|
|
|
|
if (gPluginFocusWindow) {
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
gPluginFocusWindow->LoseNonXEmbedPluginFocus();
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif /* MOZ_X11 && MOZ_WIDGET_GTK2 */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 18:11:08 -07:00
|
|
|
if (gFocusWindow) {
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip = gFocusWindow;
|
|
|
|
if (gFocusWindow->mIMModule) {
|
|
|
|
gFocusWindow->mIMModule->OnBlurWindow(gFocusWindow);
|
|
|
|
}
|
|
|
|
gFocusWindow = nsnull;
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 18:11:08 -07:00
|
|
|
DispatchDeactivateEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-02-20 02:10:08 -08:00
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
2008-02-06 13:56:02 -08:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-14 11:11:22 -07:00
|
|
|
nsCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this);
|
2008-02-06 13:56:02 -08:00
|
|
|
DispatchEvent(&event, status);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-07-13 18:58:07 -07:00
|
|
|
nsWindow::DispatchContentCommandEvent(PRInt32 aMsg)
|
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-03 00:56:21 -07:00
|
|
|
nsContentCommandEvent event(true, aMsg, this);
|
2011-07-13 18:58:07 -07:00
|
|
|
DispatchEvent(&event, status);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-03-18 21:21:16 -07:00
|
|
|
IsCtrlAltTab(GdkEventKey *aEvent)
|
|
|
|
{
|
|
|
|
return aEvent->keyval == GDK_Tab &&
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::AreModifiersActive(
|
|
|
|
KeymapWrapper::CTRL | KeymapWrapper::ALT, aEvent->state);
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsWindow::DispatchKeyDownEvent(GdkEventKey *aEvent, bool *aCancelled)
|
2010-03-18 21:21:16 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aCancelled, "aCancelled must not be null");
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
*aCancelled = false;
|
2010-03-18 21:21:16 -07:00
|
|
|
|
|
|
|
if (IsCtrlAltTab(aEvent)) {
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// send the key down event
|
|
|
|
nsEventStatus status;
|
2011-10-03 00:56:21 -07:00
|
|
|
nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitKeyEvent(downEvent, aEvent);
|
2010-03-18 21:21:16 -07:00
|
|
|
DispatchEvent(&downEvent, status);
|
|
|
|
*aCancelled = (status == nsEventStatus_eConsumeNoDefault);
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gboolean
|
2008-05-05 16:44:18 -07:00
|
|
|
nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
|
|
|
// if we are in the middle of composing text, XIM gets to see it
|
|
|
|
// before mozilla does.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IMEWasEnabled = false;
|
2011-01-14 05:40:08 -08:00
|
|
|
if (mIMModule) {
|
|
|
|
IMEWasEnabled = mIMModule->IsEnabled();
|
|
|
|
if (mIMModule->OnKeyEvent(this, aEvent)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
|
|
|
|
// work around for annoying things.
|
2010-03-18 21:21:16 -07:00
|
|
|
if (IsCtrlAltTab(aEvent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
|
|
|
|
2010-10-06 22:57:53 -07:00
|
|
|
// Dispatch keydown event always. At auto repeating, we should send
|
|
|
|
// KEYDOWN -> KEYPRESS -> KEYDOWN -> KEYPRESS ... -> KEYUP
|
|
|
|
// However, old distributions (e.g., Ubuntu 9.10) sent native key
|
|
|
|
// release event, so, on such platform, the DOM events will be:
|
|
|
|
// KEYDOWN -> KEYPRESS -> KEYUP -> KEYDOWN -> KEYPRESS -> KEYUP...
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isKeyDownCancelled = false;
|
2010-03-18 21:21:16 -07:00
|
|
|
if (DispatchKeyDownEvent(aEvent, &isKeyDownCancelled) &&
|
|
|
|
NS_UNLIKELY(mIsDestroyed)) {
|
|
|
|
return TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-14 05:40:08 -08:00
|
|
|
// If a keydown event handler causes to enable IME, i.e., it moves
|
|
|
|
// focus from IME unusable content to IME usable editor, we should
|
|
|
|
// send the native key event to IME for the first input on the editor.
|
|
|
|
if (!IMEWasEnabled && mIMModule && mIMModule->IsEnabled()) {
|
|
|
|
// Notice our keydown event was already dispatched. This prevents
|
|
|
|
// unnecessary DOM keydown event in the editor.
|
2011-10-03 00:56:21 -07:00
|
|
|
if (mIMModule->OnKeyEvent(this, aEvent, true)) {
|
2011-01-14 05:40:08 -08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't pass modifiers as NS_KEY_PRESS events.
|
|
|
|
// TODO: Instead of selectively excluding some keys from NS_KEY_PRESS events,
|
|
|
|
// we should instead selectively include (as per MSDN spec; no official
|
|
|
|
// spec covers KeyPress events).
|
2012-02-21 23:34:31 -08:00
|
|
|
if (!KeymapWrapper::IsKeyPressEventNecessary(aEvent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-02-06 13:56:02 -08:00
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-03-28 08:50:39 -07:00
|
|
|
#if ! defined AIX // no XFree86 on AIX 5L
|
2008-02-06 13:56:02 -08:00
|
|
|
// Look for specialized app-command keys
|
|
|
|
switch (aEvent->keyval) {
|
|
|
|
case XF86XK_Back:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_Forward:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_Refresh:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Reload);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_Stop:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Stop);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_Search:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Search);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_Favorites:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Bookmarks);
|
2008-02-06 13:56:02 -08:00
|
|
|
case XF86XK_HomePage:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Home);
|
2011-07-13 18:58:07 -07:00
|
|
|
case XF86XK_Copy:
|
|
|
|
case GDK_F16: // F16, F20, F18, F14 are old keysyms for Copy Cut Paste Undo
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_COPY);
|
|
|
|
case XF86XK_Cut:
|
|
|
|
case GDK_F20:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_CUT);
|
|
|
|
case XF86XK_Paste:
|
|
|
|
case GDK_F18:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_PASTE);
|
|
|
|
case GDK_Redo:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
|
|
|
|
case GDK_Undo:
|
|
|
|
case GDK_F14:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
2008-02-06 13:56:02 -08:00
|
|
|
}
|
2010-03-28 08:50:39 -07:00
|
|
|
#endif /* ! AIX */
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2008-02-06 13:56:02 -08:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitKeyEvent(event, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isKeyDownCancelled) {
|
|
|
|
// If prevent default set for onkeydown, do the same for onkeypress
|
|
|
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// before we dispatch a key, check if it's the context menu key.
|
|
|
|
// If so, send a context menu key event instead.
|
|
|
|
if (is_context_menu_key(event)) {
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2008-02-20 02:04:56 -08:00
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
2012-02-21 23:34:31 -08:00
|
|
|
|
|
|
|
contextMenuEvent.refPoint = nsIntPoint(0, 0);
|
|
|
|
contextMenuEvent.time = aEvent->time;
|
|
|
|
contextMenuEvent.clickCount = 1;
|
|
|
|
KeymapWrapper::InitInputEvent(contextMenuEvent, aEvent->state);
|
2007-03-22 10:30:00 -07:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
else {
|
2010-07-04 05:42:04 -07:00
|
|
|
// If the character code is in the BMP, send the key press event.
|
|
|
|
// Otherwise, send a text event with the equivalent UTF-16 string.
|
|
|
|
if (IS_IN_BMP(event.charCode)) {
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-03 00:56:21 -07:00
|
|
|
nsTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2010-07-04 05:42:04 -07:00
|
|
|
PRUnichar textString[3];
|
|
|
|
textString[0] = H_SURROGATE(event.charCode);
|
|
|
|
textString[1] = L_SURROGATE(event.charCode);
|
|
|
|
textString[2] = 0;
|
|
|
|
textEvent.theText = textString;
|
|
|
|
textEvent.time = event.time;
|
|
|
|
DispatchEvent(&textEvent, status);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the event was consumed, return.
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2008-05-05 16:44:18 -07:00
|
|
|
nsWindow::OnKeyReleaseEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-03-18 21:21:16 -07:00
|
|
|
if (mIMModule && mIMModule->OnKeyEvent(this, aEvent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return TRUE;
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// send the key event as a key up event
|
2011-10-03 00:56:21 -07:00
|
|
|
nsKeyEvent event(true, NS_KEY_UP, this);
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitKeyEvent(event, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsEventStatus status;
|
2007-03-22 10:30:00 -07:00
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
// If the event was consumed, return.
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnScrollEvent(GtkWidget *aWidget, GdkEventScroll *aEvent)
|
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
2012-02-01 18:11:06 -08:00
|
|
|
bool rolledUp =
|
|
|
|
check_for_rollup(aEvent->x_root, aEvent->y_root, true, false);
|
2008-01-14 01:40:45 -08:00
|
|
|
if (gConsumeRollupEvent && rolledUp)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsMouseScrollEvent event(true, NS_MOUSE_SCROLL, this);
|
2007-12-11 00:49:46 -08:00
|
|
|
switch (aEvent->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsVertical;
|
|
|
|
event.delta = -3;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsVertical;
|
|
|
|
event.delta = 3;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_LEFT:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
|
2008-02-09 22:08:58 -08:00
|
|
|
event.delta = -1;
|
2007-12-11 00:49:46 -08:00
|
|
|
break;
|
|
|
|
case GDK_SCROLL_RIGHT:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
|
2008-02-09 22:08:58 -08:00
|
|
|
event.delta = 1;
|
2007-12-11 00:49:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (aEvent->window == mGdkWindow) {
|
2009-02-18 16:11:49 -08:00
|
|
|
// we are the window that the event happened on so no need for expensive WidgetToScreenOffset
|
2007-12-11 00:49:46 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->x);
|
|
|
|
event.refPoint.y = nscoord(aEvent->y);
|
|
|
|
} else {
|
|
|
|
// XXX we're never quite sure which GdkWindow the event came from due to our custom bubbling
|
|
|
|
// in scroll_event_cb(), so use ScreenToWidget to translate the screen root coordinates into
|
|
|
|
// coordinates relative to this widget.
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
|
|
|
|
event.refPoint = point - WidgetToScreenOffset();
|
2007-12-11 00:49:46 -08:00
|
|
|
}
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::InitInputEvent(event, aEvent->state);
|
2007-12-11 00:49:46 -08:00
|
|
|
|
|
|
|
event.time = aEvent->time;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnVisibilityNotifyEvent(GtkWidget *aWidget,
|
|
|
|
GdkEventVisibility *aEvent)
|
|
|
|
{
|
2009-11-01 18:03:12 -08:00
|
|
|
LOGDRAW(("Visibility event %i on [%p] %p\n",
|
|
|
|
aEvent->state, this, aEvent->window));
|
|
|
|
|
|
|
|
if (!mGdkWindow)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (aEvent->state) {
|
|
|
|
case GDK_VISIBILITY_UNOBSCURED:
|
|
|
|
case GDK_VISIBILITY_PARTIAL:
|
2009-11-01 18:03:12 -08:00
|
|
|
if (mIsFullyObscured && mHasMappedToplevel) {
|
|
|
|
// GDK_EXPOSE events have been ignored, so make sure GDK
|
|
|
|
// doesn't think that the window has already been painted.
|
|
|
|
gdk_window_invalidate_rect(mGdkWindow, NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsFullyObscured = false;
|
2009-11-01 18:03:12 -08:00
|
|
|
|
2008-09-15 08:58:57 -07:00
|
|
|
// In Hildon/Maemo, a browser window will get into 'patially visible' state wheneven an
|
|
|
|
// autocomplete feature is dropped down (from urlbar or from an entry form completion),
|
|
|
|
// and there are no much further ways for that to happen in the plaftorm. In such cases, if hildon
|
|
|
|
// virtual keyboard is up, we can not grab focus to any dropdown list. Reason: nsWindow::EnsureGrabs()
|
|
|
|
// calls gdk_pointer_grab() which grabs the pointer (usually a mouse) so that all events are passed
|
|
|
|
// to this it until the pointer is ungrabbed.
|
2010-03-18 21:21:16 -07:00
|
|
|
if (!nsGtkIMModule::IsVirtualKeyboardOpened()) {
|
|
|
|
// if we have to retry the grab, retry it.
|
|
|
|
EnsureGrabs();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
default: // includes GDK_VISIBILITY_FULLY_OBSCURED
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsFullyObscured = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnWindowStateEvent(GtkWidget *aWidget, GdkEventWindowState *aEvent)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::OnWindowStateEvent [%p] changed %d new_window_state %d\n",
|
|
|
|
(void *)this, aEvent->changed_mask, aEvent->new_window_state));
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
if (IS_MOZ_CONTAINER(aWidget)) {
|
|
|
|
// This event is notifying the container widget of changes to the
|
|
|
|
// toplevel window. Just detect changes affecting whether windows are
|
|
|
|
// viewable.
|
|
|
|
//
|
|
|
|
// (A visibility notify event is sent to each window that becomes
|
|
|
|
// viewable when the toplevel is mapped, but we can't rely on that for
|
|
|
|
// setting mHasMappedToplevel because these toplevel window state
|
|
|
|
// events are asynchronous. The windows in the hierarchy now may not
|
|
|
|
// be the same windows as when the toplevel was mapped, so they may
|
|
|
|
// not get VisibilityNotify events.)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mapped =
|
2009-11-01 18:03:12 -08:00
|
|
|
!(aEvent->new_window_state &
|
|
|
|
(GDK_WINDOW_STATE_ICONIFIED|GDK_WINDOW_STATE_WITHDRAWN));
|
|
|
|
if (mHasMappedToplevel != mapped) {
|
|
|
|
SetHasMappedToplevel(mapped);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// else the widget is a shell widget.
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
nsSizeModeEvent event(true, NS_SIZEMODE, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-06 10:17:32 -08:00
|
|
|
// We don't care about anything but changes in the maximized/icon/fullscreen
|
2007-03-22 10:30:00 -07:00
|
|
|
// states
|
2007-12-19 03:21:05 -08:00
|
|
|
if ((aEvent->changed_mask
|
2012-02-06 10:17:32 -08:00
|
|
|
& (GDK_WINDOW_STATE_ICONIFIED |
|
|
|
|
GDK_WINDOW_STATE_MAXIMIZED |
|
|
|
|
GDK_WINDOW_STATE_FULLSCREEN)) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->new_window_state & GDK_WINDOW_STATE_ICONIFIED) {
|
|
|
|
LOG(("\tIconified\n"));
|
|
|
|
event.mSizeMode = nsSizeMode_Minimized;
|
|
|
|
mSizeState = nsSizeMode_Minimized;
|
2011-03-26 09:06:00 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
DispatchMinimizeEventAccessible();
|
|
|
|
#endif //ACCESSIBILITY
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-06 10:17:32 -08:00
|
|
|
else if (aEvent->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
|
|
|
|
LOG(("\tFullscreen\n"));
|
|
|
|
event.mSizeMode = nsSizeMode_Fullscreen;
|
|
|
|
mSizeState = nsSizeMode_Fullscreen;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aEvent->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
|
|
|
|
LOG(("\tMaximized\n"));
|
|
|
|
event.mSizeMode = nsSizeMode_Maximized;
|
|
|
|
mSizeState = nsSizeMode_Maximized;
|
2011-03-26 09:06:00 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
DispatchMaximizeEventAccessible();
|
|
|
|
#endif //ACCESSIBILITY
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(("\tNormal\n"));
|
|
|
|
event.mSizeMode = nsSizeMode_Normal;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2011-03-26 09:06:00 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
DispatchRestoreEventAccessible();
|
|
|
|
#endif //ACCESSIBILITY
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ThemeChanged()
|
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsGUIEvent event(true, NS_THEMECHANGED, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow || NS_UNLIKELY(mIsDestroyed))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Dispatch NS_THEMECHANGED to all child windows
|
|
|
|
GList *children =
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_peek_children(mGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (children) {
|
|
|
|
GdkWindow *gdkWin = GDK_WINDOW(children->data);
|
|
|
|
|
|
|
|
nsWindow *win = (nsWindow*) g_object_get_data(G_OBJECT(gdkWin),
|
|
|
|
"nsWindow");
|
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
if (win && win != this) { // guard against infinite recursion
|
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip = win;
|
2007-03-22 10:30:00 -07:00
|
|
|
win->ThemeChanged();
|
2007-04-29 17:46:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
children = children->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 18:00:25 -07:00
|
|
|
void
|
|
|
|
nsWindow::DispatchDragEvent(PRUint32 aMsg, const nsIntPoint& aRefPoint,
|
|
|
|
guint aTime)
|
|
|
|
{
|
|
|
|
nsDragEvent event(true, aMsg, this);
|
|
|
|
|
|
|
|
if (aMsg == NS_DRAGDROP_OVER) {
|
|
|
|
InitDragEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.refPoint = aRefPoint;
|
|
|
|
event.time = aTime;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::OnDragDataReceivedEvent(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
GtkSelectionData *aSelectionData,
|
|
|
|
guint aInfo,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData)
|
|
|
|
{
|
2009-06-14 17:48:52 -07:00
|
|
|
LOGDRAG(("nsWindow::OnDragDataReceived(%p)\n", (void*)this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-18 23:18:31 -07:00
|
|
|
nsDragService::GetInstance()->
|
|
|
|
TargetDataReceived(aWidget, aDragContext, aX, aY,
|
|
|
|
aSelectionData, aInfo, aTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
2009-02-27 17:47:40 -08:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
2007-03-22 10:30:00 -07:00
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
if (bundleService)
|
|
|
|
bundleService->CreateBundle(
|
|
|
|
"chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
|
|
|
|
if (bundle)
|
|
|
|
bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("brandShortName").get(),
|
|
|
|
getter_Copies(brandName));
|
|
|
|
|
|
|
|
if (brandName.IsEmpty())
|
|
|
|
brandName.Assign(NS_LITERAL_STRING("Mozilla"));
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
static GdkWindow *
|
|
|
|
CreateGdkWindow(GdkWindow *parent, GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GdkWindowAttr attributes;
|
2011-09-22 13:58:07 -07:00
|
|
|
gint attributes_mask = GDK_WA_VISUAL;
|
2009-07-26 18:39:36 -07:00
|
|
|
|
|
|
|
attributes.event_mask = (GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK |
|
|
|
|
GDK_VISIBILITY_NOTIFY_MASK |
|
|
|
|
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
2012-05-02 23:23:31 -07:00
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
2009-07-26 18:39:36 -07:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
#endif
|
|
|
|
GDK_POINTER_MOTION_MASK);
|
|
|
|
|
|
|
|
attributes.width = 1;
|
|
|
|
attributes.height = 1;
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.visual = gtk_widget_get_visual(widget);
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
attributes_mask |= GDK_WA_COLORMAP;
|
|
|
|
attributes.colormap = gtk_widget_get_colormap(widget);
|
|
|
|
#endif
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
GdkWindow *window = gdk_window_new(parent, &attributes, attributes_mask);
|
|
|
|
gdk_window_set_user_data(window, widget);
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
// GTK3 TODO?
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-07-26 18:39:36 -07:00
|
|
|
/* set the default pixmap to None so that you don't end up with the
|
|
|
|
gtk default which is BlackPixel. */
|
|
|
|
gdk_window_set_back_pixmap(window, NULL, FALSE);
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif
|
2009-07-26 18:39:36 -07:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWidgetInitData *aInitData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// only set the base parent if we're going to be a dialog or a
|
|
|
|
// toplevel
|
|
|
|
nsIWidget *baseParent = aInitData &&
|
|
|
|
(aInitData->mWindowType == eWindowType_dialog ||
|
|
|
|
aInitData->mWindowType == eWindowType_toplevel ||
|
|
|
|
aInitData->mWindowType == eWindowType_invisible) ?
|
|
|
|
nsnull : aParent;
|
|
|
|
|
2007-10-07 22:02:38 -07:00
|
|
|
NS_ASSERTION(!mWindowGroup, "already have window group (leaking it)");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-04 17:54:17 -08:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// Send a DBus message to check whether a11y is enabled
|
|
|
|
a11y::PreInit();
|
|
|
|
#endif
|
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
// Ensure that the toolkit is created.
|
|
|
|
nsGTKToolkit::GetToolkit();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// initialize all the common bits of this class
|
2011-10-25 08:05:32 -07:00
|
|
|
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aInitData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Do we need to listen for resizes?
|
2011-09-28 23:19:26 -07:00
|
|
|
bool listenForResizes = false;;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aNativeParent || (aInitData && aInitData->mListenForResizes))
|
2011-10-03 00:56:21 -07:00
|
|
|
listenForResizes = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// and do our common creation
|
|
|
|
CommonCreate(aParent, listenForResizes);
|
|
|
|
|
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
// figure out our parent window
|
2009-07-26 18:39:36 -07:00
|
|
|
GtkWidget *parentMozContainer = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
GtkContainer *parentGtkContainer = nsnull;
|
|
|
|
GdkWindow *parentGdkWindow = nsnull;
|
|
|
|
GtkWindow *topLevelParent = nsnull;
|
|
|
|
|
|
|
|
if (aParent)
|
|
|
|
parentGdkWindow = GDK_WINDOW(aParent->GetNativeData(NS_NATIVE_WINDOW));
|
|
|
|
else if (aNativeParent && GDK_IS_WINDOW(aNativeParent))
|
|
|
|
parentGdkWindow = GDK_WINDOW(aNativeParent);
|
|
|
|
else if (aNativeParent && GTK_IS_CONTAINER(aNativeParent))
|
|
|
|
parentGtkContainer = GTK_CONTAINER(aNativeParent);
|
|
|
|
|
|
|
|
if (parentGdkWindow) {
|
2009-07-26 18:39:36 -07:00
|
|
|
// get the widget for the window - it should be a moz container
|
|
|
|
parentMozContainer = get_gtk_widget_for_gdk_window(parentGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!IS_MOZ_CONTAINER(parentMozContainer))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get the toplevel window just in case someone needs to use it
|
|
|
|
// for setting transients or whatever.
|
|
|
|
topLevelParent =
|
|
|
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(parentMozContainer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, create our windows
|
|
|
|
switch (mWindowType) {
|
|
|
|
case eWindowType_dialog:
|
|
|
|
case eWindowType_popup:
|
|
|
|
case eWindowType_toplevel:
|
|
|
|
case eWindowType_invisible: {
|
2011-10-03 00:56:21 -07:00
|
|
|
mIsTopLevel = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-07 20:13:52 -07:00
|
|
|
// We only move a general managed toplevel window if someone has
|
|
|
|
// actually placed the window somewhere. If no placement has taken
|
|
|
|
// place, we just let the window manager Do The Right Thing.
|
|
|
|
//
|
|
|
|
// Indicate that if we're shown, we at least need to have our size set.
|
|
|
|
// If we get explicitly moved, the position will also be set.
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsResize = true;
|
2011-07-07 20:13:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mWindowType == eWindowType_dialog) {
|
|
|
|
mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
SetDefaultIcon();
|
2012-03-27 16:17:35 -07:00
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(mShell), "Dialog",
|
|
|
|
gdk_get_program_class());
|
2007-03-22 10:30:00 -07:00
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(mShell),
|
|
|
|
GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(mShell),
|
|
|
|
topLevelParent);
|
|
|
|
mTransientParent = topLevelParent;
|
|
|
|
// add ourselves to the parent window's window group
|
|
|
|
if (!topLevelParent) {
|
|
|
|
gtk_widget_realize(mShell);
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow* dialoglead = gtk_widget_get_window(mShell);
|
2007-03-22 10:30:00 -07:00
|
|
|
gdk_window_set_group(dialoglead, dialoglead);
|
|
|
|
}
|
2009-07-26 18:39:36 -07:00
|
|
|
if (parentGdkWindow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow *parentnsWindow =
|
2009-07-26 18:39:36 -07:00
|
|
|
get_window_for_gdk_window(parentGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(parentnsWindow,
|
2009-07-26 18:39:36 -07:00
|
|
|
"no nsWindow for parentGdkWindow!");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parentnsWindow && parentnsWindow->mWindowGroup) {
|
|
|
|
gtk_window_group_add_window(parentnsWindow->mWindowGroup,
|
|
|
|
GTK_WINDOW(mShell));
|
|
|
|
// store this in case any children are created
|
|
|
|
mWindowGroup = parentnsWindow->mWindowGroup;
|
2011-05-11 06:10:36 -07:00
|
|
|
g_object_ref(mWindowGroup);
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG(("adding window %p to group %p\n",
|
|
|
|
(void *)mShell, (void *)mWindowGroup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mWindowType == eWindowType_popup) {
|
2011-07-07 20:13:52 -07:00
|
|
|
// With popup windows, we want to control their position, so don't
|
|
|
|
// wait for the window manager to place them (which wouldn't
|
|
|
|
// happen with override-redirect windows anyway).
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsMove = true;
|
2011-07-07 20:13:52 -07:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// Popups that are not noautohide are only temporary. The are used
|
|
|
|
// for menus and the like and disappear when another window is used.
|
|
|
|
if (!aInitData->mNoAutoHide) {
|
2010-06-17 18:15:03 -07:00
|
|
|
// For most popups, use the standard GtkWindowType
|
|
|
|
// GTK_WINDOW_POPUP, which will use a Window with the
|
|
|
|
// override-redirect attribute (for temporary windows).
|
2008-03-14 09:26:13 -07:00
|
|
|
mShell = gtk_window_new(GTK_WINDOW_POPUP);
|
2012-03-27 16:17:35 -07:00
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(mShell), "Popup",
|
|
|
|
gdk_get_program_class());
|
2010-06-17 18:15:03 -07:00
|
|
|
} else {
|
|
|
|
// For long-lived windows, their stacking order is managed by
|
|
|
|
// the window manager, as indicated by GTK_WINDOW_TOPLEVEL ...
|
|
|
|
mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
2012-03-27 16:17:35 -07:00
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(mShell), "Popup",
|
|
|
|
gdk_get_program_class());
|
2010-06-17 18:15:03 -07:00
|
|
|
// ... but the window manager does not decorate this window,
|
|
|
|
// nor provide a separate taskbar icon.
|
2010-07-27 06:38:04 -07:00
|
|
|
if (mBorderStyle == eBorderStyle_default) {
|
|
|
|
gtk_window_set_decorated(GTK_WINDOW(mShell), FALSE);
|
|
|
|
}
|
|
|
|
else {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool decorate = mBorderStyle & eBorderStyle_title;
|
2010-07-27 06:38:04 -07:00
|
|
|
gtk_window_set_decorated(GTK_WINDOW(mShell), decorate);
|
|
|
|
if (decorate) {
|
|
|
|
gtk_window_set_deletable(GTK_WINDOW(mShell), mBorderStyle & eBorderStyle_close);
|
|
|
|
}
|
|
|
|
}
|
2010-09-02 00:23:52 -07:00
|
|
|
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mShell), TRUE);
|
2010-06-17 18:15:03 -07:00
|
|
|
// Element focus is managed by the parent window so the
|
|
|
|
// WM_HINTS input field is set to False to tell the window
|
|
|
|
// manager not to set input focus to this window ...
|
2010-09-02 00:23:52 -07:00
|
|
|
gtk_window_set_accept_focus(GTK_WINDOW(mShell), FALSE);
|
2010-06-17 18:15:03 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// ... but when the window manager offers focus through
|
|
|
|
// WM_TAKE_FOCUS, focus is requested on the parent window.
|
|
|
|
gtk_widget_realize(mShell);
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_add_filter(gtk_widget_get_window(mShell),
|
2010-06-17 18:15:03 -07:00
|
|
|
popup_take_focus_filter, NULL);
|
|
|
|
#endif
|
2008-03-14 09:26:13 -07:00
|
|
|
}
|
2008-03-08 03:32:25 -08:00
|
|
|
|
|
|
|
GdkWindowTypeHint gtkTypeHint;
|
2011-04-25 18:37:20 -07:00
|
|
|
if (aInitData->mIsDragPopup) {
|
|
|
|
gtkTypeHint = GDK_WINDOW_TYPE_HINT_DND;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (aInitData->mPopupHint) {
|
|
|
|
case ePopupTypeMenu:
|
|
|
|
gtkTypeHint = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
|
|
|
|
break;
|
|
|
|
case ePopupTypeTooltip:
|
|
|
|
gtkTypeHint = GDK_WINDOW_TYPE_HINT_TOOLTIP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gtkTypeHint = GDK_WINDOW_TYPE_HINT_UTILITY;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-28 12:18:11 -08:00
|
|
|
}
|
2008-03-08 03:32:25 -08:00
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(mShell), gtkTypeHint);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (topLevelParent) {
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(mShell),
|
|
|
|
topLevelParent);
|
|
|
|
mTransientParent = topLevelParent;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
GtkWindowGroup *groupParent = gtk_window_get_group(topLevelParent);
|
|
|
|
if (groupParent) {
|
|
|
|
gtk_window_group_add_window(groupParent, GTK_WINDOW(mShell));
|
|
|
|
mWindowGroup = groupParent;
|
2011-05-11 06:10:36 -07:00
|
|
|
g_object_ref(mWindowGroup);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // must be eWindowType_toplevel
|
|
|
|
mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
SetDefaultIcon();
|
2012-03-27 16:17:35 -07:00
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(mShell), "Toplevel",
|
|
|
|
gdk_get_program_class());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// each toplevel window gets its own window group
|
|
|
|
mWindowGroup = gtk_window_group_new();
|
|
|
|
|
|
|
|
// and add ourselves to the window group
|
|
|
|
LOG(("adding window %p to new group %p\n",
|
|
|
|
(void *)mShell, (void *)mWindowGroup));
|
|
|
|
gtk_window_group_add_window(mWindowGroup, GTK_WINDOW(mShell));
|
|
|
|
}
|
|
|
|
|
|
|
|
// create our container
|
2009-07-26 18:39:36 -07:00
|
|
|
GtkWidget *container = moz_container_new();
|
|
|
|
mContainer = MOZ_CONTAINER(container);
|
|
|
|
gtk_container_add(GTK_CONTAINER(mShell), container);
|
|
|
|
gtk_widget_realize(container);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-07-21 17:44:55 -07:00
|
|
|
// Don't let GTK mess with the shapes of our GdkWindows
|
2009-07-26 18:39:36 -07:00
|
|
|
GTK_PRIVATE_SET_FLAG(container, GTK_HAS_SHAPE_MASK);
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// make sure this is the focus widget in the container
|
2009-07-26 18:39:36 -07:00
|
|
|
gtk_window_set_focus(GTK_WINDOW(mShell), container);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 18:40:46 -07:00
|
|
|
// the drawing window
|
2011-09-22 13:58:07 -07:00
|
|
|
mGdkWindow = gtk_widget_get_window(container);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mWindowType == eWindowType_popup) {
|
|
|
|
// gdk does not automatically set the cursor for "temporary"
|
|
|
|
// windows, which are what gtk uses for popups.
|
|
|
|
|
|
|
|
mCursor = eCursor_wait; // force SetCursor to actually set the
|
|
|
|
// cursor, even though our internal state
|
|
|
|
// indicates that we already have the
|
|
|
|
// standard cursor.
|
|
|
|
SetCursor(eCursor_standard);
|
2010-07-27 06:38:03 -07:00
|
|
|
|
|
|
|
if (aInitData->mNoAutoHide) {
|
|
|
|
gint wmd = ConvertBorderStyles(mBorderStyle);
|
|
|
|
if (wmd != -1)
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_set_decorations(gtk_widget_get_window(mShell), (GdkWMDecoration) wmd);
|
2010-07-27 06:38:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-09-24 02:32:20 -07:00
|
|
|
case eWindowType_plugin:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eWindowType_child: {
|
|
|
|
if (parentMozContainer) {
|
2009-07-26 18:39:36 -07:00
|
|
|
mGdkWindow = CreateGdkWindow(parentGdkWindow, parentMozContainer);
|
2009-11-01 18:03:12 -08:00
|
|
|
nsWindow *parentnsWindow =
|
|
|
|
get_window_for_gdk_window(parentGdkWindow);
|
|
|
|
if (parentnsWindow)
|
|
|
|
mHasMappedToplevel = parentnsWindow->mHasMappedToplevel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (parentGtkContainer) {
|
2009-07-26 18:39:36 -07:00
|
|
|
GtkWidget *container = moz_container_new();
|
|
|
|
mContainer = MOZ_CONTAINER(container);
|
|
|
|
gtk_container_add(parentGtkContainer, container);
|
|
|
|
gtk_widget_realize(container);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-07-21 17:44:55 -07:00
|
|
|
// Don't let GTK mess with the shapes of our GdkWindows
|
2009-07-26 18:39:36 -07:00
|
|
|
GTK_PRIVATE_SET_FLAG(container, GTK_HAS_SHAPE_MASK);
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
mGdkWindow = gtk_widget_get_window(container);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("Warning: tried to create a new child widget with no parent!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Disable the double buffer because it will make the caret crazy
|
|
|
|
// For bug#153805 (Gtk2 double buffer makes carets misbehave)
|
2008-08-06 13:48:55 -07:00
|
|
|
// DirectFB's expose code depends on gtk double buffering
|
|
|
|
// XXX - I think this bug is probably dead, we can just use gtk's
|
|
|
|
// double-buffering everywhere
|
|
|
|
#ifdef MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContainer)
|
|
|
|
gtk_widget_set_double_buffered (GTK_WIDGET(mContainer),FALSE);
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
// label the drawing window with this object so we can find our way home
|
|
|
|
g_object_set_data(G_OBJECT(mGdkWindow), "nsWindow", this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mContainer)
|
|
|
|
g_object_set_data(G_OBJECT(mContainer), "nsWindow", this);
|
|
|
|
|
|
|
|
if (mShell)
|
|
|
|
g_object_set_data(G_OBJECT(mShell), "nsWindow", this);
|
|
|
|
|
|
|
|
// attach listeners for events
|
|
|
|
if (mShell) {
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mShell, "configure_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(configure_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mShell, "delete_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(delete_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mShell, "window_state_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(window_state_event_cb), NULL);
|
|
|
|
|
|
|
|
GtkSettings* default_settings = gtk_settings_get_default();
|
|
|
|
g_signal_connect_after(default_settings,
|
|
|
|
"notify::gtk-theme-name",
|
|
|
|
G_CALLBACK(theme_changed_cb), this);
|
|
|
|
g_signal_connect_after(default_settings,
|
|
|
|
"notify::gtk-font-name",
|
|
|
|
G_CALLBACK(theme_changed_cb), this);
|
2010-03-31 21:38:51 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
|
|
|
if (mWindowType == eWindowType_toplevel) {
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *gdkwin = gtk_widget_get_window(mShell);
|
2010-03-31 21:38:51 -07:00
|
|
|
|
2010-04-01 06:58:42 -07:00
|
|
|
// Tell the Hildon desktop that we support being rotated
|
|
|
|
gulong portrait_set = 1;
|
|
|
|
GdkAtom support = gdk_atom_intern("_HILDON_PORTRAIT_MODE_SUPPORT", FALSE);
|
|
|
|
gdk_property_change(gdkwin, support, gdk_x11_xatom_to_atom(XA_CARDINAL),
|
|
|
|
32, GDK_PROP_MODE_REPLACE,
|
|
|
|
(const guchar *) &portrait_set, 1);
|
|
|
|
|
2010-03-31 21:38:51 -07:00
|
|
|
// Tell maemo-status-volume daemon to ungrab keys
|
|
|
|
gulong volume_set = 1;
|
|
|
|
GdkAtom keys = gdk_atom_intern("_HILDON_ZOOM_KEY_ATOM", FALSE);
|
|
|
|
gdk_property_change(gdkwin, keys, gdk_x11_xatom_to_atom(XA_INTEGER),
|
|
|
|
32, GDK_PROP_MODE_REPLACE, (const guchar *) &volume_set, 1);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mContainer) {
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "unrealize",
|
2009-05-14 19:14:45 -07:00
|
|
|
G_CALLBACK(container_unrealize_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect_after(mContainer, "size_allocate",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(size_allocate_cb), NULL);
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "expose_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(expose_event_cb), NULL);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
g_signal_connect(G_OBJECT(mContainer), "draw",
|
|
|
|
G_CALLBACK(expose_event_cb), NULL);
|
|
|
|
#endif
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "enter_notify_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(enter_notify_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "leave_notify_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(leave_notify_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "motion_notify_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(motion_notify_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "button_press_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(button_press_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "button_release_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(button_release_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "focus_in_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(focus_in_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "focus_out_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(focus_out_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "key_press_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(key_press_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "key_release_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(key_release_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "scroll_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(scroll_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "visibility_notify_event",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(visibility_notify_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "hierarchy_changed",
|
2009-11-01 18:03:12 -08:00
|
|
|
G_CALLBACK(hierarchy_changed_cb), NULL);
|
|
|
|
// Initialize mHasMappedToplevel.
|
|
|
|
hierarchy_changed_cb(GTK_WIDGET(mContainer), NULL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gtk_drag_dest_set((GtkWidget *)mContainer,
|
|
|
|
(GtkDestDefaults)0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
(GdkDragAction)0);
|
|
|
|
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "drag_motion",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(drag_motion_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "drag_leave",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(drag_leave_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "drag_drop",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(drag_drop_event_cb), NULL);
|
2011-05-11 06:10:36 -07:00
|
|
|
g_signal_connect(mContainer, "drag_data_received",
|
2007-03-22 10:30:00 -07:00
|
|
|
G_CALLBACK(drag_data_received_event_cb), NULL);
|
|
|
|
|
|
|
|
// We create input contexts for all containers, except for
|
|
|
|
// toplevel popup windows
|
2010-03-18 21:21:16 -07:00
|
|
|
if (mWindowType != eWindowType_popup) {
|
|
|
|
mIMModule = new nsGtkIMModule(this);
|
|
|
|
}
|
|
|
|
} else if (!mIMModule) {
|
|
|
|
nsWindow *container = GetContainerWindow();
|
|
|
|
if (container) {
|
|
|
|
mIMModule = container->mIMModule;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("nsWindow [%p]\n", (void *)this));
|
|
|
|
if (mShell) {
|
2011-09-22 13:58:07 -07:00
|
|
|
LOG(("\tmShell %p %p %lx\n", (void *)mShell, (void *)gtk_widget_get_window(mShell),
|
|
|
|
gdk_x11_window_get_xid(gtk_widget_get_window(mShell))));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mContainer) {
|
|
|
|
LOG(("\tmContainer %p %p %lx\n", (void *)mContainer,
|
2011-09-22 13:58:07 -07:00
|
|
|
(void *)gtk_widget_get_window(GTK_WIDGET(mContainer)),
|
|
|
|
gdk_x11_window_get_xid(gtk_widget_get_window(GTK_WIDGET(mContainer)))));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-26 18:40:46 -07:00
|
|
|
else if (mGdkWindow) {
|
2009-07-26 18:39:36 -07:00
|
|
|
LOG(("\tmGdkWindow %p %lx\n", (void *)mGdkWindow,
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_x11_window_get_xid(mGdkWindow)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// resize so that everything is set to the right dimensions
|
2007-06-05 12:57:38 -07:00
|
|
|
if (!mIsTopLevel)
|
2011-10-03 00:56:21 -07:00
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
|
|
|
{
|
|
|
|
if (!mShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-03-27 16:17:35 -07:00
|
|
|
const char *res_class = gdk_get_program_class();
|
|
|
|
if (!res_class)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
char *res_name = ToNewCString(xulWinType);
|
|
|
|
if (!res_name)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-03-27 16:17:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const char *role = NULL;
|
|
|
|
|
|
|
|
// Parse res_name into a name and role. Characters other than
|
|
|
|
// [A-Za-z0-9_-] are converted to '_'. Anything after the first
|
|
|
|
// colon is assigned to role; if there's no colon, assign the
|
|
|
|
// whole thing to both role and res_name.
|
2012-03-27 16:17:35 -07:00
|
|
|
for (char *c = res_name; *c; c++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (':' == *c) {
|
|
|
|
*c = 0;
|
|
|
|
role = c + 1;
|
|
|
|
}
|
|
|
|
else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c)))
|
|
|
|
*c = '_';
|
|
|
|
}
|
2012-03-27 16:17:35 -07:00
|
|
|
res_name[0] = toupper(res_name[0]);
|
|
|
|
if (!role) role = res_name;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *shellWindow = gtk_widget_get_window(GTK_WIDGET(mShell));
|
|
|
|
gdk_window_set_role(shellWindow, role);
|
2012-03-27 16:17:35 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
XClassHint *class_hint = XAllocClassHint();
|
|
|
|
if (!class_hint) {
|
|
|
|
nsMemory::Free(res_name);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
class_hint->res_name = res_name;
|
|
|
|
class_hint->res_class = const_cast<char*>(res_class);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Can't use gtk_window_set_wmclass() for this; it prints
|
|
|
|
// a warning & refuses to make the change.
|
2011-09-22 13:58:07 -07:00
|
|
|
XSetClassHint(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
|
|
|
|
gdk_x11_window_get_xid(shellWindow),
|
2007-03-22 10:30:00 -07:00
|
|
|
class_hint);
|
|
|
|
XFree(class_hint);
|
2012-03-27 16:17:35 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2008-08-06 13:48:55 -07:00
|
|
|
|
|
|
|
nsMemory::Free(res_name);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::NativeResize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
|
|
|
|
|
|
|
ResizeTransparencyBitmap(aWidth, aHeight);
|
|
|
|
|
|
|
|
// clear our resize flag
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsResize = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mIsTopLevel) {
|
|
|
|
gtk_window_resize(GTK_WINDOW(mShell), aWidth, aHeight);
|
|
|
|
}
|
|
|
|
else if (mContainer) {
|
2009-07-26 18:40:46 -07:00
|
|
|
GtkWidget *widget = GTK_WIDGET(mContainer);
|
2011-09-22 13:58:07 -07:00
|
|
|
GtkAllocation allocation, prev_allocation;
|
|
|
|
gtk_widget_get_allocation(widget, &prev_allocation);
|
|
|
|
allocation.x = prev_allocation.x;
|
|
|
|
allocation.y = prev_allocation.y;
|
2007-03-22 10:30:00 -07:00
|
|
|
allocation.width = aWidth;
|
|
|
|
allocation.height = aHeight;
|
2009-07-26 18:40:46 -07:00
|
|
|
gtk_widget_size_allocate(widget, &allocation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-26 18:40:46 -07:00
|
|
|
else if (mGdkWindow) {
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_resize(mGdkWindow, aWidth, aHeight);
|
2009-03-31 03:03:43 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::NativeResize(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aX, aY, aWidth, aHeight));
|
|
|
|
|
|
|
|
ResizeTransparencyBitmap(aWidth, aHeight);
|
|
|
|
|
|
|
|
if (mIsTopLevel) {
|
2011-07-07 20:14:27 -07:00
|
|
|
// aX and aY give the position of the window manager frame top-left.
|
2010-12-20 18:45:58 -08:00
|
|
|
gtk_window_move(GTK_WINDOW(mShell), aX, aY);
|
2011-07-07 20:14:27 -07:00
|
|
|
// This sets the client window size.
|
2007-11-28 12:18:11 -08:00
|
|
|
gtk_window_resize(GTK_WINDOW(mShell), aWidth, aHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mContainer) {
|
|
|
|
GtkAllocation allocation;
|
2009-07-26 18:40:46 -07:00
|
|
|
allocation.x = aX;
|
|
|
|
allocation.y = aY;
|
2007-03-22 10:30:00 -07:00
|
|
|
allocation.width = aWidth;
|
|
|
|
allocation.height = aHeight;
|
|
|
|
gtk_widget_size_allocate(GTK_WIDGET(mContainer), &allocation);
|
|
|
|
}
|
2009-07-26 18:39:36 -07:00
|
|
|
else if (mGdkWindow) {
|
|
|
|
gdk_window_move_resize(mGdkWindow, aX, aY, aWidth, aHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::NativeShow (bool aAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aAction) {
|
|
|
|
// GTK wants us to set the window mask before we show the window
|
|
|
|
// for the first time, or setting the mask later won't work.
|
|
|
|
// GTK also wants us to NOT set the window mask if we're not really
|
|
|
|
// going to need it, because GTK won't let us unset the mask properly
|
|
|
|
// later.
|
|
|
|
// So, we delay setting the mask until the last moment: when the window
|
|
|
|
// is shown.
|
|
|
|
// XXX that may or may not be true for GTK+ 2.x
|
|
|
|
if (mTransparencyBitmap) {
|
|
|
|
ApplyTransparencyBitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// unset our flag now that our window has been shown
|
2011-10-03 00:56:21 -07:00
|
|
|
mNeedsShow = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mIsTopLevel) {
|
|
|
|
// Set up usertime/startupID metadata for the created window.
|
|
|
|
if (mWindowType != eWindowType_invisible) {
|
|
|
|
SetUserTimeAndStartupIDForActivatedWindow(mShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(mContainer));
|
|
|
|
gtk_widget_show(mShell);
|
|
|
|
}
|
|
|
|
else if (mContainer) {
|
|
|
|
gtk_widget_show(GTK_WIDGET(mContainer));
|
|
|
|
}
|
2009-07-26 18:39:36 -07:00
|
|
|
else if (mGdkWindow) {
|
|
|
|
gdk_window_show_unraised(mGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mIsTopLevel) {
|
|
|
|
gtk_widget_hide(GTK_WIDGET(mShell));
|
|
|
|
gtk_widget_hide(GTK_WIDGET(mContainer));
|
|
|
|
}
|
|
|
|
else if (mContainer) {
|
|
|
|
gtk_widget_hide(GTK_WIDGET(mContainer));
|
|
|
|
}
|
2009-07-26 18:40:46 -07:00
|
|
|
else if (mGdkWindow) {
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_hide(mGdkWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetHasMappedToplevel(bool aState)
|
2009-11-01 18:03:12 -08:00
|
|
|
{
|
|
|
|
// Even when aState == mHasMappedToplevel (as when this method is called
|
|
|
|
// from Show()), child windows need to have their state checked, so don't
|
|
|
|
// return early.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool oldState = mHasMappedToplevel;
|
2009-11-01 18:03:12 -08:00
|
|
|
mHasMappedToplevel = aState;
|
|
|
|
|
|
|
|
// mHasMappedToplevel is not updated for children of windows that are
|
|
|
|
// hidden; GDK knows not to send expose events for these windows. The
|
|
|
|
// state is recorded on the hidden window itself, but, for child trees of
|
|
|
|
// hidden windows, their state essentially becomes disconnected from their
|
|
|
|
// hidden parent. When the hidden parent gets shown, the child trees are
|
|
|
|
// reconnected, and the state of the window being shown can be easily
|
|
|
|
// propagated.
|
|
|
|
if (!mIsShown || !mGdkWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aState && !oldState && !mIsFullyObscured) {
|
|
|
|
// GDK_EXPOSE events have been ignored but the window is now visible,
|
|
|
|
// so make sure GDK doesn't think that the window has already been
|
|
|
|
// painted.
|
|
|
|
gdk_window_invalidate_rect(mGdkWindow, NULL, FALSE);
|
|
|
|
|
|
|
|
// Check that a grab didn't fail due to the window not being
|
|
|
|
// viewable.
|
|
|
|
EnsureGrabs();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (GList *children = gdk_window_peek_children(mGdkWindow);
|
|
|
|
children;
|
|
|
|
children = children->next) {
|
|
|
|
GdkWindow *gdkWin = GDK_WINDOW(children->data);
|
|
|
|
nsWindow *child = get_window_for_gdk_window(gdkWin);
|
|
|
|
|
|
|
|
if (child && child->mHasMappedToplevel != aState) {
|
|
|
|
child->SetHasMappedToplevel(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntSize
|
|
|
|
nsWindow::GetSafeWindowSize(nsIntSize aSize)
|
2008-07-02 04:09:15 -07:00
|
|
|
{
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntSize result = aSize;
|
2008-09-03 08:39:08 -07:00
|
|
|
const PRInt32 kInt16Max = 32767;
|
|
|
|
if (result.width > kInt16Max) {
|
2008-07-02 04:09:15 -07:00
|
|
|
NS_WARNING("Clamping huge window width");
|
2008-09-03 08:39:08 -07:00
|
|
|
result.width = kInt16Max;
|
2008-07-02 04:09:15 -07:00
|
|
|
}
|
2008-09-03 08:39:08 -07:00
|
|
|
if (result.height > kInt16Max) {
|
2008-07-02 04:09:15 -07:00
|
|
|
NS_WARNING("Clamping huge window height");
|
2008-09-03 08:39:08 -07:00
|
|
|
result.height = kInt16Max;
|
2008-07-02 04:09:15 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::EnsureGrabs(void)
|
|
|
|
{
|
|
|
|
if (mRetryPointerGrab)
|
2012-02-01 18:12:26 -08:00
|
|
|
GrabPointer(sRetryGrabTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
void
|
|
|
|
nsWindow::SetTransparencyMode(nsTransparencyMode aMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// Pass the request to the toplevel window
|
|
|
|
GtkWidget *topWidget = nsnull;
|
|
|
|
GetToplevelWidget(&topWidget);
|
|
|
|
if (!topWidget)
|
2008-08-12 17:44:14 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsWindow *topWindow = get_window_for_gtk_widget(topWidget);
|
|
|
|
if (!topWindow)
|
2008-08-12 17:44:14 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
topWindow->SetTransparencyMode(aMode);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isTransparent = aMode == eTransparencyTransparent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
if (mIsTransparent == isTransparent)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
if (!isTransparent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mTransparencyBitmap) {
|
|
|
|
delete[] mTransparencyBitmap;
|
|
|
|
mTransparencyBitmap = nsnull;
|
|
|
|
mTransparencyBitmapWidth = 0;
|
|
|
|
mTransparencyBitmapHeight = 0;
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
gtk_widget_reset_shapes(mShell);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
// GTK3 TODO
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} // else the new default alpha values are "all 1", so we don't
|
|
|
|
// need to change anything yet
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
mIsTransparent = isTransparent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
nsTransparencyMode
|
|
|
|
nsWindow::GetTransparencyMode()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// Pass the request to the toplevel window
|
|
|
|
GtkWidget *topWidget = nsnull;
|
|
|
|
GetToplevelWidget(&topWidget);
|
|
|
|
if (!topWidget) {
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyOpaque;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow *topWindow = get_window_for_gtk_widget(topWidget);
|
|
|
|
if (!topWindow) {
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyOpaque;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
return topWindow->GetTransparencyMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
return mIsTransparent ? eTransparencyTransparent : eTransparencyOpaque;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-21 17:44:55 -07:00
|
|
|
nsresult
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
2011-10-03 00:56:21 -07:00
|
|
|
w->SetWindowClipRegion(configuration.mClipRegion, true);
|
2009-07-21 17:44:55 -07:00
|
|
|
if (w->mBounds.Size() != configuration.mBounds.Size()) {
|
|
|
|
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
|
|
|
|
configuration.mBounds.width, configuration.mBounds.height,
|
2011-10-03 00:56:21 -07:00
|
|
|
true);
|
2009-07-21 17:44:55 -07:00
|
|
|
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
|
|
|
w->Move(configuration.mBounds.x, configuration.mBounds.y);
|
|
|
|
}
|
2011-10-03 00:56:21 -07:00
|
|
|
w->SetWindowClipRegion(configuration.mClipRegion, false);
|
2009-07-21 17:44:55 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:56:31 -07:00
|
|
|
static pixman_box32
|
|
|
|
ToPixmanBox(const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
pixman_box32_t result;
|
|
|
|
result.x1 = aRect.x;
|
|
|
|
result.y1 = aRect.y;
|
|
|
|
result.x2 = aRect.XMost();
|
|
|
|
result.y2 = aRect.YMost();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIntRect
|
|
|
|
ToIntRect(const pixman_box32& aBox)
|
|
|
|
{
|
|
|
|
nsIntRect result;
|
|
|
|
result.x = aBox.x1;
|
|
|
|
result.y = aBox.y1;
|
|
|
|
result.width = aBox.x2 - aBox.x1;
|
|
|
|
result.height = aBox.y2 - aBox.y1;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitRegion(pixman_region32* aRegion,
|
|
|
|
const nsTArray<nsIntRect>& aRects)
|
|
|
|
{
|
|
|
|
nsAutoTArray<pixman_box32,10> rects;
|
|
|
|
rects.SetCapacity(aRects.Length());
|
|
|
|
for (PRUint32 i = 0; i < aRects.Length (); ++i) {
|
|
|
|
if (!aRects[i].IsEmpty()) {
|
|
|
|
rects.AppendElement(ToPixmanBox(aRects[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pixman_region32_init_rects(aRegion,
|
|
|
|
rects.Elements(), rects.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetIntRects(pixman_region32& aRegion, nsTArray<nsIntRect>* aRects)
|
|
|
|
{
|
|
|
|
int nRects;
|
|
|
|
pixman_box32* boxes = pixman_region32_rectangles(&aRegion, &nRects);
|
|
|
|
aRects->SetCapacity(aRects->Length() + nRects);
|
|
|
|
for (int i = 0; i < nRects; ++i) {
|
|
|
|
aRects->AppendElement(ToIntRect(boxes[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-13 13:01:33 -08:00
|
|
|
void
|
|
|
|
nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIntersectWithExisting)
|
2009-07-21 17:44:55 -07:00
|
|
|
{
|
2009-12-13 13:01:33 -08:00
|
|
|
const nsTArray<nsIntRect>* newRects = &aRects;
|
|
|
|
|
|
|
|
nsAutoTArray<nsIntRect,1> intersectRects;
|
|
|
|
if (aIntersectWithExisting) {
|
|
|
|
nsAutoTArray<nsIntRect,1> existingRects;
|
|
|
|
GetWindowClipRegion(&existingRects);
|
|
|
|
|
|
|
|
nsAutoRef<pixman_region32> existingRegion;
|
|
|
|
InitRegion(&existingRegion, existingRects);
|
|
|
|
nsAutoRef<pixman_region32> newRegion;
|
|
|
|
InitRegion(&newRegion, aRects);
|
|
|
|
nsAutoRef<pixman_region32> intersectRegion;
|
2010-03-07 14:33:42 -08:00
|
|
|
pixman_region32_init(&intersectRegion);
|
2009-12-13 13:01:33 -08:00
|
|
|
pixman_region32_intersect(&intersectRegion,
|
|
|
|
&newRegion, &existingRegion);
|
|
|
|
|
2010-12-09 20:33:33 -08:00
|
|
|
// If mClipRects is null we haven't set a clip rect yet, so we
|
|
|
|
// need to set the clip even if it is equal.
|
|
|
|
if (mClipRects &&
|
|
|
|
pixman_region32_equal(&intersectRegion, &existingRegion)) {
|
2009-12-13 13:01:33 -08:00
|
|
|
return;
|
2010-12-09 20:33:33 -08:00
|
|
|
}
|
2009-12-13 13:01:33 -08:00
|
|
|
|
|
|
|
if (!pixman_region32_equal(&intersectRegion, &newRegion)) {
|
|
|
|
GetIntRects(intersectRegion, &intersectRects);
|
|
|
|
newRects = &intersectRects;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StoreWindowClipRegion(*newRects))
|
|
|
|
return;
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2009-12-13 13:01:33 -08:00
|
|
|
return;
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-12-13 13:01:33 -08:00
|
|
|
GdkRegion *region = gdk_region_new(); // aborts on OOM
|
|
|
|
for (PRUint32 i = 0; i < newRects->Length(); ++i) {
|
|
|
|
const nsIntRect& r = newRects->ElementAt(i);
|
2009-07-21 17:44:55 -07:00
|
|
|
GdkRectangle rect = { r.x, r.y, r.width, r.height };
|
|
|
|
gdk_region_union_with_rect(region, &rect);
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_shape_combine_region(mGdkWindow, region, 0, 0);
|
2009-07-21 17:44:55 -07:00
|
|
|
gdk_region_destroy(region);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_region_t *region = cairo_region_create();
|
|
|
|
for (PRUint32 i = 0; i < newRects->Length(); ++i) {
|
|
|
|
const nsIntRect& r = newRects->ElementAt(i);
|
|
|
|
cairo_rectangle_int_t rect = { r.x, r.y, r.width, r.height };
|
|
|
|
cairo_region_union_rectangle(region, &rect);
|
|
|
|
}
|
2009-07-21 17:44:55 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_shape_combine_region(mGdkWindow, region, 0, 0);
|
|
|
|
cairo_region_destroy(region);
|
|
|
|
#endif
|
|
|
|
|
2009-12-13 13:01:33 -08:00
|
|
|
return;
|
2009-07-21 17:44:55 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight)
|
|
|
|
{
|
|
|
|
if (!mTransparencyBitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aNewWidth == mTransparencyBitmapWidth &&
|
|
|
|
aNewHeight == mTransparencyBitmapHeight)
|
|
|
|
return;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
PRInt32 newSize = GetBitmapStride(aNewWidth)*aNewHeight;
|
2007-03-22 10:30:00 -07:00
|
|
|
gchar* newBits = new gchar[newSize];
|
|
|
|
if (!newBits) {
|
|
|
|
delete[] mTransparencyBitmap;
|
|
|
|
mTransparencyBitmap = nsnull;
|
|
|
|
mTransparencyBitmapWidth = 0;
|
|
|
|
mTransparencyBitmapHeight = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// fill new mask with "opaque", first
|
|
|
|
memset(newBits, 255, newSize);
|
|
|
|
|
|
|
|
// Now copy the intersection of the old and new areas into the new mask
|
2011-06-02 05:56:50 -07:00
|
|
|
PRInt32 copyWidth = NS_MIN(aNewWidth, mTransparencyBitmapWidth);
|
|
|
|
PRInt32 copyHeight = NS_MIN(aNewHeight, mTransparencyBitmapHeight);
|
2011-09-22 13:58:07 -07:00
|
|
|
PRInt32 oldRowBytes = GetBitmapStride(mTransparencyBitmapWidth);
|
|
|
|
PRInt32 newRowBytes = GetBitmapStride(aNewWidth);
|
|
|
|
PRInt32 copyBytes = GetBitmapStride(copyWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
gchar* fromPtr = mTransparencyBitmap;
|
|
|
|
gchar* toPtr = newBits;
|
|
|
|
for (i = 0; i < copyHeight; i++) {
|
|
|
|
memcpy(toPtr, fromPtr, copyBytes);
|
|
|
|
fromPtr += oldRowBytes;
|
|
|
|
toPtr += newRowBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] mTransparencyBitmap;
|
|
|
|
mTransparencyBitmap = newBits;
|
|
|
|
mTransparencyBitmapWidth = aNewWidth;
|
|
|
|
mTransparencyBitmapHeight = aNewHeight;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
ChangedMaskBits(gchar* aMaskBits, PRInt32 aMaskWidth, PRInt32 aMaskHeight,
|
2009-01-14 19:27:09 -08:00
|
|
|
const nsIntRect& aRect, PRUint8* aAlphas, PRInt32 aStride)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 x, y, xMax = aRect.XMost(), yMax = aRect.YMost();
|
2011-09-22 13:58:07 -07:00
|
|
|
PRInt32 maskBytesPerRow = GetBitmapStride(aMaskWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (y = aRect.y; y < yMax; y++) {
|
|
|
|
gchar* maskBytes = aMaskBits + y*maskBytesPerRow;
|
|
|
|
PRUint8* alphas = aAlphas;
|
|
|
|
for (x = aRect.x; x < xMax; x++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newBit = *alphas > 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
alphas++;
|
|
|
|
|
|
|
|
gchar maskByte = maskBytes[x >> 3];
|
2011-09-28 23:19:26 -07:00
|
|
|
bool maskBit = (maskByte & (1 << (x & 7))) != 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (maskBit != newBit) {
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
aAlphas += aStride;
|
|
|
|
}
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void UpdateMaskBits(gchar* aMaskBits, PRInt32 aMaskWidth, PRInt32 aMaskHeight,
|
2009-01-14 19:27:09 -08:00
|
|
|
const nsIntRect& aRect, PRUint8* aAlphas, PRInt32 aStride)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 x, y, xMax = aRect.XMost(), yMax = aRect.YMost();
|
2011-09-22 13:58:07 -07:00
|
|
|
PRInt32 maskBytesPerRow = GetBitmapStride(aMaskWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (y = aRect.y; y < yMax; y++) {
|
|
|
|
gchar* maskBytes = aMaskBits + y*maskBytesPerRow;
|
|
|
|
PRUint8* alphas = aAlphas;
|
|
|
|
for (x = aRect.x; x < xMax; x++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newBit = *alphas > 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
alphas++;
|
|
|
|
|
|
|
|
gchar mask = 1 << (x & 7);
|
|
|
|
gchar maskByte = maskBytes[x >> 3];
|
|
|
|
// Note: '-newBit' turns 0 into 00...00 and 1 into 11...11
|
|
|
|
maskBytes[x >> 3] = (maskByte & ~mask) | (-newBit & mask);
|
|
|
|
}
|
|
|
|
aAlphas += aStride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ApplyTransparencyBitmap()
|
|
|
|
{
|
2011-05-10 21:54:12 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// We use X11 calls where possible, because GDK handles expose events
|
|
|
|
// for shaped windows in a way that's incompatible with us (Bug 635903).
|
|
|
|
// It doesn't occur when the shapes are set through X.
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *shellWindow = gtk_widget_get_window(mShell);
|
|
|
|
Display* xDisplay = GDK_WINDOW_XDISPLAY(shellWindow);
|
|
|
|
Window xDrawable = GDK_WINDOW_XID(shellWindow);
|
2011-05-10 21:54:12 -07:00
|
|
|
Pixmap maskPixmap = XCreateBitmapFromData(xDisplay,
|
|
|
|
xDrawable,
|
|
|
|
mTransparencyBitmap,
|
|
|
|
mTransparencyBitmapWidth,
|
|
|
|
mTransparencyBitmapHeight);
|
|
|
|
XShapeCombineMask(xDisplay, xDrawable,
|
|
|
|
ShapeBounding, 0, 0,
|
|
|
|
maskPixmap, ShapeSet);
|
|
|
|
XFreePixmap(xDisplay, maskPixmap);
|
|
|
|
#else
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
gtk_widget_reset_shapes(mShell);
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkBitmap* maskBitmap = gdk_bitmap_create_from_data(gtk_widget_get_window(mShell),
|
2007-03-22 10:30:00 -07:00
|
|
|
mTransparencyBitmap,
|
|
|
|
mTransparencyBitmapWidth, mTransparencyBitmapHeight);
|
|
|
|
if (!maskBitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_shape_combine_mask(mShell, maskBitmap, 0, 0);
|
2009-02-02 09:49:58 -08:00
|
|
|
g_object_unref(maskBitmap);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
cairo_surface_t *maskBitmap;
|
|
|
|
maskBitmap = cairo_image_surface_create_for_data((unsigned char*)mTransparencyBitmap,
|
|
|
|
CAIRO_FORMAT_A1,
|
|
|
|
mTransparencyBitmapWidth,
|
|
|
|
mTransparencyBitmapHeight,
|
|
|
|
GetBitmapStride(mTransparencyBitmapWidth));
|
|
|
|
if (!maskBitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cairo_region_t * maskRegion = gdk_cairo_region_create_from_surface(maskBitmap);
|
|
|
|
gtk_widget_shape_combine_region(mShell, maskRegion);
|
|
|
|
cairo_region_destroy(maskRegion);
|
|
|
|
cairo_surface_destroy(maskBitmap);
|
|
|
|
#endif // MOZ_WIDGET_GTK2
|
|
|
|
#endif // MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-01-14 19:27:09 -08:00
|
|
|
nsWindow::UpdateTranslucentWindowAlphaInternal(const nsIntRect& aRect,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint8* aAlphas, PRInt32 aStride)
|
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// Pass the request to the toplevel window
|
|
|
|
GtkWidget *topWidget = nsnull;
|
|
|
|
GetToplevelWidget(&topWidget);
|
|
|
|
if (!topWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsWindow *topWindow = get_window_for_gtk_widget(topWidget);
|
|
|
|
if (!topWindow)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return topWindow->UpdateTranslucentWindowAlphaInternal(aRect, aAlphas, aStride);
|
|
|
|
}
|
|
|
|
|
2007-12-19 11:40:18 -08:00
|
|
|
NS_ASSERTION(mIsTransparent, "Window is not transparent");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mTransparencyBitmap == nsnull) {
|
2011-09-22 13:58:07 -07:00
|
|
|
PRInt32 size = GetBitmapStride(mBounds.width)*mBounds.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
mTransparencyBitmap = new gchar[size];
|
|
|
|
if (mTransparencyBitmap == nsnull)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
memset(mTransparencyBitmap, 255, size);
|
|
|
|
mTransparencyBitmapWidth = mBounds.width;
|
|
|
|
mTransparencyBitmapHeight = mBounds.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aRect.x >= 0 && aRect.y >= 0
|
|
|
|
&& aRect.XMost() <= mBounds.width && aRect.YMost() <= mBounds.height,
|
|
|
|
"Rect is out of window bounds");
|
|
|
|
|
|
|
|
if (!ChangedMaskBits(mTransparencyBitmap, mBounds.width, mBounds.height,
|
|
|
|
aRect, aAlphas, aStride))
|
|
|
|
// skip the expensive stuff if the mask bits haven't changed; hopefully
|
|
|
|
// this is the common case
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
UpdateMaskBits(mTransparencyBitmap, mBounds.width, mBounds.height,
|
|
|
|
aRect, aAlphas, aStride);
|
|
|
|
|
|
|
|
if (!mNeedsShow) {
|
|
|
|
ApplyTransparencyBitmap();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 18:12:26 -08:00
|
|
|
nsWindow::GrabPointer(guint32 aTime)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-07 12:51:15 -08:00
|
|
|
LOG(("GrabPointer time=0x%08x retry=%d\n",
|
|
|
|
(unsigned int)aTime, mRetryPointerGrab));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mRetryPointerGrab = false;
|
2012-02-07 12:51:15 -08:00
|
|
|
sRetryGrabTime = aTime;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If the window isn't visible, just set the flag to retry the
|
|
|
|
// grab. When this window becomes visible, the grab will be
|
|
|
|
// retried.
|
2009-11-01 18:03:12 -08:00
|
|
|
if (!mHasMappedToplevel || mIsFullyObscured) {
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG(("GrabPointer: window not visible\n"));
|
2011-10-03 00:56:21 -07:00
|
|
|
mRetryPointerGrab = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
gint retval;
|
2009-07-26 18:39:36 -07:00
|
|
|
retval = gdk_pointer_grab(mGdkWindow, TRUE,
|
2007-03-22 10:30:00 -07:00
|
|
|
(GdkEventMask)(GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_ENTER_NOTIFY_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK |
|
2012-05-02 23:23:31 -07:00
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
2008-11-26 05:43:36 -08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
GDK_POINTER_MOTION_MASK),
|
2012-02-01 18:12:26 -08:00
|
|
|
(GdkWindow *)NULL, NULL, aTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-01 18:11:44 -08:00
|
|
|
if (retval == GDK_GRAB_NOT_VIEWABLE) {
|
|
|
|
LOG(("GrabPointer: window not viewable; will retry\n"));
|
2011-10-03 00:56:21 -07:00
|
|
|
mRetryPointerGrab = true;
|
2012-02-01 18:11:44 -08:00
|
|
|
} else if (retval != GDK_GRAB_SUCCESS) {
|
|
|
|
LOG(("GrabPointer: pointer grab failed: %i\n", retval));
|
|
|
|
// A failed grab indicates that another app has grabbed the pointer.
|
|
|
|
// Check for rollup now, because, without the grab, we likely won't
|
|
|
|
// get subsequent button press events.
|
|
|
|
check_for_rollup(0, 0, false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ReleaseGrabs(void)
|
|
|
|
{
|
|
|
|
LOG(("ReleaseGrabs\n"));
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
mRetryPointerGrab = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
gdk_pointer_ungrab(GDK_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::GetToplevelWidget(GtkWidget **aWidget)
|
|
|
|
{
|
|
|
|
*aWidget = nsnull;
|
|
|
|
|
|
|
|
if (mShell) {
|
|
|
|
*aWidget = mShell;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *widget = GetMozContainerWidget();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*aWidget = gtk_widget_get_toplevel(widget);
|
|
|
|
}
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *
|
|
|
|
nsWindow::GetMozContainerWidget()
|
|
|
|
{
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2009-02-19 18:07:08 -08:00
|
|
|
return NULL;
|
|
|
|
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *owningWidget =
|
2009-07-26 18:39:36 -07:00
|
|
|
get_gtk_widget_for_gdk_window(mGdkWindow);
|
2008-08-27 19:04:06 -07:00
|
|
|
return owningWidget;
|
|
|
|
}
|
|
|
|
|
2009-02-19 18:07:08 -08:00
|
|
|
nsWindow *
|
|
|
|
nsWindow::GetContainerWindow()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-27 19:04:06 -07:00
|
|
|
GtkWidget *owningWidget = GetMozContainerWidget();
|
2009-02-19 18:07:08 -08:00
|
|
|
if (!owningWidget)
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-19 18:07:08 -08:00
|
|
|
nsWindow *window = get_window_for_gtk_widget(owningWidget);
|
|
|
|
NS_ASSERTION(window, "No nsWindow for container widget");
|
|
|
|
return window;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetUrgencyHint(GtkWidget *top_window, bool state)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!top_window)
|
|
|
|
return;
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
gdk_window_set_urgency_hint(gtk_widget_get_window(top_window), state);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
2009-07-26 18:39:36 -07:00
|
|
|
if (!mGdkWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
if (gdk_window_is_destroyed(mGdkWindow) == TRUE)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
Window window = gdk_x11_window_get_xid(mGdkWindow);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// we have to flush the X queue here so that any plugins that
|
|
|
|
// might be running on separate X connections will be able to use
|
|
|
|
// this window in case it was just created
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2011-09-22 13:58:07 -07:00
|
|
|
XWindowAttributes xattrs;
|
|
|
|
Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
|
|
|
XGetWindowAttributes(display, window, &xattrs);
|
|
|
|
XSelectInput (display, window,
|
2007-03-22 10:30:00 -07:00
|
|
|
xattrs.your_event_mask |
|
|
|
|
SubstructureNotifyMask);
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
gdk_window_add_filter(mGdkWindow, plugin_window_filter_func, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
XSync(display, False);
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
return (void *)window;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
|
|
|
{
|
2008-01-09 22:04:51 -08:00
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SetPluginType(PluginType aPluginType)
|
|
|
|
{
|
|
|
|
mPluginType = aPluginType;
|
|
|
|
}
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::SetNonXEmbedPluginFocus()
|
|
|
|
{
|
|
|
|
if (gPluginFocusWindow == this || mPluginType!=PluginType_NONXEMBED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gPluginFocusWindow) {
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
gPluginFocusWindow->LoseNonXEmbedPluginFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGFOCUS(("nsWindow::SetNonXEmbedPluginFocus\n"));
|
|
|
|
|
|
|
|
Window curFocusWindow;
|
|
|
|
int focusState;
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
GdkDisplay *gdkDisplay = gdk_window_get_display(mGdkWindow);
|
|
|
|
XGetInputFocus(gdk_x11_display_get_xdisplay(gdkDisplay),
|
2007-03-22 10:30:00 -07:00
|
|
|
&curFocusWindow,
|
|
|
|
&focusState);
|
|
|
|
|
|
|
|
LOGFOCUS(("\t curFocusWindow=%p\n", curFocusWindow));
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
GdkWindow* toplevel = gdk_window_get_toplevel(mGdkWindow);
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
GdkWindow *gdkfocuswin = gdk_window_lookup(curFocusWindow);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
GdkWindow *gdkfocuswin = gdk_x11_window_lookup_for_display(gdkDisplay,
|
|
|
|
curFocusWindow);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// lookup with the focus proxy window is supposed to get the
|
|
|
|
// same GdkWindow as toplevel. If the current focused window
|
|
|
|
// is not the focus proxy, we return without any change.
|
|
|
|
if (gdkfocuswin != toplevel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// switch the focus from the focus proxy to the plugin window
|
|
|
|
mOldFocusWindow = curFocusWindow;
|
2009-07-26 18:39:36 -07:00
|
|
|
XRaiseWindow(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_x11_window_get_xid(mGdkWindow));
|
2007-03-22 10:30:00 -07:00
|
|
|
gdk_error_trap_push();
|
2009-07-26 18:39:36 -07:00
|
|
|
XSetInputFocus(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_x11_window_get_xid(mGdkWindow),
|
2007-03-22 10:30:00 -07:00
|
|
|
RevertToNone,
|
|
|
|
CurrentTime);
|
|
|
|
gdk_flush();
|
|
|
|
gdk_error_trap_pop();
|
|
|
|
gPluginFocusWindow = this;
|
|
|
|
gdk_window_add_filter(NULL, plugin_client_message_filter, this);
|
|
|
|
|
|
|
|
LOGFOCUS(("nsWindow::SetNonXEmbedPluginFocus oldfocus=%p new=%p\n",
|
2011-09-22 13:58:07 -07:00
|
|
|
mOldFocusWindow, gdk_x11_window_get_xid(mGdkWindow)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::LoseNonXEmbedPluginFocus()
|
|
|
|
{
|
|
|
|
LOGFOCUS(("nsWindow::LoseNonXEmbedPluginFocus\n"));
|
|
|
|
|
|
|
|
// This method is only for the nsWindow which contains a
|
|
|
|
// Non-XEmbed plugin, for example, JAVA plugin.
|
|
|
|
if (gPluginFocusWindow != this || mPluginType!=PluginType_NONXEMBED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window curFocusWindow;
|
|
|
|
int focusState;
|
|
|
|
|
2009-07-26 18:39:36 -07:00
|
|
|
XGetInputFocus(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
2007-03-22 10:30:00 -07:00
|
|
|
&curFocusWindow,
|
|
|
|
&focusState);
|
|
|
|
|
|
|
|
// we only switch focus between plugin window and focus proxy. If the
|
|
|
|
// current focused window is not the plugin window, just removing the
|
|
|
|
// event filter that blocks the WM_TAKE_FOCUS is enough. WM and gtk2
|
|
|
|
// will take care of the focus later.
|
|
|
|
if (!curFocusWindow ||
|
2011-09-22 13:58:07 -07:00
|
|
|
curFocusWindow == gdk_x11_window_get_xid(mGdkWindow)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gdk_error_trap_push();
|
2009-07-26 18:39:36 -07:00
|
|
|
XRaiseWindow(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
2007-03-22 10:30:00 -07:00
|
|
|
mOldFocusWindow);
|
2009-07-26 18:39:36 -07:00
|
|
|
XSetInputFocus(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
2007-03-22 10:30:00 -07:00
|
|
|
mOldFocusWindow,
|
|
|
|
RevertToParent,
|
|
|
|
CurrentTime);
|
|
|
|
gdk_flush();
|
|
|
|
gdk_error_trap_pop();
|
|
|
|
}
|
|
|
|
gPluginFocusWindow = NULL;
|
|
|
|
mOldFocusWindow = 0;
|
|
|
|
gdk_window_remove_filter(NULL, plugin_client_message_filter, this);
|
|
|
|
|
|
|
|
LOGFOCUS(("nsWindow::LoseNonXEmbedPluginFocus end\n"));
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gint
|
|
|
|
nsWindow::ConvertBorderStyles(nsBorderStyle aStyle)
|
|
|
|
{
|
|
|
|
gint w = 0;
|
|
|
|
|
|
|
|
if (aStyle == eBorderStyle_default)
|
|
|
|
return -1;
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// note that we don't handle eBorderStyle_close yet
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aStyle & eBorderStyle_all)
|
|
|
|
w |= GDK_DECOR_ALL;
|
|
|
|
if (aStyle & eBorderStyle_border)
|
|
|
|
w |= GDK_DECOR_BORDER;
|
|
|
|
if (aStyle & eBorderStyle_resizeh)
|
|
|
|
w |= GDK_DECOR_RESIZEH;
|
|
|
|
if (aStyle & eBorderStyle_title)
|
|
|
|
w |= GDK_DECOR_TITLE;
|
|
|
|
if (aStyle & eBorderStyle_menu)
|
|
|
|
w |= GDK_DECOR_MENU;
|
|
|
|
if (aStyle & eBorderStyle_minimize)
|
|
|
|
w |= GDK_DECOR_MINIMIZE;
|
|
|
|
if (aStyle & eBorderStyle_maximize)
|
|
|
|
w |= GDK_DECOR_MAXIMIZE;
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-14 12:56:56 -07:00
|
|
|
LOG(("nsWindow::MakeFullScreen [%p] aFullScreen %d\n",
|
|
|
|
(void *)this, aFullScreen));
|
|
|
|
|
|
|
|
if (aFullScreen) {
|
2009-08-26 17:09:47 -07:00
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen)
|
|
|
|
mLastSizeMode = mSizeMode;
|
|
|
|
|
2009-08-14 12:56:56 -07:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
2009-11-10 12:46:09 -08:00
|
|
|
gtk_window_fullscreen(GTK_WINDOW(mShell));
|
2009-08-14 12:56:56 -07:00
|
|
|
}
|
2009-08-26 17:09:47 -07:00
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
2009-11-10 12:46:09 -08:00
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(mShell));
|
2009-08-26 17:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
2008-01-04 21:34:00 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::HideWindowChrome(bool aShouldHide)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mShell) {
|
|
|
|
// Pass the request to the toplevel window
|
|
|
|
GtkWidget *topWidget = nsnull;
|
|
|
|
GetToplevelWidget(&topWidget);
|
2009-02-19 18:07:08 -08:00
|
|
|
if (!topWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow *topWindow = get_window_for_gtk_widget(topWidget);
|
2009-02-19 18:07:08 -08:00
|
|
|
if (!topWindow)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return topWindow->HideWindowChrome(aShouldHide);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sawfish, metacity, and presumably other window managers get
|
|
|
|
// confused if we change the window decorations while the window
|
|
|
|
// is visible.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasVisible = false;
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *shellWindow = gtk_widget_get_window(mShell);
|
|
|
|
if (gdk_window_is_visible(shellWindow)) {
|
|
|
|
gdk_window_hide(shellWindow);
|
2011-10-03 00:56:21 -07:00
|
|
|
wasVisible = true;
|
2008-01-14 01:35:19 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gint wmd;
|
|
|
|
if (aShouldHide)
|
|
|
|
wmd = 0;
|
|
|
|
else
|
|
|
|
wmd = ConvertBorderStyles(mBorderStyle);
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
if (wmd != -1)
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_set_decorations(shellWindow, (GdkWMDecoration) wmd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-14 01:35:19 -08:00
|
|
|
if (wasVisible)
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_window_show(shellWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// For some window managers, adding or removing window decorations
|
|
|
|
// requires unmapping and remapping our toplevel window. Go ahead
|
|
|
|
// and flush the queue here so that we don't end up with a BadWindow
|
|
|
|
// error later when this happens (when the persistence timer fires
|
|
|
|
// and GetWindowPos is called)
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2011-09-22 13:58:07 -07:00
|
|
|
XSync(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) , False);
|
2008-08-06 13:48:55 -07:00
|
|
|
#else
|
|
|
|
gdk_flush ();
|
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-02-01 18:11:06 -08:00
|
|
|
check_for_rollup(gdouble aMouseX, gdouble aMouseY,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsWheel, bool aAlwaysRollup)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retVal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
|
|
|
|
|
|
|
if (rollupWidget && gRollupListener) {
|
|
|
|
GdkWindow *currentPopup =
|
|
|
|
(GdkWindow *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
2010-09-16 04:24:08 -07:00
|
|
|
if (aAlwaysRollup || !is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool rollup = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIsWheel) {
|
2011-11-08 11:59:07 -08:00
|
|
|
rollup = gRollupListener->ShouldRollupOnMouseWheelEvent();
|
2011-10-03 00:56:21 -07:00
|
|
|
retVal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// if we're dealing with menus, we probably have submenus and
|
2010-09-16 04:24:08 -07:00
|
|
|
// we don't want to rollup if the click is in a parent menu of
|
2007-03-22 10:30:00 -07:00
|
|
|
// the current submenu
|
2009-06-12 11:23:16 -07:00
|
|
|
PRUint32 popupsToRollup = PR_UINT32_MAX;
|
2011-11-08 11:59:07 -08:00
|
|
|
if (!aAlwaysRollup) {
|
2008-01-16 22:57:13 -08:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2011-11-08 11:59:07 -08:00
|
|
|
PRUint32 sameTypeCount = gRollupListener->GetSubmenuWidgetChain(&widgetChain);
|
2008-01-16 22:57:13 -08:00
|
|
|
for (PRUint32 i=0; i<widgetChain.Length(); ++i) {
|
2009-06-12 11:23:16 -07:00
|
|
|
nsIWidget* widget = widgetChain[i];
|
2008-01-16 22:57:13 -08:00
|
|
|
GdkWindow* currWindow =
|
|
|
|
(GdkWindow*) widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
|
2010-05-13 05:19:50 -07:00
|
|
|
// don't roll up if the mouse event occurred within a
|
|
|
|
// menu of the same type. If the mouse event occurred
|
2009-06-12 11:23:16 -07:00
|
|
|
// in a menu higher than that, roll up, but pass the
|
|
|
|
// number of popups to Rollup so that only those of the
|
|
|
|
// same type close up.
|
|
|
|
if (i < sameTypeCount) {
|
2011-10-03 00:56:21 -07:00
|
|
|
rollup = false;
|
2009-06-12 11:23:16 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-16 22:57:13 -08:00
|
|
|
}
|
|
|
|
} // foreach parent menu widget
|
2007-03-22 10:30:00 -07:00
|
|
|
} // if rollup listener knows about menus
|
|
|
|
|
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
2011-11-08 11:59:07 -08:00
|
|
|
gRollupListener->Rollup(popupsToRollup);
|
2009-06-12 11:23:16 -07:00
|
|
|
if (popupsToRollup == PR_UINT32_MAX) {
|
2011-10-03 00:56:21 -07:00
|
|
|
retVal = true;
|
2009-06-12 11:23:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow::DragInProgress(void)
|
|
|
|
{
|
2012-04-16 18:00:26 -07:00
|
|
|
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
|
|
|
|
|
|
|
|
if (!dragService)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDragSession> currentDragSession;
|
|
|
|
dragService->GetCurrentSession(getter_AddRefs(currentDragSession));
|
|
|
|
|
|
|
|
return currentDragSession != nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
is_mouse_in_window (GdkWindow* aWindow, gdouble aMouseX, gdouble aMouseY)
|
|
|
|
{
|
|
|
|
gint x = 0;
|
|
|
|
gint y = 0;
|
|
|
|
gint w, h;
|
|
|
|
|
|
|
|
gint offsetX = 0;
|
|
|
|
gint offsetY = 0;
|
|
|
|
|
2009-02-19 18:07:08 -08:00
|
|
|
GdkWindow *window = aWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (window) {
|
|
|
|
gint tmpX = 0;
|
|
|
|
gint tmpY = 0;
|
|
|
|
|
|
|
|
gdk_window_get_position(window, &tmpX, &tmpY);
|
2009-02-19 18:07:08 -08:00
|
|
|
GtkWidget *widget = get_gtk_widget_for_gdk_window(window);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if this is a window, compute x and y given its origin and our
|
|
|
|
// offset
|
|
|
|
if (GTK_IS_WINDOW(widget)) {
|
|
|
|
x = tmpX + offsetX;
|
|
|
|
y = tmpY + offsetY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offsetX += tmpX;
|
|
|
|
offsetY += tmpY;
|
|
|
|
window = gdk_window_get_parent(window);
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2009-02-02 09:49:58 -08:00
|
|
|
gdk_drawable_get_size(aWindow, &w, &h);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
w = gdk_window_get_width(aWindow);
|
|
|
|
h = gdk_window_get_height(aWindow);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aMouseX > x && aMouseX < x + w &&
|
|
|
|
aMouseY > y && aMouseY < y + h)
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static nsWindow *
|
2007-03-22 10:30:00 -07:00
|
|
|
get_window_for_gtk_widget(GtkWidget *widget)
|
|
|
|
{
|
2009-02-19 18:07:08 -08:00
|
|
|
gpointer user_data = g_object_get_data(G_OBJECT(widget), "nsWindow");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsWindow *>(user_data);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static nsWindow *
|
2007-03-22 10:30:00 -07:00
|
|
|
get_window_for_gdk_window(GdkWindow *window)
|
|
|
|
{
|
2009-02-19 18:07:08 -08:00
|
|
|
gpointer user_data = g_object_get_data(G_OBJECT(window), "nsWindow");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsWindow *>(user_data);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GtkWidget *
|
2007-03-22 10:30:00 -07:00
|
|
|
get_gtk_widget_for_gdk_window(GdkWindow *window)
|
|
|
|
{
|
|
|
|
gpointer user_data = NULL;
|
|
|
|
gdk_window_get_user_data(window, &user_data);
|
|
|
|
|
|
|
|
return GTK_WIDGET(user_data);
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GdkCursor *
|
2007-03-22 10:30:00 -07:00
|
|
|
get_gtk_cursor(nsCursor aCursor)
|
|
|
|
{
|
|
|
|
GdkCursor *gdkcursor = nsnull;
|
|
|
|
PRUint8 newType = 0xff;
|
|
|
|
|
|
|
|
if ((gdkcursor = gCursorCache[aCursor])) {
|
|
|
|
return gdkcursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aCursor) {
|
|
|
|
case eCursor_standard:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_LEFT_PTR);
|
|
|
|
break;
|
|
|
|
case eCursor_wait:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_WATCH);
|
|
|
|
break;
|
|
|
|
case eCursor_select:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_XTERM);
|
|
|
|
break;
|
|
|
|
case eCursor_hyperlink:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_HAND2);
|
|
|
|
break;
|
|
|
|
case eCursor_n_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_TOP_SIDE);
|
|
|
|
break;
|
|
|
|
case eCursor_s_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_BOTTOM_SIDE);
|
|
|
|
break;
|
|
|
|
case eCursor_w_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_LEFT_SIDE);
|
|
|
|
break;
|
|
|
|
case eCursor_e_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_RIGHT_SIDE);
|
|
|
|
break;
|
|
|
|
case eCursor_nw_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_TOP_LEFT_CORNER);
|
|
|
|
break;
|
|
|
|
case eCursor_se_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER);
|
|
|
|
break;
|
|
|
|
case eCursor_ne_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_TOP_RIGHT_CORNER);
|
|
|
|
break;
|
|
|
|
case eCursor_sw_resize:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER);
|
|
|
|
break;
|
|
|
|
case eCursor_crosshair:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_CROSSHAIR);
|
|
|
|
break;
|
|
|
|
case eCursor_move:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_FLEUR);
|
|
|
|
break;
|
|
|
|
case eCursor_help:
|
2007-09-17 14:03:34 -07:00
|
|
|
gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eCursor_copy: // CSS3
|
|
|
|
newType = MOZ_CURSOR_COPY;
|
|
|
|
break;
|
|
|
|
case eCursor_alias:
|
|
|
|
newType = MOZ_CURSOR_ALIAS;
|
|
|
|
break;
|
|
|
|
case eCursor_context_menu:
|
|
|
|
newType = MOZ_CURSOR_CONTEXT_MENU;
|
|
|
|
break;
|
|
|
|
case eCursor_cell:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_PLUS);
|
|
|
|
break;
|
|
|
|
case eCursor_grab:
|
|
|
|
newType = MOZ_CURSOR_HAND_GRAB;
|
|
|
|
break;
|
|
|
|
case eCursor_grabbing:
|
|
|
|
newType = MOZ_CURSOR_HAND_GRABBING;
|
|
|
|
break;
|
|
|
|
case eCursor_spinning:
|
|
|
|
newType = MOZ_CURSOR_SPINNING;
|
|
|
|
break;
|
|
|
|
case eCursor_zoom_in:
|
|
|
|
newType = MOZ_CURSOR_ZOOM_IN;
|
|
|
|
break;
|
|
|
|
case eCursor_zoom_out:
|
|
|
|
newType = MOZ_CURSOR_ZOOM_OUT;
|
|
|
|
break;
|
|
|
|
case eCursor_not_allowed:
|
|
|
|
case eCursor_no_drop:
|
|
|
|
newType = MOZ_CURSOR_NOT_ALLOWED;
|
|
|
|
break;
|
|
|
|
case eCursor_vertical_text:
|
|
|
|
newType = MOZ_CURSOR_VERTICAL_TEXT;
|
|
|
|
break;
|
|
|
|
case eCursor_all_scroll:
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_FLEUR);
|
|
|
|
break;
|
|
|
|
case eCursor_nesw_resize:
|
|
|
|
newType = MOZ_CURSOR_NESW_RESIZE;
|
|
|
|
break;
|
|
|
|
case eCursor_nwse_resize:
|
|
|
|
newType = MOZ_CURSOR_NWSE_RESIZE;
|
|
|
|
break;
|
|
|
|
case eCursor_ns_resize:
|
2009-07-04 03:03:16 -07:00
|
|
|
case eCursor_row_resize:
|
2007-03-22 10:30:00 -07:00
|
|
|
gdkcursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
|
|
|
|
break;
|
|
|
|
case eCursor_ew_resize:
|
2009-07-04 03:03:16 -07:00
|
|
|
case eCursor_col_resize:
|
2007-03-22 10:30:00 -07:00
|
|
|
gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
|
|
|
|
break;
|
2008-01-18 10:39:49 -08:00
|
|
|
case eCursor_none:
|
|
|
|
newType = MOZ_CURSOR_NONE;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
NS_ASSERTION(aCursor, "Invalid cursor type");
|
|
|
|
gdkcursor = gdk_cursor_new(GDK_LEFT_PTR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-14 02:34:31 -08:00
|
|
|
// If by now we don't have a xcursor, this means we have to make a custom
|
|
|
|
// one. First, we try creating a named cursor based on the hash of our
|
|
|
|
// custom bitmap, as libXcursor has some magic to convert bitmapped cursors
|
|
|
|
// to themed cursors
|
|
|
|
if (newType != 0xFF && GtkCursors[newType].hash) {
|
|
|
|
gdkcursor = gdk_cursor_new_from_name(gdk_display_get_default(),
|
|
|
|
GtkCursors[newType].hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we still don't have a xcursor, we now really create a bitmap cursor
|
|
|
|
if (newType != 0xff && !gdkcursor) {
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkPixbuf * cursor_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 32, 32);
|
|
|
|
if (!cursor_pixbuf)
|
2007-10-10 05:21:29 -07:00
|
|
|
return NULL;
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
guchar *data = gdk_pixbuf_get_pixels(cursor_pixbuf);
|
|
|
|
|
|
|
|
// Read data from GtkCursors and compose RGBA surface from 1bit bitmap and mask
|
|
|
|
// GtkCursors bits and mask are 32x32 monochrome bitmaps (1 bit for each pixel)
|
|
|
|
// so it's 128 byte array (4 bytes for are one bitmap row and there are 32 rows here).
|
|
|
|
const unsigned char *bits = GtkCursors[newType].bits;
|
|
|
|
const unsigned char *mask_bits = GtkCursors[newType].mask_bits;
|
|
|
|
|
|
|
|
for (int i = 0; i < 128; i++) {
|
|
|
|
char bit = *bits++;
|
|
|
|
char mask = *mask_bits++;
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
unsigned char pix = ~(((bit >> j) & 0x01) * 0xff);
|
|
|
|
*data++ = pix;
|
|
|
|
*data++ = pix;
|
|
|
|
*data++ = pix;
|
|
|
|
*data++ = (((mask >> j) & 0x01) * 0xff);
|
|
|
|
}
|
2007-10-10 05:21:29 -07:00
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
gdkcursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), cursor_pixbuf,
|
2007-03-22 10:30:00 -07:00
|
|
|
GtkCursors[newType].hot_x,
|
|
|
|
GtkCursors[newType].hot_y);
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
g_object_unref(cursor_pixbuf);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gCursorCache[aCursor] = gdkcursor;
|
|
|
|
|
|
|
|
return gdkcursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gtk callbacks
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
expose_event_cb(GtkWidget *widget, GdkEventExpose *event)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gdk_window(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// XXX We are so getting lucky here. We are doing all of
|
|
|
|
// mozilla's painting and then allowing default processing to occur.
|
|
|
|
// This means that Mozilla paints in all of it's stuff and then
|
|
|
|
// NO_WINDOW widgets (like scrollbars, for example) are painted by
|
|
|
|
// Gtk on top of what we painted.
|
|
|
|
|
|
|
|
// This return window->OnExposeEvent(widget, event); */
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
window->OnExposeEvent(event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
draw_window_of_widget(GtkWidget *widget, GdkWindow *aWindow, cairo_t *cr)
|
|
|
|
{
|
|
|
|
gpointer windowWidget;
|
|
|
|
gdk_window_get_user_data(aWindow, &windowWidget);
|
|
|
|
|
|
|
|
// aWindow is in another widget
|
|
|
|
if (windowWidget != widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_cairo_should_draw_window(cr, aWindow)) {
|
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gdk_window(aWindow);
|
|
|
|
if (!window) {
|
|
|
|
NS_WARNING("Cannot get nsWindow from GtkWidget");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_save(cr);
|
|
|
|
gtk_cairo_transform_to_window(cr, widget, aWindow);
|
|
|
|
// TODO - window->OnExposeEvent() can destroy this or other windows,
|
|
|
|
// do we need to handle it somehow?
|
|
|
|
window->OnExposeEvent(cr);
|
|
|
|
cairo_restore(cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *children = gdk_window_get_children(aWindow);
|
|
|
|
GList *child = children;
|
|
|
|
while (child) {
|
|
|
|
draw_window_of_widget(widget, GDK_WINDOW(child->data), cr);
|
|
|
|
child = g_list_next(child);
|
|
|
|
}
|
|
|
|
g_list_free(children);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
gboolean
|
|
|
|
expose_event_cb(GtkWidget *widget, cairo_t *cr)
|
|
|
|
{
|
|
|
|
draw_window_of_widget(widget, gtk_widget_get_window(widget), cr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#endif //MOZ_WIDGET_GTK2
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
configure_event_cb(GtkWidget *widget,
|
|
|
|
GdkEventConfigure *event)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return window->OnConfigureEvent(widget, event);
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static void
|
2009-05-14 19:14:45 -07:00
|
|
|
container_unrealize_cb (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->OnContainerUnrealize(widget);
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->OnSizeAllocate(widget, allocation);
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
delete_event_cb(GtkWidget *widget, GdkEventAny *event)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
window->OnDeleteEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
enter_notify_event_cb(GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gdk_window(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
window->OnEnterNotifyEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
leave_notify_event_cb(GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (is_parent_grab_leave(event)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-19 03:21:05 -08:00
|
|
|
// bug 369599: Suppress LeaveNotify events caused by pointer grabs to
|
|
|
|
// avoid generating spurious mouse exit events.
|
|
|
|
gint x = gint(event->x_root);
|
|
|
|
gint y = gint(event->y_root);
|
|
|
|
GdkDisplay* display = gtk_widget_get_display(widget);
|
|
|
|
GdkWindow* winAtPt = gdk_display_get_window_at_pointer(display, &x, &y);
|
|
|
|
if (winAtPt == event->window) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gdk_window(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
window->OnLeaveNotifyEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static nsWindow*
|
2007-12-13 23:00:44 -08:00
|
|
|
GetFirstNSWindowForGDKWindow(GdkWindow *aGdkWindow)
|
|
|
|
{
|
|
|
|
nsWindow* window;
|
|
|
|
while (!(window = get_window_for_gdk_window(aGdkWindow))) {
|
|
|
|
// The event has bubbled to the moz_container widget as passed into each caller's *widget parameter,
|
|
|
|
// but its corresponding nsWindow is an ancestor of the window that we need. Instead, look at
|
|
|
|
// event->window and find the first ancestor nsWindow of it because event->window may be in a plugin.
|
|
|
|
aGdkWindow = gdk_window_get_parent(aGdkWindow);
|
|
|
|
if (!aGdkWindow) {
|
|
|
|
window = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-13 12:19:59 -08:00
|
|
|
UpdateLastInputEventTime(event);
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2007-12-13 23:00:44 -08:00
|
|
|
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
2007-12-13 23:00:44 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
window->OnMotionNotifyEvent(widget, event);
|
|
|
|
|
2012-05-02 23:23:31 -07:00
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
2008-11-26 05:43:36 -08:00
|
|
|
gdk_event_request_motions(event);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
button_press_event_cb(GtkWidget *widget, GdkEventButton *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-13 12:19:59 -08:00
|
|
|
UpdateLastInputEventTime(event);
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2007-12-13 23:00:44 -08:00
|
|
|
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
2007-12-13 23:00:44 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
window->OnButtonPressEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
button_release_event_cb(GtkWidget *widget, GdkEventButton *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-13 12:19:59 -08:00
|
|
|
UpdateLastInputEventTime(event);
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2007-12-13 23:00:44 -08:00
|
|
|
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
2007-12-13 23:00:44 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
window->OnButtonReleaseEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
focus_in_event_cb(GtkWidget *widget, GdkEventFocus *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
window->OnContainerFocusInEvent(widget, event);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
focus_out_event_cb(GtkWidget *widget, GdkEventFocus *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
window->OnContainerFocusOutEvent(widget, event);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-06-17 18:15:03 -07:00
|
|
|
// For long-lived popup windows that don't really take focus themselves but
|
|
|
|
// may have elements that accept keyboard input when the parent window is
|
|
|
|
// active, focus is handled specially. These windows include noautohide
|
|
|
|
// panels. (This special handling is not necessary for temporary popups where
|
|
|
|
// the keyboard is grabbed.)
|
|
|
|
//
|
|
|
|
// Mousing over or clicking on these windows should not cause them to steal
|
|
|
|
// focus from their parent windows, so, the input field of WM_HINTS is set to
|
|
|
|
// False to request that the window manager not set the input focus to this
|
|
|
|
// window. http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
|
|
|
|
//
|
|
|
|
// However, these windows can still receive WM_TAKE_FOCUS messages from the
|
|
|
|
// window manager, so they can still detect when the user has indicated that
|
|
|
|
// they wish to direct keyboard input at these windows. When the window
|
|
|
|
// manager offers focus to these windows (after a mouse over or click, for
|
|
|
|
// example), a request to make the parent window active is issued. When the
|
|
|
|
// parent window becomes active, keyboard events will be received.
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GdkFilterReturn
|
2010-06-17 18:15:03 -07:00
|
|
|
popup_take_focus_filter(GdkXEvent *gdk_xevent,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
XEvent* xevent = static_cast<XEvent*>(gdk_xevent);
|
|
|
|
if (xevent->type != ClientMessage)
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
XClientMessageEvent& xclient = xevent->xclient;
|
|
|
|
if (xclient.message_type != gdk_x11_get_xatom_by_name("WM_PROTOCOLS"))
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
Atom atom = xclient.data.l[0];
|
|
|
|
if (atom != gdk_x11_get_xatom_by_name("WM_TAKE_FOCUS"))
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
guint32 timestamp = xclient.data.l[1];
|
|
|
|
|
|
|
|
GtkWidget* widget = get_gtk_widget_for_gdk_window(event->any.window);
|
|
|
|
if (!widget)
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
GtkWindow* parent = gtk_window_get_transient_for(GTK_WINDOW(widget));
|
|
|
|
if (!parent)
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
if (gtk_window_is_active(parent))
|
|
|
|
return GDK_FILTER_REMOVE; // leave input focus on the parent
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow* parent_window = gtk_widget_get_window(GTK_WIDGET(parent));
|
2010-06-17 18:15:03 -07:00
|
|
|
if (!parent_window)
|
|
|
|
return GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
// In case the parent has not been deconified.
|
|
|
|
gdk_window_show_unraised(parent_window);
|
|
|
|
|
|
|
|
// Request focus on the parent window.
|
|
|
|
// Use gdk_window_focus rather than gtk_window_present to avoid
|
|
|
|
// raising the parent window.
|
|
|
|
gdk_window_focus(parent_window, timestamp);
|
|
|
|
return GDK_FILTER_REMOVE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GdkFilterReturn
|
2007-04-29 17:46:47 -07:00
|
|
|
plugin_window_filter_func(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *plugin_window;
|
|
|
|
XEvent *xevent;
|
|
|
|
Window xeventWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> nswindow = (nsWindow*)data;
|
2007-03-22 10:30:00 -07:00
|
|
|
GdkFilterReturn return_val;
|
|
|
|
|
|
|
|
xevent = (XEvent *)gdk_xevent;
|
|
|
|
return_val = GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case CreateNotify:
|
|
|
|
case ReparentNotify:
|
|
|
|
if (xevent->type==CreateNotify) {
|
2011-09-22 13:58:07 -07:00
|
|
|
xeventWindow = xevent->xcreatewindow.window;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (xevent->xreparent.event != xevent->xreparent.parent)
|
|
|
|
break;
|
2011-09-22 13:58:07 -07:00
|
|
|
xeventWindow = xevent->xreparent.window;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
plugin_window = gdk_window_lookup(xeventWindow);
|
|
|
|
#else
|
|
|
|
plugin_window = gdk_x11_window_lookup_for_display(
|
|
|
|
gdk_x11_lookup_xdisplay(xevent->xcreatewindow.display), xeventWindow);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
if (plugin_window) {
|
2009-02-19 18:07:08 -08:00
|
|
|
GtkWidget *widget =
|
|
|
|
get_gtk_widget_for_gdk_window(plugin_window);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
// TODO GTK3
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GTK_IS_XTBIN(widget)) {
|
|
|
|
nswindow->SetPluginType(nsWindow::PluginType_NONXEMBED);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-22 13:58:07 -07:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if(GTK_IS_SOCKET(widget)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nswindow->SetPluginType(nsWindow::PluginType_XEMBED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nswindow->SetPluginType(nsWindow::PluginType_NONXEMBED);
|
|
|
|
return_val = GDK_FILTER_REMOVE;
|
|
|
|
break;
|
|
|
|
case EnterNotify:
|
|
|
|
nswindow->SetNonXEmbedPluginFocus();
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
|
|
|
gdk_window_remove_filter
|
|
|
|
((GdkWindow*)(nswindow->GetNativeData(NS_NATIVE_WINDOW)),
|
|
|
|
plugin_window_filter_func,
|
|
|
|
nswindow);
|
|
|
|
// Currently we consider all plugins are non-xembed and calls
|
|
|
|
// LoseNonXEmbedPluginFocus without any checking.
|
|
|
|
nswindow->LoseNonXEmbedPluginFocus();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GdkFilterReturn
|
2007-04-29 17:46:47 -07:00
|
|
|
plugin_client_message_filter(GdkXEvent *gdk_xevent,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
XEvent *xevent;
|
|
|
|
xevent = (XEvent *)gdk_xevent;
|
|
|
|
|
|
|
|
GdkFilterReturn return_val;
|
|
|
|
return_val = GDK_FILTER_CONTINUE;
|
|
|
|
|
|
|
|
if (!gPluginFocusWindow || xevent->type!=ClientMessage) {
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When WM sends out WM_TAKE_FOCUS, gtk2 will use XSetInputFocus
|
|
|
|
// to set the focus to the focus proxy. To prevent this happen
|
|
|
|
// while the focus is on the plugin, we filter the WM_TAKE_FOCUS
|
|
|
|
// out.
|
|
|
|
if (gdk_x11_get_xatom_by_name("WM_PROTOCOLS")
|
|
|
|
!= xevent->xclient.message_type) {
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Atom) xevent->xclient.data.l[0] ==
|
|
|
|
gdk_x11_get_xatom_by_name("WM_TAKE_FOCUS")) {
|
|
|
|
// block it from gtk2.0 focus proxy
|
|
|
|
return_val = GDK_FILTER_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_val;
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif /* MOZ_X11 */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
key_press_event_cb(GtkWidget *widget, GdkEventKey *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("key_press_event_cb\n"));
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2012-02-13 12:19:59 -08:00
|
|
|
UpdateLastInputEventTime(event);
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// find the window with focus and dispatch this event to that widget
|
|
|
|
nsWindow *window = get_window_for_gtk_widget(widget);
|
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> focusWindow = gFocusWindow ? gFocusWindow : window;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-15 03:34:05 -08:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// Keyboard repeat can cause key press events to queue up when there are
|
|
|
|
// slow event handlers (bug 301029). Throttle these events by removing
|
|
|
|
// consecutive pending duplicate KeyPress events to the same window.
|
|
|
|
// We use the event time of the last one.
|
|
|
|
// Note: GDK calls XkbSetDetectableAutorepeat so that KeyRelease events
|
|
|
|
// are generated only when the key is physically released.
|
|
|
|
#define NS_GDKEVENT_MATCH_MASK 0x1FFF /* GDK_SHIFT_MASK .. GDK_BUTTON5_MASK */
|
|
|
|
GdkDisplay* gdkDisplay = gtk_widget_get_display(widget);
|
|
|
|
Display* dpy = GDK_DISPLAY_XDISPLAY(gdkDisplay);
|
|
|
|
while (XPending(dpy)) {
|
|
|
|
XEvent next_event;
|
|
|
|
XPeekEvent(dpy, &next_event);
|
|
|
|
GdkWindow* nextGdkWindow =
|
2011-09-22 13:58:07 -07:00
|
|
|
gdk_x11_window_lookup_for_display(gdkDisplay, next_event.xany.window);
|
2008-12-15 03:34:05 -08:00
|
|
|
if (nextGdkWindow != event->window ||
|
|
|
|
next_event.type != KeyPress ||
|
|
|
|
next_event.xkey.keycode != event->hardware_keycode ||
|
|
|
|
next_event.xkey.state != (event->state & NS_GDKEVENT_MATCH_MASK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
XNextEvent(dpy, &next_event);
|
|
|
|
event->time = next_event.xkey.time;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-05 16:44:18 -07:00
|
|
|
return focusWindow->OnKeyPressEvent(widget, event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
key_release_event_cb(GtkWidget *widget, GdkEventKey *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("key_release_event_cb\n"));
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2012-02-13 12:19:59 -08:00
|
|
|
UpdateLastInputEventTime(event);
|
2009-09-17 10:13:45 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// find the window with focus and dispatch this event to that widget
|
|
|
|
nsWindow *window = get_window_for_gtk_widget(widget);
|
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> focusWindow = gFocusWindow ? gFocusWindow : window;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-05-05 16:44:18 -07:00
|
|
|
return focusWindow->OnKeyReleaseEvent(widget, event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-04-29 17:46:47 -07:00
|
|
|
scroll_event_cb(GtkWidget *widget, GdkEventScroll *event)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-13 23:00:44 -08:00
|
|
|
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
|
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
window->OnScrollEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
visibility_notify_event_cb (GtkWidget *widget, GdkEventVisibility *event)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gdk_window(event->window);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
window->OnVisibilityNotifyEvent(widget, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-11-01 18:03:12 -08:00
|
|
|
static void
|
|
|
|
hierarchy_changed_cb (GtkWidget *widget,
|
|
|
|
GtkWidget *previous_toplevel)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel(widget);
|
|
|
|
GdkWindowState old_window_state = GDK_WINDOW_STATE_WITHDRAWN;
|
|
|
|
GdkEventWindowState event;
|
|
|
|
|
|
|
|
event.new_window_state = GDK_WINDOW_STATE_WITHDRAWN;
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW(previous_toplevel)) {
|
|
|
|
g_signal_handlers_disconnect_by_func(previous_toplevel,
|
|
|
|
FuncToGpointer(window_state_event_cb),
|
|
|
|
widget);
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *win = gtk_widget_get_window(previous_toplevel);
|
|
|
|
if (win) {
|
|
|
|
old_window_state = gdk_window_get_state(win);
|
2009-11-01 18:03:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW(toplevel)) {
|
|
|
|
g_signal_connect_swapped(toplevel, "window-state-event",
|
|
|
|
G_CALLBACK(window_state_event_cb), widget);
|
2011-09-22 13:58:07 -07:00
|
|
|
GdkWindow *win = gtk_widget_get_window(toplevel);
|
|
|
|
if (win) {
|
|
|
|
event.new_window_state = gdk_window_get_state(win);
|
2009-11-01 18:03:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.changed_mask = static_cast<GdkWindowState>
|
|
|
|
(old_window_state ^ event.new_window_state);
|
|
|
|
|
|
|
|
if (event.changed_mask) {
|
|
|
|
event.type = GDK_WINDOW_STATE;
|
|
|
|
event.window = NULL;
|
|
|
|
event.send_event = TRUE;
|
|
|
|
window_state_event_cb(widget, &event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
window->OnWindowStateEvent(widget, event);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
theme_changed_cb (GtkSettings *settings, GParamSpec *pspec, nsWindow *data)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = data;
|
|
|
|
window->ThemeChanged();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// These are all of our drag and drop operations
|
|
|
|
|
|
|
|
void
|
2008-08-27 05:07:27 -07:00
|
|
|
nsWindow::InitDragEvent(nsDragEvent &aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// set the keyboard modifiers
|
2012-02-21 23:34:31 -08:00
|
|
|
guint modifierState = KeymapWrapper::GetCurrentModifierState();
|
|
|
|
KeymapWrapper::InitInputEvent(aEvent, modifierState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
drag_motion_event_cb(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(aWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-04-18 23:18:31 -07:00
|
|
|
// figure out which internal widget this drag motion actually happened on
|
|
|
|
nscoord retx = 0;
|
|
|
|
nscoord rety = 0;
|
|
|
|
|
|
|
|
GdkWindow *innerWindow =
|
|
|
|
get_inner_gdk_window(gtk_widget_get_window(aWidget), aX, aY,
|
|
|
|
&retx, &rety);
|
|
|
|
nsRefPtr<nsWindow> innerMostWindow = get_window_for_gdk_window(innerWindow);
|
|
|
|
|
|
|
|
if (!innerMostWindow) {
|
|
|
|
innerMostWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGDRAG(("nsWindow drag-motion signal for %p\n", (void*)innerMostWindow));
|
|
|
|
|
|
|
|
return nsDragService::GetInstance()->
|
|
|
|
ScheduleMotionEvent(innerMostWindow, aDragContext,
|
|
|
|
nsIntPoint(aX, aY), aTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-05-17 06:55:16 -07:00
|
|
|
|
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
drag_leave_event_cb(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData)
|
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(aWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2012-04-18 23:18:31 -07:00
|
|
|
nsDragService *dragService = nsDragService::GetInstance();
|
|
|
|
|
|
|
|
nsWindow *mostRecentDragWindow = dragService->GetMostRecentDestWindow();
|
|
|
|
if (!mostRecentDragWindow) {
|
2012-04-18 23:18:31 -07:00
|
|
|
// This can happen when the target will not accept a drop. A GTK drag
|
|
|
|
// source sends the leave message to the destination before the
|
|
|
|
// drag-failed signal on the source widget, but the leave message goes
|
|
|
|
// via the X server, and so doesn't get processed at least until the
|
|
|
|
// event loop runs again.
|
2012-04-18 23:18:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *mozContainer = mostRecentDragWindow->GetMozContainerWidget();
|
|
|
|
if (aWidget != mozContainer)
|
|
|
|
{
|
|
|
|
// When the drag moves between widgets, GTK can send leave signal for
|
|
|
|
// the old widget after the motion or drop signal for the new widget.
|
|
|
|
// We'll send the leave event when the motion or drop event is run.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGDRAG(("nsWindow drag-leave signal for %p\n",
|
|
|
|
(void*)mostRecentDragWindow));
|
|
|
|
|
|
|
|
dragService->ScheduleLeaveEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
drag_drop_event_cb(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
guint aTime,
|
2011-05-19 03:51:11 -07:00
|
|
|
gpointer aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-29 17:46:47 -07:00
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(aWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-04-18 23:18:31 -07:00
|
|
|
// figure out which internal widget this drag motion actually happened on
|
|
|
|
nscoord retx = 0;
|
|
|
|
nscoord rety = 0;
|
|
|
|
|
|
|
|
GdkWindow *innerWindow =
|
|
|
|
get_inner_gdk_window(gtk_widget_get_window(aWidget), aX, aY,
|
|
|
|
&retx, &rety);
|
|
|
|
nsRefPtr<nsWindow> innerMostWindow = get_window_for_gdk_window(innerWindow);
|
|
|
|
|
|
|
|
if (!innerMostWindow) {
|
|
|
|
innerMostWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGDRAG(("nsWindow drag-drop signal for %p\n", (void*)innerMostWindow));
|
|
|
|
|
|
|
|
return nsDragService::GetInstance()->
|
|
|
|
ScheduleDropEvent(innerMostWindow, aDragContext,
|
|
|
|
nsIntPoint(aX, aY), aTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static void
|
2007-04-29 17:46:47 -07:00
|
|
|
drag_data_received_event_cb(GtkWidget *aWidget,
|
|
|
|
GdkDragContext *aDragContext,
|
|
|
|
gint aX,
|
|
|
|
gint aY,
|
|
|
|
GtkSelectionData *aSelectionData,
|
|
|
|
guint aInfo,
|
|
|
|
guint aTime,
|
|
|
|
gpointer aData)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsWindow> window = get_window_for_gtk_widget(aWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->OnDragDataReceivedEvent(aWidget,
|
|
|
|
aDragContext,
|
|
|
|
aX, aY,
|
|
|
|
aSelectionData,
|
|
|
|
aInfo, aTime, aData);
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
initialize_prefs(void)
|
|
|
|
{
|
2011-05-28 00:03:00 -07:00
|
|
|
gRaiseWindows =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool("mozilla.widget.raise-on-setfocus", true);
|
2008-09-17 14:15:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static GdkWindow *
|
2007-03-22 10:30:00 -07:00
|
|
|
get_inner_gdk_window (GdkWindow *aWindow,
|
|
|
|
gint x, gint y,
|
|
|
|
gint *retx, gint *rety)
|
|
|
|
{
|
2011-09-22 13:58:07 -07:00
|
|
|
gint cx, cy, cw, ch;
|
2011-05-11 06:12:15 -07:00
|
|
|
GList *children = gdk_window_peek_children(aWindow);
|
|
|
|
for (GList *child = g_list_last(children);
|
|
|
|
child;
|
|
|
|
child = g_list_previous(child)) {
|
|
|
|
GdkWindow *childWindow = (GdkWindow *) child->data;
|
|
|
|
if (get_window_for_gdk_window(childWindow)) {
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
gdk_window_get_geometry(childWindow, &cx, &cy, &cw, &ch, NULL);
|
|
|
|
#else
|
|
|
|
gdk_window_get_geometry(childWindow, &cx, &cy, &cw, &ch);
|
|
|
|
#endif
|
2011-05-11 06:12:15 -07:00
|
|
|
if ((cx < x) && (x < (cx + cw)) &&
|
|
|
|
(cy < y) && (y < (cy + ch)) &&
|
|
|
|
gdk_window_is_visible(childWindow)) {
|
|
|
|
return get_inner_gdk_window(childWindow,
|
|
|
|
x - cx, y - cy,
|
|
|
|
retx, rety);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*retx = x;
|
|
|
|
*rety = y;
|
|
|
|
return aWindow;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2007-03-22 10:30:00 -07:00
|
|
|
is_context_menu_key(const nsKeyEvent& aKeyEvent)
|
|
|
|
{
|
2012-04-24 20:00:02 -07:00
|
|
|
return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.IsShift() &&
|
|
|
|
!aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
|
|
|
|
!aKeyEvent.IsAlt()) ||
|
|
|
|
(aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.IsShift() &&
|
|
|
|
!aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
|
|
|
|
!aKeyEvent.IsAlt()));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static int
|
2007-03-22 10:30:00 -07:00
|
|
|
is_parent_ungrab_enter(GdkEventCrossing *aEvent)
|
|
|
|
{
|
|
|
|
return (GDK_CROSSING_UNGRAB == aEvent->mode) &&
|
|
|
|
((GDK_NOTIFY_ANCESTOR == aEvent->detail) ||
|
|
|
|
(GDK_NOTIFY_VIRTUAL == aEvent->detail));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-17 06:55:16 -07:00
|
|
|
static int
|
2007-03-22 10:30:00 -07:00
|
|
|
is_parent_grab_leave(GdkEventCrossing *aEvent)
|
|
|
|
{
|
|
|
|
return (GDK_CROSSING_GRAB == aEvent->mode) &&
|
|
|
|
((GDK_NOTIFY_ANCESTOR == aEvent->detail) ||
|
|
|
|
(GDK_NOTIFY_VIRTUAL == aEvent->detail));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
void
|
|
|
|
nsWindow::CreateRootAccessible()
|
|
|
|
{
|
|
|
|
if (mIsTopLevel && !mRootAccessible) {
|
2011-05-28 02:26:56 -07:00
|
|
|
LOG(("nsWindow:: Create Toplevel Accessibility\n"));
|
2010-05-11 23:47:35 -07:00
|
|
|
nsAccessible *acc = DispatchAccessibleEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (acc) {
|
|
|
|
mRootAccessible = acc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-11 23:47:35 -07:00
|
|
|
nsAccessible*
|
|
|
|
nsWindow::DispatchAccessibleEvent()
|
2010-05-12 02:14:50 -07:00
|
|
|
{
|
2011-10-03 00:56:21 -07:00
|
|
|
nsAccessibleEvent event(true, NS_GETACCESSIBLE, this);
|
2010-05-12 02:14:50 -07:00
|
|
|
|
2010-05-11 23:47:35 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return event.mAccessible;
|
2010-05-12 02:14:50 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 23:47:35 -07:00
|
|
|
void
|
|
|
|
nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-04 17:54:17 -08:00
|
|
|
if (!a11y::ShouldA11yBeEnabled()) {
|
2010-05-11 23:47:35 -07:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-11 23:47:35 -07:00
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
if (!accService) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-12 02:14:50 -07:00
|
|
|
|
2010-09-22 20:35:39 -07:00
|
|
|
// Get the root document accessible and fire event to it.
|
2010-05-11 23:47:35 -07:00
|
|
|
nsAccessible *acc = DispatchAccessibleEvent();
|
2010-09-22 20:35:39 -07:00
|
|
|
if (acc) {
|
|
|
|
accService->FireAccessibleEvent(aEventType, acc);
|
2010-05-11 23:47:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-18 18:13:27 -07:00
|
|
|
nsWindow::DispatchActivateEventAccessible(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-11 23:47:35 -07:00
|
|
|
DispatchEventToRootAccessible(nsIAccessibleEvent::EVENT_WINDOW_ACTIVATE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-18 18:13:27 -07:00
|
|
|
nsWindow::DispatchDeactivateEventAccessible(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-11 23:47:35 -07:00
|
|
|
DispatchEventToRootAccessible(nsIAccessibleEvent::EVENT_WINDOW_DEACTIVATE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-18 18:13:27 -07:00
|
|
|
|
2011-03-26 09:06:00 -07:00
|
|
|
void
|
|
|
|
nsWindow::DispatchMaximizeEventAccessible(void)
|
|
|
|
{
|
|
|
|
DispatchEventToRootAccessible(nsIAccessibleEvent::EVENT_WINDOW_MAXIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchMinimizeEventAccessible(void)
|
|
|
|
{
|
|
|
|
DispatchEventToRootAccessible(nsIAccessibleEvent::EVENT_WINDOW_MINIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchRestoreEventAccessible(void)
|
|
|
|
{
|
|
|
|
DispatchEventToRootAccessible(nsIAccessibleEvent::EVENT_WINDOW_RESTORE);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* #ifdef ACCESSIBILITY */
|
|
|
|
|
|
|
|
// nsChildWindow class
|
|
|
|
|
|
|
|
nsChildWindow::nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChildWindow::~nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ResetInputState()
|
|
|
|
{
|
2010-03-18 21:21:16 -07:00
|
|
|
return mIMModule ? mIMModule->ResetInputState(this) : NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-11-27 03:51:52 -08:00
|
|
|
if (!mIMModule) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIMModule->SetInputContext(this, &aContext, &aAction);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContext context;
|
2010-03-18 21:21:16 -07:00
|
|
|
if (!mIMModule) {
|
2011-11-27 03:51:53 -08:00
|
|
|
context.mIMEState.mEnabled = IMEState::DISABLED;
|
|
|
|
context.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
2011-11-27 03:51:52 -08:00
|
|
|
} else {
|
|
|
|
context = mIMModule->GetInputContext();
|
2010-03-18 21:21:16 -07:00
|
|
|
}
|
2011-11-27 03:51:52 -08:00
|
|
|
return context;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CancelIMEComposition()
|
|
|
|
{
|
2010-03-18 21:21:16 -07:00
|
|
|
return mIMModule ? mIMModule->CancelIMEComposition(this) : NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-18 21:21:16 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::OnIMEFocusChange(bool aFocus)
|
2010-03-18 21:21:16 -07:00
|
|
|
{
|
|
|
|
if (mIMModule) {
|
|
|
|
mIMModule->OnFocusChangeInGecko(aFocus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-20 05:01:48 -07:00
|
|
|
// XXX Return NS_ERROR_NOT_IMPLEMENTED, see bug 496360.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-06-16 12:19:46 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::GetToggledKeyState(PRUint32 aKeyCode, bool* aLEDState)
|
2007-06-16 12:19:46 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLEDState);
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
KeymapWrapper::Modifiers modifier;
|
2007-06-16 12:19:46 -07:00
|
|
|
switch (aKeyCode) {
|
2012-02-21 23:34:31 -08:00
|
|
|
case NS_VK_CAPS_LOCK: modifier = KeymapWrapper::CAPS_LOCK; break;
|
|
|
|
case NS_VK_NUM_LOCK: modifier = KeymapWrapper::NUM_LOCK; break;
|
|
|
|
case NS_VK_SCROLL_LOCK: modifier = KeymapWrapper::SCROLL_LOCK; break;
|
|
|
|
default: return NS_ERROR_INVALID_ARG;
|
2007-06-16 12:19:46 -07:00
|
|
|
}
|
|
|
|
|
2012-02-21 23:34:31 -08:00
|
|
|
*aLEDState =
|
|
|
|
KeymapWrapper::AreModifiersCurrentlyActive(modifier);
|
2007-06-16 12:19:46 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
|
2008-06-18 02:20:29 -07:00
|
|
|
/* static */ already_AddRefed<gfxASurface>
|
|
|
|
nsWindow::GetSurfaceForGdkDrawable(GdkDrawable* aDrawable,
|
2009-01-14 19:27:09 -08:00
|
|
|
const nsIntSize& aSize)
|
2008-06-18 02:20:29 -07:00
|
|
|
{
|
|
|
|
GdkVisual* visual = gdk_drawable_get_visual(aDrawable);
|
2010-07-01 20:55:24 -07:00
|
|
|
Screen* xScreen =
|
|
|
|
gdk_x11_screen_get_xscreen(gdk_drawable_get_screen(aDrawable));
|
|
|
|
Display* xDisplay = DisplayOfScreen(xScreen);
|
2008-06-18 02:20:29 -07:00
|
|
|
Drawable xDrawable = gdk_x11_drawable_get_xid(aDrawable);
|
|
|
|
|
2008-09-17 14:15:52 -07:00
|
|
|
gfxASurface* result = nsnull;
|
|
|
|
|
|
|
|
if (visual) {
|
|
|
|
Visual* xVisual = gdk_x11_visual_get_xvisual(visual);
|
|
|
|
|
|
|
|
result = new gfxXlibSurface(xDisplay, xDrawable, xVisual,
|
|
|
|
gfxIntSize(aSize.width, aSize.height));
|
|
|
|
} else {
|
|
|
|
// no visual? we must be using an xrender format. Find a format
|
|
|
|
// for this depth.
|
|
|
|
XRenderPictFormat *pf = NULL;
|
|
|
|
switch (gdk_drawable_get_depth(aDrawable)) {
|
|
|
|
case 32:
|
|
|
|
pf = XRenderFindStandardFormat(xDisplay, PictStandardARGB32);
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
pf = XRenderFindStandardFormat(xDisplay, PictStandardRGB24);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Don't know how to handle the given depth!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-01 20:55:24 -07:00
|
|
|
result = new gfxXlibSurface(xScreen, xDrawable, pf,
|
2008-09-17 14:15:52 -07:00
|
|
|
gfxIntSize(aSize.width, aSize.height));
|
|
|
|
}
|
|
|
|
|
2008-06-18 02:20:29 -07:00
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif
|
2008-06-18 02:20:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// return the gfxASurface for rendering to this widget
|
|
|
|
gfxASurface*
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindow::GetThebesSurface()
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
nsWindow::GetThebesSurface(cairo_t *cr)
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-10 13:57:25 -08:00
|
|
|
if (!mGdkWindow)
|
|
|
|
return nsnull;
|
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if !defined(MOZ_WIDGET_GTK2)
|
|
|
|
cairo_surface_t *surf = cairo_get_target(cr);
|
|
|
|
if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
NS_NOTREACHED("Missing cairo target?");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_GTK2
|
2008-08-06 13:48:55 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
gint width, height;
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
|
|
|
gdk_drawable_get_size(GDK_DRAWABLE(mGdkWindow), &width, &height);
|
|
|
|
#else
|
|
|
|
width = gdk_window_get_width(mGdkWindow);
|
|
|
|
height = gdk_window_get_height(mGdkWindow);
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
// Owen Taylor says this is the right thing to do!
|
2011-06-02 05:56:50 -07:00
|
|
|
width = NS_MIN(32767, width);
|
|
|
|
height = NS_MIN(32767, height);
|
2010-09-23 18:00:06 -07:00
|
|
|
gfxIntSize size(width, height);
|
2011-09-22 13:58:07 -07:00
|
|
|
|
|
|
|
GdkVisual *gdkVisual = gdk_window_get_visual(mGdkWindow);
|
|
|
|
Visual* visual = gdk_x11_visual_get_xvisual(gdkVisual);
|
2010-09-23 18:00:06 -07:00
|
|
|
|
|
|
|
# ifdef MOZ_HAVE_SHMIMAGE
|
2011-09-28 23:19:26 -07:00
|
|
|
bool usingShm = false;
|
2010-10-26 21:56:31 -07:00
|
|
|
if (nsShmImage::UseShm()) {
|
2010-09-23 18:00:06 -07:00
|
|
|
// EnsureShmImage() is a dangerous interface, but we guarantee
|
|
|
|
// that the thebes surface and the shmimage have the same
|
|
|
|
// lifetime
|
2010-10-26 21:56:31 -07:00
|
|
|
mThebesSurface =
|
|
|
|
nsShmImage::EnsureShmImage(size,
|
2011-09-22 13:58:07 -07:00
|
|
|
visual, gdk_visual_get_depth(gdkVisual),
|
2010-10-26 21:56:31 -07:00
|
|
|
mShmImage);
|
2010-09-23 18:00:06 -07:00
|
|
|
usingShm = mThebesSurface != nsnull;
|
|
|
|
}
|
|
|
|
if (!usingShm)
|
|
|
|
# endif // MOZ_HAVE_SHMIMAGE
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2011-09-22 13:58:07 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK2)
|
2008-08-06 13:48:55 -07:00
|
|
|
mThebesSurface = new gfxXlibSurface
|
2011-09-22 13:58:07 -07:00
|
|
|
(GDK_WINDOW_XDISPLAY(mGdkWindow),
|
|
|
|
gdk_x11_window_get_xid(mGdkWindow),
|
2010-09-23 18:00:06 -07:00
|
|
|
visual,
|
|
|
|
size);
|
2011-09-22 13:58:07 -07:00
|
|
|
#else
|
|
|
|
#if MOZ_TREE_CAIRO
|
|
|
|
#error "cairo-gtk3 target must be built with --enable-system-cairo"
|
|
|
|
#else
|
|
|
|
mThebesSurface = gfxASurface::Wrap(surf);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2008-03-14 01:08:18 -07:00
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
// if the surface creation is reporting an error, then
|
|
|
|
// we don't have a surface to give back
|
|
|
|
if (mThebesSurface && mThebesSurface->CairoStatus() != 0) {
|
|
|
|
mThebesSurface = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mThebesSurface;
|
|
|
|
}
|
2007-12-11 02:08:35 -08:00
|
|
|
|
2010-07-17 01:11:54 -07:00
|
|
|
// Code shared begin BeginMoveDrag and BeginResizeDrag
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-17 01:11:54 -07:00
|
|
|
nsWindow::GetDragInfo(nsMouseEvent* aMouseEvent,
|
|
|
|
GdkWindow** aWindow, gint* aButton,
|
|
|
|
gint* aRootX, gint* aRootY)
|
|
|
|
{
|
|
|
|
if (aMouseEvent->button != nsMouseEvent::eLeftButton) {
|
|
|
|
// we can only begin a move drag with the left mouse button
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2010-07-17 01:11:54 -07:00
|
|
|
}
|
|
|
|
*aButton = 1;
|
|
|
|
|
|
|
|
// get the gdk window for this widget
|
|
|
|
GdkWindow* gdk_window = mGdkWindow;
|
|
|
|
if (!gdk_window) {
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2010-07-17 01:11:54 -07:00
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(GDK_IS_WINDOW(gdk_window), "must really be window");
|
|
|
|
|
|
|
|
// find the top-level window
|
|
|
|
gdk_window = gdk_window_get_toplevel(gdk_window);
|
|
|
|
NS_ABORT_IF_FALSE(gdk_window,
|
|
|
|
"gdk_window_get_toplevel should not return null");
|
|
|
|
*aWindow = gdk_window;
|
|
|
|
|
|
|
|
if (!aMouseEvent->widget) {
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2010-07-17 01:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: It would be nice to have the widget position at the time
|
|
|
|
// of the event, but it's relatively unlikely that the widget has
|
|
|
|
// moved since the mousedown. (On the other hand, it's quite likely
|
|
|
|
// that the mouse has moved, which is why we use the mouse position
|
|
|
|
// from the event.)
|
|
|
|
nsIntPoint offset = aMouseEvent->widget->WidgetToScreenOffset();
|
|
|
|
*aRootX = aMouseEvent->refPoint.x + offset.x;
|
|
|
|
*aRootY = aMouseEvent->refPoint.y + offset.y;
|
|
|
|
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2010-07-17 01:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::BeginMoveDrag(nsMouseEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aEvent, "must have event");
|
|
|
|
NS_ABORT_IF_FALSE(aEvent->eventStructType == NS_MOUSE_EVENT,
|
|
|
|
"event must have correct struct type");
|
|
|
|
|
|
|
|
GdkWindow *gdk_window;
|
|
|
|
gint button, screenX, screenY;
|
|
|
|
if (!GetDragInfo(aEvent, &gdk_window, &button, &screenX, &screenY)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell the window manager to start the move
|
|
|
|
gdk_window_begin_move_drag(gdk_window, button, screenX, screenY,
|
|
|
|
aEvent->time);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-11 02:08:35 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
|
|
|
|
if (aEvent->eventStructType != NS_MOUSE_EVENT) {
|
2010-07-17 01:11:54 -07:00
|
|
|
// you can only begin a resize drag with a mouse event
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-12-11 02:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent* mouse_event = static_cast<nsMouseEvent*>(aEvent);
|
2009-02-27 17:47:40 -08:00
|
|
|
|
2010-07-17 01:11:54 -07:00
|
|
|
GdkWindow *gdk_window;
|
|
|
|
gint button, screenX, screenY;
|
|
|
|
if (!GetDragInfo(mouse_event, &gdk_window, &button, &screenX, &screenY)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-11 02:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// work out what GdkWindowEdge we're talking about
|
|
|
|
GdkWindowEdge window_edge;
|
|
|
|
if (aVertical < 0) {
|
|
|
|
if (aHorizontal < 0) {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_NORTH_WEST;
|
|
|
|
} else if (aHorizontal == 0) {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_NORTH;
|
|
|
|
} else {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_NORTH_EAST;
|
|
|
|
}
|
|
|
|
} else if (aVertical == 0) {
|
|
|
|
if (aHorizontal < 0) {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_WEST;
|
|
|
|
} else if (aHorizontal == 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
} else {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_EAST;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aHorizontal < 0) {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_SOUTH_WEST;
|
|
|
|
} else if (aHorizontal == 0) {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_SOUTH;
|
|
|
|
} else {
|
|
|
|
window_edge = GDK_WINDOW_EDGE_SOUTH_EAST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell the window manager to start the resize
|
2010-07-17 01:11:54 -07:00
|
|
|
gdk_window_begin_resize_drag(gdk_window, window_edge, button,
|
|
|
|
screenX, screenY, aEvent->time);
|
2007-12-11 02:08:35 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-01-21 13:45:23 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ClearCachedResources()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == LayerManager::LAYERS_BASIC) {
|
|
|
|
static_cast<BasicLayerManager*> (mLayerManager.get())->
|
|
|
|
ClearCachedResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
GList* children = gdk_window_peek_children(mGdkWindow);
|
|
|
|
for (GList* list = children; list; list = list->next) {
|
|
|
|
nsWindow* window = get_window_for_gdk_window(GDK_WINDOW(list->data));
|
|
|
|
if (window) {
|
|
|
|
window->ClearCachedResources();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 14:55:21 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWindow::SynthesizeNativeMouseEvent(nsIntPoint aPoint,
|
|
|
|
PRUint32 aNativeMessage,
|
|
|
|
PRUint32 aModifierFlags)
|
|
|
|
{
|
|
|
|
if (!mGdkWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkDisplay* display = gdk_window_get_display(mGdkWindow);
|
|
|
|
GdkScreen* screen = gdk_window_get_screen(mGdkWindow);
|
|
|
|
gdk_display_warp_pointer(display, screen, aPoint.x, aPoint.y);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|