diff options
Diffstat (limited to 'src')
15 files changed, 154 insertions, 92 deletions
diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h index b57d7e50ccd..34e6bd84f3f 100644 --- a/src/corelib/kernel/qobject_impl.h +++ b/src/corelib/kernel/qobject_impl.h @@ -1,8 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#ifndef Q_QDOC - #ifndef QOBJECT_H #error Do not include qobject_impl.h directly #endif @@ -41,5 +39,3 @@ namespace QtPrivate { QT_END_NAMESPACE - -#endif diff --git a/src/corelib/platform/wasm/qwasmsuspendresumecontrol.cpp b/src/corelib/platform/wasm/qwasmsuspendresumecontrol.cpp index a081edcf542..5fe92926240 100644 --- a/src/corelib/platform/wasm/qwasmsuspendresumecontrol.cpp +++ b/src/corelib/platform/wasm/qwasmsuspendresumecontrol.cpp @@ -77,32 +77,20 @@ void qtRegisterEventHandlerJs(int index) { }[name]; } - function deepShallowClone(parent, obj, depth) { + function deepShallowClone(obj) { if (obj === null) return obj; - if (typeof obj === 'function') { - if (obj.name !== "") - return createNamedFunction(obj.name, parent, obj); - } - - if (depth >= 1) - return obj; - - if (typeof obj !== 'object') + if (!(obj instanceof Event)) return obj; - if (Array.isArray(obj)) { - const arrCopy = []; - for (let i = 0; i < obj.length; i++) - arrCopy[i] = deepShallowClone(obj, obj[i], depth + 1); - - return arrCopy; - } - const objCopy = {}; - for (const key in obj) - objCopy[key] = deepShallowClone(obj, obj[key], depth + 1); + for (const key in obj) { + if (typeof obj[key] === 'function') + objCopy[key] = createNamedFunction(obj[key].name, obj, obj[key]); + else + objCopy[key] = obj[key]; + } return objCopy; } @@ -112,7 +100,7 @@ void qtRegisterEventHandlerJs(int index) { let handler = (arg) => { // Copy the top level object, alias the rest. // functions are copied by creating new forwarding functions. - arg = deepShallowClone(arg, arg, 0); + arg = deepShallowClone(arg); // Add event to event queue control.pendingEvents.push({ diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index a3f9f069b69..4c5414f177e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6474,8 +6474,9 @@ QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextO and height (on both 1x and 2x displays), and produces high-resolution output on 2x displays. - The \a position offset is always in the painter coordinate system, - indepentent of display devicePixelRatio. + The \a position offset is provided in the device independent pixels + relative to the top-left corner of the \a rectangle. The \a position + can be used to align the repeating pattern inside the \a rectangle. \sa drawPixmap() */ @@ -6579,8 +6580,12 @@ void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPo (\a{x}, \a{y}) specifies the top-left point in the paint device that is to be drawn onto; with the given \a width and \a - height. (\a{sx}, \a{sy}) specifies the top-left point in the \a - pixmap that is to be drawn; this defaults to (0, 0). + height. + + (\a{sx}, \a{sy}) specifies the origin inside the specified rectangle + where the pixmap will be drawn. The origin position is specified in + the device independent pixels relative to (\a{x}, \a{y}). This defaults + to (0, 0). */ #ifndef QT_NO_PICTURE diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp index a0546fdc215..6dfb4284149 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.cpp +++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp @@ -24,13 +24,13 @@ using namespace qstdweb; void QWasmInputContext::inputCallback(emscripten::val event) { - qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << "isComposing : " << event["isComposing"].as<bool>(); - emscripten::val inputType = event["inputType"]; if (inputType.isNull() || inputType.isUndefined()) return; const auto inputTypeString = inputType.as<std::string>(); + // also may be dataTransfer + // containing rich text emscripten::val inputData = event["data"]; QString inputStr = (!inputData.isNull() && !inputData.isUndefined()) ? QString::fromEcmaString(inputData) : QString(); @@ -44,10 +44,10 @@ void QWasmInputContext::inputCallback(emscripten::val event) QInputMethodQueryEvent queryEvent(Qt::ImQueryAll); QCoreApplication::sendEvent(m_focusObject, &queryEvent); int cursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt(); - int deleteLength = rangesPair.second - rangesPair.first; int deleteFrom = -1; - if (cursorPosition > rangesPair.first) { + + if (cursorPosition >= rangesPair.first) { deleteFrom = -(cursorPosition - rangesPair.first); } QInputMethodEvent e; @@ -65,21 +65,55 @@ void QWasmInputContext::inputCallback(emscripten::val event) event.call<void>("stopImmediatePropagation"); return; } else if (!inputTypeString.compare("insertCompositionText")) { - qCDebug(qLcQpaWasmInputContext) << "inputString : " << inputStr; - insertPreedit(); + qCDebug(qLcQpaWasmInputContext) << "insertCompositionText : " << inputStr; + event.call<void>("stopImmediatePropagation"); + + QInputMethodQueryEvent queryEvent(Qt::ImQueryAll); + QCoreApplication::sendEvent(m_focusObject, &queryEvent); + + int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt() ; + int replaceIndex = (qCursorPosition - rangesPair.first); + int replaceLength = rangesPair.second - rangesPair.first; + + setPreeditString(inputStr, replaceIndex); + insertPreedit(replaceLength); + + rangesPair.first = 0; + rangesPair.second = 0; event.call<void>("stopImmediatePropagation"); return; } else if (!inputTypeString.compare("insertReplacementText")) { - qCDebug(qLcQpaWasmInputContext) << "inputString : " << inputStr; - //auto ranges = event.call<emscripten::val>("getTargetRanges"); - //qCDebug(qLcQpaWasmInputContext) << ranges["length"].as<int>(); - // WA For Korean IME - // insertReplacementText should have targetRanges but - // Safari cannot have it and just it seems to be supposed - // to replace previous input. - insertText(inputStr, true); + // the previous input string up to the space, needs replaced with this + // used on iOS when continuing composition after focus change + // there's no range given + + qCDebug(qLcQpaWasmInputContext) << "insertReplacementText >>>>" << "inputString : " << inputStr; + emscripten::val ranges = event.call<emscripten::val>("getTargetRanges"); + + m_preeditString.clear(); + std::string elementString = m_inputElement["value"].as<std::string>(); + QInputMethodQueryEvent queryEvent(Qt::ImQueryAll); + QCoreApplication::sendEvent(m_focusObject, &queryEvent); + QString textFieldString = queryEvent.value(Qt::ImTextBeforeCursor).toString(); + int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt(); + + if (rangesPair.first != 0 || rangesPair.second != 0) { + + int replaceIndex = (qCursorPosition - rangesPair.first); + int replaceLength = rangesPair.second - rangesPair.first; + replaceText(inputStr, -replaceIndex, replaceLength); + rangesPair.first = 0; + rangesPair.second = 0; + + } else { + int spaceIndex = textFieldString.lastIndexOf(' ') + 1; + int replaceIndex = (qCursorPosition - spaceIndex); + + replaceText(inputStr, -replaceIndex, replaceIndex); + } event.call<void>("stopImmediatePropagation"); + return; } else if (!inputTypeString.compare("deleteCompositionText")) { setPreeditString("", 0); @@ -92,7 +126,25 @@ void QWasmInputContext::inputCallback(emscripten::val event) event.call<void>("stopImmediatePropagation"); return; } else if (!inputTypeString.compare("insertText")) { - insertText(inputStr); + if ((rangesPair.first != 0 || rangesPair.second != 0) + && rangesPair.first != rangesPair.second) { + + QInputMethodQueryEvent queryEvent(Qt::ImQueryAll); + QCoreApplication::sendEvent(m_focusObject, &queryEvent); + + int qCursorPosition = queryEvent.value(Qt::ImCursorPosition).toInt(); + int replaceIndex = (qCursorPosition - rangesPair.first); + int replaceLength = rangesPair.second - rangesPair.first; + + replaceText(inputStr, -replaceIndex, replaceLength); + + rangesPair.first = 0; + rangesPair.second = 0; + + } else { + insertText(inputStr); + } + event.call<void>("stopImmediatePropagation"); #if QT_CONFIG(clipboard) } else if (!inputTypeString.compare("insertFromPaste")) { @@ -112,9 +164,8 @@ void QWasmInputContext::inputCallback(emscripten::val event) void QWasmInputContext::compositionEndCallback(emscripten::val event) { const auto inputStr = QString::fromEcmaString(event["data"]); - qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr; - if (preeditString().isEmpty()) + if (preeditString().isEmpty()) // we get final results from inputCallback return; if (inputStr != preeditString()) { @@ -127,27 +178,11 @@ void QWasmInputContext::compositionEndCallback(emscripten::val event) void QWasmInputContext::compositionStartCallback(emscripten::val event) { - Q_UNUSED(event); - qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO; + Q_UNUSED(event); // Do nothing when starting composition } -/* -// Test implementation -static void beforeInputCallback(emscripten::val event) -{ - qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO; - - auto ranges = event.call<emscripten::val>("getTargetRanges"); - auto length = ranges["length"].as<int>(); - for (auto i = 0; i < length; i++) { - qCDebug(qLcQpaWasmInputContext) << ranges.call<emscripten::val>("get", i)["startOffset"].as<int>(); - qCDebug(qLcQpaWasmInputContext) << ranges.call<emscripten::val>("get", i)["endOffset"].as<int>(); - } -} -*/ - void QWasmInputContext::compositionUpdateCallback(emscripten::val event) { const auto compositionStr = QString::fromEcmaString(event["data"]); @@ -317,18 +352,21 @@ void QWasmInputContext::hideInputPanel() void QWasmInputContext::setPreeditString(QString preeditStr, int replaceSize) { + qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << preeditStr << replaceSize; m_preeditString = preeditStr; - m_replaceSize = replaceSize; + m_replaceIndex = replaceSize; } -void QWasmInputContext::insertPreedit() +void QWasmInputContext::insertPreedit(int replaceLength) { qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << m_preeditString; + if (replaceLength == 0) + replaceLength = m_preeditString.length(); QList<QInputMethodEvent::Attribute> attributes; { QInputMethodEvent::Attribute attr_cursor(QInputMethodEvent::Cursor, - m_preeditString.length(), + 0, 1); attributes.append(attr_cursor); @@ -336,21 +374,19 @@ void QWasmInputContext::insertPreedit() format.setFontUnderline(true); format.setUnderlineStyle(QTextCharFormat::SingleUnderline); QInputMethodEvent::Attribute attr_format(QInputMethodEvent::TextFormat, - 0, - m_preeditString.length(), format); + 0, + replaceLength, format); attributes.append(attr_format); } QInputMethodEvent e(m_preeditString, attributes); - if (m_replaceSize > 0) - e.setCommitString("", -m_replaceSize, m_replaceSize); + if (m_replaceIndex > 0) + e.setCommitString("", -m_replaceIndex, replaceLength); QCoreApplication::sendEvent(m_focusObject, &e); } void QWasmInputContext::commitPreeditAndClear() { - qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << m_preeditString; - if (m_preeditString.isEmpty()) return; QInputMethodEvent e; @@ -360,7 +396,8 @@ void QWasmInputContext::commitPreeditAndClear() } void QWasmInputContext::insertText(QString inputStr, bool replace) -{ +{ // commitString + qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr << replace; Q_UNUSED(replace); if (!inputStr.isEmpty()) { const int replaceLen = 0; @@ -370,4 +407,35 @@ void QWasmInputContext::insertText(QString inputStr, bool replace) } } +/* This will replace the text in the focusobject at replaceFrom position, and replaceSize length + with the text in inputStr. */ + + void QWasmInputContext::replaceText(QString inputStr, int replaceFrom, int replaceSize) + { + qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO << inputStr << replaceFrom << replaceSize; + + QList<QInputMethodEvent::Attribute> attributes; + { + QInputMethodEvent::Attribute attr_cursor(QInputMethodEvent::Cursor, + 0, // start + 1); // length + attributes.append(attr_cursor); + + QTextCharFormat format; + format.setFontUnderline(true); + format.setUnderlineStyle(QTextCharFormat::SingleUnderline); + QInputMethodEvent::Attribute attr_format(QInputMethodEvent::TextFormat, + 0, + replaceSize, + format); + attributes.append(attr_format); + } + + QInputMethodEvent e1(QString(), attributes); + e1.setCommitString(inputStr, replaceFrom, replaceSize); + QCoreApplication::sendEvent(m_focusObject, &e1); + + m_preeditString.clear(); + } + QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasminputcontext.h b/src/plugins/platforms/wasm/qwasminputcontext.h index 97415451b2a..006a03455d7 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.h +++ b/src/plugins/platforms/wasm/qwasminputcontext.h @@ -33,10 +33,11 @@ public: const QString preeditString() { return m_preeditString; } void setPreeditString(QString preeditStr, int replaceSize); - void insertPreedit(); + void insertPreedit(int repalcementLength = 0); void commitPreeditAndClear(); void insertText(QString inputStr, bool replace = false); + void replaceText(QString inputString, int replaceFrom, int replaceSize); bool usingTextInput() const { return m_inputMethodAccepted; } void setFocusObject(QObject *object) override; @@ -58,7 +59,7 @@ private: private: QString m_preeditString; - int m_replaceSize = 0; + int m_replaceIndex = 0; bool m_inputMethodAccepted = false; QObject *m_focusObject = nullptr; diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index a88299975d0..d318c977a90 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -761,12 +761,10 @@ void QWasmWindow::handleCompositionEndEvent(emscripten::val event) void QWasmWindow::handleBeforeInputEvent(emscripten::val event) { - qWarning() << Q_FUNC_INFO; - if (QWasmInputContext *inputContext = QWasmIntegration::get()->wasmInputContext(); inputContext->isActive()) inputContext->beforeInputCallback(event); - // else - // m_focusHelper.set("innerHTML", std::string()); + else + m_focusHelper.set("innerHTML", std::string()); } void QWasmWindow::handlePointerEnterLeaveEvent(const PointerEvent &event) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 3013de1c068..156351987cb 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -696,7 +696,7 @@ HWND QWindowsContext::createDummyWindow(const QString &classNameIn, { if (!wndProc) wndProc = DefWindowProc; - QString className = d->m_windowClassRegistry.registerWindowClass(QWindowsWindowClassRegistry::classNamePrefix() + classNameIn, wndProc); + QString className = d->m_windowClassRegistry.registerWindowClass(classNameIn, wndProc); return CreateWindowEx(0, reinterpret_cast<LPCWSTR>(className.utf16()), windowName, style, CW_USEDEFAULT, CW_USEDEFAULT, diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 9139ec0c463..2bd2f0c9e3d 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -704,7 +704,7 @@ void QWindowsScreenManager::initialize() qCDebug(lcQpaScreen) << "Initializing screen manager"; auto className = QWindowsWindowClassRegistry::instance()->registerWindowClass( - QWindowsWindowClassRegistry::classNamePrefix() + QLatin1String("ScreenChangeObserverWindow"), + QLatin1String("ScreenChangeObserverWindow"), qDisplayChangeObserverWndProc); // HWND_MESSAGE windows do not get WM_DISPLAYCHANGE, so we need to create diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index a2ce1e86a4d..beeab1a089e 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -119,9 +119,9 @@ static inline HWND createTrayIconMessageWindow() if (!ctx) return nullptr; // Register window class in the platform plugin. - const QString className = - ctx->registerWindowClass(QWindowsWindowClassRegistry::classNamePrefix() + "TrayIconMessageWindowClass"_L1, - qWindowsTrayIconWndProc); + const QString className = ctx->registerWindowClass( + "TrayIconMessageWindowClass"_L1, + qWindowsTrayIconWndProc); const wchar_t windowName[] = L"QTrayIconMessageWindow"; return CreateWindowEx(0, reinterpret_cast<const wchar_t *>(className.utf16()), windowName, WS_OVERLAPPED, diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 33d7c4124ac..d132bbb6130 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -549,7 +549,7 @@ QWindowsTheme::QWindowsTheme() refreshIconPixmapSizes(); auto className = QWindowsWindowClassRegistry::instance()->registerWindowClass( - QWindowsWindowClassRegistry::classNamePrefix() + QLatin1String("ThemeChangeObserverWindow"), + QLatin1String("ThemeChangeObserverWindow"), qThemeChangeObserverWndProc); // HWND_MESSAGE windows do not get the required theme events, // so we use a real top-level window that we never show. diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 26d0f907b92..ed391009423 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -887,9 +887,12 @@ QWindowsWindowData const auto appinst = reinterpret_cast<HINSTANCE>(GetModuleHandle(nullptr)); const QString windowClassName = QWindowsWindowClassRegistry::instance()->registerWindowClass(w); - const QString windowTitlebarName = QWindowsWindowClassRegistry::instance()->registerWindowClass({ - QStringLiteral("_q_titlebar"), DefWindowProc, CS_VREDRAW | CS_HREDRAW - }); + + QWindowsWindowClassDescription windowTitlebarDescription; + windowTitlebarDescription.name = QStringLiteral("_q_titlebar"); + windowTitlebarDescription.style = CS_VREDRAW | CS_HREDRAW; + windowTitlebarDescription.shouldAddPrefix = false; + const QString windowTitlebarName = QWindowsWindowClassRegistry::instance()->registerWindowClass(windowTitlebarDescription); const QScreen *screen{}; const QRect rect = QPlatformWindow::initialGeometry(w, data.geometry, diff --git a/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp b/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp index cb862bba47c..63e16260b62 100644 --- a/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp +++ b/src/plugins/platforms/windows/qwindowswindowclassdescription.cpp @@ -49,8 +49,7 @@ QWindowsWindowClassDescription QWindowsWindowClassDescription::fromWindow(const break; } // Create a unique name for the flag combination - description.name = QWindowsWindowClassRegistry::classNamePrefix(); - description.name += "QWindow"_L1; + description.name = "QWindow"_L1; switch (type) { case Qt::Tool: description.name += "Tool"_L1; diff --git a/src/plugins/platforms/windows/qwindowswindowclassdescription.h b/src/plugins/platforms/windows/qwindowswindowclassdescription.h index ece48e4343c..9423abf9d2d 100644 --- a/src/plugins/platforms/windows/qwindowswindowclassdescription.h +++ b/src/plugins/platforms/windows/qwindowswindowclassdescription.h @@ -22,6 +22,7 @@ struct QWindowsWindowClassDescription unsigned int style{ 0 }; HBRUSH brush{ nullptr }; bool hasIcon{ false }; + bool shouldAddPrefix{ true }; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp b/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp index e367350d55e..c330720a09c 100644 --- a/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp +++ b/src/plugins/platforms/windows/qwindowswindowclassregistry.cpp @@ -59,6 +59,9 @@ QString QWindowsWindowClassRegistry::registerWindowClass(const QWindowsWindowCla { QString className = description.name; + if (description.shouldAddPrefix) + className = classNamePrefix() + className; + // since multiple Qt versions can be used in one process // each one has to have window class names with a unique name // The first instance gets the unmodified name; if the class diff --git a/src/plugins/platforms/windows/qwindowswindowclassregistry.h b/src/plugins/platforms/windows/qwindowswindowclassregistry.h index d1f10310dc8..c19b4f616fb 100644 --- a/src/plugins/platforms/windows/qwindowswindowclassregistry.h +++ b/src/plugins/platforms/windows/qwindowswindowclassregistry.h @@ -27,13 +27,13 @@ public: static QWindowsWindowClassRegistry *instance(); - static QString classNamePrefix(); - QString registerWindowClass(const QWindowsWindowClassDescription &description); QString registerWindowClass(const QWindow *window); QString registerWindowClass(QString name, WNDPROC procedure); private: + static QString classNamePrefix(); + void unregisterWindowClasses(); static QWindowsWindowClassRegistry *m_instance; |
