diff --git a/interface/resources/qml/controls/Key.qml b/interface/resources/qml/controls/Key.qml index 172d6cb507..4d6fb79354 100644 --- a/interface/resources/qml/controls/Key.qml +++ b/interface/resources/qml/controls/Key.qml @@ -11,22 +11,40 @@ Item { id: mouseArea1 anchors.fill: parent hoverEnabled: true + + onCanceled: { + keyItem.state = "" + } + + onClicked: { + mouse.accepted = true + webEntity.synthesizeKeyPress(glyph) + } + + onDoubleClicked: { + mouse.accepted = true + } + onEntered: { keyItem.state = "mouseOver" } + onExited: { keyItem.state = "" } + onPressed: { keyItem.state = "mouseClicked" + mouse.accepted = true } + onReleased: { - keyItem.state = "" - } - onClicked: { - } - onCanceled: { - keyItem.state = "" + if (containsMouse) { + keyItem.state = "mouseOver" + } else { + keyItem.state = "" + } + mouse.accepted = true } } diff --git a/interface/resources/qml/controls/Keyboard.qml b/interface/resources/qml/controls/Keyboard.qml index d895fcf0f1..9b1cb0e277 100644 --- a/interface/resources/qml/controls/Keyboard.qml +++ b/interface/resources/qml/controls/Keyboard.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { id: keyboardBase + height: 200 Rectangle { id: leftRect y: 0 diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index 8de68d0d00..99dc9c21c9 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -6,7 +6,12 @@ Item { WebEngineView { id: root - anchors.fill: parent + + x: 0 + y: 0 + width: parent.width + height: parent.height - keyboard1.height + property string newUrl: "" profile.httpUserAgent: "Mozilla/5.0 Chrome (HighFidelityInterface)" diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 9cd8e4ca35..426fd20e02 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -37,6 +37,12 @@ static uint64_t MAX_NO_RENDER_INTERVAL = 30 * USECS_PER_SECOND; static int MAX_WINDOW_SIZE = 4096; static float OPAQUE_ALPHA_THRESHOLD = 0.99f; +void WebEntityQMLAPIHelper::synthesizeKeyPress(QString key) { + if (_ptr) { + _ptr->synthesizeKeyPress(key); + } +} + EntityItemPointer RenderableWebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer entity{ new RenderableWebEntityItem(entityID) }; entity->setProperties(properties); @@ -51,9 +57,12 @@ RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemI _touchDevice.setType(QTouchDevice::TouchScreen); _touchDevice.setName("RenderableWebEntityItemTouchDevice"); _touchDevice.setMaximumTouchPoints(4); + + _webEntityQMLAPIHelper.setPtr(this); } RenderableWebEntityItem::~RenderableWebEntityItem() { + _webEntityQMLAPIHelper.setPtr(nullptr); destroyWebSurface(); qDebug() << "Destroyed web entity " << getID(); } @@ -76,6 +85,7 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { _webSurface->resume(); _webSurface->getRootItem()->setProperty("url", _sourceUrl); _webSurface->getRootContext()->setContextProperty("desktop", QVariant()); + _webSurface->getRootContext()->setContextProperty("webEntity", &_webEntityQMLAPIHelper); _connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { _texture = textureId; }); @@ -98,13 +108,8 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { point.setState(Qt::TouchPointReleased); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); QPointF windowPoint(windowPos.x, windowPos.y); - auto item = _webSurface->getRootItem()->childAt(windowPos.x, windowPos.y); - QPointF localPoint = windowPoint; - if (item) { - localPoint = item->mapFromScene(windowPoint); - } point.setScenePos(windowPoint); - point.setPos(localPoint); + point.setPos(windowPoint); QList touchPoints; touchPoints.push_back(point); QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); @@ -224,13 +229,6 @@ void RenderableWebEntityItem::handlePointerEvent(const PointerEvent& event) { glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); QPointF windowPoint(windowPos.x, windowPos.y); - - auto item = _webSurface->getRootItem()->childAt(windowPos.x, windowPos.y); - QPointF localPoint = windowPoint; - if (item) { - localPoint = item->mapFromScene(windowPoint); - } - if (event.getType() == PointerEvent::Move) { // Forward a mouse move event to webSurface QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton, Qt::NoButton, Qt::NoModifier); @@ -266,7 +264,7 @@ void RenderableWebEntityItem::handlePointerEvent(const PointerEvent& event) { QTouchEvent::TouchPoint point; point.setId(event.getID()); point.setState(touchPointState); - point.setPos(localPoint); + point.setPos(windowPoint); point.setScreenPos(windowPoint); QList touchPoints; touchPoints.push_back(point); @@ -323,3 +321,11 @@ bool RenderableWebEntityItem::isTransparent() { float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f; return fadeRatio < OPAQUE_ALPHA_THRESHOLD; } + +void RenderableWebEntityItem::synthesizeKeyPress(QString key) { + auto utf8Key = key.toUtf8(); + QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, (int)utf8Key[0], Qt::NoModifier, key); + QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, (int)utf8Key[0], Qt::NoModifier, key); + QCoreApplication::postEvent(getEventHandler(), pressEvent); + QCoreApplication::postEvent(getEventHandler(), releaseEvent); +} diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index 20c121a2c1..ec8223432c 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -22,6 +22,19 @@ class OffscreenQmlSurface; class QWindow; class QObject; class EntityTreeRenderer; +class RenderableWebEntityItem; + +class WebEntityQMLAPIHelper : public QObject { + Q_OBJECT +public: + void setPtr(RenderableWebEntityItem* ptr) { + _ptr = ptr; + } + Q_INVOKABLE void synthesizeKeyPress(QString key); + +protected: + RenderableWebEntityItem* _ptr{ nullptr }; +}; class RenderableWebEntityItem : public WebEntityItem { public: @@ -46,6 +59,9 @@ public: virtual bool isTransparent() override; +public: + void synthesizeKeyPress(QString key); + private: bool buildWebSurface(EntityTreeRenderer* renderer); void destroyWebSurface(); @@ -59,6 +75,7 @@ private: QTouchEvent _lastTouchEvent { QEvent::TouchUpdate }; uint64_t _lastRenderTime{ 0 }; QTouchDevice _touchDevice; + WebEntityQMLAPIHelper _webEntityQMLAPIHelper; QMetaObject::Connection _mousePressConnection; QMetaObject::Connection _mouseReleaseConnection; @@ -66,5 +83,4 @@ private: QMetaObject::Connection _hoverLeaveConnection; }; - #endif // hifi_RenderableWebEntityItem_h diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 32e0b047de..d285ddf5d8 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -21,7 +21,7 @@ Script.include("/~/system/libraries/Xform.js"); // add lines where the hand ray picking is happening // var WANT_DEBUG = false; -var WANT_DEBUG_STATE = false; +var WANT_DEBUG_STATE = true; var WANT_DEBUG_SEARCH_NAME = null; // @@ -2159,6 +2159,7 @@ function MyController(hand) { }; } else { pointerEvent = this.touchingEnterPointerEvent; + pointerEvent.type = "Release"; pointerEvent.button = "Primary"; pointerEvent.isPrimaryButton = false; }