Changeset 72650 in webkit


Ignore:
Timestamp:
Nov 24, 2010 1:34:56 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

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):
Location:
trunk/WebKit/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/Api/qgraphicswebview.cpp

    r72612 r72650  
    5454        : q(parent)
    5555        , page(0)
    56         , resizesToContents(false) {}
     56        , resizesToContents(false)
     57        , currentScene(0) {}
    5758
    5859    virtual ~QGraphicsWebViewPrivate();
     
    7677    QWebPage* page;
    7778    bool resizesToContents;
     79    QGraphicsScene* currentScene;
    7880
    7981    QGraphicsItemOverlay* overlay() const
     
    253255    QObject::connect(this, SIGNAL(scaleChanged()), this, SLOT(_q_scaleChanged()));
    254256#endif
     257
     258    if (scene()) {
     259        d->currentScene = scene();
     260        d->currentScene->installEventFilter(this);
     261    }
    255262}
    256263
     
    305312    page()->mainFrame()->render(painter, QWebFrame::AllLayers, option->exposedRect.toRect());
    306313#endif
     314}
     315
     316/*! \reimp
     317*/
     318bool QGraphicsWebView::eventFilter(QObject* object, QEvent* event)
     319{
     320    if (object == d->currentScene
     321        && (event->type() == QEvent::FocusIn
     322            || event->type() == QEvent::FocusOut)) {
     323        QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event);
     324        if (focusEvent->reason() == Qt::ActiveWindowFocusReason)
     325            d->page->event(event);
     326    }
     327    return false;
    307328}
    308329
     
    342363            QApplication::sendEvent(this, &event);
    343364            return value;
     365        }
     366    case ItemSceneHasChanged: {
     367            QGraphicsScene* newScene = qVariantValue<QGraphicsScene*>(value);
     368            if (d->currentScene)
     369                d->currentScene->removeEventFilter(this);
     370            d->currentScene = newScene;
     371            if (d->currentScene)
     372                d->currentScene->installEventFilter(this);
    344373        }
    345374    default:
  • trunk/WebKit/qt/Api/qgraphicswebview.h

    r68457 r72650  
    141141    virtual bool sceneEvent(QEvent*);
    142142
     143    virtual bool eventFilter(QObject*, QEvent*);
     144
    143145private:
    144146    Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
  • trunk/WebKit/qt/ChangeLog

    r72612 r72650  
     12010-11-24  Jan Erik Hanssen  <jhanssen@sencha.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Html autofocus not working with QGraphicsWebView
     6        https://bugs.webkit.org/show_bug.cgi?id=43169
     7
     8        QGraphicsScene does not propagate Qt::ActivateWindowFocusReason focus
     9        events when there are no active items.
     10
     11        * Api/qgraphicswebview.cpp:
     12        (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate):
     13        (QGraphicsWebView::QGraphicsWebView):
     14        (QGraphicsWebView::eventFilter):
     15        (QGraphicsWebView::itemChange):
     16        * Api/qgraphicswebview.h:
     17        * tests/qgraphicswebview/tst_qgraphicswebview.cpp:
     18        (FocusPage::FocusPage):
     19        (FocusPage::event):
     20        (FocusPage::gotFocus):
     21        (tst_QGraphicsWebView::receivesFocusInOnShow):
     22
    1232010-11-23  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    224
  • trunk/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp

    r70556 r72650  
    3737    void crashOnSetScaleBeforeSetUrl();
    3838    void widgetsRenderingThroughCache();
     39    void receivesFocusInOnShow();
    3940};
    4041
     
    260261}
    261262
     263class FocusPage : public QWebPage {
     264public:
     265    FocusPage(QObject* parent = 0);
     266
     267    bool gotFocus() const;
     268
     269protected:
     270    bool event(QEvent* e);
     271
     272private:
     273    bool m_focus;
     274};
     275
     276FocusPage::FocusPage(QObject *parent)
     277    : QWebPage(parent), m_focus(false)
     278{
     279}
     280
     281bool FocusPage::event(QEvent *e)
     282{
     283    if (e->type() == QEvent::FocusIn)
     284        m_focus = true;
     285    return QWebPage::event(e);
     286}
     287
     288bool FocusPage::gotFocus() const
     289{
     290    return m_focus;
     291}
     292
     293void tst_QGraphicsWebView::receivesFocusInOnShow()
     294{
     295    QGraphicsWebView webView;
     296    webView.setHtml("<body><input type=text autofocus=autofocus></input></body>");
     297    FocusPage page;
     298    webView.setPage(&page);
     299
     300    for (int i = 0; i < 3; ++i) {
     301        QGraphicsView view;
     302        QGraphicsScene* scene = new QGraphicsScene(&view);
     303        view.setScene(scene);
     304        scene->addItem(&webView);
     305        view.setGeometry(QRect(0, 0, 500, 500));
     306
     307        view.show();
     308        QTest::qWaitForWindowShown(&view);
     309
     310        QVERIFY(page.gotFocus());
     311
     312        scene->removeItem(&webView);
     313    }
     314}
    262315
    263316
Note: See TracChangeset for help on using the changeset viewer.