Changeset 53610 in webkit


Ignore:
Timestamp:
Jan 21, 2010 12:10:46 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-21 Luiz Agostini <luiz.agostini@openbossa.org>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Custom select popups.
https://bugs.webkit.org/show_bug.cgi?id=33418

Optimization of the WebCore support to combobox popup delegate.

  • platform/qt/PopupMenuQt.cpp: (WebCore::PopupMenu::show):
  • platform/qt/QtAbstractWebPopup.cpp: (WebCore::QtAbstractWebPopup::QtAbstractWebPopup): (WebCore::QtAbstractWebPopup::itemType):
  • platform/qt/QtAbstractWebPopup.h: (WebCore::QtAbstractWebPopup::): (WebCore::QtAbstractWebPopup::itemText): (WebCore::QtAbstractWebPopup::itemToolTip): (WebCore::QtAbstractWebPopup::itemIsEnabled): (WebCore::QtAbstractWebPopup::itemCount): (WebCore::QtAbstractWebPopup::view): (WebCore::QtAbstractWebPopup::geometry): (WebCore::QtAbstractWebPopup::currentIndex): (WebCore::QtAbstractWebPopup::font):

2010-01-21 Luiz Agostini <luiz.agostini@openbossa.org>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Custom select popups.
https://bugs.webkit.org/show_bug.cgi?id=33418

