2010-08-26 07:52:22 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 et sw=4 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-26 07:52:22 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtGui/QResizeEvent>
|
|
|
|
|
2010-03-04 13:51:42 -08:00
|
|
|
#include "mozqwidget.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
using namespace mozilla::widget;
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
MozQWidget::MozQWidget(nsWindow* aReceiver, QWindow* aParent)
|
|
|
|
: QWindow(aParent)
|
|
|
|
, mReceiver(aReceiver)
|
|
|
|
, mUpdatePending(false)
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
2014-04-05 01:17:00 -07:00
|
|
|
mWindowType = mReceiver->WindowType();
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2009-03-27 04:35:27 -07:00
|
|
|
MozQWidget::~MozQWidget()
|
|
|
|
{
|
2010-02-25 10:58:19 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::render(QPainter* painter)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
Q_UNUSED(painter);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::renderLater()
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!mUpdatePending) {
|
|
|
|
mUpdatePending = true;
|
|
|
|
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::renderNow()
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mReceiver->OnPaint();
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
bool MozQWidget::event(QEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::UpdateRequest:
|
|
|
|
mUpdatePending = false;
|
|
|
|
renderNow();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return QWindow::event(event);
|
|
|
|
}
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::exposeEvent(QExposeEvent* event)
|
2011-03-15 21:41:53 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
Q_UNUSED(event);
|
|
|
|
if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) {
|
2011-03-15 21:41:53 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p] flags:%x\n", __FUNCTION__, (void *)this, flags()));
|
|
|
|
renderNow();
|
2011-03-15 21:41:53 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::resizeEvent(QResizeEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->resizeEvent(event);
|
|
|
|
QWindow::resizeEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::focusInEvent(QFocusEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->focusInEvent(event);
|
|
|
|
QWindow::focusInEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::focusOutEvent(QFocusEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->focusOutEvent(event);
|
|
|
|
QWindow::focusOutEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::hideEvent(QHideEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->hideEvent(event);
|
|
|
|
QWindow::hideEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::keyPressEvent(QKeyEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->keyPressEvent(event);
|
|
|
|
QWindow::keyPressEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::keyReleaseEvent(QKeyEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->keyReleaseEvent(event);
|
|
|
|
QWindow::keyReleaseEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::mouseDoubleClickEvent(QMouseEvent* event)
|
2011-01-28 03:00:31 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->mouseDoubleClickEvent(event);
|
|
|
|
QWindow::mouseDoubleClickEvent(event);
|
2011-01-28 03:00:31 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::mouseMoveEvent(QMouseEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
mReceiver->mouseMoveEvent(event);
|
|
|
|
QWindow::mouseMoveEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::mousePressEvent(QMouseEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->mousePressEvent(event);
|
|
|
|
QWindow::mousePressEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::mouseReleaseEvent(QMouseEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->mouseReleaseEvent(event);
|
|
|
|
QWindow::mouseReleaseEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::moveEvent(QMoveEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->moveEvent(event);
|
|
|
|
QWindow::moveEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::showEvent(QShowEvent* event)
|
2010-03-12 14:11:42 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->showEvent(event);
|
|
|
|
QWindow::showEvent(event);
|
2010-03-12 14:11:42 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::wheelEvent(QWheelEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
mReceiver->wheelEvent(event);
|
|
|
|
QWindow::wheelEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
2008-04-20 01:37:07 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::tabletEvent(QTabletEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
QWindow::tabletEvent(event);
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void MozQWidget::touchEvent(QTouchEvent* event)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this));
|
|
|
|
QWindow::touchEvent(event);
|
2008-04-19 08:31:50 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 10:28:26 -07:00
|
|
|
void MozQWidget::SetCursor(nsCursor aCursor)
|
2008-04-19 08:37:55 -07:00
|
|
|
{
|
|
|
|
Qt::CursorShape cursor = Qt::ArrowCursor;
|
|
|
|
switch(aCursor) {
|
|
|
|
case eCursor_standard:
|
|
|
|
cursor = Qt::ArrowCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_wait:
|
|
|
|
cursor = Qt::WaitCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_select:
|
|
|
|
cursor = Qt::IBeamCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_hyperlink:
|
|
|
|
cursor = Qt::PointingHandCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_ew_resize:
|
|
|
|
cursor = Qt::SplitHCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_ns_resize:
|
|
|
|
cursor = Qt::SplitVCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_nw_resize:
|
|
|
|
case eCursor_se_resize:
|
|
|
|
cursor = Qt::SizeBDiagCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_ne_resize:
|
|
|
|
case eCursor_sw_resize:
|
|
|
|
cursor = Qt::SizeFDiagCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_crosshair:
|
|
|
|
case eCursor_move:
|
|
|
|
cursor = Qt::SizeAllCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_help:
|
|
|
|
cursor = Qt::WhatsThisCursor;
|
|
|
|
break;
|
|
|
|
case eCursor_copy:
|
|
|
|
case eCursor_alias:
|
|
|
|
break;
|
|
|
|
case eCursor_context_menu:
|
|
|
|
case eCursor_cell:
|
|
|
|
case eCursor_grab:
|
|
|
|
case eCursor_grabbing:
|
|
|
|
case eCursor_spinning:
|
|
|
|
case eCursor_zoom_in:
|
|
|
|
case eCursor_zoom_out:
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor);
|
|
|
|
}
|