[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Thu Apr 8 00:58:45 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 556684f76531e5949462574278f28d17486bfa05
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jan 8 21:48:02 2010 +0000

    2010-01-08  Luiz Agostini  <luiz.agostini at openbossa.org>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] Delegation client
            https://bugs.webkit.org/show_bug.cgi?id=32826
    
            Factory related code removed from QtAbstractWebPopup. Popups are now created
            by ChromeClientQt.
            Popup content information struct added to class QtAbstractWebPopup.
            PopupMenuClient is now hidden from higher layers.
            QtAbstractWebPopup now receives content information and font as parameters
            of method populate.
            QtFallbackWebPopup moved to WebKit/qt/WebCoreSupport.
    
            * WebCore.pro:
            * platform/qt/PopupMenuQt.cpp:
            (WebCore::PopupMenu::PopupMenu):
            (WebCore::getItems):
            (WebCore::PopupMenu::show):
            * platform/qt/QtAbstractWebPopup.cpp:
            (WebCore::QtAbstractWebPopup::QtAbstractWebPopup):
            (WebCore::QtAbstractWebPopup::popupDidHide):
            (WebCore::QtAbstractWebPopup::valueChanged):
            * platform/qt/QtAbstractWebPopup.h:
            (WebCore::QtAbstractWebPopup::Item::):
            * platform/qt/QtFallbackWebPopup.cpp: Removed.
            * platform/qt/QtFallbackWebPopup.h: Removed.
    2010-01-08  Luiz Agostini  <luiz.agostini at openbossa.org>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] Delegation client
            https://bugs.webkit.org/show_bug.cgi?id=32826
    
            Added method createPopup to ChromeClientQt used to create popups.
            QtFallbackWebPopup moved from WebCore/platform/qt to
            WebKit/qt/WebCoreSupport.
    
            * WebCoreSupport/ChromeClientQt.cpp:
            (WebCore::ChromeClientQt::createPopup):
            * WebCoreSupport/ChromeClientQt.h:
            * WebCoreSupport/QtFallbackWebPopup.cpp: Added.
            (WebCore::QtFallbackWebPopup::QtFallbackWebPopup):
            (WebCore::QtFallbackWebPopup::show):
            (WebCore::QtFallbackWebPopup::populate):
            (WebCore::QtFallbackWebPopup::showPopup):
            (WebCore::QtFallbackWebPopup::hidePopup):
            (WebCore::QtFallbackWebPopup::activeChanged):
            (WebCore::QtFallbackWebPopup::setParent):
            * WebCoreSupport/QtFallbackWebPopup.h: Added.
            (WebCore::QtFallbackWebPopup::hide):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53005 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index b95f5b2..7a62cd1 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,32 @@
+2010-01-08  Luiz Agostini  <luiz.agostini at openbossa.org>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Delegation client
+        https://bugs.webkit.org/show_bug.cgi?id=32826
+
+        Factory related code removed from QtAbstractWebPopup. Popups are now created
+        by ChromeClientQt.
+        Popup content information struct added to class QtAbstractWebPopup.
+        PopupMenuClient is now hidden from higher layers.
+        QtAbstractWebPopup now receives content information and font as parameters
+        of method populate.
+        QtFallbackWebPopup moved to WebKit/qt/WebCoreSupport.
+
+        * WebCore.pro:
+        * platform/qt/PopupMenuQt.cpp:
+        (WebCore::PopupMenu::PopupMenu):
+        (WebCore::getItems):
+        (WebCore::PopupMenu::show):
+        * platform/qt/QtAbstractWebPopup.cpp:
+        (WebCore::QtAbstractWebPopup::QtAbstractWebPopup):
+        (WebCore::QtAbstractWebPopup::popupDidHide):
+        (WebCore::QtAbstractWebPopup::valueChanged):
+        * platform/qt/QtAbstractWebPopup.h:
+        (WebCore::QtAbstractWebPopup::Item::):
+        * platform/qt/QtFallbackWebPopup.cpp: Removed.
+        * platform/qt/QtFallbackWebPopup.h: Removed.
+
 2010-01-08  Yuzo Fujishima  <yuzo at google.com>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 6636b21..6f03838 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -1983,7 +1983,6 @@ HEADERS += \
     platform/qt/ClipboardQt.h \
     platform/qt/QWebPageClient.h \
     platform/qt/QtAbstractWebPopup.h \
