Changeset 39232 in webkit


Ignore:
Timestamp:
Dec 12, 2008, 1:42:16 AM (16 years ago)
Author:
Simon Hausmann
Message:

2008-12-11 Enrico Ros <enrico.ros@m31.com>

Reviewed by Simon Hausmann.

Fix the broken focus behavior that happened when QWebPage lost
focus to a popup menu.

The previous code didn't notify the QWebPage at all when the
focus was back in (breaking focus rects, caret blinking, ...).
By the way when a popup is show, 2 FocusOut events are delivered
to the QWebPage, but this doesn't seem to hurt.

Added a test to check popup opening, closing a lineedit blinks.

Location:
trunk/WebKit/qt
Files:
3 edited

Legend:

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

    r39210 r39232  
    730730void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
    731731{
    732     if (ev->reason() == Qt::PopupFocusReason)
    733         return;
    734 
    735732    FocusController *focusController = page->focusController();
    736733    Frame *frame = focusController->focusedFrame();
     
    745742void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
    746743{
    747     if (ev->reason() == Qt::PopupFocusReason)
    748         return;
    749 
    750744    // only set the focused frame inactive so that we stop painting the caret
    751745    // and the focus frame. But don't tell the focus controller so that upon
  • trunk/WebKit/qt/ChangeLog

    r39231 r39232  
     12008-12-11  Enrico Ros  <enrico.ros@m31.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Fix the broken focus behavior that happened when QWebPage lost
     6        focus to a popup menu.
     7
     8        The previous code didn't notify the QWebPage at all when the
     9        focus was back in (breaking focus rects, caret blinking, ...).
     10        By the way when a popup is show, 2 FocusOut events are delivered
     11        to the QWebPage, but this doesn't seem to hurt.
     12
     13        Added a test to check popup opening, closing a lineedit blinks.
     14
     15        * Api/qwebpage.cpp:
     16        (QWebPagePrivate::focusInEvent):
     17        (QWebPagePrivate::focusOutEvent):
     18        * tests/qwebframe/tst_qwebframe.cpp:
     19        (tst_QWebFrame::):
     20
    1212008-12-11  Ariya Hidayat  <ariya.hidayat@trolltech.com>
    222
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r38947 r39232  
    2626#include <qwebframe.h>
    2727#include <qwebhistory.h>
     28#include <QAbstractItemView>
     29#include <QApplication>
     30#include <QComboBox>
    2831#include <QRegExp>
    2932#include <QNetworkRequest>
     
    539542    tst_QWebFrame();
    540543    virtual ~tst_QWebFrame();
     544    bool eventFilter(QObject* watched, QEvent* event);
    541545
    542546public slots:
     
    568572    void ipv6HostEncoding();
    569573    void metaData();
     574    void popupFocus();
    570575private:
    571576    QString  evalJS(const QString&s) {
     
    613618        return ret;
    614619    }
     620    QObject* firstChildByClassName(QObject* parent, const char* className) {
     621        const QObjectList & children = parent->children();
     622        foreach (QObject* child, children) {
     623            if (!strcmp(child->metaObject()->className(), className)) {
     624                return child;
     625            }
     626        }
     627        return 0;
     628    }
    615629
    616630    const QString sTrue;
     
    628642    QWebPage* m_page;
    629643    MyQObject* m_myObject;
     644    QWebView* m_popupTestView;
     645    int m_popupTestPaintCount;
    630646};
    631647
    632648tst_QWebFrame::tst_QWebFrame()
    633649    : sTrue("true"), sFalse("false"), sUndefined("undefined"), sArray("array"), sFunction("function"), sError("error"),
    634         sString("string"), sObject("object"), sNumber("number")
     650        sString("string"), sObject("object"), sNumber("number"), m_popupTestView(0), m_popupTestPaintCount(0)
    635651{
    636652}
     
    638654tst_QWebFrame::~tst_QWebFrame()
    639655{
     656}
     657
     658bool tst_QWebFrame::eventFilter(QObject* watched, QEvent* event)
     659{
     660    // used on the popupFocus test
     661    if (watched == m_popupTestView) {
     662        if (event->type() == QEvent::Paint)
     663            m_popupTestPaintCount++;
     664    }
     665    return QObject::eventFilter(watched, event);
    640666}
    641667
     
    21742200}
    21752201
     2202void tst_QWebFrame::popupFocus()
     2203{
     2204    QWebView view;
     2205    view.setHtml("<html>"
     2206                 "    <body>"
     2207                 "        <select name=\"select\">"
     2208                 "            <option>1</option>"
     2209                 "            <option>2</option>"
     2210                 "        </select>"
     2211                 "        <input type=\"text\"> </input>"
     2212                 "        <textarea name=\"text_area\" rows=\"3\" cols=\"40\">"
     2213                 "This test checks whether showing and hiding a popup"
     2214                 "takes the focus away from the webpage."
     2215                 "        </textarea>"
     2216                 "    </body>"
     2217                 "</html>");
     2218    view.resize(400, 100);
     2219    view.show();
     2220    view.setFocus();
     2221    QTest::qWait(200);
     2222    QVERIFY2(view.hasFocus(),
     2223             "The WebView should be created");
     2224
     2225    // open the popup by clicking. check if focus is on the popup
     2226    QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(25, 25));
     2227    QObject* webpopup = firstChildByClassName(&view, "WebCore::QWebPopup");
     2228    QComboBox* combo = dynamic_cast<QComboBox*>(webpopup);
     2229    QTest::qWait(1);
     2230    QVERIFY2(!view.hasFocus() && combo->view()->hasFocus(),
     2231             "Focus sould be on the Popup");
     2232
     2233    // hide the popup and check if focus is on the page
     2234    combo->hidePopup();
     2235    QTest::qWait(1);
     2236    QVERIFY2(view.hasFocus() && !combo->view()->hasFocus(),
     2237             "Focus sould be back on the WebView");
     2238
     2239    // focus the lineedit and check if it blinks
     2240    QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(200, 25));
     2241    m_popupTestView = &view;
     2242    view.installEventFilter( this );
     2243    QTest::qWait(2000);
     2244    QVERIFY2(m_popupTestPaintCount >= 4,
     2245             "The input field should have a blinking caret");
     2246}
     2247
    21762248QTEST_MAIN(tst_QWebFrame)
    21772249#include "tst_qwebframe.moc"
Note: See TracChangeset for help on using the changeset viewer.