2010-03-03 20:45:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-04-19 19:37:51 +04:00
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04: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 19:37:51 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <QGuiApplication>
|
2010-03-05 00:51:42 +03:00
|
|
|
#include <QtGui/QCursor>
|
2012-03-23 03:24:40 +04:00
|
|
|
#include <QIcon>
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QResizeEvent>
|
2010-04-14 03:11:23 +04:00
|
|
|
#include <QPaintEngine>
|
2012-03-23 03:24:40 +04:00
|
|
|
#include <QMimeData>
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <QScreen>
|
2010-03-05 00:51:42 +03:00
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
#include <QtCore/QVariant>
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-03-05 00:51:42 +03:00
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <X11/Xlib.h>
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <X11/Xutil.h>
|
2014-05-29 23:55:44 +04:00
|
|
|
#include "gfxXlibSurface.h"
|
2010-08-26 22:11:54 +04:00
|
|
|
#endif //MOZ_X11
|
|
|
|
|
2010-03-18 19:44:33 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
#include "prlink.h"
|
|
|
|
|
2008-04-19 19:31:50 +04:00
|
|
|
#include "nsWindow.h"
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "mozqwidget.h"
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
#include "nsIdleService.h"
|
2008-04-19 19:37:51 +04:00
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsQtKeyUtils.h"
|
2010-05-14 13:24:41 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-06-07 11:38:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-10-26 17:32:10 +04: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 13:20:52 +04:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsIWidgetListener.h"
|
2014-02-21 06:09:02 +04:00
|
|
|
#include "ClientLayerManager.h"
|
|
|
|
#include "BasicLayers.h"
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
#include "gfxQtPlatform.h"
|
2009-03-27 14:35:27 +03:00
|
|
|
|
2012-08-12 05:42:37 +04:00
|
|
|
#include "nsIDOMWheelEvent.h"
|
2010-03-13 01:11:42 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "keysym2ucs.h"
|
2011-09-07 19:06:35 +04:00
|
|
|
#endif
|
2010-08-26 22:11:54 +04:00
|
|
|
|
2010-06-24 14:07:57 +04:00
|
|
|
#include "Layers.h"
|
2012-11-04 08:00:08 +04:00
|
|
|
#include "GLContextProvider.h"
|
2010-10-27 08:56:31 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-21 06:09:02 +04:00
|
|
|
using namespace mozilla::gl;
|
2011-11-27 15:51:52 +04:00
|
|
|
using namespace mozilla::widget;
|
2014-02-21 06:09:02 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::layers;
|
2012-11-04 08:00:08 +04:00
|
|
|
using mozilla::gl::GLContext;
|
2010-10-27 08:56:31 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// Qt
|
2008-04-19 19:37:51 +04:00
|
|
|
static const int WHEEL_DELTA = 120;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gGlobalsInitialized = false;
|
2011-01-26 12:01:01 +03:00
|
|
|
static bool sAltGrModifier = false;
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
static void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem);
|
|
|
|
static bool is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2015-02-18 09:27:53 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTopLevel = false;
|
|
|
|
mIsDestroyed = false;
|
|
|
|
mIsShown = false;
|
|
|
|
mEnabled = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mWidget = nullptr;
|
2014-02-21 06:09:02 +04:00
|
|
|
mVisible = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
mActivatePending = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
2010-05-30 22:35:07 +04:00
|
|
|
mLastSizeMode = nsSizeMode_Normal;
|
2008-04-19 19:37:51 +04:00
|
|
|
mQCursor = Qt::ArrowCursor;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
|
|
|
mListenForResizes = false;
|
|
|
|
mNeedsShow = false;
|
|
|
|
mTimerStarted = false;
|
2011-01-18 11:51:04 +03:00
|
|
|
mMoveEvent.needDispatch = false;
|
2014-02-21 06:09:02 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
if (!gGlobalsInitialized) {
|
2012-03-22 03:14:09 +04:00
|
|
|
gfxPlatform::GetPlatform();
|
2011-10-17 18:59:28 +04:00
|
|
|
gGlobalsInitialized = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTransparent = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
mCursor = eCursor_standard;
|
2010-02-20 06:46:54 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::~nsWindow()
|
2010-02-20 06:46:54 +03:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
Destroy();
|
2010-04-14 03:11:23 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsresult
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
nsWidgetInitData *aInitData)
|
2010-02-20 06:46:54 +03:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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
|
2015-02-05 08:18:30 +03:00
|
|
|
BaseCreate(baseParent, aRect, aInitData);
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mVisible = true;
|
|
|
|
|
|
|
|
// and do our common creation
|
|
|
|
mParent = (nsWindow *)aParent;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// find native parent
|
|
|
|
MozQWidget *parent = nullptr;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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-27 08:56:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("Create: nsWindow [%p] mWidget:[%p] parent:[%p], natPar:[%p] mParent:%p\n", (void *)this, (void*)mWidget, parent, aNativeParent, mParent));
|
2010-10-27 08:56:31 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// ok, create our QGraphicsWidget
|
|
|
|
mWidget = createQWidget(parent, aInitData);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// resize so that everything is set to the right dimensions
|
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// check if we should listen for resizes
|
|
|
|
mListenForResizes = (aNativeParent ||
|
|
|
|
(aInitData && aInitData->mListenForResizes));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MozQWidget*
|
|
|
|
nsWindow::createQWidget(MozQWidget* parent,
|
|
|
|
nsWidgetInitData* aInitData)
|
2009-08-05 06:39:05 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
const char *windowName = nullptr;
|
|
|
|
Qt::WindowFlags flags = Qt::Widget;
|
2009-08-05 06:39:05 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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-05 06:39:05 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
MozQWidget* widget = new MozQWidget(this, parent);
|
|
|
|
if (!widget) {
|
|
|
|
return nullptr;
|
2009-08-05 06:39:05 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
|
|
|
|
widget->setObjectName(QString(windowName));
|
|
|
|
if (mWindowType == eWindowType_invisible) {
|
2014-05-17 03:33:53 +04:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
|
2014-02-21 06:09:02 +04:00
|
|
|
widget->setVisibility(QWindow::Hidden);
|
2014-05-17 03:33:53 +04:00
|
|
|
#else
|
|
|
|
widget->hide();
|
|
|
|
#endif
|
2014-02-21 06:09:02 +04: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-05 06:39:05 +04:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mIsDestroyed || !mWidget) {
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDestroyed = true;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2012-11-04 08:00:08 +04:00
|
|
|
/** Need to clean our LayerManager up while still alive */
|
2010-09-10 03:41:02 +04:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mLayerManager = nullptr;
|
2010-09-10 03:41:02 +04:00
|
|
|
|
2012-11-04 08:00:08 +04: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 21:27:04 +04:00
|
|
|
if (rollupListener) {
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = rollupListener->GetRollupWidget();
|
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget) {
|
2015-01-08 04:52:20 +03:00
|
|
|
rollupListener->Rollup(0, false, nullptr, nullptr);
|
2012-12-31 21:27:04 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-04 08:00:08 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
Show(false);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// walk the list of children and call destroy on them. Have to be
|
|
|
|
// careful, though -- calling destroy on a kid may actually remove
|
|
|
|
// it from our child list, losing its sibling links.
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; ) {
|
|
|
|
nsIWidget* next = kid->GetNextSibling();
|
|
|
|
kid->Destroy();
|
|
|
|
kid = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy thebes surface now. Badness can happen if we destroy
|
|
|
|
// the surface after its X Window.
|
2009-07-15 16:20:21 +04:00
|
|
|
if (mWidget) {
|
|
|
|
mWidget->dropReceiver();
|
2008-04-20 12:16:40 +04:00
|
|
|
|
|
|
|
// Call deleteLater instead of delete; Qt still needs the object
|
|
|
|
// to be valid even after sending it a Close event. We could
|
|
|
|
// also set WA_DeleteOnClose, but this gives us more control.
|
2009-07-15 16:20:21 +04:00
|
|
|
mWidget->deleteLater();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mWidget = nullptr;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
OnDestroy();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Show(bool aState)
|
2012-11-04 08:00:08 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
|
|
|
if (aState == mIsShown) {
|
|
|
|
return NS_OK;
|
2012-11-04 08:00:08 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// Clear our cached resources when the window is hidden.
|
|
|
|
if (mIsShown && !aState) {
|
|
|
|
ClearCachedResources();
|
2010-09-18 15:28:50 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mIsShown = aState;
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 15:28:50 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
bool
|
|
|
|
nsWindow::IsVisible() const
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2012-07-19 12:57:50 +04:00
|
|
|
return mIsShown;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 13:57:38 +04:00
|
|
|
nsWindow::Move(double aX, double aY)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2012-12-12 13:57:38 +04:00
|
|
|
LOG(("nsWindow::Move [%p] %f %f\n", (void *)this,
|
2008-04-19 19:37:51 +04:00
|
|
|
aX, aY));
|
|
|
|
|
2012-12-12 13:57:38 +04:00
|
|
|
int32_t x = NSToIntRound(aX);
|
|
|
|
int32_t y = NSToIntRound(aY);
|
|
|
|
|
2010-03-17 09:32:38 +03:00
|
|
|
if (mIsTopLevel) {
|
2009-11-02 22:10:07 +03:00
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (x == mBounds.x && y == mBounds.y) {
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsMove = false;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-02-16 21:14:20 +03:00
|
|
|
// update the bounds
|
2014-02-21 06:09:02 +04:00
|
|
|
QPoint pos(x, y);
|
2011-02-03 09:31:43 +03:00
|
|
|
if (mIsTopLevel) {
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->setPosition(x, y);
|
2011-02-03 09:31:43 +03:00
|
|
|
}
|
|
|
|
else if (mWidget) {
|
2010-02-16 21:14:20 +03:00
|
|
|
// the position of the widget is set relative to the parent
|
|
|
|
// so we map the coordinates accordingly
|
2014-02-21 06:09:02 +04:00
|
|
|
pos = mWidget->mapToGlobal(pos);
|
|
|
|
mWidget->setPosition(pos);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = pos.x();
|
|
|
|
mBounds.y = pos.y();
|
|
|
|
|
2012-10-26 17:15:22 +04:00
|
|
|
NotifyRollupGeometryChange();
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// synthesize a resize event if this isn't a toplevel
|
|
|
|
if (mIsTopLevel || mListenForResizes) {
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(mBounds, status);
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NotifyRollupGeometryChange();
|
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
|
|
|
|
bool aRepaint)
|
2010-02-16 21:14:20 +03:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
mBounds.x = NSToIntRound(aX);
|
|
|
|
mBounds.y = NSToIntRound(aY);
|
|
|
|
mBounds.width = NSToIntRound(aWidth);
|
|
|
|
mBounds.height = NSToIntRound(aHeight);
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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-26 03:33:31 +03:00
|
|
|
else {
|
2014-02-21 06:09:02 +04: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-26 03:33:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 06:09:02 +04: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 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsWindow::SetFocus(bool aRaise)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
// Make sure that our owning widget has focus. If it doesn't try to
|
|
|
|
// grab it. Note that we don't set our focus flag in this case.
|
|
|
|
LOGFOCUS((" SetFocus [%p]\n", (void *)this));
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mWidget->focusObject()) {
|
2010-03-26 03:33:31 +03:00
|
|
|
return NS_OK;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2010-03-26 03:33:31 +03:00
|
|
|
|
|
|
|
// Because QGraphicsItem cannot get the focus if they are
|
2010-02-16 21:14:20 +03:00
|
|
|
// invisible, we look up the chain, for the lowest visible
|
|
|
|
// parent and focus that one
|
2014-02-21 06:09:02 +04:00
|
|
|
QWindow* realFocusItem = nullptr;
|
2010-02-16 21:14:20 +03:00
|
|
|
find_first_visible_parent(mWidget, realFocusItem);
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!realFocusItem || realFocusItem->focusObject()) {
|
2009-07-15 16:20:21 +04:00
|
|
|
return NS_OK;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (aRaise && mWidget) {
|
2010-02-25 21:58:19 +03:00
|
|
|
// the raising has to happen on the view widget
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->raise();
|
2010-02-25 21:58:19 +03:00
|
|
|
}
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
// XXXndeakin why is this here? It should dispatch only when the OS
|
|
|
|
// notifies us.
|
2010-02-16 21:14:20 +03:00
|
|
|
DispatchActivateEvent();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
2010-12-29 19:22:26 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-24 07:52:21 +04:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2011-12-24 07:52:21 +04:00
|
|
|
LOGDRAW(("Invalidate (rect) [%p,%p]: %d %d %d %d\n", (void *)this,
|
|
|
|
(void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->renderLater();
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::WidgetToScreenOffset()
|
2010-02-16 21:14:20 +03:00
|
|
|
{
|
2015-05-19 04:13:56 +03:00
|
|
|
NS_ENSURE_TRUE(mWidget, LayoutDeviceIntPoint(0,0));
|
2014-02-21 06:09:02 +04:00
|
|
|
|
|
|
|
QPoint origin(0, 0);
|
|
|
|
origin = mWidget->mapToGlobal(origin);
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
return LayoutDeviceIntPoint(origin.x(), origin.y());
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
void*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWindow::GetNativeData(uint32_t aDataType)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-15 16:20:21 +04:00
|
|
|
return mWidget;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW: {
|
|
|
|
return mWidget ? (void*)mWidget->winId() : nullptr;
|
|
|
|
}
|
|
|
|
case NS_NATIVE_DISPLAY: {
|
2011-08-24 20:15:58 +04:00
|
|
|
#ifdef MOZ_X11
|
2014-02-21 06:09:02 +04:00
|
|
|
return gfxQtPlatform::GetXDisplay(mWidget);
|
2011-08-24 20:15:58 +04:00
|
|
|
#endif
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
2010-06-24 14:07:57 +04:00
|
|
|
case NS_NATIVE_SHELLWIDGET: {
|
2014-02-21 06:09:02 +04:00
|
|
|
break;
|
2011-08-31 23:01:38 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("nsWindow::%s [%p] aDataType:%i\n", __FUNCTION__, (void *)this, aDataType));
|
|
|
|
return nullptr;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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-15 09:08:15 +03:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(mWidget);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// SetSoftwareKeyboardState uses mInputContext,
|
|
|
|
// so, before calling that, record aContext in mInputContext.
|
|
|
|
mInputContext = aContext;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return mInputContext;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2010-03-06 10:25:46 +03:00
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-07-09 23:29:28 +04:00
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen, nsIScreen*)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (aFullScreen) {
|
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen) {
|
|
|
|
mLastSizeMode = mSizeMode;
|
|
|
|
}
|
2010-03-15 09:08:15 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
|
|
|
mWidget->showFullScreen();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
2010-03-15 09:08:15 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
|
|
|
return nsBaseWidget::MakeFullScreen(aFullScreen);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
LayerManager*
|
|
|
|
nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mLayerManager && eTransparencyTransparent == GetTransparencyMode()) {
|
|
|
|
mLayerManager = CreateBasicLayerManager();
|
|
|
|
}
|
2008-08-16 11:07:21 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return nsBaseWidget::GetLayerManager(aShadowManager, aBackendHint,
|
|
|
|
aPersistence, aAllowRetaining);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
2008-08-16 11:07:21 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
2012-12-31 21:27:04 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mIdleService) {
|
|
|
|
mIdleService->ResetIdleTimeOut(0);
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
uint32_t
|
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
2008-08-16 11:07:21 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) {
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
}
|
|
|
|
return LOCAL_GL_NONE;
|
2008-08-16 11:07:21 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2014-05-29 23:55:44 +04:00
|
|
|
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 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::SetCursor(nsCursor aCursor)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-05-28 05:12:29 +04:00
|
|
|
if (mCursor == aCursor && !mUpdateCursor) {
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
2011-10-28 16:13:57 +04:00
|
|
|
}
|
2014-05-28 05:12:29 +04:00
|
|
|
mUpdateCursor = false;
|
2014-02-21 06:09:02 +04:00
|
|
|
mCursor = aCursor;
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->SetCursor(mCursor);
|
2010-02-20 06:46:54 +03:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
QString qStr(QString::fromUtf16((const ushort*)aTitle.BeginReading(), aTitle.Length()));
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->setTitle(qStr);
|
2008-04-19 19:43:23 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-03-16 07:41:53 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// EVENTS
|
2010-03-11 01:13:02 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::OnPaint()
|
|
|
|
{
|
|
|
|
LOGDRAW(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
nsIWidgetListener* listener =
|
|
|
|
mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener;
|
|
|
|
if (!listener) {
|
|
|
|
return;
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
listener->WillPaintWindow(this);
|
2008-04-19 19:43:23 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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-27 08:56:31 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid layer manager");
|
2010-02-25 23:45:37 +03:00
|
|
|
}
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
listener->DidPaintWindow();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::moveEvent(QMoveEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOG(("configure event [%p] %d %d\n", (void *)this,
|
|
|
|
aEvent->pos().x(), aEvent->pos().y()));
|
|
|
|
|
|
|
|
// can we shortcut?
|
2012-08-15 22:52:42 +04:00
|
|
|
if (!mWidget || !mWidgetListener)
|
2008-04-22 15:21:18 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if ((mBounds.x == aEvent->pos().x() &&
|
|
|
|
mBounds.y == aEvent->pos().y()))
|
2008-04-20 12:16:40 +04:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-28 11:45:08 +04:00
|
|
|
NotifyWindowMoved(aEvent->pos().x(), aEvent->pos().y());
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::resizeEvent(QResizeEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2009-02-11 16:51:06 +03:00
|
|
|
nsIntRect rect;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
// Generate XPFE resize event
|
|
|
|
GetBounds(rect);
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
rect.width = aEvent->size().width();
|
|
|
|
rect.height = aEvent->size().height();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::mouseMoveEvent(QMouseEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-10-09 10:08:42 +04:00
|
|
|
UserActivity();
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mMoveEvent.pos = aEvent->pos();
|
|
|
|
mMoveEvent.modifiers = aEvent->modifiers();
|
2011-01-18 11:51:04 +03:00
|
|
|
mMoveEvent.needDispatch = true;
|
|
|
|
DispatchMotionToMainThread();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2011-01-18 11:51:04 +03:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-05-26 20:25:40 +04: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 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::mousePressEvent(QMouseEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
QPoint pos = aEvent->pos();
|
2010-02-16 21:14:20 +03:00
|
|
|
|
|
|
|
// we check against the widgets geometry, so use parent coordinates
|
|
|
|
// for the check
|
|
|
|
if (mWidget)
|
2014-02-21 06:09:02 +04:00
|
|
|
pos = mWidget->mapToGlobal(pos);
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-05-26 20:25:40 +04:00
|
|
|
if (CheckForRollup(pos.x(), pos.y(), false))
|
2008-08-16 11:07:21 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2014-05-26 20:25:40 +04: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 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:30 +03:00
|
|
|
WidgetMouseEvent event(true, eMouseDown, this, WidgetMouseEvent::eReal);
|
2014-05-26 20:25:40 +04:00
|
|
|
InitMouseEvent(event, aEvent, 1);
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-05-26 20:25:40 +04:00
|
|
|
// Right click on linux should also pop up a context menu.
|
|
|
|
if (event.button == WidgetMouseEvent::eRightButton &&
|
2012-10-26 17:32:10 +04:00
|
|
|
MOZ_LIKELY(!mIsDestroyed)) {
|
2015-08-31 18:20:06 +03:00
|
|
|
WidgetMouseEvent contextMenuEvent(true, eContextMenu, this,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 20:25:40 +04:00
|
|
|
InitMouseEvent(contextMenuEvent, aEvent, 1);
|
2008-04-19 19:37:51 +04:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return status;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::mouseReleaseEvent(QMouseEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2014-05-26 20:25:40 +04:00
|
|
|
if (!IsAcceptedButton(aEvent->button()))
|
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-20 12:37:07 +04:00
|
|
|
|
2015-08-29 02:58:30 +03:00
|
|
|
WidgetMouseEvent event(true, eMouseUp, this, WidgetMouseEvent::eReal);
|
2014-05-26 20:25:40 +04:00
|
|
|
InitMouseEvent(event, aEvent, 1);
|
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::mouseDoubleClickEvent(QMouseEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-05-26 20:25:40 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-05-26 20:25:40 +04:00
|
|
|
if (!IsAcceptedButton(aEvent->button()))
|
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2015-08-29 02:58:31 +03:00
|
|
|
WidgetMouseEvent event(true, eMouseDoubleClick, this,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal);
|
2014-05-26 20:25:40 +04:00
|
|
|
InitMouseEvent(event, aEvent, 2);
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::focusInEvent(QFocusEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this));
|
2010-07-29 05:05:56 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2010-07-29 05:05:56 +04:00
|
|
|
DispatchActivateEventOnTopLevelWindow();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::focusOutEvent(QFocusEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2008-04-22 15:21:18 +04:00
|
|
|
LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this));
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
2010-07-29 05:05:56 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2010-07-29 05:05:56 +04:00
|
|
|
|
|
|
|
DispatchDeactivateEventOnTopLevelWindow();
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-07-22 20:59:48 +04:00
|
|
|
static bool
|
|
|
|
IsContextMenuKeyEvent(const QKeyEvent* aQEvent)
|
|
|
|
{
|
|
|
|
if (aQEvent->modifiers() & (Qt::ControlModifier |
|
|
|
|
Qt::AltModifier |
|
|
|
|
Qt::MetaModifier)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isShift = aQEvent->modifiers() & Qt::ShiftModifier;
|
|
|
|
uint32_t keyCode = QtKeyCodeToDOMKeyCode(aQEvent->key());
|
|
|
|
return (keyCode == NS_VK_F10 && isShift) ||
|
|
|
|
(keyCode == NS_VK_CONTEXT_MENU && !isShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitKeyEvent(WidgetKeyboardEvent& aEvent, QKeyEvent* aQEvent)
|
|
|
|
{
|
|
|
|
aEvent.InitBasicModifiers(aQEvent->modifiers() & Qt::ControlModifier,
|
|
|
|
aQEvent->modifiers() & Qt::AltModifier,
|
|
|
|
aQEvent->modifiers() & Qt::ShiftModifier,
|
|
|
|
aQEvent->modifiers() & Qt::MetaModifier);
|
|
|
|
|
|
|
|
aEvent.mIsRepeat =
|
2015-08-29 02:58:27 +03:00
|
|
|
(aEvent.mMessage == eKeyDown || aEvent.mMessage == eKeyPress) &&
|
2014-07-22 20:59:48 +04:00
|
|
|
aQEvent->isAutoRepeat();
|
|
|
|
aEvent.time = 0;
|
|
|
|
|
|
|
|
if (sAltGrModifier) {
|
|
|
|
aEvent.modifiers |= (MODIFIER_CONTROL | MODIFIER_ALT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aQEvent->text().length() && aQEvent->text()[0].isPrint()) {
|
|
|
|
aEvent.charCode = (int32_t) aQEvent->text()[0].unicode();
|
|
|
|
aEvent.keyCode = 0;
|
|
|
|
aEvent.mKeyNameIndex = KEY_NAME_INDEX_PrintableKey;
|
|
|
|
} else {
|
|
|
|
aEvent.charCode = 0;
|
|
|
|
aEvent.keyCode = QtKeyCodeToDOMKeyCode(aQEvent->key());
|
|
|
|
aEvent.mKeyNameIndex = QtKeyCodeToDOMKeyNameIndex(aQEvent->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.mCodeNameIndex = ScanCodeToDOMCodeNameIndex(aQEvent->nativeScanCode());
|
|
|
|
|
|
|
|
// 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.)
|
2014-07-23 23:55:51 +04:00
|
|
|
aEvent.mPluginEvent.Copy(*aQEvent);
|
2014-07-22 20:59:48 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::keyPressEvent(QKeyEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = true;
|
|
|
|
}
|
|
|
|
|
2014-07-22 20:59:48 +04:00
|
|
|
// Before we dispatch a key, check if it's the context menu key.
|
2010-08-26 22:11:54 +04:00
|
|
|
// If so, send a context menu key event instead.
|
2014-07-22 20:59:48 +04:00
|
|
|
if (IsContextMenuKeyEvent(aEvent)) {
|
2015-08-31 18:20:06 +03:00
|
|
|
WidgetMouseEvent contextMenuEvent(true, eContextMenu, this,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal,
|
|
|
|
WidgetMouseEvent::eContextMenuKey);
|
2010-08-26 22:11:54 +04:00
|
|
|
return DispatchEvent(&contextMenuEvent);
|
|
|
|
}
|
|
|
|
|
2014-07-22 20:59:48 +04:00
|
|
|
//:TODO: fix shortcuts hebrew for non X11,
|
|
|
|
//see Bug 562195##51
|
2010-08-26 22:11:54 +04:00
|
|
|
|
2014-07-22 20:59:48 +04:00
|
|
|
uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
2013-04-24 07:49:48 +04:00
|
|
|
|
2010-08-26 22:11:54 +04:00
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
|
|
|
|
2015-08-29 02:58:27 +03:00
|
|
|
WidgetKeyboardEvent downEvent(true, eKeyDown, this);
|
2010-08-26 22:11:54 +04:00
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273)
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(mIsDestroyed)) {
|
2010-08-26 22:11:54 +04:00
|
|
|
qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed";
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:28 +04:00
|
|
|
// If prevent default on keydown, don't dispatch keypress event
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
2010-08-26 22:11:54 +04:00
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:27 +03:00
|
|
|
// Don't pass modifiers as eKeyPress events.
|
|
|
|
// Instead of selectively excluding some keys from eKeyPress events,
|
2010-08-26 22:11:54 +04:00
|
|
|
// 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-25 10:09:28 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2010-08-26 22:11:54 +04:00
|
|
|
}
|
|
|
|
|
2011-07-14 05:58:07 +04:00
|
|
|
// Look for specialized app-command keys
|
|
|
|
switch (aEvent->key()) {
|
|
|
|
case Qt::Key_Back:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Back);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Forward:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Forward);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Refresh:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Reload);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Stop:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Stop);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Search:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Search);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Favorites:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Bookmarks);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_HomePage:
|
2011-10-14 22:11:22 +04:00
|
|
|
return DispatchCommandEvent(nsGkAtoms::Home);
|
2011-07-14 05:58:07 +04:00
|
|
|
case Qt::Key_Copy:
|
|
|
|
case Qt::Key_F16: // F16, F20, F18, F14 are old keysyms for Copy Cut Paste Undo
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_COPY);
|
|
|
|
case Qt::Key_Cut:
|
|
|
|
case Qt::Key_F20:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_CUT);
|
|
|
|
case Qt::Key_Paste:
|
|
|
|
case Qt::Key_F18:
|
|
|
|
case Qt::Key_F9:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_PASTE);
|
|
|
|
case Qt::Key_F14:
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Qt::Key_Redo and Qt::Key_Undo are not available yet.
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff66) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
|
|
|
|
}
|
|
|
|
if (aEvent->nativeVirtualKey() == 0xff65) {
|
|
|
|
return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
|
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:27 +03:00
|
|
|
WidgetKeyboardEvent event(true, eKeyPress, this);
|
2010-08-26 22:11:54 +04:00
|
|
|
InitKeyEvent(event, aEvent);
|
2014-07-22 20:59:48 +04:00
|
|
|
// Seend the key press event
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::keyReleaseEvent(QKeyEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
// The user has done something.
|
|
|
|
UserActivity();
|
|
|
|
|
2014-07-22 20:59:48 +04:00
|
|
|
if (IsContextMenuKeyEvent(aEvent)) {
|
2008-04-20 12:16:40 +04:00
|
|
|
// er, what do we do here? DoDefault or NoDefault?
|
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
// send the key event as a key up event
|
2015-08-29 02:58:27 +03:00
|
|
|
WidgetKeyboardEvent event(true, eKeyUp, this);
|
2008-04-19 19:37:51 +04:00
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
2011-01-26 12:01:01 +03:00
|
|
|
if (aEvent->key() == Qt::Key_AltGr) {
|
|
|
|
sAltGrModifier = false;
|
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
// unset the key down flag
|
|
|
|
ClearKeyDownFlag(event.keyCode);
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::wheelEvent(QWheelEvent* aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
2013-10-16 13:37:36 +04:00
|
|
|
WidgetWheelEvent wheelEvent(true, NS_WHEEL_WHEEL, this);
|
2012-08-12 05:42:37 +04: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 19:56:38 +04:00
|
|
|
int32_t delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
|
|
|
switch (aEvent->orientation()) {
|
|
|
|
case Qt::Vertical:
|
2012-08-12 05:42:37 +04:00
|
|
|
wheelEvent.deltaY = wheelEvent.lineOrPageDeltaY = delta;
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
case Qt::Horizontal:
|
2012-08-12 05:42:37 +04:00
|
|
|
wheelEvent.deltaX = wheelEvent.lineOrPageDeltaX = delta;
|
2008-04-19 19:37:51 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
wheelEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
wheelEvent.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2012-08-12 05:42:37 +04: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 19:37:51 +04:00
|
|
|
|
2012-08-12 05:42:37 +04:00
|
|
|
return DispatchEvent(&wheelEvent);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2014-02-21 06:09:02 +04:00
|
|
|
mVisible = true;
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
nsEventStatus
|
2008-04-19 19:37:51 +04:00
|
|
|
nsWindow::hideEvent(QHideEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
2014-02-21 06:09:02 +04:00
|
|
|
mVisible = false;
|
2008-04-20 12:16:40 +04:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus nsWindow::touchEvent(QTouchEvent* aEvent)
|
2010-03-13 01:11:42 +03:00
|
|
|
{
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2010-10-09 10:08:42 +04:00
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::tabletEvent(QTabletEvent* aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2011-01-18 11:51:04 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// Helpers
|
2010-10-09 10:08:42 +04:00
|
|
|
|
|
|
|
nsEventStatus
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent)
|
2010-10-09 10:08:42 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(aEvent, status);
|
|
|
|
return status;
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
2010-03-13 01:11:42 +03:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowActivated();
|
|
|
|
}
|
2010-03-13 01:11:42 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
void
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowDeactivated();
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEventOnTopLevelWindow(void)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nullptr) {
|
|
|
|
topLevelWindow->DispatchActivateEvent();
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEventOnTopLevelWindow(void)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget());
|
|
|
|
if (topLevelWindow != nullptr) {
|
|
|
|
topLevelWindow->DispatchDeactivateEvent();
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
if (mWidgetListener &&
|
|
|
|
mWidgetListener->WindowResized(this, aRect.width, aRect.height)) {
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
2008-04-19 19:43:56 +04:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
///////////////////////////////////// OLD GECKO ECENTS need to Sort ///////////////////
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewParent);
|
2010-03-22 05:55:36 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
ReparentNativeWidget(aNewParent);
|
|
|
|
aNewParent->AddChild(this);
|
2008-04-19 19:37:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetModal(bool aModal)
|
2010-08-31 20:35:57 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04: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 20:35:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
|
|
|
bool aActivate)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
2015-08-29 04:12:41 +03:00
|
|
|
nsWindow::SetSizeMode(nsSizeMode aMode)
|
2014-02-21 06:09:02 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
|
|
|
if (aMode != nsSizeMode_Minimized) {
|
|
|
|
mWidget->requestActivate();
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// Save the requested state.
|
|
|
|
rv = nsBaseWidget::SetSizeMode(aMode);
|
|
|
|
|
|
|
|
// return if there's no shell or our current state is the same as
|
|
|
|
// the mode we were just set to.
|
|
|
|
if (!mWidget || mSizeState == mSizeMode) {
|
|
|
|
return rv;
|
2010-02-16 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
|
|
|
mWidget->showMaximized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
|
|
|
mWidget->showMinimized();
|
|
|
|
break;
|
|
|
|
case nsSizeMode_Fullscreen:
|
|
|
|
mWidget->showFullScreen();
|
|
|
|
break;
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
|
|
|
mWidget->show();
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 17:54:27 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(aItem);
|
2010-03-22 05:55:36 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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-03 09:31:43 +03:00
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2015-04-21 18:04:57 +03:00
|
|
|
aRect = gfx::IntRect(gfx::IntPoint(0, 0), mBounds.Size());
|
2010-05-14 22:13:36 +04:00
|
|
|
if (mIsTopLevel) {
|
2014-02-21 06:09:02 +04:00
|
|
|
QPoint pos = mWidget->position();
|
|
|
|
aRect.MoveTo(pos.x(), pos.y());
|
2010-05-14 22:13:36 +04:00
|
|
|
}
|
2011-02-03 09:31:43 +03:00
|
|
|
else {
|
2015-05-19 04:13:56 +03:00
|
|
|
aRect.MoveTo(WidgetToScreenOffsetUntyped());
|
2011-02-03 09:31:43 +03:00
|
|
|
}
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsCOMPtr<nsIFile> iconFile;
|
|
|
|
nsAutoCString path;
|
|
|
|
nsTArray<nsCString> iconList;
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// Look for icons with the following suffixes appended to the base name.
|
|
|
|
// The last two entries (for the old XPM format) will be ignored unless
|
|
|
|
// no icons are found using the other suffixes. XPM icons are depricated.
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
|
|
|
|
".xpm", "16.xpm" };
|
2010-03-06 10:25:46 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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-06 10:25:46 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
|
|
|
iconList.AppendElement(path);
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 14:35:27 +03:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::CaptureMouse(bool aCapture)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_OK;
|
2010-02-04 17:43:52 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->setMouseGrabEnabled(aCapture);
|
2010-03-26 03:33:31 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
bool
|
|
|
|
nsWindow::CheckForRollup(double aMouseX, double aMouseY,
|
|
|
|
bool aIsWheel)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
nsIRollupListener* rollupListener = GetActiveRollupListener();
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget;
|
|
|
|
if (rollupListener) {
|
|
|
|
rollupWidget = rollupListener->GetRollupWidget();
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!rollupWidget) {
|
|
|
|
nsBaseWidget::gRollupListener = nullptr;
|
|
|
|
return false;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04: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 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
|
|
|
nsIntPoint pos(aMouseX, aMouseY);
|
2015-01-08 04:52:20 +03:00
|
|
|
retVal = rollupListener->Rollup(popupsToRollup, true, &pos, nullptr);
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
2008-04-19 19:37:51 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return retVal;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2014-02-21 06:09:02 +04:00
|
|
|
bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return aWindow->geometry().contains(aMouseX, aMouseY);
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetAttention(int32_t aCycleCount)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::OnCloseEvent(QCloseEvent *aEvent)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidgetListener)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
mWidgetListener->RequestWindowClose(this);
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
inline bool
|
|
|
|
is_latin_shortcut_key(quint32 aKeyval)
|
2008-04-19 19:37:51 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return ((Qt::Key_0 <= aKeyval && aKeyval <= Qt::Key_9) ||
|
|
|
|
(Qt::Key_A <= aKeyval && aKeyval <= Qt::Key_Z));
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this);
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
return status;
|
2012-04-12 08:18:35 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchContentCommandEvent(int32_t aMsg)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
WidgetContentCommandEvent event(true, aMsg, this);
|
2010-02-16 21:14:20 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
2011-02-03 09:31:36 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return status;
|
|
|
|
}
|
2011-02-03 09:31:43 +03:00
|
|
|
|
2011-08-28 22:09:56 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
2011-01-04 18:37:27 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
if (bundleService) {
|
|
|
|
bundleService->CreateBundle(
|
|
|
|
"chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
2011-02-03 09:31:43 +03:00
|
|
|
}
|
2009-07-15 16:20:21 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (bundle) {
|
|
|
|
bundle->GetStringFromName(
|
|
|
|
MOZ_UTF16("brandShortName"),
|
|
|
|
getter_Copies(brandName));
|
2008-04-20 12:16:40 +04:00
|
|
|
}
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (brandName.IsEmpty()) {
|
2014-05-26 22:54:10 +04:00
|
|
|
brandName.AssignLiteral(MOZ_UTF16("Mozilla"));
|
2010-02-20 06:46:54 +03:00
|
|
|
}
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (!mWidget) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-19 19:37:51 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
2011-09-22 13:17:40 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
XClassHint *class_hint = XAllocClassHint();
|
|
|
|
if (!class_hint) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2011-09-22 13:17:40 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04: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) {
|
2015-03-27 03:01:12 +03:00
|
|
|
free(class_hint->res_name);
|
2014-02-21 06:09:02 +04:00
|
|
|
XFree(class_hint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-08-13 13:57:55 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04: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 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 15:21:17 +04:00
|
|
|
|
2015-03-27 03:01:12 +03:00
|
|
|
free(class_hint->res_class);
|
|
|
|
free(class_hint->res_name);
|
2014-02-21 06:09:02 +04:00
|
|
|
XFree(class_hint);
|
|
|
|
#endif
|
2010-07-29 05:05:56 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return NS_OK;
|
2010-07-29 05:05:56 +04:00
|
|
|
}
|
|
|
|
|
2008-04-22 15:21:17 +04:00
|
|
|
void
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::NativeResize(int32_t aWidth, int32_t aHeight, bool aRepaint)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mNeedsResize = false;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->resize(aWidth, aHeight);
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (aRepaint) {
|
|
|
|
mWidget->renderLater();
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04: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 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mNeedsResize = false;
|
|
|
|
mNeedsMove = false;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
2011-05-02 12:16:22 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (aRepaint) {
|
|
|
|
mWidget->renderLater();
|
2011-05-02 12:16:22 +04:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2011-05-02 12:16:22 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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-22 05:55:36 +03:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
else {
|
|
|
|
mWidget->hide();
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetHasTransparentBackground(bool aTransparent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-21 06:09:02 +04:00
|
|
|
nsWindow::GetHasTransparentBackground(bool& aTransparent)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
aTransparent = mIsTransparent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("Not implemented");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
nsresult
|
|
|
|
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
|
|
|
|
{
|
|
|
|
QIcon icon;
|
2010-03-22 05:55:36 +03:00
|
|
|
|
2014-02-21 06:09:02 +04: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 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
mWidget->setIcon(icon);
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void nsWindow::QWidgetDestroyed()
|
|
|
|
{
|
|
|
|
mWidget = nullptr;
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::HideWindowChrome(bool aShouldHide)
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
// Nothing to hide
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-22 05:55:36 +03:00
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04: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 21:14:20 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
if (wasVisible) {
|
|
|
|
NativeShow(true);
|
|
|
|
}
|
2008-04-22 15:21:18 +04:00
|
|
|
|
2008-04-22 15:21:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
nsWindow::HasGLContext()
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
|
|
|
|
nsIWidget*
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
2008-04-22 15:21:17 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return qApp->primaryScreen()->logicalDotsPerInch();
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mOnDestroyCalled) {
|
2008-04-22 15:21:17 +04:00
|
|
|
return;
|
2014-02-21 06:09:02 +04:00
|
|
|
}
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mOnDestroyCalled = true;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
2011-10-25 19:05:32 +04:00
|
|
|
// release references to children and device context
|
2008-04-22 15:21:17 +04:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// let go of our parent
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2008-04-22 15:21:17 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
2012-08-15 22:52:41 +04:00
|
|
|
NotifyWindowDestroyed();
|
2008-04-22 15:21:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-04-22 15:21:17 +04:00
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
if (mBounds.width > 0 && mBounds.height > 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-03-13 01:07:32 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return false;
|
2010-03-13 01:07:32 +03:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:06:35 +04:00
|
|
|
void
|
2011-11-27 15:51:52 +04:00
|
|
|
nsWindow::SetSoftwareKeyboardState(bool aOpen,
|
|
|
|
const InputContextAction& aAction)
|
2011-09-07 19:06:35 +04:00
|
|
|
{
|
|
|
|
if (aOpen) {
|
2012-12-24 08:45:57 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(mInputContext.mIMEState.mEnabled !=
|
|
|
|
IMEState::DISABLED);
|
2011-09-07 19:06:35 +04:00
|
|
|
|
|
|
|
// Ensure that opening the virtual keyboard is allowed for this specific
|
2011-11-27 15:51:52 +04:00
|
|
|
// InputContext depending on the content.ime.strict.policy pref
|
2011-11-27 15:51:53 +04:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2011-11-27 15:51:52 +04:00
|
|
|
Preferences::GetBool("content.ime.strict_policy", false) &&
|
2011-11-27 15:51:53 +04:00
|
|
|
!aAction.ContentGotFocusByTrustedCause() &&
|
|
|
|
!aAction.UserMightRequestOpenVKB()) {
|
2011-11-27 15:51:52 +04:00
|
|
|
return;
|
2011-09-07 19:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOpen) {
|
2014-02-21 06:09:02 +04:00
|
|
|
qApp->inputMethod()->show();
|
2011-09-07 19:06:35 +04:00
|
|
|
} else {
|
2014-02-21 06:09:02 +04:00
|
|
|
qApp->inputMethod()->hide();
|
2011-09-07 19:06:35 +04:00
|
|
|
}
|
2010-04-16 21:37:16 +04:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return;
|
2010-04-16 21:37:16 +04:00
|
|
|
}
|
2012-02-22 23:16:15 +04:00
|
|
|
|
|
|
|
|
2013-10-22 17:27:35 +04:00
|
|
|
void
|
|
|
|
nsWindow::ProcessMotionEvent()
|
|
|
|
{
|
|
|
|
if (mMoveEvent.needDispatch) {
|
2015-08-29 02:58:29 +03:00
|
|
|
WidgetMouseEvent event(true, eMouseMove, this, WidgetMouseEvent::eReal);
|
2013-10-22 17:27:35 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|