Title: [94321] trunk/Source/WebKit/qt
Revision
94321
Author
[email protected]
Date
2011-09-01 11:39:12 -0700 (Thu, 01 Sep 2011)

Log Message

[Qt] Transform QtFallbackWebPopupCombo into QtWebComboBox
https://bugs.webkit.org/show_bug.cgi?id=67344

Reviewed by Andreas Kling.

Renamed QtFallbackWebPopup to QtWebComboBox and decoupled it from
QtFallbackWebPopup. The new class is a QComboBox with the features that
we need for QtWebKit: tracking when the popup is hidden (via the didHide()
signal) and a convenience method to show its popup in the cursor position.

An important change was made to the combobox: instead of hooking our actions in
showPopup() and hidePopup(), as well as watching for popup visibility events, we
now just watch for the visibility events. This allowed us to get rid of
m_popupVisible and tracking the Show event.

This commit also removed a workaround for input focus added in r40970 after
reviewers request. See bug report for details.

* QtWebKit.pro:
* WebCoreSupport/QtFallbackWebPopup.cpp:
(WebCore::QtFallbackWebPopup::QtFallbackWebPopup):
(WebCore::QtFallbackWebPopup::~QtFallbackWebPopup):
(WebCore::QtFallbackWebPopup::show):
(WebCore::QtFallbackWebPopup::deleteComboBox):
* WebCoreSupport/QtFallbackWebPopup.h:
* WebCoreSupport/QtWebComboBox.cpp: Added.
(WebCore::QtWebComboBox::QtWebComboBox):
(WebCore::QtWebComboBox::showPopupAtCursorPosition):
(WebCore::QtWebComboBox::eventFilter):
* WebCoreSupport/QtWebComboBox.h: Added.

* tests/qwebframe/tst_qwebframe.cpp:
(tst_QWebFrame::popupFocus):
Change the test to use QObject::findChild(). The old method couldn't find our
new class because we defined a new metaclass for it.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/qt/ChangeLog (94320 => 94321)


--- trunk/Source/WebKit/qt/ChangeLog	2011-09-01 18:37:07 UTC (rev 94320)
+++ trunk/Source/WebKit/qt/ChangeLog	2011-09-01 18:39:12 UTC (rev 94321)
@@ -1,3 +1,41 @@
+2011-09-01  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        [Qt] Transform QtFallbackWebPopupCombo into QtWebComboBox
+        https://bugs.webkit.org/show_bug.cgi?id=67344
+
+        Reviewed by Andreas Kling.
+
+        Renamed QtFallbackWebPopup to QtWebComboBox and decoupled it from
+        QtFallbackWebPopup. The new class is a QComboBox with the features that
+        we need for QtWebKit: tracking when the popup is hidden (via the didHide()
+        signal) and a convenience method to show its popup in the cursor position.
+
+        An important change was made to the combobox: instead of hooking our actions in
+        showPopup() and hidePopup(), as well as watching for popup visibility events, we
+        now just watch for the visibility events. This allowed us to get rid of
+        m_popupVisible and tracking the Show event.
+
+        This commit also removed a workaround for input focus added in r40970 after
+        reviewers request. See bug report for details.
+
+        * QtWebKit.pro:
+        * WebCoreSupport/QtFallbackWebPopup.cpp:
+        (WebCore::QtFallbackWebPopup::QtFallbackWebPopup):
+        (WebCore::QtFallbackWebPopup::~QtFallbackWebPopup):
+        (WebCore::QtFallbackWebPopup::show):
+        (WebCore::QtFallbackWebPopup::deleteComboBox):
+        * WebCoreSupport/QtFallbackWebPopup.h:
+        * WebCoreSupport/QtWebComboBox.cpp: Added.
+        (WebCore::QtWebComboBox::QtWebComboBox):
+        (WebCore::QtWebComboBox::showPopupAtCursorPosition):
+        (WebCore::QtWebComboBox::eventFilter):
+        * WebCoreSupport/QtWebComboBox.h: Added.
+
+        * tests/qwebframe/tst_qwebframe.cpp:
+        (tst_QWebFrame::popupFocus):
+        Change the test to use QObject::findChild(). The old method couldn't find our
+        new class because we defined a new metaclass for it.
+
 2011-08-31  Ryosuke Niwa  <[email protected]>
 
         Move text() and textWithHardLineBreaks() from RenderTextControl to HTMLTextFormControlElement