-    platform/qt/QtFallbackWebPopup.h \
     platform/qt/RenderThemeQt.h \
     platform/qt/ScrollbarThemeQt.h \
     platform/Scrollbar.h \
@@ -2385,6 +2384,7 @@ HEADERS += \
     xml/XSLTProcessor.h \
     xml/XSLTUnicodeSort.h \
     $$PWD/../WebKit/qt/Api/qwebplugindatabase_p.h \
+    $$PWD/../WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h \
     $$PWD/../WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h \
     $$PWD/platform/network/qt/DnsPrefetchHelper.h
 
@@ -2446,7 +2446,6 @@ SOURCES += \
     platform/qt/PlatformTouchPointQt.cpp \
     platform/qt/PopupMenuQt.cpp \
     platform/qt/QtAbstractWebPopup.cpp \
-    platform/qt/QtFallbackWebPopup.cpp \
     platform/qt/RenderThemeQt.cpp \
     platform/qt/ScrollbarQt.cpp \
     platform/qt/ScrollbarThemeQt.cpp \
@@ -2463,6 +2462,7 @@ SOURCES += \
     platform/qt/WheelEventQt.cpp \
     platform/qt/WidgetQt.cpp \
     plugins/qt/PluginDataQt.cpp \
+    ../WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp \
     ../WebKit/qt/WebCoreSupport/ChromeClientQt.cpp \
     ../WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp \
     ../WebKit/qt/WebCoreSupport/DragClientQt.cpp \