Adjusting QtFallbackWebPopupCombo to the changes in WebCore layer.

  • WebCoreSupport/ChromeClientQt.cpp: (WebCore::ChromeClientQt::createSelectPopup):
  • WebCoreSupport/ChromeClientQt.h:
  • WebCoreSupport/QtFallbackWebPopup.cpp: (WebCore::QtFallbackWebPopupCombo::QtFallbackWebPopupCombo): (WebCore::QtFallbackWebPopupCombo::showPopup): (WebCore::QtFallbackWebPopupCombo::hidePopup): (WebCore::QtFallbackWebPopup::QtFallbackWebPopup): (WebCore::QtFallbackWebPopup::~QtFallbackWebPopup): (WebCore::QtFallbackWebPopup::show): (WebCore::QtFallbackWebPopup::hide): (WebCore::QtFallbackWebPopup::populate):
  • WebCoreSupport/QtFallbackWebPopup.h:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53607 r53610  
     12010-01-21  Luiz Agostini  <luiz.agostini@openbossa.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Custom select popups.
     6        https://bugs.webkit.org/show_bug.cgi?id=33418
     7
     8        Optimization of the WebCore support to combobox popup delegate.
     9
     10        * platform/qt/PopupMenuQt.cpp:
     11        (WebCore::PopupMenu::show):
     12        * platform/qt/QtAbstractWebPopup.cpp:
     13        (WebCore::QtAbstractWebPopup::QtAbstractWebPopup):
     14        (WebCore::QtAbstractWebPopup::itemType):
     15        * platform/qt/QtAbstractWebPopup.h:
     16        (WebCore::QtAbstractWebPopup::):
     17        (WebCore::QtAbstractWebPopup::itemText):
     18        (WebCore::QtAbstractWebPopup::itemToolTip):
     19        (WebCore::QtAbstractWebPopup::itemIsEnabled):
     20        (WebCore::QtAbstractWebPopup::itemCount):
     21        (WebCore::QtAbstractWebPopup::view):
     22        (WebCore::QtAbstractWebPopup::geometry):
     23        (WebCore::QtAbstractWebPopup::currentIndex):
     24        (WebCore::QtAbstractWebPopup::font):
     25
    1262010-01-20  Adam Barth  <abarth@webkit.org>
    227
  • trunk/WebCore/platform/qt/PopupMenuQt.cpp

    r53005 r53610  
    4747}
    4848
    49 static QList<QtAbstractWebPopup::Item> getItems(PopupMenuClient* client)
    50 {
    51     QList<QtAbstractWebPopup::Item> result;
    52 
    53     int size = client->listSize();
    54     for (int i = 0; i < size; ++i) {
    55         QtAbstractWebPopup::Item item;
    56 
    57         if (client->itemIsSeparator(i))
    58             item.type = QtAbstractWebPopup::Item::Separator;
    59         else if (client->itemIsLabel(i))
    60             item.type = QtAbstractWebPopup::Item::Group;
    61         else
    62             item.type = QtAbstractWebPopup::Item::Option;
    63 
    64         item.text = client->itemText(i);
    65         item.toolTip = client->itemToolTip(i);
    66         item.enabled = client->itemIsEnabled(i);
    67         result.append(item);
    68     }
    69     return result;
    70 }
    71 
    7249void PopupMenu::show(const IntRect& rect, FrameView* view, int index)
    7350{
     
    7653    ASSERT(chromeClient);
    7754
    78     if (!m_popup) {
    79         m_popup = chromeClient->createPopup();
    80         m_popup->m_client = m_popupClient;
    81     }
     55    if (!m_popup)
     56        m_popup = chromeClient->createSelectPopup();
    8257
    83     m_popup->setParent(chromeClient->platformPageClient()->ownerWidget());
    84     m_popup->populate(m_popupClient->menuStyle().font().font(),
    85                       getItems(m_popupClient));
     58    m_popup->m_client = m_popupClient;
     59    m_popup->m_currentIndex = index;
     60    m_popup->m_view = chromeClient->platformPageClient()->ownerWidget();
    8661
    87     QRect bounds = rect;
    88     bounds.moveTopLeft(view->contentsToWindow(rect.topLeft()));
    89     m_popup->show(bounds, index);
     62    QRect geometry(rect);
     63    geometry.moveTopLeft(view->contentsToWindow(rect.topLeft()));
     64    m_popup->m_geometry = geometry;
     65
     66    m_popup->show();
     67
    9068}
    9169
  • trunk/WebCore/platform/qt/QtAbstractWebPopup.cpp

    r53005 r53610  
    2828QtAbstractWebPopup::QtAbstractWebPopup()
    2929    : m_client(0)
     30    , m_view(0)
     31    , m_currentIndex(-1)
    3032{
    3133}
     
    4749}
    4850
     51QtAbstractWebPopup::ItemType QtAbstractWebPopup::itemType(int idx) const
     52{
     53    if (m_client->itemIsSeparator(idx))
     54        return Separator;
     55    if (m_client->itemIsLabel(idx))
     56        return Group;
     57    return Option;
     58}
     59
    4960} // namespace WebCore
  • trunk/WebCore/platform/qt/QtAbstractWebPopup.h

    r53005 r53610  
    2121#define QtAbstractWebPopup_h
    2222
     23#include "PopupMenuClient.h"
     24
    2325#include <QFont>
    2426#include <QList>
    2527#include <QRect>
     28#include <QWidget>
    2629
    2730namespace WebCore {
    2831
    29 class PopupMenuClient;
    3032
    3133class QtAbstractWebPopup {
    3234public:
    33     struct Item {
    34         enum { Option, Group, Separator } type;
    35         QString text;
    36         QString toolTip;
    37         bool enabled;
    38     };
     35    enum ItemType { Option, Group, Separator };
     36
     37    ItemType itemType(int) const;
     38    QString itemText(int idx) const { return m_client->itemText(idx); }
     39    QString itemToolTip(int idx) const { return m_client->itemToolTip(idx); }
     40    bool itemIsEnabled(int idx) const { return m_client->itemIsEnabled(idx); }
     41    int itemCount() const { return m_client->listSize(); }
     42
     43    QWidget* view() { return m_view; }
     44    QRect geometry() const { return m_geometry; }
     45    int currentIndex() const { return m_currentIndex; }
    3946
    4047    QtAbstractWebPopup();
    4148    virtual ~QtAbstractWebPopup();
    4249
    43     virtual void show(const QRect& geometry, int selectedIndex) = 0;
     50    virtual void show() = 0;
    4451    virtual void hide() = 0;
    45     virtual void populate(const QFont& font, const QList<Item>& items) = 0;
    46     virtual void setParent(QWidget* parent) = 0;
    4752
    48 protected:
    4953    void popupDidHide(bool acceptSuggestions);
    5054    void valueChanged(int index);
     55
     56    QFont font() { return m_client->menuStyle().font().font(); }
    5157
    5258private:
    5359    friend class PopupMenu;
    5460    PopupMenuClient* m_client;
     61    QWidget* m_view;
     62    int m_currentIndex;
     63    QRect m_geometry;
    5564};
    5665
  • trunk/WebKit/qt/ChangeLog

    r53464 r53610  
     12010-01-21  Luiz Agostini  <luiz.agostini@openbossa.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Custom select popups.
     6        https://bugs.webkit.org/show_bug.cgi?id=33418
     7
     8        Adjusting QtFallbackWebPopupCombo to the changes in WebCore layer.
     9
     10        * WebCoreSupport/ChromeClientQt.cpp:
     11        (WebCore::ChromeClientQt::createSelectPopup):
     12        * WebCoreSupport/ChromeClientQt.h:
     13        * WebCoreSupport/QtFallbackWebPopup.cpp:
     14        (WebCore::QtFallbackWebPopupCombo::QtFallbackWebPopupCombo):
     15        (WebCore::QtFallbackWebPopupCombo::showPopup):
     16        (WebCore::QtFallbackWebPopupCombo::hidePopup):
     17        (WebCore::QtFallbackWebPopup::QtFallbackWebPopup):
     18        (WebCore::QtFallbackWebPopup::~QtFallbackWebPopup):
     19        (WebCore::QtFallbackWebPopup::show):
     20        (WebCore::QtFallbackWebPopup::hide):
     21        (WebCore::QtFallbackWebPopup::populate):
     22        * WebCoreSupport/QtFallbackWebPopup.h:
     23
    1242010-01-19  Steve Block  <steveblock@google.com>
    225
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp

    r53005 r53610  
    467467}
    468468
    469 QtAbstractWebPopup* ChromeClientQt::createPopup()
     469QtAbstractWebPopup* ChromeClientQt::createSelectPopup()
    470470{
    471471    return new QtFallbackWebPopup;
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.h

    r53005 r53610  
    136136        virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
    137137
    138         QtAbstractWebPopup* createPopup();
     138        QtAbstractWebPopup* createSelectPopup();
    139139
    140140        QWebPage* m_webPage;
  • trunk/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp

    r53005 r53610  
    3232namespace WebCore {
    3333
    34 // QtFallbackWebPopup
    35 
    36 QtFallbackWebPopup::QtFallbackWebPopup()
    37     : QtAbstractWebPopup()
    38     , m_popupVisible(false)
     34QtFallbackWebPopupCombo::QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup)
     35    : m_ownerPopup(ownerPopup)
    3936{
    40     connect(this, SIGNAL(activated(int)),
    41             SLOT(activeChanged(int)), Qt::QueuedConnection);
    4237}
    4338
    44 
    45 void QtFallbackWebPopup::show(const QRect& geometry, int selectedIndex)
     39void QtFallbackWebPopupCombo::showPopup()
    4640{
    47     setCurrentIndex(selectedIndex);
    48 
    49     /*
    50     QWidget* parent = 0;
    51     if (client()->hostWindow() && client()->hostWindow()->platformPageClient())
    52        parent = client()->hostWindow()->platformPageClient()->ownerWidget();
    53 
    54     setParent(parent);
    55     */
    56 
    57     setGeometry(QRect(geometry.left(), geometry.top(), geometry.width(), sizeHint().height()));
    58 
    59     QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
    60                       Qt::LeftButton, Qt::NoModifier);
    61     QCoreApplication::sendEvent(this, &event);
     41    QComboBox::showPopup();
     42    m_ownerPopup.m_popupVisible = true;
    6243}
    6344
    64 void QtFallbackWebPopup::populate(const QFont& font, const QList<Item>& items)
    65 {
    66     clear();
    67 
    68     QStandardItemModel* model = qobject_cast<QStandardItemModel*>(QComboBox::model());
    69     Q_ASSERT(model);
    70 
    71     setFont(font);
    72     for (int i = 0; i < items.size(); ++i) {
    73         switch (items[i].type) {
    74         case QtAbstractWebPopup::Item::Separator:
    75             insertSeparator(i);
    76             break;
    77         case QtAbstractWebPopup::Item::Group:
    78             insertItem(i, items[i].text);
    79             model->item(i)->setEnabled(false);
    80             break;
    81         case QtAbstractWebPopup::Item::Option:
    82             insertItem(i, items[i].text);
    83             model->item(i)->setEnabled(items[i].enabled);
    84             break;
    85         }
    86     }
    87 }
    88 
    89 void QtFallbackWebPopup::showPopup()
    90 {
    91     QComboBox::showPopup();
    92     m_popupVisible = true;
    93 }
    94 
    95 void QtFallbackWebPopup::hidePopup()
     45void QtFallbackWebPopupCombo::hidePopup()
    9646{
    9747    QWidget* activeFocus = QApplication::focusWidget();
    98     if (activeFocus && activeFocus == view()
     48    if (activeFocus && activeFocus == QComboBox::view()
    9949        && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
    10050        QInputContext* qic = activeFocus->inputContext();
     
    10656
    10757    QComboBox::hidePopup();
    108     if (!m_popupVisible)
     58    if (!m_ownerPopup.m_popupVisible)
    10959        return;
    11060
    111     m_popupVisible = false;
    112     popupDidHide(true);
     61    m_ownerPopup.m_popupVisible = false;
     62    m_ownerPopup.popupDidHide(true);
     63}
     64
     65// QtFallbackWebPopup
     66
     67QtFallbackWebPopup::QtFallbackWebPopup()
     68    : QtAbstractWebPopup()
     69    , m_popupVisible(false)
     70    , m_combo(new QtFallbackWebPopupCombo(*this))
     71{
     72    connect(m_combo, SIGNAL(activated(int)),
     73            SLOT(activeChanged(int)), Qt::QueuedConnection);
     74}
     75
     76QtFallbackWebPopup::~QtFallbackWebPopup()
     77{
     78    delete m_combo;
     79}
     80
     81void QtFallbackWebPopup::show()
     82{
     83    populate();
     84    m_combo->setParent(view());
     85    m_combo->setCurrentIndex(currentIndex());
     86
     87    QRect rect = geometry();
     88    m_combo->setGeometry(QRect(rect.left(), rect.top(),
     89                               rect.width(), m_combo->sizeHint().height()));
     90
     91    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
     92                      Qt::LeftButton, Qt::NoModifier);
     93    QCoreApplication::sendEvent(m_combo, &event);
     94}
     95
     96void QtFallbackWebPopup::hide()
     97{
     98    m_combo->hidePopup();
     99}
     100
     101void QtFallbackWebPopup::populate()
     102{
     103    m_combo->clear();
     104
     105    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_combo->model());
     106    Q_ASSERT(model);
     107
     108    m_combo->setFont(font());
     109    for (int i = 0; i < itemCount(); ++i) {
     110        switch (itemType(i)) {
     111        case Separator:
     112            m_combo->insertSeparator(i);
     113            break;
     114        case Group:
     115            m_combo->insertItem(i, itemText(i));
     116            model->item(i)->setEnabled(false);
     117            break;
     118        case Option:
     119            m_combo->insertItem(i, itemText(i));
     120            model->item(i)->setEnabled(itemIsEnabled(i));
     121            break;
     122        }
     123    }
    113124}
    114125
     
    121132}
    122133
    123 void QtFallbackWebPopup::setParent(QWidget* parent)
    124 {
    125     QComboBox::setParent(parent);
    126134}
    127 
    128 }
  • trunk/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h

    r53005 r53610  
    2626namespace WebCore {
    2727
    28 class QtFallbackWebPopup : private QComboBox, public QtAbstractWebPopup {
     28class QtFallbackWebPopupCombo;
     29
     30class QtFallbackWebPopup : public QObject, public QtAbstractWebPopup {
    2931    Q_OBJECT
    3032public:
    3133    QtFallbackWebPopup();
     34    ~QtFallbackWebPopup();
    3235
    33     virtual void show(const QRect& geometry, int selectedIndex);
    34     virtual void hide() { hidePopup(); }
    35     virtual void populate(const QFont& font, const QList<Item>& items);
    36     virtual void setParent(QWidget* parent);
     36    virtual void show();
     37    virtual void hide();
    3738
    3839private slots:
     
    4041
    4142private:
     43    friend class QtFallbackWebPopupCombo;
    4244    bool m_popupVisible;
     45    QtFallbackWebPopupCombo* m_combo;
    4346
     47    void populate();
     48};
    4449
     50class QtFallbackWebPopupCombo : public QComboBox {
     51public:
     52    QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup);
    4553    virtual void showPopup();
    4654    virtual void hidePopup();
     55
     56private:
     57    QtFallbackWebPopup& m_ownerPopup;
    4758};
    4859
Note: See TracChangeset for help on using the changeset viewer.