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:expandtab:shiftwidth=4:tabstop=4: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/ArrayUtils.h" |
michael@0 | 9 | #include "mozilla/MiscEvents.h" |
michael@0 | 10 | #include "mozilla/MouseEvents.h" |
michael@0 | 11 | #include "mozilla/TextEvents.h" |
michael@0 | 12 | #include "mozilla/TouchEvents.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <QGuiApplication> |
michael@0 | 15 | #include <QtGui/QCursor> |
michael@0 | 16 | #include <QIcon> |
michael@0 | 17 | #include <QMouseEvent> |
michael@0 | 18 | #include <QWheelEvent> |
michael@0 | 19 | #include <QResizeEvent> |
michael@0 | 20 | #include <QPaintEngine> |
michael@0 | 21 | #include <QMimeData> |
michael@0 | 22 | #include <QScreen> |
michael@0 | 23 | |
michael@0 | 24 | #include <QtCore/QDebug> |
michael@0 | 25 | #include <QtCore/QEvent> |
michael@0 | 26 | #include <QtCore/QVariant> |
michael@0 | 27 | #include <algorithm> |
michael@0 | 28 | |
michael@0 | 29 | #ifdef MOZ_X11 |
michael@0 | 30 | #include <X11/Xlib.h> |
michael@0 | 31 | #include <X11/Xutil.h> |
michael@0 | 32 | #endif //MOZ_X11 |
michael@0 | 33 | |
michael@0 | 34 | #include "nsXULAppAPI.h" |
michael@0 | 35 | |
michael@0 | 36 | #include "prlink.h" |
michael@0 | 37 | |
michael@0 | 38 | #include "nsWindow.h" |
michael@0 | 39 | #include "mozqwidget.h" |
michael@0 | 40 | |
michael@0 | 41 | #include "nsIdleService.h" |
michael@0 | 42 | #include "nsRenderingContext.h" |
michael@0 | 43 | #include "nsIRollupListener.h" |
michael@0 | 44 | #include "nsWidgetsCID.h" |
michael@0 | 45 | #include "nsQtKeyUtils.h" |
michael@0 | 46 | #include "mozilla/Services.h" |
michael@0 | 47 | #include "mozilla/Preferences.h" |
michael@0 | 48 | #include "mozilla/Likely.h" |
michael@0 | 49 | #include "mozilla/layers/LayersTypes.h" |
michael@0 | 50 | #include "nsIWidgetListener.h" |
michael@0 | 51 | #include "ClientLayerManager.h" |
michael@0 | 52 | #include "BasicLayers.h" |
michael@0 | 53 | |
michael@0 | 54 | #include "nsIStringBundle.h" |
michael@0 | 55 | #include "nsGfxCIID.h" |
michael@0 | 56 | |
michael@0 | 57 | #include "imgIContainer.h" |
michael@0 | 58 | #include "nsGfxCIID.h" |
michael@0 | 59 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 60 | #include "nsAutoPtr.h" |
michael@0 | 61 | |
michael@0 | 62 | #include "gfxQtPlatform.h" |
michael@0 | 63 | |
michael@0 | 64 | #include "nsIDOMWheelEvent.h" |
michael@0 | 65 | |
michael@0 | 66 | #include "GLContext.h" |
michael@0 | 67 | |
michael@0 | 68 | #ifdef MOZ_X11 |
michael@0 | 69 | #include "keysym2ucs.h" |
michael@0 | 70 | #endif |
michael@0 | 71 | |
michael@0 | 72 | #include "Layers.h" |
michael@0 | 73 | #include "GLContextProvider.h" |
michael@0 | 74 | |
michael@0 | 75 | using namespace mozilla; |
michael@0 | 76 | using namespace mozilla::gl; |
michael@0 | 77 | using namespace mozilla::widget; |
michael@0 | 78 | using namespace mozilla::gfx; |
michael@0 | 79 | using namespace mozilla::layers; |
michael@0 | 80 | using mozilla::gl::GLContext; |
michael@0 | 81 | |
michael@0 | 82 | #define kWindowPositionSlop 20 |
michael@0 | 83 | |
michael@0 | 84 | // Qt |
michael@0 | 85 | static const int WHEEL_DELTA = 120; |
michael@0 | 86 | static bool gGlobalsInitialized = false; |
michael@0 | 87 | static bool sAltGrModifier = false; |
michael@0 | 88 | |
michael@0 | 89 | static void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem); |
michael@0 | 90 | static bool is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY); |
michael@0 | 91 | static bool isContextMenuKeyEvent(const QKeyEvent *qe); |
michael@0 | 92 | static void InitKeyEvent(WidgetKeyboardEvent &aEvent, QKeyEvent *aQEvent); |
michael@0 | 93 | |
michael@0 | 94 | nsWindow::nsWindow() |
michael@0 | 95 | { |
michael@0 | 96 | LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this)); |
michael@0 | 97 | |
michael@0 | 98 | mIsTopLevel = false; |
michael@0 | 99 | mIsDestroyed = false; |
michael@0 | 100 | mIsShown = false; |
michael@0 | 101 | mEnabled = true; |
michael@0 | 102 | mWidget = nullptr; |
michael@0 | 103 | mVisible = false; |
michael@0 | 104 | mActivatePending = false; |
michael@0 | 105 | mWindowType = eWindowType_child; |
michael@0 | 106 | mSizeState = nsSizeMode_Normal; |
michael@0 | 107 | mLastSizeMode = nsSizeMode_Normal; |
michael@0 | 108 | mQCursor = Qt::ArrowCursor; |
michael@0 | 109 | mNeedsResize = false; |
michael@0 | 110 | mNeedsMove = false; |
michael@0 | 111 | mListenForResizes = false; |
michael@0 | 112 | mNeedsShow = false; |
michael@0 | 113 | mTimerStarted = false; |
michael@0 | 114 | mMoveEvent.needDispatch = false; |
michael@0 | 115 | |
michael@0 | 116 | if (!gGlobalsInitialized) { |
michael@0 | 117 | gfxPlatform::GetPlatform(); |
michael@0 | 118 | gGlobalsInitialized = true; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags)); |
michael@0 | 122 | |
michael@0 | 123 | mIsTransparent = false; |
michael@0 | 124 | |
michael@0 | 125 | mCursor = eCursor_standard; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | nsWindow::~nsWindow() |
michael@0 | 129 | { |
michael@0 | 130 | LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this)); |
michael@0 | 131 | |
michael@0 | 132 | Destroy(); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | nsresult |
michael@0 | 136 | nsWindow::Create(nsIWidget *aParent, |
michael@0 | 137 | nsNativeWidget aNativeParent, |
michael@0 | 138 | const nsIntRect &aRect, |
michael@0 | 139 | nsDeviceContext *aContext, |
michael@0 | 140 | nsWidgetInitData *aInitData) |
michael@0 | 141 | { |
michael@0 | 142 | // only set the base parent if we're not going to be a dialog or a |
michael@0 | 143 | // toplevel |
michael@0 | 144 | nsIWidget *baseParent = aParent; |
michael@0 | 145 | |
michael@0 | 146 | // initialize all the common bits of this class |
michael@0 | 147 | BaseCreate(baseParent, aRect, aContext, aInitData); |
michael@0 | 148 | |
michael@0 | 149 | mVisible = true; |
michael@0 | 150 | |
michael@0 | 151 | // and do our common creation |
michael@0 | 152 | mParent = (nsWindow *)aParent; |
michael@0 | 153 | |
michael@0 | 154 | // save our bounds |
michael@0 | 155 | mBounds = aRect; |
michael@0 | 156 | |
michael@0 | 157 | // find native parent |
michael@0 | 158 | MozQWidget *parent = nullptr; |
michael@0 | 159 | |
michael@0 | 160 | if (aParent != nullptr) { |
michael@0 | 161 | parent = static_cast<MozQWidget*>(aParent->GetNativeData(NS_NATIVE_WIDGET)); |
michael@0 | 162 | } else if (aNativeParent != nullptr) { |
michael@0 | 163 | parent = static_cast<MozQWidget*>(aNativeParent); |
michael@0 | 164 | if (parent && mParent == nullptr) { |
michael@0 | 165 | mParent = parent->getReceiver(); |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | LOG(("Create: nsWindow [%p] mWidget:[%p] parent:[%p], natPar:[%p] mParent:%p\n", (void *)this, (void*)mWidget, parent, aNativeParent, mParent)); |
michael@0 | 170 | |
michael@0 | 171 | // ok, create our QGraphicsWidget |
michael@0 | 172 | mWidget = createQWidget(parent, aInitData); |
michael@0 | 173 | |
michael@0 | 174 | if (!mWidget) { |
michael@0 | 175 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | |
michael@0 | 179 | // resize so that everything is set to the right dimensions |
michael@0 | 180 | Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false); |
michael@0 | 181 | |
michael@0 | 182 | // check if we should listen for resizes |
michael@0 | 183 | mListenForResizes = (aNativeParent || |
michael@0 | 184 | (aInitData && aInitData->mListenForResizes)); |
michael@0 | 185 | |
michael@0 | 186 | return NS_OK; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | MozQWidget* |
michael@0 | 190 | nsWindow::createQWidget(MozQWidget* parent, |
michael@0 | 191 | nsWidgetInitData* aInitData) |
michael@0 | 192 | { |
michael@0 | 193 | const char *windowName = nullptr; |
michael@0 | 194 | Qt::WindowFlags flags = Qt::Widget; |
michael@0 | 195 | |
michael@0 | 196 | // ok, create our windows |
michael@0 | 197 | switch (mWindowType) { |
michael@0 | 198 | case eWindowType_dialog: |
michael@0 | 199 | windowName = "topLevelDialog"; |
michael@0 | 200 | flags = Qt::Dialog; |
michael@0 | 201 | break; |
michael@0 | 202 | case eWindowType_popup: |
michael@0 | 203 | windowName = "topLevelPopup"; |
michael@0 | 204 | flags = Qt::Popup; |
michael@0 | 205 | break; |
michael@0 | 206 | case eWindowType_toplevel: |
michael@0 | 207 | windowName = "topLevelWindow"; |
michael@0 | 208 | flags = Qt::Window; |
michael@0 | 209 | break; |
michael@0 | 210 | case eWindowType_invisible: |
michael@0 | 211 | windowName = "topLevelInvisible"; |
michael@0 | 212 | break; |
michael@0 | 213 | case eWindowType_child: |
michael@0 | 214 | case eWindowType_plugin: |
michael@0 | 215 | default: // sheet |
michael@0 | 216 | windowName = "paintArea"; |
michael@0 | 217 | break; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | MozQWidget* widget = new MozQWidget(this, parent); |
michael@0 | 221 | if (!widget) { |
michael@0 | 222 | return nullptr; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | widget->setObjectName(QString(windowName)); |
michael@0 | 226 | if (mWindowType == eWindowType_invisible) { |
michael@0 | 227 | widget->setVisibility(QWindow::Hidden); |
michael@0 | 228 | } |
michael@0 | 229 | if (mWindowType == eWindowType_dialog) { |
michael@0 | 230 | widget->setModality(Qt::WindowModal); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | widget->create(); |
michael@0 | 234 | |
michael@0 | 235 | // create a QGraphicsView if this is a new toplevel window |
michael@0 | 236 | LOG(("nsWindow::%s [%p] Created Window: %s, widget:%p, par:%p\n", __FUNCTION__, (void *)this, windowName, widget, parent)); |
michael@0 | 237 | |
michael@0 | 238 | return widget; |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | NS_IMETHODIMP |
michael@0 | 242 | nsWindow::Destroy(void) |
michael@0 | 243 | { |
michael@0 | 244 | if (mIsDestroyed || !mWidget) { |
michael@0 | 245 | return NS_OK; |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | LOG(("nsWindow::Destroy [%p]\n", (void *)this)); |
michael@0 | 249 | mIsDestroyed = true; |
michael@0 | 250 | |
michael@0 | 251 | /** Need to clean our LayerManager up while still alive */ |
michael@0 | 252 | if (mLayerManager) { |
michael@0 | 253 | mLayerManager->Destroy(); |
michael@0 | 254 | } |
michael@0 | 255 | mLayerManager = nullptr; |
michael@0 | 256 | |
michael@0 | 257 | // It is safe to call DestroyeCompositor several times (here and |
michael@0 | 258 | // in the parent class) since it will take effect only once. |
michael@0 | 259 | // The reason we call it here is because on gtk platforms we need |
michael@0 | 260 | // to destroy the compositor before we destroy the gdk window (which |
michael@0 | 261 | // destroys the the gl context attached to it). |
michael@0 | 262 | DestroyCompositor(); |
michael@0 | 263 | |
michael@0 | 264 | ClearCachedResources(); |
michael@0 | 265 | |
michael@0 | 266 | nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener(); |
michael@0 | 267 | if (rollupListener) { |
michael@0 | 268 | nsCOMPtr<nsIWidget> rollupWidget = rollupListener->GetRollupWidget(); |
michael@0 | 269 | if (static_cast<nsIWidget *>(this) == rollupWidget) { |
michael@0 | 270 | rollupListener->Rollup(0, nullptr, nullptr); |
michael@0 | 271 | } |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | Show(false); |
michael@0 | 275 | |
michael@0 | 276 | // walk the list of children and call destroy on them. Have to be |
michael@0 | 277 | // careful, though -- calling destroy on a kid may actually remove |
michael@0 | 278 | // it from our child list, losing its sibling links. |
michael@0 | 279 | for (nsIWidget* kid = mFirstChild; kid; ) { |
michael@0 | 280 | nsIWidget* next = kid->GetNextSibling(); |
michael@0 | 281 | kid->Destroy(); |
michael@0 | 282 | kid = next; |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | // Destroy thebes surface now. Badness can happen if we destroy |
michael@0 | 286 | // the surface after its X Window. |
michael@0 | 287 | if (mWidget) { |
michael@0 | 288 | mWidget->dropReceiver(); |
michael@0 | 289 | |
michael@0 | 290 | // Call deleteLater instead of delete; Qt still needs the object |
michael@0 | 291 | // to be valid even after sending it a Close event. We could |
michael@0 | 292 | // also set WA_DeleteOnClose, but this gives us more control. |
michael@0 | 293 | mWidget->deleteLater(); |
michael@0 | 294 | } |
michael@0 | 295 | mWidget = nullptr; |
michael@0 | 296 | |
michael@0 | 297 | OnDestroy(); |
michael@0 | 298 | |
michael@0 | 299 | return NS_OK; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | NS_IMETHODIMP |
michael@0 | 303 | nsWindow::Show(bool aState) |
michael@0 | 304 | { |
michael@0 | 305 | LOG(("nsWindow::Show [%p] state %d\n", (void *)this, aState)); |
michael@0 | 306 | if (aState == mIsShown) { |
michael@0 | 307 | return NS_OK; |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | // Clear our cached resources when the window is hidden. |
michael@0 | 311 | if (mIsShown && !aState) { |
michael@0 | 312 | ClearCachedResources(); |
michael@0 | 313 | } |
michael@0 | 314 | |
michael@0 | 315 | mIsShown = aState; |
michael@0 | 316 | |
michael@0 | 317 | if ((aState && !AreBoundsSane()) || !mWidget) { |
michael@0 | 318 | LOG(("\tbounds are insane or window hasn't been created yet\n")); |
michael@0 | 319 | mNeedsShow = true; |
michael@0 | 320 | return NS_OK; |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | if (aState) { |
michael@0 | 324 | if (mNeedsMove) { |
michael@0 | 325 | NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, |
michael@0 | 326 | false); |
michael@0 | 327 | } else if (mNeedsResize) { |
michael@0 | 328 | NativeResize(mBounds.width, mBounds.height, false); |
michael@0 | 329 | } |
michael@0 | 330 | } |
michael@0 | 331 | else { |
michael@0 | 332 | // If someone is hiding this widget, clear any needing show flag. |
michael@0 | 333 | mNeedsShow = false; |
michael@0 | 334 | } |
michael@0 | 335 | |
michael@0 | 336 | NativeShow(aState); |
michael@0 | 337 | |
michael@0 | 338 | return NS_OK; |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | bool |
michael@0 | 342 | nsWindow::IsVisible() const |
michael@0 | 343 | { |
michael@0 | 344 | return mIsShown; |
michael@0 | 345 | } |
michael@0 | 346 | |
michael@0 | 347 | NS_IMETHODIMP |
michael@0 | 348 | nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) |
michael@0 | 349 | { |
michael@0 | 350 | if (!mWidget) { |
michael@0 | 351 | return NS_ERROR_FAILURE; |
michael@0 | 352 | } |
michael@0 | 353 | |
michael@0 | 354 | int32_t screenWidth = qApp->primaryScreen()->size().width(); |
michael@0 | 355 | int32_t screenHeight = qApp->primaryScreen()->size().height(); |
michael@0 | 356 | |
michael@0 | 357 | if (aAllowSlop) { |
michael@0 | 358 | if (*aX < (kWindowPositionSlop - mBounds.width)) |
michael@0 | 359 | *aX = kWindowPositionSlop - mBounds.width; |
michael@0 | 360 | if (*aX > (screenWidth - kWindowPositionSlop)) |
michael@0 | 361 | *aX = screenWidth - kWindowPositionSlop; |
michael@0 | 362 | if (*aY < (kWindowPositionSlop - mBounds.height)) |
michael@0 | 363 | *aY = kWindowPositionSlop - mBounds.height; |
michael@0 | 364 | if (*aY > (screenHeight - kWindowPositionSlop)) |
michael@0 | 365 | *aY = screenHeight - kWindowPositionSlop; |
michael@0 | 366 | } else { |
michael@0 | 367 | if (*aX < 0) |
michael@0 | 368 | *aX = 0; |
michael@0 | 369 | if (*aX > (screenWidth - mBounds.width)) |
michael@0 | 370 | *aX = screenWidth - mBounds.width; |
michael@0 | 371 | if (*aY < 0) |
michael@0 | 372 | *aY = 0; |
michael@0 | 373 | if (*aY > (screenHeight - mBounds.height)) |
michael@0 | 374 | *aY = screenHeight - mBounds.height; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | return NS_OK; |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | NS_IMETHODIMP |
michael@0 | 381 | nsWindow::Move(double aX, double aY) |
michael@0 | 382 | { |
michael@0 | 383 | LOG(("nsWindow::Move [%p] %f %f\n", (void *)this, |
michael@0 | 384 | aX, aY)); |
michael@0 | 385 | |
michael@0 | 386 | int32_t x = NSToIntRound(aX); |
michael@0 | 387 | int32_t y = NSToIntRound(aY); |
michael@0 | 388 | |
michael@0 | 389 | if (mIsTopLevel) { |
michael@0 | 390 | SetSizeMode(nsSizeMode_Normal); |
michael@0 | 391 | } |
michael@0 | 392 | |
michael@0 | 393 | if (x == mBounds.x && y == mBounds.y) { |
michael@0 | 394 | return NS_OK; |
michael@0 | 395 | } |
michael@0 | 396 | |
michael@0 | 397 | mNeedsMove = false; |
michael@0 | 398 | |
michael@0 | 399 | // update the bounds |
michael@0 | 400 | QPoint pos(x, y); |
michael@0 | 401 | if (mIsTopLevel) { |
michael@0 | 402 | mWidget->setPosition(x, y); |
michael@0 | 403 | } |
michael@0 | 404 | else if (mWidget) { |
michael@0 | 405 | // the position of the widget is set relative to the parent |
michael@0 | 406 | // so we map the coordinates accordingly |
michael@0 | 407 | pos = mWidget->mapToGlobal(pos); |
michael@0 | 408 | mWidget->setPosition(pos); |
michael@0 | 409 | } |
michael@0 | 410 | |
michael@0 | 411 | mBounds.x = pos.x(); |
michael@0 | 412 | mBounds.y = pos.y(); |
michael@0 | 413 | |
michael@0 | 414 | NotifyRollupGeometryChange(); |
michael@0 | 415 | return NS_OK; |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | NS_IMETHODIMP |
michael@0 | 419 | nsWindow::Resize(double aWidth, double aHeight, bool aRepaint) |
michael@0 | 420 | { |
michael@0 | 421 | mBounds.width = NSToIntRound(aWidth); |
michael@0 | 422 | mBounds.height = NSToIntRound(aHeight); |
michael@0 | 423 | |
michael@0 | 424 | if (!mWidget) |
michael@0 | 425 | return NS_OK; |
michael@0 | 426 | |
michael@0 | 427 | if (mIsShown) { |
michael@0 | 428 | if (AreBoundsSane()) { |
michael@0 | 429 | if (mIsTopLevel || mNeedsShow) |
michael@0 | 430 | NativeResize(mBounds.x, mBounds.y, |
michael@0 | 431 | mBounds.width, mBounds.height, aRepaint); |
michael@0 | 432 | else |
michael@0 | 433 | NativeResize(mBounds.width, mBounds.height, aRepaint); |
michael@0 | 434 | |
michael@0 | 435 | // Does it need to be shown because it was previously insane? |
michael@0 | 436 | if (mNeedsShow) { |
michael@0 | 437 | NativeShow(true); |
michael@0 | 438 | } |
michael@0 | 439 | } |
michael@0 | 440 | else { |
michael@0 | 441 | // If someone has set this so that the needs show flag is false |
michael@0 | 442 | // and it needs to be hidden, update the flag and hide the |
michael@0 | 443 | // window. This flag will be cleared the next time someone |
michael@0 | 444 | // hides the window or shows it. It also prevents us from |
michael@0 | 445 | // calling NativeShow(false) excessively on the window which |
michael@0 | 446 | // causes unneeded X traffic. |
michael@0 | 447 | if (!mNeedsShow) { |
michael@0 | 448 | mNeedsShow = true; |
michael@0 | 449 | NativeShow(false); |
michael@0 | 450 | } |
michael@0 | 451 | } |
michael@0 | 452 | } |
michael@0 | 453 | else if (AreBoundsSane() && mListenForResizes) { |
michael@0 | 454 | // For widgets that we listen for resizes for (widgets created |
michael@0 | 455 | // with native parents) we apparently _always_ have to resize. I |
michael@0 | 456 | // dunno why, but apparently we're lame like that. |
michael@0 | 457 | NativeResize(mBounds.width, mBounds.height, aRepaint); |
michael@0 | 458 | } |
michael@0 | 459 | else { |
michael@0 | 460 | mNeedsResize = true; |
michael@0 | 461 | } |
michael@0 | 462 | |
michael@0 | 463 | // synthesize a resize event if this isn't a toplevel |
michael@0 | 464 | if (mIsTopLevel || mListenForResizes) { |
michael@0 | 465 | nsEventStatus status; |
michael@0 | 466 | DispatchResizeEvent(mBounds, status); |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | NotifyRollupGeometryChange(); |
michael@0 | 470 | return NS_OK; |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | NS_IMETHODIMP |
michael@0 | 474 | nsWindow::Resize(double aX, double aY, double aWidth, double aHeight, |
michael@0 | 475 | bool aRepaint) |
michael@0 | 476 | { |
michael@0 | 477 | mBounds.x = NSToIntRound(aX); |
michael@0 | 478 | mBounds.y = NSToIntRound(aY); |
michael@0 | 479 | mBounds.width = NSToIntRound(aWidth); |
michael@0 | 480 | mBounds.height = NSToIntRound(aHeight); |
michael@0 | 481 | |
michael@0 | 482 | mPlaced = true; |
michael@0 | 483 | |
michael@0 | 484 | if (!mWidget) { |
michael@0 | 485 | return NS_OK; |
michael@0 | 486 | } |
michael@0 | 487 | |
michael@0 | 488 | // Has this widget been set to visible? |
michael@0 | 489 | if (mIsShown) { |
michael@0 | 490 | // Are the bounds sane? |
michael@0 | 491 | if (AreBoundsSane()) { |
michael@0 | 492 | // Yep? Resize the window |
michael@0 | 493 | NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, |
michael@0 | 494 | aRepaint); |
michael@0 | 495 | // Does it need to be shown because it was previously insane? |
michael@0 | 496 | if (mNeedsShow) |
michael@0 | 497 | NativeShow(true); |
michael@0 | 498 | } |
michael@0 | 499 | else { |
michael@0 | 500 | // If someone has set this so that the needs show flag is false |
michael@0 | 501 | // and it needs to be hidden, update the flag and hide the |
michael@0 | 502 | // window. This flag will be cleared the next time someone |
michael@0 | 503 | // hides the window or shows it. It also prevents us from |
michael@0 | 504 | // calling NativeShow(false) excessively on the window which |
michael@0 | 505 | // causes unneeded X traffic. |
michael@0 | 506 | if (!mNeedsShow) { |
michael@0 | 507 | mNeedsShow = true; |
michael@0 | 508 | NativeShow(false); |
michael@0 | 509 | } |
michael@0 | 510 | } |
michael@0 | 511 | } |
michael@0 | 512 | // If the widget hasn't been shown, mark the widget as needing to be |
michael@0 | 513 | // resized before it is shown |
michael@0 | 514 | else if (AreBoundsSane() && mListenForResizes) { |
michael@0 | 515 | // For widgets that we listen for resizes for (widgets created |
michael@0 | 516 | // with native parents) we apparently _always_ have to resize. I |
michael@0 | 517 | // dunno why, but apparently we're lame like that. |
michael@0 | 518 | NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, |
michael@0 | 519 | aRepaint); |
michael@0 | 520 | } |
michael@0 | 521 | else { |
michael@0 | 522 | mNeedsResize = true; |
michael@0 | 523 | mNeedsMove = true; |
michael@0 | 524 | } |
michael@0 | 525 | |
michael@0 | 526 | if (mIsTopLevel || mListenForResizes) { |
michael@0 | 527 | // synthesize a resize event |
michael@0 | 528 | nsEventStatus status; |
michael@0 | 529 | DispatchResizeEvent(mBounds, status); |
michael@0 | 530 | } |
michael@0 | 531 | |
michael@0 | 532 | if (aRepaint) { |
michael@0 | 533 | mWidget->renderLater(); |
michael@0 | 534 | } |
michael@0 | 535 | |
michael@0 | 536 | NotifyRollupGeometryChange(); |
michael@0 | 537 | return NS_OK; |
michael@0 | 538 | } |
michael@0 | 539 | |
michael@0 | 540 | NS_IMETHODIMP |
michael@0 | 541 | nsWindow::Enable(bool aState) |
michael@0 | 542 | { |
michael@0 | 543 | mEnabled = aState; |
michael@0 | 544 | |
michael@0 | 545 | return NS_OK; |
michael@0 | 546 | } |
michael@0 | 547 | |
michael@0 | 548 | bool |
michael@0 | 549 | nsWindow::IsEnabled() const |
michael@0 | 550 | { |
michael@0 | 551 | return mEnabled; |
michael@0 | 552 | } |
michael@0 | 553 | |
michael@0 | 554 | NS_IMETHODIMP |
michael@0 | 555 | nsWindow::SetFocus(bool aRaise) |
michael@0 | 556 | { |
michael@0 | 557 | // Make sure that our owning widget has focus. If it doesn't try to |
michael@0 | 558 | // grab it. Note that we don't set our focus flag in this case. |
michael@0 | 559 | LOGFOCUS((" SetFocus [%p]\n", (void *)this)); |
michael@0 | 560 | |
michael@0 | 561 | if (!mWidget) { |
michael@0 | 562 | return NS_ERROR_FAILURE; |
michael@0 | 563 | } |
michael@0 | 564 | |
michael@0 | 565 | if (mWidget->focusObject()) { |
michael@0 | 566 | return NS_OK; |
michael@0 | 567 | } |
michael@0 | 568 | |
michael@0 | 569 | // Because QGraphicsItem cannot get the focus if they are |
michael@0 | 570 | // invisible, we look up the chain, for the lowest visible |
michael@0 | 571 | // parent and focus that one |
michael@0 | 572 | QWindow* realFocusItem = nullptr; |
michael@0 | 573 | find_first_visible_parent(mWidget, realFocusItem); |
michael@0 | 574 | |
michael@0 | 575 | if (!realFocusItem || realFocusItem->focusObject()) { |
michael@0 | 576 | return NS_OK; |
michael@0 | 577 | } |
michael@0 | 578 | |
michael@0 | 579 | if (aRaise && mWidget) { |
michael@0 | 580 | // the raising has to happen on the view widget |
michael@0 | 581 | mWidget->raise(); |
michael@0 | 582 | } |
michael@0 | 583 | |
michael@0 | 584 | // XXXndeakin why is this here? It should dispatch only when the OS |
michael@0 | 585 | // notifies us. |
michael@0 | 586 | DispatchActivateEvent(); |
michael@0 | 587 | |
michael@0 | 588 | return NS_OK; |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | NS_IMETHODIMP |
michael@0 | 592 | nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigurations) |
michael@0 | 593 | { |
michael@0 | 594 | for (uint32_t i = 0; i < aConfigurations.Length(); ++i) { |
michael@0 | 595 | const Configuration& configuration = aConfigurations[i]; |
michael@0 | 596 | |
michael@0 | 597 | nsWindow* w = static_cast<nsWindow*>(configuration.mChild); |
michael@0 | 598 | NS_ASSERTION(w->GetParent() == this, |
michael@0 | 599 | "Configured widget is not a child"); |
michael@0 | 600 | |
michael@0 | 601 | if (w->mBounds.Size() != configuration.mBounds.Size()) { |
michael@0 | 602 | w->Resize(configuration.mBounds.x, configuration.mBounds.y, |
michael@0 | 603 | configuration.mBounds.width, configuration.mBounds.height, |
michael@0 | 604 | true); |
michael@0 | 605 | } else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) { |
michael@0 | 606 | w->Move(configuration.mBounds.x, configuration.mBounds.y); |
michael@0 | 607 | } |
michael@0 | 608 | } |
michael@0 | 609 | return NS_OK; |
michael@0 | 610 | } |
michael@0 | 611 | |
michael@0 | 612 | NS_IMETHODIMP |
michael@0 | 613 | nsWindow::Invalidate(const nsIntRect &aRect) |
michael@0 | 614 | { |
michael@0 | 615 | LOGDRAW(("Invalidate (rect) [%p,%p]: %d %d %d %d\n", (void *)this, |
michael@0 | 616 | (void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height)); |
michael@0 | 617 | |
michael@0 | 618 | if (!mWidget) { |
michael@0 | 619 | return NS_OK; |
michael@0 | 620 | } |
michael@0 | 621 | |
michael@0 | 622 | mWidget->renderLater(); |
michael@0 | 623 | |
michael@0 | 624 | return NS_OK; |
michael@0 | 625 | } |
michael@0 | 626 | |
michael@0 | 627 | nsIntPoint |
michael@0 | 628 | nsWindow::WidgetToScreenOffset() |
michael@0 | 629 | { |
michael@0 | 630 | NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0)); |
michael@0 | 631 | |
michael@0 | 632 | QPoint origin(0, 0); |
michael@0 | 633 | origin = mWidget->mapToGlobal(origin); |
michael@0 | 634 | |
michael@0 | 635 | return nsIntPoint(origin.x(), origin.y()); |
michael@0 | 636 | } |
michael@0 | 637 | |
michael@0 | 638 | void* |
michael@0 | 639 | nsWindow::GetNativeData(uint32_t aDataType) |
michael@0 | 640 | { |
michael@0 | 641 | switch (aDataType) { |
michael@0 | 642 | case NS_NATIVE_WINDOW: |
michael@0 | 643 | case NS_NATIVE_WIDGET: { |
michael@0 | 644 | return mWidget; |
michael@0 | 645 | } |
michael@0 | 646 | case NS_NATIVE_SHAREABLE_WINDOW: { |
michael@0 | 647 | return mWidget ? (void*)mWidget->winId() : nullptr; |
michael@0 | 648 | } |
michael@0 | 649 | case NS_NATIVE_DISPLAY: { |
michael@0 | 650 | #ifdef MOZ_X11 |
michael@0 | 651 | return gfxQtPlatform::GetXDisplay(mWidget); |
michael@0 | 652 | #endif |
michael@0 | 653 | break; |
michael@0 | 654 | } |
michael@0 | 655 | case NS_NATIVE_PLUGIN_PORT: |
michael@0 | 656 | case NS_NATIVE_GRAPHIC: |
michael@0 | 657 | case NS_NATIVE_SHELLWIDGET: { |
michael@0 | 658 | break; |
michael@0 | 659 | } |
michael@0 | 660 | default: |
michael@0 | 661 | NS_WARNING("nsWindow::GetNativeData called with bad value"); |
michael@0 | 662 | return nullptr; |
michael@0 | 663 | } |
michael@0 | 664 | LOG(("nsWindow::%s [%p] aDataType:%i\n", __FUNCTION__, (void *)this, aDataType)); |
michael@0 | 665 | return nullptr; |
michael@0 | 666 | } |
michael@0 | 667 | |
michael@0 | 668 | NS_IMETHODIMP |
michael@0 | 669 | nsWindow::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus) |
michael@0 | 670 | { |
michael@0 | 671 | #ifdef DEBUG |
michael@0 | 672 | debug_DumpEvent(stdout, aEvent->widget, aEvent, |
michael@0 | 673 | nsAutoCString("something"), 0); |
michael@0 | 674 | #endif |
michael@0 | 675 | |
michael@0 | 676 | aStatus = nsEventStatus_eIgnore; |
michael@0 | 677 | |
michael@0 | 678 | // send it to the standard callback |
michael@0 | 679 | if (mWidgetListener) { |
michael@0 | 680 | aStatus = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents); |
michael@0 | 681 | } |
michael@0 | 682 | |
michael@0 | 683 | return NS_OK; |
michael@0 | 684 | } |
michael@0 | 685 | |
michael@0 | 686 | NS_IMETHODIMP_(void) |
michael@0 | 687 | nsWindow::SetInputContext(const InputContext& aContext, |
michael@0 | 688 | const InputContextAction& aAction) |
michael@0 | 689 | { |
michael@0 | 690 | NS_ENSURE_TRUE_VOID(mWidget); |
michael@0 | 691 | |
michael@0 | 692 | // SetSoftwareKeyboardState uses mInputContext, |
michael@0 | 693 | // so, before calling that, record aContext in mInputContext. |
michael@0 | 694 | mInputContext = aContext; |
michael@0 | 695 | |
michael@0 | 696 | switch (mInputContext.mIMEState.mEnabled) { |
michael@0 | 697 | case IMEState::ENABLED: |
michael@0 | 698 | case IMEState::PASSWORD: |
michael@0 | 699 | case IMEState::PLUGIN: |
michael@0 | 700 | SetSoftwareKeyboardState(true, aAction); |
michael@0 | 701 | break; |
michael@0 | 702 | default: |
michael@0 | 703 | SetSoftwareKeyboardState(false, aAction); |
michael@0 | 704 | break; |
michael@0 | 705 | } |
michael@0 | 706 | } |
michael@0 | 707 | |
michael@0 | 708 | NS_IMETHODIMP_(InputContext) |
michael@0 | 709 | nsWindow::GetInputContext() |
michael@0 | 710 | { |
michael@0 | 711 | mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED; |
michael@0 | 712 | // Our qt widget looks like using only one context per process. |
michael@0 | 713 | // However, it's better to set the context's pointer. |
michael@0 | 714 | mInputContext.mNativeIMEContext = qApp->inputMethod(); |
michael@0 | 715 | |
michael@0 | 716 | return mInputContext; |
michael@0 | 717 | } |
michael@0 | 718 | |
michael@0 | 719 | NS_IMETHODIMP |
michael@0 | 720 | nsWindow::ReparentNativeWidget(nsIWidget *aNewParent) |
michael@0 | 721 | { |
michael@0 | 722 | NS_PRECONDITION(aNewParent, ""); |
michael@0 | 723 | |
michael@0 | 724 | MozQWidget* newParent = static_cast<MozQWidget*>(aNewParent->GetNativeData(NS_NATIVE_WINDOW)); |
michael@0 | 725 | NS_ASSERTION(newParent, "Parent widget has a null native window handle"); |
michael@0 | 726 | if (mWidget) { |
michael@0 | 727 | mWidget->setParent(newParent); |
michael@0 | 728 | } |
michael@0 | 729 | return NS_OK; |
michael@0 | 730 | } |
michael@0 | 731 | |
michael@0 | 732 | NS_IMETHODIMP |
michael@0 | 733 | nsWindow::MakeFullScreen(bool aFullScreen) |
michael@0 | 734 | { |
michael@0 | 735 | NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE); |
michael@0 | 736 | |
michael@0 | 737 | if (aFullScreen) { |
michael@0 | 738 | if (mSizeMode != nsSizeMode_Fullscreen) { |
michael@0 | 739 | mLastSizeMode = mSizeMode; |
michael@0 | 740 | } |
michael@0 | 741 | |
michael@0 | 742 | mSizeMode = nsSizeMode_Fullscreen; |
michael@0 | 743 | mWidget->showFullScreen(); |
michael@0 | 744 | } |
michael@0 | 745 | else { |
michael@0 | 746 | mSizeMode = mLastSizeMode; |
michael@0 | 747 | |
michael@0 | 748 | switch (mSizeMode) { |
michael@0 | 749 | case nsSizeMode_Maximized: |
michael@0 | 750 | mWidget->showMaximized(); |
michael@0 | 751 | break; |
michael@0 | 752 | case nsSizeMode_Minimized: |
michael@0 | 753 | mWidget->showMinimized(); |
michael@0 | 754 | break; |
michael@0 | 755 | case nsSizeMode_Normal: |
michael@0 | 756 | mWidget->showNormal(); |
michael@0 | 757 | break; |
michael@0 | 758 | default: |
michael@0 | 759 | mWidget->showNormal(); |
michael@0 | 760 | break; |
michael@0 | 761 | } |
michael@0 | 762 | } |
michael@0 | 763 | |
michael@0 | 764 | NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen, |
michael@0 | 765 | "mLastSizeMode should never be fullscreen"); |
michael@0 | 766 | return nsBaseWidget::MakeFullScreen(aFullScreen); |
michael@0 | 767 | } |
michael@0 | 768 | |
michael@0 | 769 | LayerManager* |
michael@0 | 770 | nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager, |
michael@0 | 771 | LayersBackend aBackendHint, |
michael@0 | 772 | LayerManagerPersistence aPersistence, |
michael@0 | 773 | bool* aAllowRetaining) |
michael@0 | 774 | { |
michael@0 | 775 | if (!mLayerManager && eTransparencyTransparent == GetTransparencyMode()) { |
michael@0 | 776 | mLayerManager = CreateBasicLayerManager(); |
michael@0 | 777 | } |
michael@0 | 778 | |
michael@0 | 779 | return nsBaseWidget::GetLayerManager(aShadowManager, aBackendHint, |
michael@0 | 780 | aPersistence, aAllowRetaining); |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | void |
michael@0 | 784 | nsWindow::UserActivity() |
michael@0 | 785 | { |
michael@0 | 786 | if (!mIdleService) { |
michael@0 | 787 | mIdleService = do_GetService("@mozilla.org/widget/idleservice;1"); |
michael@0 | 788 | } |
michael@0 | 789 | |
michael@0 | 790 | if (mIdleService) { |
michael@0 | 791 | mIdleService->ResetIdleTimeOut(0); |
michael@0 | 792 | } |
michael@0 | 793 | } |
michael@0 | 794 | |
michael@0 | 795 | uint32_t |
michael@0 | 796 | nsWindow::GetGLFrameBufferFormat() |
michael@0 | 797 | { |
michael@0 | 798 | if (mLayerManager && |
michael@0 | 799 | mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) { |
michael@0 | 800 | return LOCAL_GL_RGB; |
michael@0 | 801 | } |
michael@0 | 802 | return LOCAL_GL_NONE; |
michael@0 | 803 | } |
michael@0 | 804 | |
michael@0 | 805 | NS_IMETHODIMP |
michael@0 | 806 | nsWindow::SetCursor(nsCursor aCursor) |
michael@0 | 807 | { |
michael@0 | 808 | if (mCursor == aCursor) { |
michael@0 | 809 | return NS_OK; |
michael@0 | 810 | } |
michael@0 | 811 | |
michael@0 | 812 | mCursor = aCursor; |
michael@0 | 813 | if (mWidget) { |
michael@0 | 814 | mWidget->SetCursor(mCursor); |
michael@0 | 815 | } |
michael@0 | 816 | return NS_OK; |
michael@0 | 817 | } |
michael@0 | 818 | |
michael@0 | 819 | NS_IMETHODIMP |
michael@0 | 820 | nsWindow::SetTitle(const nsAString& aTitle) |
michael@0 | 821 | { |
michael@0 | 822 | QString qStr(QString::fromUtf16((const ushort*)aTitle.BeginReading(), aTitle.Length())); |
michael@0 | 823 | |
michael@0 | 824 | mWidget->setTitle(qStr); |
michael@0 | 825 | |
michael@0 | 826 | return NS_OK; |
michael@0 | 827 | } |
michael@0 | 828 | |
michael@0 | 829 | // EVENTS |
michael@0 | 830 | |
michael@0 | 831 | void |
michael@0 | 832 | nsWindow::OnPaint() |
michael@0 | 833 | { |
michael@0 | 834 | LOGDRAW(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this)); |
michael@0 | 835 | nsIWidgetListener* listener = |
michael@0 | 836 | mAttachedWidgetListener ? mAttachedWidgetListener : mWidgetListener; |
michael@0 | 837 | if (!listener) { |
michael@0 | 838 | return; |
michael@0 | 839 | } |
michael@0 | 840 | |
michael@0 | 841 | listener->WillPaintWindow(this); |
michael@0 | 842 | |
michael@0 | 843 | switch (GetLayerManager()->GetBackendType()) { |
michael@0 | 844 | case mozilla::layers::LayersBackend::LAYERS_CLIENT: { |
michael@0 | 845 | nsIntRegion region(nsIntRect(0, 0, mWidget->width(), mWidget->height())); |
michael@0 | 846 | listener->PaintWindow(this, region); |
michael@0 | 847 | break; |
michael@0 | 848 | } |
michael@0 | 849 | default: |
michael@0 | 850 | NS_ERROR("Invalid layer manager"); |
michael@0 | 851 | } |
michael@0 | 852 | |
michael@0 | 853 | listener->DidPaintWindow(); |
michael@0 | 854 | } |
michael@0 | 855 | |
michael@0 | 856 | nsEventStatus |
michael@0 | 857 | nsWindow::moveEvent(QMoveEvent* aEvent) |
michael@0 | 858 | { |
michael@0 | 859 | LOG(("configure event [%p] %d %d\n", (void *)this, |
michael@0 | 860 | aEvent->pos().x(), aEvent->pos().y())); |
michael@0 | 861 | |
michael@0 | 862 | // can we shortcut? |
michael@0 | 863 | if (!mWidget || !mWidgetListener) |
michael@0 | 864 | return nsEventStatus_eIgnore; |
michael@0 | 865 | |
michael@0 | 866 | if ((mBounds.x == aEvent->pos().x() && |
michael@0 | 867 | mBounds.y == aEvent->pos().y())) |
michael@0 | 868 | { |
michael@0 | 869 | return nsEventStatus_eIgnore; |
michael@0 | 870 | } |
michael@0 | 871 | |
michael@0 | 872 | NotifyWindowMoved(aEvent->pos().x(), aEvent->pos().y()); |
michael@0 | 873 | return nsEventStatus_eConsumeNoDefault; |
michael@0 | 874 | } |
michael@0 | 875 | |
michael@0 | 876 | nsEventStatus |
michael@0 | 877 | nsWindow::resizeEvent(QResizeEvent* aEvent) |
michael@0 | 878 | { |
michael@0 | 879 | nsIntRect rect; |
michael@0 | 880 | |
michael@0 | 881 | // Generate XPFE resize event |
michael@0 | 882 | GetBounds(rect); |
michael@0 | 883 | |
michael@0 | 884 | rect.width = aEvent->size().width(); |
michael@0 | 885 | rect.height = aEvent->size().height(); |
michael@0 | 886 | |
michael@0 | 887 | mBounds.width = rect.width; |
michael@0 | 888 | mBounds.height = rect.height; |
michael@0 | 889 | |
michael@0 | 890 | nsEventStatus status; |
michael@0 | 891 | DispatchResizeEvent(rect, status); |
michael@0 | 892 | return status; |
michael@0 | 893 | } |
michael@0 | 894 | |
michael@0 | 895 | nsEventStatus |
michael@0 | 896 | nsWindow::mouseMoveEvent(QMouseEvent* aEvent) |
michael@0 | 897 | { |
michael@0 | 898 | UserActivity(); |
michael@0 | 899 | |
michael@0 | 900 | mMoveEvent.pos = aEvent->pos(); |
michael@0 | 901 | mMoveEvent.modifiers = aEvent->modifiers(); |
michael@0 | 902 | mMoveEvent.needDispatch = true; |
michael@0 | 903 | DispatchMotionToMainThread(); |
michael@0 | 904 | |
michael@0 | 905 | return nsEventStatus_eIgnore; |
michael@0 | 906 | } |
michael@0 | 907 | |
michael@0 | 908 | nsEventStatus |
michael@0 | 909 | nsWindow::mousePressEvent(QMouseEvent* aEvent) |
michael@0 | 910 | { |
michael@0 | 911 | // The user has done something. |
michael@0 | 912 | UserActivity(); |
michael@0 | 913 | |
michael@0 | 914 | QPoint pos = aEvent->pos(); |
michael@0 | 915 | |
michael@0 | 916 | // we check against the widgets geometry, so use parent coordinates |
michael@0 | 917 | // for the check |
michael@0 | 918 | if (mWidget) |
michael@0 | 919 | pos = mWidget->mapToGlobal(pos); |
michael@0 | 920 | |
michael@0 | 921 | if (CheckForRollup( pos.x(), pos.y(), false)) |
michael@0 | 922 | return nsEventStatus_eIgnore; |
michael@0 | 923 | |
michael@0 | 924 | uint16_t domButton; |
michael@0 | 925 | switch (aEvent->button()) { |
michael@0 | 926 | case Qt::MidButton: |
michael@0 | 927 | domButton = WidgetMouseEvent::eMiddleButton; |
michael@0 | 928 | break; |
michael@0 | 929 | case Qt::RightButton: |
michael@0 | 930 | domButton = WidgetMouseEvent::eRightButton; |
michael@0 | 931 | break; |
michael@0 | 932 | default: |
michael@0 | 933 | domButton = WidgetMouseEvent::eLeftButton; |
michael@0 | 934 | break; |
michael@0 | 935 | } |
michael@0 | 936 | |
michael@0 | 937 | WidgetMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, |
michael@0 | 938 | WidgetMouseEvent::eReal); |
michael@0 | 939 | event.button = domButton; |
michael@0 | 940 | InitButtonEvent(event, aEvent, 1); |
michael@0 | 941 | |
michael@0 | 942 | LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton)); |
michael@0 | 943 | |
michael@0 | 944 | nsEventStatus status = DispatchEvent(&event); |
michael@0 | 945 | |
michael@0 | 946 | // right menu click on linux should also pop up a context menu |
michael@0 | 947 | if (domButton == WidgetMouseEvent::eRightButton && |
michael@0 | 948 | MOZ_LIKELY(!mIsDestroyed)) { |
michael@0 | 949 | WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this, |
michael@0 | 950 | WidgetMouseEvent::eReal); |
michael@0 | 951 | InitButtonEvent(contextMenuEvent, aEvent, 1); |
michael@0 | 952 | DispatchEvent(&contextMenuEvent, status); |
michael@0 | 953 | } |
michael@0 | 954 | |
michael@0 | 955 | return status; |
michael@0 | 956 | } |
michael@0 | 957 | |
michael@0 | 958 | nsEventStatus |
michael@0 | 959 | nsWindow::mouseReleaseEvent(QMouseEvent* aEvent) |
michael@0 | 960 | { |
michael@0 | 961 | // The user has done something. |
michael@0 | 962 | UserActivity(); |
michael@0 | 963 | |
michael@0 | 964 | uint16_t domButton; |
michael@0 | 965 | |
michael@0 | 966 | switch (aEvent->button()) { |
michael@0 | 967 | case Qt::MidButton: |
michael@0 | 968 | domButton = WidgetMouseEvent::eMiddleButton; |
michael@0 | 969 | break; |
michael@0 | 970 | case Qt::RightButton: |
michael@0 | 971 | domButton = WidgetMouseEvent::eRightButton; |
michael@0 | 972 | break; |
michael@0 | 973 | default: |
michael@0 | 974 | domButton = WidgetMouseEvent::eLeftButton; |
michael@0 | 975 | break; |
michael@0 | 976 | } |
michael@0 | 977 | |
michael@0 | 978 | LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton)); |
michael@0 | 979 | |
michael@0 | 980 | WidgetMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, |
michael@0 | 981 | WidgetMouseEvent::eReal); |
michael@0 | 982 | event.button = domButton; |
michael@0 | 983 | InitButtonEvent(event, aEvent, 1); |
michael@0 | 984 | |
michael@0 | 985 | nsEventStatus status = DispatchEvent(&event); |
michael@0 | 986 | |
michael@0 | 987 | return status; |
michael@0 | 988 | } |
michael@0 | 989 | |
michael@0 | 990 | nsEventStatus |
michael@0 | 991 | nsWindow::mouseDoubleClickEvent(QMouseEvent* aEvent) |
michael@0 | 992 | { |
michael@0 | 993 | uint32_t eventType; |
michael@0 | 994 | |
michael@0 | 995 | switch (aEvent->button()) { |
michael@0 | 996 | case Qt::MidButton: |
michael@0 | 997 | eventType = WidgetMouseEvent::eMiddleButton; |
michael@0 | 998 | break; |
michael@0 | 999 | case Qt::RightButton: |
michael@0 | 1000 | eventType = WidgetMouseEvent::eRightButton; |
michael@0 | 1001 | break; |
michael@0 | 1002 | default: |
michael@0 | 1003 | eventType = WidgetMouseEvent::eLeftButton; |
michael@0 | 1004 | break; |
michael@0 | 1005 | } |
michael@0 | 1006 | |
michael@0 | 1007 | WidgetMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this, |
michael@0 | 1008 | WidgetMouseEvent::eReal); |
michael@0 | 1009 | event.button = eventType; |
michael@0 | 1010 | |
michael@0 | 1011 | InitButtonEvent(event, aEvent, 2); |
michael@0 | 1012 | //pressed |
michael@0 | 1013 | return DispatchEvent(&event); |
michael@0 | 1014 | } |
michael@0 | 1015 | |
michael@0 | 1016 | nsEventStatus |
michael@0 | 1017 | nsWindow::focusInEvent(QFocusEvent* aEvent) |
michael@0 | 1018 | { |
michael@0 | 1019 | LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this)); |
michael@0 | 1020 | |
michael@0 | 1021 | if (!mWidget) { |
michael@0 | 1022 | return nsEventStatus_eIgnore; |
michael@0 | 1023 | } |
michael@0 | 1024 | |
michael@0 | 1025 | DispatchActivateEventOnTopLevelWindow(); |
michael@0 | 1026 | |
michael@0 | 1027 | LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this)); |
michael@0 | 1028 | return nsEventStatus_eIgnore; |
michael@0 | 1029 | } |
michael@0 | 1030 | |
michael@0 | 1031 | nsEventStatus |
michael@0 | 1032 | nsWindow::focusOutEvent(QFocusEvent* aEvent) |
michael@0 | 1033 | { |
michael@0 | 1034 | LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this)); |
michael@0 | 1035 | |
michael@0 | 1036 | if (!mWidget) { |
michael@0 | 1037 | return nsEventStatus_eIgnore; |
michael@0 | 1038 | } |
michael@0 | 1039 | |
michael@0 | 1040 | DispatchDeactivateEventOnTopLevelWindow(); |
michael@0 | 1041 | |
michael@0 | 1042 | LOGFOCUS(("Done with container focus out [%p]\n", (void *)this)); |
michael@0 | 1043 | return nsEventStatus_eIgnore; |
michael@0 | 1044 | } |
michael@0 | 1045 | |
michael@0 | 1046 | nsEventStatus |
michael@0 | 1047 | nsWindow::keyPressEvent(QKeyEvent* aEvent) |
michael@0 | 1048 | { |
michael@0 | 1049 | LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this)); |
michael@0 | 1050 | |
michael@0 | 1051 | // The user has done something. |
michael@0 | 1052 | UserActivity(); |
michael@0 | 1053 | |
michael@0 | 1054 | if (aEvent->key() == Qt::Key_AltGr) { |
michael@0 | 1055 | sAltGrModifier = true; |
michael@0 | 1056 | } |
michael@0 | 1057 | |
michael@0 | 1058 | #ifdef MOZ_X11 |
michael@0 | 1059 | // before we dispatch a key, check if it's the context menu key. |
michael@0 | 1060 | // If so, send a context menu key event instead. |
michael@0 | 1061 | if (isContextMenuKeyEvent(aEvent)) { |
michael@0 | 1062 | WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this, |
michael@0 | 1063 | WidgetMouseEvent::eReal, |
michael@0 | 1064 | WidgetMouseEvent::eContextMenuKey); |
michael@0 | 1065 | //keyEventToContextMenuEvent(&event, &contextMenuEvent); |
michael@0 | 1066 | return DispatchEvent(&contextMenuEvent); |
michael@0 | 1067 | } |
michael@0 | 1068 | |
michael@0 | 1069 | uint32_t domCharCode = 0; |
michael@0 | 1070 | uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key()); |
michael@0 | 1071 | |
michael@0 | 1072 | // get keymap and modifier map from the Xserver |
michael@0 | 1073 | Display *display = gfxQtPlatform::GetXDisplay(mWidget); |
michael@0 | 1074 | int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode; |
michael@0 | 1075 | XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode); |
michael@0 | 1076 | XModifierKeymap *xmodmap = XGetModifierMapping(display); |
michael@0 | 1077 | if (!xmodmap) |
michael@0 | 1078 | return nsEventStatus_eIgnore; |
michael@0 | 1079 | |
michael@0 | 1080 | KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode, |
michael@0 | 1081 | &xkeysyms_per_keycode); |
michael@0 | 1082 | if (!xkeymap) { |
michael@0 | 1083 | XFreeModifiermap(xmodmap); |
michael@0 | 1084 | return nsEventStatus_eIgnore; |
michael@0 | 1085 | } |
michael@0 | 1086 | |
michael@0 | 1087 | // create modifier masks |
michael@0 | 1088 | qint32 shift_mask = 0, shift_lock_mask = 0, caps_lock_mask = 0, num_lock_mask = 0; |
michael@0 | 1089 | |
michael@0 | 1090 | for (int i = 0; i < 8 * xmodmap->max_keypermod; ++i) { |
michael@0 | 1091 | qint32 maskbit = 1 << (i / xmodmap->max_keypermod); |
michael@0 | 1092 | KeyCode modkeycode = xmodmap->modifiermap[i]; |
michael@0 | 1093 | if (modkeycode == NoSymbol) { |
michael@0 | 1094 | continue; |
michael@0 | 1095 | } |
michael@0 | 1096 | |
michael@0 | 1097 | quint32 mapindex = (modkeycode - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1098 | for (int j = 0; j < xkeysyms_per_keycode; ++j) { |
michael@0 | 1099 | KeySym modkeysym = xkeymap[mapindex + j]; |
michael@0 | 1100 | switch (modkeysym) { |
michael@0 | 1101 | case XK_Num_Lock: |
michael@0 | 1102 | num_lock_mask |= maskbit; |
michael@0 | 1103 | break; |
michael@0 | 1104 | case XK_Caps_Lock: |
michael@0 | 1105 | caps_lock_mask |= maskbit; |
michael@0 | 1106 | break; |
michael@0 | 1107 | case XK_Shift_Lock: |
michael@0 | 1108 | shift_lock_mask |= maskbit; |
michael@0 | 1109 | break; |
michael@0 | 1110 | case XK_Shift_L: |
michael@0 | 1111 | case XK_Shift_R: |
michael@0 | 1112 | shift_mask |= maskbit; |
michael@0 | 1113 | break; |
michael@0 | 1114 | } |
michael@0 | 1115 | } |
michael@0 | 1116 | } |
michael@0 | 1117 | // indicate whether is down or not |
michael@0 | 1118 | bool shift_state = ((shift_mask & aEvent->nativeModifiers()) != 0) ^ |
michael@0 | 1119 | (bool)(shift_lock_mask & aEvent->nativeModifiers()); |
michael@0 | 1120 | bool capslock_state = (bool)(caps_lock_mask & aEvent->nativeModifiers()); |
michael@0 | 1121 | |
michael@0 | 1122 | // try to find a keysym that we can translate to a DOMKeyCode |
michael@0 | 1123 | // this is needed because some of Qt's keycodes cannot be translated |
michael@0 | 1124 | // TODO: use US keyboard keymap instead of localised keymap |
michael@0 | 1125 | if (!domKeyCode && |
michael@0 | 1126 | aEvent->nativeScanCode() >= (quint32)x_min_keycode && |
michael@0 | 1127 | aEvent->nativeScanCode() <= (quint32)x_max_keycode) { |
michael@0 | 1128 | int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1129 | for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) { |
michael@0 | 1130 | domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]); |
michael@0 | 1131 | } |
michael@0 | 1132 | } |
michael@0 | 1133 | |
michael@0 | 1134 | // store character in domCharCode |
michael@0 | 1135 | if (aEvent->text().length() && aEvent->text()[0].isPrint()) |
michael@0 | 1136 | domCharCode = (int32_t) aEvent->text()[0].unicode(); |
michael@0 | 1137 | |
michael@0 | 1138 | KeyNameIndex keyNameIndex = |
michael@0 | 1139 | domCharCode ? KEY_NAME_INDEX_PrintableKey : |
michael@0 | 1140 | QtKeyCodeToDOMKeyNameIndex(aEvent->key()); |
michael@0 | 1141 | |
michael@0 | 1142 | // If the key isn't autorepeat, we need to send the initial down event |
michael@0 | 1143 | if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) { |
michael@0 | 1144 | // send the key down event |
michael@0 | 1145 | |
michael@0 | 1146 | SetKeyDownFlag(domKeyCode); |
michael@0 | 1147 | |
michael@0 | 1148 | WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this); |
michael@0 | 1149 | InitKeyEvent(downEvent, aEvent); |
michael@0 | 1150 | |
michael@0 | 1151 | downEvent.keyCode = domKeyCode; |
michael@0 | 1152 | downEvent.mKeyNameIndex = keyNameIndex; |
michael@0 | 1153 | |
michael@0 | 1154 | nsEventStatus status = DispatchEvent(&downEvent); |
michael@0 | 1155 | |
michael@0 | 1156 | // DispatchEvent can Destroy us (bug 378273) |
michael@0 | 1157 | if (MOZ_UNLIKELY(mIsDestroyed)) { |
michael@0 | 1158 | qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed"; |
michael@0 | 1159 | return status; |
michael@0 | 1160 | } |
michael@0 | 1161 | |
michael@0 | 1162 | // If prevent default on keydown, don't dispatch keypress event |
michael@0 | 1163 | if (status == nsEventStatus_eConsumeNoDefault) { |
michael@0 | 1164 | return nsEventStatus_eConsumeNoDefault; |
michael@0 | 1165 | } |
michael@0 | 1166 | } |
michael@0 | 1167 | |
michael@0 | 1168 | // Don't pass modifiers as NS_KEY_PRESS events. |
michael@0 | 1169 | // Instead of selectively excluding some keys from NS_KEY_PRESS events, |
michael@0 | 1170 | // we instead selectively include (as per MSDN spec |
michael@0 | 1171 | // ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28VS.71%29.aspx ); |
michael@0 | 1172 | // no official spec covers KeyPress events). |
michael@0 | 1173 | if (aEvent->key() == Qt::Key_Shift || |
michael@0 | 1174 | aEvent->key() == Qt::Key_Control || |
michael@0 | 1175 | aEvent->key() == Qt::Key_Meta || |
michael@0 | 1176 | aEvent->key() == Qt::Key_Alt || |
michael@0 | 1177 | aEvent->key() == Qt::Key_AltGr) { |
michael@0 | 1178 | |
michael@0 | 1179 | return nsEventStatus_eIgnore; |
michael@0 | 1180 | } |
michael@0 | 1181 | |
michael@0 | 1182 | // Look for specialized app-command keys |
michael@0 | 1183 | switch (aEvent->key()) { |
michael@0 | 1184 | case Qt::Key_Back: |
michael@0 | 1185 | return DispatchCommandEvent(nsGkAtoms::Back); |
michael@0 | 1186 | case Qt::Key_Forward: |
michael@0 | 1187 | return DispatchCommandEvent(nsGkAtoms::Forward); |
michael@0 | 1188 | case Qt::Key_Refresh: |
michael@0 | 1189 | return DispatchCommandEvent(nsGkAtoms::Reload); |
michael@0 | 1190 | case Qt::Key_Stop: |
michael@0 | 1191 | return DispatchCommandEvent(nsGkAtoms::Stop); |
michael@0 | 1192 | case Qt::Key_Search: |
michael@0 | 1193 | return DispatchCommandEvent(nsGkAtoms::Search); |
michael@0 | 1194 | case Qt::Key_Favorites: |
michael@0 | 1195 | return DispatchCommandEvent(nsGkAtoms::Bookmarks); |
michael@0 | 1196 | case Qt::Key_HomePage: |
michael@0 | 1197 | return DispatchCommandEvent(nsGkAtoms::Home); |
michael@0 | 1198 | case Qt::Key_Copy: |
michael@0 | 1199 | case Qt::Key_F16: // F16, F20, F18, F14 are old keysyms for Copy Cut Paste Undo |
michael@0 | 1200 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_COPY); |
michael@0 | 1201 | case Qt::Key_Cut: |
michael@0 | 1202 | case Qt::Key_F20: |
michael@0 | 1203 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_CUT); |
michael@0 | 1204 | case Qt::Key_Paste: |
michael@0 | 1205 | case Qt::Key_F18: |
michael@0 | 1206 | case Qt::Key_F9: |
michael@0 | 1207 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_PASTE); |
michael@0 | 1208 | case Qt::Key_F14: |
michael@0 | 1209 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO); |
michael@0 | 1210 | } |
michael@0 | 1211 | |
michael@0 | 1212 | // Qt::Key_Redo and Qt::Key_Undo are not available yet. |
michael@0 | 1213 | if (aEvent->nativeVirtualKey() == 0xff66) { |
michael@0 | 1214 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO); |
michael@0 | 1215 | } |
michael@0 | 1216 | if (aEvent->nativeVirtualKey() == 0xff65) { |
michael@0 | 1217 | return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO); |
michael@0 | 1218 | } |
michael@0 | 1219 | |
michael@0 | 1220 | WidgetKeyboardEvent event(true, NS_KEY_PRESS, this); |
michael@0 | 1221 | InitKeyEvent(event, aEvent); |
michael@0 | 1222 | |
michael@0 | 1223 | // If there is no charcode attainable from the text, try to |
michael@0 | 1224 | // generate it from the keycode. Check shift state for case |
michael@0 | 1225 | // Also replace the charcode if ControlModifier is the only |
michael@0 | 1226 | // pressed Modifier |
michael@0 | 1227 | if ((!domCharCode) && |
michael@0 | 1228 | (QGuiApplication::keyboardModifiers() & |
michael@0 | 1229 | (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) { |
michael@0 | 1230 | |
michael@0 | 1231 | // get a character from X11 key map |
michael@0 | 1232 | KeySym keysym = aEvent->nativeVirtualKey(); |
michael@0 | 1233 | if (keysym) { |
michael@0 | 1234 | domCharCode = (uint32_t) keysym2ucs(keysym); |
michael@0 | 1235 | if (domCharCode == -1 || !QChar((quint32)domCharCode).isPrint()) { |
michael@0 | 1236 | domCharCode = 0; |
michael@0 | 1237 | } |
michael@0 | 1238 | } |
michael@0 | 1239 | |
michael@0 | 1240 | // if Ctrl is pressed and domCharCode is not a ASCII character |
michael@0 | 1241 | if (domCharCode > 0xFF && (QGuiApplication::keyboardModifiers() & Qt::ControlModifier)) { |
michael@0 | 1242 | // replace Unicode character |
michael@0 | 1243 | int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1244 | for (int i = 0; i < xkeysyms_per_keycode; ++i) { |
michael@0 | 1245 | if (xkeymap[index + i] <= 0xFF && !shift_state) { |
michael@0 | 1246 | domCharCode = (uint32_t) QChar::toLower((uint) xkeymap[index + i]); |
michael@0 | 1247 | break; |
michael@0 | 1248 | } |
michael@0 | 1249 | } |
michael@0 | 1250 | } |
michael@0 | 1251 | |
michael@0 | 1252 | } else { // The key event should cause a character input. |
michael@0 | 1253 | // At that time, we need to reset the modifiers |
michael@0 | 1254 | // because nsEditor will not accept a key event |
michael@0 | 1255 | // for text input if one or more modifiers are set. |
michael@0 | 1256 | event.modifiers &= ~(MODIFIER_CONTROL | |
michael@0 | 1257 | MODIFIER_ALT | |
michael@0 | 1258 | MODIFIER_META); |
michael@0 | 1259 | } |
michael@0 | 1260 | |
michael@0 | 1261 | KeySym keysym = NoSymbol; |
michael@0 | 1262 | int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1263 | for (int i = 0; i < xkeysyms_per_keycode; ++i) { |
michael@0 | 1264 | if (xkeymap[index + i] == aEvent->nativeVirtualKey()) { |
michael@0 | 1265 | if ((i % 2) == 0) { // shifted char |
michael@0 | 1266 | keysym = xkeymap[index + i + 1]; |
michael@0 | 1267 | break; |
michael@0 | 1268 | } else { // unshifted char |
michael@0 | 1269 | keysym = xkeymap[index + i - 1]; |
michael@0 | 1270 | break; |
michael@0 | 1271 | } |
michael@0 | 1272 | } |
michael@0 | 1273 | if (xkeysyms_per_keycode - 1 == i) { |
michael@0 | 1274 | qWarning() << "Symbol '" << aEvent->nativeVirtualKey() << "' not found"; |
michael@0 | 1275 | } |
michael@0 | 1276 | } |
michael@0 | 1277 | QChar unshiftedChar(domCharCode); |
michael@0 | 1278 | long ucs = keysym2ucs(keysym); |
michael@0 | 1279 | ucs = ucs == -1 ? 0 : ucs; |
michael@0 | 1280 | QChar shiftedChar((uint)ucs); |
michael@0 | 1281 | |
michael@0 | 1282 | // append alternativeCharCodes if modifier is pressed |
michael@0 | 1283 | // append an additional alternativeCharCodes if domCharCode is not a Latin character |
michael@0 | 1284 | // and if one of these modifiers is pressed (i.e. Ctrl, Alt, Meta) |
michael@0 | 1285 | if (domCharCode && |
michael@0 | 1286 | (QGuiApplication::keyboardModifiers() & |
michael@0 | 1287 | (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) { |
michael@0 | 1288 | |
michael@0 | 1289 | event.charCode = domCharCode; |
michael@0 | 1290 | event.keyCode = 0; |
michael@0 | 1291 | AlternativeCharCode altCharCode(0, 0); |
michael@0 | 1292 | // if character has a lower and upper representation |
michael@0 | 1293 | if ((unshiftedChar.isUpper() || unshiftedChar.isLower()) && |
michael@0 | 1294 | unshiftedChar.toLower() == shiftedChar.toLower()) { |
michael@0 | 1295 | if (shift_state ^ capslock_state) { |
michael@0 | 1296 | altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode); |
michael@0 | 1297 | altCharCode.mShiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode); |
michael@0 | 1298 | } else { |
michael@0 | 1299 | altCharCode.mUnshiftedCharCode = (uint32_t) QChar::toLower((uint)domCharCode); |
michael@0 | 1300 | altCharCode.mShiftedCharCode = (uint32_t) QChar::toUpper((uint)domCharCode); |
michael@0 | 1301 | } |
michael@0 | 1302 | } else { |
michael@0 | 1303 | altCharCode.mUnshiftedCharCode = (uint32_t) unshiftedChar.unicode(); |
michael@0 | 1304 | altCharCode.mShiftedCharCode = (uint32_t) shiftedChar.unicode(); |
michael@0 | 1305 | } |
michael@0 | 1306 | |
michael@0 | 1307 | // append alternative char code to event |
michael@0 | 1308 | if ((altCharCode.mUnshiftedCharCode && altCharCode.mUnshiftedCharCode != domCharCode) || |
michael@0 | 1309 | (altCharCode.mShiftedCharCode && altCharCode.mShiftedCharCode != domCharCode)) { |
michael@0 | 1310 | event.alternativeCharCodes.AppendElement(altCharCode); |
michael@0 | 1311 | } |
michael@0 | 1312 | |
michael@0 | 1313 | // check if the alternative char codes are latin-1 |
michael@0 | 1314 | if (altCharCode.mUnshiftedCharCode > 0xFF || altCharCode.mShiftedCharCode > 0xFF) { |
michael@0 | 1315 | altCharCode.mUnshiftedCharCode = altCharCode.mShiftedCharCode = 0; |
michael@0 | 1316 | |
michael@0 | 1317 | // find latin char for keycode |
michael@0 | 1318 | KeySym keysym = NoSymbol; |
michael@0 | 1319 | int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1320 | // find first shifted and unshifted Latin-Char in XKeyMap |
michael@0 | 1321 | for (int i = 0; i < xkeysyms_per_keycode; ++i) { |
michael@0 | 1322 | keysym = xkeymap[index + i]; |
michael@0 | 1323 | if (keysym && keysym <= 0xFF) { |
michael@0 | 1324 | if ((shift_state && (i % 2 == 1)) || |
michael@0 | 1325 | (!shift_state && (i % 2 == 0))) { |
michael@0 | 1326 | altCharCode.mUnshiftedCharCode = altCharCode.mUnshiftedCharCode ? |
michael@0 | 1327 | altCharCode.mUnshiftedCharCode : |
michael@0 | 1328 | keysym; |
michael@0 | 1329 | } else { |
michael@0 | 1330 | altCharCode.mShiftedCharCode = altCharCode.mShiftedCharCode ? |
michael@0 | 1331 | altCharCode.mShiftedCharCode : |
michael@0 | 1332 | keysym; |
michael@0 | 1333 | } |
michael@0 | 1334 | if (altCharCode.mUnshiftedCharCode && altCharCode.mShiftedCharCode) { |
michael@0 | 1335 | break; |
michael@0 | 1336 | } |
michael@0 | 1337 | } |
michael@0 | 1338 | } |
michael@0 | 1339 | |
michael@0 | 1340 | if (altCharCode.mUnshiftedCharCode || altCharCode.mShiftedCharCode) { |
michael@0 | 1341 | event.alternativeCharCodes.AppendElement(altCharCode); |
michael@0 | 1342 | } |
michael@0 | 1343 | } |
michael@0 | 1344 | } else { |
michael@0 | 1345 | event.charCode = domCharCode; |
michael@0 | 1346 | } |
michael@0 | 1347 | |
michael@0 | 1348 | if (xmodmap) { |
michael@0 | 1349 | XFreeModifiermap(xmodmap); |
michael@0 | 1350 | } |
michael@0 | 1351 | if (xkeymap) { |
michael@0 | 1352 | XFree(xkeymap); |
michael@0 | 1353 | } |
michael@0 | 1354 | |
michael@0 | 1355 | event.keyCode = domCharCode ? 0 : domKeyCode; |
michael@0 | 1356 | event.mKeyNameIndex = keyNameIndex; |
michael@0 | 1357 | // send the key press event |
michael@0 | 1358 | return DispatchEvent(&event); |
michael@0 | 1359 | #else |
michael@0 | 1360 | |
michael@0 | 1361 | //:TODO: fix shortcuts hebrew for non X11, |
michael@0 | 1362 | //see Bug 562195##51 |
michael@0 | 1363 | |
michael@0 | 1364 | // before we dispatch a key, check if it's the context menu key. |
michael@0 | 1365 | // If so, send a context menu key event instead. |
michael@0 | 1366 | if (isContextMenuKeyEvent(aEvent)) { |
michael@0 | 1367 | WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this, |
michael@0 | 1368 | WidgetMouseEvent::eReal, |
michael@0 | 1369 | WidgetMouseEvent::eContextMenuKey); |
michael@0 | 1370 | //keyEventToContextMenuEvent(&event, &contextMenuEvent); |
michael@0 | 1371 | return DispatchEvent(&contextMenuEvent); |
michael@0 | 1372 | } |
michael@0 | 1373 | |
michael@0 | 1374 | uint32_t domCharCode = 0; |
michael@0 | 1375 | uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key()); |
michael@0 | 1376 | |
michael@0 | 1377 | if (aEvent->text().length() && aEvent->text()[0].isPrint()) { |
michael@0 | 1378 | domCharCode = (int32_t) aEvent->text()[0].unicode(); |
michael@0 | 1379 | } |
michael@0 | 1380 | |
michael@0 | 1381 | KeyNameIndex keyNameIndex = |
michael@0 | 1382 | domCharCode ? KEY_NAME_INDEX_PrintableKey : |
michael@0 | 1383 | QtKeyCodeToDOMKeyNameIndex(aEvent->key()); |
michael@0 | 1384 | |
michael@0 | 1385 | // If the key isn't autorepeat, we need to send the initial down event |
michael@0 | 1386 | if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) { |
michael@0 | 1387 | // send the key down event |
michael@0 | 1388 | |
michael@0 | 1389 | SetKeyDownFlag(domKeyCode); |
michael@0 | 1390 | |
michael@0 | 1391 | WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this); |
michael@0 | 1392 | InitKeyEvent(downEvent, aEvent); |
michael@0 | 1393 | |
michael@0 | 1394 | downEvent.keyCode = domKeyCode; |
michael@0 | 1395 | downEvent.mKeyNameIndex = keyNameIndex; |
michael@0 | 1396 | |
michael@0 | 1397 | nsEventStatus status = DispatchEvent(&downEvent); |
michael@0 | 1398 | |
michael@0 | 1399 | // If prevent default on keydown, don't dispatch keypress event |
michael@0 | 1400 | if (status == nsEventStatus_eConsumeNoDefault) { |
michael@0 | 1401 | return nsEventStatus_eConsumeNoDefault; |
michael@0 | 1402 | } |
michael@0 | 1403 | } |
michael@0 | 1404 | |
michael@0 | 1405 | WidgetKeyboardEvent event(true, NS_KEY_PRESS, this); |
michael@0 | 1406 | InitKeyEvent(event, aEvent); |
michael@0 | 1407 | |
michael@0 | 1408 | event.charCode = domCharCode; |
michael@0 | 1409 | |
michael@0 | 1410 | event.keyCode = domCharCode ? 0 : domKeyCode; |
michael@0 | 1411 | event.mKeyNameIndex = keyNameIndex; |
michael@0 | 1412 | |
michael@0 | 1413 | // send the key press event |
michael@0 | 1414 | return DispatchEvent(&event); |
michael@0 | 1415 | #endif |
michael@0 | 1416 | } |
michael@0 | 1417 | |
michael@0 | 1418 | nsEventStatus |
michael@0 | 1419 | nsWindow::keyReleaseEvent(QKeyEvent* aEvent) |
michael@0 | 1420 | { |
michael@0 | 1421 | LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this)); |
michael@0 | 1422 | |
michael@0 | 1423 | // The user has done something. |
michael@0 | 1424 | UserActivity(); |
michael@0 | 1425 | |
michael@0 | 1426 | if (isContextMenuKeyEvent(aEvent)) { |
michael@0 | 1427 | // er, what do we do here? DoDefault or NoDefault? |
michael@0 | 1428 | return nsEventStatus_eConsumeDoDefault; |
michael@0 | 1429 | } |
michael@0 | 1430 | |
michael@0 | 1431 | uint32_t domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key()); |
michael@0 | 1432 | |
michael@0 | 1433 | #ifdef MOZ_X11 |
michael@0 | 1434 | if (!domKeyCode) { |
michael@0 | 1435 | // get keymap from the Xserver |
michael@0 | 1436 | Display *display = gfxQtPlatform::GetXDisplay(mWidget); |
michael@0 | 1437 | int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode; |
michael@0 | 1438 | XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode); |
michael@0 | 1439 | KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode, |
michael@0 | 1440 | &xkeysyms_per_keycode); |
michael@0 | 1441 | |
michael@0 | 1442 | if (aEvent->nativeScanCode() >= (quint32)x_min_keycode && |
michael@0 | 1443 | aEvent->nativeScanCode() <= (quint32)x_max_keycode) { |
michael@0 | 1444 | int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode; |
michael@0 | 1445 | for(int i = 0; (i < xkeysyms_per_keycode) && (domKeyCode == (quint32)NoSymbol); ++i) { |
michael@0 | 1446 | domKeyCode = QtKeyCodeToDOMKeyCode(xkeymap[index + i]); |
michael@0 | 1447 | } |
michael@0 | 1448 | } |
michael@0 | 1449 | |
michael@0 | 1450 | if (xkeymap) { |
michael@0 | 1451 | XFree(xkeymap); |
michael@0 | 1452 | } |
michael@0 | 1453 | } |
michael@0 | 1454 | #endif // MOZ_X11 |
michael@0 | 1455 | |
michael@0 | 1456 | // send the key event as a key up event |
michael@0 | 1457 | WidgetKeyboardEvent event(true, NS_KEY_UP, this); |
michael@0 | 1458 | InitKeyEvent(event, aEvent); |
michael@0 | 1459 | |
michael@0 | 1460 | if (aEvent->key() == Qt::Key_AltGr) { |
michael@0 | 1461 | sAltGrModifier = false; |
michael@0 | 1462 | } |
michael@0 | 1463 | |
michael@0 | 1464 | event.keyCode = domKeyCode; |
michael@0 | 1465 | event.mKeyNameIndex = |
michael@0 | 1466 | (aEvent->text().length() && aEvent->text()[0].isPrint()) ? |
michael@0 | 1467 | KEY_NAME_INDEX_PrintableKey : |
michael@0 | 1468 | QtKeyCodeToDOMKeyNameIndex(aEvent->key()); |
michael@0 | 1469 | |
michael@0 | 1470 | // unset the key down flag |
michael@0 | 1471 | ClearKeyDownFlag(event.keyCode); |
michael@0 | 1472 | |
michael@0 | 1473 | return DispatchEvent(&event); |
michael@0 | 1474 | } |
michael@0 | 1475 | |
michael@0 | 1476 | nsEventStatus |
michael@0 | 1477 | nsWindow::wheelEvent(QWheelEvent* aEvent) |
michael@0 | 1478 | { |
michael@0 | 1479 | // check to see if we should rollup |
michael@0 | 1480 | WidgetWheelEvent wheelEvent(true, NS_WHEEL_WHEEL, this); |
michael@0 | 1481 | wheelEvent.deltaMode = nsIDOMWheelEvent::DOM_DELTA_LINE; |
michael@0 | 1482 | |
michael@0 | 1483 | // negative values for aEvent->delta indicate downward scrolling; |
michael@0 | 1484 | // this is opposite Gecko usage. |
michael@0 | 1485 | // TODO: Store the unused delta values due to fraction round and add it |
michael@0 | 1486 | // to next event. The stored values should be reset by other |
michael@0 | 1487 | // direction scroll event. |
michael@0 | 1488 | int32_t delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3; |
michael@0 | 1489 | |
michael@0 | 1490 | switch (aEvent->orientation()) { |
michael@0 | 1491 | case Qt::Vertical: |
michael@0 | 1492 | wheelEvent.deltaY = wheelEvent.lineOrPageDeltaY = delta; |
michael@0 | 1493 | break; |
michael@0 | 1494 | case Qt::Horizontal: |
michael@0 | 1495 | wheelEvent.deltaX = wheelEvent.lineOrPageDeltaX = delta; |
michael@0 | 1496 | break; |
michael@0 | 1497 | default: |
michael@0 | 1498 | Q_ASSERT(0); |
michael@0 | 1499 | break; |
michael@0 | 1500 | } |
michael@0 | 1501 | |
michael@0 | 1502 | wheelEvent.refPoint.x = nscoord(aEvent->pos().x()); |
michael@0 | 1503 | wheelEvent.refPoint.y = nscoord(aEvent->pos().y()); |
michael@0 | 1504 | |
michael@0 | 1505 | wheelEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier, |
michael@0 | 1506 | aEvent->modifiers() & Qt::AltModifier, |
michael@0 | 1507 | aEvent->modifiers() & Qt::ShiftModifier, |
michael@0 | 1508 | aEvent->modifiers() & Qt::MetaModifier); |
michael@0 | 1509 | wheelEvent.time = 0; |
michael@0 | 1510 | |
michael@0 | 1511 | return DispatchEvent(&wheelEvent); |
michael@0 | 1512 | } |
michael@0 | 1513 | |
michael@0 | 1514 | nsEventStatus |
michael@0 | 1515 | nsWindow::showEvent(QShowEvent *) |
michael@0 | 1516 | { |
michael@0 | 1517 | LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this)); |
michael@0 | 1518 | mVisible = true; |
michael@0 | 1519 | return nsEventStatus_eConsumeDoDefault; |
michael@0 | 1520 | } |
michael@0 | 1521 | |
michael@0 | 1522 | nsEventStatus |
michael@0 | 1523 | nsWindow::hideEvent(QHideEvent *) |
michael@0 | 1524 | { |
michael@0 | 1525 | LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this)); |
michael@0 | 1526 | mVisible = false; |
michael@0 | 1527 | return nsEventStatus_eConsumeDoDefault; |
michael@0 | 1528 | } |
michael@0 | 1529 | |
michael@0 | 1530 | nsEventStatus nsWindow::touchEvent(QTouchEvent* aEvent) |
michael@0 | 1531 | { |
michael@0 | 1532 | return nsEventStatus_eIgnore; |
michael@0 | 1533 | } |
michael@0 | 1534 | |
michael@0 | 1535 | nsEventStatus |
michael@0 | 1536 | nsWindow::tabletEvent(QTabletEvent* aEvent) |
michael@0 | 1537 | { |
michael@0 | 1538 | LOGFOCUS(("nsWindow::%s [%p]\n", __FUNCTION__, (void *)this)); |
michael@0 | 1539 | return nsEventStatus_eIgnore; |
michael@0 | 1540 | } |
michael@0 | 1541 | |
michael@0 | 1542 | // Helpers |
michael@0 | 1543 | |
michael@0 | 1544 | void |
michael@0 | 1545 | nsWindow::InitButtonEvent(WidgetMouseEvent& aMoveEvent, |
michael@0 | 1546 | QMouseEvent* aEvent, |
michael@0 | 1547 | int aClickCount) |
michael@0 | 1548 | { |
michael@0 | 1549 | aMoveEvent.refPoint.x = nscoord(aEvent->pos().x()); |
michael@0 | 1550 | aMoveEvent.refPoint.y = nscoord(aEvent->pos().y()); |
michael@0 | 1551 | |
michael@0 | 1552 | aMoveEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier, |
michael@0 | 1553 | aEvent->modifiers() & Qt::AltModifier, |
michael@0 | 1554 | aEvent->modifiers() & Qt::ShiftModifier, |
michael@0 | 1555 | aEvent->modifiers() & Qt::MetaModifier); |
michael@0 | 1556 | aMoveEvent.clickCount = aClickCount; |
michael@0 | 1557 | } |
michael@0 | 1558 | |
michael@0 | 1559 | nsEventStatus |
michael@0 | 1560 | nsWindow::DispatchEvent(WidgetGUIEvent* aEvent) |
michael@0 | 1561 | { |
michael@0 | 1562 | nsEventStatus status; |
michael@0 | 1563 | DispatchEvent(aEvent, status); |
michael@0 | 1564 | return status; |
michael@0 | 1565 | } |
michael@0 | 1566 | |
michael@0 | 1567 | void |
michael@0 | 1568 | nsWindow::DispatchActivateEvent(void) |
michael@0 | 1569 | { |
michael@0 | 1570 | if (mWidgetListener) { |
michael@0 | 1571 | mWidgetListener->WindowActivated(); |
michael@0 | 1572 | } |
michael@0 | 1573 | } |
michael@0 | 1574 | |
michael@0 | 1575 | void |
michael@0 | 1576 | nsWindow::DispatchDeactivateEvent(void) |
michael@0 | 1577 | { |
michael@0 | 1578 | if (mWidgetListener) { |
michael@0 | 1579 | mWidgetListener->WindowDeactivated(); |
michael@0 | 1580 | } |
michael@0 | 1581 | } |
michael@0 | 1582 | |
michael@0 | 1583 | void |
michael@0 | 1584 | nsWindow::DispatchActivateEventOnTopLevelWindow(void) |
michael@0 | 1585 | { |
michael@0 | 1586 | nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget()); |
michael@0 | 1587 | if (topLevelWindow != nullptr) { |
michael@0 | 1588 | topLevelWindow->DispatchActivateEvent(); |
michael@0 | 1589 | } |
michael@0 | 1590 | } |
michael@0 | 1591 | |
michael@0 | 1592 | void |
michael@0 | 1593 | nsWindow::DispatchDeactivateEventOnTopLevelWindow(void) |
michael@0 | 1594 | { |
michael@0 | 1595 | nsWindow* topLevelWindow = static_cast<nsWindow*>(GetTopLevelWidget()); |
michael@0 | 1596 | if (topLevelWindow != nullptr) { |
michael@0 | 1597 | topLevelWindow->DispatchDeactivateEvent(); |
michael@0 | 1598 | } |
michael@0 | 1599 | } |
michael@0 | 1600 | |
michael@0 | 1601 | void |
michael@0 | 1602 | nsWindow::DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus) |
michael@0 | 1603 | { |
michael@0 | 1604 | aStatus = nsEventStatus_eIgnore; |
michael@0 | 1605 | if (mWidgetListener && |
michael@0 | 1606 | mWidgetListener->WindowResized(this, aRect.width, aRect.height)) { |
michael@0 | 1607 | aStatus = nsEventStatus_eConsumeNoDefault; |
michael@0 | 1608 | } |
michael@0 | 1609 | } |
michael@0 | 1610 | |
michael@0 | 1611 | ///////////////////////////////////// OLD GECKO ECENTS need to Sort /////////////////// |
michael@0 | 1612 | |
michael@0 | 1613 | /* static */ bool |
michael@0 | 1614 | isContextMenuKeyEvent(const QKeyEvent *qe) |
michael@0 | 1615 | { |
michael@0 | 1616 | uint32_t kc = QtKeyCodeToDOMKeyCode(qe->key()); |
michael@0 | 1617 | if (qe->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) { |
michael@0 | 1618 | return false; |
michael@0 | 1619 | } |
michael@0 | 1620 | |
michael@0 | 1621 | bool isShift = qe->modifiers() & Qt::ShiftModifier; |
michael@0 | 1622 | return (kc == NS_VK_F10 && isShift) || |
michael@0 | 1623 | (kc == NS_VK_CONTEXT_MENU && !isShift); |
michael@0 | 1624 | } |
michael@0 | 1625 | |
michael@0 | 1626 | /* static */void |
michael@0 | 1627 | InitKeyEvent(WidgetKeyboardEvent &aEvent, QKeyEvent *aQEvent) |
michael@0 | 1628 | { |
michael@0 | 1629 | aEvent.InitBasicModifiers(aQEvent->modifiers() & Qt::ControlModifier, |
michael@0 | 1630 | aQEvent->modifiers() & Qt::AltModifier, |
michael@0 | 1631 | aQEvent->modifiers() & Qt::ShiftModifier, |
michael@0 | 1632 | aQEvent->modifiers() & Qt::MetaModifier); |
michael@0 | 1633 | aEvent.mIsRepeat = |
michael@0 | 1634 | (aEvent.message == NS_KEY_DOWN || aEvent.message == NS_KEY_PRESS) && |
michael@0 | 1635 | aQEvent->isAutoRepeat(); |
michael@0 | 1636 | aEvent.time = 0; |
michael@0 | 1637 | |
michael@0 | 1638 | if (sAltGrModifier) { |
michael@0 | 1639 | aEvent.modifiers |= (MODIFIER_CONTROL | MODIFIER_ALT); |
michael@0 | 1640 | } |
michael@0 | 1641 | |
michael@0 | 1642 | // The transformations above and in qt for the keyval are not invertible |
michael@0 | 1643 | // so link to the QKeyEvent (which will vanish soon after return from the |
michael@0 | 1644 | // event callback) to give plugins access to hardware_keycode and state. |
michael@0 | 1645 | // (An XEvent would be nice but the QKeyEvent is good enough.) |
michael@0 | 1646 | aEvent.pluginEvent = (void *)aQEvent; |
michael@0 | 1647 | } |
michael@0 | 1648 | |
michael@0 | 1649 | NS_IMPL_ISUPPORTS_INHERITED(nsWindow, nsBaseWidget, nsISupportsWeakReference) |
michael@0 | 1650 | |
michael@0 | 1651 | |
michael@0 | 1652 | |
michael@0 | 1653 | void |
michael@0 | 1654 | nsWindow::ClearCachedResources() |
michael@0 | 1655 | { |
michael@0 | 1656 | if (mLayerManager && |
michael@0 | 1657 | mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_BASIC) { |
michael@0 | 1658 | mLayerManager->ClearCachedResources(); |
michael@0 | 1659 | } |
michael@0 | 1660 | for (nsIWidget* kid = mFirstChild; kid; ) { |
michael@0 | 1661 | nsIWidget* next = kid->GetNextSibling(); |
michael@0 | 1662 | static_cast<nsWindow*>(kid)->ClearCachedResources(); |
michael@0 | 1663 | kid = next; |
michael@0 | 1664 | } |
michael@0 | 1665 | } |
michael@0 | 1666 | |
michael@0 | 1667 | NS_IMETHODIMP |
michael@0 | 1668 | nsWindow::SetParent(nsIWidget *aNewParent) |
michael@0 | 1669 | { |
michael@0 | 1670 | NS_ENSURE_ARG_POINTER(aNewParent); |
michael@0 | 1671 | |
michael@0 | 1672 | nsCOMPtr<nsIWidget> kungFuDeathGrip(this); |
michael@0 | 1673 | nsIWidget* parent = GetParent(); |
michael@0 | 1674 | if (parent) { |
michael@0 | 1675 | parent->RemoveChild(this); |
michael@0 | 1676 | } |
michael@0 | 1677 | ReparentNativeWidget(aNewParent); |
michael@0 | 1678 | aNewParent->AddChild(this); |
michael@0 | 1679 | return NS_OK; |
michael@0 | 1680 | } |
michael@0 | 1681 | |
michael@0 | 1682 | NS_IMETHODIMP |
michael@0 | 1683 | nsWindow::SetModal(bool aModal) |
michael@0 | 1684 | { |
michael@0 | 1685 | LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget)); |
michael@0 | 1686 | if (mWidget) { |
michael@0 | 1687 | mWidget->setModality(aModal ? Qt::WindowModal : Qt::NonModal); |
michael@0 | 1688 | } |
michael@0 | 1689 | |
michael@0 | 1690 | return NS_OK; |
michael@0 | 1691 | } |
michael@0 | 1692 | |
michael@0 | 1693 | |
michael@0 | 1694 | NS_IMETHODIMP |
michael@0 | 1695 | nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, |
michael@0 | 1696 | nsIWidget *aWidget, |
michael@0 | 1697 | bool aActivate) |
michael@0 | 1698 | { |
michael@0 | 1699 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 1700 | } |
michael@0 | 1701 | |
michael@0 | 1702 | NS_IMETHODIMP |
michael@0 | 1703 | nsWindow::SetSizeMode(int32_t aMode) |
michael@0 | 1704 | { |
michael@0 | 1705 | nsresult rv; |
michael@0 | 1706 | |
michael@0 | 1707 | LOG(("nsWindow::SetSizeMode [%p] %d\n", (void *)this, aMode)); |
michael@0 | 1708 | if (aMode != nsSizeMode_Minimized) { |
michael@0 | 1709 | mWidget->requestActivate(); |
michael@0 | 1710 | } |
michael@0 | 1711 | |
michael@0 | 1712 | // Save the requested state. |
michael@0 | 1713 | rv = nsBaseWidget::SetSizeMode(aMode); |
michael@0 | 1714 | |
michael@0 | 1715 | // return if there's no shell or our current state is the same as |
michael@0 | 1716 | // the mode we were just set to. |
michael@0 | 1717 | if (!mWidget || mSizeState == mSizeMode) { |
michael@0 | 1718 | return rv; |
michael@0 | 1719 | } |
michael@0 | 1720 | |
michael@0 | 1721 | switch (aMode) { |
michael@0 | 1722 | case nsSizeMode_Maximized: |
michael@0 | 1723 | mWidget->showMaximized(); |
michael@0 | 1724 | break; |
michael@0 | 1725 | case nsSizeMode_Minimized: |
michael@0 | 1726 | mWidget->showMinimized(); |
michael@0 | 1727 | break; |
michael@0 | 1728 | case nsSizeMode_Fullscreen: |
michael@0 | 1729 | mWidget->showFullScreen(); |
michael@0 | 1730 | break; |
michael@0 | 1731 | |
michael@0 | 1732 | default: |
michael@0 | 1733 | // nsSizeMode_Normal, really. |
michael@0 | 1734 | mWidget->show(); |
michael@0 | 1735 | break; |
michael@0 | 1736 | } |
michael@0 | 1737 | |
michael@0 | 1738 | mSizeState = mSizeMode; |
michael@0 | 1739 | |
michael@0 | 1740 | return rv; |
michael@0 | 1741 | } |
michael@0 | 1742 | |
michael@0 | 1743 | // Helper function to recursively find the first parent item that |
michael@0 | 1744 | // is still visible (QGraphicsItem can be hidden even if they are |
michael@0 | 1745 | // set to visible if one of their ancestors is invisible) |
michael@0 | 1746 | /* static */ |
michael@0 | 1747 | void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem) |
michael@0 | 1748 | { |
michael@0 | 1749 | NS_ENSURE_TRUE_VOID(aItem); |
michael@0 | 1750 | |
michael@0 | 1751 | aVisibleItem = nullptr; |
michael@0 | 1752 | QWindow* parItem = nullptr; |
michael@0 | 1753 | while (!aVisibleItem) { |
michael@0 | 1754 | if (aItem->isVisible()) { |
michael@0 | 1755 | aVisibleItem = aItem; |
michael@0 | 1756 | } |
michael@0 | 1757 | else { |
michael@0 | 1758 | parItem = aItem->parent(); |
michael@0 | 1759 | if (parItem) { |
michael@0 | 1760 | aItem = parItem; |
michael@0 | 1761 | } |
michael@0 | 1762 | else { |
michael@0 | 1763 | aItem->setVisible(true); |
michael@0 | 1764 | aVisibleItem = aItem; |
michael@0 | 1765 | } |
michael@0 | 1766 | } |
michael@0 | 1767 | } |
michael@0 | 1768 | } |
michael@0 | 1769 | |
michael@0 | 1770 | NS_IMETHODIMP |
michael@0 | 1771 | nsWindow::GetScreenBounds(nsIntRect &aRect) |
michael@0 | 1772 | { |
michael@0 | 1773 | aRect = nsIntRect(nsIntPoint(0, 0), mBounds.Size()); |
michael@0 | 1774 | if (mIsTopLevel) { |
michael@0 | 1775 | QPoint pos = mWidget->position(); |
michael@0 | 1776 | aRect.MoveTo(pos.x(), pos.y()); |
michael@0 | 1777 | } |
michael@0 | 1778 | else { |
michael@0 | 1779 | aRect.MoveTo(WidgetToScreenOffset()); |
michael@0 | 1780 | } |
michael@0 | 1781 | LOG(("GetScreenBounds %d %d | %d %d | %d %d\n", |
michael@0 | 1782 | aRect.x, aRect.y, |
michael@0 | 1783 | mBounds.width, mBounds.height, |
michael@0 | 1784 | aRect.width, aRect.height)); |
michael@0 | 1785 | return NS_OK; |
michael@0 | 1786 | } |
michael@0 | 1787 | |
michael@0 | 1788 | NS_IMETHODIMP |
michael@0 | 1789 | nsWindow::SetIcon(const nsAString& aIconSpec) |
michael@0 | 1790 | { |
michael@0 | 1791 | if (!mWidget) |
michael@0 | 1792 | return NS_OK; |
michael@0 | 1793 | |
michael@0 | 1794 | nsCOMPtr<nsIFile> iconFile; |
michael@0 | 1795 | nsAutoCString path; |
michael@0 | 1796 | nsTArray<nsCString> iconList; |
michael@0 | 1797 | |
michael@0 | 1798 | // Look for icons with the following suffixes appended to the base name. |
michael@0 | 1799 | // The last two entries (for the old XPM format) will be ignored unless |
michael@0 | 1800 | // no icons are found using the other suffixes. XPM icons are depricated. |
michael@0 | 1801 | |
michael@0 | 1802 | const char extensions[6][7] = { ".png", "16.png", "32.png", "48.png", |
michael@0 | 1803 | ".xpm", "16.xpm" }; |
michael@0 | 1804 | |
michael@0 | 1805 | for (uint32_t i = 0; i < ArrayLength(extensions); i++) { |
michael@0 | 1806 | // Don't bother looking for XPM versions if we found a PNG. |
michael@0 | 1807 | if (i == ArrayLength(extensions) - 2 && iconList.Length()) |
michael@0 | 1808 | break; |
michael@0 | 1809 | |
michael@0 | 1810 | nsAutoString extension; |
michael@0 | 1811 | extension.AppendASCII(extensions[i]); |
michael@0 | 1812 | |
michael@0 | 1813 | ResolveIconName(aIconSpec, extension, getter_AddRefs(iconFile)); |
michael@0 | 1814 | if (iconFile) { |
michael@0 | 1815 | iconFile->GetNativePath(path); |
michael@0 | 1816 | iconList.AppendElement(path); |
michael@0 | 1817 | } |
michael@0 | 1818 | } |
michael@0 | 1819 | |
michael@0 | 1820 | // leave the default icon intact if no matching icons were found |
michael@0 | 1821 | if (iconList.Length() == 0) |
michael@0 | 1822 | return NS_OK; |
michael@0 | 1823 | |
michael@0 | 1824 | return SetWindowIconList(iconList); |
michael@0 | 1825 | } |
michael@0 | 1826 | |
michael@0 | 1827 | NS_IMETHODIMP |
michael@0 | 1828 | nsWindow::CaptureMouse(bool aCapture) |
michael@0 | 1829 | { |
michael@0 | 1830 | LOG(("CaptureMouse %p\n", (void *)this)); |
michael@0 | 1831 | |
michael@0 | 1832 | if (!mWidget) |
michael@0 | 1833 | return NS_OK; |
michael@0 | 1834 | |
michael@0 | 1835 | mWidget->setMouseGrabEnabled(aCapture); |
michael@0 | 1836 | |
michael@0 | 1837 | return NS_OK; |
michael@0 | 1838 | } |
michael@0 | 1839 | |
michael@0 | 1840 | bool |
michael@0 | 1841 | nsWindow::CheckForRollup(double aMouseX, double aMouseY, |
michael@0 | 1842 | bool aIsWheel) |
michael@0 | 1843 | { |
michael@0 | 1844 | nsIRollupListener* rollupListener = GetActiveRollupListener(); |
michael@0 | 1845 | nsCOMPtr<nsIWidget> rollupWidget; |
michael@0 | 1846 | if (rollupListener) { |
michael@0 | 1847 | rollupWidget = rollupListener->GetRollupWidget(); |
michael@0 | 1848 | } |
michael@0 | 1849 | if (!rollupWidget) { |
michael@0 | 1850 | nsBaseWidget::gRollupListener = nullptr; |
michael@0 | 1851 | return false; |
michael@0 | 1852 | } |
michael@0 | 1853 | |
michael@0 | 1854 | bool retVal = false; |
michael@0 | 1855 | MozQWidget *currentPopup = |
michael@0 | 1856 | (MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW); |
michael@0 | 1857 | if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) { |
michael@0 | 1858 | bool rollup = true; |
michael@0 | 1859 | if (aIsWheel) { |
michael@0 | 1860 | rollup = rollupListener->ShouldRollupOnMouseWheelEvent(); |
michael@0 | 1861 | retVal = true; |
michael@0 | 1862 | } |
michael@0 | 1863 | // if we're dealing with menus, we probably have submenus and |
michael@0 | 1864 | // we don't want to rollup if the clickis in a parent menu of |
michael@0 | 1865 | // the current submenu |
michael@0 | 1866 | uint32_t popupsToRollup = UINT32_MAX; |
michael@0 | 1867 | if (rollupListener) { |
michael@0 | 1868 | nsAutoTArray<nsIWidget*, 5> widgetChain; |
michael@0 | 1869 | uint32_t sameTypeCount = rollupListener->GetSubmenuWidgetChain(&widgetChain); |
michael@0 | 1870 | for (uint32_t i=0; i<widgetChain.Length(); ++i) { |
michael@0 | 1871 | nsIWidget* widget = widgetChain[i]; |
michael@0 | 1872 | MozQWidget* currWindow = |
michael@0 | 1873 | (MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW); |
michael@0 | 1874 | if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) { |
michael@0 | 1875 | if (i < sameTypeCount) { |
michael@0 | 1876 | rollup = false; |
michael@0 | 1877 | } |
michael@0 | 1878 | else { |
michael@0 | 1879 | popupsToRollup = sameTypeCount; |
michael@0 | 1880 | } |
michael@0 | 1881 | break; |
michael@0 | 1882 | } |
michael@0 | 1883 | } // foreach parent menu widget |
michael@0 | 1884 | } // if rollup listener knows about menus |
michael@0 | 1885 | |
michael@0 | 1886 | // if we've determined that we should still rollup, do it. |
michael@0 | 1887 | if (rollup) { |
michael@0 | 1888 | nsIntPoint pos(aMouseX, aMouseY); |
michael@0 | 1889 | retVal = rollupListener->Rollup(popupsToRollup, &pos, nullptr); |
michael@0 | 1890 | } |
michael@0 | 1891 | } |
michael@0 | 1892 | |
michael@0 | 1893 | return retVal; |
michael@0 | 1894 | } |
michael@0 | 1895 | |
michael@0 | 1896 | /* static */ |
michael@0 | 1897 | bool |
michael@0 | 1898 | is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY) |
michael@0 | 1899 | { |
michael@0 | 1900 | return aWindow->geometry().contains(aMouseX, aMouseY); |
michael@0 | 1901 | } |
michael@0 | 1902 | |
michael@0 | 1903 | NS_IMETHODIMP |
michael@0 | 1904 | nsWindow::GetAttention(int32_t aCycleCount) |
michael@0 | 1905 | { |
michael@0 | 1906 | LOG(("nsWindow::GetAttention [%p]\n", (void *)this)); |
michael@0 | 1907 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 1908 | } |
michael@0 | 1909 | |
michael@0 | 1910 | |
michael@0 | 1911 | |
michael@0 | 1912 | nsEventStatus |
michael@0 | 1913 | nsWindow::OnCloseEvent(QCloseEvent *aEvent) |
michael@0 | 1914 | { |
michael@0 | 1915 | if (!mWidgetListener) |
michael@0 | 1916 | return nsEventStatus_eIgnore; |
michael@0 | 1917 | mWidgetListener->RequestWindowClose(this); |
michael@0 | 1918 | return nsEventStatus_eConsumeNoDefault; |
michael@0 | 1919 | } |
michael@0 | 1920 | |
michael@0 | 1921 | |
michael@0 | 1922 | inline bool |
michael@0 | 1923 | is_latin_shortcut_key(quint32 aKeyval) |
michael@0 | 1924 | { |
michael@0 | 1925 | return ((Qt::Key_0 <= aKeyval && aKeyval <= Qt::Key_9) || |
michael@0 | 1926 | (Qt::Key_A <= aKeyval && aKeyval <= Qt::Key_Z)); |
michael@0 | 1927 | } |
michael@0 | 1928 | |
michael@0 | 1929 | nsEventStatus |
michael@0 | 1930 | nsWindow::DispatchCommandEvent(nsIAtom* aCommand) |
michael@0 | 1931 | { |
michael@0 | 1932 | WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this); |
michael@0 | 1933 | |
michael@0 | 1934 | nsEventStatus status; |
michael@0 | 1935 | DispatchEvent(&event, status); |
michael@0 | 1936 | |
michael@0 | 1937 | return status; |
michael@0 | 1938 | } |
michael@0 | 1939 | |
michael@0 | 1940 | nsEventStatus |
michael@0 | 1941 | nsWindow::DispatchContentCommandEvent(int32_t aMsg) |
michael@0 | 1942 | { |
michael@0 | 1943 | WidgetContentCommandEvent event(true, aMsg, this); |
michael@0 | 1944 | |
michael@0 | 1945 | nsEventStatus status; |
michael@0 | 1946 | DispatchEvent(&event, status); |
michael@0 | 1947 | |
michael@0 | 1948 | return status; |
michael@0 | 1949 | } |
michael@0 | 1950 | |
michael@0 | 1951 | |
michael@0 | 1952 | static void |
michael@0 | 1953 | GetBrandName(nsXPIDLString& brandName) |
michael@0 | 1954 | { |
michael@0 | 1955 | nsCOMPtr<nsIStringBundleService> bundleService = |
michael@0 | 1956 | mozilla::services::GetStringBundleService(); |
michael@0 | 1957 | |
michael@0 | 1958 | nsCOMPtr<nsIStringBundle> bundle; |
michael@0 | 1959 | if (bundleService) { |
michael@0 | 1960 | bundleService->CreateBundle( |
michael@0 | 1961 | "chrome://branding/locale/brand.properties", |
michael@0 | 1962 | getter_AddRefs(bundle)); |
michael@0 | 1963 | } |
michael@0 | 1964 | |
michael@0 | 1965 | if (bundle) { |
michael@0 | 1966 | bundle->GetStringFromName( |
michael@0 | 1967 | MOZ_UTF16("brandShortName"), |
michael@0 | 1968 | getter_Copies(brandName)); |
michael@0 | 1969 | } |
michael@0 | 1970 | |
michael@0 | 1971 | if (brandName.IsEmpty()) { |
michael@0 | 1972 | brandName.Assign(NS_LITERAL_STRING("Mozilla")); |
michael@0 | 1973 | } |
michael@0 | 1974 | } |
michael@0 | 1975 | |
michael@0 | 1976 | NS_IMETHODIMP |
michael@0 | 1977 | nsWindow::SetWindowClass(const nsAString &xulWinType) |
michael@0 | 1978 | { |
michael@0 | 1979 | if (!mWidget) { |
michael@0 | 1980 | return NS_ERROR_FAILURE; |
michael@0 | 1981 | } |
michael@0 | 1982 | |
michael@0 | 1983 | nsXPIDLString brandName; |
michael@0 | 1984 | GetBrandName(brandName); |
michael@0 | 1985 | |
michael@0 | 1986 | #ifdef MOZ_X11 |
michael@0 | 1987 | XClassHint *class_hint = XAllocClassHint(); |
michael@0 | 1988 | if (!class_hint) { |
michael@0 | 1989 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 1990 | } |
michael@0 | 1991 | const char *role = nullptr; |
michael@0 | 1992 | class_hint->res_name = ToNewCString(xulWinType); |
michael@0 | 1993 | if (!class_hint->res_name) { |
michael@0 | 1994 | XFree(class_hint); |
michael@0 | 1995 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 1996 | } |
michael@0 | 1997 | class_hint->res_class = ToNewCString(brandName); |
michael@0 | 1998 | if (!class_hint->res_class) { |
michael@0 | 1999 | nsMemory::Free(class_hint->res_name); |
michael@0 | 2000 | XFree(class_hint); |
michael@0 | 2001 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 2002 | } |
michael@0 | 2003 | |
michael@0 | 2004 | // Parse res_name into a name and role. Characters other than |
michael@0 | 2005 | // [A-Za-z0-9_-] are converted to '_'. Anything after the first |
michael@0 | 2006 | // colon is assigned to role; if there's no colon, assign the |
michael@0 | 2007 | // whole thing to both role and res_name. |
michael@0 | 2008 | for (char *c = class_hint->res_name; *c; c++) { |
michael@0 | 2009 | if (':' == *c) { |
michael@0 | 2010 | *c = 0; |
michael@0 | 2011 | role = c + 1; |
michael@0 | 2012 | } |
michael@0 | 2013 | else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c))) |
michael@0 | 2014 | *c = '_'; |
michael@0 | 2015 | } |
michael@0 | 2016 | class_hint->res_name[0] = toupper(class_hint->res_name[0]); |
michael@0 | 2017 | if (!role) role = class_hint->res_name; |
michael@0 | 2018 | |
michael@0 | 2019 | QWindow *widget = mWidget; |
michael@0 | 2020 | // If widget not show, handle might be null |
michael@0 | 2021 | if (widget && widget->winId()) { |
michael@0 | 2022 | XSetClassHint(gfxQtPlatform::GetXDisplay(widget), |
michael@0 | 2023 | widget->winId(), |
michael@0 | 2024 | class_hint); |
michael@0 | 2025 | } |
michael@0 | 2026 | |
michael@0 | 2027 | nsMemory::Free(class_hint->res_class); |
michael@0 | 2028 | nsMemory::Free(class_hint->res_name); |
michael@0 | 2029 | XFree(class_hint); |
michael@0 | 2030 | #endif |
michael@0 | 2031 | |
michael@0 | 2032 | return NS_OK; |
michael@0 | 2033 | } |
michael@0 | 2034 | |
michael@0 | 2035 | void |
michael@0 | 2036 | nsWindow::NativeResize(int32_t aWidth, int32_t aHeight, bool aRepaint) |
michael@0 | 2037 | { |
michael@0 | 2038 | LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this, |
michael@0 | 2039 | aWidth, aHeight)); |
michael@0 | 2040 | |
michael@0 | 2041 | mNeedsResize = false; |
michael@0 | 2042 | |
michael@0 | 2043 | mWidget->resize(aWidth, aHeight); |
michael@0 | 2044 | |
michael@0 | 2045 | if (aRepaint) { |
michael@0 | 2046 | mWidget->renderLater(); |
michael@0 | 2047 | } |
michael@0 | 2048 | } |
michael@0 | 2049 | |
michael@0 | 2050 | void |
michael@0 | 2051 | nsWindow::NativeResize(int32_t aX, int32_t aY, |
michael@0 | 2052 | int32_t aWidth, int32_t aHeight, |
michael@0 | 2053 | bool aRepaint) |
michael@0 | 2054 | { |
michael@0 | 2055 | LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this, |
michael@0 | 2056 | aX, aY, aWidth, aHeight)); |
michael@0 | 2057 | |
michael@0 | 2058 | mNeedsResize = false; |
michael@0 | 2059 | mNeedsMove = false; |
michael@0 | 2060 | |
michael@0 | 2061 | mWidget->setGeometry(aX, aY, aWidth, aHeight); |
michael@0 | 2062 | |
michael@0 | 2063 | if (aRepaint) { |
michael@0 | 2064 | mWidget->renderLater(); |
michael@0 | 2065 | } |
michael@0 | 2066 | } |
michael@0 | 2067 | |
michael@0 | 2068 | void |
michael@0 | 2069 | nsWindow::NativeShow(bool aAction) |
michael@0 | 2070 | { |
michael@0 | 2071 | if (aAction) { |
michael@0 | 2072 | // On e10s, we never want the child process or plugin process |
michael@0 | 2073 | // to go fullscreen because if we do the window because visible |
michael@0 | 2074 | // do to disabled Qt-Xembed |
michael@0 | 2075 | mWidget->show(); |
michael@0 | 2076 | // unset our flag now that our window has been shown |
michael@0 | 2077 | mNeedsShow = false; |
michael@0 | 2078 | } |
michael@0 | 2079 | else { |
michael@0 | 2080 | mWidget->hide(); |
michael@0 | 2081 | } |
michael@0 | 2082 | } |
michael@0 | 2083 | |
michael@0 | 2084 | NS_IMETHODIMP |
michael@0 | 2085 | nsWindow::SetHasTransparentBackground(bool aTransparent) |
michael@0 | 2086 | { |
michael@0 | 2087 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 2088 | } |
michael@0 | 2089 | |
michael@0 | 2090 | NS_IMETHODIMP |
michael@0 | 2091 | nsWindow::GetHasTransparentBackground(bool& aTransparent) |
michael@0 | 2092 | { |
michael@0 | 2093 | aTransparent = mIsTransparent; |
michael@0 | 2094 | return NS_OK; |
michael@0 | 2095 | } |
michael@0 | 2096 | |
michael@0 | 2097 | void * |
michael@0 | 2098 | nsWindow::SetupPluginPort(void) |
michael@0 | 2099 | { |
michael@0 | 2100 | NS_WARNING("Not implemented"); |
michael@0 | 2101 | return nullptr; |
michael@0 | 2102 | } |
michael@0 | 2103 | |
michael@0 | 2104 | nsresult |
michael@0 | 2105 | nsWindow::SetWindowIconList(const nsTArray<nsCString> &aIconList) |
michael@0 | 2106 | { |
michael@0 | 2107 | QIcon icon; |
michael@0 | 2108 | |
michael@0 | 2109 | for (uint32_t i = 0; i < aIconList.Length(); ++i) { |
michael@0 | 2110 | const char *path = aIconList[i].get(); |
michael@0 | 2111 | LOG(("window [%p] Loading icon from %s\n", (void *)this, path)); |
michael@0 | 2112 | icon.addFile(path); |
michael@0 | 2113 | } |
michael@0 | 2114 | |
michael@0 | 2115 | mWidget->setIcon(icon); |
michael@0 | 2116 | |
michael@0 | 2117 | return NS_OK; |
michael@0 | 2118 | } |
michael@0 | 2119 | |
michael@0 | 2120 | void |
michael@0 | 2121 | nsWindow::SetDefaultIcon(void) |
michael@0 | 2122 | { |
michael@0 | 2123 | SetIcon(NS_LITERAL_STRING("default")); |
michael@0 | 2124 | } |
michael@0 | 2125 | |
michael@0 | 2126 | void nsWindow::QWidgetDestroyed() |
michael@0 | 2127 | { |
michael@0 | 2128 | mWidget = nullptr; |
michael@0 | 2129 | } |
michael@0 | 2130 | |
michael@0 | 2131 | |
michael@0 | 2132 | NS_IMETHODIMP |
michael@0 | 2133 | nsWindow::HideWindowChrome(bool aShouldHide) |
michael@0 | 2134 | { |
michael@0 | 2135 | if (!mWidget) { |
michael@0 | 2136 | // Nothing to hide |
michael@0 | 2137 | return NS_ERROR_FAILURE; |
michael@0 | 2138 | } |
michael@0 | 2139 | |
michael@0 | 2140 | // Sawfish, metacity, and presumably other window managers get |
michael@0 | 2141 | // confused if we change the window decorations while the window |
michael@0 | 2142 | // is visible. |
michael@0 | 2143 | bool wasVisible = false; |
michael@0 | 2144 | if (mWidget->isVisible()) { |
michael@0 | 2145 | NativeShow(false); |
michael@0 | 2146 | wasVisible = true; |
michael@0 | 2147 | } |
michael@0 | 2148 | |
michael@0 | 2149 | if (wasVisible) { |
michael@0 | 2150 | NativeShow(true); |
michael@0 | 2151 | } |
michael@0 | 2152 | |
michael@0 | 2153 | return NS_OK; |
michael@0 | 2154 | } |
michael@0 | 2155 | |
michael@0 | 2156 | ////////////////////////////////////////////////////////////////////// |
michael@0 | 2157 | |
michael@0 | 2158 | NS_IMETHODIMP_(bool) |
michael@0 | 2159 | nsWindow::HasGLContext() |
michael@0 | 2160 | { |
michael@0 | 2161 | return false; |
michael@0 | 2162 | } |
michael@0 | 2163 | |
michael@0 | 2164 | |
michael@0 | 2165 | nsIWidget* |
michael@0 | 2166 | nsWindow::GetParent(void) |
michael@0 | 2167 | { |
michael@0 | 2168 | return mParent; |
michael@0 | 2169 | } |
michael@0 | 2170 | |
michael@0 | 2171 | float |
michael@0 | 2172 | nsWindow::GetDPI() |
michael@0 | 2173 | { |
michael@0 | 2174 | return qApp->primaryScreen()->logicalDotsPerInch(); |
michael@0 | 2175 | } |
michael@0 | 2176 | |
michael@0 | 2177 | void |
michael@0 | 2178 | nsWindow::OnDestroy(void) |
michael@0 | 2179 | { |
michael@0 | 2180 | if (mOnDestroyCalled) { |
michael@0 | 2181 | return; |
michael@0 | 2182 | } |
michael@0 | 2183 | |
michael@0 | 2184 | mOnDestroyCalled = true; |
michael@0 | 2185 | |
michael@0 | 2186 | // release references to children and device context |
michael@0 | 2187 | nsBaseWidget::OnDestroy(); |
michael@0 | 2188 | |
michael@0 | 2189 | // let go of our parent |
michael@0 | 2190 | mParent = nullptr; |
michael@0 | 2191 | |
michael@0 | 2192 | nsCOMPtr<nsIWidget> kungFuDeathGrip = this; |
michael@0 | 2193 | NotifyWindowDestroyed(); |
michael@0 | 2194 | } |
michael@0 | 2195 | |
michael@0 | 2196 | bool |
michael@0 | 2197 | nsWindow::AreBoundsSane(void) |
michael@0 | 2198 | { |
michael@0 | 2199 | if (mBounds.width > 0 && mBounds.height > 0) { |
michael@0 | 2200 | return true; |
michael@0 | 2201 | } |
michael@0 | 2202 | |
michael@0 | 2203 | return false; |
michael@0 | 2204 | } |
michael@0 | 2205 | |
michael@0 | 2206 | void |
michael@0 | 2207 | nsWindow::SetSoftwareKeyboardState(bool aOpen, |
michael@0 | 2208 | const InputContextAction& aAction) |
michael@0 | 2209 | { |
michael@0 | 2210 | if (aOpen) { |
michael@0 | 2211 | NS_ENSURE_TRUE_VOID(mInputContext.mIMEState.mEnabled != |
michael@0 | 2212 | IMEState::DISABLED); |
michael@0 | 2213 | |
michael@0 | 2214 | // Ensure that opening the virtual keyboard is allowed for this specific |
michael@0 | 2215 | // InputContext depending on the content.ime.strict.policy pref |
michael@0 | 2216 | if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN && |
michael@0 | 2217 | Preferences::GetBool("content.ime.strict_policy", false) && |
michael@0 | 2218 | !aAction.ContentGotFocusByTrustedCause() && |
michael@0 | 2219 | !aAction.UserMightRequestOpenVKB()) { |
michael@0 | 2220 | return; |
michael@0 | 2221 | } |
michael@0 | 2222 | } |
michael@0 | 2223 | |
michael@0 | 2224 | if (aOpen) { |
michael@0 | 2225 | qApp->inputMethod()->show(); |
michael@0 | 2226 | } else { |
michael@0 | 2227 | qApp->inputMethod()->hide(); |
michael@0 | 2228 | } |
michael@0 | 2229 | |
michael@0 | 2230 | return; |
michael@0 | 2231 | } |
michael@0 | 2232 | |
michael@0 | 2233 | |
michael@0 | 2234 | void |
michael@0 | 2235 | nsWindow::ProcessMotionEvent() |
michael@0 | 2236 | { |
michael@0 | 2237 | if (mMoveEvent.needDispatch) { |
michael@0 | 2238 | WidgetMouseEvent event(true, NS_MOUSE_MOVE, this, |
michael@0 | 2239 | WidgetMouseEvent::eReal); |
michael@0 | 2240 | |
michael@0 | 2241 | event.refPoint.x = nscoord(mMoveEvent.pos.x()); |
michael@0 | 2242 | event.refPoint.y = nscoord(mMoveEvent.pos.y()); |
michael@0 | 2243 | |
michael@0 | 2244 | event.InitBasicModifiers(mMoveEvent.modifiers & Qt::ControlModifier, |
michael@0 | 2245 | mMoveEvent.modifiers & Qt::AltModifier, |
michael@0 | 2246 | mMoveEvent.modifiers & Qt::ShiftModifier, |
michael@0 | 2247 | mMoveEvent.modifiers & Qt::MetaModifier); |
michael@0 | 2248 | event.clickCount = 0; |
michael@0 | 2249 | |
michael@0 | 2250 | DispatchEvent(&event); |
michael@0 | 2251 | mMoveEvent.needDispatch = false; |
michael@0 | 2252 | } |
michael@0 | 2253 | |
michael@0 | 2254 | mTimerStarted = false; |
michael@0 | 2255 | } |
michael@0 | 2256 |