2 * This file is part of the popup menu implementation for <select> elements in WebCore.
4 * Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2006 Apple Computer, Inc.
6 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
7 * Coypright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
27 #include "PopupMenuQt.h"
29 #include "ChromeClientQt.h"
30 #include "FrameView.h"
31 #include "PopupMenuClient.h"
32 #include "QtFallbackWebPopup.h"
34 #include "qwebkitplatformplugin.h"
36 class SelectData : public QWebSelectData {
38 SelectData(WebCore::PopupMenuClient*& data) : d(data) {}
40 virtual ItemType itemType(int) const;
41 virtual QString itemText(int idx) const { return QString(d ? d->itemText(idx) : ""); }
42 virtual QString itemToolTip(int idx) const { return QString(d ? d->itemToolTip(idx) : ""); }
43 virtual bool itemIsEnabled(int idx) const { return d ? d->itemIsEnabled(idx) : false; }
44 virtual int itemCount() const { return d ? d->listSize() : 0; }
45 virtual bool itemIsSelected(int idx) const { return d ? d->itemIsSelected(idx) : false; }
46 virtual bool multiple() const;
49 WebCore::PopupMenuClient*& d;
52 bool SelectData::multiple() const
57 #if ENABLE(NO_LISTBOX_RENDERING)
58 WebCore::ListPopupMenuClient* client = static_cast<WebCore::ListPopupMenuClient*>(d);
59 return client && client->multiple();
65 SelectData::ItemType SelectData::itemType(int idx) const
68 return SelectData::Option;
70 if (d->itemIsSeparator(idx))
71 return SelectData::Separator;
72 if (d->itemIsLabel(idx))
73 return SelectData::Group;
74 return SelectData::Option;
79 PopupMenuQt::PopupMenuQt(PopupMenuClient* client, const ChromeClientQt* chromeClient)
80 : m_popupClient(client)
83 , m_chromeClient(chromeClient)
87 PopupMenuQt::~PopupMenuQt()
93 void PopupMenuQt::disconnectClient()
98 void PopupMenuQt::show(const IntRect& rect, FrameView* view, int index)
100 #ifndef QT_NO_COMBOBOX
105 m_popup = m_chromeClient->createSelectPopup();
106 connect(m_popup, SIGNAL(didHide()), this, SLOT(didHide()));
107 connect(m_popup, SIGNAL(selectItem(int, bool, bool)), this, SLOT(selectItem(int, bool, bool)));
110 if (QtFallbackWebPopup* fallback = qobject_cast<QtFallbackWebPopup*>(m_popup)) {
111 QRect geometry(rect);
112 geometry.moveTopLeft(view->contentsToWindow(rect.location()));
113 fallback->setGeometry(geometry);
114 fallback->setFont(m_popupClient->menuStyle().font().font());
119 m_selectData = new SelectData(m_popupClient);
120 m_popup->show(*m_selectData);
124 void PopupMenuQt::didHide()
127 m_popupClient->popupDidHide();
130 void PopupMenuQt::hide()
136 void PopupMenuQt::updateFromElement()
139 m_popupClient->setTextFromItem(m_popupClient->selectedIndex());
142 void PopupMenuQt::selectItem(int index, bool ctrl, bool shift)
147 #if ENABLE(NO_LISTBOX_RENDERING)
148 ListPopupMenuClient* client = static_cast<ListPopupMenuClient*>(m_popupClient);
150 client->listBoxSelectItem(index, ctrl, shift);
155 m_popupClient->valueChanged(index);