2010-11-24 Jan Erik Hanssen <jhanssen@sencha.com>

        Reviewed by Kenneth Rohde Christiansen.

        [Qt] Html autofocus not working with QGraphicsWebView
        https://bugs.webkit.org/show_bug.cgi?id=43169

        QGraphicsScene does not propagate Qt::ActivateWindowFocusReason focus
        events when there are no active items.

        * Api/qgraphicswebview.cpp:
        (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate):
        (QGraphicsWebView::QGraphicsWebView):
        (QGraphicsWebView::eventFilter):
        (QGraphicsWebView::itemChange):
        * Api/qgraphicswebview.h:
        * tests/qgraphicswebview/tst_qgraphicswebview.cpp:
        (FocusPage::FocusPage):
        (FocusPage::event):
        (FocusPage::gotFocus):
        (tst_QGraphicsWebView::receivesFocusInOnShow):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72650 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 334460ec
......@@ -53,7 +53,8 @@ public:
QGraphicsWebViewPrivate(QGraphicsWebView* parent)
: q(parent)
, page(0)
, resizesToContents(false) {}
, resizesToContents(false)
, currentScene(0) {}
virtual ~QGraphicsWebViewPrivate();
......@@ -75,6 +76,7 @@ public:
QGraphicsWebView* q;
QWebPage* page;
bool resizesToContents;
QGraphicsScene* currentScene;
QGraphicsItemOverlay* overlay() const
{
......@@ -252,6 +254,11 @@ QGraphicsWebView::QGraphicsWebView(QGraphicsItem* parent)
#if ENABLE(TILED_BACKING_STORE)
QObject::connect(this, SIGNAL(scaleChanged()), this, SLOT(_q_scaleChanged()));
#endif
if (scene()) {
d->currentScene = scene();
d->currentScene->installEventFilter(this);
}
}
/*!
......@@ -306,6 +313,20 @@ void QGraphicsWebView::paint(QPainter* painter, const QStyleOptionGraphicsItem*
#endif
}
/*! \reimp
*/
bool QGraphicsWebView::eventFilter(QObject* object, QEvent* event)
{
if (object == d->currentScene
&& (event->type() == QEvent::FocusIn
|| event->type() == QEvent::FocusOut)) {
QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event);
if (focusEvent->reason() == Qt::ActiveWindowFocusReason)
d->page->event(event);
}
return false;
}
/*! \reimp
*/
bool QGraphicsWebView::sceneEvent(QEvent* event)
......@@ -342,6 +363,14 @@ QVariant QGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant&
QApplication::sendEvent(this, &event);
return value;
}
case ItemSceneHasChanged: {
QGraphicsScene* newScene = qVariantValue<QGraphicsScene*>(value);
if (d->currentScene)
d->currentScene->removeEventFilter(this);
d->currentScene = newScene;
if (d->currentScene)
d->currentScene->installEventFilter(this);
}
default:
break;
}
......
......@@ -140,6 +140,8 @@ protected:
virtual bool sceneEvent(QEvent*);
virtual bool eventFilter(QObject*, QEvent*);
private:
Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
......
2010-11-24 Jan Erik Hanssen <jhanssen@sencha.com>
Reviewed by Kenneth Rohde Christiansen.
[Qt] Html autofocus not working with QGraphicsWebView
https://bugs.webkit.org/show_bug.cgi?id=43169
QGraphicsScene does not propagate Qt::ActivateWindowFocusReason focus
events when there are no active items.
* Api/qgraphicswebview.cpp:
(QGraphicsWebViewPrivate::QGraphicsWebViewPrivate):
(QGraphicsWebView::QGraphicsWebView):
(QGraphicsWebView::eventFilter):
(QGraphicsWebView::itemChange):
* Api/qgraphicswebview.h:
* tests/qgraphicswebview/tst_qgraphicswebview.cpp:
(FocusPage::FocusPage):
(FocusPage::event):
(FocusPage::gotFocus):
(tst_QGraphicsWebView::receivesFocusInOnShow):
2010-11-23 Kenneth Rohde Christiansen <kenneth@webkit.org>
Reviewed by Andreas Kling.
......
......@@ -36,6 +36,7 @@ private slots:
void focusInputTypes();
void crashOnSetScaleBeforeSetUrl();
void widgetsRenderingThroughCache();
void receivesFocusInOnShow();
};
void tst_QGraphicsWebView::qgraphicswebview()
......@@ -259,6 +260,58 @@ void tst_QGraphicsWebView::focusInputTypes()
delete view;
}
class FocusPage : public QWebPage {
public:
FocusPage(QObject* parent = 0);
bool gotFocus() const;
protected:
bool event(QEvent* e);
private:
bool m_focus;
};
FocusPage::FocusPage(QObject *parent)
: QWebPage(parent), m_focus(false)
{
}
bool FocusPage::event(QEvent *e)
{
if (e->type() == QEvent::FocusIn)
m_focus = true;
return QWebPage::event(e);
}
bool FocusPage::gotFocus() const
{
return m_focus;
}
void tst_QGraphicsWebView::receivesFocusInOnShow()
{
QGraphicsWebView webView;
webView.setHtml("<body><input type=text autofocus=autofocus></input></body>");
FocusPage page;
webView.setPage(&page);
for (int i = 0; i < 3; ++i) {
QGraphicsView view;
QGraphicsScene* scene = new QGraphicsScene(&view);
view.setScene(scene);
scene->addItem(&webView);
view.setGeometry(QRect(0, 0, 500, 500));
view.show();
QTest::qWaitForWindowShown(&view);
QVERIFY(page.gotFocus());
scene->removeItem(&webView);
}
}
QTEST_MAIN(tst_QGraphicsWebView)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment