1 /*
2 *
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21 #include "config.h"
22 #include "QWebPopup.h"
23 #include "PopupMenuStyle.h"
24
25 #include <QAbstractItemView>
26 #include <QApplication>
27 #include <QInputContext>
28 #include <QMouseEvent>
29
30 namespace WebCore {
31
QWebPopup(PopupMenuClient * client)32 QWebPopup::QWebPopup(PopupMenuClient* client)
33 : m_client(client)
34 , m_popupVisible(false)
35 {
36 Q_ASSERT(m_client);
37
38 setFont(m_client->menuStyle().font().font());
39 connect(this, SIGNAL(activated(int)),
40 SLOT(activeChanged(int)), Qt::QueuedConnection);
41 }
42
43
exec()44 void QWebPopup::exec()
45 {
46 QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
47 Qt::LeftButton, Qt::NoModifier);
48 QCoreApplication::sendEvent(this, &event);
49 }
50
showPopup()51 void QWebPopup::showPopup()
52 {
53 QComboBox::showPopup();
54 m_popupVisible = true;
55 }
56
hidePopup()57 void QWebPopup::hidePopup()
58 {
59 QWidget* activeFocus = QApplication::focusWidget();
60 if (activeFocus && activeFocus == view()
61 && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) {
62 QInputContext* qic = activeFocus->inputContext();
63 if (qic) {
64 qic->reset();
65 qic->setFocusWidget(0);
66 }
67 }
68
69 QComboBox::hidePopup();
70 if (!m_popupVisible)
71 return;
72
73 m_popupVisible = false;
74 m_client->hidePopup();
75 }
76
activeChanged(int index)77 void QWebPopup::activeChanged(int index)
78 {
79 if (index < 0)
80 return;
81
82 m_client->valueChanged(index);
83 }
84
85 } // namespace WebCore
86
87 #include "moc_QWebPopup.cpp"
88