summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-10-03 16:19:42 +0200
committerMikolaj Boc <mikolaj.boc@qt.io>2022-10-19 00:19:11 +0200
commit9c6b8ea2907ac97392b521a1c68e4dd03c2028e1 (patch)
tree9dbb418a648047fa4c6352b4d907d880bf0057cb /src/corelib/kernel
parentfda5061abd5cef06d8ac649d927792fdc8d1d01f (diff)
Add the toDOMRect/fromDOMRect functions to QRectF
These are very helpful when converting to and from DOMRect. Change-Id: I4a7fc6318f45bed8e2b82fd5d6ec174dc1762326 Fixes: QTBUG-107740 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qcore_wasm.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_wasm.cpp b/src/corelib/kernel/qcore_wasm.cpp
new file mode 100644
index 0000000000..5c8fac59b0
--- /dev/null
+++ b/src/corelib/kernel/qcore_wasm.cpp
@@ -0,0 +1,45 @@
+// Copyright (C) 2022 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
+
+#include <QtCore/qrect.h>
+
+#include <emscripten/val.h>
+
+#if !defined(Q_OS_WASM)
+static_assert(false, "This is a wasm-only file.");
+#endif // !defined(Q_OS_WASM)
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ Converts the DOMRect (https://www.w3.org/TR/geometry-1/) \a domRect to QRectF. The behavior is
+ undefined if the provided parameter is not a DOMRect.
+
+ \since 6.5
+ \ingroup platform-type-conversions
+
+ \sa toDOMRect()
+*/
+QRectF QRectF::fromDOMRect(emscripten::val domRect)
+{
+ Q_ASSERT_X(domRect["constructor"]["name"].as<std::string>() == "DOMRect", Q_FUNC_INFO,
+ "Passed object is not a DOMRect");
+
+ return QRectF(domRect["left"].as<qreal>(), domRect["top"].as<qreal>(),
+ domRect["width"].as<qreal>(), domRect["height"].as<qreal>());
+}
+
+/*!
+ Converts this object to a DOMRect (https://www.w3.org/TR/geometry-1/).
+
+ \since 6.5
+ \ingroup platform-type-conversions
+
+ \sa fromDOMRect()
+*/
+emscripten::val QRectF::toDOMRect() const
+{
+ return emscripten::val::global("DOMRect").new_(left(), top(), width(), height());
+}
+
+QT_END_NAMESPACE