2010-03-03 09:45:16 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-04-19 08:37:51 -07:00
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QGuiApplication>
|
2010-03-04 13:51:42 -08:00
|
|
|
#include <QtGui/QCursor>
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QIcon>
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QResizeEvent>
|
2010-04-13 16:11:23 -07:00
|
|
|
#include <QPaintEngine>
|
2012-03-22 16:24:40 -07:00
|
|
|
#include <QMimeData>
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QScreen>
|
2010-03-04 13:51:42 -08:00
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
#include <QtCore/QVariant>
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-03-04 13:51:42 -08:00
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <X11/Xlib.h>
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <X11/Xutil.h>
|
2014-05-29 12:55:44 -07:00
|
|
|
#include "gfxXlibSurface.h"
|
2010-08-26 11:11:54 -07:00
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2010-03-18 09:44:33 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
#include "prlink.h"
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
#include "nsWindow.h"
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "mozqwidget.h"
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
#include "nsIdleService.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2008-04-19 08:37:51 -07:00
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsQtKeyUtils.h"
|
2010-05-14 02:24:41 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2014-02-20 18:09:02 -08:00
|
|
|
#include "ClientLayerManager.h"
|
|
|
|
#include "BasicLayers.h"
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
#include "gfxQtPlatform.h"
|
2009-03-27 04:35:27 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
#include "nsIDOMWheelEvent.h"
|
2010-03-12 14:11:42 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "keysym2ucs.h"
|
2011-09-07 08:06:35 -07:00
|
|
|
#endif
|
2010-08-26 11:11:54 -07:00
|
|
|
|
2010-06-24 03:07:57 -07:00
|
|
|
#include "Layers.h"
|
2012-11-03 21:00:08 -07:00
|
|
|
#include "GLContextProvider.h"
|
2010-10-26 21:56:31 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-20 18:09:02 -08:00
|
|
|
using namespace mozilla::gl;
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
2014-02-20 18:09:02 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::layers;
|
2012-11-03 21:00:08 -07:00
|
|
|
using mozilla::gl::GLContext;
|
2010-10-26 21:56:31 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// Qt
|
2008-04-19 08:37:51 -07:00
|
|
|
static const int WHEEL_DELTA = 120;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gGlobalsInitialized = false;
|
2011-01-26 01:01:01 -08:00
|
|
|
static bool sAltGrModifier = false;
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
static void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem);
|
|
|
|
static bool is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
|
|
|
|
static bool isContextMenuKeyEvent(const QKeyEvent *qe);
|
|
|
|
static void InitKeyEvent(WidgetKeyboardEvent &aEvent, QKeyEvent *aQEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTopLevel = false;
|
|
|
|
mIsDestroyed = false;
|
|
|
|
mIsShown = false;
|
|
|
|
mEnabled = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
mWidget = nullptr;
|
2014-02-20 18:09:02 -08:00
|
|
|
mVisible = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
mActivatePending = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2010-05-30 11:35:07 -07:00
|
|
|
mLastSizeMode = nsSizeMode_Normal;
|
2008-04-19 08:37:51 -07:00
|
|
|
mQCursor = Qt::ArrowCursor;
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
|
|
|
mListenForResizes = false;
|
|
|
|
mNeedsShow = false;
|
|
|
|
mTimerStarted = false;
|
2011-01-18 00:51:04 -08:00
|
|
|
mMoveEvent.needDispatch = false;
|
2014-02-20 18:09:02 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (!gGlobalsInitialized) {
|
2012-03-21 16:14:09 -07:00
|
|
|
gfxPlatform::GetPlatform();
|
2011-10-17 07:59:28 -07:00
|
|
|
gGlobalsInitialized = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsTransparent = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
mCursor = eCursor_standard;
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::~nsWindow()
|
2010-02-19 19:46:54 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
Destroy();
|
2010-04-13 16:11:23 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsresult
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
nsDeviceContext *aContext,
|
|
|
|
nsWidgetInitData *aInitData)
|
2010-02-19 19:46:54 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
// only set the base parent if we're not going to be a dialog or a
|
|
|
|
// toplevel
|
|
|
|
nsIWidget *baseParent = aParent;
|
|
|
|
|
|
|
|
// initialize all the common bits of this class
|
|
|
|
BaseCreate(baseParent, aRect, aContext, aInitData);
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mVisible = true;
|
|
|
|
|
|
|
|
// and do our common creation
|
|
|
|
mParent = (nsWindow *)aParent;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// find native parent
|
|
|
|
MozQWidget *parent = nullptr;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aParent != nullptr) {
|
|
|
|
parent = static_cast<MozQWidget*>(aParent->GetNativeData(NS_NATIVE_WIDGET));
|
|
|
|
} else if (aNativeParent != nullptr) {
|
|
|
|
parent = static_cast<MozQWidget*>(aNativeParent);
|
|
|
|
if (parent && mParent == nullptr) {
|
|
|
|
mParent = parent->getReceiver();
|
2010-10-26 21:56:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("Create: nsWindow [%p] mWidget:[%p] parent:[%p], natPar:[%p] mParent:%p\n", (void *)this, (void*)mWidget, parent, aNativeParent, mParent));
|
2010-10-26 21:56:31 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// ok, create our QGraphicsWidget
|
|
|
|
mWidget = createQWidget(parent, aInitData);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// resize so that everything is set to the right dimensions
|
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// check if we should listen for resizes
|
|
|
|
mListenForResizes = (aNativeParent ||
|
|
|
|
(aInitData && aInitData->mListenForResizes));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MozQWidget*
|
|
|
|
nsWindow::createQWidget(MozQWidget* parent,
|
|
|
|
nsWidgetInitData* aInitData)
|
2009-08-04 19:39:05 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
const char *windowName = nullptr;
|
|
|
|
Qt::WindowFlags flags = Qt::Widget;
|
2009-08-04 19:39:05 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// ok, create our windows
|
|
|
|
switch (mWindowType) {
|
|
|
|
case eWindowType_dialog:
|
|
|
|
windowName = "topLevelDialog";
|
|
|
|
flags = Qt::Dialog;
|
|
|
|
break;
|
|
|
|
case eWindowType_popup:
|
|
|
|
windowName = "topLevelPopup";
|
|
|
|
flags = Qt::Popup;
|
|
|
|
break;
|
|
|
|
case eWindowType_toplevel:
|
|
|
|
windowName = "topLevelWindow";
|
|
|
|
flags = Qt::Window;
|
|
|
|
break;
|
|
|
|
case eWindowType_invisible:
|
|
|
|
windowName = "topLevelInvisible";
|
|
|
|
break;
|
|
|
|
case eWindowType_child:
|
|
|
|
case eWindowType_plugin:
|
|
|
|
default: // sheet
|
|
|
|
windowName = "paintArea";
|
|
|
|
break;
|
|
|
|
}
|
2009-08-04 19:39:05 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
MozQWidget* widget = new MozQWidget(this, parent);
|
|
|
|
if (!widget) {
|
|
|
|
return nullptr;
|
2009-08-04 19:39:05 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
|
|
|
|
widget->setObjectName(QString(windowName));
|
|
|
|
if (mWindowType == eWindowType_invisible) {
|
2014-05-16 16:33:53 -07:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
|
2014-02-20 18:09:02 -08:00
|
|
|
widget->setVisibility(QWindow::Hidden);
|
2014-05-16 16:33:53 -07:00
|
|
|
#else
|
|
|
|
widget->hide();
|
|
|
|
#endif
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
|
|
|
if (mWindowType == eWindowType_dialog) {
|
|
|
|
widget->setModality(Qt::WindowModal);
|
|
|
|
}
|
|
|
|
|
|
|
|
widget->create();
|
|
|
|
|
|
|
|
// create a QGraphicsView if this is a new toplevel window
|
|
|
|
LOG(("nsWindow::%s [%p] Created Window: %s, widget:%p, par:%p\n", __FUNCTION__, (void *)this, windowName, widget, parent));
|
|
|
|
|
|
|
|
return widget;
|
2009-08-04 19:39:05 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mIsDestroyed || !mWidget) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsDestroyed = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-11-03 21:00:08 -07:00
|
|
|
/** Need to clean our LayerManager up while still alive */
|
2010-09-09 16:41:02 -07:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mLayerManager = nullptr;
|
2010-09-09 16:41:02 -07:00
|
|
|
|
2012-11-03 21:00:08 -07:00
|
|
|
// It is safe to call DestroyeCompositor several times (here and
|
|
|
|
// in the parent class) since it will take effect only once.
|
|
|
|
// The reason we call it here is because on gtk platforms we need
|
|
|
|
// to destroy the compositor before we destroy the gdk window (which
|
|
|
|
// destroys the the gl context attached to it).
|
|
|
|
DestroyCompositor();
|
|
|
|
|
|
|
|
ClearCachedResources();
|
|
|
|
|
|
|
|
nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
if (rollupListener) {
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget) {
|
2014-02-20 18:09:02 -08:00
|
|
|
rollupListener->Rollup(0, nullptr, nullptr);
|
2012-12-31 09:27:04 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-03 21:00:08 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
Show(false);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// walk the list of children and call destroy on them. Have to be
|
|
|
|
// careful, though -- calling destroy on a kid may actually remove
|
|
|
|
// it from our child list, losing its sibling links.
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; ) {
|
|
|
|
nsIWidget* next = kid->GetNextSibling();
|
|
|
|
kid->Destroy();
|
|
|
|
kid = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy thebes surface now. Badness can happen if we destroy
|
|
|
|
// the surface after its X Window.
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget) {
|
|
|
|
mWidget->dropReceiver();
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// Call deleteLater instead of delete; Qt still needs the object
|
|
|
|
// to be valid even after sending it a Close event. We could
|
|
|
|
// also set WA_DeleteOnClose, but this gives us more control.
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->deleteLater();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mWidget = nullptr;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
OnDestroy();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Show(bool aState)
|
2012-11-03 21:00:08 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
|
|
|
if (aState == mIsShown) {
|
|
|
|
return NS_OK;
|
2012-11-03 21:00:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// Clear our cached resources when the window is hidden.
|
|
|
|
if (mIsShown && !aState) {
|
|
|
|
ClearCachedResources();
|
2010-09-18 04:28:50 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mIsShown = aState;
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if ((aState && !AreBoundsSane()) || !mWidget) {
|
|
|
|
LOG(("\tbounds are insane or window hasn't been created yet\n"));
|
|
|
|
mNeedsShow = true;
|
|
|
|
return NS_OK;
|
2010-09-18 04:28:50 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aState) {
|
|
|
|
if (mNeedsMove) {
|
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
|
|
|
false);
|
|
|
|
} else if (mNeedsResize) {
|
|
|
|
NativeResize(mBounds.width, mBounds.height, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If someone is hiding this widget, clear any needing show flag.
|
|
|
|
mNeedsShow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeShow(aState);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
bool
|
|
|
|
nsWindow::IsVisible() const
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-07-19 01:57:50 -07:00
|
|
|
return mIsShown;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t screenWidth = qApp->primaryScreen()->size().width();
|
|
|
|
int32_t screenHeight = qApp->primaryScreen()->size().height();
|
|
|
|
|
|
|
|
if (aAllowSlop) {
|
|
|
|
if (*aX < (kWindowPositionSlop - mBounds.width))
|
|
|
|
*aX = kWindowPositionSlop - mBounds.width;
|
|
|
|
if (*aX > (screenWidth - kWindowPositionSlop))
|
|
|
|
*aX = screenWidth - kWindowPositionSlop;
|
|
|
|
if (*aY < (kWindowPositionSlop - mBounds.height))
|
|
|
|
*aY = kWindowPositionSlop - mBounds.height;
|
|
|
|
if (*aY > (screenHeight - kWindowPositionSlop))
|
|
|
|
*aY = screenHeight - kWindowPositionSlop;
|
|
|
|
} else {
|
|
|
|
if (*aX < 0)
|
|
|
|
*aX = 0;
|
|
|
|
if (*aX > (screenWidth - mBounds.width))
|
|
|
|
*aX = screenWidth - mBounds.width;
|
|
|
|
if (*aY < 0)
|
|
|
|
*aY = 0;
|
|
|
|
if (*aY > (screenHeight - mBounds.height))
|
|
|
|
*aY = screenHeight - mBounds.height;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 01:57:38 -08:00
|
|
|
nsWindow::Move(double aX, double aY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2012-12-12 01:57:38 -08:00
|
|
|
LOG(("nsWindow::Move [%p] %f %f\n", (void *)this,
|
2008-04-19 08:37:51 -07:00
|
|
|
aX, aY));
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
int32_t x = NSToIntRound(aX);
|
|
|
|
int32_t y = NSToIntRound(aY);
|
|
|
|
|
2010-03-16 23:32:38 -07:00
|
|
|
if (mIsTopLevel) {
|
2009-11-02 11:10:07 -08:00
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (x == mBounds.x && y == mBounds.y) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsMove = false;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// update the bounds
|
2014-02-20 18:09:02 -08:00
|
|
|
QPoint pos(x, y);
|
2011-02-02 22:31:43 -08:00
|
|
|
if (mIsTopLevel) {
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->setPosition(x, y);
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
|
|
|
else if (mWidget) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// the position of the widget is set relative to the parent
|
|
|
|
// so we map the coordinates accordingly
|
2014-02-20 18:09:02 -08:00
|
|
|
pos = mWidget->mapToGlobal(pos);
|
|
|
|
mWidget->setPosition(pos);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = pos.x();
|
|
|
|
mBounds.y = pos.y();
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NotifyRollupGeometryChange();
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08: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);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow) {
|
|
|
|
NativeShow(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
// calling NativeShow(false) excessively on the window which
|
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08: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(mBounds.width, mBounds.height, aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mNeedsResize = true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// synthesize a resize event if this isn't a toplevel
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(mBounds, status);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NotifyRollupGeometryChange();
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
|
|
|
|
bool aRepaint)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
mBounds.x = NSToIntRound(aX);
|
|
|
|
mBounds.y = NSToIntRound(aY);
|
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mPlaced = true;
|
|
|
|
|
|
|
|
if (!mWidget) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has this widget been set to visible?
|
|
|
|
if (mIsShown) {
|
|
|
|
// Are the bounds sane?
|
|
|
|
if (AreBoundsSane()) {
|
|
|
|
// Yep? Resize the window
|
|
|
|
NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
|
|
|
aRepaint);
|
|
|
|
// Does it need to be shown because it was previously insane?
|
|
|
|
if (mNeedsShow)
|
|
|
|
NativeShow(true);
|
|
|
|
}
|
2010-03-25 17:33:31 -07:00
|
|
|
else {
|
2014-02-20 18:09:02 -08:00
|
|
|
// 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
|
|
|
|
// calling NativeShow(false) excessively on the window which
|
|
|
|
// causes unneeded X traffic.
|
|
|
|
if (!mNeedsShow) {
|
|
|
|
mNeedsShow = true;
|
|
|
|
NativeShow(false);
|
2010-03-25 17:33:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 18:09:02 -08: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(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
|
|
|
|
aRepaint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mNeedsResize = true;
|
|
|
|
mNeedsMove = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
// synthesize a resize event
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(mBounds, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRepaint) {
|
|
|
|
mWidget->renderLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyRollupGeometryChange();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Enable(bool aState)
|
|
|
|
{
|
|
|
|
mEnabled = aState;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsWindow::IsEnabled() const
|
|
|
|
{
|
|
|
|
return mEnabled;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// Make sure that our owning widget has focus. If it doesn't try to
|
|
|
|
// grab it. Note that we don't set our focus flag in this case.
|
|
|
|
LOGFOCUS((" SetFocus [%p]\n", (void *)this));
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mWidget->focusObject()) {
|
2010-03-25 17:33:31 -07:00
|
|
|
return NS_OK;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2010-03-25 17:33:31 -07:00
|
|
|
|
|
|
|
// Because QGraphicsItem cannot get the focus if they are
|
2010-02-16 10:14:20 -08:00
|
|
|
// invisible, we look up the chain, for the lowest visible
|
|
|
|
// parent and focus that one
|
2014-02-20 18:09:02 -08:00
|
|
|
QWindow* realFocusItem = nullptr;
|
2010-02-16 10:14:20 -08:00
|
|
|
find_first_visible_parent(mWidget, realFocusItem);
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!realFocusItem || realFocusItem->focusObject()) {
|
2009-07-15 05:20:21 -07:00
|
|
|
return NS_OK;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aRaise && mWidget) {
|
2010-02-25 10:58:19 -08:00
|
|
|
// the raising has to happen on the view widget
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->raise();
|
2010-02-25 10:58:19 -08:00
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
// XXXndeakin why is this here? It should dispatch only when the OS
|
|
|
|
// notifies us.
|
2010-02-16 10:14:20 -08:00
|
|
|
DispatchActivateEvent();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
2010-12-29 08:22:26 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (w->mBounds.Size() != configuration.mBounds.Size()) {
|
|
|
|
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
|
|
|
|
configuration.mBounds.width, configuration.mBounds.height,
|
|
|
|
true);
|
|
|
|
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
|
|
|
w->Move(configuration.mBounds.x, configuration.mBounds.y);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-23 19:52:21 -08:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2011-12-23 19:52:21 -08:00
|
|
|
LOGDRAW(("Invalidate (rect) [%p,%p]: %d %d %d %d\n", (void *)this,
|
|
|
|
(void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->renderLater();
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0));
|
|
|
|
|
|
|
|
QPoint origin(0, 0);
|
|
|
|
origin = mWidget->mapToGlobal(origin);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return nsIntPoint(origin.x(), origin.y());
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
void*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWindow::GetNativeData(uint32_t aDataType)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-15 05:20:21 -07:00
|
|
|
return mWidget;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW: {
|
|
|
|
return mWidget ? (void*)mWidget->winId() : nullptr;
|
|
|
|
}
|
|
|
|
case NS_NATIVE_DISPLAY: {
|
2011-08-24 09:15:58 -07:00
|
|
|
#ifdef MOZ_X11
|
2014-02-20 18:09:02 -08:00
|
|
|
return gfxQtPlatform::GetXDisplay(mWidget);
|
2011-08-24 09:15:58 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
2010-06-24 03:07:57 -07:00
|
|
|
case NS_NATIVE_SHELLWIDGET: {
|
2014-02-20 18:09:02 -08:00
|
|
|
break;
|
2011-08-31 12:01:38 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::%s [%p] aDataType:%i\n", __FUNCTION__, (void *)this, aDataType));
|
|
|
|
return nullptr;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, aEvent->widget, aEvent,
|
|
|
|
nsAutoCString("something"), 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// send it to the standard callback
|
|
|
|
if (mWidgetListener) {
|
|
|
|
aStatus = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
|
2010-03-14 23:08:15 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(mWidget);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// SetSoftwareKeyboardState uses mInputContext,
|
|
|
|
// so, before calling that, record aContext in mInputContext.
|
|
|
|
mInputContext = aContext;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
switch (mInputContext.mIMEState.mEnabled) {
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
case IMEState::PASSWORD:
|
|
|
|
case IMEState::PLUGIN:
|
|
|
|
SetSoftwareKeyboardState(true, aAction);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetSoftwareKeyboardState(false, aAction);
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
|
|
|
// Our qt widget looks like using only one context per process.
|
|
|
|
// However, it's better to set the context's pointer.
|
|
|
|
mInputContext.mNativeIMEContext = qApp->inputMethod();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return mInputContext;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
|
|
|
|
MozQWidget* newParent = static_cast<MozQWidget*>(aNewParent->GetNativeData(NS_NATIVE_WINDOW));
|
|
|
|
NS_ASSERTION(newParent, "Parent widget has a null native window handle");
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->setParent(newParent);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aFullScreen) {
|
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen) {
|
|
|
|
mLastSizeMode = mSizeMode;
|
|
|
|
}
|
2010-03-14 23:08:15 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
|
|
|
mWidget->showFullScreen();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
2010-03-14 23:08:15 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
switch (mSizeMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
|
|
|
mWidget->showMaximized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
mWidget->showMinimized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Normal:
|
|
|
|
mWidget->showNormal();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mWidget->showNormal();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
|
|
|
return nsBaseWidget::MakeFullScreen(aFullScreen);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
LayerManager*
|
|
|
|
nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mLayerManager && eTransparencyTransparent == GetTransparencyMode()) {
|
|
|
|
mLayerManager = CreateBasicLayerManager();
|
|
|
|
}
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return nsBaseWidget::GetLayerManager(aShadowManager, aBackendHint,
|
|
|
|
aPersistence, aAllowRetaining);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
2008-08-16 00:07:21 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
2012-12-31 09:27:04 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mIdleService) {
|
|
|
|
mIdleService->ResetIdleTimeOut(0);
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
uint32_t
|
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
2008-08-16 00:07:21 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) {
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
}
|
|
|
|
return LOCAL_GL_NONE;
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
2014-05-29 12:55:44 -07:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
nsWindow::StartRemoteDrawing()
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
Display* dpy = gfxQtPlatform::GetXDisplay(mWidget);
|
|
|
|
Screen* screen = DefaultScreenOfDisplay(dpy);
|
|
|
|
Visual* defaultVisual = DefaultVisualOfScreen(screen);
|
|
|
|
gfxASurface* surf = new gfxXlibSurface(dpy, mWidget->winId(), defaultVisual,
|
|
|
|
gfxIntSize(mWidget->width(),
|
|
|
|
mWidget->height()));
|
|
|
|
|
|
|
|
IntSize size(surf->GetSize().width, surf->GetSize().height);
|
|
|
|
if (size.width <= 0 || size.height <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(surf, size);
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::SetCursor(nsCursor aCursor)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-05-27 18:12:29 -07:00
|
|
|
if (mCursor == aCursor && !mUpdateCursor) {
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
2011-10-28 05:13:57 -07:00
|
|
|
}
|
2014-05-27 18:12:29 -07:00
|
|
|
mUpdateCursor = false;
|
2014-02-20 18:09:02 -08:00
|
|
|
mCursor = aCursor;
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->SetCursor(mCursor);
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
QString qStr(QString::fromUtf16((const ushort*)aTitle.BeginReading(), aTitle.Length()));
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->setTitle(qStr);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-03-15 21:41:53 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// EVENTS
|
2010-03-10 14:13:02 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::OnPaint()
|
|
|
|
{
|
|
|
|
LOGDRAW(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
nsIWidgetListener* listener =
|
|
|
|
mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener;
|
|
|
|
if (!listener) {
|
|
|
|
return;
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
listener->WillPaintWindow(this);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
switch (GetLayerManager()->GetBackendType()) {
|
|
|
|
case mozilla::layers::LayersBackend::LAYERS_CLIENT: {
|
|
|
|
nsIntRegion region(nsIntRect(0, 0, mWidget->width(), mWidget->height()));
|
|
|
|
listener->PaintWindow(this, region);
|
|
|
|
break;
|
2010-10-26 21:56:31 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid layer manager");
|
2010-02-25 12:45:37 -08:00
|
|
|
}
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
listener->DidPaintWindow();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::moveEvent(QMoveEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("configure event [%p] %d %d\n", (void *)this,
|
|
|
|
aEvent->pos().x(), aEvent->pos().y()));
|
|
|
|
|
|
|
|
// can we shortcut?
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidget || !mWidgetListener)
|
2008-04-22 04:21:18 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if ((mBounds.x == aEvent->pos().x() &&
|
|
|
|
mBounds.y == aEvent->pos().y()))
|
2008-04-20 01:16:40 -07:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-27 23:45:08 -08:00
|
|
|
NotifyWindowMoved(aEvent->pos().x(), aEvent->pos().y());
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::resizeEvent(QResizeEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-02-11 05:51:06 -08:00
|
|
|
nsIntRect rect;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// Generate XPFE resize event
|
|
|
|
GetBounds(rect);
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
rect.width = aEvent->size().width();
|
|
|
|
rect.height = aEvent->size().height();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::mouseMoveEvent(QMouseEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-10-08 23:08:42 -07:00
|
|
|
UserActivity();
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mMoveEvent.pos = aEvent->pos();
|
|
|
|
mMoveEvent.modifiers = aEvent->modifiers();
|
2011-01-18 00:51:04 -08:00
|
|
|
mMoveEvent.needDispatch = true;
|
|
|
|
DispatchMotionToMainThread();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2011-01-18 00:51:04 -08:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
static void
|
|
|
|
InitMouseEvent(WidgetMouseEvent& aMouseEvent, QMouseEvent* aEvent,
|
|
|
|
int aClickCount)
|
|
|
|
{
|
|
|
|
aMouseEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
aMouseEvent.refPoint.y = nscoord(aEvent->pos().y());
|
|
|
|
|
|
|
|
aMouseEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aEvent->modifiers() & Qt::MetaModifier);
|
|
|
|
aMouseEvent.clickCount = aClickCount;
|
|
|
|
|
|
|
|
switch (aEvent->button()) {
|
|
|
|
case Qt::LeftButton:
|
|
|
|
aMouseEvent.button = WidgetMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
aMouseEvent.button = WidgetMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
aMouseEvent.button = WidgetMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsAcceptedButton(Qt::MouseButton button)
|
|
|
|
{
|
|
|
|
switch (button) {
|
|
|
|
case Qt::LeftButton:
|
|
|
|
case Qt::RightButton:
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::mousePressEvent(QMouseEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
QPoint pos = aEvent->pos();
|
2010-02-16 10:14:20 -08:00
|
|
|
|
|
|
|
// we check against the widgets geometry, so use parent coordinates
|
|
|
|
// for the check
|
|
|
|
if (mWidget)
|
2014-02-20 18:09:02 -08:00
|
|
|
pos = mWidget->mapToGlobal(pos);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
if (CheckForRollup(pos.x(), pos.y(), false))
|
2008-08-16 00:07:21 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
if (!IsAcceptedButton(aEvent->button())) {
|
|
|
|
if (aEvent->button() == Qt::BackButton)
|
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
|
|
|
if (aEvent->button() == Qt::ForwardButton)
|
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this,
|
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 09:25:40 -07:00
|
|
|
InitMouseEvent(event, aEvent, 1);
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
// Right click on linux should also pop up a context menu.
|
|
|
|
if (event.button == WidgetMouseEvent::eRightButton &&
|
2012-10-26 06:32:10 -07:00
|
|
|
MOZ_LIKELY(!mIsDestroyed)) {
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 09:25:40 -07:00
|
|
|
InitMouseEvent(contextMenuEvent, aEvent, 1);
|
2008-04-19 08:37:51 -07:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::mouseReleaseEvent(QMouseEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
if (!IsAcceptedButton(aEvent->button()))
|
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-20 01:37:07 -07:00
|
|
|
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, NS_MOUSE_BUTTON_UP, this,
|
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 09:25:40 -07:00
|
|
|
InitMouseEvent(event, aEvent, 1);
|
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::mouseDoubleClickEvent(QMouseEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-05-26 09:25:40 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-05-26 09:25:40 -07:00
|
|
|
if (!IsAcceptedButton(aEvent->button()))
|
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this,
|
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 09:25:40 -07:00
|
|
|
InitMouseEvent(event, aEvent, 2);
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::focusInEvent(QFocusEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this));
|
2010-07-28 18:05:56 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-07-28 18:05:56 -07:00
|
|
|
DispatchActivateEventOnTopLevelWindow();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::focusOutEvent(QFocusEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
2010-07-28 18:05:56 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2010-07-28 18:05:56 -07:00
|
|
|
|
|
|
|
DispatchDeactivateEventOnTopLevelWindow();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::keyPressEvent(QKeyEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 19:09:00 -07:00
|
|
|
CodeNameIndex codeNameIndex =
|
|
|
|
ScanCodeToDOMCodeNameIndex(aEvent->nativeScanCode());
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// before we dispatch a key, check if it's the context menu key.
|
|
|
|
// If so, send a context menu key event instead.
|
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
|
|
|
WidgetMouseEvent::eReal,
|
|
|
|
WidgetMouseEvent::eContextMenuKey);
|
2010-08-26 11:11:54 -07:00
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domCharCode = 0;
|
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// get keymap and modifier map from the Xserver
|
2014-02-20 18:09:02 -08:00
|
|
|
Display *display = gfxQtPlatform::GetXDisplay(mWidget);
|
2010-08-26 11:11:54 -07:00
|
|
|
int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
|
|
|
|
XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
|
|
|
|
XModifierKeymap *xmodmap = XGetModifierMapping(display);
|
2010-12-11 10:42:02 -08:00
|
|
|
if (!xmodmap)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
|
|
|
|
&xkeysyms_per_keycode);
|
2010-12-11 10:42:02 -08:00
|
|
|
if (!xkeymap) {
|
|
|
|
XFreeModifiermap(xmodmap);
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// create modifier masks
|
|
|
|
qint32 shift_mask = 0, shift_lock_mask = 0, caps_lock_mask = 0, num_lock_mask = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 8 * xmodmap->max_keypermod; ++i) {
|
|
|
|
qint32 maskbit = 1 << (i / xmodmap->max_keypermod);
|
|
|
|
KeyCode modkeycode = xmodmap->modifiermap[i];
|
|
|
|
if (modkeycode == NoSymbol) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 mapindex = (modkeycode - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int j = 0; j < xkeysyms_per_keycode; ++j) {
|
|
|
|
KeySym modkeysym = xkeymap[mapindex + j];
|
|
|
|
switch (modkeysym) {
|
|
|
|
case XK_Num_Lock:
|
|
|
|
num_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Caps_Lock:
|
|
|
|
caps_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Shift_Lock:
|
|
|
|
shift_lock_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
case XK_Shift_L:
|
|
|
|
case XK_Shift_R:
|
|
|
|
shift_mask |= maskbit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// indicate whether is down or not
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shift_state = ((shift_mask & aEvent->nativeModifiers()) != 0) ^
|
2010-08-26 11:11:54 -07:00
|
|
|
(bool)(shift_lock_mask & aEvent->nativeModifiers());
|
2011-09-28 23:19:26 -07:00
|
|
|
bool capslock_state = (bool)(caps_lock_mask & aEvent->nativeModifiers());
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
// try to find a keysym that we can translate to a DOMKeyCode
|
|
|
|
// this is needed because some of Qt's keycodes cannot be translated
|
|
|
|
// TODO: use US keyboard keymap instead of localised keymap
|
|
|
|
if (!domKeyCode &&
|
|
|
|
aEvent->nativeScanCode() >= (quint32)x_min_keycode &&
|
|
|
|
aEvent->nativeScanCode() <= (quint32)x_max_keycode) {
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) {
|
|
|
|
domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// store character in domCharCode
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (int32_t) aEvent->text()[0].unicode();
|
2010-08-26 11:11:54 -07:00
|
|
|
|
2013-04-23 20:49:48 -07:00
|
|
|
KeyNameIndex keyNameIndex =
|
|
|
|
domCharCode ? KEY_NAME_INDEX_PrintableKey :
|
|
|
|
QtKeyCodeToDOMKeyNameIndex(aEvent->key());
|
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
// If the key isn't autorepeat, we need to send the initial down event
|
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
// send the key down event
|
|
|
|
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
|
2010-08-26 11:11:54 -07:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
|
|
|
downEvent.keyCode = domKeyCode;
|
2013-04-23 20:49:48 -07:00
|
|
|
downEvent.mKeyNameIndex = keyNameIndex;
|
2014-05-24 19:09:00 -07:00
|
|
|
downEvent.mCodeNameIndex = codeNameIndex;
|
2010-08-26 11:11:54 -07:00
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273)
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(mIsDestroyed)) {
|
2010-08-26 11:11:54 -07:00
|
|
|
qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed";
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:28 -07:00
|
|
|
// If prevent default on keydown, don't dispatch keypress event
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't pass modifiers as NS_KEY_PRESS events.
|
|
|
|
// Instead of selectively excluding some keys from NS_KEY_PRESS events,
|
|
|
|
// we instead selectively include (as per MSDN spec
|
|
|
|
// ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28VS.71%29.aspx );
|
|
|
|
// no official spec covers KeyPress events).
|
|
|
|
if (aEvent->key() == Qt::Key_Shift ||
|
|
|
|
aEvent->key() == Qt::Key_Control ||
|
|
|
|
aEvent->key() == Qt::Key_Meta ||
|
|
|
|
aEvent->key() == Qt::Key_Alt ||
|
|
|
|
aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
|
2013-07-24 23:09:28 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
2011-07-13 18:58:07 -07:00
|
|
|
// Look for specialized app-command keys
|
|
|
|
switch (aEvent->key()) {
|
|
|
|
case Qt::Key_Back:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Forward:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Refresh:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Reload);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Stop:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Stop);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Search:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Search);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Favorites:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Bookmarks);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_HomePage:
|
2011-10-14 11:11:22 -07:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Home);
|
2011-07-13 18:58:07 -07:00
|
|
|
case Qt::Key_Copy:
|
|
|
|
case Qt::Key_F16: // F16, F20, F18, F14 are old keysyms for Copy Cut Paste Undo
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_COPY);
|
|
|
|
case Qt::Key_Cut:
|
|
|
|
case Qt::Key_F20:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_CUT);
|
|
|
|
case Qt::Key_Paste:
|
|
|
|
case Qt::Key_F18:
|
|
|
|
case Qt::Key_F9:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_PASTE);
|
|
|
|
case Qt::Key_F14:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Qt::Key_Redo and Qt::Key_Undo are not available yet.
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff66) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
|
|
|
|
}
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff65) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
|
2010-08-26 11:11:54 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
// 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) &&
|
2014-02-20 18:09:02 -08:00
|
|
|
(QGuiApplication::keyboardModifiers() &
|
2010-08-26 11:11:54 -07:00
|
|
|
(Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
|
|
|
|
|
|
|
// get a character from X11 key map
|
|
|
|
KeySym keysym = aEvent->nativeVirtualKey();
|
|
|
|
if (keysym) {
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (uint32_t) keysym2ucs(keysym);
|
2012-11-03 21:00:08 -07:00
|
|
|
if (domCharCode == -1 || !QChar((quint32)domCharCode).isPrint()) {
|
2010-08-26 11:11:54 -07:00
|
|
|
domCharCode = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if Ctrl is pressed and domCharCode is not a ASCII character
|
2014-02-20 18:09:02 -08:00
|
|
|
if (domCharCode > 0xFF && (QGuiApplication::keyboardModifiers() & Qt::ControlModifier)) {
|
2010-08-26 11:11:54 -07:00
|
|
|
// replace Unicode character
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
if (xkeymap[index + i] <= 0xFF && !shift_state) {
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (uint32_t) QChar::toLower((uint) xkeymap[index + i]);
|
2010-08-26 11:11:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // The key event should cause a character input.
|
|
|
|
// At that time, we need to reset the modifiers
|
|
|
|
// because nsEditor will not accept a key event
|
|
|
|
// for text input if one or more modifiers are set.
|
2013-09-13 19:39:41 -07:00
|
|
|
event.modifiers &= ~(MODIFIER_CONTROL |
|
|
|
|
MODIFIER_ALT |
|
|
|
|
MODIFIER_META);
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
KeySym keysym = NoSymbol;
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
if (xkeymap[index + i] == aEvent->nativeVirtualKey()) {
|
|
|
|
if ((i % 2) == 0) { // shifted char
|
|
|
|
keysym = xkeymap[index + i + 1];
|
|
|
|
break;
|
|
|
|
} else { // unshifted char
|
|
|
|
keysym = xkeymap[index + i - 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xkeysyms_per_keycode - 1 == i) {
|
|
|
|
qWarning() << "Symbol '" << aEvent->nativeVirtualKey() << "' not found";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QChar unshiftedChar(domCharCode);
|
|
|
|
long ucs = keysym2ucs(keysym);
|
|
|
|
ucs = ucs == -1 ? 0 : ucs;
|
|
|
|
QChar shiftedChar((uint)ucs);
|
|
|
|
|
|
|
|
// append alternativeCharCodes if modifier is pressed
|
|
|
|
// append an additional alternativeCharCodes if domCharCode is not a Latin character
|
|
|
|
// and if one of these modifiers is pressed (i.e. Ctrl, Alt, Meta)
|
|
|
|
if (domCharCode &&
|
2014-02-20 18:09:02 -08:00
|
|
|
(QGuiApplication::keyboardModifiers() &
|
2010-08-26 11:11:54 -07:00
|
|
|
(Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
|
|
|
event.keyCode = 0;
|
2013-10-01 00:22:57 -07:00
|
|
|
AlternativeCharCode altCharCode(0, 0);
|
2010-08-26 11:11:54 -07:00
|
|
|
// if character has a lower and upper representation
|
|
|
|
if ((unshiftedChar.isUpper() || unshiftedChar.isLower()) &&
|
|
|
|
unshiftedChar.toLower() == shiftedChar.toLower()) {
|
|
|
|
if (shift_state ^ capslock_state) {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode);
|
2010-08-26 11:11:54 -07:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode);
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode);
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
altCharCode.mUnshiftedCharCode = (uint32_t) unshiftedChar.unicode();
|
|
|
|
altCharCode.mShiftedCharCode = (uint32_t) shiftedChar.unicode();
|
2010-08-26 11:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// append alternative char code to event
|
|
|
|
if ((altCharCode.mUnshiftedCharCode && altCharCode.mUnshiftedCharCode != domCharCode) ||
|
|
|
|
(altCharCode.mShiftedCharCode && altCharCode.mShiftedCharCode != domCharCode)) {
|
|
|
|
event.alternativeCharCodes.AppendElement(altCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the alternative char codes are latin-1
|
|
|
|
if (altCharCode.mUnshiftedCharCode > 0xFF || altCharCode.mShiftedCharCode > 0xFF) {
|
|
|
|
altCharCode.mUnshiftedCharCode = altCharCode.mShiftedCharCode = 0;
|
|
|
|
|
|
|
|
// find latin char for keycode
|
|
|
|
KeySym keysym = NoSymbol;
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
// find first shifted and unshifted Latin-Char in XKeyMap
|
|
|
|
for (int i = 0; i < xkeysyms_per_keycode; ++i) {
|
|
|
|
keysym = xkeymap[index + i];
|
|
|
|
if (keysym && keysym <= 0xFF) {
|
|
|
|
if ((shift_state && (i % 2 == 1)) ||
|
|
|
|
(!shift_state && (i % 2 == 0))) {
|
|
|
|
altCharCode.mUnshiftedCharCode = altCharCode.mUnshiftedCharCode ?
|
|
|
|
altCharCode.mUnshiftedCharCode :
|
|
|
|
keysym;
|
|
|
|
} else {
|
|
|
|
altCharCode.mShiftedCharCode = altCharCode.mShiftedCharCode ?
|
|
|
|
altCharCode.mShiftedCharCode :
|
|
|
|
keysym;
|
|
|
|
}
|
|
|
|
if (altCharCode.mUnshiftedCharCode && altCharCode.mShiftedCharCode) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (altCharCode.mUnshiftedCharCode || altCharCode.mShiftedCharCode) {
|
|
|
|
event.alternativeCharCodes.AppendElement(altCharCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event.charCode = domCharCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmodmap) {
|
|
|
|
XFreeModifiermap(xmodmap);
|
|
|
|
}
|
|
|
|
if (xkeymap) {
|
|
|
|
XFree(xkeymap);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
2013-04-23 20:49:48 -07:00
|
|
|
event.mKeyNameIndex = keyNameIndex;
|
2014-05-24 19:09:00 -07:00
|
|
|
event.mCodeNameIndex = codeNameIndex;
|
2010-08-26 11:11:54 -07:00
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
|
|
|
#else
|
|
|
|
|
|
|
|
//:TODO: fix shortcuts hebrew for non X11,
|
|
|
|
//see Bug 562195##51
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// before we dispatch a key, check if it's the context menu key.
|
|
|
|
// If so, send a context menu key event instead.
|
2008-04-20 01:16:40 -07:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
|
|
|
|
WidgetMouseEvent::eReal,
|
|
|
|
WidgetMouseEvent::eContextMenuKey);
|
2008-04-20 01:16:40 -07:00
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domCharCode = 0;
|
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
domCharCode = (int32_t) aEvent->text()[0].unicode();
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2013-04-23 20:49:48 -07:00
|
|
|
KeyNameIndex keyNameIndex =
|
|
|
|
domCharCode ? KEY_NAME_INDEX_PrintableKey :
|
|
|
|
QtKeyCodeToDOMKeyNameIndex(aEvent->key());
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
// If the key isn't autorepeat, we need to send the initial down event
|
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
// send the key down event
|
|
|
|
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
2010-04-22 05:58:46 -07:00
|
|
|
downEvent.keyCode = domKeyCode;
|
2013-04-23 20:49:48 -07:00
|
|
|
downEvent.mKeyNameIndex = keyNameIndex;
|
2014-05-24 19:09:00 -07:00
|
|
|
downEvent.mCodeNameIndex = codeNameIndex;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
2013-07-24 23:09:28 -07:00
|
|
|
// If prevent default on keydown, don't dispatch keypress event
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
2010-08-26 11:11:54 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
2013-04-23 20:49:48 -07:00
|
|
|
event.mKeyNameIndex = keyNameIndex;
|
2014-05-24 19:09:00 -07:00
|
|
|
event.mCodeNameIndex = codeNameIndex;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
2010-08-26 11:11:54 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::keyReleaseEvent(QKeyEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 10:37:16 -07:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
|
|
|
// er, what do we do here? DoDefault or NoDefault?
|
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2010-08-26 11:11:54 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
if (!domKeyCode) {
|
|
|
|
// get keymap from the Xserver
|
2014-02-20 18:09:02 -08:00
|
|
|
Display *display = gfxQtPlatform::GetXDisplay(mWidget);
|
2010-08-26 11:11:54 -07:00
|
|
|
int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
|
|
|
|
XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
|
|
|
|
KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
|
|
|
|
&xkeysyms_per_keycode);
|
|
|
|
|
|
|
|
if (aEvent->nativeScanCode() >= (quint32)x_min_keycode &&
|
|
|
|
aEvent->nativeScanCode() <= (quint32)x_max_keycode) {
|
|
|
|
int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
|
|
|
|
for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) {
|
|
|
|
domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xkeymap) {
|
|
|
|
XFree(xkeymap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_X11
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// send the key event as a key up event
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent event(true, NS_KEY_UP, this);
|
2008-04-19 08:37:51 -07:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
2011-01-26 01:01:01 -08:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = false;
|
|
|
|
}
|
|
|
|
|
2010-04-22 05:58:46 -07:00
|
|
|
event.keyCode = domKeyCode;
|
2013-04-23 20:49:48 -07:00
|
|
|
event.mKeyNameIndex =
|
|
|
|
(aEvent->text().length() && aEvent->text()[0].isPrint()) ?
|
|
|
|
KEY_NAME_INDEX_PrintableKey :
|
|
|
|
QtKeyCodeToDOMKeyNameIndex(aEvent->key());
|
2014-05-24 19:09:00 -07:00
|
|
|
event.mCodeNameIndex =
|
|
|
|
ScanCodeToDOMCodeNameIndex(aEvent->nativeScanCode());
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// unset the key down flag
|
|
|
|
ClearKeyDownFlag(event.keyCode);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::wheelEvent(QWheelEvent* aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
2013-10-16 02:37:36 -07:00
|
|
|
WidgetWheelEvent wheelEvent(true, NS_WHEEL_WHEEL, this);
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaMode = nsIDOMWheelEvent::DOM_DELTA_LINE;
|
|
|
|
|
|
|
|
// negative values for aEvent->delta indicate downward scrolling;
|
|
|
|
// this is opposite Gecko usage.
|
|
|
|
// TODO: Store the unused delta values due to fraction round and add it
|
|
|
|
// to next event. The stored values should be reset by other
|
|
|
|
// direction scroll event.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
switch (aEvent->orientation()) {
|
|
|
|
case Qt::Vertical:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaY = wheelEvent.lineOrPageDeltaY = delta;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
case Qt::Horizontal:
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.deltaX = wheelEvent.lineOrPageDeltaX = delta;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
wheelEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
wheelEvent.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
wheelEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aEvent->modifiers() & Qt::MetaModifier);
|
|
|
|
wheelEvent.time = 0;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2012-08-11 18:42:37 -07:00
|
|
|
return DispatchEvent(&wheelEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2014-02-20 18:09:02 -08:00
|
|
|
mVisible = true;
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::hideEvent(QHideEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2014-02-20 18:09:02 -08:00
|
|
|
mVisible = false;
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus nsWindow::touchEvent(QTouchEvent* aEvent)
|
2010-03-12 14:11:42 -08:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-10-08 23:08:42 -07:00
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::tabletEvent(QTabletEvent* aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2011-01-18 00:51:04 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// Helpers
|
2010-10-08 23:08:42 -07:00
|
|
|
|
|
|
|
nsEventStatus
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent)
|
2010-10-08 23:08:42 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(aEvent, status);
|
|
|
|
return status;
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
2010-03-12 14:11:42 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowActivated();
|
|
|
|
}
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
void
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowDeactivated();
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEventOnTopLevelWindow(void)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nullptr) {
|
|
|
|
topLevelWindow->DispatchActivateEvent();
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEventOnTopLevelWindow(void)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nullptr) {
|
|
|
|
topLevelWindow->DispatchDeactivateEvent();
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
if (mWidgetListener &&
|
|
|
|
mWidgetListener->WindowResized(this, aRect.width, aRect.height)) {
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
2008-04-19 08:43:56 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
///////////////////////////////////// OLD GECKO ECENTS need to Sort ///////////////////
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
/* static */ bool
|
|
|
|
isContextMenuKeyEvent(const QKeyEvent *qe)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
uint32_t kc = QtKeyCodeToDOMKeyCode(qe->key());
|
|
|
|
if (qe->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
bool isShift = qe->modifiers() & Qt::ShiftModifier;
|
|
|
|
return (kc == NS_VK_F10 && isShift) ||
|
|
|
|
(kc == NS_VK_CONTEXT_MENU && !isShift);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
/* static */void
|
|
|
|
InitKeyEvent(WidgetKeyboardEvent &aEvent, QKeyEvent *aQEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
aEvent.InitBasicModifiers(aQEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aQEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aQEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aQEvent->modifiers() & Qt::MetaModifier);
|
|
|
|
aEvent.mIsRepeat =
|
|
|
|
(aEvent.message == NS_KEY_DOWN || aEvent.message == NS_KEY_PRESS) &&
|
|
|
|
aQEvent->isAutoRepeat();
|
|
|
|
aEvent.time = 0;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (sAltGrModifier) {
|
|
|
|
aEvent.modifiers |= (MODIFIER_CONTROL | MODIFIER_ALT);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// The transformations above and in qt for the keyval are not invertible
|
|
|
|
// so link to the QKeyEvent (which will vanish soon after return from the
|
|
|
|
// event callback) to give plugins access to hardware_keycode and state.
|
|
|
|
// (An XEvent would be nice but the QKeyEvent is good enough.)
|
|
|
|
aEvent.pluginEvent = (void *)aQEvent;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsWindow, nsBaseWidget, nsISupportsWeakReference)
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-02-16 07:27:18 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::ClearCachedResources()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_BASIC) {
|
|
|
|
mLayerManager->ClearCachedResources();
|
|
|
|
}
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; ) {
|
|
|
|
nsIWidget* next = kid->GetNextSibling();
|
|
|
|
static_cast<nsWindow*>(kid)->ClearCachedResources();
|
|
|
|
kid = next;
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewParent);
|
2010-03-21 19:55:36 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
ReparentNativeWidget(aNewParent);
|
|
|
|
aNewParent->AddChild(this);
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetModal(bool aModal)
|
2010-08-31 09:35:57 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget));
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->setModality(aModal ? Qt::WindowModal : Qt::NonModal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2010-08-31 09:35:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
|
|
|
bool aActivate)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(int32_t aMode)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
|
|
|
if (aMode != nsSizeMode_Minimized) {
|
|
|
|
mWidget->requestActivate();
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08: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.
|
|
|
|
if (!mWidget || mSizeState == mSizeMode) {
|
|
|
|
return rv;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
|
|
|
mWidget->showMaximized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
mWidget->showMinimized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Fullscreen:
|
|
|
|
mWidget->showFullScreen();
|
|
|
|
break;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
|
|
|
mWidget->show();
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 06:54:27 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// Helper function to recursively find the first parent item that
|
|
|
|
// is still visible (QGraphicsItem can be hidden even if they are
|
|
|
|
// set to visible if one of their ancestors is invisible)
|
|
|
|
/* static */
|
|
|
|
void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(aItem);
|
2010-03-21 19:55:36 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
aVisibleItem = nullptr;
|
|
|
|
QWindow* parItem = nullptr;
|
|
|
|
while (!aVisibleItem) {
|
|
|
|
if (aItem->isVisible()) {
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parItem = aItem->parent();
|
|
|
|
if (parItem) {
|
|
|
|
aItem = parItem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aItem->setVisible(true);
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
aRect = nsIntRect(nsIntPoint(0, 0), mBounds.Size());
|
2010-05-14 11:13:36 -07:00
|
|
|
if (mIsTopLevel) {
|
2014-02-20 18:09:02 -08:00
|
|
|
QPoint pos = mWidget->position();
|
|
|
|
aRect.MoveTo(pos.x(), pos.y());
|
2010-05-14 11:13:36 -07:00
|
|
|
}
|
2011-02-02 22:31:43 -08:00
|
|
|
else {
|
2014-02-20 18:09:02 -08:00
|
|
|
aRect.MoveTo(WidgetToScreenOffset());
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
|
|
|
|
aRect.x, aRect.y,
|
|
|
|
mBounds.width, mBounds.height,
|
|
|
|
aRect.width, aRect.height));
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsCOMPtr<nsIFile> iconFile;
|
|
|
|
nsAutoCString path;
|
|
|
|
nsTArray<nsCString> iconList;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08: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.
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
|
|
|
|
".xpm", "16.xpm" };
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(extensions); i++) {
|
|
|
|
// Don't bother looking for XPM versions if we found a PNG.
|
|
|
|
if (i == ArrayLength(extensions) - 2 && iconList.Length())
|
|
|
|
break;
|
2010-03-05 23:25:46 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
|
|
|
iconList.AppendElement(path);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// leave the default icon intact if no matching icons were found
|
|
|
|
if (iconList.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return SetWindowIconList(iconList);
|
2009-03-27 04:35:27 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::CaptureMouse(bool aCapture)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2010-02-04 06:43:52 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->setMouseGrabEnabled(aCapture);
|
2010-03-25 17:33:31 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
bool
|
|
|
|
nsWindow::CheckForRollup(double aMouseX, double aMouseY,
|
|
|
|
bool aIsWheel)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
nsIRollupListener* rollupListener = GetActiveRollupListener();
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!rollupWidget) {
|
|
|
|
nsBaseWidget::gRollupListener = nullptr;
|
|
|
|
return false;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
bool retVal = false;
|
|
|
|
MozQWidget *currentPopup =
|
|
|
|
(MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
|
|
|
|
bool rollup = true;
|
|
|
|
if (aIsWheel) {
|
|
|
|
rollup = rollupListener->ShouldRollupOnMouseWheelEvent();
|
|
|
|
retVal = true;
|
|
|
|
}
|
|
|
|
// if we're dealing with menus, we probably have submenus and
|
|
|
|
// we don't want to rollup if the clickis in a parent menu of
|
|
|
|
// the current submenu
|
|
|
|
uint32_t popupsToRollup = UINT32_MAX;
|
|
|
|
if (rollupListener) {
|
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
|
|
|
uint32_t sameTypeCount = rollupListener->GetSubmenuWidgetChain(&widgetChain);
|
|
|
|
for (uint32_t i=0; i<widgetChain.Length(); ++i) {
|
|
|
|
nsIWidget* widget = widgetChain[i];
|
|
|
|
MozQWidget* currWindow =
|
|
|
|
(MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
|
|
|
|
if (i < sameTypeCount) {
|
|
|
|
rollup = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // foreach parent menu widget
|
|
|
|
} // if rollup listener knows about menus
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
|
|
|
nsIntPoint pos(aMouseX, aMouseY);
|
|
|
|
retVal = rollupListener->Rollup(popupsToRollup, &pos, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return retVal;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2014-02-20 18:09:02 -08:00
|
|
|
bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return aWindow->geometry().contains(aMouseX, aMouseY);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetAttention(int32_t aCycleCount)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::OnCloseEvent(QCloseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidgetListener)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
mWidgetListener->RequestWindowClose(this);
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
inline bool
|
|
|
|
is_latin_shortcut_key(quint32 aKeyval)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return ((Qt::Key_0 <= aKeyval && aKeyval <= Qt::Key_9) ||
|
|
|
|
(Qt::Key_A <= aKeyval && aKeyval <= Qt::Key_Z));
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this);
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return status;
|
2012-04-11 21:18:35 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchContentCommandEvent(int32_t aMsg)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
WidgetContentCommandEvent event(true, aMsg, this);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2011-02-02 22:31:36 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return status;
|
|
|
|
}
|
2011-02-02 22:31:43 -08:00
|
|
|
|
2011-08-28 11:09:56 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2011-01-04 07:37:27 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
if (bundleService) {
|
|
|
|
bundleService->CreateBundle(
|
|
|
|
"chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
2011-02-02 22:31:43 -08:00
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (bundle) {
|
|
|
|
bundle->GetStringFromName(
|
|
|
|
MOZ_UTF16("brandShortName"),
|
|
|
|
getter_Copies(brandName));
|
2008-04-20 01:16:40 -07:00
|
|
|
}
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (brandName.IsEmpty()) {
|
2014-05-26 11:54:10 -07:00
|
|
|
brandName.AssignLiteral(MOZ_UTF16("Mozilla"));
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mWidget) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
2011-09-22 02:17:40 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
XClassHint *class_hint = XAllocClassHint();
|
|
|
|
if (!class_hint) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2011-09-22 02:17:40 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
const char *role = nullptr;
|
|
|
|
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;
|
2010-08-13 02:57:55 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// 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;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
QWindow *widget = mWidget;
|
|
|
|
// If widget not show, handle might be null
|
|
|
|
if (widget && widget->winId()) {
|
|
|
|
XSetClassHint(gfxQtPlatform::GetXDisplay(widget),
|
|
|
|
widget->winId(),
|
|
|
|
class_hint);
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsMemory::Free(class_hint->res_class);
|
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
|
|
|
#endif
|
2010-07-28 18:05:56 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return NS_OK;
|
2010-07-28 18:05:56 -07:00
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
void
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::NativeResize(int32_t aWidth, int32_t aHeight, bool aRepaint)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mNeedsResize = false;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->resize(aWidth, aHeight);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aRepaint) {
|
|
|
|
mWidget->renderLater();
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::NativeResize(int32_t aX, int32_t aY,
|
|
|
|
int32_t aWidth, int32_t aHeight,
|
|
|
|
bool aRepaint)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aX, aY, aWidth, aHeight));
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
2011-05-02 01:16:22 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (aRepaint) {
|
|
|
|
mWidget->renderLater();
|
2011-05-02 01:16:22 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2011-05-02 01:16:22 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::NativeShow(bool aAction)
|
|
|
|
{
|
|
|
|
if (aAction) {
|
|
|
|
// 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
|
|
|
|
mWidget->show();
|
|
|
|
// unset our flag now that our window has been shown
|
|
|
|
mNeedsShow = false;
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
else {
|
|
|
|
mWidget->hide();
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetHasTransparentBackground(bool aTransparent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-20 18:09:02 -08:00
|
|
|
nsWindow::GetHasTransparentBackground(bool& aTransparent)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
aTransparent = mIsTransparent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("Not implemented");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsresult
|
|
|
|
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
|
|
|
|
{
|
|
|
|
QIcon icon;
|
2010-03-21 19:55:36 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
for (uint32_t 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-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mWidget->setIcon(icon);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void nsWindow::QWidgetDestroyed()
|
|
|
|
{
|
|
|
|
mWidget = nullptr;
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::HideWindowChrome(bool aShouldHide)
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
// Nothing to hide
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-21 19:55:36 -07:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
// Sawfish, metacity, and presumably other window managers get
|
|
|
|
// confused if we change the window decorations while the window
|
|
|
|
// is visible.
|
|
|
|
bool wasVisible = false;
|
|
|
|
if (mWidget->isVisible()) {
|
|
|
|
NativeShow(false);
|
|
|
|
wasVisible = true;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (wasVisible) {
|
|
|
|
NativeShow(true);
|
|
|
|
}
|
2008-04-22 04:21:18 -07:00
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
nsWindow::HasGLContext()
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return false;
|
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
|
|
|
|
nsIWidget*
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return qApp->primaryScreen()->logicalDotsPerInch();
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mOnDestroyCalled) {
|
2008-04-22 04:21:17 -07:00
|
|
|
return;
|
2014-02-20 18:09:02 -08:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mOnDestroyCalled = true;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
// release references to children and device context
|
2008-04-22 04:21:17 -07:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// let go of our parent
|
2012-07-30 07:20:58 -07:00
|
|
|
mParent = nullptr;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
2012-08-15 11:52:41 -07:00
|
|
|
NotifyWindowDestroyed();
|
2008-04-22 04:21:17 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-04-22 04:21:17 -07:00
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (mBounds.width > 0 && mBounds.height > 0) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-12 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return false;
|
2010-03-12 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
2011-09-07 08:06:35 -07:00
|
|
|
void
|
2011-11-27 03:51:52 -08:00
|
|
|
nsWindow::SetSoftwareKeyboardState(bool aOpen,
|
|
|
|
const InputContextAction& aAction)
|
2011-09-07 08:06:35 -07:00
|
|
|
{
|
|
|
|
if (aOpen) {
|
2012-12-23 20:45:57 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(mInputContext.mIMEState.mEnabled !=
|
|
|
|
IMEState::DISABLED);
|
2011-09-07 08:06:35 -07:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 03:51:52 -08:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 03:51:53 -08:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 03:51:52 -08:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 03:51:53 -08:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 03:51:52 -08:00
|
|
|
return;
|
2011-09-07 08:06:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOpen) {
|
2014-02-20 18:09:02 -08:00
|
|
|
qApp->inputMethod()->show();
|
2011-09-07 08:06:35 -07:00
|
|
|
} else {
|
2014-02-20 18:09:02 -08:00
|
|
|
qApp->inputMethod()->hide();
|
2011-09-07 08:06:35 -07:00
|
|
|
}
|
2010-04-16 10:37:16 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return;
|
2010-04-16 10:37:16 -07:00
|
|
|
}
|
2012-02-22 11:16:15 -08:00
|
|
|
|
|
|
|
|
2013-10-22 06:27:35 -07:00
|
|
|
void
|
|
|
|
nsWindow::ProcessMotionEvent()
|
|
|
|
{
|
|
|
|
if (mMoveEvent.needDispatch) {
|
|
|
|
WidgetMouseEvent event(true, NS_MOUSE_MOVE, this,
|
|
|
|
WidgetMouseEvent::eReal);
|
|
|
|
|
|
|
|
event.refPoint.x = nscoord(mMoveEvent.pos.x());
|
|
|
|
event.refPoint.y = nscoord(mMoveEvent.pos.y());
|
|
|
|
|
|
|
|
event.InitBasicModifiers(mMoveEvent.modifiers & Qt::ControlModifier,
|
|
|
|
mMoveEvent.modifiers & Qt::AltModifier,
|
|
|
|
mMoveEvent.modifiers & Qt::ShiftModifier,
|
|
|
|
mMoveEvent.modifiers & Qt::MetaModifier);
|
|
|
|
event.clickCount = 0;
|
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
mMoveEvent.needDispatch = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimerStarted = false;
|
|
|
|
}
|
|
|
|
|