author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* This file is part of the popup menu implementation for <select> elements in WebCore. |
|
3 |
* |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4 |
* Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> |
0 | 5 |
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
6 |
* Copyright (C) 2006 Apple Computer, Inc. |
|
7 |
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com |
|
8 |
* Coypright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
|
9 |
* |
|
10 |
* This library is free software; you can redistribute it and/or |
|
11 |
* modify it under the terms of the GNU Library General Public |
|
12 |
* License as published by the Free Software Foundation; either |
|
13 |
* version 2 of the License, or (at your option) any later version. |
|
14 |
* |
|
15 |
* This library is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
* Library General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU Library General Public License |
|
21 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
22 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
23 |
* Boston, MA 02110-1301, USA. |
|
24 |
* |
|
25 |
*/ |
|
26 |
||
27 |
#include "config.h" |
|
28 |
#include "PopupMenu.h" |
|
29 |
||
30 |
#include "Frame.h" |
|
31 |
#include "FrameView.h" |
|
32 |
#include "HostWindow.h" |
|
33 |
#include "PopupMenuClient.h" |
|
34 |
#include "QWebPageClient.h" |
|
35 |
#include "QWebPopup.h" |
|
36 |
||
37 |
#include <QAction> |
|
38 |
#include <QDebug> |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
#include <QGraphicsProxyWidget> |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
#include <QGraphicsScene> |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
41 |
#include <QGraphicsView> |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
42 |
#include <qgraphicswebview.h> |
0 | 43 |
#include <QListWidget> |
44 |
#include <QListWidgetItem> |
|
45 |
#include <QMenu> |
|
46 |
#include <QPoint> |
|
47 |
#include <QStandardItemModel> |
|
48 |
#include <QWidgetAction> |
|
49 |
||
50 |
namespace WebCore { |
|
51 |
||
52 |
PopupMenu::PopupMenu(PopupMenuClient* client) |
|
53 |
: m_popupClient(client) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
, m_proxy(0) |
0 | 55 |
{ |
56 |
m_popup = new QWebPopup(client); |
|
57 |
} |
|
58 |
||
59 |
PopupMenu::~PopupMenu() |
|
60 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
// If we create a proxy, then the deletion of the proxy and the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
// combo will be done by the proxy's parent (QGraphicsWebView) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
if (!m_proxy) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
delete m_popup; |
0 | 65 |
} |
66 |
||
67 |
void PopupMenu::clear() |
|
68 |
{ |
|
69 |
m_popup->clear(); |
|
70 |
} |
|
71 |
||
72 |
void PopupMenu::populate(const IntRect&) |
|
73 |
{ |
|
74 |
clear(); |
|
75 |
Q_ASSERT(client()); |
|
76 |
||
77 |
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_popup->model()); |
|
78 |
Q_ASSERT(model); |
|
79 |
||
80 |
int size = client()->listSize(); |
|
81 |
for (int i = 0; i < size; i++) { |
|
82 |
if (client()->itemIsSeparator(i)) |
|
83 |
m_popup->insertSeparator(i); |
|
84 |
else { |
|
85 |
m_popup->insertItem(i, client()->itemText(i)); |
|
86 |
||
87 |
if (model && !client()->itemIsEnabled(i)) |
|
88 |
model->item(i)->setEnabled(false); |
|
89 |
||
90 |
if (client()->itemIsSelected(i)) |
|
91 |
m_popup->setCurrentIndex(i); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
void PopupMenu::show(const IntRect& r, FrameView* v, int index) |
|
97 |
{ |
|
98 |
QWebPageClient* client = v->hostWindow()->platformPageClient(); |
|
99 |
populate(r); |
|
100 |
QRect rect = r; |
|
101 |
rect.moveTopLeft(v->contentsToWindow(r.topLeft())); |
|
102 |
rect.setHeight(m_popup->sizeHint().height()); |
|
103 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
if (QGraphicsView* view = qobject_cast<QGraphicsView*>(client->ownerWidget())) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
if (!m_proxy) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
m_proxy = new QGraphicsProxyWidget(qobject_cast<QGraphicsWebView*>(client->pluginParent())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
m_proxy->setWidget(m_popup); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
} else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
m_proxy->setVisible(true); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
m_proxy->setGeometry(rect); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
m_popup->setParent(client->ownerWidget()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
m_popup->setGeometry(rect); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
|
0 | 116 |
m_popup->setCurrentIndex(index); |
117 |
m_popup->exec(); |
|
118 |
} |
|
119 |
||
120 |
void PopupMenu::hide() |
|
121 |
{ |
|
122 |
m_popup->hidePopup(); |
|
123 |
} |
|
124 |
||
125 |
void PopupMenu::updateFromElement() |
|
126 |
{ |
|
127 |
client()->setTextFromItem(m_popupClient->selectedIndex()); |
|
128 |
} |
|
129 |
||
130 |
bool PopupMenu::itemWritingDirectionIsNatural() |
|
131 |
{ |
|
132 |
return false; |
|
133 |
} |
|
134 |
||
135 |
} |
|
136 |
||
137 |
// vim: ts=4 sw=4 et |