2010-08-26 14:52:22 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 et sw=4 tw=80: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* 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 Nokia.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Nokia Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 15:31:50 +00:00
|
|
|
#ifndef MOZQWIDGET_H
|
|
|
|
#define MOZQWIDGET_H
|
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
2010-03-04 21:51:42 +00:00
|
|
|
#include "nsIWidget.h"
|
2010-04-02 14:08:30 +00:00
|
|
|
#include "prenv.h"
|
2010-03-04 21:51:42 +00:00
|
|
|
|
2010-08-30 23:49:11 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
|
2011-03-16 04:41:53 +00:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include "mozqorientationsensorfilter.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-25 13:22:34 +00:00
|
|
|
#ifdef MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
#include <QtGui/QGraphicsSceneResizeEvent>
|
|
|
|
#include <MSceneWindow>
|
|
|
|
#include <MScene>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <MInputMethodState>
|
|
|
|
#include <MApplication>
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
class QEvent;
|
2010-02-16 18:14:20 +00:00
|
|
|
class QPixmap;
|
|
|
|
class QWidget;
|
|
|
|
|
2008-04-19 15:37:51 +00:00
|
|
|
class nsWindow;
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
class MozQWidget : public QGraphicsWidget
|
2008-04-19 15:31:50 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2010-02-16 18:14:20 +00:00
|
|
|
MozQWidget(nsWindow* aReceiver, QGraphicsItem *aParent);
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2009-03-27 11:35:27 +00:00
|
|
|
~MozQWidget();
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
/**
|
|
|
|
* Mozilla helper.
|
|
|
|
*/
|
|
|
|
void setModal(bool);
|
2008-04-19 15:37:55 +00:00
|
|
|
bool SetCursor(nsCursor aCursor);
|
2008-04-20 08:16:40 +00:00
|
|
|
void dropReceiver() { mReceiver = 0x0; };
|
|
|
|
nsWindow* getReceiver() { return mReceiver; };
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2010-02-25 18:58:19 +00:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery aQuery) const;
|
|
|
|
|
2010-03-12 22:07:32 +00:00
|
|
|
/**
|
|
|
|
* VirtualKeyboardIntegration
|
|
|
|
*/
|
2010-08-03 20:17:44 +00:00
|
|
|
void requestVKB(int aTimeout);
|
2010-03-12 22:07:32 +00:00
|
|
|
void hideVKB();
|
|
|
|
bool isVKBOpen();
|
|
|
|
|
2010-08-03 20:17:44 +00:00
|
|
|
public slots:
|
|
|
|
void showVKB();
|
|
|
|
|
2011-03-16 04:41:53 +00:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
void orientationChanged();
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
protected:
|
2010-02-16 18:14:20 +00:00
|
|
|
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* aEvent);
|
|
|
|
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dropEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void focusInEvent(QFocusEvent* aEvent);
|
|
|
|
virtual void focusOutEvent(QFocusEvent* aEvent);
|
|
|
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void keyPressEvent(QKeyEvent* aEvent);
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent* aEvent);
|
|
|
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* aEvent);
|
2011-01-28 11:00:31 +00:00
|
|
|
virtual void inputMethodEvent(QInputMethodEvent* aEvent);
|
2010-03-12 22:06:17 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
virtual void wheelEvent(QGraphicsSceneWheelEvent* aEvent);
|
|
|
|
virtual void paint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget = 0);
|
|
|
|
virtual void resizeEvent(QGraphicsSceneResizeEvent* aEvent);
|
|
|
|
virtual void closeEvent(QCloseEvent* aEvent);
|
|
|
|
virtual void hideEvent(QHideEvent* aEvent);
|
|
|
|
virtual void showEvent(QShowEvent* aEvent);
|
2010-03-12 22:11:42 +00:00
|
|
|
virtual bool event(QEvent* aEvent);
|
2010-03-12 22:06:17 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
bool SetCursor(const QPixmap& aPixmap, int, int);
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
private:
|
2011-01-28 11:00:31 +00:00
|
|
|
void sendPressReleaseKeyEvent(int key, const QChar* letter = 0, bool autorep = false, ushort count = 1);
|
2008-04-19 15:37:51 +00:00
|
|
|
nsWindow *mReceiver;
|
2008-04-19 15:31:50 +00:00
|
|
|
};
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
class MozQGraphicsViewEvents
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-07-29 01:05:56 +00:00
|
|
|
MozQGraphicsViewEvents(QGraphicsView* aView)
|
|
|
|
: mView(aView)
|
2010-03-12 22:06:17 +00:00
|
|
|
{ }
|
2010-02-25 18:58:19 +00:00
|
|
|
|
2010-07-29 01:05:56 +00:00
|
|
|
void handleEvent(QEvent* aEvent, MozQWidget* aTopLevel)
|
2010-02-25 18:58:19 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-02-25 18:58:19 +00:00
|
|
|
if (aEvent->type() == QEvent::WindowActivate) {
|
2010-07-29 01:05:56 +00:00
|
|
|
if (aTopLevel)
|
|
|
|
aTopLevel->activate();
|
2010-02-25 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->type() == QEvent::WindowDeactivate) {
|
2010-07-29 01:05:56 +00:00
|
|
|
if (aTopLevel)
|
|
|
|
aTopLevel->deactivate();
|
2010-02-25 18:58:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-29 01:05:56 +00:00
|
|
|
void handleResizeEvent(QResizeEvent* aEvent, MozQWidget* aTopLevel)
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-07-29 01:05:56 +00:00
|
|
|
if (aTopLevel) {
|
2010-02-16 18:14:20 +00:00
|
|
|
// transfer new size to graphics widget
|
2010-07-29 01:05:56 +00:00
|
|
|
aTopLevel->setGeometry(0.0, 0.0,
|
2010-02-16 18:14:20 +00:00
|
|
|
static_cast<qreal>(aEvent->size().width()),
|
|
|
|
static_cast<qreal>(aEvent->size().height()));
|
2010-02-25 20:45:37 +00:00
|
|
|
// resize scene rect to vieport size,
|
|
|
|
// to avoid extra scrolling from QAbstractScrollable
|
2010-03-12 22:06:17 +00:00
|
|
|
if (mView)
|
|
|
|
mView->setSceneRect(mView->viewport()->rect());
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-29 01:05:56 +00:00
|
|
|
bool handleCloseEvent(QCloseEvent* aEvent, MozQWidget* aTopLevel)
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return false;
|
2010-07-29 01:05:56 +00:00
|
|
|
if (aTopLevel) {
|
2010-02-16 18:14:20 +00:00
|
|
|
// close graphics widget instead, this view will be discarded
|
|
|
|
// automatically
|
2010-07-29 01:05:56 +00:00
|
|
|
QApplication::postEvent(aTopLevel, new QCloseEvent(*aEvent));
|
2010-02-16 18:14:20 +00:00
|
|
|
aEvent->ignore();
|
2010-03-12 22:06:17 +00:00
|
|
|
return true;
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
2010-03-12 22:06:17 +00:00
|
|
|
|
|
|
|
return false;
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-03-12 22:06:17 +00:00
|
|
|
QGraphicsView* mView;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a helper class to synchronize the QGraphicsView window with
|
|
|
|
its contained QGraphicsWidget for things like resizing and closing
|
|
|
|
by the user.
|
|
|
|
*/
|
|
|
|
class MozQGraphicsView : public QGraphicsView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MozQGraphicsView(MozQWidget* aTopLevel, QWidget * aParent = nsnull)
|
|
|
|
: QGraphicsView (new QGraphicsScene(), aParent)
|
2010-07-29 01:05:56 +00:00
|
|
|
, mEventHandler(this)
|
2010-06-24 10:07:57 +00:00
|
|
|
, mTopLevelWidget(aTopLevel)
|
2010-03-12 22:06:17 +00:00
|
|
|
{
|
|
|
|
scene()->addItem(aTopLevel);
|
2011-02-03 21:27:01 +00:00
|
|
|
setMouseTracking(true);
|
2011-03-15 20:30:34 +00:00
|
|
|
setFrameShape(QFrame::NoFrame);
|
2010-03-12 22:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual bool event(QEvent* aEvent)
|
|
|
|
{
|
2010-07-29 01:05:56 +00:00
|
|
|
mEventHandler.handleEvent(aEvent, mTopLevelWidget);
|
2010-03-12 22:06:17 +00:00
|
|
|
return QGraphicsView::event(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void resizeEvent(QResizeEvent* aEvent)
|
|
|
|
{
|
2010-07-29 01:05:56 +00:00
|
|
|
mEventHandler.handleResizeEvent(aEvent, mTopLevelWidget);
|
2010-03-12 22:06:17 +00:00
|
|
|
QGraphicsView::resizeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void closeEvent (QCloseEvent* aEvent)
|
|
|
|
{
|
2010-07-29 01:05:56 +00:00
|
|
|
if (!mEventHandler.handleCloseEvent(aEvent, mTopLevelWidget))
|
2010-03-12 22:06:17 +00:00
|
|
|
QGraphicsView::closeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQGraphicsViewEvents mEventHandler;
|
2010-06-24 10:07:57 +00:00
|
|
|
MozQWidget* mTopLevelWidget;
|
2010-02-16 18:14:20 +00:00
|
|
|
};
|
|
|
|
|
2011-06-25 13:22:34 +00:00
|
|
|
#ifdef MOZ_ENABLE_MEEGOTOUCH
|
|
|
|
class MozMSceneWindow : public MSceneWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
MozMSceneWindow(MozQWidget* aTopLevel)
|
|
|
|
: MSceneWindow(aTopLevel->parentItem())
|
|
|
|
, mTopLevelWidget(aTopLevel)
|
|
|
|
{
|
|
|
|
mTopLevelWidget->setParentItem(this);
|
|
|
|
mTopLevelWidget->installEventFilter(this);
|
|
|
|
MInputMethodState* inputMethodState = MInputMethodState::instance();
|
|
|
|
if (inputMethodState) {
|
|
|
|
connect(inputMethodState, SIGNAL(inputMethodAreaChanged(const QRect&)),
|
|
|
|
this, SLOT(VisibleScreenAreaChanged(const QRect&)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void resizeEvent(QGraphicsSceneResizeEvent* aEvent)
|
|
|
|
{
|
|
|
|
mCurrentSize = aEvent->newSize();
|
|
|
|
MSceneWindow::resizeEvent(aEvent);
|
|
|
|
CheckTopLevelSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool eventFilter(QObject* watched, QEvent* e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::GraphicsSceneResize ||
|
|
|
|
e->type() == QEvent::GraphicsSceneMove) {
|
|
|
|
|
|
|
|
//Do this in next event loop, or we are in recursion!
|
|
|
|
QTimer::singleShot(0, this, SLOT(CheckTopLevelSize()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void CheckTopLevelSize()
|
|
|
|
{
|
|
|
|
if (mTopLevelWidget) {
|
|
|
|
qreal xpos = 0;
|
|
|
|
qreal ypos = 0;
|
|
|
|
qreal width = mCurrentSize.width();
|
|
|
|
qreal height = mCurrentSize.height();
|
|
|
|
|
|
|
|
// transfer new size to graphics widget if changed
|
|
|
|
QRectF r = mTopLevelWidget->geometry();
|
|
|
|
if (r != QRectF(xpos, ypos, width, height)) {
|
|
|
|
mTopLevelWidget->setGeometry(xpos, ypos, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisibleScreenAreaChanged(const QRect& rect) {
|
|
|
|
if (mTopLevelWidget) {
|
2011-07-13 13:59:28 +00:00
|
|
|
QRegion region(scene()->views()[0]->rect());
|
|
|
|
region -= rect;
|
|
|
|
QRectF bounds = mapRectFromScene(region.boundingRect());
|
2011-06-25 13:22:34 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
QString rect = QString("{\"left\": %1, \"top\": %2, \"right\": %3, \"bottom\": %4}")
|
2011-07-13 13:59:28 +00:00
|
|
|
.arg(bounds.x()).arg(bounds.y()).arg(bounds.width()).arg(bounds.height());
|
2011-06-25 13:22:34 +00:00
|
|
|
observerService->NotifyObservers(nsnull, "softkb-change", rect.utf16());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQWidget* mTopLevelWidget;
|
|
|
|
QSizeF mCurrentSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a helper class to synchronize the MWindow window with
|
|
|
|
its contained QGraphicsWidget for things like resizing and closing
|
|
|
|
by the user.
|
|
|
|
*/
|
|
|
|
class MozMGraphicsView : public MWindow
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
MozMGraphicsView(MozQWidget* aTopLevel, QWidget* aParent = nsnull)
|
|
|
|
: MWindow(aParent)
|
|
|
|
, mEventHandler(this)
|
|
|
|
, mTopLevelWidget(aTopLevel)
|
|
|
|
{
|
|
|
|
MozMSceneWindow* page = new MozMSceneWindow(aTopLevel);
|
|
|
|
page->appear(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool event(QEvent* aEvent) {
|
|
|
|
mEventHandler.handleEvent(aEvent, mTopLevelWidget);
|
|
|
|
return MWindow::event(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void resizeEvent(QResizeEvent* aEvent)
|
|
|
|
{
|
|
|
|
setSceneRect(viewport()->rect());
|
|
|
|
MWindow::resizeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void closeEvent (QCloseEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mEventHandler.handleCloseEvent(aEvent, mTopLevelWidget)) {
|
|
|
|
MWindow::closeEvent(aEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQGraphicsViewEvents mEventHandler;
|
|
|
|
MozQWidget* mTopLevelWidget;
|
|
|
|
};
|
2010-08-03 17:44:52 +00:00
|
|
|
|
2011-06-25 13:22:34 +00:00
|
|
|
#endif /* MOZ_ENABLE_MEEGOTOUCH */
|
2008-04-19 15:31:50 +00:00
|
|
|
#endif
|