2008-04-19 08:37:51 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2008-04-19 08:31:50 -07:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2008-04-19 08:37:51 -07:00
|
|
|
* The Initial Developer of the Original Code is Christopher Blizzard
|
|
|
|
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
|
|
|
* are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
|
2008-04-19 08:31:50 -07:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2008-04-19 08:37:51 -07:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2008-04-19 08:39:38 -07:00
|
|
|
* Romashin Oleg <romaxa@gmail.com>
|
2008-04-22 04:21:18 -07:00
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2010-02-16 10:14:20 -08:00
|
|
|
* Jeremias Bosch <jeremias.bosch@gmail.com>
|
|
|
|
* Steffen Imhof <steffen.imhof@gmail.com>
|
2008-04-19 08:31:50 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2008-04-19 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"
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
#include "nsToolkit.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIRegion.h"
|
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsIMenuRollup.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsQtKeyUtils.h"
|
|
|
|
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QDesktopWidget>
|
|
|
|
#include <QtGui/QCursor>
|
2010-02-16 10:14:20 -08:00
|
|
|
#include <QtGui/QIcon>
|
2009-07-15 05:20:21 -07:00
|
|
|
#include <QtGui/QX11Info>
|
2010-02-16 10:14:20 -08:00
|
|
|
#include <QtGui/QGraphicsScene>
|
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
#include <QtGui/QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <QtGui/QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QtGui/QGraphicsSceneMouseEvent>
|
|
|
|
#include <QtGui/QGraphicsSceneHoverEvent>
|
|
|
|
#include <QtGui/QGraphicsSceneWheelEvent>
|
|
|
|
#include <QtGui/QGraphicsSceneResizeEvent>
|
|
|
|
#include <QtGui/QStyleOptionGraphicsItem>
|
2008-04-20 06:54:27 -07:00
|
|
|
|
2009-03-27 04:35:27 -07:00
|
|
|
#include <QtCore/QDebug>
|
2010-02-16 10:14:20 -08:00
|
|
|
#include <QtCore/QEvent>
|
|
|
|
#include <QtCore/QVariant>
|
|
|
|
|
|
|
|
#include "gfxQtPlatform.h"
|
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#include "gfxQPainterSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2010-02-19 19:46:54 -08:00
|
|
|
#include "gfxSharedImageSurface.h"
|
2009-03-27 04:35:27 -07:00
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
// Buffered Pixmap stuff
|
|
|
|
static QPixmap *gBufferPixmap = nsnull;
|
|
|
|
static int gBufferPixmapUsageCount = 0;
|
|
|
|
|
|
|
|
// Buffered shared image + pixmap
|
|
|
|
static gfxSharedImageSurface *gBufferImage = nsnull;
|
|
|
|
static gfxSharedImageSurface *gBufferImageTemp = nsnull;
|
|
|
|
PRBool gNeedColorConversion = PR_FALSE;
|
|
|
|
extern "C" {
|
|
|
|
#include "pixman.h"
|
|
|
|
}
|
2008-04-19 08:37:55 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
/* For PrepareNativeWidget */
|
|
|
|
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
|
|
|
|
|
|
|
// initialization static functions
|
|
|
|
static nsresult initialize_prefs (void);
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
|
|
|
|
|
|
|
#define NS_WINDOW_TITLE_MAX_LENGTH 4095
|
|
|
|
|
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// Qt
|
2008-04-19 08:37:51 -07:00
|
|
|
static const int WHEEL_DELTA = 120;
|
|
|
|
static PRBool gGlobalsInitialized = PR_FALSE;
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2009-12-22 15:49:33 -08:00
|
|
|
static nsIRollupListener* gRollupListener;
|
|
|
|
static nsIMenuRollup* gMenuRollup;
|
2008-08-16 00:07:21 -07:00
|
|
|
static nsWeakPtr gRollupWindow;
|
|
|
|
static PRBool gConsumeRollupEvent;
|
|
|
|
|
|
|
|
static PRBool check_for_rollup(double aMouseX, double aMouseY,
|
|
|
|
PRBool aIsWheel);
|
2010-02-16 10:14:20 -08:00
|
|
|
static bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
static PRBool
|
|
|
|
isContextMenuKeyEvent(const QKeyEvent *qe)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
PRUint32 kc = QtKeyCodeToDOMKeyCode(qe->key());
|
|
|
|
if (qe->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool 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
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
static void
|
|
|
|
InitKeyEvent(nsKeyEvent &aEvent, QKeyEvent *aQEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-01-08 00:12:21 -08:00
|
|
|
aEvent.isShift = (aQEvent->modifiers() & Qt::ShiftModifier) ? PR_TRUE : PR_FALSE;
|
|
|
|
aEvent.isControl = (aQEvent->modifiers() & Qt::ControlModifier) ? PR_TRUE : PR_FALSE;
|
|
|
|
aEvent.isAlt = (aQEvent->modifiers() & Qt::AltModifier) ? PR_TRUE : PR_FALSE;
|
|
|
|
aEvent.isMeta = (aQEvent->modifiers() & Qt::MetaModifier) ? PR_TRUE : PR_FALSE;
|
2008-04-20 01:16:40 -07:00
|
|
|
aEvent.time = 0;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// The transformations above and in qt for the keyval are not invertible
|
|
|
|
// so link to the QKeyEvent (which will vanish soon after return from the
|
2008-04-20 01:16:40 -07:00
|
|
|
// event callback) to give plugins access to hardware_keycode and state.
|
2010-02-16 10:14:20 -08:00
|
|
|
// (An XEvent would be nice but the QKeyEvent is good enough.)
|
2009-11-10 13:55:38 -08:00
|
|
|
aEvent.pluginEvent = (void *)aQEvent;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
mIsTopLevel = PR_FALSE;
|
|
|
|
mIsDestroyed = PR_FALSE;
|
|
|
|
mIsShown = PR_FALSE;
|
|
|
|
mEnabled = PR_TRUE;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget = nsnull;
|
2008-04-19 08:37:51 -07:00
|
|
|
mIsVisible = PR_FALSE;
|
|
|
|
mActivatePending = PR_FALSE;
|
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
mSizeState = nsSizeMode_Normal;
|
|
|
|
mPluginType = PluginType_NONE;
|
|
|
|
mQCursor = Qt::ArrowCursor;
|
2010-02-16 10:14:20 -08:00
|
|
|
mScene = nsnull;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (!gGlobalsInitialized) {
|
|
|
|
gGlobalsInitialized = PR_TRUE;
|
|
|
|
|
|
|
|
// It's OK if either of these fail, but it may not be one day.
|
|
|
|
initialize_prefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags));
|
|
|
|
|
|
|
|
mIsTransparent = PR_FALSE;
|
|
|
|
|
|
|
|
mCursor = eCursor_standard;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
|
|
|
gBufferPixmapUsageCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gfxASurface::gfxImageFormat
|
|
|
|
_depth_to_gfximage_format(PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
switch (aDepth) {
|
|
|
|
case 32:
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
case 24:
|
|
|
|
return gfxASurface::ImageFormatRGB24;
|
|
|
|
default:
|
|
|
|
return gfxASurface::ImageFormatUnknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeOffScreenBuffers(void)
|
|
|
|
{
|
|
|
|
delete gBufferImage;
|
|
|
|
delete gBufferImageTemp;
|
|
|
|
delete gBufferPixmap;
|
|
|
|
gBufferImage = nsnull;
|
|
|
|
gBufferImageTemp = nsnull;
|
|
|
|
gBufferPixmap = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
UpdateOffScreenBuffers(QSize aSize, int aDepth)
|
|
|
|
{
|
|
|
|
gfxIntSize size(aSize.width(), aSize.height());
|
|
|
|
if (gBufferPixmap) {
|
|
|
|
if (gBufferPixmap->size().width() < size.width ||
|
|
|
|
gBufferPixmap->size().height() < size.height) {
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBufferPixmap = new QPixmap(size.width, size.height);
|
|
|
|
if (!gBufferPixmap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (gfxQtPlatform::GetPlatform()->GetRenderMode() == gfxQtPlatform::RENDER_XLIB)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check if system depth has related gfxImage format
|
|
|
|
gfxASurface::gfxImageFormat format =
|
|
|
|
_depth_to_gfximage_format(gBufferPixmap->x11Info().depth());
|
|
|
|
|
|
|
|
gNeedColorConversion = (format == gfxASurface::ImageFormatUnknown);
|
|
|
|
|
|
|
|
gBufferImage = new gfxSharedImageSurface();
|
|
|
|
if (!gBufferImage) {
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gBufferImage->Init(gfxIntSize(gBufferPixmap->size().width(),
|
|
|
|
gBufferPixmap->size().height()),
|
|
|
|
_depth_to_gfximage_format(gBufferPixmap->x11Info().depth()))) {
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gfxImageSurface does not support system color depth format
|
|
|
|
// we have to paint it with temp surface and color conversion
|
|
|
|
if (!gNeedColorConversion)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
gBufferImageTemp = new gfxSharedImageSurface();
|
|
|
|
if (!gBufferImageTemp) {
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gBufferImageTemp->Init(gfxIntSize(gBufferPixmap->size().width(),
|
|
|
|
gBufferPixmap->size().height()),
|
|
|
|
gfxASurface::ImageFormatRGB24)) {
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsWindow::ReleaseGlobals()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsBaseWidget, nsISupportsWeakReference)
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
|
|
|
|
|
|
|
if (w->mBounds.Size() != configuration.mBounds.Size()) {
|
|
|
|
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
|
|
|
|
configuration.mBounds.width, configuration.mBounds.height,
|
|
|
|
PR_TRUE);
|
|
|
|
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
|
|
|
w->Move(configuration.mBounds.x, configuration.mBounds.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mIsDestroyed || !mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("nsWindow::Destroy [%p]\n", (void *)this));
|
|
|
|
mIsDestroyed = PR_TRUE;
|
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
if (gBufferPixmapUsageCount &&
|
|
|
|
--gBufferPixmapUsageCount == 0) {
|
|
|
|
|
|
|
|
FreeOffScreenBuffers();
|
|
|
|
}
|
|
|
|
|
2008-08-16 00:07:21 -07:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
|
|
|
if (static_cast<nsIWidget *>(this) == rollupWidget.get()) {
|
|
|
|
if (gRollupListener)
|
2009-06-12 11:23:16 -07:00
|
|
|
gRollupListener->Rollup(nsnull, nsnull);
|
2008-08-16 00:07:21 -07:00
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
2009-12-22 15:49:33 -08:00
|
|
|
NS_IF_RELEASE(gMenuRollup);
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
Show(PR_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.
|
|
|
|
mThebesSurface = nsnull;
|
|
|
|
|
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
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget = nsnull;
|
2008-04-20 01:16:40 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
OnDestroy();
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// tear down some infrastructure after all event handling is finished
|
|
|
|
if (mScene) {
|
|
|
|
QWidget* view = GetViewWidget();
|
|
|
|
|
|
|
|
delete mScene;
|
|
|
|
mScene = nsnull;
|
|
|
|
|
|
|
|
delete view;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetParent(nsIWidget *aNewParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNewParent);
|
2009-07-15 05:20:21 -07:00
|
|
|
if (aNewParent) {
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget* newParent = static_cast<MozQWidget*>(aNewParent->GetNativeData(NS_NATIVE_WINDOW));
|
2009-07-15 05:20:21 -07:00
|
|
|
NS_ASSERTION(newParent, "Parent widget has a null native window handle");
|
|
|
|
if (mWidget) {
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget->setParentItem(newParent);
|
2009-07-15 05:20:21 -07:00
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
aNewParent->AddChild(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
|
|
|
|
if (mWidget)
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget->setParentItem(0);
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetModal(PRBool aModal)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget));
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->setModal(aModal);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsVisible(PRBool & aState)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
aState = mWidget ? mWidget->isVisible() : PR_FALSE;
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget) {
|
2008-04-19 08:37:51 -07:00
|
|
|
PRInt32 screenWidth = QApplication::desktop()->width();
|
|
|
|
PRInt32 screenHeight = QApplication::desktop()->height();
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (aAllowSlop) {
|
|
|
|
if (*aX < (kWindowPositionSlop - mBounds.width))
|
|
|
|
*aX = kWindowPositionSlop - mBounds.width;
|
|
|
|
if (*aX > (screenWidth - kWindowPositionSlop))
|
|
|
|
*aX = screenWidth - kWindowPositionSlop;
|
|
|
|
if (*aY < (kWindowPositionSlop - mBounds.height))
|
|
|
|
*aY = kWindowPositionSlop - mBounds.height;
|
|
|
|
if (*aY > (screenHeight - kWindowPositionSlop))
|
|
|
|
*aY = screenHeight - kWindowPositionSlop;
|
|
|
|
} else {
|
|
|
|
if (*aX < 0)
|
|
|
|
*aX = 0;
|
|
|
|
if (*aX > (screenWidth - mBounds.width))
|
|
|
|
*aX = screenWidth - mBounds.width;
|
|
|
|
if (*aY < 0)
|
|
|
|
*aY = 0;
|
|
|
|
if (*aY > (screenHeight - mBounds.height))
|
|
|
|
*aY = screenHeight - mBounds.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Move(PRInt32 aX, PRInt32 aY)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::Move [%p] %d %d\n", (void *)this,
|
|
|
|
aX, aY));
|
|
|
|
|
2009-11-02 11:10:07 -08:00
|
|
|
if (mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog) {
|
|
|
|
SetSizeMode(nsSizeMode_Normal);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
|
|
|
// the internal QGraphicsWidget is always in the top corner of
|
|
|
|
// the view if it is a toplevel one
|
|
|
|
aX = aY = 0;
|
2009-11-02 11:10:07 -08:00
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (aX == mBounds.x && aY == mBounds.y)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// update the bounds
|
|
|
|
QPointF pos( aX, aY );
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// the position of the widget is set relative to the parent
|
|
|
|
// so we map the coordinates accordingly
|
|
|
|
pos = mWidget->mapFromScene(pos);
|
|
|
|
pos = mWidget->mapToParent(pos);
|
|
|
|
mWidget->setPos(pos);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.x = pos.x();
|
|
|
|
mBounds.y = pos.y();
|
|
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget,
|
|
|
|
PRBool aActivate)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode));
|
|
|
|
|
|
|
|
// Save the requested state.
|
|
|
|
rv = nsBaseWidget::SetSizeMode(aMode);
|
|
|
|
|
|
|
|
// return if there's no shell or our current state is the same as
|
|
|
|
// the mode we were just set to.
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget || mSizeState == mSizeMode) {
|
2008-04-19 08:37:51 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showMaximized();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showMinimized();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
2010-02-04 06:43:52 -08:00
|
|
|
case nsSizeMode_Fullscreen:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showFullScreen();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
default:
|
|
|
|
// nsSizeMode_Normal, really.
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showNormal();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSizeState = mSizeMode;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// Helper function to recursively find the first parent item that
|
|
|
|
// is still visible (QGraphicsItem can be hidden even if they are
|
|
|
|
// set to visible if one of their ancestors is invisible)
|
|
|
|
static void find_first_visible_parent(QGraphicsItem* aItem, QGraphicsItem*& aVisibleItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!aVisibleItem && aItem->isVisible())
|
|
|
|
aVisibleItem = aItem;
|
|
|
|
else if (aVisibleItem && !aItem->isVisible())
|
|
|
|
aVisibleItem = nsnull;
|
|
|
|
|
|
|
|
// check further up the chain
|
|
|
|
find_first_visible_parent(aItem->parentItem(), aVisibleItem);
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetFocus(PRBool aRaise)
|
|
|
|
{
|
|
|
|
// Make sure that our owning widget has focus. If it doesn't try to
|
|
|
|
// grab it. Note that we don't set our focus flag in this case.
|
|
|
|
LOGFOCUS((" SetFocus [%p]\n", (void *)this));
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
|
|
|
// Because QGraphicsItem cannot get the focus if they are
|
|
|
|
// invisible, we look up the chain, for the lowest visible
|
|
|
|
// parent and focus that one
|
|
|
|
QGraphicsItem* realFocusItem = nsnull;
|
|
|
|
find_first_visible_parent(mWidget, realFocusItem);
|
|
|
|
|
|
|
|
if (!realFocusItem || realFocusItem->hasFocus())
|
2009-07-15 05:20:21 -07:00
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
if (aRaise)
|
2010-02-16 10:14:20 -08:00
|
|
|
realFocusItem->setFocus(Qt::ActiveWindowFocusReason);
|
|
|
|
else
|
|
|
|
realFocusItem->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
DispatchActivateEvent();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-11 05:51:06 -08:00
|
|
|
nsWindow::GetScreenBounds(nsIntRect &aRect)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size());
|
|
|
|
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
|
2008-04-19 08:37:51 -07:00
|
|
|
aRect.x, aRect.y,
|
|
|
|
mBounds.width, mBounds.height,
|
|
|
|
aRect.width, aRect.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetForegroundColor(const nscolor &aColor)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetBackgroundColor(const nscolor &aColor)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
|
|
|
mCursor = aCursor;
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget)
|
|
|
|
mWidget->SetCursor(mCursor);
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetCursor(imgIContainer* aCursor,
|
|
|
|
PRUint32 aHotspotX, PRUint32 aHotspotY)
|
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-11 05:51:06 -08:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect,
|
2008-04-19 08:37:51 -07:00
|
|
|
PRBool aIsSynchronous)
|
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
LOGDRAW(("Invalidate (rect) [%p,%p]: %d %d %d %d (sync: %d)\n", (void *)this,
|
2009-07-15 05:20:21 -07:00
|
|
|
(void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height, aIsSynchronous));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget->update(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
|
|
|
|
// QGraphicsItems cannot trigger a repaint themselves, so we start it on the view
|
|
|
|
if (aIsSynchronous && GetViewWidget())
|
|
|
|
GetViewWidget()->repaint();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Update()
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update(); // FIXME This call cause update for whole window on each scroll event
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
void
|
|
|
|
nsWindow::Scroll(const nsIntPoint& aDelta,
|
2009-08-27 07:48:00 -07:00
|
|
|
const nsTArray<nsIntRect>& aDestRects,
|
2009-08-04 19:39:05 -07:00
|
|
|
const nsTArray<nsIWidget::Configuration>& aConfigurations)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-08-04 19:39:05 -07:00
|
|
|
if (!mWidget) {
|
|
|
|
NS_ERROR("No widget to scroll.");
|
|
|
|
return;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
nsAutoTArray<nsWindow*,1> windowsToShow;
|
|
|
|
// Hide any widgets that are becoming invisible or that are moving.
|
|
|
|
// Moving widgets are hidden for the duration of the scroll so that
|
|
|
|
// the XCopyArea treats their drawn pixels as part of the window
|
|
|
|
// that should be scrolled. This works well when the widgets are
|
|
|
|
// moving because they're being scrolled, which is normally true.
|
|
|
|
for (PRUint32 i = 0; i < aConfigurations.Length(); ++i) {
|
|
|
|
const Configuration& configuration = aConfigurations[i];
|
|
|
|
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
|
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configuration widget is not a child");
|
|
|
|
if (w->mIsShown &&
|
|
|
|
(configuration.mClipRegion.IsEmpty() ||
|
|
|
|
configuration.mBounds != w->mBounds)) {
|
|
|
|
w->NativeShow(PR_FALSE);
|
|
|
|
windowsToShow.AppendElement(w);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2009-12-13 13:01:33 -08:00
|
|
|
for (BlitRectIter iter(aDelta, aDestRects); !iter.IsDone(); ++iter) {
|
|
|
|
const nsIntRect & r = iter.Rect();
|
2009-08-27 07:48:00 -07:00
|
|
|
QRect rect(r.x - aDelta.x, r.y - aDelta.y, r.width, r.height);
|
|
|
|
mWidget->scroll(aDelta.x, aDelta.y, rect);
|
|
|
|
}
|
2009-08-04 19:39:05 -07:00
|
|
|
ConfigureChildren(aConfigurations);
|
|
|
|
|
|
|
|
// Show windows again...
|
|
|
|
for (PRUint32 i = 0; i < windowsToShow.Length(); ++i) {
|
|
|
|
windowsToShow[i]->NativeShow(PR_TRUE);
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QWidget* nsWindow::GetViewWidget()
|
|
|
|
{
|
|
|
|
QWidget* viewWidget = nsnull;
|
|
|
|
|
|
|
|
if (!mScene) {
|
|
|
|
if (mParent)
|
|
|
|
return static_cast<nsWindow*>(mParent.get())->GetViewWidget();
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mScene->views().size() == 1, "Not exactly one view for our scene!");
|
|
|
|
viewWidget = mScene->views()[0];
|
|
|
|
|
|
|
|
return viewWidget;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
void*
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_WIDGET: {
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
return mWidget;
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
return SetupPluginPort();
|
|
|
|
break;
|
|
|
|
|
2008-04-20 06:54:27 -07:00
|
|
|
#ifdef Q_WS_X11
|
2008-04-19 08:37:51 -07:00
|
|
|
case NS_NATIVE_DISPLAY:
|
2010-02-16 10:14:20 -08:00
|
|
|
return GetViewWidget()->x11Info().display();
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
2008-04-20 06:54:27 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC: {
|
|
|
|
NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");
|
|
|
|
return (void *)static_cast<nsToolkit *>(mToolkit)->GetSharedGC();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_NATIVE_SHELLWIDGET:
|
2010-02-16 10:14:20 -08:00
|
|
|
return (void *) GetViewWidget();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length()));
|
|
|
|
if (mIsTopLevel)
|
|
|
|
GetViewWidget()->setWindowTitle(qStr);
|
|
|
|
else if (mWidget)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setWindowTitle(qStr);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetIcon(const nsAString& aIconSpec)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> iconFile;
|
|
|
|
nsCAutoString path;
|
2009-01-21 20:15:34 -08:00
|
|
|
nsTArray<nsCString> iconList;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// Look for icons with the following suffixes appended to the base name.
|
|
|
|
// The last two entries (for the old XPM format) will be ignored unless
|
|
|
|
// no icons are found using the other suffixes. XPM icons are depricated.
|
|
|
|
|
|
|
|
const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png",
|
|
|
|
".xpm", "16.xpm" };
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(extensions); i++) {
|
|
|
|
// Don't bother looking for XPM versions if we found a PNG.
|
2009-01-21 20:15:34 -08:00
|
|
|
if (i == NS_ARRAY_LENGTH(extensions) - 2 && iconList.Length())
|
2008-04-19 08:37:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
nsAutoString extension;
|
|
|
|
extension.AppendASCII(extensions[i]);
|
|
|
|
|
|
|
|
ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile));
|
|
|
|
if (iconFile) {
|
|
|
|
iconFile->GetNativePath(path);
|
2009-01-21 20:15:34 -08:00
|
|
|
iconList.AppendElement(path);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leave the default icon intact if no matching icons were found
|
2009-01-21 20:15:34 -08:00
|
|
|
if (iconList.Length() == 0)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return SetWindowIconList(iconList);
|
|
|
|
}
|
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QPointF origin(0, 0);
|
|
|
|
origin = mWidget->mapToScene(origin);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
return nsIntPoint(origin.x(), origin.y());
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
2009-02-18 16:11:49 -08:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::EnableDragDrop(PRBool aEnable)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setAcceptDrops(aEnable);
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CaptureMouse(PRBool aCapture)
|
|
|
|
{
|
|
|
|
LOG(("CaptureMouse %p\n", (void *)this));
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aCapture)
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->grabMouse();
|
2008-04-20 01:37:07 -07:00
|
|
|
else
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->releaseMouse();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
|
2009-12-22 15:49:33 -08:00
|
|
|
nsIMenuRollup *aMenuRollup,
|
2008-04-19 08:37:51 -07:00
|
|
|
PRBool aDoCapture,
|
|
|
|
PRBool aConsumeRollupEvent)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("CaptureRollupEvents %p\n", (void *)this));
|
2008-08-16 00:07:21 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (aDoCapture) {
|
2008-08-16 00:07:21 -07:00
|
|
|
gConsumeRollupEvent = aConsumeRollupEvent;
|
|
|
|
gRollupListener = aListener;
|
2009-12-22 15:49:33 -08:00
|
|
|
NS_IF_RELEASE(gMenuRollup);
|
|
|
|
gMenuRollup = aMenuRollup;
|
|
|
|
NS_IF_ADDREF(aMenuRollup);
|
2008-08-16 00:07:21 -07:00
|
|
|
gRollupWindow = do_GetWeakReference(static_cast<nsIWidget*>(this));
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-08-16 00:07:21 -07:00
|
|
|
gRollupListener = nsnull;
|
2009-12-22 15:49:33 -08:00
|
|
|
NS_IF_RELEASE(gMenuRollup);
|
2008-08-16 00:07:21 -07:00
|
|
|
gRollupWindow = nsnull;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-16 00:07:21 -07:00
|
|
|
PRBool
|
|
|
|
check_for_rollup(double aMouseX, double aMouseY,
|
|
|
|
PRBool aIsWheel)
|
|
|
|
{
|
|
|
|
PRBool retVal = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = do_QueryReferent(gRollupWindow);
|
|
|
|
|
|
|
|
if (rollupWidget && gRollupListener) {
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget *currentPopup =
|
|
|
|
(MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
2008-08-16 00:07:21 -07:00
|
|
|
|
|
|
|
if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
|
|
|
|
PRBool rollup = PR_TRUE;
|
|
|
|
if (aIsWheel) {
|
|
|
|
gRollupListener->ShouldRollupOnMouseWheelEvent(&rollup);
|
|
|
|
retVal = PR_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
|
2009-06-12 11:23:16 -07:00
|
|
|
PRUint32 popupsToRollup = PR_UINT32_MAX;
|
2009-12-22 15:49:33 -08:00
|
|
|
if (gMenuRollup) {
|
2008-08-16 00:07:21 -07:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2009-12-22 15:49:33 -08:00
|
|
|
PRUint32 sameTypeCount = gMenuRollup->GetSubmenuWidgetChain(&widgetChain);
|
2008-08-16 00:07:21 -07:00
|
|
|
for (PRUint32 i=0; i<widgetChain.Length(); ++i) {
|
|
|
|
nsIWidget* widget = widgetChain[i];
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget* currWindow =
|
|
|
|
(MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW);
|
2008-08-16 00:07:21 -07:00
|
|
|
if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
|
2009-06-12 11:23:16 -07:00
|
|
|
if (i < sameTypeCount) {
|
|
|
|
rollup = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
|
|
|
break;
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
} // foreach parent menu widget
|
|
|
|
} // if rollup listener knows about menus
|
|
|
|
|
|
|
|
// if we've determined that we should still rollup, do it.
|
|
|
|
if (rollup) {
|
2009-06-12 11:23:16 -07:00
|
|
|
gRollupListener->Rollup(popupsToRollup, nsnull);
|
2008-08-16 00:07:21 -07:00
|
|
|
retVal = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gRollupWindow = nsnull;
|
|
|
|
gRollupListener = nsnull;
|
2010-01-27 20:12:47 -08:00
|
|
|
NS_IF_RELEASE(gMenuRollup);
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2010-02-16 10:14:20 -08:00
|
|
|
bool
|
|
|
|
is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY)
|
2008-08-16 00:07:21 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
return aWindow->geometry().contains( aMouseX, aMouseY );
|
2008-08-16 00:07:21 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetAttention(PRInt32 aCycleCount)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::GetAttention [%p]\n", (void *)this));
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
static already_AddRefed<gfxASurface>
|
|
|
|
GetSurfaceForQWidget(QPixmap* aDrawable)
|
|
|
|
{
|
|
|
|
gfxASurface* result =
|
|
|
|
new gfxXlibSurface(aDrawable->x11Info().display(),
|
|
|
|
aDrawable->handle(),
|
|
|
|
(Visual*)aDrawable->x11Info().visual(),
|
|
|
|
gfxIntSize(aDrawable->size().width(), aDrawable->size().height()));
|
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::DoPaint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
if (mIsDestroyed) {
|
|
|
|
LOG(("Expose event on destroyed window [%p] window %p\n",
|
2009-07-15 05:20:21 -07:00
|
|
|
(void *)this, mWidget));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRegion> updateRegion = do_CreateInstance(kRegionCID);
|
|
|
|
if (!updateRegion)
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
QRectF r;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (aOption)
|
|
|
|
r = aOption->exposedRect;
|
|
|
|
else
|
|
|
|
r = mWidget->boundingRect();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
updateRegion->SetTo( (int)r.x(), (int)r.y(), (int)r.width(), (int)r.height() );
|
2008-04-20 01:37:07 -07:00
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
|
|
|
// Prepare offscreen buffers if RenderMode Xlib or Image
|
|
|
|
if (renderMode != gfxQtPlatform::RENDER_QPAINTER)
|
|
|
|
if (!UpdateOffScreenBuffers(r.size().toSize(), QX11Info().depth()))
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> targetSurface = nsnull;
|
|
|
|
if (renderMode == gfxQtPlatform::RENDER_XLIB) {
|
|
|
|
targetSurface = GetSurfaceForQWidget(gBufferPixmap);
|
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_SHARED_IMAGE) {
|
|
|
|
targetSurface = gNeedColorConversion ? gBufferImageTemp->getASurface()
|
|
|
|
: gBufferImage->getASurface();
|
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
targetSurface = new gfxQPainterSurface(aPainter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_UNLIKELY(!targetSurface))
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2008-04-19 08:43:23 -07:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRenderingContext> rc;
|
|
|
|
GetDeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc));
|
|
|
|
if (NS_UNLIKELY(!rc))
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
|
|
|
rc->Init(GetDeviceContext(), ctx);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
nsPaintEvent event(PR_TRUE, NS_PAINT, this);
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2009-02-11 05:51:06 -08:00
|
|
|
nsIntRect rect(r.x(), r.y(), r.width(), r.height());
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = r.x();
|
|
|
|
event.refPoint.y = r.y();
|
|
|
|
event.rect = nsnull;
|
2008-04-19 08:37:51 -07:00
|
|
|
event.region = updateRegion;
|
|
|
|
event.renderingContext = rc;
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
|
|
|
|
// operations below if that happened - it will lead to XError and exit().
|
2008-04-19 08:43:23 -07:00
|
|
|
if (NS_UNLIKELY(mIsDestroyed))
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (status == nsEventStatus_eIgnore)
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOGDRAW(("[%p] draw done\n", this));
|
|
|
|
|
2010-02-19 19:46:54 -08:00
|
|
|
if (renderMode == gfxQtPlatform::RENDER_SHARED_IMAGE) {
|
|
|
|
if (gNeedColorConversion) {
|
|
|
|
pixman_image_t *src_image = NULL;
|
|
|
|
pixman_image_t *dst_image = NULL;
|
|
|
|
src_image = pixman_image_create_bits(PIXMAN_x8r8g8b8,
|
|
|
|
gBufferImageTemp->GetSize().width,
|
|
|
|
gBufferImageTemp->GetSize().height,
|
|
|
|
(uint32_t*)gBufferImageTemp->Data(),
|
|
|
|
gBufferImageTemp->Stride());
|
|
|
|
dst_image = pixman_image_create_bits(PIXMAN_r5g6b5,
|
|
|
|
gBufferImage->GetSize().width,
|
|
|
|
gBufferImage->GetSize().height,
|
|
|
|
(uint32_t*)gBufferImage->Data(),
|
|
|
|
gBufferImage->Stride());
|
|
|
|
pixman_image_composite(PIXMAN_OP_SRC,
|
|
|
|
src_image,
|
|
|
|
NULL,
|
|
|
|
dst_image,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
gBufferImageTemp->GetSize().width,
|
|
|
|
gBufferImageTemp->GetSize().height);
|
|
|
|
pixman_image_unref(src_image);
|
|
|
|
pixman_image_unref(dst_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *disp = gBufferPixmap->x11Info().display();
|
|
|
|
XGCValues gcv;
|
|
|
|
gcv.graphics_exposures = False;
|
|
|
|
GC gc = XCreateGC (disp, gBufferPixmap->handle(), GCGraphicsExposures, &gcv);
|
|
|
|
XShmPutImage(disp, gBufferPixmap->handle(), gc, gBufferImage->image(),
|
|
|
|
0, 0, 0, 0, gBufferImage->GetSize().width, gBufferImage->GetSize().height,
|
|
|
|
False);
|
|
|
|
XFreeGC (disp, gc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (renderMode != gfxQtPlatform::RENDER_QPAINTER)
|
|
|
|
aPainter->drawPixmap(QPoint(0, 0), *gBufferPixmap);
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
ctx = nsnull;
|
|
|
|
targetSurface = nsnull;
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// check the return value!
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnMoveEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("configure event [%p] %d %d\n", (void *)this,
|
|
|
|
aEvent->pos().x(), aEvent->pos().y()));
|
|
|
|
|
|
|
|
// can we shortcut?
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
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
|
|
|
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_MOVE, this);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = aEvent->pos().x();
|
|
|
|
event.refPoint.y = aEvent->pos().y();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// XXX mozilla will invalidate the entire window after this move
|
|
|
|
// complete. wtf?
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnResizeEvent(QGraphicsSceneResizeEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2009-02-11 05:51:06 -08:00
|
|
|
nsIntRect rect;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// Generate XPFE resize event
|
|
|
|
GetBounds(rect);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
rect.width = aEvent->newSize().width();
|
|
|
|
rect.height = aEvent->newSize().height();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
mBounds.width = rect.width;
|
|
|
|
mBounds.height = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchResizeEvent(rect, status);
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-22 04:21:18 -07:00
|
|
|
nsWindow::OnCloseEvent(QCloseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, this);
|
|
|
|
|
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnEnterNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this, nsMouseEvent::eReal);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOG(("OnEnterNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnLeaveNotifyEvent(QGraphicsSceneHoverEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this, nsMouseEvent::eReal);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOG(("OnLeaveNotify: %p\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnMotionNotifyEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.isShift = ((aEvent->modifiers() & Qt::ShiftModifier) != 0);
|
|
|
|
event.isControl = ((aEvent->modifiers() & Qt::ControlModifier) != 0);
|
|
|
|
event.isAlt = ((aEvent->modifiers() & Qt::AltModifier) != 0);
|
|
|
|
event.isMeta = ((aEvent->modifiers() & Qt::MetaModifier) != 0);
|
2008-04-19 08:37:51 -07:00
|
|
|
event.clickCount = 0;
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
|
|
|
|
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::InitButtonEvent(nsMouseEvent &aMoveEvent,
|
|
|
|
QGraphicsSceneMouseEvent *aEvent, int aClickCount)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
aMoveEvent.refPoint.x = nscoord(aEvent->pos().x());
|
|
|
|
aMoveEvent.refPoint.y = nscoord(aEvent->pos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
aMoveEvent.isShift = ((aEvent->modifiers() & Qt::ShiftModifier) != 0);
|
|
|
|
aMoveEvent.isControl = ((aEvent->modifiers() & Qt::ControlModifier) != 0);
|
|
|
|
aMoveEvent.isAlt = ((aEvent->modifiers() & Qt::AltModifier) != 0);
|
|
|
|
aMoveEvent.isMeta = ((aEvent->modifiers() & Qt::MetaModifier) != 0);
|
|
|
|
aMoveEvent.clickCount = aClickCount;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnButtonPressEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
QPointF pos = aEvent->pos();
|
|
|
|
|
|
|
|
// we check against the widgets geometry, so use parent coordinates
|
|
|
|
// for the check
|
|
|
|
if (mWidget)
|
|
|
|
pos = mWidget->mapToParent(pos);
|
|
|
|
|
|
|
|
PRBool rolledUp = check_for_rollup( pos.x(), pos.y(), PR_FALSE);
|
2008-08-16 00:07:21 -07:00
|
|
|
if (gConsumeRollupEvent && rolledUp)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
PRUint16 domButton;
|
|
|
|
switch (aEvent->button()) {
|
|
|
|
case Qt::MidButton:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal);
|
|
|
|
event.button = domButton;
|
|
|
|
InitButtonEvent(event, aEvent, 1);
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// right menu click on linux should also pop up a context menu
|
|
|
|
if (domButton == nsMouseEvent::eRightButton &&
|
|
|
|
NS_LIKELY(!mIsDestroyed)) {
|
|
|
|
nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this,
|
|
|
|
nsMouseEvent::eReal);
|
2008-04-19 08:38:12 -07:00
|
|
|
InitButtonEvent(contextMenuEvent, aEvent, 1);
|
2008-04-19 08:37:51 -07:00
|
|
|
DispatchEvent(&contextMenuEvent, status);
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnButtonReleaseEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
PRUint16 domButton;
|
|
|
|
|
|
|
|
switch (aEvent->button()) {
|
|
|
|
case Qt::MidButton:
|
|
|
|
domButton = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
domButton = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
domButton = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal);
|
|
|
|
event.button = domButton;
|
2008-04-19 08:38:12 -07:00
|
|
|
InitButtonEvent(event, aEvent, 1);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
nsEventStatus status = DispatchEvent(&event);
|
|
|
|
|
|
|
|
return status;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
PRUint32 eventType;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
switch (aEvent->button()) {
|
2008-04-19 08:37:51 -07:00
|
|
|
case Qt::MidButton:
|
|
|
|
eventType = nsMouseEvent::eMiddleButton;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
eventType = nsMouseEvent::eRightButton;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eventType = nsMouseEvent::eLeftButton;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_MOUSE_DOUBLECLICK, this, nsMouseEvent::eReal);
|
|
|
|
event.button = eventType;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
InitButtonEvent(event, aEvent, 2);
|
2008-04-19 08:37:51 -07:00
|
|
|
//pressed
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnFocusInEvent(QEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this));
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-19 08:38:12 -07:00
|
|
|
DispatchActivateEvent();
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnFocusOutEvent(QEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-22 04:21:18 -07:00
|
|
|
LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
DispatchDeactivateEvent();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
is_latin_shortcut_key(quint32 aKeyval)
|
|
|
|
{
|
|
|
|
return ((Qt::Key_0 <= aKeyval && aKeyval <= Qt::Key_9) ||
|
|
|
|
(Qt::Key_A <= aKeyval && aKeyval <= Qt::Key_Z));
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsWindow::DispatchCommandEvent(nsIAtom* aCommand)
|
|
|
|
{
|
|
|
|
nsCommandEvent event(PR_TRUE, nsWidgetAtoms::onAppCommand, aCommand, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
return PR_TRUE;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::OnKeyPressEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
PRBool setNoDefault = PR_FALSE;
|
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)) {
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this,
|
|
|
|
nsMouseEvent::eReal,
|
|
|
|
nsMouseEvent::eContextMenuKey);
|
2008-04-20 01:16:40 -07:00
|
|
|
//keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
|
|
|
return DispatchEvent(&contextMenuEvent);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
PRUint32 domCharCode = 0;
|
|
|
|
PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
|
|
|
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
|
|
|
domCharCode = (PRInt32) aEvent->text()[0].unicode();
|
|
|
|
|
|
|
|
// If the key isn't autorepeat, we need to send the initial down event
|
|
|
|
if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
|
|
|
|
// send the key down event
|
|
|
|
|
|
|
|
SetKeyDownFlag(domKeyCode);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsKeyEvent downEvent(PR_TRUE, NS_KEY_DOWN, this);
|
|
|
|
InitKeyEvent(downEvent, aEvent);
|
|
|
|
|
|
|
|
downEvent.charCode = domCharCode;
|
|
|
|
downEvent.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
|
|
|
|
nsEventStatus status = DispatchEvent(&downEvent);
|
|
|
|
|
|
|
|
// If prevent default on keydown, do same for keypress
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault)
|
|
|
|
setNoDefault = PR_TRUE;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsKeyEvent event(PR_TRUE, NS_KEY_PRESS, this);
|
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
|
|
|
event.charCode = domCharCode;
|
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
|
|
|
|
if (setNoDefault)
|
|
|
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
|
|
|
|
// send the key press event
|
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::OnKeyReleaseEvent(QKeyEvent *aEvent)
|
|
|
|
{
|
|
|
|
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
if (isContextMenuKeyEvent(aEvent)) {
|
|
|
|
// er, what do we do here? DoDefault or NoDefault?
|
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 domCharCode = 0;
|
|
|
|
PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
|
|
|
|
|
|
|
|
if (aEvent->text().length() && aEvent->text()[0].isPrint())
|
|
|
|
domCharCode = (PRInt32) aEvent->text()[0].unicode();
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// send the key event as a key up event
|
|
|
|
nsKeyEvent event(PR_TRUE, NS_KEY_UP, this);
|
|
|
|
InitKeyEvent(event, aEvent);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
event.charCode = domCharCode;
|
|
|
|
event.keyCode = domCharCode ? 0 : domKeyCode;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// unset the key down flag
|
|
|
|
ClearKeyDownFlag(event.keyCode);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnScrollEvent(QGraphicsSceneWheelEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// check to see if we should rollup
|
|
|
|
nsMouseScrollEvent event(PR_TRUE, NS_MOUSE_SCROLL, this);
|
|
|
|
|
|
|
|
switch (aEvent->orientation()) {
|
|
|
|
case Qt::Vertical:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsVertical;
|
|
|
|
break;
|
|
|
|
case Qt::Horizontal:
|
|
|
|
event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
// negative values for aEvent->delta indicate downward scrolling;
|
|
|
|
// this is opposite Gecko usage.
|
|
|
|
|
|
|
|
event.delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
event.refPoint.x = nscoord(aEvent->scenePos().x());
|
|
|
|
event.refPoint.y = nscoord(aEvent->scenePos().y());
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
event.isShift = aEvent->modifiers() & Qt::ShiftModifier;
|
|
|
|
event.isControl = aEvent->modifiers() & Qt::ControlModifier;
|
|
|
|
event.isAlt = aEvent->modifiers() & Qt::AltModifier;
|
|
|
|
event.isMeta = aEvent->modifiers() & Qt::MetaModifier;
|
|
|
|
event.time = 0;
|
|
|
|
|
2008-04-20 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
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this));
|
|
|
|
mIsVisible = PR_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));
|
|
|
|
mIsVisible = PR_FALSE;
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eConsumeDoDefault;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::ThemeChanged()
|
|
|
|
{
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_THEMECHANGED, this);
|
2008-04-20 01:16:40 -07:00
|
|
|
|
|
|
|
DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// do nothing
|
2008-04-19 08:37:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragMotionEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
LOG(("nsWindow::OnDragMotionSignal\n"));
|
|
|
|
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, 0,
|
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragLeaveEvent(QGraphicsSceneDragDropEvent *aEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
|
|
|
// XXX Do we want to pass this on only if the event's subwindow is null?
|
|
|
|
LOG(("nsWindow::OnDragLeaveSignal(%p)\n", this));
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragDropEvent(QGraphicsSceneDragDropEvent *aDropEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-19 08:43:56 -07:00
|
|
|
if (aDropEvent->proposedAction() == Qt::CopyAction)
|
|
|
|
{
|
|
|
|
printf("text version of the data: %s\n", aDropEvent->mimeData()->text().toAscii().data());
|
|
|
|
aDropEvent->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
LOG(("nsWindow::OnDragDropSignal\n"));
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, 0,
|
|
|
|
nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::OnDragEnter(QGraphicsSceneDragDropEvent *aDragEvent)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2008-04-19 08:43:56 -07:00
|
|
|
// Is it some format we think we can support?
|
|
|
|
if ( aDragEvent->mimeData()->hasFormat(kURLMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kURLDataMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kURLDescriptionMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kHTMLMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kUnicodeMime)
|
|
|
|
|| aDragEvent->mimeData()->hasFormat(kTextMime)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
aDragEvent->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// XXX Do we want to pass this on only if the event's subwindow is null?
|
|
|
|
|
|
|
|
LOG(("nsWindow::OnDragEnter(%p)\n", this));
|
|
|
|
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal);
|
2008-04-20 01:16:40 -07:00
|
|
|
return DispatchEvent(&event);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetBrandName(nsXPIDLString& brandName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
if (bundleService)
|
|
|
|
bundleService->CreateBundle(
|
|
|
|
"chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
|
|
|
|
if (bundle)
|
|
|
|
bundle->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("brandShortName").get(),
|
|
|
|
getter_Copies(brandName));
|
|
|
|
|
|
|
|
if (brandName.IsEmpty())
|
|
|
|
brandName.Assign(NS_LITERAL_STRING("Mozilla"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
// only set the base parent if we're not going to be a dialog or a
|
2008-04-19 08:37:51 -07:00
|
|
|
// toplevel
|
2010-02-16 10:14:20 -08:00
|
|
|
nsIWidget *baseParent = aParent;
|
|
|
|
|
|
|
|
if (aInitData &&
|
2008-04-19 08:37:51 -07:00
|
|
|
(aInitData->mWindowType == eWindowType_dialog ||
|
|
|
|
aInitData->mWindowType == eWindowType_toplevel ||
|
2010-02-16 10:14:20 -08:00
|
|
|
aInitData->mWindowType == eWindowType_invisible)) {
|
|
|
|
|
|
|
|
baseParent = nsnull;
|
|
|
|
// also drop native parent for toplevel windows
|
|
|
|
aNativeParent = nsnull;
|
|
|
|
}
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// initialize all the common bits of this class
|
|
|
|
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
|
|
|
|
aAppShell, aToolkit, aInitData);
|
|
|
|
|
|
|
|
// and do our common creation
|
2008-04-22 04:21:18 -07:00
|
|
|
mParent = aParent;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// save our bounds
|
|
|
|
mBounds = aRect;
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// find native parent
|
|
|
|
MozQWidget *parent = nsnull;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
if (aParent != nsnull)
|
2010-02-16 10:14:20 -08:00
|
|
|
parent = static_cast<MozQWidget*>(aParent->GetNativeData(NS_NATIVE_WIDGET));
|
2008-04-19 08:37:51 -07:00
|
|
|
else
|
2010-02-16 10:14:20 -08:00
|
|
|
parent = static_cast<MozQWidget*>(aNativeParent);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
// ok, create our QGraphicsWidget
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget = createQWidget(parent, aInitData);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-02-16 07:27:18 -08:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
LOG(("Create: nsWindow [%p] [%p]\n", (void *)this, (void *)mWidget));
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
// resize so that everything is set to the right dimensions
|
2008-04-22 04:21:18 -07:00
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, PR_FALSE);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetWindowClass(const nsAString &xulWinType)
|
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
if (!mWidget)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
nsXPIDLString brandName;
|
|
|
|
GetBrandName(brandName);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 06:54:27 -07:00
|
|
|
#ifdef Q_WS_X11
|
2010-02-16 10:14:20 -08:00
|
|
|
XClassHint *class_hint = XAllocClassHint();
|
|
|
|
if (!class_hint)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
const char *role = NULL;
|
|
|
|
class_hint->res_name = ToNewCString(xulWinType);
|
|
|
|
if (!class_hint->res_name) {
|
|
|
|
XFree(class_hint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
class_hint->res_class = ToNewCString(brandName);
|
|
|
|
if (!class_hint->res_class) {
|
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse res_name into a name and role. Characters other than
|
|
|
|
// [A-Za-z0-9_-] are converted to '_'. Anything after the first
|
|
|
|
// colon is assigned to role; if there's no colon, assign the
|
|
|
|
// whole thing to both role and res_name.
|
|
|
|
for (char *c = class_hint->res_name; *c; c++) {
|
|
|
|
if (':' == *c) {
|
|
|
|
*c = 0;
|
|
|
|
role = c + 1;
|
|
|
|
}
|
|
|
|
else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c)))
|
|
|
|
*c = '_';
|
|
|
|
}
|
|
|
|
class_hint->res_name[0] = toupper(class_hint->res_name[0]);
|
|
|
|
if (!role) role = class_hint->res_name;
|
|
|
|
|
|
|
|
XSetClassHint(GetViewWidget()->x11Info().display(),
|
|
|
|
GetViewWidget()->handle(),
|
|
|
|
class_hint);
|
|
|
|
|
|
|
|
nsMemory::Free(class_hint->res_class);
|
2008-04-19 08:37:51 -07:00
|
|
|
nsMemory::Free(class_hint->res_name);
|
|
|
|
XFree(class_hint);
|
2008-04-20 06:54:27 -07:00
|
|
|
#endif
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::NativeResize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
|
|
|
|
aWidth, aHeight));
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->resize( aWidth, aHeight);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::NativeResize(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
|
|
|
PRBool aRepaint)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
|
|
|
|
aX, aY, aWidth, aHeight));
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
2008-04-19 08:37:51 -07:00
|
|
|
|
2008-04-20 01:37:07 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
2009-08-04 19:39:05 -07:00
|
|
|
void
|
|
|
|
nsWindow::NativeShow(PRBool aAction)
|
|
|
|
{
|
|
|
|
if (aAction == PR_TRUE)
|
|
|
|
mWidget->show();
|
|
|
|
else
|
|
|
|
mWidget->hide();
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetHasTransparentBackground(PRBool aTransparent)
|
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::GetHasTransparentBackground(PRBool& aTransparent)
|
|
|
|
{
|
|
|
|
aTransparent = mIsTransparent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::GetToplevelWidget(MozQWidget **aWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
*aWidget = mWidget;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsWindow::SetupPluginPort(void)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-19 08:37:51 -07:00
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-01-21 20:15:34 -08:00
|
|
|
nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList)
|
2008-04-19 08:37:51 -07:00
|
|
|
{
|
2010-02-16 10:14:20 -08:00
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aIconList.Length(); ++i) {
|
|
|
|
const char *path = aIconList[i].get();
|
|
|
|
LOG(("window [%p] Loading icon from %s\n", (void *)this, path));
|
|
|
|
icon.addFile(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
GetViewWidget()->setWindowIcon(icon);
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::SetDefaultIcon(void)
|
|
|
|
{
|
|
|
|
SetIcon(NS_LITERAL_STRING("default"));
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:35:27 -07:00
|
|
|
void nsWindow::QWidgetDestroyed()
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget = nsnull;
|
2009-03-27 04:35:27 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::MakeFullScreen(PRBool aFullScreen)
|
|
|
|
{
|
2010-02-04 06:43:52 -08:00
|
|
|
if (aFullScreen) {
|
|
|
|
if (mSizeMode != nsSizeMode_Fullscreen)
|
|
|
|
mLastSizeMode = mSizeMode;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2010-02-04 06:43:52 -08:00
|
|
|
mSizeMode = nsSizeMode_Fullscreen;
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showFullScreen();
|
2010-02-04 06:43:52 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSizeMode = mLastSizeMode;
|
|
|
|
|
|
|
|
switch (mSizeMode) {
|
|
|
|
case nsSizeMode_Maximized:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showMaximized();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Minimized:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showMinimized();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
case nsSizeMode_Normal:
|
2010-02-16 10:14:20 -08:00
|
|
|
GetViewWidget()->showNormal();
|
2010-02-04 06:43:52 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
|
|
|
|
"mLastSizeMode should never be fullscreen");
|
|
|
|
return NS_OK;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::HideWindowChrome(PRBool aShouldHide)
|
|
|
|
{
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget) {
|
2008-04-19 08:37:51 -07:00
|
|
|
// Pass the request to the toplevel window
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget *topWidget = nsnull;
|
2008-04-19 08:37:51 -07:00
|
|
|
GetToplevelWidget(&topWidget);
|
|
|
|
// return topWindow->HideWindowChrome(aShouldHide);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sawfish, metacity, and presumably other window managers get
|
|
|
|
// confused if we change the window decorations while the window
|
|
|
|
// is visible.
|
|
|
|
PRBool wasVisible = PR_FALSE;
|
2009-07-15 05:20:21 -07:00
|
|
|
if (mWidget->isVisible()) {
|
2009-08-04 19:39:05 -07:00
|
|
|
NativeShow(PR_FALSE);
|
2008-04-19 08:37:51 -07:00
|
|
|
wasVisible = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasVisible) {
|
2009-08-04 19:39:05 -07:00
|
|
|
NativeShow(PR_TRUE);
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For some window managers, adding or removing window decorations
|
|
|
|
// requires unmapping and remapping our toplevel window. Go ahead
|
|
|
|
// and flush the queue here so that we don't end up with a BadWindow
|
|
|
|
// error later when this happens (when the persistence timer fires
|
|
|
|
// and GetWindowPos is called)
|
2008-04-20 06:54:27 -07:00
|
|
|
#ifdef Q_WS_X11
|
2010-02-16 10:14:20 -08:00
|
|
|
XSync(GetViewWidget()->x11Info().display(), False);
|
2008-04-20 06:54:27 -07:00
|
|
|
#endif
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// These are all of our drag and drop operations
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::InitDragEvent(nsMouseEvent &aEvent)
|
|
|
|
{
|
|
|
|
// set the keyboard modifiers
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will update the drag action based on the information in the
|
2010-02-16 10:14:20 -08:00
|
|
|
// drag context.
|
2008-04-19 08:37:51 -07:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
initialize_prefs(void)
|
|
|
|
{
|
|
|
|
// check to see if we should set our raise pref
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRBool val = PR_TRUE;
|
|
|
|
nsresult rv;
|
|
|
|
rv = prefs->GetBoolPref("mozilla.widget.raise-on-setfocus", &val);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
is_context_menu_key(const nsKeyEvent& aKeyEvent)
|
|
|
|
{
|
|
|
|
return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.isShift &&
|
|
|
|
!aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt) ||
|
|
|
|
(aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.isShift &&
|
|
|
|
!aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
key_event_to_context_menu_event(nsMouseEvent &aEvent,
|
|
|
|
QKeyEvent *aGdkEvent)
|
|
|
|
{
|
2009-02-11 05:51:06 -08:00
|
|
|
aEvent.refPoint = nsIntPoint(0, 0);
|
2008-04-19 08:37:51 -07:00
|
|
|
aEvent.isShift = PR_FALSE;
|
|
|
|
aEvent.isControl = PR_FALSE;
|
|
|
|
aEvent.isAlt = PR_FALSE;
|
|
|
|
aEvent.isMeta = PR_FALSE;
|
|
|
|
aEvent.time = 0;
|
|
|
|
aEvent.clickCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsChildWindow class
|
|
|
|
|
|
|
|
nsChildWindow::nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChildWindow::~nsChildWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::nsPopupWindow()
|
|
|
|
{
|
|
|
|
qDebug("===================== popup!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindow::~nsPopupWindow()
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
MozQWidget*
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::createQWidget(MozQWidget *parent, nsWidgetInitData *aInitData)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
const char *windowName = NULL;
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
#ifdef DEBUG_WIDGETS
|
|
|
|
qDebug("NEW WIDGET\n\tparent is %p (%s)", (void*)parent,
|
|
|
|
parent ? qPrintable(parent->objectName()) : "null");
|
|
|
|
#endif
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
// ok, create our windows
|
|
|
|
switch (mWindowType) {
|
|
|
|
case eWindowType_dialog:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelDialog";
|
2010-02-16 10:14:20 -08:00
|
|
|
mIsTopLevel = PR_TRUE;
|
2008-04-20 01:16:40 -07:00
|
|
|
break;
|
2008-04-19 08:31:50 -07:00
|
|
|
case eWindowType_popup:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelPopup";
|
|
|
|
break;
|
2008-04-19 08:31:50 -07:00
|
|
|
case eWindowType_toplevel:
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "topLevelWindow";
|
2010-02-16 10:14:20 -08:00
|
|
|
mIsTopLevel = PR_TRUE;
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
2008-04-20 01:16:40 -07:00
|
|
|
case eWindowType_invisible:
|
|
|
|
windowName = "topLevelInvisible";
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
2008-04-20 01:16:40 -07:00
|
|
|
case eWindowType_child:
|
2009-09-24 02:32:20 -07:00
|
|
|
case eWindowType_plugin:
|
|
|
|
default: // sheet
|
2008-04-20 01:16:40 -07:00
|
|
|
windowName = "paintArea";
|
2008-04-19 08:31:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget * widget = new MozQWidget(this, parent);
|
|
|
|
if (!widget)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// create a QGraphicsView if this is a new toplevel window
|
|
|
|
MozQGraphicsView* newView = 0;
|
|
|
|
|
|
|
|
if (eWindowType_dialog == mWindowType ||
|
|
|
|
eWindowType_toplevel == mWindowType)
|
|
|
|
{
|
|
|
|
mScene = new QGraphicsScene();
|
|
|
|
if (!mScene) {
|
|
|
|
delete widget;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
newView = new MozQGraphicsView(mScene);
|
|
|
|
if (!newView) {
|
|
|
|
delete mScene;
|
|
|
|
delete widget;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
newView->show();
|
|
|
|
newView->raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mScene && newView) {
|
|
|
|
mScene->addItem(widget);
|
|
|
|
newView->setTopLevel(widget);
|
|
|
|
}
|
2009-07-15 05:20:21 -07:00
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
2010-02-16 10:14:20 -08:00
|
|
|
widget->setZValue(100);
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
// XXX is this needed for Qt?
|
|
|
|
// gdk does not automatically set the cursor for "temporary"
|
|
|
|
// windows, which are what gtk uses for popups.
|
|
|
|
SetCursor(eCursor_standard);
|
|
|
|
} else if (mIsTopLevel) {
|
|
|
|
SetDefaultIcon();
|
|
|
|
}
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
return widget;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
// return the gfxASurface for rendering to this widget
|
2008-04-19 08:31:50 -07:00
|
|
|
gfxASurface*
|
|
|
|
nsWindow::GetThebesSurface()
|
|
|
|
{
|
2008-04-28 18:16:45 -07:00
|
|
|
/* This is really a dummy surface; this is only used when doing reflow, because
|
|
|
|
* we need a RenderingContext to measure text against.
|
|
|
|
*/
|
2010-02-19 19:46:54 -08:00
|
|
|
if (mThebesSurface)
|
|
|
|
return mThebesSurface;
|
|
|
|
|
|
|
|
gfxQtPlatform::RenderMode renderMode = gfxQtPlatform::GetPlatform()->GetRenderMode();
|
|
|
|
if (renderMode == gfxQtPlatform::RENDER_QPAINTER) {
|
|
|
|
mThebesSurface = new gfxQPainterSurface(gfxIntSize(1, 1), gfxASurface::CONTENT_COLOR);
|
|
|
|
} else if (renderMode == gfxQtPlatform::RENDER_XLIB) {
|
|
|
|
mThebesSurface = new gfxXlibSurface(QX11Info().display(),
|
|
|
|
(Visual*)QX11Info().visual(),
|
|
|
|
gfxIntSize(1, 1), QX11Info().depth());
|
|
|
|
}
|
|
|
|
if (!mThebesSurface) {
|
|
|
|
gfxASurface::gfxImageFormat imageFormat = gfxASurface::ImageFormatRGB24;
|
|
|
|
mThebesSurface = new gfxImageSurface(gfxIntSize(1, 1), imageFormat);
|
|
|
|
}
|
2008-04-19 08:31:50 -07:00
|
|
|
|
|
|
|
return mThebesSurface;
|
|
|
|
}
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-19 08:37:51 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
|
|
|
|
if (aEvent->eventStructType != NS_MOUSE_EVENT) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// you can only begin a resize drag with a mouse event
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMouseEvent* mouse_event = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
|
|
|
|
if (mouse_event->button != nsMouseEvent::eLeftButton) {
|
2010-02-16 10:14:20 -08:00
|
|
|
// you can only begin a resize drag with the left mouse button
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-04-19 08:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2010-02-16 10:14:20 -08:00
|
|
|
nsWindow::contextMenuEvent(QGraphicsSceneContextMenuEvent *)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::imStartEvent(QEvent *)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::imComposeEvent(QEvent *)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:16:40 -07:00
|
|
|
nsEventStatus
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow::imEndEvent(QEvent * )
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2008-04-20 01:16:40 -07:00
|
|
|
return nsEventStatus_eIgnore;
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
nsIWidget *
|
|
|
|
nsWindow::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchActivateEvent(void)
|
|
|
|
{
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this);
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DispatchDeactivateEvent(void)
|
|
|
|
{
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this);
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-11 05:51:06 -08:00
|
|
|
nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
|
|
|
nsSizeEvent event(PR_TRUE, NS_SIZE, this);
|
|
|
|
|
|
|
|
event.windowSize = &aRect;
|
|
|
|
event.refPoint.x = aRect.x;
|
|
|
|
event.refPoint.y = aRect.y;
|
|
|
|
event.mWinWidth = aRect.width;
|
|
|
|
event.mWinHeight = aRect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent,
|
|
|
|
nsEventStatus &aStatus)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, aEvent->widget, aEvent,
|
|
|
|
nsCAutoString("something"), 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// send it to the standard callback
|
|
|
|
if (mEventCallback)
|
|
|
|
aStatus = (* mEventCallback)(aEvent);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Show(PRBool aState)
|
|
|
|
{
|
|
|
|
LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState));
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
mIsShown = aState;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-22 04:21:18 -07:00
|
|
|
return NS_OK;
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setVisible(aState);
|
2008-08-16 00:07:21 -07:00
|
|
|
if (mWindowType == eWindowType_popup && aState)
|
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, PR_FALSE);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->resize(aWidth, aHeight);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
GetViewWidget()->resize(aWidth,aHeight);
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-22 04:21:17 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
|
2008-04-22 04:21:18 -07:00
|
|
|
PRBool aRepaint)
|
2008-04-22 04:21:17 -07:00
|
|
|
{
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
|
|
|
|
mPlaced = PR_TRUE;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
if (!mWidget)
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->setGeometry(aX, aY, aWidth, aHeight);
|
2008-04-22 04:21:17 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mIsTopLevel) {
|
|
|
|
GetViewWidget()->resize(aWidth,aHeight);
|
|
|
|
}
|
|
|
|
|
2008-04-22 04:21:18 -07:00
|
|
|
if (aRepaint)
|
2009-07-15 05:20:21 -07:00
|
|
|
mWidget->update();
|
2008-04-22 04:21:18 -07:00
|
|
|
|
2008-04-22 04:21:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Enable(PRBool aState)
|
|
|
|
{
|
|
|
|
mEnabled = aState;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsEnabled(PRBool *aState)
|
|
|
|
{
|
|
|
|
*aState = mEnabled;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::OnDestroy(void)
|
|
|
|
{
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mOnDestroyCalled = PR_TRUE;
|
|
|
|
|
|
|
|
// release references to children, device context, toolkit + app shell
|
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
|
|
|
// let go of our parent
|
|
|
|
mParent = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
|
|
|
|
|
|
|
|
nsGUIEvent event(PR_TRUE, NS_DESTROY, this);
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsWindow::AreBoundsSane(void)
|
|
|
|
{
|
|
|
|
if (mBounds.width > 0 && mBounds.height > 0)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|