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