diff --git a/WebCore/platform/qt/PopupMenuQt.cpp b/WebCore/platform/qt/PopupMenuQt.cpp
index 498ef7b..63e1565 100644
--- a/WebCore/platform/qt/PopupMenuQt.cpp
+++ b/WebCore/platform/qt/PopupMenuQt.cpp
@@ -1,7 +1,7 @@
 /*
  * This file is part of the popup menu implementation for <select> elements in WebCore.
  *
- * Copyright (C) 2008, 2009 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
  * Copyright (C) 2006 Apple Computer, Inc.
  * Copyright (C) 2006 Michael Emmel mike.emmel at gmail.com 
  * Coypright (C) 2006 Nikolas Zimmermann <zimmermann at kde.org>
@@ -26,17 +26,19 @@
 #include "config.h"
 #include "PopupMenu.h"
 
+#include "Chrome.h"
+#include "ChromeClientQt.h"
 #include "FrameView.h"
 #include "PopupMenuClient.h"
+#include "QWebPageClient.h"
 #include "QtAbstractWebPopup.h"
-#include "QtFallbackWebPopup.h"
 
 namespace WebCore {
 
 PopupMenu::PopupMenu(PopupMenuClient* client)
     : m_popupClient(client)
+    , m_popup(0)
 {
-    m_popup = QtAbstractWebPopup::create(client);
 }
 
 PopupMenu::~PopupMenu()
@@ -44,11 +46,47 @@ PopupMenu::~PopupMenu()
     delete m_popup;
 }
 
-void PopupMenu::show(const IntRect& r, FrameView* v, int index)
+static QList<QtAbstractWebPopup::Item> getItems(PopupMenuClient* client)
 {
-    QRect rect = r;
-    rect.moveTopLeft(v->contentsToWindow(r.topLeft()));
-    m_popup->show(rect, index);
+    QList<QtAbstractWebPopup::Item> result;
+
+    int size = client->listSize();
+    for (int i = 0; i < size; ++i) {
+        QtAbstractWebPopup::Item item;
+
+        if (client->itemIsSeparator(i))
+            item.type = QtAbstractWebPopup::Item::Separator;
+        else if (client->itemIsLabel(i))
+            item.type = QtAbstractWebPopup::Item::Group;
+        else
+            item.type = QtAbstractWebPopup::Item::Option;
+
+        item.text = client->itemText(i);
+        item.toolTip = client->itemToolTip(i);
+        item.enabled = client->itemIsEnabled(i);
+        result.append(item);
+    }
+    return result;
+}
+
+void PopupMenu::show(const IntRect& rect, FrameView* view, int index)
+{
+    ChromeClientQt* chromeClient = static_cast<ChromeClientQt*>(
+        view->frame()->page()->chrome()->client());
+    ASSERT(chromeClient);
+
+    if (!m_popup) {
+        m_popup = chromeClient->createPopup();
+        m_popup->m_client = m_popupClient;
+    }
+
+    m_popup->setParent(chromeClient->platformPageClient()->ownerWidget());
+    m_popup->populate(m_popupClient->menuStyle().font().font(),
+                      getItems(m_popupClient));
+
+    QRect bounds = rect;
+    bounds.moveTopLeft(view->contentsToWindow(rect.topLeft()));
+    m_popup->show(bounds, index);
 }
 
 void PopupMenu::hide()
diff --git a/WebCore/platform/qt/QtAbstractWebPopup.cpp b/WebCore/platform/qt/QtAbstractWebPopup.cpp
index cbe7174..75d8fb5 100644
--- a/WebCore/platform/qt/QtAbstractWebPopup.cpp
+++ b/WebCore/platform/qt/QtAbstractWebPopup.cpp
@@ -21,36 +21,29 @@
 #include "QtAbstractWebPopup.h"
 
 #include "PopupMenuClient.h"
-#include "QtFallbackWebPopup.h"
 
 
 namespace WebCore {
 
-QtAbstractWebPopupFactory* QtAbstractWebPopup::m_factory = 0;
-
-QtAbstractWebPopup::QtAbstractWebPopup(PopupMenuClient* client)
-    : m_client(client)
+QtAbstractWebPopup::QtAbstractWebPopup()
+    : m_client(0)
 {
-    Q_ASSERT(m_client);
 }
 
 QtAbstractWebPopup::~QtAbstractWebPopup()
 {
 }
 
-PopupMenuClient* QtAbstractWebPopup::client()
+void QtAbstractWebPopup::popupDidHide(bool acceptSuggestions)
 {
-    return m_client;
-}
-
-void QtAbstractWebPopup::setFactory(QtAbstractWebPopupFactory* factory)
-{
-    m_factory = factory;
+    Q_ASSERT(m_client);
+    m_client->popupDidHide(acceptSuggestions);
 }
 
-QtAbstractWebPopup* QtAbstractWebPopup::create(PopupMenuClient* client)
+void QtAbstractWebPopup::valueChanged(int index)
 {
-    return m_factory ? m_factory->create(client) : new QtFallbackWebPopup(client);
+    Q_ASSERT(m_client);
+    m_client->valueChanged(index);
 }
 
 } // namespace WebCore
diff --git a/WebCore/platform/qt/QtAbstractWebPopup.h b/WebCore/platform/qt/QtAbstractWebPopup.h
index b8cab4a..c890441 100644
--- a/WebCore/platform/qt/QtAbstractWebPopup.h
+++ b/WebCore/platform/qt/QtAbstractWebPopup.h
@@ -20,35 +20,38 @@
 #ifndef QtAbstractWebPopup_h
 #define QtAbstractWebPopup_h
 
+#include <QFont>
+#include <QList>
 #include <QRect>
 
 namespace WebCore {
 
-class QtAbstractWebPopup;
 class PopupMenuClient;
 
-class QtAbstractWebPopupFactory {
-public:
-    virtual QtAbstractWebPopup* create(PopupMenuClient* client) = 0;
-};
-
 class QtAbstractWebPopup {
 public:
-    QtAbstractWebPopup(PopupMenuClient* client);
+    struct Item {
+        enum { Option, Group, Separator } type;
+        QString text;
+        QString toolTip;
+        bool enabled;
+    };
+
+    QtAbstractWebPopup();
     virtual ~QtAbstractWebPopup();
 
     virtual void show(const QRect& geometry, int selectedIndex) = 0;
     virtual void hide() = 0;
-
-    static void setFactory(QtAbstractWebPopupFactory* factory);
-    static QtAbstractWebPopup* create(PopupMenuClient* client);
+    virtual void populate(const QFont& font, const QList<Item>& items) = 0;
+    virtual void setParent(QWidget* parent) = 0;
 
 protected:
-    PopupMenuClient* client();
+    void popupDidHide(bool acceptSuggestions);
+    void valueChanged(int index);
 
 private:
+    friend class PopupMenu;
     PopupMenuClient* m_client;
-    static QtAbstractWebPopupFactory* m_factory;
 };
 
 }
diff --git a/WebCore/platform/qt/QtFallbackWebPopup.cpp b/WebCore/platform/qt/QtFallbackWebPopup.cpp
deleted file mode 100644
index fd14b32..0000000
--- a/WebCore/platform/qt/QtFallbackWebPopup.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2009 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 "QtFallbackWebPopup.h"
-
-#include "HostWindow.h"
-#include "PopupMenuClient.h"
-#include "QWebPageClient.h"
-#include <QAbstractItemView>
-#include <QApplication>
-#include <QInputContext>
-#include <QMouseEvent>
-#include <QStandardItemModel>
-
-namespace WebCore {
-
-// QtFallbackWebPopup
-
-QtFallbackWebPopup::QtFallbackWebPopup(PopupMenuClient* client)
-    : QtAbstractWebPopup(client)
-    , m_popupVisible(false)
-{
-    setFont(QtAbstractWebPopup::client()->menuStyle().font().font());
-    connect(this, SIGNAL(activated(int)),
-            SLOT(activeChanged(int)), Qt::QueuedConnection);
-}
-
-
-void QtFallbackWebPopup::show(const QRect& geometry, int selectedIndex)
-{
-    populate();
-    setCurrentIndex(selectedIndex);
-
-    QWidget* parent = 0;
-    if (client()->hostWindow() && client()->hostWindow()->platformPageClient())
-       parent = client()->hostWindow()->platformPageClient()->ownerWidget();
-
-    setParent(parent);
-    setGeometry(QRect(geometry.left(), geometry.top(), geometry.width(), sizeHint().height()));
-
-    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
-                      Qt::LeftButton, Qt::NoModifier);
-    QCoreApplication::sendEvent(this, &event);
-}
-
-void QtFallbackWebPopup::populate()
-{
-    clear();
-
-    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(QComboBox::model());
-    Q_ASSERT(model);
-
-    int size = client()->listSize();
-    for (int i = 0; i < size; i++) {
-        if (client()->itemIsSeparator(i))
-            insertSeparator(i);
-        else {
-            insertItem(i, client()->itemText(i));
-
-            if (model && !client()->itemIsEnabled(i))
-                model->item(i)->setEnabled(false);
-        }
-    }
-}
-
-void QtFallbackWebPopup::showPopup()
-{
-    QComboBox::showPopup();
-    m_popupVisible = true;
-}
-
-void QtFallbackWebPopup::hidePopup()
-{
-    QWidget* activeFocus = QApplication::focusWidget();
-    if (activeFocus && activeFocus == view()
-        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
-        QInputContext* qic = activeFocus->inputContext();
-        if (qic) {
-            qic->reset();
-            qic->setFocusWidget(0);
-        }
-    }
-
-    QComboBox::hidePopup();
-    if (!m_popupVisible)
-        return;
-
-    m_popupVisible = false;
-    client()->popupDidHide(true);
-}
-
-void QtFallbackWebPopup::activeChanged(int index)
-{
-    if (index < 0)
-        return;
-
-    client()->valueChanged(index);
-}
-
-}
diff --git a/WebCore/platform/qt/QtFallbackWebPopup.h b/WebCore/platform/qt/QtFallbackWebPopup.h
deleted file mode 100644
index 039270c..0000000
--- a/WebCore/platform/qt/QtFallbackWebPopup.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2009 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 QtFallbackWebPopup_h
-#define QtFallbackWebPopup_h
-
-#include "QtAbstractWebPopup.h"
-#include <QComboBox>
-
-namespace WebCore {
-
-class QtFallbackWebPopup : private QComboBox, public QtAbstractWebPopup {
-    Q_OBJECT
-public:
-    QtFallbackWebPopup(PopupMenuClient* client);
-
-    virtual void show(const QRect& geometry, int selectedIndex);
-    virtual void hide() { hidePopup(); }
-
-private slots:
-    void activeChanged(int);
-
-private:
-    bool m_popupVisible;
-
-    void populate();
-
-    virtual void showPopup();
-    virtual void hidePopup();
-};
-
-}
-
-#endif // QtFallbackWebPopup_h
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index 9da774b..c303b43 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,28 @@
+2010-01-08  Luiz Agostini  <luiz.agostini at openbossa.org>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Delegation client
+        https://bugs.webkit.org/show_bug.cgi?id=32826
+
+        Added method createPopup to ChromeClientQt used to create popups.
+        QtFallbackWebPopup moved from WebCore/platform/qt to
+        WebKit/qt/WebCoreSupport.
+
+        * WebCoreSupport/ChromeClientQt.cpp:
+        (WebCore::ChromeClientQt::createPopup):
+        * WebCoreSupport/ChromeClientQt.h:
+        * WebCoreSupport/QtFallbackWebPopup.cpp: Added.
+        (WebCore::QtFallbackWebPopup::QtFallbackWebPopup):
+        (WebCore::QtFallbackWebPopup::show):
+        (WebCore::QtFallbackWebPopup::populate):
+        (WebCore::QtFallbackWebPopup::showPopup):
+        (WebCore::QtFallbackWebPopup::hidePopup):
+        (WebCore::QtFallbackWebPopup::activeChanged):
+        (WebCore::QtFallbackWebPopup::setParent):
+        * WebCoreSupport/QtFallbackWebPopup.h: Added.
+        (WebCore::QtFallbackWebPopup::hide):
+
 2010-01-07  Yael Aharon  <yael.aharon at nokia.com>
 
         Reviewed by Kenneth Rohde Christiansen.
diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
index 73cb4d7..f62bc86 100644
--- a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
@@ -38,8 +38,9 @@
 #include "NotImplemented.h"
 #include "WindowFeatures.h"
 #include "DatabaseTracker.h"
-#include "SecurityOrigin.h"
+#include "QtFallbackWebPopup.h"
 #include "QWebPageClient.h"
+#include "SecurityOrigin.h"
 
 #include "qwebpage.h"
 #include "qwebpage_p.h"
@@ -465,4 +466,9 @@ void ChromeClientQt::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
     notImplemented();
 }
 
+QtAbstractWebPopup* ChromeClientQt::createPopup()
+{
+    return new QtFallbackWebPopup;
+}
+
 }
diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.h b/WebKit/qt/WebCoreSupport/ChromeClientQt.h
index 939fe04..106d4cc 100644
--- a/WebKit/qt/WebCoreSupport/ChromeClientQt.h
+++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.h
@@ -42,6 +42,7 @@ namespace WebCore {
     class FloatRect;
     class Page;
     struct FrameLoadRequest;
+    class QtAbstractWebPopup;
 
     class ChromeClientQt : public ChromeClient
     {
@@ -134,6 +135,8 @@ namespace WebCore {
 
         virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
 
+        QtAbstractWebPopup* createPopup();
+
         QWebPage* m_webPage;
         WebCore::KURL lastHoverURL;
         WebCore::String lastHoverTitle;
diff --git a/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp b/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp
new file mode 100644
index 0000000..344d58a
--- /dev/null
+++ b/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2009 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 "QtFallbackWebPopup.h"
+
+#include "HostWindow.h"
+#include "PopupMenuClient.h"
+#include "QWebPageClient.h"
+#include <QAbstractItemView>
+#include <QApplication>
+#include <QInputContext>
+#include <QMouseEvent>
+#include <QStandardItemModel>
+
+namespace WebCore {
+
+// QtFallbackWebPopup
+
+QtFallbackWebPopup::QtFallbackWebPopup()
+    : QtAbstractWebPopup()
+    , m_popupVisible(false)
+{
+    connect(this, SIGNAL(activated(int)),
+            SLOT(activeChanged(int)), Qt::QueuedConnection);
+}
+
+
+void QtFallbackWebPopup::show(const QRect& geometry, int selectedIndex)
+{
+    setCurrentIndex(selectedIndex);
+
+    /*
+    QWidget* parent = 0;
+    if (client()->hostWindow() && client()->hostWindow()->platformPageClient())
+       parent = client()->hostWindow()->platformPageClient()->ownerWidget();
+
+    setParent(parent);
+    */
+
+    setGeometry(QRect(geometry.left(), geometry.top(), geometry.width(), sizeHint().height()));
+
+    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
+                      Qt::LeftButton, Qt::NoModifier);
+    QCoreApplication::sendEvent(this, &event);
+}
+
+void QtFallbackWebPopup::populate(const QFont& font, const QList<Item>& items)
+{
+    clear();
+
+    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(QComboBox::model());
+    Q_ASSERT(model);
+
+    setFont(font);
+    for (int i = 0; i < items.size(); ++i) {
+        switch (items[i].type) {
+        case QtAbstractWebPopup::Item::Separator:
+            insertSeparator(i);
+            break;
+        case QtAbstractWebPopup::Item::Group:
+            insertItem(i, items[i].text);
+            model->item(i)->setEnabled(false);
+            break;
+        case QtAbstractWebPopup::Item::Option:
+            insertItem(i, items[i].text);
+            model->item(i)->setEnabled(items[i].enabled);
+            break;
+        }
+    }
+}
+
+void QtFallbackWebPopup::showPopup()
+{
+    QComboBox::showPopup();
+    m_popupVisible = true;
+}
+
+void QtFallbackWebPopup::hidePopup()
+{
+    QWidget* activeFocus = QApplication::focusWidget();
+    if (activeFocus && activeFocus == view()
+        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
+        QInputContext* qic = activeFocus->inputContext();
+        if (qic) {
+            qic->reset();
+            qic->setFocusWidget(0);
+        }
+    }
+
+    QComboBox::hidePopup();
+    if (!m_popupVisible)
+        return;
+
+    m_popupVisible = false;
+    popupDidHide(true);
+}
+
+void QtFallbackWebPopup::activeChanged(int index)
+{
+    if (index < 0)
+        return;
+
+    valueChanged(index);
+}
+
+void QtFallbackWebPopup::setParent(QWidget* parent)
+{
+    QComboBox::setParent(parent);
+}
+
+}
diff --git a/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h b/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h
new file mode 100644
index 0000000..5affe0a
--- /dev/null
+++ b/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 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 QtFallbackWebPopup_h
+#define QtFallbackWebPopup_h
+
+#include "QtAbstractWebPopup.h"
+#include <QComboBox>
+
+namespace WebCore {
+
+class QtFallbackWebPopup : private QComboBox, public QtAbstractWebPopup {
+    Q_OBJECT
+public:
+    QtFallbackWebPopup();
+
+    virtual void show(const QRect& geometry, int selectedIndex);
+    virtual void hide() { hidePopup(); }
+    virtual void populate(const QFont& font, const QList<Item>& items);
+    virtual void setParent(QWidget* parent);
+
+private slots:
+    void activeChanged(int);
+
+private:
+    bool m_popupVisible;
+
+
+    virtual void showPopup();
+    virtual void hidePopup();
+};
+
+}
+
+#endif // QtFallbackWebPopup_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list