Modified: trunk/Source/WebKit/qt/QtWebKit.pro (94320 => 94321)


--- trunk/Source/WebKit/qt/QtWebKit.pro	2011-09-01 18:37:07 UTC (rev 94320)
+++ trunk/Source/WebKit/qt/QtWebKit.pro	2011-09-01 18:39:12 UTC (rev 94321)
@@ -177,6 +177,7 @@
     $$PWD/Api/qwebkitversion.cpp \
     \
     $$PWD/WebCoreSupport/QtFallbackWebPopup.cpp \
+    $$PWD/WebCoreSupport/QtWebComboBox.cpp \
     $$PWD/WebCoreSupport/ChromeClientQt.cpp \
     $$PWD/WebCoreSupport/ContextMenuClientQt.cpp \
     $$PWD/WebCoreSupport/DragClientQt.cpp \
@@ -202,6 +203,7 @@
     \
     $$PWD/WebCoreSupport/InspectorServerQt.h \
     $$PWD/WebCoreSupport/QtFallbackWebPopup.h \
+    $$PWD/WebCoreSupport/QtWebComboBox.h \
     $$PWD/WebCoreSupport/FrameLoaderClientQt.h \
     $$PWD/WebCoreSupport/FrameNetworkingContextQt.h \
     $$PWD/WebCoreSupport/GeolocationPermissionClientQt.h \

Modified: trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp (94320 => 94321)


--- trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp	2011-09-01 18:37:07 UTC (rev 94320)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp	2011-09-01 18:39:12 UTC (rev 94321)
@@ -24,82 +24,23 @@
 #ifndef QT_NO_COMBOBOX
 
 #include "ChromeClientQt.h"
+#include "QtWebComboBox.h"
 #include "QWebPageClient.h"
 #include "qgraphicswebview.h"
-#include <QAbstractItemView>
-#include <QApplication>
 #include <QGraphicsProxyWidget>
-#include <QGraphicsScene>
-#include <QGraphicsView>
-#include <QInputContext>
-#include <QMouseEvent>
 #include <QStandardItemModel>
 
 namespace WebCore {
 
-QtFallbackWebPopupCombo::QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup)
-    : m_ownerPopup(ownerPopup)
-{
-    // Install an event filter on the view inside the combo box popup to make sure we know
-    // when the popup got closed. E.g. QComboBox::hidePopup() won't be called when the popup
-    // is closed by a mouse wheel event outside its window.
-    view()->installEventFilter(this);
-}
-
-void QtFallbackWebPopupCombo::showPopup()
-{
-    QComboBox::showPopup();
-    m_ownerPopup.m_popupVisible = true;
-}
-
-void QtFallbackWebPopupCombo::hidePopup()
-{
-#ifndef QT_NO_IM
-    QWidget* activeFocus = QApplication::focusWidget();
-    if (activeFocus && activeFocus == QComboBox::view()
-        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
-        QInputContext* qic = activeFocus->inputContext();
-        if (qic) {
-            qic->reset();
-            qic->setFocusWidget(0);
-        }
-    }
-#endif // QT_NO_IM
-
-    QComboBox::hidePopup();
-
-    if (!m_ownerPopup.m_popupVisible)
-        return;
-
-    m_ownerPopup.m_popupVisible = false;
-    emit m_ownerPopup.didHide();
-    m_ownerPopup.destroyPopup();
-}
-
-bool QtFallbackWebPopupCombo::eventFilter(QObject* watched, QEvent* event)
-{
-    Q_ASSERT(watched == view());
-
-    if (event->type() == QEvent::Show && !m_ownerPopup.m_popupVisible)
-        showPopup();
-    else if (event->type() == QEvent::Hide && m_ownerPopup.m_popupVisible)
-        hidePopup();
-
-    return false;
-}
-
-// QtFallbackWebPopup
-
 QtFallbackWebPopup::QtFallbackWebPopup(const ChromeClientQt* chromeClient)
