|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim: set ts=4 et sw=4 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include <QtCore/QCoreApplication> |
|
8 #include <QtGui/QResizeEvent> |
|
9 |
|
10 #include "mozqwidget.h" |
|
11 #include "nsWindow.h" |
|
12 |
|
13 using namespace mozilla::widget; |
|
14 |
|
15 MozQWidget::MozQWidget(nsWindow* aReceiver, QWindow* aParent) |
|
16 : QWindow(aParent) |
|
17 , mReceiver(aReceiver) |
|
18 , mUpdatePending(false) |
|
19 { |
|
20 mWindowType = mReceiver->WindowType(); |
|
21 } |
|
22 |
|
23 MozQWidget::~MozQWidget() |
|
24 { |
|
25 } |
|
26 |
|
27 void MozQWidget::render(QPainter* painter) |
|
28 { |
|
29 Q_UNUSED(painter); |
|
30 } |
|
31 |
|
32 void MozQWidget::renderLater() |
|
33 { |
|
34 if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) { |
|
35 return; |
|
36 } |
|
37 |
|
38 if (!mUpdatePending) { |
|
39 mUpdatePending = true; |
|
40 QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); |
|
41 } |
|
42 } |
|
43 |
|
44 void MozQWidget::renderNow() |
|
45 { |
|
46 if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) { |
|
47 return; |
|
48 } |
|
49 |
|
50 mReceiver->OnPaint(); |
|
51 } |
|
52 |
|
53 bool MozQWidget::event(QEvent* event) |
|
54 { |
|
55 switch (event->type()) { |
|
56 case QEvent::UpdateRequest: |
|
57 mUpdatePending = false; |
|
58 renderNow(); |
|
59 return true; |
|
60 default: |
|
61 return QWindow::event(event); |
|
62 } |
|
63 } |
|
64 |
|
65 void MozQWidget::exposeEvent(QExposeEvent* event) |
|
66 { |
|
67 Q_UNUSED(event); |
|
68 if (!isExposed() || eWindowType_child != mWindowType || !isVisible()) { |
|
69 return; |
|
70 } |
|
71 LOG(("MozQWidget::%s [%p] flags:%x\n", __FUNCTION__, (void *)this, flags())); |
|
72 renderNow(); |
|
73 |
|
74 } |
|
75 |
|
76 void MozQWidget::resizeEvent(QResizeEvent* event) |
|
77 { |
|
78 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
79 mReceiver->resizeEvent(event); |
|
80 QWindow::resizeEvent(event); |
|
81 } |
|
82 |
|
83 void MozQWidget::focusInEvent(QFocusEvent* event) |
|
84 { |
|
85 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
86 mReceiver->focusInEvent(event); |
|
87 QWindow::focusInEvent(event); |
|
88 } |
|
89 |
|
90 void MozQWidget::focusOutEvent(QFocusEvent* event) |
|
91 { |
|
92 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
93 mReceiver->focusOutEvent(event); |
|
94 QWindow::focusOutEvent(event); |
|
95 } |
|
96 |
|
97 void MozQWidget::hideEvent(QHideEvent* event) |
|
98 { |
|
99 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
100 mReceiver->hideEvent(event); |
|
101 QWindow::hideEvent(event); |
|
102 } |
|
103 |
|
104 void MozQWidget::keyPressEvent(QKeyEvent* event) |
|
105 { |
|
106 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
107 mReceiver->keyPressEvent(event); |
|
108 QWindow::keyPressEvent(event); |
|
109 } |
|
110 |
|
111 void MozQWidget::keyReleaseEvent(QKeyEvent* event) |
|
112 { |
|
113 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
114 mReceiver->keyReleaseEvent(event); |
|
115 QWindow::keyReleaseEvent(event); |
|
116 } |
|
117 |
|
118 void MozQWidget::mouseDoubleClickEvent(QMouseEvent* event) |
|
119 { |
|
120 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
121 mReceiver->mouseDoubleClickEvent(event); |
|
122 QWindow::mouseDoubleClickEvent(event); |
|
123 } |
|
124 |
|
125 void MozQWidget::mouseMoveEvent(QMouseEvent* event) |
|
126 { |
|
127 mReceiver->mouseMoveEvent(event); |
|
128 QWindow::mouseMoveEvent(event); |
|
129 } |
|
130 |
|
131 void MozQWidget::mousePressEvent(QMouseEvent* event) |
|
132 { |
|
133 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
134 mReceiver->mousePressEvent(event); |
|
135 QWindow::mousePressEvent(event); |
|
136 } |
|
137 |
|
138 void MozQWidget::mouseReleaseEvent(QMouseEvent* event) |
|
139 { |
|
140 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
141 mReceiver->mouseReleaseEvent(event); |
|
142 QWindow::mouseReleaseEvent(event); |
|
143 } |
|
144 |
|
145 void MozQWidget::moveEvent(QMoveEvent* event) |
|
146 { |
|
147 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
148 mReceiver->moveEvent(event); |
|
149 QWindow::moveEvent(event); |
|
150 } |
|
151 |
|
152 void MozQWidget::showEvent(QShowEvent* event) |
|
153 { |
|
154 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
155 mReceiver->showEvent(event); |
|
156 QWindow::showEvent(event); |
|
157 } |
|
158 |
|
159 void MozQWidget::wheelEvent(QWheelEvent* event) |
|
160 { |
|
161 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
162 mReceiver->wheelEvent(event); |
|
163 QWindow::wheelEvent(event); |
|
164 } |
|
165 |
|
166 void MozQWidget::tabletEvent(QTabletEvent* event) |
|
167 { |
|
168 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
169 QWindow::tabletEvent(event); |
|
170 } |
|
171 |
|
172 void MozQWidget::touchEvent(QTouchEvent* event) |
|
173 { |
|
174 LOG(("MozQWidget::%s [%p]\n", __FUNCTION__, (void *)this)); |
|
175 QWindow::touchEvent(event); |
|
176 } |
|
177 |
|
178 void MozQWidget::SetCursor(nsCursor aCursor) |
|
179 { |
|
180 Qt::CursorShape cursor = Qt::ArrowCursor; |
|
181 switch(aCursor) { |
|
182 case eCursor_standard: |
|
183 cursor = Qt::ArrowCursor; |
|
184 break; |
|
185 case eCursor_wait: |
|
186 cursor = Qt::WaitCursor; |
|
187 break; |
|
188 case eCursor_select: |
|
189 cursor = Qt::IBeamCursor; |
|
190 break; |
|
191 case eCursor_hyperlink: |
|
192 cursor = Qt::PointingHandCursor; |
|
193 break; |
|
194 case eCursor_ew_resize: |
|
195 cursor = Qt::SplitHCursor; |
|
196 break; |
|
197 case eCursor_ns_resize: |
|
198 cursor = Qt::SplitVCursor; |
|
199 break; |
|
200 case eCursor_nw_resize: |
|
201 case eCursor_se_resize: |
|
202 cursor = Qt::SizeBDiagCursor; |
|
203 break; |
|
204 case eCursor_ne_resize: |
|
205 case eCursor_sw_resize: |
|
206 cursor = Qt::SizeFDiagCursor; |
|
207 break; |
|
208 case eCursor_crosshair: |
|
209 case eCursor_move: |
|
210 cursor = Qt::SizeAllCursor; |
|
211 break; |
|
212 case eCursor_help: |
|
213 cursor = Qt::WhatsThisCursor; |
|
214 break; |
|
215 case eCursor_copy: |
|
216 case eCursor_alias: |
|
217 break; |
|
218 case eCursor_context_menu: |
|
219 case eCursor_cell: |
|
220 case eCursor_grab: |
|
221 case eCursor_grabbing: |
|
222 case eCursor_spinning: |
|
223 case eCursor_zoom_in: |
|
224 case eCursor_zoom_out: |
|
225 |
|
226 default: |
|
227 break; |
|
228 } |
|
229 |
|
230 setCursor(cursor); |
|
231 } |