2010-03-03 09:45:16 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-04-19 08:37:51 -07:00
|
|
|
/* 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/. */
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2010-03-04 13:51:42 -08:00
|
|
|
#include <QtGui/QCursor>
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QGraphicsSceneWheelEvent>
|
|
|
|
#include <QGraphicsSceneResizeEvent>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
2010-04-13 16:11:23 -07:00
|
|
|
#include <QPaintEngine>
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QMimeData>
|
2012-08-16 08:31:47 -07:00
|
|
|
#include "mozqglwidgetwrapper.h"
|
2010-03-04 13:51:42 -08:00
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
#include <QtCore/QVariant>
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-03-12 14:11:42 -08:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
|
|
|
#include <QPinchGesture>
|
2010-10-08 23:08:42 -07:00
|
|
|
#include <QGestureRecognizer>
|
|
|
|
#include "mozSwipeGesture.h"
|
|
|
|
static Qt::GestureType gSwipeGestureId = Qt::CustomGesture;
|
|
|
|
|
|
|
|
// How many milliseconds mouseevents are blocked after receiving
|
|
|
|
// multitouch.
|
|
|
|
static const float GESTURES_BLOCK_MOUSE_FOR = 200;
|
2011-03-15 21:41:53 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include <QtSensors/QOrientationSensor>
|
|
|
|
using namespace QtMobility;
|
|
|
|
#endif // MOZ_ENABLE_QTMOBILITY
|
|
|
|
#endif // QT version check 4.6
|
2010-03-04 13:51:42 -08:00
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2010-03-18 09:44:33 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
#include "prlink.h"
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
#include "nsWindow.h"
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "mozqwidget.h"
|
|
|
|
|
2011-03-15 21:41:53 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include "mozqorientationsensorfilter.h"
|
|
|
|
#endif
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
#include "nsIdleService.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2008-04-19 08:37:51 -07:00
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsQtKeyUtils.h"
|
2010-05-14 02:24:41 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "gfxQtPlatform.h"
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "gfxXlibSurface.h"
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "gfxQPainterSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2010-05-11 10:31:56 -07:00
|
|
|
#include "gfxImageSurface.h"
|
2009-03-27 04:35:27 -07:00
|
|
|
|
2010-03-12 14:11:42 -08:00
|
|
|
#include "nsIDOMSimpleGestureEvent.h" //Gesture support
|
2012-08-11 18:42:37 -07:00
|
|
|
#include "nsIDOMWheelEvent.h"
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2010-08-30 16:40:14 -07:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIFocusManager.h"
|
|
|
|
#endif
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "keysym2ucs.h"
|
2011-09-07 08:06:35 -07:00
|
|
|
#if MOZ_PLATFORM_MAEMO == 6
|
|
|
|
#include <X11/Xatom.h>
|
2012-07-30 07:20:58 -07:00
|
|
|
static Atom sPluginIMEAtom = nullptr;
|
2011-09-07 08:06:35 -07:00
|
|
|
#define PLUGIN_VKB_REQUEST_PROP "_NPAPI_PLUGIN_REQUEST_VKB"
|
2011-10-07 08:16:37 -07:00
|
|
|
#include <QThread>
|
2011-09-07 08:06:35 -07:00
|
|
|
#endif
|
2010-08-26 11:11:54 -07:00
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2012-11-03 21:00:08 -07:00
|
|
|
#include "gfxUtils.h"
|
2010-06-24 03:07:57 -07:00
|
|
|
#include "Layers.h"
|
2012-11-03 21:00:08 -07:00
|
|
|
#include "GLContextProvider.h"
|
2012-08-16 08:31:47 -07:00
|
|
|
#include "BasicLayers.h"
|
2010-06-24 03:07:57 -07:00
|
|
|
#include "LayerManagerOGL.h"
|
2011-10-28 05:13:57 -07:00
|
|
|
#include "nsFastStartupQt.h"
|
2010-06-24 03:07:57 -07:00
|
|
|
|
2011-09-25 12:03:22 -07:00
|
|
|
// If embedding clients want to create widget without real parent window
|
|
|
|
// then nsIBaseWindow->Init() should have parent argument equal to PARENTLESS_WIDGET
|
|
|
|
#define PARENTLESS_WIDGET (void*)0x13579
|
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
#include "nsShmImage.h"
|
|
|
|
extern "C" {
|
2011-11-22 17:42:57 -08:00
|
|
|
#define PIXMAN_DONT_DEFINE_STDINT
|
2010-10-26 21:56:31 -07:00
|
|
|
#include "pixman.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
2012-11-03 21:00:08 -07:00
|
|
|
using mozilla::gl::GLContext;
|
|
|
|
using mozilla::layers::LayerManagerOGL;
|
2010-10-26 21:56:31 -07:00
|
|
|
|
2010-06-11 02:32:00 -07:00
|
|
|
// Cached offscreen surface
|
|
|
|
static nsRefPtr<gfxASurface> gBufferSurface;
|
2010-10-26 21:56:31 -07:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
// If we're using xshm rendering, mThebesSurface wraps gShmImage
|
|
|
|
nsRefPtr<nsShmImage> gShmImage;
|
|
|
|
#endif
|
2010-05-15 03:37:51 -07:00
|
|
|
|
|
|
|
static int gBufferPixmapUsageCount = 0;
|
2010-04-13 16:11:23 -07:00
|
|
|
static gfxIntSize gBufferMaxSize(0, 0);
|
2008-04-19 08:37:55 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// initialization static functions
|
|
|
|
static nsresult initialize_prefs (void);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
|
|
|
|
|
|
|
#define NS_WINDOW_TITLE_MAX_LENGTH 4095
|
|
|
|
|
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// Qt
|
2008-04-19 08:37:51 -07:00
|
|
|
static const int WHEEL_DELTA = 120;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gGlobalsInitialized = false;
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
static bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
static bool sAltGrModifier = false;
|
|
|
|
|
2011-03-15 21:41:53 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
2012-07-30 07:20:58 -07:00
|
|
|
static QOrientationSensor *gOrientation = nullptr;
|
2011-03-15 21:41:53 -07:00
|
|
|
static MozQOrientationSensorFilter gOrientationFilter;
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-04-20 01:16:40 -07:00
|
|
|
isContextMenuKeyEvent(const QKeyEvent *qe)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t kc = QtKeyCodeToDOMKeyCode(qe->key());
|
2008-04-20 01:16:40 -07:00
|
|
|
if (qe->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isShift = qe->modifiers() & Qt::ShiftModifier;
|
2008-04-20 01:16:40 -07:00
|
|
|
return (kc == NS_VK_F10 && isShift) ||
|
|
|
|
(kc == NS_VK_CONTEXT_MENU && !isShift);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
static void
|
|
|
|
InitKeyEvent(nsKeyEvent &aEvent, QKeyEvent *aQEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-04-24 20:00:02 -07:00
|
|
|
aEvent.InitBasicModifiers(aQEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aQEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aQEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aQEvent->modifiers() & Qt::MetaModifier);
|
2012-05-03 01:35:02 -07:00
|
|
|
|
|
|
|
// TODO: Needs to set .location for desktop Qt build.
|
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
|
|
|
aEvent.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
|
|
|
|
#endif
|
2008-04-20 01:16:40 -07:00
|
|
|
aEvent.time = 0;
|
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
if (sAltGrModifier) {
|
2012-04-24 20:00:02 -07:00
|
|
|
aEvent.modifiers |= (widget::MODIFIER_CONTROL | widget::MODIFIER_ALT);
|
2011-01-26 01:01:01 -08:00
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// The transformations above and in qt for the keyval are not invertible
|
|
|
|
// so link to the QKeyEvent (which will vanish soon after return from the
|
2008-04-20 01:16:40 -07:00
|
|
|
// event callback) to give plugins access to hardware_keycode and state.
|
2010-02-16 10:14:20 -08:00
|
|
|
// (An XEvent would be nice but the QKeyEvent is good enough.)
|
2009-11-10 13:55:38 -08:00
|
|
|
aEvent.pluginEvent = (void *)aQEvent;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTopLevel = false;
|
|
|
|
mIsDestroyed = false;
|
|
|
|
mIsShown = false;
|
|
|
|
mEnabled = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
mWidget = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsVisible = false;
|
|
|
|
mActivatePending = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2010-05-30 11:35:07 -07:00
|
|
|
mLastSizeMode = nsSizeMode_Normal;
|
2008-04-19 08:37:51 -07:00
|
|
|
mPluginType = PluginType_NONE;
|
|
|
|
mQCursor = Qt::ArrowCursor;
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
|
|
|
mListenForResizes = false;
|
|
|
|
mNeedsShow = false;
|
|
|
|
mGesturesCancelled = false;
|
|
|
|
mTimerStarted = false;
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.needDispatch = false;
|
|
|
|
mMoveEvent.needDispatch = false;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (!gGlobalsInitialized) {
|
2012-03-21 16:14:09 -07:00
|
|
|
gfxPlatform::GetPlatform();
|
2011-10-17 07:59:28 -07:00
|
|
|
gGlobalsInitialized = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-09-07 08:06:35 -07:00
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
2011-10-07 08:16:37 -07:00
|
|
|
// This cannot be called on non-main thread
|
|
|
|
if (QThread::currentThread() == qApp->thread()) {
|
2012-03-22 16:24:40 -07:00
|
|
|
sPluginIMEAtom = XInternAtom(mozilla::DefaultXDisplay(), PLUGIN_VKB_REQUEST_PROP, False);
|
2011-10-07 08:16:37 -07:00
|
|
|
}
|
2011-09-07 08:06:35 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
// It's OK if either of these fail, but it may not be one day.
|
|
|
|
initialize_prefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTransparent = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
mCursor = eCursor_standard;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
|
|
|
gBufferPixmapUsageCount++;
|
2010-10-08 23:08:42 -07:00
|
|
|
|
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(4,6,0))
|
|
|
|
if (gSwipeGestureId == Qt::CustomGesture) {
|
|
|
|
// QGestureRecognizer takes ownership
|
|
|
|
MozSwipeGestureRecognizer* swipeRecognizer = new MozSwipeGestureRecognizer;
|
|
|
|
gSwipeGestureId = QGestureRecognizer::registerRecognizer(swipeRecognizer);
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline gfxASurface::gfxImageFormat
|
2012-08-22 08:56:38 -07:00
|
|
|
_depth_to_gfximage_format(int32_t aDepth)
|
2010-02-19 19:46:54 -08:00
|
|
|
{
|
|
|
|
switch (aDepth) {
|
|
|
|
case 32:
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
case 24:
|
|
|
|
return gfxASurface::ImageFormatRGB24;
|
2010-06-11 02:33:22 -07:00
|
|
|
case 16:
|
|
|
|
return gfxASurface::ImageFormatRGB16_565;
|
2010-02-19 19:46:54 -08:00
|
|
|
default:
|
|
|
|
return gfxASurface::ImageFormatUnknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-13 16:11:23 -07:00
|
|
|
static inline QImage::Format
|
2010-05-11 10:31:56 -07:00
|
|
|
_gfximage_to_qformat(gfxASurface::gfxImageFormat aFormat)
|
2010-04-13 16:11:23 -07:00
|
|
|
{
|
2010-05-11 10:31:56 -07:00
|
|
|
switch (aFormat) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
2010-06-11 02:33:22 -07:00
|
|
|
return QImage::Format_ARGB32_Premultiplied;
|
2010-05-11 10:31:56 -07:00
|
|
|
case gfxASurface::ImageFormatRGB24:
|
2010-04-13 16:11:23 -07:00
|
|
|
return QImage::Format_ARGB32;
|
2010-06-11 02:33:22 -07:00
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
return QImage::Format_RGB16;
|
2010-04-13 16:11:23 -07:00
|
|
|
default:
|
|
|
|
return QImage::Format_Invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
static bool
|
2012-07-30 07:20:58 -07:00
|
|
|
UpdateOffScreenBuffers(int aDepth, QSize aSize, QWidget* aWidget = nullptr)
|
2010-02-19 19:46:54 -08:00
|
|
|
{
|
|
|
|
gfxIntSize size(aSize.width(), aSize.height());
|
2010-06-11 02:32:00 -07:00
|
|
|
if (gBufferSurface) {
|
2010-04-13 16:11:23 -07:00
|
|
|
if (gBufferMaxSize.width < size.width ||
|
|
|
|
gBufferMaxSize.height < size.height) {
|
2012-07-30 07:20:58 -07:00
|
|
|
gBufferSurface = nullptr;
|
2010-02-19 19:46:54 -08:00
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
gBufferMaxSize.width = std::max(gBufferMaxSize.width, size.width);
|
|
|
|
gBufferMaxSize.height = std::max(gBufferMaxSize.height, size.height);
|
2010-02-19 19:46:54 -08:00
|
|
|
|
|
|
|
// Check if system depth has related gfxImage format
|
|
|
|
gfxASurface::gfxImageFormat format =
|
2010-04-13 16:11:23 -07:00
|
|
|
_depth_to_gfximage_format(aDepth);
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2010-05-11 10:31:56 -07:00
|
|
|
// Use fallback RGB24 format, Qt will do conversion for us
|
|
|
|
if (format == gfxASurface::ImageFormatUnknown)
|
2010-04-13 16:11:23 -07:00
|
|
|
format = gfxASurface::ImageFormatRGB24;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
if (aWidget) {
|
|
|
|
if (gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType() ==
|
|
|
|
gfxASurface::SurfaceTypeImage) {
|
|
|
|
gShmImage = nsShmImage::Create(gBufferMaxSize,
|
2012-03-22 16:24:40 -07:00
|
|
|
DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aWidget)),
|
2010-10-26 21:56:31 -07:00
|
|
|
aDepth);
|
|
|
|
gBufferSurface = gShmImage->AsSurface();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-11 02:32:00 -07:00
|
|
|
gBufferSurface = gfxPlatform::GetPlatform()->
|
2010-09-16 14:34:53 -07:00
|
|
|
CreateOffscreenSurface(gBufferMaxSize, gfxASurface::ContentFromFormat(format));
|
2010-10-26 21:56:31 -07:00
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
return true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsWindow::ReleaseGlobals()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsBaseWidget, nsISupportsWeakReference)
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
|
2009-08-04 19:39:05 -07:00
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
|
|
|
|
|
|
|
if (w->mBounds.Size() != configuration.mBounds.Size()) {
|
|
|
|
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
|
|
|
|
configuration.mBounds.width, configuration.mBounds.height,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2009-08-04 19:39:05 -07:00
|
|
|
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
|
|
|
w->Move(configuration.mBounds.x, configuration.mBounds.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mIsDestroyed || !mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsDestroyed = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
if (gBufferPixmapUsageCount &&
|
|
|
|
--gBufferPixmapUsageCount == 0) {
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gBufferSurface = nullptr;
|
2010-10-26 21:56:31 -07:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
2012-07-30 07:20:58 -07:00
|
|
|
gShmImage = nullptr;
|
2011-03-15 21:41:53 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
if (gOrientation) {
|
|
|
|
gOrientation->removeFilter(&gOrientationFilter);
|
|
|
|
gOrientation->stop();
|
|
|
|
delete gOrientation;
|
2012-07-30 07:20:58 -07:00
|
|
|
gOrientation = nullptr;
|
2011-03-15 21:41:53 -07:00
|
|
|
}
|
2010-10-26 21:56:31 -07:00
|
|
|
#endif
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
|
|
|
|
2012-11-03 21:00:08 -07:00
|
|
|
/** Need to clean our LayerManager up while still alive */
|
2010-09-09 16:41:02 -07:00
|
|
|
if (mLayerManager) {
|
2012-11-03 21:00:08 -07:00
|
|
|
nsRefPtr<GLContext> gl = nullptr;
|
|
|
|
if (mLayerManager->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
|
|
|
LayerManagerOGL *ogllm = static_cast<LayerManagerOGL*>(mLayerManager.get());
|
|
|
|
gl = ogllm->gl();
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:41:02 -07:00
|
|
|
mLayerManager->Destroy();
|
2012-11-03 21:00:08 -07:00
|
|
|
|
|
|
|
if (gl) {
|
|
|
|
gl->MarkDestroyed();
|
|
|
|
}
|
2010-09-09 16:41:02 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mLayerManager = nullptr;
|
2010-09-09 16:41:02 -07:00
|
|
|
|
2012-11-03 21:00:08 -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();
|
|
|
|
|
|
|
|
ClearCachedResources();
|
|
|
|
|
|
|
|
nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
if (rollupListener) {
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget) {
|
|
|
|
rollupListener->Rollup(0, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 21:00:08 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
Show(false);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// walk the list of children and call destroy on them. Have to be
|
|
|
|
// careful, though -- calling destroy on a kid may actually remove
|
|
|
|
// it from our child list, losing its sibling links.
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; ) {
|
|
|
|
nsIWidget* next = kid->GetNextSibling();
|
|
|
|
kid->Destroy();
|
|
|
|
kid = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy thebes surface now. Badness can happen if we destroy
|
|
|
|
// the surface after its X Window.
|
2012-07-30 07:20:58 -07:00
|
|
|
mThebesSurface = nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
QWidget *view = nullptr;
|
|
|
|
QGraphicsScene *scene = nullptr;
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget) {
|
2010-03-05 23:25:46 -08:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
view = GetViewWidget();
|
|
|
|
scene = mWidget->scene();
|
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->dropReceiver();
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// Call deleteLater instead of delete; Qt still needs the object
|
|
|
|
// to be valid even after sending it a Close event. We could
|
|
|
|
// also set WA_DeleteOnClose, but this gives us more control.
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->deleteLater();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mWidget = nullptr;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
OnDestroy();
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// tear down some infrastructure after all event handling is finished
|
2010-03-05 23:25:46 -08:00
|
|
|
delete scene;
|
|
|
|
delete view;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-03 21:00:08 -07:00
|
|
|
void
|
|
|
|
nsWindow::ClearCachedResources()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LAYERS_BASIC) {
|
|
|
|
static_cast<mozilla::layers::BasicLayerManager*> (mLayerManager.get())->
|
|
|
|
ClearCachedResources();
|
|
|
|
}
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; ) {
|
|
|
|
nsIWidget* next = kid->GetNextSibling();
|
|
|
|
static_cast<nsWindow*>(kid)->ClearCachedResources();
|
|
|
|
kid = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewParent);
|
2010-09-18 04:28:50 -07:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
2011-05-30 14:51:54 -07:00
|
|
|
ReparentNativeWidget(aNewParent);
|
|
|
|
aNewParent->AddChild(this);
|
2010-09-18 04:28:50 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
MozQWidget* newParent = static_cast<MozQWidget*>(aNewParent->GetNativeData(NS_NATIVE_WINDOW));
|
|
|
|
NS_ASSERTION(newParent, "Parent widget has a null native window handle");
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->setParentItem(newParent);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetModal(bool aModal)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget));
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->setModal(aModal);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
bool
|
|
|
|
nsWindow::IsVisible() const
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-07-19 01:57:50 -07:00
|
|
|
return mIsShown;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t screenWidth = QApplication::desktop()->width();
|
|
|
|
int32_t screenHeight = QApplication::desktop()->height();
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Move(double aX, double aY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
LOG(("nsWindow::Move [%p] %f %f\n", (void *)this,
|
2008-04-19 08:37:51 -07:00
|
|
|
aX, aY));
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
int32_t x = NSToIntRound(aX);
|
|
|
|
int32_t y = NSToIntRound(aY);
|
|
|
|
|
2010-03-16 23:32:38 -07:00
|
|
|
if (mIsTopLevel) {
|
2009-11-02 11:10:07 -08:00
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
if (x == mBounds.x && y == mBounds.y)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsMove = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// update the bounds
|
2012-12-12 01:57:38 -08:00
|
|
|
QPointF pos( x, y );
|
2011-02-02 22:31:43 -08:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_OK);
|
2012-12-12 01:57:38 -08:00
|
|
|
widget->move(x, y);
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
|
|
|
else if (mWidget) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// the position of the widget is set relative to the parent
|
|
|
|
// so we map the coordinates accordingly
|
|
|
|
pos = mWidget->mapFromScene(pos);
|
|
|
|
pos = mWidget->mapToParent(pos);
|
|
|
|
mWidget->setPos(pos);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = pos.x();
|
|
|
|
mBounds.y = pos.y();
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aActivate)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::SetSizeMode(int32_t aMode)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
2011-05-03 09:40:02 -07:00
|
|
|
if (aMode != nsSizeMode_Minimized) {
|
|
|
|
GetViewWidget()->activateWindow();
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// 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.
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget || mSizeState == mSizeMode) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-14 23:08:15 -07:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showMaximized();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showMinimized();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
2010-02-04 06:43:52 -08:00
|
|
|
case nsSizeMode_Fullscreen:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showFullScreen();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showNormal();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// Helper function to recursively find the first parent item that
|
|
|
|
// is still visible (QGraphicsItem can be hidden even if they are
|
|
|
|
// set to visible if one of their ancestors is invisible)
|
|
|
|
static void find_first_visible_parent(QGraphicsItem* aItem, QGraphicsItem*& aVisibleItem)
|
|
|
|
{
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(aItem);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
aVisibleItem = nullptr;
|
|
|
|
QGraphicsItem* parItem = nullptr;
|
2010-03-25 17:33:31 -07:00
|
|
|
while (!aVisibleItem) {
|
|
|
|
if (aItem->isVisible())
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
else {
|
|
|
|
parItem = aItem->parentItem();
|
|
|
|
if (parItem)
|
|
|
|
aItem = parItem;
|
|
|
|
else {
|
|
|
|
aItem->setVisible(true);
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2008-04-19 08:37:51 -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.
|
|
|
|
LOGFOCUS((" SetFocus [%p]\n", (void *)this));
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-03-25 17:33:31 -07:00
|
|
|
if (mWidget->hasFocus())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Because QGraphicsItem cannot get the focus if they are
|
2010-02-16 10:14:20 -08:00
|
|
|
// invisible, we look up the chain, for the lowest visible
|
|
|
|
// parent and focus that one
|
2012-07-30 07:20:58 -07:00
|
|
|
QGraphicsItem* realFocusItem = nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
find_first_visible_parent(mWidget, realFocusItem);
|
|
|
|
|
|
|
|
if (!realFocusItem || realFocusItem->hasFocus())
|
2009-07-15 05:20:21 -07:00
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-25 10:58:19 -08:00
|
|
|
if (aRaise) {
|
|
|
|
// the raising has to happen on the view widget
|
2010-03-14 23:08:15 -07:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
if (widget)
|
|
|
|
widget->raise();
|
2010-02-16 10:14:20 -08:00
|
|
|
realFocusItem->setFocus(Qt::ActiveWindowFocusReason);
|
2010-02-25 10:58:19 -08:00
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
else
|
|
|
|
realFocusItem->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
// XXXndeakin why is this here? It should dispatch only when the OS
|
|
|
|
// notifies us.
|
2010-02-16 10:14:20 -08:00
|
|
|
DispatchActivateEvent();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-11 05:51:06 -08:00
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2011-02-02 22:31:43 -08:00
|
|
|
aRect = nsIntRect(nsIntPoint(0, 0), mBounds.Size());
|
|
|
|
if (mIsTopLevel) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_OK);
|
|
|
|
QPoint pos = widget->pos();
|
|
|
|
aRect.MoveTo(pos.x(), pos.y());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRect.MoveTo(WidgetToScreenOffset());
|
|
|
|
}
|
2010-03-05 23:25:46 -08:00
|
|
|
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
|
2008-04-19 08:37:51 -07:00
|
|
|
aRect.x, aRect.y,
|
|
|
|
mBounds.width, mBounds.height,
|
|
|
|
aRect.width, aRect.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-12-29 08:22:26 -08:00
|
|
|
if (mCursor == aCursor)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
mCursor = aCursor;
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->SetCursor(mCursor);
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(imgIContainer* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-23 19:52:21 -08:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2011-12-23 19:52:21 -08:00
|
|
|
LOGDRAW(("Invalidate (rect) [%p,%p]: %d %d %d %d\n", (void *)this,
|
|
|
|
(void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-25 17:33:31 -07:00
|
|
|
mDirtyScrollArea = mDirtyScrollArea.united(QRect(aRect.x, aRect.y, aRect.width, aRect.height));
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget->update(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:25:46 -08:00
|
|
|
// Returns the graphics view widget for this nsWindow by iterating
|
|
|
|
// the chain of parents until a toplevel window with a view/scene is found.
|
|
|
|
// (This function always returns something or asserts if the precondition
|
|
|
|
// is not met)
|
2010-02-16 10:14:20 -08:00
|
|
|
QWidget* nsWindow::GetViewWidget()
|
|
|
|
{
|
2010-03-05 23:25:46 -08:00
|
|
|
NS_ASSERTION(mWidget, "Calling GetViewWidget without mWidget created");
|
2010-08-20 18:12:14 -07:00
|
|
|
if (!mWidget || !mWidget->scene() || !mWidget->scene()->views().size())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-03-05 23:25:46 -08:00
|
|
|
NS_ASSERTION(mWidget->scene()->views().size() == 1, "Not exactly one view for our scene!");
|
|
|
|
return mWidget->scene()->views()[0];
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
void*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::GetNativeData(uint32_t aDataType)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
return mWidget;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
return SetupPluginPort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_DISPLAY:
|
2010-03-16 23:28:42 -07:00
|
|
|
{
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2012-03-22 16:24:40 -07:00
|
|
|
return gfxQtPlatform::GetXDisplay(GetViewWidget());
|
2011-08-24 09:15:58 -07:00
|
|
|
#else
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2010-03-16 23:28:42 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC: {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-24 03:07:57 -07:00
|
|
|
case NS_NATIVE_SHELLWIDGET: {
|
2012-07-30 07:20:58 -07:00
|
|
|
QWidget* widget = nullptr;
|
2010-06-24 03:07:57 -07:00
|
|
|
if (mWidget && mWidget->scene())
|
|
|
|
widget = mWidget->scene()->views()[0]->viewport();
|
|
|
|
return (void *) widget;
|
|
|
|
}
|
2011-08-31 12:01:38 -07:00
|
|
|
|
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW: {
|
|
|
|
QWidget *widget = GetViewWidget();
|
2012-07-30 07:20:58 -07:00
|
|
|
return widget ? (void*)widget->winId() : nullptr;
|
2011-08-31 12:01:38 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length()));
|
2010-03-14 23:08:15 -07:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
if (widget)
|
|
|
|
widget->setWindowTitle(qStr);
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
else if (mWidget)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setWindowTitle(qStr);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> iconFile;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString path;
|
2009-01-21 20:15:34 -08:00
|
|
|
nsTArray<nsCString> iconList;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// 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 the other suffixes. XPM icons are depricated.
|
|
|
|
|
|
|
|
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
|
|
|
|
".xpm", "16.xpm" };
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(extensions); i++) {
|
2008-04-19 08:37:51 -07:00
|
|
|
// Don't bother looking for XPM versions if we found a PNG.
|
2011-10-10 22:50:08 -07:00
|
|
|
if (i == ArrayLength(extensions) - 2 && iconList.Length())
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
|
|
|
|
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
2009-01-21 20:15:34 -08:00
|
|
|
iconList.AppendElement(path);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leave the default icon intact if no matching icons were found
|
2009-01-21 20:15:34 -08:00
|
|
|
if (iconList.Length() == 0)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return SetWindowIconList(iconList);
|
|
|
|
}
|
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QPointF origin(0, 0);
|
|
|
|
origin = mWidget->mapToScene(origin);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
return nsIntPoint(origin.x(), origin.y());
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::EnableDragDrop(bool aEnable)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setAcceptDrops(aEnable);
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::CaptureMouse(bool aCapture)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
2010-03-14 23:08:15 -07:00
|
|
|
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aCapture)
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->grabMouse();
|
2008-04-20 01:37:07 -07:00
|
|
|
else
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->releaseMouse();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
|
2012-10-26 06:15:22 -07:00
|
|
|
bool aDoCapture)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("CaptureRollupEvents %p\n", (void *)this));
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
gRollupListener = aDoCapture ? aListener : nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-10-26 06:15:22 -07:00
|
|
|
nsWindow::CheckForRollup(double aMouseX, double aMouseY,
|
|
|
|
bool aIsWheel)
|
2008-08-16 00:07:21 -07:00
|
|
|
{
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* rollupListener = GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
}
|
|
|
|
if (!rollupWidget) {
|
2012-10-26 06:15:22 -07:00
|
|
|
nsBaseWidget::gRollupListener = nullptr;
|
2012-12-31 09:27:04 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool retVal = false;
|
|
|
|
MozQWidget *currentPopup =
|
|
|
|
(MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
|
|
|
|
bool rollup = true;
|
|
|
|
if (aIsWheel) {
|
|
|
|
rollup = rollupListener->ShouldRollupOnMouseWheelEvent();
|
|
|
|
retVal = true;
|
|
|
|
}
|
|
|
|
// if we're dealing with menus, we probably have submenus and
|
|
|
|
// we don't want to rollup if the clickis in a parent menu of
|
|
|
|
// the current submenu
|
|
|
|
uint32_t popupsToRollup = UINT32_MAX;
|
|
|
|
if (rollupListener) {
|
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
|
|
|
uint32_t sameTypeCount = rollupListener->GetSubmenuWidgetChain(&widgetChain);
|
|
|
|
for (uint32_t i=0; i<widgetChain.Length(); ++i) {
|
|
|
|
nsIWidget* widget = widgetChain[i];
|
|
|
|
MozQWidget* currWindow =
|
|
|
|
(MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
|
|
|
|
if (i < sameTypeCount) {
|
|
|
|
rollup = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // foreach parent menu widget
|
|
|
|
} // if rollup listener knows about menus
|
|
|
|
|
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
|
|
|
retVal = rollupListener->Rollup(popupsToRollup, nullptr);
|
|
|
|
}
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2010-02-16 10:14:20 -08:00
|
|
|
bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY)
|
2008-08-16 00:07:21 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
return aWindow->geometry().contains( aMouseX, aMouseY );
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::GetAttention(int32_t aCycleCount)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
static already_AddRefed<gfxASurface>
|
|
|
|
GetSurfaceForQWidget(QWidget* aDrawable)
|
|
|
|
{
|
|
|
|
gfxASurface* result =
|
2012-03-22 16:24:40 -07:00
|
|
|
new gfxXlibSurface(gfxQtPlatform::GetXDisplay(aDrawable),
|
|
|
|
aDrawable->winId(),
|
|
|
|
DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aDrawable)),
|
2010-10-26 21:56:31 -07:00
|
|
|
gfxIntSize(aDrawable->size().width(),
|
|
|
|
aDrawable->size().height()));
|
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
bool
|
2010-10-26 21:56:31 -07:00
|
|
|
nsWindow::DoPaint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
if (mIsDestroyed) {
|
|
|
|
LOG(("Expose event on destroyed window [%p] window %p\n",
|
2009-07-15 05:20:21 -07:00
|
|
|
(void *)this, mWidget));
|
2012-08-15 11:52:42 -07:00
|
|
|
return false;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
// Call WillPaintWindow to allow scripts etc. to run before we paint
|
2012-03-19 13:16:57 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
2013-01-28 11:34:08 -08:00
|
|
|
mWidgetListener->WillPaintWindow(this);
|
2012-03-19 13:16:57 -07:00
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2012-08-15 11:52:42 -07:00
|
|
|
return false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QRectF r;
|
|
|
|
if (aOption)
|
|
|
|
r = aOption->exposedRect;
|
|
|
|
else
|
|
|
|
r = mWidget->boundingRect();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-03-10 14:13:02 -08:00
|
|
|
if (r.isEmpty())
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-03-07 03:07:25 -08:00
|
|
|
if (!mDirtyScrollArea.isEmpty())
|
|
|
|
mDirtyScrollArea = QRegion();
|
2008-04-20 01:37:07 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
bool painted = false;
|
2010-06-24 03:07:57 -07:00
|
|
|
nsIntRect rect(r.x(), r.y(), r.width(), r.height());
|
|
|
|
|
2011-10-28 05:13:57 -07:00
|
|
|
nsFastStartup* startup = nsFastStartup::GetSingleton();
|
|
|
|
if (startup) {
|
|
|
|
startup->RemoveFakeLayout();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (GetLayerManager(nullptr)->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
2012-03-19 13:16:57 -07:00
|
|
|
aPainter->beginNativePainting();
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIntRegion region(rect);
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nullptr))->
|
2012-08-15 11:52:42 -07:00
|
|
|
SetClippingRegion(region);
|
2011-03-15 21:41:53 -07:00
|
|
|
|
|
|
|
gfxMatrix matr;
|
|
|
|
matr.Translate(gfxPoint(aPainter->transform().dx(), aPainter->transform().dy()));
|
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
// This is needed for rotate transformation on MeeGo
|
|
|
|
// This will work very slow if pixman does not handle rotation very well
|
|
|
|
matr.Rotate((M_PI/180) * gOrientationFilter.GetWindowRotationAngle());
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nullptr))->
|
2011-03-15 21:41:53 -07:00
|
|
|
SetWorldTransform(matr);
|
|
|
|
#endif //MOZ_ENABLE_QTMOBILITY
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
2013-01-28 11:34:06 -08:00
|
|
|
painted = mWidgetListener->PaintWindow(this, region, 0);
|
2012-03-19 13:16:57 -07:00
|
|
|
aPainter->endNativePainting();
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->DidPaintWindow();
|
|
|
|
return painted;
|
2010-06-24 03:07:57 -07:00
|
|
|
}
|
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
2010-04-13 16:11:23 -07:00
|
|
|
int depth = aPainter->device()->depth();
|
2010-05-11 10:31:56 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsRefPtr<gfxASurface> targetSurface = nullptr;
|
2010-05-11 10:31:56 -07:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
|
|
|
// Prepare offscreen buffers iamge or xlib, depends from paintEngineType
|
2010-06-11 02:32:00 -07:00
|
|
|
if (!UpdateOffScreenBuffers(depth, QSize(r.width(), r.height())))
|
2012-08-15 11:52:42 -07:00
|
|
|
return false;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2010-06-11 02:32:00 -07:00
|
|
|
targetSurface = gBufferSurface;
|
2010-05-11 10:31:56 -07:00
|
|
|
|
2010-10-04 23:15:57 -07:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-02-19 19:46:54 -08:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
targetSurface = new gfxQPainterSurface(aPainter);
|
2010-10-04 23:15:57 -07:00
|
|
|
#endif
|
2010-10-26 21:56:31 -07:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
if (!UpdateOffScreenBuffers(depth, aWidget->size(), aWidget)) {
|
2012-08-15 11:52:42 -07:00
|
|
|
return false;
|
2010-10-26 21:56:31 -07:00
|
|
|
}
|
|
|
|
targetSurface = gBufferSurface;
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!targetSurface))
|
2012-08-15 11:52:42 -07:00
|
|
|
return false;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2008-04-19 08:43:23 -07:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
2010-03-10 14:13:02 -08:00
|
|
|
// We will paint to 0, 0 position in offscrenn buffer
|
2010-10-26 21:56:31 -07:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
2010-03-10 14:13:02 -08:00
|
|
|
ctx->Translate(gfxPoint(-r.x(), -r.y()));
|
2010-10-26 21:56:31 -07:00
|
|
|
}
|
|
|
|
else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
2011-01-19 22:27:49 -08:00
|
|
|
gfxMatrix matr;
|
|
|
|
matr.Translate(gfxPoint(aPainter->transform().dx(), aPainter->transform().dy()));
|
2011-03-15 21:41:53 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
// This is needed for rotate transformation on MeeGo
|
|
|
|
// This will work very slow if pixman does not handle rotation very well
|
|
|
|
matr.Rotate((M_PI/180) * gOrientationFilter.GetWindowRotationAngle());
|
|
|
|
NS_ASSERTION(PIXMAN_VERSION > PIXMAN_VERSION_ENCODE(0, 21, 2) ||
|
|
|
|
!gOrientationFilter.GetWindowRotationAngle(),
|
|
|
|
"Old pixman and rotate transform, it is going to be slow");
|
|
|
|
#endif //MOZ_ENABLE_QTMOBILITY
|
|
|
|
|
2011-01-19 22:27:49 -08:00
|
|
|
ctx->SetMatrix(matr);
|
|
|
|
}
|
2010-03-10 14:13:02 -08:00
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
{
|
2010-10-26 21:56:31 -07:00
|
|
|
AutoLayerManagerSetup
|
2012-07-30 17:42:26 -07:00
|
|
|
setupLayerManager(this, ctx, mozilla::layers::BUFFER_NONE);
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
nsIntRegion region(rect);
|
2013-01-28 11:34:06 -08:00
|
|
|
painted = mWidgetListener->PaintWindow(this, region, 0);
|
2012-08-15 11:52:42 -07:00
|
|
|
}
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
|
|
|
|
// operations below if that happened - it will lead to XError and exit().
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(mIsDestroyed))
|
2012-08-15 11:52:42 -07:00
|
|
|
return painted;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!painted)
|
|
|
|
return false;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOGDRAW(("[%p] draw done\n", this));
|
|
|
|
|
2010-05-11 10:31:56 -07:00
|
|
|
// Handle buffered painting mode
|
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
2012-03-22 16:24:40 -07:00
|
|
|
#if defined(MOZ_X11) && defined(Q_WS_X11)
|
2010-06-11 02:32:00 -07:00
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
2010-04-13 16:11:23 -07:00
|
|
|
// Paint offscreen pixmap to QPainter
|
2010-06-11 02:32:00 -07:00
|
|
|
static QPixmap gBufferPixmap;
|
|
|
|
Drawable draw = static_cast<gfxXlibSurface*>(gBufferSurface.get())->XDrawable();
|
|
|
|
if (gBufferPixmap.handle() != draw)
|
|
|
|
gBufferPixmap = QPixmap::fromX11Pixmap(draw, QPixmap::ExplicitlyShared);
|
|
|
|
XSync(static_cast<gfxXlibSurface*>(gBufferSurface.get())->XDisplay(), False);
|
|
|
|
aPainter->drawPixmap(QPoint(rect.x, rect.y), gBufferPixmap,
|
2010-03-10 14:13:02 -08:00
|
|
|
QRect(0, 0, rect.width, rect.height));
|
2010-04-13 16:11:23 -07:00
|
|
|
|
2011-08-24 09:15:58 -07:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeImage) {
|
2010-04-13 16:11:23 -07:00
|
|
|
// in raster mode we can just wrap gBufferImage as QImage and paint directly
|
2010-06-11 02:32:00 -07:00
|
|
|
gfxImageSurface *imgs = static_cast<gfxImageSurface*>(gBufferSurface.get());
|
|
|
|
QImage img(imgs->Data(),
|
|
|
|
imgs->Width(),
|
|
|
|
imgs->Height(),
|
|
|
|
imgs->Stride(),
|
|
|
|
_gfximage_to_qformat(imgs->Format()));
|
2010-02-25 12:45:37 -08:00
|
|
|
aPainter->drawImage(QPoint(rect.x, rect.y), img,
|
2010-03-10 14:13:02 -08:00
|
|
|
QRect(0, 0, rect.width, rect.height));
|
2010-02-25 12:45:37 -08:00
|
|
|
}
|
2010-10-26 21:56:31 -07:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
QRect trans = aPainter->transform().mapRect(r).toRect();
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-10-26 21:56:31 -07:00
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
|
|
|
nsRefPtr<gfxASurface> widgetSurface = GetSurfaceForQWidget(aWidget);
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(widgetSurface);
|
|
|
|
ctx->SetSource(gBufferSurface);
|
2011-10-17 07:59:28 -07:00
|
|
|
ctx->Rectangle(gfxRect(trans.x(), trans.y(), trans.width(), trans.height()), true);
|
2010-10-26 21:56:31 -07:00
|
|
|
ctx->Clip();
|
|
|
|
ctx->Fill();
|
2011-08-24 09:15:58 -07:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeImage) {
|
2010-10-26 21:56:31 -07:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
if (gShmImage) {
|
|
|
|
gShmImage->Put(aWidget, trans);
|
|
|
|
} else
|
|
|
|
#endif
|
2011-08-24 09:15:58 -07:00
|
|
|
{
|
|
|
|
// Qt should take care about optimized rendering on QImage into painter device (gl/fb/image et.c.)
|
|
|
|
gfxImageSurface *imgs = static_cast<gfxImageSurface*>(gBufferSurface.get());
|
|
|
|
QImage img(imgs->Data(),
|
|
|
|
imgs->Width(),
|
|
|
|
imgs->Height(),
|
|
|
|
imgs->Stride(),
|
|
|
|
_gfximage_to_qformat(imgs->Format()));
|
|
|
|
aPainter->drawImage(trans, img, trans);
|
2010-10-26 21:56:31 -07:00
|
|
|
}
|
|
|
|
}
|
2010-02-25 12:45:37 -08:00
|
|
|
}
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
ctx = nullptr;
|
|
|
|
targetSurface = nullptr;
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->DidPaintWindow();
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// check the return value!
|
2012-08-15 11:52:42 -07:00
|
|
|
return painted;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnMoveEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("configure event [%p] %d %d\n", (void *)this,
|
|
|
|
aEvent->pos().x(), aEvent->pos().y()));
|
|
|
|
|
|
|
|
// can we shortcut?
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidget || !mWidgetListener)
|
2008-04-22 04:21:18 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if ((mBounds.x == aEvent->pos().x() &&
|
|
|
|
mBounds.y == aEvent->pos().y()))
|
2008-04-20 01:16:40 -07:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
bool moved = mWidgetListener->WindowMoved(this, aEvent->pos().x(), aEvent->pos().y());
|
|
|
|
return moved ? nsEventStatus_eConsumeNoDefault : nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnResizeEvent(QGraphicsSceneResizeEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-02-11 05:51:06 -08:00
|
|
|
nsIntRect rect;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// Generate XPFE resize event
|
|
|
|
GetBounds(rect);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
rect.width = aEvent->newSize().width();
|
|
|
|
rect.height = aEvent->newSize().height();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-22 04:21:18 -07:00
|
|
|
nsWindow::OnCloseEvent(QCloseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidgetListener)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
mWidgetListener->RequestWindowClose(this);
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnEnterNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_ENTER, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOG(("OnEnterNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnLeaveNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_EXIT, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOG(("OnLeaveNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
// Block the mouse events if user was recently executing gestures;
|
|
|
|
// otherwise there will be also some panning during/after gesture
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
|
|
|
#define CHECK_MOUSE_BLOCKED { \
|
|
|
|
if (mLastMultiTouchTime.isValid()) { \
|
|
|
|
if (mLastMultiTouchTime.elapsed() < GESTURES_BLOCK_MOUSE_FOR) \
|
|
|
|
return nsEventStatus_eIgnore; \
|
|
|
|
else \
|
|
|
|
mLastMultiTouchTime = QTime(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
define CHECK_MOUSE_BLOCKED {}
|
|
|
|
#endif
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2011-02-03 13:27:01 -08:00
|
|
|
nsWindow::OnMotionNotifyEvent(QPointF aPos, Qt::KeyboardModifiers aModifiers)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-10-08 23:08:42 -07:00
|
|
|
UserActivity();
|
|
|
|
|
|
|
|
CHECK_MOUSE_BLOCKED
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2011-02-03 13:27:01 -08:00
|
|
|
mMoveEvent.pos = aPos;
|
|
|
|
mMoveEvent.modifiers = aModifiers;
|
2011-01-18 00:51:04 -08:00
|
|
|
mMoveEvent.needDispatch = true;
|
|
|
|
DispatchMotionToMainThread();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-01-18 00:51:04 -08:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::InitButtonEvent(nsMouseEvent &aMoveEvent,
|
|
|
|
QGraphicsSceneMouseEvent *aEvent, int aClickCount)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
aMoveEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
aMoveEvent.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-04-24 20:00:02 -07:00
|
|
|
aMoveEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aEvent->modifiers() & Qt::MetaModifier);
|
2010-02-16 10:14:20 -08:00
|
|
|
aMoveEvent.clickCount = aClickCount;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnButtonPressEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
CHECK_MOUSE_BLOCKED
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QPointF pos = aEvent->pos();
|
|
|
|
|
|
|
|
// we check against the widgets geometry, so use parent coordinates
|
|
|
|
// for the check
|
|
|
|
if (mWidget)
|
|
|
|
pos = mWidget->mapToParent(pos);
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
if (CheckForRollup( pos.x(), pos.y(), false))
|
2008-08-16 00:07:21 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t domButton;
|
2008-04-19 08:37:51 -07:00
|
|
|
switch (aEvent->button()) {
|
|
|
|
case Qt::MidButton:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
event.button = domButton;
|
|
|
|
InitButtonEvent(event, aEvent, 1);
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// right menu click on linux should also pop up a context menu
|
|
|
|
if (domButton == nsMouseEvent::eRightButton &&
|
2012-10-26 06:32:10 -07:00
|
|
|
MOZ_LIKELY(!mIsDestroyed)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-19 08:38:12 -07:00
|
|
|
InitButtonEvent(contextMenuEvent, aEvent, 1);
|
2008-04-19 08:37:51 -07:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnButtonReleaseEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-10-08 23:08:42 -07:00
|
|
|
UserActivity();
|
|
|
|
CHECK_MOUSE_BLOCKED
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t domButton;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
switch (aEvent->button()) {
|
|
|
|
case Qt::MidButton:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
event.button = domButton;
|
2008-04-19 08:38:12 -07:00
|
|
|
InitButtonEvent(event, aEvent, 1);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
|
|
|
|
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-04-21 15:54:25 -07:00
|
|
|
nsWindow::OnMouseDoubleClickEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t eventType;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
switch (aEvent->button()) {
|
2008-04-19 08:37:51 -07:00
|
|
|
case Qt::MidButton:
|
|
|
|
eventType = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
eventType = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eventType = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
event.button = eventType;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
InitButtonEvent(event, aEvent, 2);
|
2008-04-19 08:37:51 -07:00
|
|
|
//pressed
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnFocusInEvent(QEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this));
|
2010-07-28 18:05:56 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-07-28 18:05:56 -07:00
|
|
|
DispatchActivateEventOnTopLevelWindow();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnFocusOutEvent(QEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-07-28 18:05:56 -07:00
|
|
|
if (!mWidget)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-09-01 11:01:50 -07:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
2010-08-30 16:40:14 -07:00
|
|
|
if (((QFocusEvent*)aEvent)->reason() == Qt::OtherFocusReason
|
|
|
|
&& mWidget->isVKBOpen()) {
|
|
|
|
// We assume that the VKB was open in this case, because of the focus
|
|
|
|
// reason and clear the focus in the active window.
|
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService("@mozilla.org/focus-manager;1");
|
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
fm->GetActiveWindow(getter_AddRefs(domWindow));
|
|
|
|
fm->ClearFocus(domWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-28 18:05:56 -07:00
|
|
|
DispatchDeactivateEventOnTopLevelWindow();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2008-04-19 08:37:51 -07:00
|
|
|
is_latin_shortcut_key(quint32 aKeyval)
|
|
|
|
{
|
|
|
|
return ((Qt::Key_0 <= aKeyval && aKeyval <= Qt::Key_9) ||
|
|
|
|
(Qt::Key_A <= aKeyval && aKeyval <= Qt::Key_Z));
|
|
|
|
}
|
|
|
|
|
2011-07-13 18:58:07 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2011-07-13 18:58:07 -07:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::DispatchContentCommandEvent(int32_t aMsg)
|
2011-07-13 18:58:07 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentCommandEvent event(true, aMsg, this);
|
2011-07-13 18:58:07 -07:00
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2011-07-13 18:58:07 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::OnKeyPressEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool setNoDefault = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// before we dispatch a key, check if it's the context menu key.
|
|
|
|
// If so, send a context menu key event instead.
|
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2010-08-26 11:11:54 -07:00
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domCharCode = 0;
|
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// get keymap and modifier map from the Xserver
|
2012-03-22 16:24:40 -07:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2010-08-26 11:11:54 -07:00
|
|
|
int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
|
|
|
|
XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
|
|
|
|
XModifierKeymap *xmodmap = XGetModifierMapping(display);
|
2010-12-11 10:42:02 -08:00
|
|
|
if (!xmodmap)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
|
|
|
|
&xkeysyms_per_keycode);
|
2010-12-11 10:42:02 -08:00
|
|
|
if (!xkeymap) {
|
|
|
|
XFreeModifiermap(xmodmap);
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// create modifier masks
|
|
|
|
qint32 shift_mask = 0, shift_lock_mask = 0, caps_lock_mask = 0, num_lock_mask = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 8 * xmodmap->max_keypermod; ++i) {
|
|
|
|
qint32 maskbit = 1 << (i / xmodmap->max_keypermod);
|
|
|
|
KeyCode modkeycode = xmodmap->modifiermap[i];
|
|
|
|
if (modkeycode == NoSymbol) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 mapindex = (modkeycode - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int j = 0; j < xkeysyms_per_keycode; ++j) {
|
|
|
|
KeySym modkeysym = xkeymap[mapindex + j];
|
|
|
|
switch (modkeysym) {
|
|
|
|
case XK_Num_Lock:
|
|
|
|
num_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Caps_Lock:
|
|
|
|
caps_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Shift_Lock:
|
|
|
|
shift_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Shift_L:
|
|
|
|
case XK_Shift_R:
|
|
|
|
shift_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// indicate whether is down or not
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shift_state = ((shift_mask & aEvent->nativeModifiers()) != 0) ^
|
2010-08-26 11:11:54 -07:00
|
|
|
(bool)(shift_lock_mask & aEvent->nativeModifiers());
|
2011-09-28 23:19:26 -07:00
|
|
|
bool capslock_state = (bool)(caps_lock_mask & aEvent->nativeModifiers());
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// try to find a keysym that we can translate to a DOMKeyCode
|
|
|
|
// this is needed because some of Qt's keycodes cannot be translated
|
|
|
|
// TODO: use US keyboard keymap instead of localised keymap
|
|
|
|
if (!domKeyCode &&
|
|
|
|
aEvent->nativeScanCode() >= (quint32)x_min_keycode &&
|
|
|
|
aEvent->nativeScanCode() <= (quint32)x_max_keycode) {
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) {
|
|
|
|
domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// store character in domCharCode
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (int32_t) aEvent->text()[0].unicode();
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// If the key isn't autorepeat, we need to send the initial down event
|
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
// send the key down event
|
|
|
|
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
|
2010-08-26 11:11:54 -07:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
|
|
|
downEvent.keyCode = domKeyCode;
|
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273)
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(mIsDestroyed)) {
|
2010-08-26 11:11:54 -07:00
|
|
|
qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed";
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 07:59:28 -07:00
|
|
|
setNoDefault = true;
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't pass modifiers as NS_KEY_PRESS events.
|
|
|
|
// Instead of selectively excluding some keys from NS_KEY_PRESS events,
|
|
|
|
// we instead selectively include (as per MSDN spec
|
|
|
|
// ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28VS.71%29.aspx );
|
|
|
|
// no official spec covers KeyPress events).
|
|
|
|
if (aEvent->key() == Qt::Key_Shift ||
|
|
|
|
aEvent->key() == Qt::Key_Control ||
|
|
|
|
aEvent->key() == Qt::Key_Meta ||
|
|
|
|
aEvent->key() == Qt::Key_Alt ||
|
|
|
|
aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
|
|
|
|
return setNoDefault ?
|
|
|
|
nsEventStatus_eConsumeNoDefault :
|
|
|
|
nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2011-07-13 18:58:07 -07:00
|
|
|
// Look for specialized app-command keys
|
|
|
|
switch (aEvent->key()) {
|
|
|
|
case Qt::Key_Back:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Forward:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Refresh:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Reload);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Stop:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Stop);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Search:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Search);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Favorites:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Bookmarks);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_HomePage:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Home);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Copy:
|
|
|
|
case Qt::Key_F16: // F16, F20, F18, F14 are old keysyms for Copy Cut Paste Undo
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_COPY);
|
|
|
|
case Qt::Key_Cut:
|
|
|
|
case Qt::Key_F20:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_CUT);
|
|
|
|
case Qt::Key_Paste:
|
|
|
|
case Qt::Key_F18:
|
|
|
|
case Qt::Key_F9:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_PASTE);
|
|
|
|
case Qt::Key_F14:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Qt::Key_Redo and Qt::Key_Undo are not available yet.
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff66) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
|
|
|
|
}
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff65) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2010-08-26 11:11:54 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (setNoDefault) {
|
2012-12-15 17:26:04 -08:00
|
|
|
event.mFlags.mDefaultPrevented = true;
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no charcode attainable from the text, try to
|
|
|
|
// generate it from the keycode. Check shift state for case
|
|
|
|
// Also replace the charcode if ControlModifier is the only
|
|
|
|
// pressed Modifier
|
|
|
|
if ((!domCharCode) &&
|
|
|
|
(QApplication::keyboardModifiers() &
|
|
|
|
(Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
|
|
|
|
|
|
|
// get a character from X11 key map
|
|
|
|
KeySym keysym = aEvent->nativeVirtualKey();
|
|
|
|
if (keysym) {
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (uint32_t) keysym2ucs(keysym);
|
2012-11-03 21:00:08 -07:00
|
|
|
if (domCharCode == -1 || !QChar((quint32)domCharCode).isPrint()) {
|
2010-08-26 11:11:54 -07:00
|
|
|
domCharCode = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if Ctrl is pressed and domCharCode is not a ASCII character
|
|
|
|
if (domCharCode > 0xFF && (QApplication::keyboardModifiers() & Qt::ControlModifier)) {
|
|
|
|
// replace Unicode character
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
if (xkeymap[index + i] <= 0xFF && !shift_state) {
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (uint32_t) QChar::toLower((uint) xkeymap[index + i]);
|
2010-08-26 11:11:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // The key event should cause a character input.
|
|
|
|
// At that time, we need to reset the modifiers
|
|
|
|
// because nsEditor will not accept a key event
|
|
|
|
// for text input if one or more modifiers are set.
|
2012-04-24 20:00:02 -07:00
|
|
|
event.modifiers &= ~(widget::MODIFIER_CONTROL |
|
|
|
|
widget::MODIFIER_ALT |
|
|
|
|
widget::MODIFIER_META);
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
KeySym keysym = NoSymbol;
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
if (xkeymap[index + i] == aEvent->nativeVirtualKey()) {
|
|
|
|
if ((i % 2) == 0) { // shifted char
|
|
|
|
keysym = xkeymap[index + i + 1];
|
|
|
|
break;
|
|
|
|
} else { // unshifted char
|
|
|
|
keysym = xkeymap[index + i - 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xkeysyms_per_keycode - 1 == i) {
|
|
|
|
qWarning() << "Symbol '" << aEvent->nativeVirtualKey() << "' not found";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QChar unshiftedChar(domCharCode);
|
|
|
|
long ucs = keysym2ucs(keysym);
|
|
|
|
ucs = ucs == -1 ? 0 : ucs;
|
|
|
|
QChar shiftedChar((uint)ucs);
|
|
|
|
|
|
|
|
// append alternativeCharCodes if modifier is pressed
|
|
|
|
// append an additional alternativeCharCodes if domCharCode is not a Latin character
|
|
|
|
// and if one of these modifiers is pressed (i.e. Ctrl, Alt, Meta)
|
|
|
|
if (domCharCode &&
|
|
|
|
(QApplication::keyboardModifiers() &
|
|
|
|
(Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
|
|
|
event.keyCode = 0;
|
|
|
|
nsAlternativeCharCode altCharCode(0, 0);
|
|
|
|
// if character has a lower and upper representation
|
|
|
|
if ((unshiftedChar.isUpper() || unshiftedChar.isLower()) &&
|
|
|
|
unshiftedChar.toLower() == shiftedChar.toLower()) {
|
|
|
|
if (shift_state ^ capslock_state) {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode);
|
2010-08-26 11:11:54 -07:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode);
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) unshiftedChar.unicode();
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) shiftedChar.unicode();
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// append alternative char code to event
|
|
|
|
if ((altCharCode.mUnshiftedCharCode && altCharCode.mUnshiftedCharCode != domCharCode) ||
|
|
|
|
(altCharCode.mShiftedCharCode && altCharCode.mShiftedCharCode != domCharCode)) {
|
|
|
|
event.alternativeCharCodes.AppendElement(altCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the alternative char codes are latin-1
|
|
|
|
if (altCharCode.mUnshiftedCharCode > 0xFF || altCharCode.mShiftedCharCode > 0xFF) {
|
|
|
|
altCharCode.mUnshiftedCharCode = altCharCode.mShiftedCharCode = 0;
|
|
|
|
|
|
|
|
// find latin char for keycode
|
|
|
|
KeySym keysym = NoSymbol;
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
// find first shifted and unshifted Latin-Char in XKeyMap
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
keysym = xkeymap[index + i];
|
|
|
|
if (keysym && keysym <= 0xFF) {
|
|
|
|
if ((shift_state && (i % 2 == 1)) ||
|
|
|
|
(!shift_state && (i % 2 == 0))) {
|
|
|
|
altCharCode.mUnshiftedCharCode = altCharCode.mUnshiftedCharCode ?
|
|
|
|
altCharCode.mUnshiftedCharCode :
|
|
|
|
keysym;
|
|
|
|
} else {
|
|
|
|
altCharCode.mShiftedCharCode = altCharCode.mShiftedCharCode ?
|
|
|
|
altCharCode.mShiftedCharCode :
|
|
|
|
keysym;
|
|
|
|
}
|
|
|
|
if (altCharCode.mUnshiftedCharCode && altCharCode.mShiftedCharCode) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (altCharCode.mUnshiftedCharCode || altCharCode.mShiftedCharCode) {
|
|
|
|
event.alternativeCharCodes.AppendElement(altCharCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event.charCode = domCharCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmodmap) {
|
|
|
|
XFreeModifiermap(xmodmap);
|
|
|
|
}
|
|
|
|
if (xkeymap) {
|
|
|
|
XFree(xkeymap);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
|
|
|
#else
|
|
|
|
|
|
|
|
//:TODO: fix shortcuts hebrew for non X11,
|
|
|
|
//see Bug 562195##51
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// before we dispatch a key, check if it's the context menu key.
|
|
|
|
// If so, send a context menu key event instead.
|
2008-04-20 01:16:40 -07:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
2008-04-20 01:16:40 -07:00
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domCharCode = 0;
|
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (int32_t) aEvent->text()[0].unicode();
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// If the key isn't autorepeat, we need to send the initial down event
|
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
// send the key down event
|
|
|
|
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
2010-04-22 05:58:46 -07:00
|
|
|
downEvent.keyCode = domKeyCode;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 07:59:28 -07:00
|
|
|
setNoDefault = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
2010-08-26 11:11:54 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
|
|
|
|
if (setNoDefault)
|
2012-12-15 17:26:04 -08:00
|
|
|
event.mFlags.mDefaultPrevented = true;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
2010-08-26 11:11:54 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::OnKeyReleaseEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
|
|
|
// er, what do we do here? DoDefault or NoDefault?
|
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (!domKeyCode) {
|
|
|
|
// get keymap from the Xserver
|
2012-03-22 16:24:40 -07:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2010-08-26 11:11:54 -07:00
|
|
|
int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
|
|
|
|
XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
|
|
|
|
KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
|
|
|
|
&xkeysyms_per_keycode);
|
|
|
|
|
|
|
|
if (aEvent->nativeScanCode() >= (quint32)x_min_keycode &&
|
|
|
|
aEvent->nativeScanCode() <= (quint32)x_max_keycode) {
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) {
|
|
|
|
domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xkeymap) {
|
|
|
|
XFree(xkeymap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_X11
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// send the key event as a key up event
|
2011-10-17 07:59:28 -07:00
|
|
|
nsKeyEvent event(true, NS_KEY_UP, this);
|
2008-04-19 08:37:51 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = false;
|
|
|
|
}
|
|
|
|
|
2010-04-22 05:58:46 -07:00
|
|
|
event.keyCode = domKeyCode;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// unset the key down flag
|
|
|
|
ClearKeyDownFlag(event.keyCode);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnScrollEvent(QGraphicsSceneWheelEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
2012-08-11 18:42:37 -07:00
|
|
|
WheelEvent wheelEvent(true, NS_WHEEL_WHEEL, this);
|
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent::DOM_DELTA_LINE;
|
|
|
|
|
|
|
|
// negative values for aEvent->delta indicate downward scrolling;
|
|
|
|
// this is opposite Gecko usage.
|
|
|
|
// TODO: Store the unused delta values due to fraction round and add it
|
|
|
|
// to next event. The stored values should be reset by other
|
|
|
|
// direction scroll event.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
switch (aEvent->orientation()) {
|
|
|
|
case Qt::Vertical:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaY = wheelEvent.lineOrPageDeltaY = delta;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
case Qt::Horizontal:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaX = wheelEvent.lineOrPageDeltaX = delta;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.refPoint.x = nscoord(aEvent->scenePos().x());
|
|
|
|
wheelEvent.refPoint.y = nscoord(aEvent->scenePos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aEvent->modifiers() & Qt::MetaModifier);
|
|
|
|
wheelEvent.time = 0;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
return DispatchEvent(&wheelEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsVisible = true;
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::hideEvent(QHideEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsVisible = false;
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2010-03-12 14:11:42 -08:00
|
|
|
//Gestures are only supported in 4.6.0 >
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-09-28 23:19:26 -07:00
|
|
|
nsEventStatus nsWindow::OnTouchEvent(QTouchEvent *event, bool &handled)
|
2010-03-12 14:11:42 -08:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
handled = false;
|
2010-03-12 14:11:42 -08:00
|
|
|
const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
|
|
|
|
|
|
|
|
if (event->type() == QEvent::TouchBegin) {
|
2011-10-17 07:59:28 -07:00
|
|
|
handled = true;
|
2010-03-12 14:11:42 -08:00
|
|
|
for (int i = touchPoints.count() -1; i >= 0; i--) {
|
|
|
|
QPointF fpos = touchPoints[i].pos();
|
2011-10-17 07:59:28 -07:00
|
|
|
nsGestureNotifyEvent gestureNotifyEvent(true, NS_GESTURENOTIFY_EVENT_START, this);
|
2010-03-12 14:11:42 -08:00
|
|
|
gestureNotifyEvent.refPoint = nsIntPoint(fpos.x(), fpos.y());
|
|
|
|
DispatchEvent(&gestureNotifyEvent);
|
|
|
|
}
|
|
|
|
}
|
2010-10-08 23:08:42 -07:00
|
|
|
else if (event->type() == QEvent::TouchEnd) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mGesturesCancelled = false;
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.needDispatch = false;
|
2010-10-08 23:08:42 -07:00
|
|
|
}
|
|
|
|
|
2011-01-18 00:51:04 -08:00
|
|
|
if (touchPoints.count() > 0) {
|
|
|
|
// Remember start touch point in order to use it for
|
|
|
|
// distance calculation in NS_SIMPLE_GESTURE_MAGNIFY_UPDATE
|
2011-03-15 13:30:34 -07:00
|
|
|
mPinchEvent.touchPoint = touchPoints.at(0).pos();
|
2010-10-08 23:08:42 -07:00
|
|
|
}
|
2010-03-12 14:11:42 -08:00
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
nsEventStatus
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::OnGestureEvent(QGestureEvent* event, bool &handled) {
|
2010-10-08 23:08:42 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
handled = false;
|
2010-10-08 23:08:42 -07:00
|
|
|
if (mGesturesCancelled) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
QGesture* gesture = event->gesture(Qt::PinchGesture);
|
|
|
|
|
|
|
|
if (gesture) {
|
|
|
|
QPinchGesture* pinch = static_cast<QPinchGesture*>(gesture);
|
2011-10-17 07:59:28 -07:00
|
|
|
handled = true;
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.centerPoint =
|
2010-10-08 23:14:57 -07:00
|
|
|
mWidget->mapFromScene(event->mapToGraphicsScene(pinch->centerPoint()));
|
2011-01-18 00:51:04 -08:00
|
|
|
nsIntPoint centerPoint(mPinchEvent.centerPoint.x(),
|
|
|
|
mPinchEvent.centerPoint.y());
|
2010-03-12 14:11:42 -08:00
|
|
|
|
|
|
|
if (pinch->state() == Qt::GestureStarted) {
|
|
|
|
event->accept();
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.startDistance = DistanceBetweenPoints(mPinchEvent.centerPoint, mPinchEvent.touchPoint) * 2;
|
|
|
|
mPinchEvent.prevDistance = mPinchEvent.startDistance;
|
2010-10-08 23:08:42 -07:00
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY_START,
|
|
|
|
0, 0, centerPoint);
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
else if (pinch->state() == Qt::GestureUpdated) {
|
2011-03-15 13:30:34 -07:00
|
|
|
mPinchEvent.needDispatch = true;
|
|
|
|
mPinchEvent.delta = 0;
|
|
|
|
DispatchMotionToMainThread();
|
2010-04-20 19:50:49 -07:00
|
|
|
}
|
|
|
|
else if (pinch->state() == Qt::GestureFinished) {
|
2011-01-18 00:51:04 -08:00
|
|
|
double distance = DistanceBetweenPoints(mPinchEvent.centerPoint, mPinchEvent.touchPoint) * 2;
|
|
|
|
double delta = distance - mPinchEvent.startDistance;
|
2010-10-08 23:08:42 -07:00
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY,
|
|
|
|
0, delta, centerPoint);
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.needDispatch = false;
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
else {
|
2010-10-08 23:08:42 -07:00
|
|
|
handled = false;
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
2010-04-20 19:50:49 -07:00
|
|
|
|
2011-01-18 00:51:04 -08:00
|
|
|
//Disable mouse events when gestures are used, because they cause problems with
|
|
|
|
//Fennec
|
|
|
|
mLastMultiTouchTime.start();
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
gesture = event->gesture(gSwipeGestureId);
|
|
|
|
if (gesture) {
|
|
|
|
if (gesture->state() == Qt::GestureStarted) {
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
if (gesture->state() == Qt::GestureFinished) {
|
|
|
|
event->accept();
|
2011-10-17 07:59:28 -07:00
|
|
|
handled = true;
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
MozSwipeGesture* swipe = static_cast<MozSwipeGesture*>(gesture);
|
|
|
|
nsIntPoint hotspot;
|
|
|
|
hotspot.x = swipe->hotSpot().x();
|
|
|
|
hotspot.y = swipe->hotSpot().y();
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
// Cancel pinch gesture
|
2011-10-17 07:59:28 -07:00
|
|
|
mGesturesCancelled = true;
|
2011-01-18 00:51:04 -08:00
|
|
|
mPinchEvent.needDispatch = false;
|
|
|
|
|
|
|
|
double distance = DistanceBetweenPoints(swipe->hotSpot(), mPinchEvent.touchPoint) * 2;
|
2012-08-09 00:09:42 -07:00
|
|
|
double delta = distance - mPinchEvent.startDistance;
|
2011-01-18 00:51:04 -08:00
|
|
|
|
|
|
|
DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY, 0, delta / 2, hotspot);
|
2010-10-08 23:08:42 -07:00
|
|
|
|
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_SWIPE,
|
|
|
|
swipe->Direction(), 0, hotspot);
|
|
|
|
}
|
2011-01-18 00:51:04 -08:00
|
|
|
mLastMultiTouchTime.start();
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
2010-10-08 23:08:42 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::DispatchGestureEvent(uint32_t aMsg, uint32_t aDirection,
|
2010-10-08 23:08:42 -07:00
|
|
|
double aDelta, const nsIntPoint& aRefPoint)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsSimpleGestureEvent mozGesture(true, aMsg, this, 0, 0.0);
|
2010-10-08 23:08:42 -07:00
|
|
|
mozGesture.direction = aDirection;
|
|
|
|
mozGesture.delta = aDelta;
|
|
|
|
mozGesture.refPoint = aRefPoint;
|
|
|
|
|
|
|
|
Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
|
|
|
|
|
2012-04-24 20:00:02 -07:00
|
|
|
mozGesture.InitBasicModifiers(modifiers & Qt::ControlModifier,
|
|
|
|
modifiers & Qt::AltModifier,
|
|
|
|
modifiers & Qt::ShiftModifier,
|
|
|
|
false);
|
2010-10-08 23:08:42 -07:00
|
|
|
mozGesture.button = 0;
|
|
|
|
mozGesture.time = 0;
|
|
|
|
|
|
|
|
return DispatchEvent(&mozGesture);
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
|
2010-03-12 14:11:42 -08:00
|
|
|
double
|
|
|
|
nsWindow::DistanceBetweenPoints(const QPointF &aFirstPoint, const QPointF &aSecondPoint)
|
|
|
|
{
|
|
|
|
double result = 0;
|
|
|
|
double deltaX = abs(aFirstPoint.x() - aSecondPoint.x());
|
|
|
|
double deltaY = abs(aFirstPoint.y() - aSecondPoint.y());
|
|
|
|
result = sqrt(deltaX*deltaX + deltaY*deltaY);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //qt version check
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
void
|
|
|
|
nsWindow::ThemeChanged()
|
|
|
|
{
|
2012-08-15 11:52:35 -07:00
|
|
|
NotifyThemeChanged();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragMotionEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::OnDragMotionSignal\n"));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_OVER, 0,
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragLeaveEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// XXX Do we want to pass this on only if the event's subwindow is null?
|
|
|
|
LOG(("nsWindow::OnDragLeaveSignal(%p)\n", this));
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragDropEvent(QGraphicsSceneDragDropEvent *aDropEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-19 08:43:56 -07:00
|
|
|
if (aDropEvent->proposedAction() == Qt::CopyAction)
|
|
|
|
{
|
2013-02-25 12:25:16 -08:00
|
|
|
printf("text version of the data: %s\n", aDropEvent->mimeData()->text().toUtf8().data());
|
2008-04-19 08:43:56 -07:00
|
|
|
aDropEvent->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
LOG(("nsWindow::OnDragDropSignal\n"));
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_OVER, 0,
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragEnter(QGraphicsSceneDragDropEvent *aDragEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-19 08:43:56 -07:00
|
|
|
// Is it some format we think we can support?
|
|
|
|
if ( aDragEvent->mimeData()->hasFormat(kURLMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kURLDataMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kURLDescriptionMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kHTMLMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kUnicodeMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kTextMime)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
aDragEvent->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// XXX Do we want to pass this on only if the event's subwindow is null?
|
|
|
|
|
|
|
|
LOG(("nsWindow::OnDragEnter(%p)\n", this));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWidgetInitData *aInitData)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
// only set the base parent if we're not going to be a dialog or a
|
2008-04-19 08:37:51 -07:00
|
|
|
// toplevel
|
2010-02-16 10:14:20 -08:00
|
|
|
nsIWidget *baseParent = aParent;
|
|
|
|
|
|
|
|
if (aInitData &&
|
2008-04-19 08:37:51 -07:00
|
|
|
(aInitData->mWindowType == eWindowType_dialog ||
|
|
|
|
aInitData->mWindowType == eWindowType_toplevel ||
|
2010-02-16 10:14:20 -08:00
|
|
|
aInitData->mWindowType == eWindowType_invisible)) {
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
baseParent = nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
// also drop native parent for toplevel windows
|
2012-07-30 07:20:58 -07:00
|
|
|
aNativeParent = nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// initialize all the common bits of this class
|
2012-08-15 11:53:09 -07:00
|
|
|
BaseCreate(baseParent, aRect, aContext, aInitData);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// and do our common creation
|
2008-04-22 04:21:18 -07:00
|
|
|
mParent = aParent;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// find native parent
|
2012-07-30 07:20:58 -07:00
|
|
|
MozQWidget *parent = nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aParent != nullptr)
|
2010-02-16 10:14:20 -08:00
|
|
|
parent = static_cast<MozQWidget*>(aParent->GetNativeData(NS_NATIVE_WIDGET));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// ok, create our QGraphicsWidget
|
2011-09-25 12:03:22 -07:00
|
|
|
mWidget = createQWidget(parent, aNativeParent, aInitData);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-02-16 07:27:18 -08:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
LOG(("Create: nsWindow [%p] [%p]\n", (void *)this, (void *)mWidget));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// resize so that everything is set to the right dimensions
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
// check if we should listen for resizes
|
|
|
|
mListenForResizes = (aNativeParent ||
|
|
|
|
(aInitData && aInitData->mListenForResizes));
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-31 09:35:57 -07:00
|
|
|
already_AddRefed<nsIWidget>
|
|
|
|
nsWindow::CreateChild(const nsIntRect& aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext* aContext,
|
2010-08-31 09:35:57 -07:00
|
|
|
nsWidgetInitData* aInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool /*aForceUseIWidgetParent*/)
|
2010-08-31 09:35:57 -07:00
|
|
|
{
|
|
|
|
//We need to force parent widget, otherwise GetTopLevelWindow doesn't work
|
|
|
|
return nsBaseWidget::CreateChild(aRect,
|
|
|
|
aContext,
|
|
|
|
aInitData,
|
2011-10-17 07:59:28 -07:00
|
|
|
true); // Force parent
|
2010-08-31 09:35:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2010-02-16 10:14:20 -08:00
|
|
|
XClassHint *class_hint = XAllocClassHint();
|
|
|
|
if (!class_hint)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
const char *role = NULL;
|
|
|
|
class_hint->res_name = ToNewCString(xulWinType);
|
|
|
|
if (!class_hint->res_name) {
|
|
|
|
XFree(class_hint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
class_hint->res_class = ToNewCString(brandName);
|
|
|
|
if (!class_hint->res_class) {
|
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
for (char *c = class_hint->res_name; *c; c++) {
|
|
|
|
if (':' == *c) {
|
|
|
|
*c = 0;
|
|
|
|
role = c + 1;
|
|
|
|
}
|
|
|
|
else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c)))
|
|
|
|
*c = '_';
|
|
|
|
}
|
|
|
|
class_hint->res_name[0] = toupper(class_hint->res_name[0]);
|
|
|
|
if (!role) role = class_hint->res_name;
|
|
|
|
|
2010-03-10 14:13:02 -08:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
// If widget not show, handle might be null
|
2012-03-22 16:24:40 -07:00
|
|
|
if (widget && widget->winId())
|
|
|
|
XSetClassHint(gfxQtPlatform::GetXDisplay(widget),
|
|
|
|
widget->winId(),
|
2010-03-10 14:13:02 -08:00
|
|
|
class_hint);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
|
|
|
nsMemory::Free(class_hint->res_class);
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2008-04-20 06:54:27 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::NativeResize(int32_t aWidth, int32_t aHeight, bool aRepaint)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = false;
|
2010-03-21 19:55:36 -07:00
|
|
|
|
2011-02-02 22:31:36 -08:00
|
|
|
if (mIsTopLevel) {
|
2011-12-22 20:13:53 -08:00
|
|
|
QGraphicsView *widget = qobject_cast<QGraphicsView*>(GetViewWidget());
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(widget);
|
2011-12-22 20:13:53 -08:00
|
|
|
// map from in-scene widget to scene, from scene to view.
|
|
|
|
QRect r = widget->mapFromScene(mWidget->mapToScene(QRect(0, 0, aWidth, aHeight))).boundingRect();
|
|
|
|
// going from QPolygon to QRect includes the points, adding one to width and height
|
|
|
|
r.adjust(0, 0, -1, -1);
|
|
|
|
widget->resize(r.width(), r.height());
|
2010-08-20 18:12:14 -07:00
|
|
|
}
|
2011-02-02 22:31:43 -08:00
|
|
|
else {
|
|
|
|
mWidget->resize(aWidth, aHeight);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::NativeResize(int32_t aX, int32_t aY,
|
|
|
|
int32_t aWidth, int32_t aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aX, aY, aWidth, aHeight));
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
2010-03-21 19:55:36 -07:00
|
|
|
|
2010-05-14 11:13:36 -07:00
|
|
|
if (mIsTopLevel) {
|
2011-12-22 20:13:53 -08:00
|
|
|
QGraphicsView *widget = qobject_cast<QGraphicsView*>(GetViewWidget());
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(widget);
|
2011-12-22 20:13:53 -08:00
|
|
|
// map from in-scene widget to scene, from scene to view.
|
|
|
|
QRect r = widget->mapFromScene(mWidget->mapToScene(QRect(aX, aY, aWidth, aHeight))).boundingRect();
|
|
|
|
// going from QPolygon to QRect includes the points, adding one to width and height
|
|
|
|
r.adjust(0, 0, -1, -1);
|
|
|
|
widget->setGeometry(r.x(), r.y(), r.width(), r.height());
|
2010-05-14 11:13:36 -07:00
|
|
|
}
|
2011-02-02 22:31:43 -08:00
|
|
|
else {
|
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::NativeShow(bool aAction)
|
2009-08-04 19:39:05 -07:00
|
|
|
{
|
2010-03-14 23:08:15 -07:00
|
|
|
if (aAction) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
2010-03-18 09:44:33 -07:00
|
|
|
// On e10s, we never want the child process or plugin process
|
|
|
|
// to go fullscreen because if we do the window because visible
|
|
|
|
// do to disabled Qt-Xembed
|
2011-01-13 05:20:48 -08:00
|
|
|
if (widget &&
|
|
|
|
!widget->isVisible())
|
2010-03-14 23:08:15 -07:00
|
|
|
MakeFullScreen(mSizeMode == nsSizeMode_Fullscreen);
|
2009-08-04 19:39:05 -07:00
|
|
|
mWidget->show();
|
2010-03-21 19:55:36 -07:00
|
|
|
|
|
|
|
// unset our flag now that our window has been shown
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsShow = false;
|
2010-03-14 23:08:15 -07:00
|
|
|
}
|
2009-08-04 19:39:05 -07:00
|
|
|
else
|
|
|
|
mWidget->hide();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetHasTransparentBackground(bool aTransparent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::GetHasTransparentBackground(bool& aTransparent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
aTransparent = mIsTransparent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
2010-04-20 11:49:34 -07:00
|
|
|
NS_WARNING("Not implemented");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-01-21 20:15:34 -08:00
|
|
|
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
QIcon icon;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aIconList.Length(); ++i) {
|
2010-02-16 10:14:20 -08:00
|
|
|
const char *path = aIconList[i].get();
|
|
|
|
LOG(("window [%p] Loading icon from %s\n", (void *)this, path));
|
|
|
|
icon.addFile(path);
|
|
|
|
}
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2010-03-14 23:08:15 -07:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
widget->setWindowIcon(icon);
|
2010-03-05 23:25:46 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
|
|
|
{
|
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:35:27 -07:00
|
|
|
void nsWindow::QWidgetDestroyed()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mWidget = nullptr;
|
2009-03-27 04:35:27 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-03-14 23:08:15 -07:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
2010-02-04 06:43:52 -08:00
|
|
|
if (aFullScreen) {
|
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen)
|
|
|
|
mLastSizeMode = mSizeMode;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-02-04 06:43:52 -08:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showFullScreen();
|
2010-02-04 06:43:52 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
|
|
|
|
|
|
|
switch (mSizeMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showMaximized();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showMinimized();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Normal:
|
2010-03-14 23:08:15 -07:00
|
|
|
widget->showNormal();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
widget->showNormal();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 17:33:31 -07:00
|
|
|
|
2010-02-04 06:43:52 -08:00
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
2010-03-25 17:33:31 -07:00
|
|
|
return nsBaseWidget::MakeFullScreen(aFullScreen);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::HideWindowChrome(bool aShouldHide)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget) {
|
2010-07-26 21:38:35 -07:00
|
|
|
// Nothing to hide
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget->isVisible()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
NativeShow(false);
|
|
|
|
wasVisible = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wasVisible) {
|
2011-10-17 07:59:28 -07:00
|
|
|
NativeShow(true);
|
2008-04-19 08:37:51 -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)
|
2010-03-14 23:08:15 -07:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2012-03-22 16:24:40 -07:00
|
|
|
XSync(gfxQtPlatform::GetXDisplay(widget), False);
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// These are all of our drag and drop operations
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::InitDragEvent(nsMouseEvent &aEvent)
|
|
|
|
{
|
|
|
|
// set the keyboard modifiers
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will update the drag action based on the information in the
|
2010-02-16 10:14:20 -08:00
|
|
|
// drag context.
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
initialize_prefs(void)
|
|
|
|
{
|
|
|
|
// check to see if we should set our raise pref
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2008-04-19 08:37:51 -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()));
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
key_event_to_context_menu_event(nsMouseEvent &aEvent,
|
|
|
|
QKeyEvent *aGdkEvent)
|
|
|
|
{
|
2009-02-11 05:51:06 -08:00
|
|
|
aEvent.refPoint = nsIntPoint(0, 0);
|
2012-04-24 20:00:02 -07:00
|
|
|
aEvent.modifiers = 0;
|
2008-04-19 08:37:51 -07:00
|
|
|
aEvent.time = 0;
|
|
|
|
aEvent.clickCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsChildWindow class
|
|
|
|
|
|
|
|
nsChildWindow::nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChildWindow::~nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::nsPopupWindow()
|
|
|
|
{
|
2010-08-26 08:18:06 -07:00
|
|
|
#ifdef DEBUG_WIDGETS
|
2008-04-19 08:37:51 -07:00
|
|
|
qDebug("===================== popup!");
|
2010-08-26 08:18:06 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::~nsPopupWindow()
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-11 21:18:35 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
nsWindow::HasGLContext()
|
|
|
|
{
|
2012-08-16 08:31:47 -07:00
|
|
|
return MozQGLWidgetWrapper::hasGLContext(qobject_cast<QGraphicsView*>(GetViewWidget()));
|
2012-04-11 21:18:35 -07:00
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
MozQWidget*
|
2011-09-25 12:03:22 -07:00
|
|
|
nsWindow::createQWidget(MozQWidget *parent,
|
|
|
|
nsNativeWidget nativeParent,
|
|
|
|
nsWidgetInitData *aInitData)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
const char *windowName = NULL;
|
2011-02-02 22:31:43 -08:00
|
|
|
Qt::WindowFlags flags = Qt::Widget;
|
|
|
|
QWidget *parentWidget = (parent && parent->getReceiver()) ?
|
2012-07-30 07:20:58 -07:00
|
|
|
parent->getReceiver()->GetViewWidget() : nullptr;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
#ifdef DEBUG_WIDGETS
|
|
|
|
qDebug("NEW WIDGET\n\tparent is %p (%s)", (void*)parent,
|
|
|
|
parent ? qPrintable(parent->objectName()) : "null");
|
|
|
|
#endif
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
// ok, create our windows
|
|
|
|
switch (mWindowType) {
|
|
|
|
case eWindowType_dialog:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelDialog";
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTopLevel = true;
|
2011-02-02 22:31:43 -08:00
|
|
|
flags |= Qt::Dialog;
|
2008-04-20 01:16:40 -07:00
|
|
|
break;
|
2008-04-19 08:31:50 -07:00
|
|
|
case eWindowType_popup:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelPopup";
|
|
|
|
break;
|
2008-04-19 08:31:50 -07:00
|
|
|
case eWindowType_toplevel:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelWindow";
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTopLevel = true;
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
2008-04-20 01:16:40 -07:00
|
|
|
case eWindowType_invisible:
|
|
|
|
windowName = "topLevelInvisible";
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
2008-04-20 01:16:40 -07:00
|
|
|
case eWindowType_child:
|
2009-09-24 02:32:20 -07:00
|
|
|
case eWindowType_plugin:
|
|
|
|
default: // sheet
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "paintArea";
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
MozQWidget* parentQWidget = nullptr;
|
2011-09-25 12:03:22 -07:00
|
|
|
if (parent) {
|
|
|
|
parentQWidget = parent;
|
|
|
|
} else if (nativeParent && nativeParent != PARENTLESS_WIDGET) {
|
|
|
|
parentQWidget = static_cast<MozQWidget*>(nativeParent);
|
|
|
|
}
|
|
|
|
MozQWidget * widget = new MozQWidget(this, parentQWidget);
|
2010-02-16 10:14:20 -08:00
|
|
|
if (!widget)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-11-03 21:00:08 -07:00
|
|
|
widget->setObjectName(QString(windowName));
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-02-25 10:58:19 -08:00
|
|
|
// make only child and plugin windows focusable
|
|
|
|
if (eWindowType_child == mWindowType || eWindowType_plugin == mWindowType) {
|
|
|
|
widget->setFlag(QGraphicsItem::ItemIsFocusable);
|
|
|
|
widget->setFocusPolicy(Qt::WheelFocus);
|
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// create a QGraphicsView if this is a new toplevel window
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
if (mIsTopLevel) {
|
2011-10-28 05:13:57 -07:00
|
|
|
QGraphicsView* newView =
|
|
|
|
nsFastStartup::GetStartupGraphicsView(parentWidget, widget);
|
2011-02-02 22:31:36 -08:00
|
|
|
|
2011-02-02 22:31:43 -08:00
|
|
|
if (mWindowType == eWindowType_dialog) {
|
|
|
|
newView->setWindowModality(Qt::WindowModal);
|
|
|
|
}
|
|
|
|
|
2012-04-24 06:23:26 -07:00
|
|
|
#if defined(MOZ_PLATFORM_MAEMO) || defined(MOZ_GL_PROVIDER)
|
2012-11-15 10:55:15 -08:00
|
|
|
if (ComputeShouldAccelerate(mUseLayersAcceleration)) {
|
2011-10-28 05:13:57 -07:00
|
|
|
// Only create new OGL widget if it is not yet installed
|
2012-04-11 21:18:35 -07:00
|
|
|
if (!HasGLContext()) {
|
2012-04-24 06:23:26 -07:00
|
|
|
MozQGraphicsView *qview = qobject_cast<MozQGraphicsView*>(newView);
|
|
|
|
if (qview) {
|
|
|
|
qview->setGLWidgetEnabled(true);
|
|
|
|
}
|
2011-10-28 05:13:57 -07:00
|
|
|
}
|
2010-09-14 22:15:14 -07:00
|
|
|
}
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-10-26 21:56:31 -07:00
|
|
|
if (gfxQtPlatform::GetPlatform()->GetRenderMode() == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
// Disable double buffer and system background rendering
|
2012-03-22 16:24:40 -07:00
|
|
|
#if defined(MOZ_X11) && (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
2010-10-26 21:56:31 -07:00
|
|
|
newView->viewport()->setAttribute(Qt::WA_PaintOnScreen, true);
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2010-10-26 21:56:31 -07:00
|
|
|
newView->viewport()->setAttribute(Qt::WA_NoSystemBackground, true);
|
|
|
|
}
|
2010-03-12 14:11:42 -08:00
|
|
|
// Enable gestures:
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-08-28 11:09:56 -07:00
|
|
|
#if defined MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
// Disable default Gesture filters (speedup filtering)
|
|
|
|
newView->viewport()->ungrabGesture(Qt::PanGesture);
|
|
|
|
newView->viewport()->ungrabGesture(Qt::TapGesture);
|
|
|
|
newView->viewport()->ungrabGesture(Qt::TapAndHoldGesture);
|
|
|
|
newView->viewport()->ungrabGesture(Qt::SwipeGesture);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Enable required filters
|
2010-03-12 14:11:42 -08:00
|
|
|
newView->viewport()->grabGesture(Qt::PinchGesture);
|
2010-10-08 23:08:42 -07:00
|
|
|
newView->viewport()->grabGesture(gSwipeGestureId);
|
2010-03-12 14:11:42 -08:00
|
|
|
#endif
|
2010-02-16 10:14:20 -08:00
|
|
|
newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
2010-02-25 12:45:37 -08:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
|
|
|
// Top level widget is just container, and should not be painted
|
|
|
|
widget->setFlag(QGraphicsItem::ItemHasNoContents);
|
|
|
|
#endif
|
2011-01-04 07:37:27 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2011-02-23 09:39:00 -08:00
|
|
|
if (newView->effectiveWinId()) {
|
2012-03-22 16:24:40 -07:00
|
|
|
XSetWindowBackgroundPixmap(mozilla::DefaultXDisplay(),
|
2011-02-23 09:39:00 -08:00
|
|
|
newView->effectiveWinId(), None);
|
|
|
|
}
|
2011-01-04 07:37:27 -08:00
|
|
|
#endif
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
2010-02-16 10:14:20 -08:00
|
|
|
widget->setZValue(100);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
// XXX is this needed for Qt?
|
|
|
|
// gdk does not automatically set the cursor for "temporary"
|
|
|
|
// windows, which are what gtk uses for popups.
|
|
|
|
SetCursor(eCursor_standard);
|
|
|
|
} else if (mIsTopLevel) {
|
|
|
|
SetDefaultIcon();
|
|
|
|
}
|
2010-10-08 23:08:42 -07:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-08-28 11:09:56 -07:00
|
|
|
#if defined MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
// Disable default Gesture filters (speedup filtering)
|
|
|
|
widget->ungrabGesture(Qt::PanGesture);
|
|
|
|
widget->ungrabGesture(Qt::TapGesture);
|
|
|
|
widget->ungrabGesture(Qt::TapAndHoldGesture);
|
|
|
|
widget->ungrabGesture(Qt::SwipeGesture);
|
|
|
|
#endif
|
2010-10-08 23:08:42 -07:00
|
|
|
widget->grabGesture(Qt::PinchGesture);
|
|
|
|
widget->grabGesture(gSwipeGestureId);
|
|
|
|
#endif
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
return widget;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// return the gfxASurface for rendering to this widget
|
2008-04-19 08:31:50 -07:00
|
|
|
gfxASurface*
|
|
|
|
nsWindow::GetThebesSurface()
|
|
|
|
{
|
2008-04-28 18:16:45 -07:00
|
|
|
/* This is really a dummy surface; this is only used when doing reflow, because
|
|
|
|
* we need a RenderingContext to measure text against.
|
|
|
|
*/
|
2010-02-19 19:46:54 -08:00
|
|
|
if (mThebesSurface)
|
|
|
|
return mThebesSurface;
|
|
|
|
|
2010-10-04 23:15:57 -07:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-10-26 21:56:31 -07:00
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
2010-02-19 19:46:54 -08:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
mThebesSurface = new gfxQPainterSurface(gfxIntSize(1, 1), gfxASurface::CONTENT_COLOR);
|
|
|
|
}
|
2010-10-04 23:15:57 -07:00
|
|
|
#endif
|
2010-02-19 19:46:54 -08:00
|
|
|
if (!mThebesSurface) {
|
|
|
|
gfxASurface::gfxImageFormat imageFormat = gfxASurface::ImageFormatRGB24;
|
|
|
|
mThebesSurface = new gfxImageSurface(gfxIntSize(1, 1), imageFormat);
|
|
|
|
}
|
2008-04-19 08:31:50 -07:00
|
|
|
|
|
|
|
return mThebesSurface;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
|
|
|
|
if (aEvent->eventStructType != NS_MOUSE_EVENT) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// you can only begin a resize drag with a mouse event
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent* mouse_event = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
|
|
|
|
if (mouse_event->button != nsMouseEvent::eLeftButton) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// you can only begin a resize drag with the left mouse button
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::imComposeEvent(QInputMethodEvent *event, bool &handled)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2011-09-22 02:17:40 -07:00
|
|
|
// XXX Needs to check whether this widget has been destroyed or not after
|
|
|
|
// each DispatchEvent().
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCompositionEvent start(true, NS_COMPOSITION_START, this);
|
2010-11-19 15:41:40 -08:00
|
|
|
DispatchEvent(&start);
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2011-09-22 02:17:40 -07:00
|
|
|
nsAutoString compositionStr(event->commitString().utf16());
|
|
|
|
|
|
|
|
if (!compositionStr.IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCompositionEvent update(true, NS_COMPOSITION_UPDATE, this);
|
2011-09-22 02:17:40 -07:00
|
|
|
update.data = compositionStr;
|
|
|
|
DispatchEvent(&update);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsTextEvent text(true, NS_TEXT_TEXT, this);
|
2011-09-22 02:17:40 -07:00
|
|
|
text.theText = compositionStr;
|
2010-11-19 15:41:40 -08:00
|
|
|
DispatchEvent(&text);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCompositionEvent end(true, NS_COMPOSITION_END, this);
|
2011-09-22 02:17:40 -07:00
|
|
|
end.data = compositionStr;
|
2010-11-19 15:41:40 -08:00
|
|
|
DispatchEvent(&end);
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
nsIWidget *
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:57:55 -07:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
|
|
|
QDesktopWidget* rootWindow = QApplication::desktop();
|
|
|
|
double heightInches = rootWindow->heightMM()/25.4;
|
|
|
|
if (heightInches < 0.25) {
|
|
|
|
// Something's broken, but we'd better not crash.
|
|
|
|
return 96.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return float(rootWindow->height()/heightInches);
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->WindowActivated();
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->WindowDeactivated();
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
2010-07-28 18:05:56 -07:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEventOnTopLevelWindow(void)
|
|
|
|
{
|
|
|
|
nsWindow * topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
2012-07-30 07:20:58 -07:00
|
|
|
if (topLevelWindow != nullptr)
|
2010-07-28 18:05:56 -07:00
|
|
|
topLevelWindow->DispatchActivateEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEventOnTopLevelWindow(void)
|
|
|
|
{
|
|
|
|
nsWindow * topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
2012-07-30 07:20:58 -07:00
|
|
|
if (topLevelWindow != nullptr)
|
2010-07-28 18:05:56 -07:00
|
|
|
topLevelWindow->DispatchDeactivateEvent();
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
void
|
2009-02-11 05:51:06 -08:00
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
if (mWidgetListener &&
|
|
|
|
mWidgetListener->WindowResized(this, aRect.width, aRect.height))
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-15 11:53:09 -07:00
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, aEvent->widget, aEvent,
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString("something"), 0);
|
2008-04-22 04:21:17 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// send it to the standard callback
|
2012-08-15 11:53:09 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
aStatus = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Show(bool aState)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
2012-11-03 21:00:08 -07:00
|
|
|
if (aState == mIsShown)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Clear our cached resources when the window is hidden.
|
|
|
|
if (mIsShown && !aState) {
|
|
|
|
ClearCachedResources();
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
mIsShown = aState;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-05-02 01:16:22 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
if (mWidget &&
|
|
|
|
(mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog ||
|
|
|
|
mWindowType == eWindowType_popup))
|
|
|
|
{
|
|
|
|
if (!gOrientation) {
|
|
|
|
gOrientation = new QOrientationSensor();
|
|
|
|
gOrientation->addFilter(&gOrientationFilter);
|
|
|
|
gOrientation->start();
|
|
|
|
if (!gOrientation->isActive()) {
|
|
|
|
qWarning("Orientationsensor didn't start!");
|
|
|
|
}
|
|
|
|
gOrientationFilter.filter(gOrientation->reading());
|
|
|
|
|
|
|
|
QObject::connect((QObject*) &gOrientationFilter, SIGNAL(orientationChanged()),
|
|
|
|
mWidget, SLOT(orientationChanged()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
if ((aState && !AreBoundsSane()) || !mWidget) {
|
|
|
|
LOG(("\tbounds are insane or window hasn't been created yet\n"));
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsShow = true;
|
2008-04-22 04:21:18 -07:00
|
|
|
return NS_OK;
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aState) {
|
|
|
|
if (mNeedsMove) {
|
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2010-03-21 19:55:36 -07:00
|
|
|
} else if (mNeedsResize) {
|
2011-10-17 07:59:28 -07:00
|
|
|
NativeResize(mBounds.width, mBounds.height, false);
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// If someone is hiding this widget, clear any needing show flag.
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsShow = false;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
NativeShow(aState);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-17 08:51:54 -08:00
|
|
|
nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
if (mIsShown) {
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
if (mIsTopLevel || mNeedsShow)
|
|
|
|
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-17 07:59:28 -07:00
|
|
|
NativeShow(true);
|
2010-03-21 19:55:36 -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-17 07:59:28 -07:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2010-03-21 19:55:36 -07:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
2012-12-12 01:57:38 -08:00
|
|
|
NativeResize(mBounds.width, mBounds.height, aRepaint);
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = true;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
// synthesize a resize event if this isn't a toplevel
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
nsEventStatus status;
|
2012-12-12 01:57:38 -08:00
|
|
|
DispatchResizeEvent(mBounds, status);
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
mBounds.x = NSToIntRound(aX);
|
|
|
|
mBounds.y = NSToIntRound(aY);
|
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mPlaced = true;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
// Has this widget been set to visible?
|
|
|
|
if (mIsShown) {
|
|
|
|
// Are the bounds sane?
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
// Yep? Resize the window
|
2012-12-12 01:57:38 -08:00
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
|
|
|
aRepaint);
|
2010-03-21 19:55:36 -07:00
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow)
|
2011-10-17 07:59:28 -07:00
|
|
|
NativeShow(true);
|
2010-03-21 19:55:36 -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-17 07:59:28 -07:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2010-03-21 19:55:36 -07:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2010-03-21 19:55:36 -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.
|
2012-12-12 01:57:38 -08:00
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
|
|
|
aRepaint);
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = true;
|
|
|
|
mNeedsMove = true;
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2010-03-21 19:55:36 -07:00
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
// synthesize a resize event
|
|
|
|
nsEventStatus status;
|
2012-12-12 01:57:38 -08:00
|
|
|
DispatchResizeEvent(mBounds, status);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-22 04:21:18 -07:00
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::Enable(bool aState)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
|
|
|
mEnabled = aState;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-22 22:19:08 -07:00
|
|
|
bool
|
|
|
|
nsWindow::IsEnabled() const
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2012-07-22 22:19:08 -07:00
|
|
|
return mEnabled;
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mOnDestroyCalled = true;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
// release references to children and device context
|
2008-04-22 04:21:17 -07:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// let go of our parent
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
2012-08-15 11:52:41 -07:00
|
|
|
NotifyWindowDestroyed();
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-04-22 04:21:17 -07:00
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
|
|
|
if (mBounds.width > 0 && mBounds.height > 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
2010-03-12 14:07:32 -08:00
|
|
|
|
2011-09-07 08:06:35 -07:00
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
|
|
|
typedef enum {
|
|
|
|
VKBUndefined,
|
|
|
|
VKBOpen,
|
|
|
|
VKBClose
|
|
|
|
} PluginVKBState;
|
|
|
|
|
|
|
|
static QCoreApplication::EventFilter previousEventFilter = NULL;
|
|
|
|
|
|
|
|
static PluginVKBState
|
|
|
|
GetPluginVKBState(Window aWinId)
|
|
|
|
{
|
|
|
|
// Set default value as unexpected error
|
|
|
|
PluginVKBState imeState = VKBUndefined;
|
2012-03-22 16:24:40 -07:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2011-09-07 08:06:35 -07:00
|
|
|
|
|
|
|
Atom actualType;
|
|
|
|
int actualFormat;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
|
|
|
union {
|
|
|
|
unsigned char* asUChar;
|
|
|
|
unsigned long* asLong;
|
|
|
|
} data = {0};
|
|
|
|
int status = XGetWindowProperty(display, aWinId, sPluginIMEAtom,
|
|
|
|
0, 1, False, AnyPropertyType,
|
|
|
|
&actualType, &actualFormat, &nitems,
|
|
|
|
&bytes, &data.asUChar);
|
|
|
|
|
|
|
|
if (status == Success && actualType == XA_CARDINAL && actualFormat == 32 && nitems == 1) {
|
|
|
|
// Assume that plugin set value false - close VKB, true - open VKB
|
|
|
|
imeState = data.asLong[0] ? VKBOpen : VKBClose;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == Success) {
|
|
|
|
XFree(data.asUChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
return imeState;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetVKBState(Window aWinId, PluginVKBState aState)
|
|
|
|
{
|
2012-03-22 16:24:40 -07:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2011-09-07 08:06:35 -07:00
|
|
|
if (aState != VKBUndefined) {
|
|
|
|
unsigned long isOpen = aState == VKBOpen ? 1 : 0;
|
|
|
|
XChangeProperty(display, aWinId, sPluginIMEAtom, XA_CARDINAL, 32,
|
|
|
|
PropModeReplace, (unsigned char *) &isOpen, 1);
|
|
|
|
} else {
|
|
|
|
XDeleteProperty(display, aWinId, sPluginIMEAtom);
|
|
|
|
}
|
|
|
|
XSync(display, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
x11EventFilter(void* message, long* result)
|
|
|
|
{
|
|
|
|
XEvent* event = static_cast<XEvent*>(message);
|
|
|
|
if (event->type == PropertyNotify) {
|
|
|
|
if (event->xproperty.atom == sPluginIMEAtom) {
|
|
|
|
PluginVKBState state = GetPluginVKBState(event->xproperty.window);
|
|
|
|
if (state == VKBOpen) {
|
|
|
|
MozQWidget::requestVKB();
|
|
|
|
} else if (state == VKBClose) {
|
|
|
|
MozQWidget::hideVKB();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (previousEventFilter) {
|
|
|
|
return previousEventFilter(message, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-03-12 14:07:32 -08:00
|
|
|
{
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(mWidget);
|
2010-03-12 14:07:32 -08:00
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
// SetSoftwareKeyboardState uses mInputContext,
|
|
|
|
// so, before calling that, record aContext in mInputContext.
|
|
|
|
mInputContext = aContext;
|
2011-08-16 09:27:36 -07:00
|
|
|
|
2011-09-07 08:06:35 -07:00
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
2011-10-07 08:16:37 -07:00
|
|
|
if (sPluginIMEAtom) {
|
|
|
|
static QCoreApplication::EventFilter currentEventFilter = NULL;
|
2011-11-27 03:51:53 -08:00
|
|
|
if (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN &&
|
2011-11-27 03:51:52 -08:00
|
|
|
currentEventFilter != x11EventFilter) {
|
2011-10-07 08:16:37 -07:00
|
|
|
// Install event filter for listening Plugin IME state changes
|
|
|
|
previousEventFilter = QCoreApplication::instance()->setEventFilter(x11EventFilter);
|
|
|
|
currentEventFilter = x11EventFilter;
|
2011-11-27 03:51:53 -08:00
|
|
|
} else if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 03:51:52 -08:00
|
|
|
currentEventFilter == x11EventFilter) {
|
2011-10-07 08:16:37 -07:00
|
|
|
// Remove event filter
|
|
|
|
QCoreApplication::instance()->setEventFilter(previousEventFilter);
|
|
|
|
currentEventFilter = previousEventFilter;
|
|
|
|
previousEventFilter = NULL;
|
|
|
|
QWidget* view = GetViewWidget();
|
|
|
|
if (view) {
|
|
|
|
SetVKBState(view->winId(), VKBUndefined);
|
|
|
|
}
|
2011-09-07 08:06:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
switch (mInputContext.mIMEState.mEnabled) {
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
case IMEState::PASSWORD:
|
|
|
|
case IMEState::PLUGIN:
|
2011-11-27 03:51:52 -08:00
|
|
|
SetSoftwareKeyboardState(true, aAction);
|
2010-03-12 14:07:32 -08:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-27 03:51:52 -08:00
|
|
|
SetSoftwareKeyboardState(false, aAction);
|
2010-03-12 14:07:32 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2010-03-12 14:07:32 -08:00
|
|
|
{
|
2011-11-27 03:51:53 -08:00
|
|
|
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
2012-10-26 16:35:21 -07:00
|
|
|
// Our qt widget looks like using only one context per process.
|
|
|
|
// However, it's better to set the context's pointer.
|
2013-02-25 12:25:16 -08:00
|
|
|
#if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0))
|
2012-10-26 16:35:21 -07:00
|
|
|
mInputContext.mNativeIMEContext = qApp->inputContext();
|
2013-02-25 12:25:16 -08:00
|
|
|
#else
|
|
|
|
mInputContext.mNativeIMEContext = nullptr;
|
|
|
|
#endif
|
2011-11-27 03:51:52 -08:00
|
|
|
return mInputContext;
|
2010-03-12 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
2011-09-07 08:06:35 -07:00
|
|
|
void
|
2011-11-27 03:51:52 -08:00
|
|
|
nsWindow::SetSoftwareKeyboardState(bool aOpen,
|
|
|
|
const InputContextAction& aAction)
|
2011-09-07 08:06:35 -07:00
|
|
|
{
|
|
|
|
if (aOpen) {
|
2012-12-23 20:45:57 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(mInputContext.mIMEState.mEnabled !=
|
|
|
|
IMEState::DISABLED);
|
2011-09-07 08:06:35 -07:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 03:51:52 -08:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 03:51:53 -08:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 03:51:52 -08:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 03:51:53 -08:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 03:51:52 -08:00
|
|
|
return;
|
2011-09-07 08:06:35 -07:00
|
|
|
}
|
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
|
|
|
// doen't open VKB if plugin did set closed state
|
2011-10-07 08:16:37 -07:00
|
|
|
else if (sPluginIMEAtom) {
|
2011-09-07 08:06:35 -07:00
|
|
|
QWidget* view = GetViewWidget();
|
|
|
|
if (view && GetPluginVKBState(view->winId()) == VKBClose) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOpen) {
|
|
|
|
// VKB open need to be delayed in order to give
|
|
|
|
// to plugins chance prevent VKB from opening
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t openDelay =
|
2011-09-07 08:06:35 -07:00
|
|
|
Preferences::GetInt("ui.vkb.open.delay", 200);
|
|
|
|
MozQWidget::requestVKB(openDelay, mWidget);
|
|
|
|
} else {
|
|
|
|
MozQWidget::hideVKB();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
|
|
|
{
|
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIdleService) {
|
2012-06-29 01:32:21 -07:00
|
|
|
mIdleService->ResetIdleTimeOut(0);
|
2010-04-16 10:37:16 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 11:16:15 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-02-22 11:16:15 -08:00
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
2012-07-18 09:31:40 -07:00
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
2012-08-16 08:31:47 -07:00
|
|
|
return MozQGLWidgetWrapper::isRGBAContext() ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
|
2012-02-22 11:16:15 -08:00
|
|
|
}
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
}
|
|
|
|
|