-    : m_popupVisible(false)
-    , m_combo(0)
+    : m_combo(0)
     , m_chromeClient(chromeClient)
 {
 }
 
 QtFallbackWebPopup::~QtFallbackWebPopup()
 {
-    destroyPopup();
+    deleteComboBox();
 }
 
 void QtFallbackWebPopup::show(const QWebSelectData& data)
@@ -107,11 +48,13 @@
     if (!pageClient())
         return;
 
-    destroyPopup();
-    m_combo = new QtFallbackWebPopupCombo(*this);
-    connect(m_combo, SIGNAL(activated(int)),
-            SLOT(activeChanged(int)), Qt::QueuedConnection);
+    deleteComboBox();
 
+    m_combo = new QtWebComboBox();
+    connect(m_combo, SIGNAL(activated(int)), SLOT(activeChanged(int)), Qt::QueuedConnection);
+    connect(m_combo, SIGNAL(didHide()), SLOT(deleteComboBox()));
+    connect(m_combo, SIGNAL(didHide()), SIGNAL(didHide()));
+
     populate(data);
 
     QRect rect = geometry();
@@ -123,12 +66,9 @@
         m_combo->setParent(pageClient()->ownerWidget());
         m_combo->setGeometry(QRect(rect.left(), rect.top(),
                                rect.width(), m_combo->sizeHint().height()));
-
     }
 
-    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
-                      Qt::LeftButton, Qt::NoModifier);
-    QCoreApplication::sendEvent(m_combo, &event);
+    m_combo->showPopupAtCursorPosition();
 }
 
 void QtFallbackWebPopup::hide()
@@ -138,14 +78,6 @@
     // Qt::Popup window will hide itself on mouse events outside its window.
 }
 
-void QtFallbackWebPopup::destroyPopup()
-{
-    if (m_combo) {
-        m_combo->deleteLater();
-        m_combo = 0;
-    }
-}
-
 void QtFallbackWebPopup::populate(const QWebSelectData& data)
 {
     QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_combo->model());
@@ -191,6 +123,14 @@
     emit selectItem(index, false, false);
 }
 
+void QtFallbackWebPopup::deleteComboBox()
+{
+    if (!m_combo)
+        return;
+    m_combo->deleteLater();
+    m_combo = 0;
+}
+
 QWebPageClient* QtFallbackWebPopup::pageClient() const
 {
     return m_chromeClient->platformPageClient();

Modified: trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h (94320 => 94321)


--- trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h	2011-09-01 18:37:07 UTC (rev 94320)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h	2011-09-01 18:39:12 UTC (rev 94321)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 class ChromeClientQt;
-class QtFallbackWebPopupCombo;
+class QtWebComboBox;
 
 class QtFallbackWebPopup : public QWebSelectMethod {
     Q_OBJECT
@@ -47,8 +47,6 @@
     virtual void show(const QWebSelectData&);
     virtual void hide();
 
-    void destroyPopup();
-
     void setGeometry(const QRect& rect) { m_geometry = rect; }
     QRect geometry() const { return m_geometry; }
 
@@ -57,11 +55,10 @@
 
 private slots:
     void activeChanged(int);
+    void deleteComboBox();
 
 private:
-    friend class QtFallbackWebPopupCombo;
-    bool m_popupVisible;
-    QtFallbackWebPopupCombo* m_combo;
+    QtWebComboBox* m_combo;
     const ChromeClientQt* m_chromeClient;
     QRect m_geometry;
     QFont m_font;
@@ -71,17 +68,6 @@
     void populate(const QWebSelectData&);
 };
 
-class QtFallbackWebPopupCombo : public QComboBox {
-public:
-    QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup);
-    virtual void showPopup();
-    virtual void hidePopup();
-    virtual bool eventFilter(QObject* watched, QEvent* event);
-
-private:
-    QtFallbackWebPopup& m_ownerPopup;
-};
-
 }
 
 #endif // QT_NO_COMBOBOX

