2010-03-03 20:45:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-04-19 19:37:51 +04:00
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2008-04-19 19:31:50 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2008-04-19 19:37:51 +04:00
|
|
|
* The Initial Developer of the Original Code is Christopher Blizzard
|
|
|
|
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
|
|
|
* are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
|
2008-04-19 19:31:50 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-09-18 15:28:50 +04:00
|
|
|
* Mats Palmgren <matspal@gmail.com>
|
2008-04-19 19:37:51 +04:00
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2008-04-19 19:39:38 +04:00
|
|
|
* Romashin Oleg <romaxa@gmail.com>
|
2008-04-22 15:21:18 +04:00
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2010-02-16 21:14:20 +03:00
|
|
|
* Jeremias Bosch <jeremias.bosch@gmail.com>
|
|
|
|
* Steffen Imhof <steffen.imhof@gmail.com>
|
2011-02-03 09:31:43 +03:00
|
|
|
* Tatiana Meshkova <tanya.meshkova@gmail.com>
|
2008-04-19 19:31:50 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2012-03-23 03:24:40 +04:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2010-03-05 00:51:42 +03:00
|
|
|
#include <QtGui/QCursor>
|
2012-03-23 03:24:40 +04:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QGraphicsSceneWheelEvent>
|
|
|
|
#include <QGraphicsSceneResizeEvent>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
2010-04-14 03:11:23 +04:00
|
|
|
#include <QPaintEngine>
|
2012-03-23 03:24:40 +04:00
|
|
|
#include <QMimeData>
|
2010-03-05 00:51:42 +03:00
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
#include <QtCore/QVariant>
|
2010-03-13 01:11:42 +03:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
|
|
|
#include <QPinchGesture>
|
2010-10-09 10:08:42 +04: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-16 07:41:53 +03:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include <QtSensors/QOrientationSensor>
|
|
|
|
using namespace QtMobility;
|
|
|
|
#endif // MOZ_ENABLE_QTMOBILITY
|
|
|
|
#endif // QT version check 4.6
|
2010-03-05 00:51:42 +03:00
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2010-03-18 19:44:33 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
#include "prlink.h"
|
|
|
|
|
2008-04-19 19:31:50 +04:00
|
|
|
#include "nsWindow.h"
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "mozqwidget.h"
|
|
|
|
|
2011-03-16 07:41:53 +03:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include "mozqorientationsensorfilter.h"
|
|
|
|
#endif
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
#include "nsIdleService.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2008-04-19 19:37:51 +04:00
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsQtKeyUtils.h"
|
2010-05-14 13:24:41 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-06-07 11:38:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "gfxQtPlatform.h"
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "gfxXlibSurface.h"
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "gfxQPainterSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2010-05-11 21:31:56 +04:00
|
|
|
#include "gfxImageSurface.h"
|
2009-03-27 14:35:27 +03:00
|
|
|
|
2010-03-13 01:11:42 +03:00
|
|
|
#include "nsIDOMSimpleGestureEvent.h" //Gesture support
|
|
|
|
|
2010-08-31 03:40:14 +04:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIFocusManager.h"
|
|
|
|
#endif
|
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "keysym2ucs.h"
|
2011-09-07 19:06:35 +04:00
|
|
|
#if MOZ_PLATFORM_MAEMO == 6
|
|
|
|
#include <X11/Xatom.h>
|
2011-10-07 19:16:37 +04:00
|
|
|
static Atom sPluginIMEAtom = nsnull;
|
2011-09-07 19:06:35 +04:00
|
|
|
#define PLUGIN_VKB_REQUEST_PROP "_NPAPI_PLUGIN_REQUEST_VKB"
|
2011-10-07 19:16:37 +04:00
|
|
|
#include <QThread>
|
2011-09-07 19:06:35 +04:00
|
|
|
#endif
|
2010-08-26 22:11:54 +04:00
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2010-06-24 14:07:57 +04:00
|
|
|
#include <QtOpenGL/QGLWidget>
|
2011-08-24 20:15:58 +04:00
|
|
|
#include <QtOpenGL/QGLContext>
|
2010-06-24 17:16:27 +04:00
|
|
|
#define GLdouble_defined 1
|
2010-06-24 14:07:57 +04:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "LayerManagerOGL.h"
|
2011-10-28 16:13:57 +04:00
|
|
|
#include "nsFastStartupQt.h"
|
2010-06-24 14:07:57 +04:00
|
|
|
|
2011-09-25 23:03:22 +04: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-27 08:56:31 +04:00
|
|
|
#include "nsShmImage.h"
|
|
|
|
extern "C" {
|
2011-11-23 05:42:57 +04:00
|
|
|
#define PIXMAN_DONT_DEFINE_STDINT
|
2010-10-27 08:56:31 +04:00
|
|
|
#include "pixman.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-11-27 15:51:52 +04:00
|
|
|
using namespace mozilla::widget;
|
2010-10-27 08:56:31 +04:00
|
|
|
|
2010-03-07 14:04:40 +03:00
|
|
|
// imported in nsWidgetFactory.cpp
|
2011-09-29 10:19:26 +04:00
|
|
|
bool gDisableNativeTheme = false;
|
2010-03-07 14:04:40 +03:00
|
|
|
|
2010-06-11 13:32:00 +04:00
|
|
|
// Cached offscreen surface
|
|
|
|
static nsRefPtr<gfxASurface> gBufferSurface;
|
2010-10-27 08:56:31 +04:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
// If we're using xshm rendering, mThebesSurface wraps gShmImage
|
|
|
|
nsRefPtr<nsShmImage> gShmImage;
|
|
|
|
#endif
|
2010-05-15 14:37:51 +04:00
|
|
|
|
|
|
|
static int gBufferPixmapUsageCount = 0;
|
2010-04-14 03:11:23 +04:00
|
|
|
static gfxIntSize gBufferMaxSize(0, 0);
|
2008-04-19 19:37:55 +04:00
|
|
|
|
2008-04-19 19:37:51 +04: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 21:14:20 +03:00
|
|
|
// Qt
|
2008-04-19 19:37:51 +04:00
|
|
|
static const int WHEEL_DELTA = 120;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gGlobalsInitialized = false;
|
2008-08-16 11:07:21 +04:00
|
|
|
|
2009-12-23 02:49:33 +03:00
|
|
|
static nsIRollupListener* gRollupListener;
|
2008-08-16 11:07:21 +04:00
|
|
|
static nsWeakPtr gRollupWindow;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gConsumeRollupEvent;
|
2008-08-16 11:07:21 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool check_for_rollup(double aMouseX, double aMouseY,
|
|
|
|
bool aIsWheel);
|
2010-02-16 21:14:20 +03:00
|
|
|
static bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
|
2008-08-16 11:07:21 +04:00
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
static bool sAltGrModifier = false;
|
|
|
|
|
2011-03-16 07:41:53 +03:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
static QOrientationSensor *gOrientation = nsnull;
|
|
|
|
static MozQOrientationSensorFilter gOrientationFilter;
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-04-20 12:16:40 +04:00
|
|
|
isContextMenuKeyEvent(const QKeyEvent *qe)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-20 12:16:40 +04:00
|
|
|
PRUint32 kc = QtKeyCodeToDOMKeyCode(qe->key());
|
|
|
|
if (qe->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isShift = qe->modifiers() & Qt::ShiftModifier;
|
2008-04-20 12:16:40 +04:00
|
|
|
return (kc == NS_VK_F10 && isShift) ||
|
|
|
|
(kc == NS_VK_CONTEXT_MENU && !isShift);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
static void
|
|
|
|
InitKeyEvent(nsKeyEvent &aEvent, QKeyEvent *aQEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
aEvent.isShift = (aQEvent->modifiers() & Qt::ShiftModifier) ? true : false;
|
|
|
|
aEvent.isControl = (aQEvent->modifiers() & Qt::ControlModifier) ? true : false;
|
|
|
|
aEvent.isAlt = (aQEvent->modifiers() & Qt::AltModifier) ? true : false;
|
|
|
|
aEvent.isMeta = (aQEvent->modifiers() & Qt::MetaModifier) ? true : false;
|
2008-04-20 12:16:40 +04:00
|
|
|
aEvent.time = 0;
|
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
if (sAltGrModifier) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aEvent.isControl = true;
|
|
|
|
aEvent.isAlt = true;
|
2011-01-26 12:01:01 +03:00
|
|
|
}
|
|
|
|
|
2010-02-16 21:14:20 +03: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 12:16:40 +04:00
|
|
|
// event callback) to give plugins access to hardware_keycode and state.
|
2010-02-16 21:14:20 +03:00
|
|
|
// (An XEvent would be nice but the QKeyEvent is good enough.)
|
2009-11-11 00:55:38 +03:00
|
|
|
aEvent.pluginEvent = (void *)aQEvent;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTopLevel = false;
|
|
|
|
mIsDestroyed = false;
|
|
|
|
mIsShown = false;
|
|
|
|
mEnabled = true;
|
2010-02-16 21:14:20 +03:00
|
|
|
mWidget = nsnull;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsVisible = false;
|
|
|
|
mActivatePending = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2010-05-30 22:35:07 +04:00
|
|
|
mLastSizeMode = nsSizeMode_Normal;
|
2008-04-19 19:37:51 +04:00
|
|
|
mPluginType = PluginType_NONE;
|
|
|
|
mQCursor = Qt::ArrowCursor;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
|
|
|
mListenForResizes = false;
|
|
|
|
mNeedsShow = false;
|
|
|
|
mGesturesCancelled = false;
|
|
|
|
mTimerStarted = false;
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.needDispatch = false;
|
|
|
|
mMoveEvent.needDispatch = false;
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
if (!gGlobalsInitialized) {
|
2012-03-22 03:14:09 +04:00
|
|
|
gfxPlatform::GetPlatform();
|
2011-10-17 18:59:28 +04:00
|
|
|
gGlobalsInitialized = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-09-07 19:06:35 +04:00
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
2011-10-07 19:16:37 +04:00
|
|
|
// This cannot be called on non-main thread
|
|
|
|
if (QThread::currentThread() == qApp->thread()) {
|
2012-03-23 03:24:40 +04:00
|
|
|
sPluginIMEAtom = XInternAtom(mozilla::DefaultXDisplay(), PLUGIN_VKB_REQUEST_PROP, False);
|
2011-10-07 19:16:37 +04:00
|
|
|
}
|
2011-09-07 19:06:35 +04:00
|
|
|
#endif
|
2008-04-19 19:37:51 +04: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 18:59:28 +04:00
|
|
|
mIsTransparent = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
mCursor = eCursor_standard;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
|
|
|
gBufferPixmapUsageCount++;
|
2010-10-09 10:08:42 +04: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-20 06:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline gfxASurface::gfxImageFormat
|
|
|
|
_depth_to_gfximage_format(PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
switch (aDepth) {
|
|
|
|
case 32:
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
case 24:
|
|
|
|
return gfxASurface::ImageFormatRGB24;
|
2010-06-11 13:33:22 +04:00
|
|
|
case 16:
|
|
|
|
return gfxASurface::ImageFormatRGB16_565;
|
2010-02-20 06:46:54 +03:00
|
|
|
default:
|
|
|
|
return gfxASurface::ImageFormatUnknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-14 03:11:23 +04:00
|
|
|
static inline QImage::Format
|
2010-05-11 21:31:56 +04:00
|
|
|
_gfximage_to_qformat(gfxASurface::gfxImageFormat aFormat)
|
2010-04-14 03:11:23 +04:00
|
|
|
{
|
2010-05-11 21:31:56 +04:00
|
|
|
switch (aFormat) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
2010-06-11 13:33:22 +04:00
|
|
|
return QImage::Format_ARGB32_Premultiplied;
|
2010-05-11 21:31:56 +04:00
|
|
|
case gfxASurface::ImageFormatRGB24:
|
2010-04-14 03:11:23 +04:00
|
|
|
return QImage::Format_ARGB32;
|
2010-06-11 13:33:22 +04:00
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
return QImage::Format_RGB16;
|
2010-04-14 03:11:23 +04:00
|
|
|
default:
|
|
|
|
return QImage::Format_Invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-20 06:46:54 +03:00
|
|
|
static bool
|
2010-10-27 08:56:31 +04:00
|
|
|
UpdateOffScreenBuffers(int aDepth, QSize aSize, QWidget* aWidget = nsnull)
|
2010-02-20 06:46:54 +03:00
|
|
|
{
|
|
|
|
gfxIntSize size(aSize.width(), aSize.height());
|
2010-06-11 13:32:00 +04:00
|
|
|
if (gBufferSurface) {
|
2010-04-14 03:11:23 +04:00
|
|
|
if (gBufferMaxSize.width < size.width ||
|
|
|
|
gBufferMaxSize.height < size.height) {
|
2010-06-11 13:32:00 +04:00
|
|
|
gBufferSurface = nsnull;
|
2010-02-20 06:46:54 +03:00
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-25 18:06:02 +04:00
|
|
|
gBufferMaxSize.width = NS_MAX(gBufferMaxSize.width, size.width);
|
|
|
|
gBufferMaxSize.height = NS_MAX(gBufferMaxSize.height, size.height);
|
2010-02-20 06:46:54 +03:00
|
|
|
|
|
|
|
// Check if system depth has related gfxImage format
|
|
|
|
gfxASurface::gfxImageFormat format =
|
2010-04-14 03:11:23 +04:00
|
|
|
_depth_to_gfximage_format(aDepth);
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2010-05-11 21:31:56 +04:00
|
|
|
// Use fallback RGB24 format, Qt will do conversion for us
|
|
|
|
if (format == gfxASurface::ImageFormatUnknown)
|
2010-04-14 03:11:23 +04:00
|
|
|
format = gfxASurface::ImageFormatRGB24;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2010-10-27 08:56:31 +04:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
if (aWidget) {
|
|
|
|
if (gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType() ==
|
|
|
|
gfxASurface::SurfaceTypeImage) {
|
2012-03-23 03:24:40 +04:00
|
|
|
Display* dpy = mozilla::DefaultXDisplay();
|
2010-10-27 08:56:31 +04:00
|
|
|
gShmImage = nsShmImage::Create(gBufferMaxSize,
|
2012-03-23 03:24:40 +04:00
|
|
|
DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aWidget)),
|
2010-10-27 08:56:31 +04:00
|
|
|
aDepth);
|
|
|
|
gBufferSurface = gShmImage->AsSurface();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-11 13:32:00 +04:00
|
|
|
gBufferSurface = gfxPlatform::GetPlatform()->
|
2010-09-17 01:34:53 +04:00
|
|
|
CreateOffscreenSurface(gBufferMaxSize, gfxASurface::ContentFromFormat(format));
|
2010-10-27 08:56:31 +04:00
|
|
|
|
2010-02-20 06:46:54 +03:00
|
|
|
return true;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsWindow::ReleaseGlobals()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-22 15:21:18 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsBaseWidget, nsISupportsWeakReference)
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2009-08-05 06:39:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
|
|
|
|
|
|
|
if (w->mBounds.Size() != configuration.mBounds.Size()) {
|
|
|
|
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
|
|
|
|
configuration.mBounds.width, configuration.mBounds.height,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2009-08-05 06:39:05 +04:00
|
|
|
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
|
|
|
w->Move(configuration.mBounds.x, configuration.mBounds.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mIsDestroyed || !mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDestroyed = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-20 06:46:54 +03:00
|
|
|
if (gBufferPixmapUsageCount &&
|
|
|
|
--gBufferPixmapUsageCount == 0) {
|
|
|
|
|
2010-06-11 13:32:00 +04:00
|
|
|
gBufferSurface = nsnull;
|
2010-10-27 08:56:31 +04:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
gShmImage = nsnull;
|
2011-03-16 07:41:53 +03:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
if (gOrientation) {
|
|
|
|
gOrientation->removeFilter(&gOrientationFilter);
|
|
|
|
gOrientation->stop();
|
|
|
|
delete gOrientation;
|
|
|
|
gOrientation = nsnull;
|
|
|
|
}
|
2010-10-27 08:56:31 +04:00
|
|
|
#endif
|
2010-02-20 06:46:54 +03:00
|
|
|
}
|
|
|
|
|
2008-08-16 11:07:21 +04:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget.get()) {
|
|
|
|
if (gRollupListener)
|
2011-11-08 23:59:07 +04:00
|
|
|
gRollupListener->Rollup(0);
|
2008-08-16 11:07:21 +04:00
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-09-10 03:41:02 +04:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
}
|
|
|
|
mLayerManager = nsnull;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
Show(false);
|
2008-04-19 19:37:51 +04: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.
|
|
|
|
mThebesSurface = nsnull;
|
|
|
|
|
2010-03-06 10:25:46 +03:00
|
|
|
QWidget *view = nsnull;
|
|
|
|
QGraphicsScene *scene = nsnull;
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mWidget) {
|
2010-03-06 10:25:46 +03:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
view = GetViewWidget();
|
|
|
|
scene = mWidget->scene();
|
|
|
|
}
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->dropReceiver();
|
2008-04-20 12:16:40 +04: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 16:20:21 +04:00
|
|
|
mWidget->deleteLater();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget = nsnull;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
OnDestroy();
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// tear down some infrastructure after all event handling is finished
|
2010-03-06 10:25:46 +03:00
|
|
|
delete scene;
|
|
|
|
delete view;
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewParent);
|
2010-09-18 15:28:50 +04:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
2011-05-31 01:51:54 +04:00
|
|
|
ReparentNativeWidget(aNewParent);
|
|
|
|
aNewParent->AddChild(this);
|
2010-09-18 15:28:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2010-09-18 15:28:50 +04: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 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetModal(bool aModal)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget));
|
2010-02-16 21:14:20 +03:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->setModal(aModal);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::IsVisible(bool & aState)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-03-22 05:55:36 +03:00
|
|
|
aState = mIsShown;
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop, PRInt32 *aX, PRInt32 *aY)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mWidget) {
|
2008-04-19 19:37:51 +04:00
|
|
|
PRInt32 screenWidth = QApplication::desktop()->width();
|
|
|
|
PRInt32 screenHeight = QApplication::desktop()->height();
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2008-04-19 19:37:51 +04: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
|
|
|
|
nsWindow::Move(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::Move [%p] %d %d\n", (void *)this,
|
|
|
|
aX, aY));
|
|
|
|
|
2010-03-17 09:32:38 +03:00
|
|
|
if (mIsTopLevel) {
|
2009-11-02 22:10:07 +03:00
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
|
|
|
}
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
if (aX == mBounds.x && aY == mBounds.y)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsMove = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// update the bounds
|
|
|
|
QPointF pos( aX, aY );
|
2011-02-03 09:31:43 +03:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_OK);
|
|
|
|
widget->move(aX, aY);
|
|
|
|
}
|
|
|
|
else if (mWidget) {
|
2010-02-16 21:14:20 +03: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 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = pos.x();
|
|
|
|
mBounds.y = pos.y();
|
|
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aActivate)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
2011-05-03 20:40:02 +04:00
|
|
|
if (aMode != nsSizeMode_Minimized) {
|
|
|
|
GetViewWidget()->activateWindow();
|
|
|
|
}
|
2008-04-19 19:37:51 +04: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 16:20:21 +04:00
|
|
|
if (!mWidget || mSizeState == mSizeMode) {
|
2008-04-19 19:37:51 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-15 09:08:15 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showMaximized();
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showMinimized();
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
2010-02-04 17:43:52 +03:00
|
|
|
case nsSizeMode_Fullscreen:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showFullScreen();
|
2010-02-04 17:43:52 +03:00
|
|
|
break;
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showNormal();
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-02-16 21:14:20 +03: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)
|
|
|
|
{
|
2010-03-26 03:33:31 +03:00
|
|
|
NS_ENSURE_TRUE(aItem, );
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2010-03-26 03:33:31 +03:00
|
|
|
aVisibleItem = nsnull;
|
|
|
|
QGraphicsItem* parItem = nsnull;
|
|
|
|
while (!aVisibleItem) {
|
|
|
|
if (aItem->isVisible())
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
else {
|
|
|
|
parItem = aItem->parentItem();
|
|
|
|
if (parItem)
|
|
|
|
aItem = parItem;
|
|
|
|
else {
|
|
|
|
aItem->setVisible(true);
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2008-04-19 19:37:51 +04: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 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2010-03-26 03:33:31 +03:00
|
|
|
if (mWidget->hasFocus())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Because QGraphicsItem cannot get the focus if they are
|
2010-02-16 21:14:20 +03:00
|
|
|
// invisible, we look up the chain, for the lowest visible
|
|
|
|
// parent and focus that one
|
|
|
|
QGraphicsItem* realFocusItem = nsnull;
|
|
|
|
find_first_visible_parent(mWidget, realFocusItem);
|
|
|
|
|
|
|
|
if (!realFocusItem || realFocusItem->hasFocus())
|
2009-07-15 16:20:21 +04:00
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-25 21:58:19 +03:00
|
|
|
if (aRaise) {
|
|
|
|
// the raising has to happen on the view widget
|
2010-03-15 09:08:15 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
if (widget)
|
|
|
|
widget->raise();
|
2010-02-16 21:14:20 +03:00
|
|
|
realFocusItem->setFocus(Qt::ActiveWindowFocusReason);
|
2010-02-25 21:58:19 +03:00
|
|
|
}
|
2010-02-16 21:14:20 +03:00
|
|
|
else
|
|
|
|
realFocusItem->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
DispatchActivateEvent();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-11 16:51:06 +03:00
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-02-03 09:31:43 +03: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-06 10:25:46 +03:00
|
|
|
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
|
2008-04-19 19:37:51 +04: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 19:22:26 +03:00
|
|
|
if (mCursor == aCursor)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
mCursor = aCursor;
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->SetCursor(mCursor);
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(imgIContainer* aCursor,
|
|
|
|
PRUint32 aHotspotX, PRUint32 aHotspotY)
|
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-24 07:52:21 +04:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-12-24 07:52:21 +04: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 19:37:51 +04:00
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-26 03:33:31 +03:00
|
|
|
mDirtyScrollArea = mDirtyScrollArea.united(QRect(aRect.x, aRect.y, aRect.width, aRect.height));
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
mWidget->update(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-06 10:25:46 +03: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 21:14:20 +03:00
|
|
|
QWidget* nsWindow::GetViewWidget()
|
|
|
|
{
|
2010-03-06 10:25:46 +03:00
|
|
|
NS_ASSERTION(mWidget, "Calling GetViewWidget without mWidget created");
|
2010-08-21 05:12:14 +04:00
|
|
|
if (!mWidget || !mWidget->scene() || !mWidget->scene()->views().size())
|
2010-02-16 21:14:20 +03:00
|
|
|
return nsnull;
|
|
|
|
|
2010-03-06 10:25:46 +03:00
|
|
|
NS_ASSERTION(mWidget->scene()->views().size() == 1, "Not exactly one view for our scene!");
|
|
|
|
return mWidget->scene()->views()[0];
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
void*
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return nsnull;
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
return mWidget;
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
return SetupPluginPort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_DISPLAY:
|
2010-03-17 09:28:42 +03:00
|
|
|
{
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2012-03-23 03:24:40 +04:00
|
|
|
return gfxQtPlatform::GetXDisplay(GetViewWidget());
|
2011-08-24 20:15:58 +04:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2010-03-17 09:28:42 +03:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC: {
|
2011-10-25 19:05:32 +04:00
|
|
|
return nsnull;
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-24 14:07:57 +04:00
|
|
|
case NS_NATIVE_SHELLWIDGET: {
|
|
|
|
QWidget* widget = nsnull;
|
|
|
|
if (mWidget && mWidget->scene())
|
|
|
|
widget = mWidget->scene()->views()[0]->viewport();
|
|
|
|
return (void *) widget;
|
|
|
|
}
|
2011-08-31 23:01:38 +04:00
|
|
|
|
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW: {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
return widget ? (void*)widget->winId() : nsnull;
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length()));
|
2010-03-15 09:08:15 +03:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
if (widget)
|
|
|
|
widget->setWindowTitle(qStr);
|
|
|
|
}
|
2010-02-16 21:14:20 +03:00
|
|
|
else if (mWidget)
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->setWindowTitle(qStr);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> iconFile;
|
|
|
|
nsCAutoString path;
|
2009-01-22 07:15:34 +03:00
|
|
|
nsTArray<nsCString> iconList;
|
2008-04-19 19:37:51 +04: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" };
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(extensions); i++) {
|
2008-04-19 19:37:51 +04:00
|
|
|
// Don't bother looking for XPM versions if we found a PNG.
|
2011-10-11 09:50:08 +04:00
|
|
|
if (i == ArrayLength(extensions) - 2 && iconList.Length())
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
|
|
|
|
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
2009-01-22 07:15:34 +03:00
|
|
|
iconList.AppendElement(path);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leave the default icon intact if no matching icons were found
|
2009-01-22 07:15:34 +03:00
|
|
|
if (iconList.Length() == 0)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return SetWindowIconList(iconList);
|
|
|
|
}
|
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
QPointF origin(0, 0);
|
|
|
|
origin = mWidget->mapToScene(origin);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
return nsIntPoint(origin.x(), origin.y());
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2010-03-06 10:25:46 +03:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::EnableDragDrop(bool aEnable)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->setAcceptDrops(aEnable);
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::CaptureMouse(bool aCapture)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
2010-03-15 09:08:15 +03:00
|
|
|
|
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
if (aCapture)
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->grabMouse();
|
2008-04-20 12:37:07 +04:00
|
|
|
else
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->releaseMouse();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoCapture,
|
|
|
|
bool aConsumeRollupEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("CaptureRollupEvents %p\n", (void *)this));
|
2008-08-16 11:07:21 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
if (aDoCapture) {
|
2008-08-16 11:07:21 +04:00
|
|
|
gConsumeRollupEvent = aConsumeRollupEvent;
|
|
|
|
gRollupListener = aListener;
|
|
|
|
gRollupWindow = do_GetWeakReference(static_cast<nsIWidget*>(this));
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-08-16 11:07:21 +04:00
|
|
|
gRollupListener = nsnull;
|
|
|
|
gRollupWindow = nsnull;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-08-16 11:07:21 +04:00
|
|
|
check_for_rollup(double aMouseX, double aMouseY,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsWheel)
|
2008-08-16 11:07:21 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool retVal = false;
|
2008-08-16 11:07:21 +04:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
|
|
|
|
|
|
|
if (rollupWidget && gRollupListener) {
|
2010-02-16 21:14:20 +03:00
|
|
|
MozQWidget *currentPopup =
|
|
|
|
(MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
2008-08-16 11:07:21 +04:00
|
|
|
|
|
|
|
if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool rollup = true;
|
2008-08-16 11:07:21 +04:00
|
|
|
if (aIsWheel) {
|
2011-11-08 23:59:07 +04:00
|
|
|
rollup = gRollupListener->ShouldRollupOnMouseWheelEvent();
|
2011-10-17 18:59:28 +04:00
|
|
|
retVal = true;
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
// 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
|
2009-06-12 22:23:16 +04:00
|
|
|
PRUint32 popupsToRollup = PR_UINT32_MAX;
|
2011-11-08 23:59:07 +04:00
|
|
|
if (gRollupListener) {
|
2008-08-16 11:07:21 +04:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2011-11-08 23:59:07 +04:00
|
|
|
PRUint32 sameTypeCount = gRollupListener->GetSubmenuWidgetChain(&widgetChain);
|
2008-08-16 11:07:21 +04:00
|
|
|
for (PRUint32 i=0; i<widgetChain.Length(); ++i) {
|
|
|
|
nsIWidget* widget = widgetChain[i];
|
2010-02-16 21:14:20 +03:00
|
|
|
MozQWidget* currWindow =
|
|
|
|
(MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW);
|
2008-08-16 11:07:21 +04:00
|
|
|
if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
|
2009-06-12 22:23:16 +04:00
|
|
|
if (i < sameTypeCount) {
|
2011-10-17 18:59:28 +04:00
|
|
|
rollup = false;
|
2009-06-12 22:23:16 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
|
|
|
break;
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
} // foreach parent menu widget
|
|
|
|
} // if rollup listener knows about menus
|
|
|
|
|
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
2011-11-08 23:59:07 +04:00
|
|
|
gRollupListener->Rollup(popupsToRollup);
|
2011-10-17 18:59:28 +04:00
|
|
|
retVal = true;
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2010-02-16 21:14:20 +03:00
|
|
|
bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY)
|
2008-08-16 11:07:21 +04:00
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
return aWindow->geometry().contains( aMouseX, aMouseY );
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetAttention(PRInt32 aCycleCount)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
2010-02-16 21:14:20 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2010-10-27 08:56:31 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
static already_AddRefed<gfxASurface>
|
|
|
|
GetSurfaceForQWidget(QWidget* aDrawable)
|
|
|
|
{
|
|
|
|
gfxASurface* result =
|
2012-03-23 03:24:40 +04:00
|
|
|
new gfxXlibSurface(gfxQtPlatform::GetXDisplay(aDrawable),
|
|
|
|
aDrawable->winId(),
|
|
|
|
DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aDrawable)),
|
2010-10-27 08:56:31 +04:00
|
|
|
gfxIntSize(aDrawable->size().width(),
|
|
|
|
aDrawable->size().height()));
|
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 00:16:57 +04:00
|
|
|
static void
|
|
|
|
DispatchDidPaint(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
nsEventStatus status;
|
|
|
|
nsPaintEvent didPaintEvent(true, NS_DID_PAINT, aWidget);
|
|
|
|
aWidget->DispatchEvent(&didPaintEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-10-27 08:56:31 +04:00
|
|
|
nsWindow::DoPaint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
if (mIsDestroyed) {
|
|
|
|
LOG(("Expose event on destroyed window [%p] window %p\n",
|
2009-07-15 16:20:21 +04:00
|
|
|
(void *)this, mWidget));
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 00:16:57 +04:00
|
|
|
// Dispatch WILL_PAINT to allow scripts etc. to run before we
|
|
|
|
// dispatch PAINT
|
|
|
|
{
|
|
|
|
nsEventStatus status;
|
|
|
|
nsPaintEvent willPaintEvent(true, NS_WILL_PAINT, this);
|
|
|
|
willPaintEvent.willSendDidPaint = true;
|
|
|
|
DispatchEvent(&willPaintEvent, status);
|
|
|
|
}
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
QRectF r;
|
|
|
|
if (aOption)
|
|
|
|
r = aOption->exposedRect;
|
|
|
|
else
|
|
|
|
r = mWidget->boundingRect();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-03-11 01:13:02 +03:00
|
|
|
if (r.isEmpty())
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-03-07 14:07:25 +03:00
|
|
|
if (!mDirtyScrollArea.isEmpty())
|
|
|
|
mDirtyScrollArea = QRegion();
|
2008-04-20 12:37:07 +04:00
|
|
|
|
2010-06-24 14:07:57 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
nsIntRect rect(r.x(), r.y(), r.width(), r.height());
|
|
|
|
|
2011-10-28 16:13:57 +04:00
|
|
|
nsFastStartup* startup = nsFastStartup::GetSingleton();
|
|
|
|
if (startup) {
|
|
|
|
startup->RemoveFakeLayout();
|
|
|
|
}
|
|
|
|
|
2010-12-07 05:05:52 +03:00
|
|
|
if (GetLayerManager(nsnull)->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
2012-03-20 00:16:57 +04:00
|
|
|
aPainter->beginNativePainting();
|
2011-10-17 18:59:28 +04:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
2012-03-20 00:16:57 +04:00
|
|
|
event.willSendDidPaint = true;
|
2010-06-24 14:07:57 +04:00
|
|
|
event.refPoint.x = r.x();
|
|
|
|
event.refPoint.y = r.y();
|
|
|
|
event.region = nsIntRegion(rect);
|
2010-12-07 05:05:52 +03:00
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nsnull))->
|
2010-06-24 14:07:57 +04:00
|
|
|
SetClippingRegion(event.region);
|
2011-03-16 07:41:53 +03: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());
|
|
|
|
static_cast<mozilla::layers::LayerManagerOGL*>(GetLayerManager(nsnull))->
|
|
|
|
SetWorldTransform(matr);
|
|
|
|
#endif //MOZ_ENABLE_QTMOBILITY
|
|
|
|
|
2012-03-20 00:16:57 +04:00
|
|
|
status = DispatchEvent(&event);
|
|
|
|
aPainter->endNativePainting();
|
|
|
|
DispatchDidPaint(this);
|
|
|
|
return status;
|
2010-06-24 14:07:57 +04:00
|
|
|
}
|
|
|
|
|
2010-02-20 06:46:54 +03:00
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
2010-04-14 03:11:23 +04:00
|
|
|
int depth = aPainter->device()->depth();
|
2010-05-11 21:31:56 +04:00
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> targetSurface = nsnull;
|
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
|
|
|
// Prepare offscreen buffers iamge or xlib, depends from paintEngineType
|
2010-06-11 13:32:00 +04:00
|
|
|
if (!UpdateOffScreenBuffers(depth, QSize(r.width(), r.height())))
|
2010-02-20 06:46:54 +03:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-06-11 13:32:00 +04:00
|
|
|
targetSurface = gBufferSurface;
|
2010-05-11 21:31:56 +04:00
|
|
|
|
2010-10-05 10:15:57 +04:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-02-20 06:46:54 +03:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
targetSurface = new gfxQPainterSurface(aPainter);
|
2010-10-05 10:15:57 +04:00
|
|
|
#endif
|
2010-10-27 08:56:31 +04:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
if (!UpdateOffScreenBuffers(depth, aWidget->size(), aWidget)) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
targetSurface = gBufferSurface;
|
2010-02-20 06:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_UNLIKELY(!targetSurface))
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2008-04-19 19:43:23 +04:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
2010-03-11 01:13:02 +03:00
|
|
|
// We will paint to 0, 0 position in offscrenn buffer
|
2010-10-27 08:56:31 +04:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
2010-03-11 01:13:02 +03:00
|
|
|
ctx->Translate(gfxPoint(-r.x(), -r.y()));
|
2010-10-27 08:56:31 +04:00
|
|
|
}
|
|
|
|
else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
2011-01-20 09:27:49 +03:00
|
|
|
gfxMatrix matr;
|
|
|
|
matr.Translate(gfxPoint(aPainter->transform().dx(), aPainter->transform().dy()));
|
2011-03-16 07:41:53 +03: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-20 09:27:49 +03:00
|
|
|
ctx->SetMatrix(matr);
|
|
|
|
}
|
2010-03-11 01:13:02 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
2012-03-20 00:16:57 +04:00
|
|
|
event.willSendDidPaint = true;
|
2010-10-27 08:56:31 +04:00
|
|
|
event.refPoint.x = rect.x;
|
|
|
|
event.refPoint.y = rect.y;
|
2010-03-01 11:03:49 +03:00
|
|
|
event.region = nsIntRegion(rect);
|
|
|
|
{
|
2010-10-27 08:56:31 +04:00
|
|
|
AutoLayerManagerSetup
|
|
|
|
setupLayerManager(this, ctx, BasicLayerManager::BUFFER_NONE);
|
|
|
|
status = DispatchEvent(&event);
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
|
|
|
|
// operations below if that happened - it will lead to XError and exit().
|
2008-04-19 19:43:23 +04:00
|
|
|
if (NS_UNLIKELY(mIsDestroyed))
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:43:23 +04:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
if (status == nsEventStatus_eIgnore)
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:43:23 +04:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
LOGDRAW(("[%p] draw done\n", this));
|
|
|
|
|
2010-05-11 21:31:56 +04:00
|
|
|
// Handle buffered painting mode
|
|
|
|
if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
|
2012-03-23 03:24:40 +04:00
|
|
|
#if defined(MOZ_X11) && defined(Q_WS_X11)
|
2010-06-11 13:32:00 +04:00
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
2010-04-14 03:11:23 +04:00
|
|
|
// Paint offscreen pixmap to QPainter
|
2010-06-11 13:32:00 +04: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-11 01:13:02 +03:00
|
|
|
QRect(0, 0, rect.width, rect.height));
|
2010-04-14 03:11:23 +04:00
|
|
|
|
2011-08-24 20:15:58 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeImage) {
|
2010-04-14 03:11:23 +04:00
|
|
|
// in raster mode we can just wrap gBufferImage as QImage and paint directly
|
2010-06-11 13:32:00 +04: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 23:45:37 +03:00
|
|
|
aPainter->drawImage(QPoint(rect.x, rect.y), img,
|
2010-03-11 01:13:02 +03:00
|
|
|
QRect(0, 0, rect.width, rect.height));
|
2010-02-25 23:45:37 +03:00
|
|
|
}
|
2010-10-27 08:56:31 +04:00
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
QRect trans = aPainter->transform().mapRect(r).toRect();
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2010-10-27 08:56:31 +04:00
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
|
|
|
nsRefPtr<gfxASurface> widgetSurface = GetSurfaceForQWidget(aWidget);
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(widgetSurface);
|
|
|
|
ctx->SetSource(gBufferSurface);
|
2011-10-17 18:59:28 +04:00
|
|
|
ctx->Rectangle(gfxRect(trans.x(), trans.y(), trans.width(), trans.height()), true);
|
2010-10-27 08:56:31 +04:00
|
|
|
ctx->Clip();
|
|
|
|
ctx->Fill();
|
2011-08-24 20:15:58 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeImage) {
|
2010-10-27 08:56:31 +04:00
|
|
|
#ifdef MOZ_HAVE_SHMIMAGE
|
|
|
|
if (gShmImage) {
|
|
|
|
gShmImage->Put(aWidget, trans);
|
|
|
|
} else
|
|
|
|
#endif
|
2011-08-24 20:15:58 +04: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-27 08:56:31 +04:00
|
|
|
}
|
|
|
|
}
|
2010-02-25 23:45:37 +03:00
|
|
|
}
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
ctx = nsnull;
|
|
|
|
targetSurface = nsnull;
|
2012-03-20 00:16:57 +04:00
|
|
|
DispatchDidPaint(this);
|
2008-04-19 19:43:23 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
// check the return value!
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnMoveEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("configure event [%p] %d %d\n", (void *)this,
|
|
|
|
aEvent->pos().x(), aEvent->pos().y()));
|
|
|
|
|
|
|
|
// can we shortcut?
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-22 15:21:18 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if ((mBounds.x == aEvent->pos().x() &&
|
|
|
|
mBounds.y == aEvent->pos().y()))
|
2008-04-20 12:16:40 +04:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_MOVE, this);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
event.refPoint.x = aEvent->pos().x();
|
|
|
|
event.refPoint.y = aEvent->pos().y();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// XXX mozilla will invalidate the entire window after this move
|
|
|
|
// complete. wtf?
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnResizeEvent(QGraphicsSceneResizeEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-02-11 16:51:06 +03:00
|
|
|
nsIntRect rect;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// Generate XPFE resize event
|
|
|
|
GetBounds(rect);
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
rect.width = aEvent->newSize().width();
|
|
|
|
rect.height = aEvent->newSize().height();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-22 15:21:18 +04:00
|
|
|
nsWindow::OnCloseEvent(QCloseEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_XUL_CLOSE, this);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnEnterNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_ENTER, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOG(("OnEnterNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnLeaveNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_EXIT, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOG(("OnLeaveNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2010-10-09 10:08:42 +04: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 12:16:40 +04:00
|
|
|
nsEventStatus
|
2011-02-04 00:27:01 +03:00
|
|
|
nsWindow::OnMotionNotifyEvent(QPointF aPos, Qt::KeyboardModifiers aModifiers)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-10-09 10:08:42 +04:00
|
|
|
UserActivity();
|
|
|
|
|
|
|
|
CHECK_MOUSE_BLOCKED
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2011-02-04 00:27:01 +03:00
|
|
|
mMoveEvent.pos = aPos;
|
|
|
|
mMoveEvent.modifiers = aModifiers;
|
2011-01-18 11:51:04 +03:00
|
|
|
mMoveEvent.needDispatch = true;
|
|
|
|
DispatchMotionToMainThread();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-01-18 11:51:04 +03:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::InitButtonEvent(nsMouseEvent &aMoveEvent,
|
|
|
|
QGraphicsSceneMouseEvent *aEvent, int aClickCount)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
aMoveEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
aMoveEvent.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
aMoveEvent.isShift = ((aEvent->modifiers() & Qt::ShiftModifier) != 0);
|
|
|
|
aMoveEvent.isControl = ((aEvent->modifiers() & Qt::ControlModifier) != 0);
|
|
|
|
aMoveEvent.isAlt = ((aEvent->modifiers() & Qt::AltModifier) != 0);
|
|
|
|
aMoveEvent.isMeta = ((aEvent->modifiers() & Qt::MetaModifier) != 0);
|
|
|
|
aMoveEvent.clickCount = aClickCount;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnButtonPressEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
CHECK_MOUSE_BLOCKED
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
QPointF pos = aEvent->pos();
|
|
|
|
|
|
|
|
// we check against the widgets geometry, so use parent coordinates
|
|
|
|
// for the check
|
|
|
|
if (mWidget)
|
|
|
|
pos = mWidget->mapToParent(pos);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool rolledUp = check_for_rollup( pos.x(), pos.y(), false);
|
2008-08-16 11:07:21 +04:00
|
|
|
if (gConsumeRollupEvent && rolledUp)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
PRUint16 domButton;
|
|
|
|
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 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
event.button = domButton;
|
|
|
|
InitButtonEvent(event, aEvent, 1);
|
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// right menu click on linux should also pop up a context menu
|
|
|
|
if (domButton == nsMouseEvent::eRightButton &&
|
|
|
|
NS_LIKELY(!mIsDestroyed)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2008-04-19 19:37:51 +04:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-19 19:38:12 +04:00
|
|
|
InitButtonEvent(contextMenuEvent, aEvent, 1);
|
2008-04-19 19:37:51 +04:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnButtonReleaseEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-10-09 10:08:42 +04:00
|
|
|
UserActivity();
|
|
|
|
CHECK_MOUSE_BLOCKED
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
PRUint16 domButton;
|
|
|
|
|
|
|
|
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 12:37:07 +04:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
event.button = domButton;
|
2008-04-19 19:38:12 +04:00
|
|
|
InitButtonEvent(event, aEvent, 1);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
|
|
|
|
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-04-22 02:54:25 +04:00
|
|
|
nsWindow::OnMouseDoubleClickEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
PRUint32 eventType;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
switch (aEvent->button()) {
|
2008-04-19 19:37:51 +04:00
|
|
|
case Qt::MidButton:
|
|
|
|
eventType = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
eventType = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eventType = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
event.button = eventType;
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
InitButtonEvent(event, aEvent, 2);
|
2008-04-19 19:37:51 +04:00
|
|
|
//pressed
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnFocusInEvent(QEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this));
|
2010-07-29 05:05:56 +04:00
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-07-29 05:05:56 +04:00
|
|
|
DispatchActivateEventOnTopLevelWindow();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnFocusOutEvent(QEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-07-29 05:05:56 +04:00
|
|
|
if (!mWidget)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-09-01 22:01:50 +04:00
|
|
|
#if MOZ_PLATFORM_MAEMO > 5
|
2010-08-31 03:40:14 +04: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-29 05:05:56 +04:00
|
|
|
DispatchDeactivateEventOnTopLevelWindow();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2008-04-19 19:37:51 +04: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-14 05:58:07 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this);
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2011-07-14 05:58:07 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchContentCommandEvent(PRInt32 aMsg)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsContentCommandEvent event(true, aMsg, this);
|
2011-07-14 05:58:07 +04:00
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2011-07-14 05:58:07 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::OnKeyPressEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool setNoDefault = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 22:11:54 +04: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 18:59:28 +04:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2010-08-26 22:11:54 +04:00
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 domCharCode = 0;
|
|
|
|
PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
|
|
|
|
|
|
|
// get keymap and modifier map from the Xserver
|
2012-03-23 03:24:40 +04:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2010-08-26 22:11:54 +04: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 21:42:02 +03:00
|
|
|
if (!xmodmap)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
|
|
|
|
&xkeysyms_per_keycode);
|
2010-12-11 21:42:02 +03:00
|
|
|
if (!xkeymap) {
|
|
|
|
XFreeModifiermap(xmodmap);
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2010-08-26 22:11:54 +04: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-29 10:19:26 +04:00
|
|
|
bool shift_state = ((shift_mask & aEvent->nativeModifiers()) != 0) ^
|
2010-08-26 22:11:54 +04:00
|
|
|
(bool)(shift_lock_mask & aEvent->nativeModifiers());
|
2011-09-29 10:19:26 +04:00
|
|
|
bool capslock_state = (bool)(caps_lock_mask & aEvent->nativeModifiers());
|
2010-08-26 22:11:54 +04: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())
|
|
|
|
domCharCode = (PRInt32) aEvent->text()[0].unicode();
|
|
|
|
|
|
|
|
// 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 18:59:28 +04:00
|
|
|
nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
|
2010-08-26 22:11:54 +04:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
|
|
|
downEvent.keyCode = domKeyCode;
|
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273)
|
|
|
|
if (NS_UNLIKELY(mIsDestroyed)) {
|
|
|
|
qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed";
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 18:59:28 +04:00
|
|
|
setNoDefault = true;
|
2010-08-26 22:11:54 +04: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-14 05:58:07 +04:00
|
|
|
// Look for specialized app-command keys
|
|
|
|
switch (aEvent->key()) {
|
|
|
|
case Qt::Key_Back:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Forward:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Refresh:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Reload);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Stop:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Stop);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Search:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Search);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Favorites:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Bookmarks);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_HomePage:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Home);
|
2011-07-14 05:58:07 +04: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 18:59:28 +04:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2010-08-26 22:11:54 +04:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (setNoDefault) {
|
|
|
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
domCharCode = (PRUint32) keysym2ucs(keysym);
|
|
|
|
if (domCharCode == -1 || ! QChar((quint32)domCharCode).isPrint()) {
|
|
|
|
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) {
|
|
|
|
domCharCode = (PRUint32) QChar::toLower((uint) xkeymap[index + i]);
|
|
|
|
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.
|
2011-10-17 18:59:28 +04:00
|
|
|
event.isControl = false;
|
|
|
|
event.isAlt = false;
|
|
|
|
event.isMeta = false;
|
2010-08-26 22:11:54 +04: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) {
|
|
|
|
altCharCode.mUnshiftedCharCode = (PRUint32) QChar::toUpper((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (PRUint32) QChar::toLower((uint)domCharCode);
|
|
|
|
} else {
|
|
|
|
altCharCode.mUnshiftedCharCode = (PRUint32) QChar::toLower((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (PRUint32) QChar::toUpper((uint)domCharCode);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
altCharCode.mUnshiftedCharCode = (PRUint32) unshiftedChar.unicode();
|
|
|
|
altCharCode.mShiftedCharCode = (PRUint32) shiftedChar.unicode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 19:37:51 +04: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 12:16:40 +04:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
2008-04-19 19:37:51 +04:00
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
2008-04-20 12:16:40 +04:00
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
PRUint32 domCharCode = 0;
|
|
|
|
PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
|
|
|
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
|
|
|
domCharCode = (PRInt32) aEvent->text()[0].unicode();
|
|
|
|
|
|
|
|
// 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 19:37:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
|
2008-04-20 12:16:40 +04:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
2010-04-22 16:58:46 +04:00
|
|
|
downEvent.keyCode = domKeyCode;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 18:59:28 +04:00
|
|
|
setNoDefault = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
2008-04-20 12:16:40 +04:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
2010-08-26 22:11:54 +04:00
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
|
|
|
|
if (setNoDefault)
|
|
|
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
|
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
2010-08-26 22:11:54 +04:00
|
|
|
#endif
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::OnKeyReleaseEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
|
|
|
// er, what do we do here? DoDefault or NoDefault?
|
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (!domKeyCode) {
|
|
|
|
// get keymap from the Xserver
|
2012-03-23 03:24:40 +04:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2010-08-26 22:11:54 +04: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 19:37:51 +04:00
|
|
|
// send the key event as a key up event
|
2011-10-17 18:59:28 +04:00
|
|
|
nsKeyEvent event(true, NS_KEY_UP, this);
|
2008-04-19 19:37:51 +04:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = false;
|
|
|
|
}
|
|
|
|
|
2010-04-22 16:58:46 +04:00
|
|
|
event.keyCode = domKeyCode;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
// unset the key down flag
|
|
|
|
ClearKeyDownFlag(event.keyCode);
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnScrollEvent(QGraphicsSceneWheelEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseScrollEvent event(true, NS_MOUSE_SCROLL, this);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
switch (aEvent->orientation()) {
|
|
|
|
case Qt::Vertical:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsVertical;
|
|
|
|
break;
|
|
|
|
case Qt::Horizontal:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 12:16:40 +04:00
|
|
|
|
|
|
|
// negative values for aEvent->delta indicate downward scrolling;
|
|
|
|
// this is opposite Gecko usage.
|
|
|
|
|
|
|
|
event.delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
event.refPoint.x = nscoord(aEvent->scenePos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->scenePos().y());
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
event.isShift = aEvent->modifiers() & Qt::ShiftModifier;
|
|
|
|
event.isControl = aEvent->modifiers() & Qt::ControlModifier;
|
|
|
|
event.isAlt = aEvent->modifiers() & Qt::AltModifier;
|
|
|
|
event.isMeta = aEvent->modifiers() & Qt::MetaModifier;
|
|
|
|
event.time = 0;
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsVisible = true;
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::hideEvent(QHideEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsVisible = false;
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2010-03-13 01:11:42 +03:00
|
|
|
//Gestures are only supported in 4.6.0 >
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-09-29 10:19:26 +04:00
|
|
|
nsEventStatus nsWindow::OnTouchEvent(QTouchEvent *event, bool &handled)
|
2010-03-13 01:11:42 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
handled = false;
|
2010-03-13 01:11:42 +03:00
|
|
|
const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
|
|
|
|
|
|
|
|
if (event->type() == QEvent::TouchBegin) {
|
2011-10-17 18:59:28 +04:00
|
|
|
handled = true;
|
2010-03-13 01:11:42 +03:00
|
|
|
for (int i = touchPoints.count() -1; i >= 0; i--) {
|
|
|
|
QPointF fpos = touchPoints[i].pos();
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGestureNotifyEvent gestureNotifyEvent(true, NS_GESTURENOTIFY_EVENT_START, this);
|
2010-03-13 01:11:42 +03:00
|
|
|
gestureNotifyEvent.refPoint = nsIntPoint(fpos.x(), fpos.y());
|
|
|
|
DispatchEvent(&gestureNotifyEvent);
|
|
|
|
}
|
|
|
|
}
|
2010-10-09 10:08:42 +04:00
|
|
|
else if (event->type() == QEvent::TouchEnd) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mGesturesCancelled = false;
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.needDispatch = false;
|
2010-10-09 10:08:42 +04:00
|
|
|
}
|
|
|
|
|
2011-01-18 11:51:04 +03: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 23:30:34 +03:00
|
|
|
mPinchEvent.touchPoint = touchPoints.at(0).pos();
|
2010-10-09 10:08:42 +04:00
|
|
|
}
|
2010-03-13 01:11:42 +03:00
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
nsEventStatus
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::OnGestureEvent(QGestureEvent* event, bool &handled) {
|
2010-10-09 10:08:42 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
handled = false;
|
2010-10-09 10:08:42 +04:00
|
|
|
if (mGesturesCancelled) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
QGesture* gesture = event->gesture(Qt::PinchGesture);
|
|
|
|
|
|
|
|
if (gesture) {
|
|
|
|
QPinchGesture* pinch = static_cast<QPinchGesture*>(gesture);
|
2011-10-17 18:59:28 +04:00
|
|
|
handled = true;
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.centerPoint =
|
2010-10-09 10:14:57 +04:00
|
|
|
mWidget->mapFromScene(event->mapToGraphicsScene(pinch->centerPoint()));
|
2011-01-18 11:51:04 +03:00
|
|
|
nsIntPoint centerPoint(mPinchEvent.centerPoint.x(),
|
|
|
|
mPinchEvent.centerPoint.y());
|
2010-03-13 01:11:42 +03:00
|
|
|
|
|
|
|
if (pinch->state() == Qt::GestureStarted) {
|
|
|
|
event->accept();
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.startDistance = DistanceBetweenPoints(mPinchEvent.centerPoint, mPinchEvent.touchPoint) * 2;
|
|
|
|
mPinchEvent.prevDistance = mPinchEvent.startDistance;
|
2010-10-09 10:08:42 +04:00
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY_START,
|
|
|
|
0, 0, centerPoint);
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
else if (pinch->state() == Qt::GestureUpdated) {
|
2011-03-15 23:30:34 +03:00
|
|
|
mPinchEvent.needDispatch = true;
|
|
|
|
mPinchEvent.delta = 0;
|
|
|
|
DispatchMotionToMainThread();
|
2010-04-21 06:50:49 +04:00
|
|
|
}
|
|
|
|
else if (pinch->state() == Qt::GestureFinished) {
|
2011-01-18 11:51:04 +03:00
|
|
|
double distance = DistanceBetweenPoints(mPinchEvent.centerPoint, mPinchEvent.touchPoint) * 2;
|
|
|
|
double delta = distance - mPinchEvent.startDistance;
|
2010-10-09 10:08:42 +04:00
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY,
|
|
|
|
0, delta, centerPoint);
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.needDispatch = false;
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
else {
|
2010-10-09 10:08:42 +04:00
|
|
|
handled = false;
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
2010-04-21 06:50:49 +04:00
|
|
|
|
2011-01-18 11:51:04 +03:00
|
|
|
//Disable mouse events when gestures are used, because they cause problems with
|
|
|
|
//Fennec
|
|
|
|
mLastMultiTouchTime.start();
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
gesture = event->gesture(gSwipeGestureId);
|
|
|
|
if (gesture) {
|
|
|
|
if (gesture->state() == Qt::GestureStarted) {
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
if (gesture->state() == Qt::GestureFinished) {
|
|
|
|
event->accept();
|
2011-10-17 18:59:28 +04:00
|
|
|
handled = true;
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
MozSwipeGesture* swipe = static_cast<MozSwipeGesture*>(gesture);
|
|
|
|
nsIntPoint hotspot;
|
|
|
|
hotspot.x = swipe->hotSpot().x();
|
|
|
|
hotspot.y = swipe->hotSpot().y();
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
// Cancel pinch gesture
|
2011-10-17 18:59:28 +04:00
|
|
|
mGesturesCancelled = true;
|
2011-01-18 11:51:04 +03:00
|
|
|
mPinchEvent.needDispatch = false;
|
|
|
|
|
|
|
|
double distance = DistanceBetweenPoints(swipe->hotSpot(), mPinchEvent.touchPoint) * 2;
|
|
|
|
PRFloat64 delta = distance - mPinchEvent.startDistance;
|
|
|
|
|
|
|
|
DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY, 0, delta / 2, hotspot);
|
2010-10-09 10:08:42 +04:00
|
|
|
|
|
|
|
result = DispatchGestureEvent(NS_SIMPLE_GESTURE_SWIPE,
|
|
|
|
swipe->Direction(), 0, hotspot);
|
|
|
|
}
|
2011-01-18 11:51:04 +03:00
|
|
|
mLastMultiTouchTime.start();
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
2010-10-09 10:08:42 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchGestureEvent(PRUint32 aMsg, PRUint32 aDirection,
|
|
|
|
double aDelta, const nsIntPoint& aRefPoint)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsSimpleGestureEvent mozGesture(true, aMsg, this, 0, 0.0);
|
2010-10-09 10:08:42 +04:00
|
|
|
mozGesture.direction = aDirection;
|
|
|
|
mozGesture.delta = aDelta;
|
|
|
|
mozGesture.refPoint = aRefPoint;
|
|
|
|
|
|
|
|
Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mozGesture.isShift = (modifiers & Qt::ShiftModifier) ? true : false;
|
|
|
|
mozGesture.isControl = (modifiers & Qt::ControlModifier) ? true : false;
|
|
|
|
mozGesture.isMeta = false;
|
|
|
|
mozGesture.isAlt = (modifiers & Qt::AltModifier) ? true : false;
|
2010-10-09 10:08:42 +04:00
|
|
|
mozGesture.button = 0;
|
|
|
|
mozGesture.time = 0;
|
|
|
|
|
|
|
|
return DispatchEvent(&mozGesture);
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
|
2010-03-13 01:11:42 +03: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 19:37:51 +04:00
|
|
|
void
|
|
|
|
nsWindow::ThemeChanged()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_THEMECHANGED, this);
|
2008-04-20 12:16:40 +04:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// do nothing
|
2008-04-19 19:37:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnDragMotionEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::OnDragMotionSignal\n"));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_OVER, 0,
|
2008-04-19 19:37:51 +04:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnDragLeaveEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 19:37:51 +04: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 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnDragDropEvent(QGraphicsSceneDragDropEvent *aDropEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-19 19:43:56 +04:00
|
|
|
if (aDropEvent->proposedAction() == Qt::CopyAction)
|
|
|
|
{
|
|
|
|
printf("text version of the data: %s\n", aDropEvent->mimeData()->text().toAscii().data());
|
|
|
|
aDropEvent->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
LOG(("nsWindow::OnDragDropSignal\n"));
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_OVER, 0,
|
2008-04-19 19:37:51 +04:00
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::OnDragEnter(QGraphicsSceneDragDropEvent *aDragEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-19 19:43:56 +04: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 19:37:51 +04: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 18:59:28 +04:00
|
|
|
nsMouseEvent event(true, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal);
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
2010-05-14 13:24:41 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2008-04-19 19:37:51 +04: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-24 10:18:10 +04:00
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext *aContext,
|
2009-09-24 10:18:10 +04:00
|
|
|
nsWidgetInitData *aInitData)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
// only set the base parent if we're not going to be a dialog or a
|
2008-04-19 19:37:51 +04:00
|
|
|
// toplevel
|
2010-02-16 21:14:20 +03:00
|
|
|
nsIWidget *baseParent = aParent;
|
|
|
|
|
|
|
|
if (aInitData &&
|
2008-04-19 19:37:51 +04:00
|
|
|
(aInitData->mWindowType == eWindowType_dialog ||
|
|
|
|
aInitData->mWindowType == eWindowType_toplevel ||
|
2010-02-16 21:14:20 +03:00
|
|
|
aInitData->mWindowType == eWindowType_invisible)) {
|
|
|
|
|
|
|
|
baseParent = nsnull;
|
|
|
|
// also drop native parent for toplevel windows
|
|
|
|
aNativeParent = nsnull;
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// initialize all the common bits of this class
|
2011-10-25 19:05:32 +04:00
|
|
|
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aInitData);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// and do our common creation
|
2008-04-22 15:21:18 +04:00
|
|
|
mParent = aParent;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// find native parent
|
|
|
|
MozQWidget *parent = nsnull;
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
if (aParent != nsnull)
|
2010-02-16 21:14:20 +03:00
|
|
|
parent = static_cast<MozQWidget*>(aParent->GetNativeData(NS_NATIVE_WIDGET));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// ok, create our QGraphicsWidget
|
2011-09-25 23:03:22 +04:00
|
|
|
mWidget = createQWidget(parent, aNativeParent, aInitData);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-02-16 18:27:18 +03:00
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
LOG(("Create: nsWindow [%p] [%p]\n", (void *)this, (void *)mWidget));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// resize so that everything is set to the right dimensions
|
2011-10-17 18:59:28 +04:00
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-03-22 05:55:36 +03:00
|
|
|
// check if we should listen for resizes
|
|
|
|
mListenForResizes = (aNativeParent ||
|
|
|
|
(aInitData && aInitData->mListenForResizes));
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-31 20:35:57 +04:00
|
|
|
already_AddRefed<nsIWidget>
|
|
|
|
nsWindow::CreateChild(const nsIntRect& aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext* aContext,
|
2010-08-31 20:35:57 +04:00
|
|
|
nsWidgetInitData* aInitData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool /*aForceUseIWidgetParent*/)
|
2010-08-31 20:35:57 +04:00
|
|
|
{
|
|
|
|
//We need to force parent widget, otherwise GetTopLevelWindow doesn't work
|
|
|
|
return nsBaseWidget::CreateChild(aRect,
|
|
|
|
aHandleEventFunction,
|
|
|
|
aContext,
|
|
|
|
aInitData,
|
2011-10-17 18:59:28 +04:00
|
|
|
true); // Force parent
|
2010-08-31 20:35:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2010-02-16 21:14:20 +03: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-11 01:13:02 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
// If widget not show, handle might be null
|
2012-03-23 03:24:40 +04:00
|
|
|
if (widget && widget->winId())
|
|
|
|
XSetClassHint(gfxQtPlatform::GetXDisplay(widget),
|
|
|
|
widget->winId(),
|
2010-03-11 01:13:02 +03:00
|
|
|
class_hint);
|
2010-02-16 21:14:20 +03:00
|
|
|
|
|
|
|
nsMemory::Free(class_hint->res_class);
|
2008-04-19 19:37:51 +04:00
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2008-04-20 17:54:27 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::NativeResize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = false;
|
2010-03-22 05:55:36 +03:00
|
|
|
|
2011-02-03 09:31:36 +03:00
|
|
|
if (mIsTopLevel) {
|
2011-12-23 08:13:53 +04:00
|
|
|
QGraphicsView *widget = qobject_cast<QGraphicsView*>(GetViewWidget());
|
2010-08-21 05:12:14 +04:00
|
|
|
NS_ENSURE_TRUE(widget,);
|
2011-12-23 08:13:53 +04: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-21 05:12:14 +04:00
|
|
|
}
|
2011-02-03 09:31:43 +03:00
|
|
|
else {
|
|
|
|
mWidget->resize(aWidth, aHeight);
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
if (aRepaint)
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->update();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::NativeResize(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepaint)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aX, aY, aWidth, aHeight));
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
2010-03-22 05:55:36 +03:00
|
|
|
|
2010-05-14 22:13:36 +04:00
|
|
|
if (mIsTopLevel) {
|
2011-12-23 08:13:53 +04:00
|
|
|
QGraphicsView *widget = qobject_cast<QGraphicsView*>(GetViewWidget());
|
2011-02-03 09:31:36 +03:00
|
|
|
NS_ENSURE_TRUE(widget,);
|
2011-12-23 08:13:53 +04: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 22:13:36 +04:00
|
|
|
}
|
2011-02-03 09:31:43 +03:00
|
|
|
else {
|
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2008-04-20 12:37:07 +04:00
|
|
|
if (aRepaint)
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->update();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2009-08-05 06:39:05 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::NativeShow(bool aAction)
|
2009-08-05 06:39:05 +04:00
|
|
|
{
|
2010-03-15 09:08:15 +03:00
|
|
|
if (aAction) {
|
|
|
|
QWidget *widget = GetViewWidget();
|
2010-03-18 19:44:33 +03: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 16:20:48 +03:00
|
|
|
if (widget &&
|
|
|
|
!widget->isVisible())
|
2010-03-15 09:08:15 +03:00
|
|
|
MakeFullScreen(mSizeMode == nsSizeMode_Fullscreen);
|
2009-08-05 06:39:05 +04:00
|
|
|
mWidget->show();
|
2010-03-22 05:55:36 +03:00
|
|
|
|
|
|
|
// unset our flag now that our window has been shown
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsShow = false;
|
2010-03-15 09:08:15 +03:00
|
|
|
}
|
2009-08-05 06:39:05 +04:00
|
|
|
else
|
|
|
|
mWidget->hide();
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetHasTransparentBackground(bool aTransparent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-20 12:16:40 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::GetHasTransparentBackground(bool& aTransparent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
aTransparent = mIsTransparent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
2010-04-20 22:49:34 +04:00
|
|
|
NS_WARNING("Not implemented");
|
2008-04-19 19:37:51 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-01-22 07:15:34 +03:00
|
|
|
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-02-16 21:14:20 +03:00
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aIconList.Length(); ++i) {
|
|
|
|
const char *path = aIconList[i].get();
|
|
|
|
LOG(("window [%p] Loading icon from %s\n", (void *)this, path));
|
|
|
|
icon.addFile(path);
|
|
|
|
}
|
2010-03-06 10:25:46 +03:00
|
|
|
|
2010-03-15 09:08:15 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
|
|
|
widget->setWindowIcon(icon);
|
2010-03-06 10:25:46 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
|
|
|
{
|
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
|
|
|
}
|
|
|
|
|
2009-03-27 14:35:27 +03:00
|
|
|
void nsWindow::QWidgetDestroyed()
|
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget = nsnull;
|
2009-03-27 14:35:27 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-03-15 09:08:15 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
2010-02-04 17:43:52 +03:00
|
|
|
if (aFullScreen) {
|
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen)
|
|
|
|
mLastSizeMode = mSizeMode;
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2010-02-04 17:43:52 +03:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showFullScreen();
|
2010-02-04 17:43:52 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
|
|
|
|
|
|
|
switch (mSizeMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showMaximized();
|
2010-02-04 17:43:52 +03:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showMinimized();
|
2010-02-04 17:43:52 +03:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Normal:
|
2010-03-15 09:08:15 +03:00
|
|
|
widget->showNormal();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
widget->showNormal();
|
2010-02-04 17:43:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-26 03:33:31 +03:00
|
|
|
|
2010-02-04 17:43:52 +03:00
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
2010-03-26 03:33:31 +03:00
|
|
|
return nsBaseWidget::MakeFullScreen(aFullScreen);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::HideWindowChrome(bool aShouldHide)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget) {
|
2010-07-27 08:38:35 +04:00
|
|
|
// Nothing to hide
|
2008-04-19 19:37:51 +04: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-29 10:19:26 +04:00
|
|
|
bool wasVisible = false;
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mWidget->isVisible()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NativeShow(false);
|
|
|
|
wasVisible = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wasVisible) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NativeShow(true);
|
2008-04-19 19:37:51 +04: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-15 09:08:15 +03:00
|
|
|
QWidget *widget = GetViewWidget();
|
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2012-03-23 03:24:40 +04:00
|
|
|
XSync(gfxQtPlatform::GetXDisplay(widget), False);
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2008-04-19 19:37:51 +04: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 21:14:20 +03:00
|
|
|
// drag context.
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
initialize_prefs(void)
|
|
|
|
{
|
|
|
|
// check to see if we should set our raise pref
|
2011-06-07 11:38:00 +04:00
|
|
|
gDisableNativeTheme =
|
|
|
|
Preferences::GetBool("mozilla.widget.disable-native-theme",
|
|
|
|
gDisableNativeTheme);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2008-04-19 19:37:51 +04:00
|
|
|
is_context_menu_key(const nsKeyEvent& aKeyEvent)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
key_event_to_context_menu_event(nsMouseEvent &aEvent,
|
|
|
|
QKeyEvent *aGdkEvent)
|
|
|
|
{
|
2009-02-11 16:51:06 +03:00
|
|
|
aEvent.refPoint = nsIntPoint(0, 0);
|
2011-10-17 18:59:28 +04:00
|
|
|
aEvent.isShift = false;
|
|
|
|
aEvent.isControl = false;
|
|
|
|
aEvent.isAlt = false;
|
|
|
|
aEvent.isMeta = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
aEvent.time = 0;
|
|
|
|
aEvent.clickCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsChildWindow class
|
|
|
|
|
|
|
|
nsChildWindow::nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChildWindow::~nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::nsPopupWindow()
|
|
|
|
{
|
2010-08-26 19:18:06 +04:00
|
|
|
#ifdef DEBUG_WIDGETS
|
2008-04-19 19:37:51 +04:00
|
|
|
qDebug("===================== popup!");
|
2010-08-26 19:18:06 +04:00
|
|
|
#endif
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::~nsPopupWindow()
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:18:35 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
nsWindow::HasGLContext()
|
|
|
|
{
|
|
|
|
QGraphicsView *view = qobject_cast<QGraphicsView*>(GetViewWidget());
|
|
|
|
return view && qobject_cast<QGLWidget*>(view->viewport());
|
|
|
|
}
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
MozQWidget*
|
2011-09-25 23:03:22 +04:00
|
|
|
nsWindow::createQWidget(MozQWidget *parent,
|
|
|
|
nsNativeWidget nativeParent,
|
|
|
|
nsWidgetInitData *aInitData)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2008-04-20 12:16:40 +04:00
|
|
|
const char *windowName = NULL;
|
2011-02-03 09:31:43 +03:00
|
|
|
Qt::WindowFlags flags = Qt::Widget;
|
|
|
|
QWidget *parentWidget = (parent && parent->getReceiver()) ?
|
|
|
|
parent->getReceiver()->GetViewWidget() : nsnull;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2008-04-19 19:31:50 +04:00
|
|
|
#ifdef DEBUG_WIDGETS
|
|
|
|
qDebug("NEW WIDGET\n\tparent is %p (%s)", (void*)parent,
|
|
|
|
parent ? qPrintable(parent->objectName()) : "null");
|
|
|
|
#endif
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2008-04-19 19:31:50 +04:00
|
|
|
// ok, create our windows
|
|
|
|
switch (mWindowType) {
|
|
|
|
case eWindowType_dialog:
|
2008-04-20 12:16:40 +04:00
|
|
|
windowName = "topLevelDialog";
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTopLevel = true;
|
2011-02-03 09:31:43 +03:00
|
|
|
flags |= Qt::Dialog;
|
2008-04-20 12:16:40 +04:00
|
|
|
break;
|
2008-04-19 19:31:50 +04:00
|
|
|
case eWindowType_popup:
|
2008-04-20 12:16:40 +04:00
|
|
|
windowName = "topLevelPopup";
|
|
|
|
break;
|
2008-04-19 19:31:50 +04:00
|
|
|
case eWindowType_toplevel:
|
2008-04-20 12:16:40 +04:00
|
|
|
windowName = "topLevelWindow";
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTopLevel = true;
|
2008-04-19 19:31:50 +04:00
|
|
|
break;
|
2008-04-20 12:16:40 +04:00
|
|
|
case eWindowType_invisible:
|
|
|
|
windowName = "topLevelInvisible";
|
2008-04-19 19:31:50 +04:00
|
|
|
break;
|
2008-04-20 12:16:40 +04:00
|
|
|
case eWindowType_child:
|
2009-09-24 13:32:20 +04:00
|
|
|
case eWindowType_plugin:
|
|
|
|
default: // sheet
|
2008-04-20 12:16:40 +04:00
|
|
|
windowName = "paintArea";
|
2008-04-19 19:31:50 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-25 23:03:22 +04:00
|
|
|
MozQWidget* parentQWidget = nsnull;
|
|
|
|
if (parent) {
|
|
|
|
parentQWidget = parent;
|
|
|
|
} else if (nativeParent && nativeParent != PARENTLESS_WIDGET) {
|
|
|
|
parentQWidget = static_cast<MozQWidget*>(nativeParent);
|
|
|
|
}
|
|
|
|
MozQWidget * widget = new MozQWidget(this, parentQWidget);
|
2010-02-16 21:14:20 +03:00
|
|
|
if (!widget)
|
|
|
|
return nsnull;
|
|
|
|
|
2010-02-25 21:58:19 +03: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 21:14:20 +03:00
|
|
|
// create a QGraphicsView if this is a new toplevel window
|
|
|
|
|
2010-03-13 01:06:17 +03:00
|
|
|
if (mIsTopLevel) {
|
2011-10-28 16:13:57 +04:00
|
|
|
QGraphicsView* newView =
|
|
|
|
nsFastStartup::GetStartupGraphicsView(parentWidget, widget);
|
2011-02-03 09:31:36 +03:00
|
|
|
|
2011-02-03 09:31:43 +03:00
|
|
|
if (mWindowType == eWindowType_dialog) {
|
|
|
|
newView->setWindowModality(Qt::WindowModal);
|
|
|
|
}
|
|
|
|
|
2012-04-24 17:23:26 +04:00
|
|
|
#if defined(MOZ_PLATFORM_MAEMO) || defined(MOZ_GL_PROVIDER)
|
2011-08-24 20:15:58 +04:00
|
|
|
if (GetShouldAccelerate()) {
|
2011-10-28 16:13:57 +04:00
|
|
|
// Only create new OGL widget if it is not yet installed
|
2012-04-12 08:18:35 +04:00
|
|
|
if (!HasGLContext()) {
|
2012-04-24 17:23:26 +04:00
|
|
|
MozQGraphicsView *qview = qobject_cast<MozQGraphicsView*>(newView);
|
|
|
|
if (qview) {
|
|
|
|
qview->setGLWidgetEnabled(true);
|
|
|
|
}
|
2011-10-28 16:13:57 +04:00
|
|
|
}
|
2010-09-15 09:15:14 +04:00
|
|
|
}
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2010-10-27 08:56:31 +04:00
|
|
|
if (gfxQtPlatform::GetPlatform()->GetRenderMode() == gfxQtPlatform::RENDER_DIRECT) {
|
|
|
|
// Disable double buffer and system background rendering
|
2012-03-23 03:24:40 +04:00
|
|
|
#if defined(MOZ_X11) && (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
2010-10-27 08:56:31 +04:00
|
|
|
newView->viewport()->setAttribute(Qt::WA_PaintOnScreen, true);
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2010-10-27 08:56:31 +04:00
|
|
|
newView->viewport()->setAttribute(Qt::WA_NoSystemBackground, true);
|
|
|
|
}
|
2010-03-13 01:11:42 +03:00
|
|
|
// Enable gestures:
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-08-28 22:09:56 +04: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-13 01:11:42 +03:00
|
|
|
newView->viewport()->grabGesture(Qt::PinchGesture);
|
2010-10-09 10:08:42 +04:00
|
|
|
newView->viewport()->grabGesture(gSwipeGestureId);
|
2010-03-13 01:11:42 +03:00
|
|
|
#endif
|
2010-02-16 21:14:20 +03:00
|
|
|
newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
2010-02-25 23:45:37 +03: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 18:37:27 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2011-02-23 20:39:00 +03:00
|
|
|
if (newView->effectiveWinId()) {
|
2012-03-23 03:24:40 +04:00
|
|
|
XSetWindowBackgroundPixmap(mozilla::DefaultXDisplay(),
|
2011-02-23 20:39:00 +03:00
|
|
|
newView->effectiveWinId(), None);
|
|
|
|
}
|
2011-01-04 18:37:27 +03:00
|
|
|
#endif
|
2011-02-03 09:31:43 +03:00
|
|
|
}
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
2010-02-16 21:14:20 +03:00
|
|
|
widget->setZValue(100);
|
|
|
|
|
2008-04-20 12:16:40 +04: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-09 10:08:42 +04:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
2011-08-28 22:09:56 +04: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-09 10:08:42 +04:00
|
|
|
widget->grabGesture(Qt::PinchGesture);
|
|
|
|
widget->grabGesture(gSwipeGestureId);
|
|
|
|
#endif
|
2010-03-06 10:25:46 +03:00
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
return widget;
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
// return the gfxASurface for rendering to this widget
|
2008-04-19 19:31:50 +04:00
|
|
|
gfxASurface*
|
|
|
|
nsWindow::GetThebesSurface()
|
|
|
|
{
|
2008-04-29 05:16:45 +04: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-20 06:46:54 +03:00
|
|
|
if (mThebesSurface)
|
|
|
|
return mThebesSurface;
|
|
|
|
|
2010-10-05 10:15:57 +04:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-10-27 08:56:31 +04:00
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
2010-02-20 06:46:54 +03:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
mThebesSurface = new gfxQPainterSurface(gfxIntSize(1, 1), gfxASurface::CONTENT_COLOR);
|
|
|
|
}
|
2010-10-05 10:15:57 +04:00
|
|
|
#endif
|
2010-02-20 06:46:54 +03:00
|
|
|
if (!mThebesSurface) {
|
|
|
|
gfxASurface::gfxImageFormat imageFormat = gfxASurface::ImageFormatRGB24;
|
|
|
|
mThebesSurface = new gfxImageSurface(gfxIntSize(1, 1), imageFormat);
|
|
|
|
}
|
2008-04-19 19:31:50 +04:00
|
|
|
|
|
|
|
return mThebesSurface;
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
|
|
|
|
if (aEvent->eventStructType != NS_MOUSE_EVENT) {
|
2010-02-16 21:14:20 +03:00
|
|
|
// you can only begin a resize drag with a mouse event
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent* mouse_event = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
|
|
|
|
if (mouse_event->button != nsMouseEvent::eLeftButton) {
|
2010-02-16 21:14:20 +03:00
|
|
|
// you can only begin a resize drag with the left mouse button
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2010-02-16 21:14:20 +03:00
|
|
|
nsWindow::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::imComposeEvent(QInputMethodEvent *event, bool &handled)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2011-09-22 13:17:40 +04:00
|
|
|
// XXX Needs to check whether this widget has been destroyed or not after
|
|
|
|
// each DispatchEvent().
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent start(true, NS_COMPOSITION_START, this);
|
2010-11-20 02:41:40 +03:00
|
|
|
DispatchEvent(&start);
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2011-09-22 13:17:40 +04:00
|
|
|
nsAutoString compositionStr(event->commitString().utf16());
|
|
|
|
|
|
|
|
if (!compositionStr.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent update(true, NS_COMPOSITION_UPDATE, this);
|
2011-09-22 13:17:40 +04:00
|
|
|
update.data = compositionStr;
|
|
|
|
DispatchEvent(&update);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsTextEvent text(true, NS_TEXT_TEXT, this);
|
2011-09-22 13:17:40 +04:00
|
|
|
text.theText = compositionStr;
|
2010-11-20 02:41:40 +03:00
|
|
|
DispatchEvent(&text);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsCompositionEvent end(true, NS_COMPOSITION_END, this);
|
2011-09-22 13:17:40 +04:00
|
|
|
end.data = compositionStr;
|
2010-11-20 02:41:40 +03:00
|
|
|
DispatchEvent(&end);
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
nsIWidget *
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:57:55 +04: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 15:21:17 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_ACTIVATE, this);
|
2008-04-22 15:21:17 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_DEACTIVATE, this);
|
2008-04-22 15:21:17 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2010-07-29 05:05:56 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEventOnTopLevelWindow(void)
|
|
|
|
{
|
|
|
|
nsWindow * topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nsnull)
|
|
|
|
topLevelWindow->DispatchActivateEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEventOnTopLevelWindow(void)
|
|
|
|
{
|
|
|
|
nsWindow * topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nsnull)
|
|
|
|
topLevelWindow->DispatchDeactivateEvent();
|
|
|
|
}
|
|
|
|
|
2008-04-22 15:21:17 +04:00
|
|
|
void
|
2009-02-11 16:51:06 +03:00
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
event.windowSize = &aRect;
|
|
|
|
event.refPoint.x = aRect.x;
|
|
|
|
event.refPoint.y = aRect.y;
|
|
|
|
event.mWinWidth = aRect.width;
|
|
|
|
event.mWinHeight = aRect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent,
|
|
|
|
nsEventStatus &aStatus)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, aEvent->widget, aEvent,
|
|
|
|
nsCAutoString("something"), 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// send it to the standard callback
|
|
|
|
if (mEventCallback)
|
|
|
|
aStatus = (* mEventCallback)(aEvent);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::Show(bool aState)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
|
|
|
|
2008-04-22 15:21:18 +04:00
|
|
|
mIsShown = aState;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2011-05-02 12:16:22 +04: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-22 05:55:36 +03:00
|
|
|
if ((aState && !AreBoundsSane()) || !mWidget) {
|
|
|
|
LOG(("\tbounds are insane or window hasn't been created yet\n"));
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsShow = true;
|
2008-04-22 15:21:18 +04:00
|
|
|
return NS_OK;
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aState) {
|
|
|
|
if (mNeedsMove) {
|
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2010-03-22 05:55:36 +03:00
|
|
|
} else if (mNeedsResize) {
|
2011-10-17 18:59:28 +04:00
|
|
|
NativeResize(mBounds.width, mBounds.height, false);
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// If someone is hiding this widget, clear any needing show flag.
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsShow = false;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2010-03-22 05:55:36 +03:00
|
|
|
NativeShow(aState);
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-22 15:21:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-22 05:55:36 +03: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 18:59:28 +04:00
|
|
|
NativeShow(true);
|
2010-03-22 05:55:36 +03: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 18:59:28 +04:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2010-03-22 05:55:36 +03:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2010-03-22 05:55:36 +03: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.
|
|
|
|
NativeResize(aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = true;
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2010-03-22 05:55:36 +03:00
|
|
|
// synthesize a resize event if this isn't a toplevel
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
nsIntRect rect(mBounds.x, mBounds.y, aWidth, aHeight);
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRepaint)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPlaced = true;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2009-07-15 16:20:21 +04:00
|
|
|
if (!mWidget)
|
2008-04-22 15:21:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-22 05:55:36 +03:00
|
|
|
// Has this widget been set to visible?
|
|
|
|
if (mIsShown) {
|
|
|
|
// Are the bounds sane?
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
// Yep? Resize the window
|
|
|
|
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow)
|
2011-10-17 18:59:28 +04:00
|
|
|
NativeShow(true);
|
2010-03-22 05:55:36 +03: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 18:59:28 +04:00
|
|
|
// calling NativeShow(false) excessively on the window which
|
2010-03-22 05:55:36 +03:00
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the widget hasn't been shown, mark the widget as needing to be
|
|
|
|
// resized before it is shown
|
|
|
|
else if (AreBoundsSane() && mListenForResizes) {
|
|
|
|
// For widgets that we listen for resizes for (widgets created
|
|
|
|
// with native parents) we apparently _always_ have to resize. I
|
|
|
|
// dunno why, but apparently we're lame like that.
|
|
|
|
NativeResize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = true;
|
|
|
|
mNeedsMove = true;
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2010-03-22 05:55:36 +03:00
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
// synthesize a resize event
|
|
|
|
nsIntRect rect(aX, aY, aWidth, aHeight);
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2008-04-22 15:21:18 +04:00
|
|
|
if (aRepaint)
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->update();
|
2008-04-22 15:21:18 +04:00
|
|
|
|
2008-04-22 15:21:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::Enable(bool aState)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
|
|
|
mEnabled = aState;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::IsEnabled(bool *aState)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
|
|
|
*aState = mEnabled;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mOnDestroyCalled = true;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2011-10-25 19:05:32 +04:00
|
|
|
// release references to children and device context
|
2008-04-22 15:21:17 +04:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// let go of our parent
|
|
|
|
mParent = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsGUIEvent event(true, NS_DESTROY, this);
|
2008-04-22 15:21:17 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-04-22 15:21:17 +04:00
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
|
|
|
if (mBounds.width > 0 && mBounds.height > 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
2010-03-13 01:07:32 +03:00
|
|
|
|
2011-09-07 19:06:35 +04: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-23 03:24:40 +04:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2011-09-07 19:06:35 +04: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-23 03:24:40 +04:00
|
|
|
Display *display = mozilla::DefaultXDisplay();
|
2011-09-07 19:06:35 +04: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 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-03-13 01:07:32 +03:00
|
|
|
{
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_ENSURE_TRUE(mWidget, );
|
2010-03-13 01:07:32 +03:00
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
// SetSoftwareKeyboardState uses mInputContext,
|
|
|
|
// so, before calling that, record aContext in mInputContext.
|
|
|
|
mInputContext = aContext;
|
2011-08-16 20:27:36 +04:00
|
|
|
|
2011-09-07 19:06:35 +04:00
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
2011-10-07 19:16:37 +04:00
|
|
|
if (sPluginIMEAtom) {
|
|
|
|
static QCoreApplication::EventFilter currentEventFilter = NULL;
|
2011-11-27 15:51:53 +04:00
|
|
|
if (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN &&
|
2011-11-27 15:51:52 +04:00
|
|
|
currentEventFilter != x11EventFilter) {
|
2011-10-07 19:16:37 +04:00
|
|
|
// Install event filter for listening Plugin IME state changes
|
|
|
|
previousEventFilter = QCoreApplication::instance()->setEventFilter(x11EventFilter);
|
|
|
|
currentEventFilter = x11EventFilter;
|
2011-11-27 15:51:53 +04:00
|
|
|
} else if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 15:51:52 +04:00
|
|
|
currentEventFilter == x11EventFilter) {
|
2011-10-07 19:16:37 +04:00
|
|
|
// Remove event filter
|
|
|
|
QCoreApplication::instance()->setEventFilter(previousEventFilter);
|
|
|
|
currentEventFilter = previousEventFilter;
|
|
|
|
previousEventFilter = NULL;
|
|
|
|
QWidget* view = GetViewWidget();
|
|
|
|
if (view) {
|
|
|
|
SetVKBState(view->winId(), VKBUndefined);
|
|
|
|
}
|
2011-09-07 19:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-27 15:51:53 +04:00
|
|
|
switch (mInputContext.mIMEState.mEnabled) {
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
case IMEState::PASSWORD:
|
|
|
|
case IMEState::PLUGIN:
|
2011-11-27 15:51:52 +04:00
|
|
|
SetSoftwareKeyboardState(true, aAction);
|
2010-03-13 01:07:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-27 15:51:52 +04:00
|
|
|
SetSoftwareKeyboardState(false, aAction);
|
2010-03-13 01:07:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2010-03-13 01:07:32 +03:00
|
|
|
{
|
2011-11-27 15:51:53 +04:00
|
|
|
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
2011-11-27 15:51:52 +04:00
|
|
|
return mInputContext;
|
2010-03-13 01:07:32 +03:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:06:35 +04:00
|
|
|
void
|
2011-11-27 15:51:52 +04:00
|
|
|
nsWindow::SetSoftwareKeyboardState(bool aOpen,
|
|
|
|
const InputContextAction& aAction)
|
2011-09-07 19:06:35 +04:00
|
|
|
{
|
|
|
|
if (aOpen) {
|
2011-11-27 15:51:53 +04:00
|
|
|
NS_ENSURE_TRUE(mInputContext.mIMEState.mEnabled != IMEState::DISABLED,);
|
2011-09-07 19:06:35 +04:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 15:51:52 +04:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 15:51:53 +04:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 15:51:52 +04:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 15:51:53 +04:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 15:51:52 +04:00
|
|
|
return;
|
2011-09-07 19:06:35 +04:00
|
|
|
}
|
|
|
|
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
|
|
|
|
// doen't open VKB if plugin did set closed state
|
2011-10-07 19:16:37 +04:00
|
|
|
else if (sPluginIMEAtom) {
|
2011-09-07 19:06:35 +04: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
|
|
|
|
PRInt32 openDelay =
|
|
|
|
Preferences::GetInt("ui.vkb.open.delay", 200);
|
|
|
|
MozQWidget::requestVKB(openDelay, mWidget);
|
|
|
|
} else {
|
|
|
|
MozQWidget::hideVKB();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
|
|
|
{
|
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIdleService) {
|
|
|
|
mIdleService->ResetIdleTimeOut();
|
|
|
|
}
|
|
|
|
}
|
2012-02-22 23:16:15 +04:00
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
|
|
|
// On maemo the hardware fb has RGB format.
|
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
#else
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
}
|
|
|
|
|