diff options
author | mread <qt-info@nokia.com> | 2011-11-18 16:21:07 (GMT) |
---|---|---|
committer | mread <qt-info@nokia.com> | 2011-11-21 09:18:00 (GMT) |
commit | bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f (patch) | |
tree | 76f1e7ef0a0a164d2d1d0dc289a0982ea0547b66 /src/gui | |
parent | 52a93f068d2869fbe4e4deae2ed704d683e12834 (diff) | |
download | Qt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.zip Qt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.tar.gz Qt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.tar.bz2 |
Surviving out of memory in Qt Quick app
The QtQuickPlayground app contains a version of samegame which allow
the user to edit the code. By setting the ball size to 8, the app can
run out of memory. This leaves it in a pretty bad state. But apps
on Symbian shouldn't crash due to OOM and should allow some operation.
This change fixes the immediate OOM crashes in declarative, gui and
corelib. It shows warning dialogs which explain what has gone wrong and
leaves the app in a state that can be exited cleanly
from the Symbian task list.
Task-number: QT-5319
Reviewed-by: Shane Kearns
Reviewed-by: Gareth Stockwell
Reviewed-by: Martin Jones
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_p.h | 2 | ||||
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 193 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_s60.cpp | 96 | ||||
-rw-r--r-- | src/gui/painting/qgraphicssystemex_symbian.cpp | 2 |
4 files changed, 164 insertions, 129 deletions
diff --git a/src/gui/inputmethod/qcoefepinputcontext_p.h b/src/gui/inputmethod/qcoefepinputcontext_p.h index 90d47f9..b17d9c7 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_p.h +++ b/src/gui/inputmethod/qcoefepinputcontext_p.h @@ -162,6 +162,8 @@ private: void enableSymbianCcpuSupport(); void changeCBA(bool showCopyAndOrPaste); void copyOrCutTextToClipboard(const char *operation); + void getScreenCoordinatesForFepX(TPoint& aLeftSideOfBaseLine, TInt& aHeight, TInt& aAscent, + TInt aDocumentPosition) const; //From MEikCcpuEditor interface public: diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index ed7411f..44e0df0 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -1465,40 +1465,49 @@ void QCoeFepInputContext::CancelFepInlineEdit() m_pendingTransactionCancel = true; - QList<QInputMethodEvent::Attribute> attributes; - QInputMethodEvent event(QLatin1String(""), attributes); - event.setCommitString(QLatin1String(""), 0, 0); - m_preeditString.clear(); - m_inlinePosition = 0; - sendEvent(event); - - // Sync with native side editor state. Native side can then do various operations - // based on editor state, such as removing 'exact word bubble'. - if (!m_pendingInputCapabilitiesChanged) - ReportAknEdStateEvent(MAknEdStateObserver::EAknSyncEdwinState); + QT_TRY { + QList<QInputMethodEvent::Attribute> attributes; + QInputMethodEvent event(QLatin1String(""), attributes); + event.setCommitString(QLatin1String(""), 0, 0); + m_preeditString.clear(); + m_inlinePosition = 0; + sendEvent(event); + + // Sync with native side editor state. Native side can then do various operations + // based on editor state, such as removing 'exact word bubble'. + if (!m_pendingInputCapabilitiesChanged) + ReportAknEdStateEvent(MAknEdStateObserver::EAknSyncEdwinState); + } QT_CATCH(const std::exception&) { + m_preeditString.clear(); + m_inlinePosition = 0; + } m_pendingTransactionCancel = false; } TInt QCoeFepInputContext::DocumentLengthForFep() const { - QWidget *w = focusWidget(); - if (!w) - return 0; + QT_TRY { + QWidget *w = focusWidget(); + if (!w) + return 0; - QVariant variant = w->inputMethodQuery(Qt::ImSurroundingText); + QVariant variant = w->inputMethodQuery(Qt::ImSurroundingText); - int size = variant.value<QString>().size() + m_preeditString.size(); + int size = variant.value<QString>().size() + m_preeditString.size(); - // To fix an issue with backspaces not being generated if document size is zero, - // fake document length to be at least one always, except when dealing with - // hidden text widgets, where this faking would generate extra asterisk. Since the - // primary use of hidden text widgets is password fields, they are unlikely to - // support multiple lines anyway. - if (size == 0 && !(m_textCapabilities & TCoeInputCapabilities::ESecretText)) - size = 1; + // To fix an issue with backspaces not being generated if document size is zero, + // fake document length to be at least one always, except when dealing with + // hidden text widgets, where this faking would generate extra asterisk. Since the + // primary use of hidden text widgets is password fields, they are unlikely to + // support multiple lines anyway. + if (size == 0 && !(m_textCapabilities & TCoeInputCapabilities::ESecretText)) + size = 1; - return size; + return size; + } QT_CATCH(const std::exception&) { + return 0; + } } TInt QCoeFepInputContext::DocumentMaximumLengthForFep() const @@ -1540,42 +1549,46 @@ void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCur void QCoeFepInputContext::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const { - QWidget *w = focusWidget(); - if (!w) { - aCursorSelection.SetSelection(0,0); - return; - } + QT_TRY { + QWidget *w = focusWidget(); + if (!w) { + aCursorSelection.SetSelection(0,0); + return; + } - int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size(); - int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size(); + int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size(); + int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size(); - // If the position is stored, use that value, so that word replacement from proposed word - // lists are added to the correct position. - if (m_cachedCursorAndAnchorPosition != -1) { - cursor = m_cachedCursorAndAnchorPosition; - anchor = m_cachedCursorAndAnchorPosition; - } - QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>(); - int combinedSize = text.size() + m_preeditString.size(); - if (combinedSize < anchor || combinedSize < cursor) { - // ### TODO! FIXME! QTBUG-5050 - // This is a hack to prevent crashing in 4.6 with QLineEdits that use input masks. - // The root problem is that cursor position is relative to displayed text instead of the - // actual text we get. - // - // To properly fix this we would need to know the displayText of QLineEdits instead - // of just the text, which on itself should be a trivial change. The difficulties start - // when we need to commit the changes back to the QLineEdit, which would have to be somehow - // able to handle displayText, too. - // - // Until properly fixed, the cursor and anchor positions will not reflect correct positions - // for masked QLineEdits, unless all the masked positions are filled in order so that - // cursor position relative to the displayed text matches position relative to actual text. - aCursorSelection.iAnchorPos = combinedSize; - aCursorSelection.iCursorPos = combinedSize; - } else { - aCursorSelection.iAnchorPos = anchor; - aCursorSelection.iCursorPos = cursor; + // If the position is stored, use that value, so that word replacement from proposed word + // lists are added to the correct position. + if (m_cachedCursorAndAnchorPosition != -1) { + cursor = m_cachedCursorAndAnchorPosition; + anchor = m_cachedCursorAndAnchorPosition; + } + QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>(); + int combinedSize = text.size() + m_preeditString.size(); + if (combinedSize < anchor || combinedSize < cursor) { + // ### TODO! FIXME! QTBUG-5050 + // This is a hack to prevent crashing in 4.6 with QLineEdits that use input masks. + // The root problem is that cursor position is relative to displayed text instead of the + // actual text we get. + // + // To properly fix this we would need to know the displayText of QLineEdits instead + // of just the text, which on itself should be a trivial change. The difficulties start + // when we need to commit the changes back to the QLineEdit, which would have to be somehow + // able to handle displayText, too. + // + // Until properly fixed, the cursor and anchor positions will not reflect correct positions + // for masked QLineEdits, unless all the masked positions are filled in order so that + // cursor position relative to the displayed text matches position relative to actual text. + aCursorSelection.iAnchorPos = combinedSize; + aCursorSelection.iCursorPos = combinedSize; + } else { + aCursorSelection.iAnchorPos = anchor; + aCursorSelection.iCursorPos = cursor; + } + } QT_CATCH(const std::exception&) { + aCursorSelection.SetSelection(0,0); } } @@ -1618,6 +1631,12 @@ void QCoeFepInputContext::GetFormatForFep(TCharFormat& aFormat, TInt /* aDocumen } void QCoeFepInputContext::GetScreenCoordinatesForFepL(TPoint& aLeftSideOfBaseLine, TInt& aHeight, + TInt& aAscent, TInt aDocumentPosition) const +{ + QT_TRYCATCH_LEAVING(getScreenCoordinatesForFepX(aLeftSideOfBaseLine, aHeight, aAscent, aDocumentPosition)); +} + +void QCoeFepInputContext::getScreenCoordinatesForFepX(TPoint& aLeftSideOfBaseLine, TInt& aHeight, TInt& aAscent, TInt /* aDocumentPosition */) const { QWidget *w = focusWidget(); @@ -1774,36 +1793,40 @@ TBool QCoeFepInputContext::CcpuIsFocused() const TBool QCoeFepInputContext::CcpuCanCut() const { - bool retval = false; - if (m_inDestruction) - return retval; - QWidget *w = focusWidget(); - QObject *focusObject = 0; - if (!w) { - w = m_lastFocusedEditor; - focusObject = m_lastFocusedObject; - } else { - w = getQWidgetFromQGraphicsView(w, &focusObject); - } - if (w) { - QRect microFocus = w->inputMethodQuery(Qt::ImMicroFocus).toRect(); - if (microFocus.isNull()) { - // For some reason, the editor does not have microfocus. Most probably, - // it is due to using native fullscreen editing mode with QML apps. - // Try accessing "selectedText" directly. - QObject *invokeTarget = w; - if (focusObject) - invokeTarget = focusObject; - - QString selectedText = invokeTarget->property("selectedText").toString(); - retval = !selectedText.isNull(); + QT_TRY { + bool retval = false; + if (m_inDestruction) + return retval; + QWidget *w = focusWidget(); + QObject *focusObject = 0; + if (!w) { + w = m_lastFocusedEditor; + focusObject = m_lastFocusedObject; } else { - int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); - int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt(); - retval = cursor != anchor; + w = getQWidgetFromQGraphicsView(w, &focusObject); } + if (w) { + QRect microFocus = w->inputMethodQuery(Qt::ImMicroFocus).toRect(); + if (microFocus.isNull()) { + // For some reason, the editor does not have microfocus. Most probably, + // it is due to using native fullscreen editing mode with QML apps. + // Try accessing "selectedText" directly. + QObject *invokeTarget = w; + if (focusObject) + invokeTarget = focusObject; + + QString selectedText = invokeTarget->property("selectedText").toString(); + retval = !selectedText.isNull(); + } else { + int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); + int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt(); + retval = cursor != anchor; + } + } + return retval; + } QT_CATCH(const std::exception&) { + return EFalse; } - return retval; } void QCoeFepInputContext::CcpuCutL() diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index fe239f5..bb84491 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1534,53 +1534,57 @@ bool QSymbianControl::hasFocusedAndVisibleChild(QWidget *parentWidget) void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) { - if (m_ignoreFocusChanged || (qwidget->windowType() & Qt::WindowType_Mask) == Qt::Desktop) - return; + QT_TRY { + if (m_ignoreFocusChanged || (qwidget->windowType() & Qt::WindowType_Mask) == Qt::Desktop) + return; #ifdef Q_WS_S60 - if (S60->splitViewLastWidget) - return; + if (S60->splitViewLastWidget) + return; #endif - // Popups never get focused, but still receive the FocusChanged when they are hidden. - if (QApplicationPrivate::popupWidgets != 0 - || (qwidget->windowType() & Qt::Popup) == Qt::Popup) - return; - - if (IsFocused() && IsVisible()) { - if (m_symbianPopupIsOpen) { - QWidget *fw = QApplication::focusWidget(); - if (fw) { - QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason); - QCoreApplication::sendEvent(fw, &event); - } - m_symbianPopupIsOpen = false; - } + // Popups never get focused, but still receive the FocusChanged when they are hidden. + if (QApplicationPrivate::popupWidgets != 0 + || (qwidget->windowType() & Qt::Popup) == Qt::Popup) + return; - QApplication::setActiveWindow(qwidget->window()); - qwidget->d_func()->setWindowIcon_sys(true); - qwidget->d_func()->setWindowTitle_sys(qwidget->windowTitle()); -#ifdef Q_WS_S60 - if (qwidget->isWindow()) - S60->setRecursiveDecorationsVisibility(qwidget, qwidget->windowState()); -#endif - } else { - QWidget *parentWindow = qwidget->window(); - if (QApplication::activeWindow() == parentWindow && !hasFocusedAndVisibleChild(parentWindow)) { - if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog() || S60->menuBeingConstructed) { + if (IsFocused() && IsVisible()) { + if (m_symbianPopupIsOpen) { QWidget *fw = QApplication::focusWidget(); if (fw) { - QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason); + QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason); QCoreApplication::sendEvent(fw, &event); } - m_symbianPopupIsOpen = true; - return; + m_symbianPopupIsOpen = false; } - QApplication::setActiveWindow(0); + QApplication::setActiveWindow(qwidget->window()); + qwidget->d_func()->setWindowIcon_sys(true); + qwidget->d_func()->setWindowTitle_sys(qwidget->windowTitle()); +#ifdef Q_WS_S60 + if (qwidget->isWindow()) + S60->setRecursiveDecorationsVisibility(qwidget, qwidget->windowState()); +#endif + } else { + QWidget *parentWindow = qwidget->window(); + if (QApplication::activeWindow() == parentWindow && !hasFocusedAndVisibleChild(parentWindow)) { + if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog() || S60->menuBeingConstructed) { + QWidget *fw = QApplication::focusWidget(); + if (fw) { + QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason); + QCoreApplication::sendEvent(fw, &event); + } + m_symbianPopupIsOpen = true; + return; + } + + QApplication::setActiveWindow(0); + } } + // else { We don't touch the active window unless we were explicitly activated or deactivated } + } QT_CATCH(const std::exception&) { + // ignore errors } - // else { We don't touch the active window unless we were explicitly activated or deactivated } } void QSymbianControl::handleClientAreaChange() @@ -2377,19 +2381,25 @@ int QApplication::symbianProcessEvent(const QSymbianEvent *event) QScopedLoopLevelCounter counter(d->threadData); - if (d->eventDispatcher->filterEvent(const_cast<QSymbianEvent *>(event))) - return 1; + QT_TRY { + if (d->eventDispatcher->filterEvent(const_cast<QSymbianEvent *>(event))) + return 1; + + QWidget *w = qApp ? qApp->focusWidget() : 0; + if (w) { + QInputContext *ic = w->inputContext(); + if (ic && ic->symbianFilterEvent(w, event)) + return 1; + } - QWidget *w = qApp ? qApp->focusWidget() : 0; - if (w) { - QInputContext *ic = w->inputContext(); - if (ic && ic->symbianFilterEvent(w, event)) + if (symbianEventFilter(event)) return 1; + } QT_CATCH(const std::exception& ex) { + // don't allow an exception to stop exit command handling + if (event->type() != QSymbianEvent::CommandEvent || event->command() != EEikCmdExit) + QT_RETHROW; } - if (symbianEventFilter(event)) - return 1; - switch (event->type()) { case QSymbianEvent::WindowServerEvent: return d->symbianProcessWsEvent(event); diff --git a/src/gui/painting/qgraphicssystemex_symbian.cpp b/src/gui/painting/qgraphicssystemex_symbian.cpp index 5a182ff..5bfd5a8 100644 --- a/src/gui/painting/qgraphicssystemex_symbian.cpp +++ b/src/gui/painting/qgraphicssystemex_symbian.cpp @@ -74,7 +74,7 @@ bool QSymbianGraphicsSystemEx::hasBCM2727() #if 1 // Hacky but fast ~0ms. const char* vendor = eglQueryString(display, EGL_VENDOR); - if (strstr(vendor, "Broadcom")) { + if (vendor && strstr(vendor, "Broadcom")) { const TUid KIvePropertyCat = {0x2726beef}; enum TIvePropertyChipType { EVCBCM2727B1 = 0x00000000, |