Added: trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.cpp (0 => 94321)


--- trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.cpp	                        (rev 0)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.cpp	2011-09-01 18:39:12 UTC (rev 94321)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 Girish Ramakrishnan <[email protected]>
+ * Copyright (C) 2009, 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebComboBox.h"
+
+#ifndef QT_NO_COMBOBOX
+
+#include <QtGui/QAbstractItemView>
+#include <QtGui/QApplication>
+#include <QtGui/QMouseEvent>
+
+namespace WebCore {
+
+QtWebComboBox::QtWebComboBox()
+    : QComboBox()
+{
+    // Install an event filter on the view inside the combo box popup to make sure we know
+    // when the popup got closed. E.g. QComboBox::hidePopup() won't be called when the popup
+    // is closed by a mouse wheel event outside its window.
+    view()->installEventFilter(this);
+}
+
+void QtWebComboBox::showPopupAtCursorPosition()
+{
+    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
+                      Qt::LeftButton, Qt::NoModifier);
+    QApplication::sendEvent(this, &event);
+}
+
+bool QtWebComboBox::eventFilter(QObject* watched, QEvent* event)
+{
+    Q_ASSERT(watched == view());
+    if (event->type() == QEvent::Hide)
+        emit didHide();
+    return false;
+}
+
+}
+
+#endif // QT_NO_COMBOBOX

Added: trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.h (0 => 94321)


--- trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.h	                        (rev 0)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QtWebComboBox.h	2011-09-01 18:39:12 UTC (rev 94321)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebComboBox_h
+#define QtWebComboBox_h
+
+#include "Platform.h"
+
+#include <QtGui/QComboBox>
+
+#ifndef QT_NO_COMBOBOX
+
+namespace WebCore {
+
+class QtWebComboBox : public QComboBox {
+    Q_OBJECT
+public:
+    QtWebComboBox();
+
+    void showPopupAtCursorPosition();
+    virtual bool eventFilter(QObject* watched, QEvent*);
+
+Q_SIGNALS:
+    void didHide();
+};
+
+}
+
+#endif // QT_NO_COMBOBOX
+
+#endif // QtWebComboBox_h

Modified: trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp (94320 => 94321)


--- trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	2011-09-01 18:37:07 UTC (rev 94320)
+++ trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	2011-09-01 18:39:12 UTC (rev 94321)
@@ -709,15 +709,6 @@
         evalJS("delete retvalue; delete typevalue");
         return ret;
     }
-    QObject* firstChildByClassName(QObject* parent, const char* className) {
-        const QObjectList & children = parent->children();
-        foreach (QObject* child, children) {
-            if (!strcmp(child->metaObject()->className(), className)) {
-                return child;
-            }
-        }
-        return 0;
-    }
 
     const QString sTrue;
     const QString sFalse;
@@ -2711,8 +2702,8 @@
     // open the popup by clicking. check if focus is on the popup
     const QWebElement webCombo = view.page()->mainFrame()->documentElement().findFirst(QLatin1String("select[name=select]"));
     QTest::mouseClick(&view, Qt::LeftButton, 0, webCombo.geometry().center());
-    QObject* webpopup = firstChildByClassName(&view, "QComboBox");
-    QComboBox* combo = qobject_cast<QComboBox*>(webpopup);
+
+    QComboBox* combo = view.findChild<QComboBox*>();
     QVERIFY(combo != 0);
     QTRY_VERIFY(!view.hasFocus() && combo->view()->hasFocus()); // Focus should be on the popup
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to