12 #ifndef hifi_RenderableWebEntityItem_h
13 #define hifi_RenderableWebEntityItem_h
15 #include <QtCore/QSharedPointer>
16 #include <WebEntityItem.h>
17 #include "RenderableEntityItem.h"
19 class OffscreenQmlSurface;
22 namespace render {
namespace entities {
24 class WebEntityRenderer :
public TypedEntityRenderer<WebEntityItem> {
26 using Parent = TypedEntityRenderer<WebEntityItem>;
27 friend class EntityRenderer;
30 WebEntityRenderer(
const EntityItemPointer& entity);
33 Q_INVOKABLE
void hoverEnterEntity(
const PointerEvent& event);
34 Q_INVOKABLE
void hoverLeaveEntity(
const PointerEvent& event);
35 Q_INVOKABLE
void handlePointerEvent(
const PointerEvent& event);
37 static const QString QML;
38 static const char* URL_PROPERTY;
39 static const char* SCRIPT_URL_PROPERTY;
40 static const char* GLOBAL_POSITION_PROPERTY;
41 static const char* USE_BACKGROUND_PROPERTY;
42 static const char* USER_AGENT_PROPERTY;
44 static void setAcquireWebSurfaceOperator(std::function<
void(
const QString&,
bool, QSharedPointer<OffscreenQmlSurface>&,
bool&)> acquireWebSurfaceOperator) { _acquireWebSurfaceOperator = acquireWebSurfaceOperator; }
45 static void acquireWebSurface(
const QString& url,
bool htmlContent, QSharedPointer<OffscreenQmlSurface>& webSurface,
bool& cachedWebSurface) {
46 if (_acquireWebSurfaceOperator) {
47 _acquireWebSurfaceOperator(url, htmlContent, webSurface, cachedWebSurface);
51 static void setReleaseWebSurfaceOperator(std::function<
void(QSharedPointer<OffscreenQmlSurface>&,
bool&, std::vector<QMetaObject::Connection>&)> releaseWebSurfaceOperator) { _releaseWebSurfaceOperator = releaseWebSurfaceOperator; }
52 static void releaseWebSurface(QSharedPointer<OffscreenQmlSurface>& webSurface,
bool& cachedWebSurface, std::vector<QMetaObject::Connection>& connections) {
53 if (_releaseWebSurfaceOperator) {
54 _releaseWebSurfaceOperator(webSurface, cachedWebSurface, connections);
58 virtual void setProxyWindow(QWindow* proxyWindow)
override;
59 virtual QObject* getEventHandler()
override;
61 gpu::TexturePointer getTexture()
override {
return _texture; }
64 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const override;
65 virtual void doRenderUpdateSynchronousTyped(
const ScenePointer& scene, Transaction& transaction,
const TypedEntityPointer& entity)
override;
66 virtual void doRender(RenderArgs* args)
override;
67 virtual bool isTransparent()
const override;
69 virtual bool wantsHandControllerPointerEvents()
const override {
return true; }
70 virtual bool wantsKeyboardFocus()
const override {
return true; }
72 void handlePointerEventAsTouch(
const PointerEvent& event);
73 void handlePointerEventAsMouse(
const PointerEvent& event);
77 void buildWebSurface(
const EntityItemPointer& entity,
const QString& newSourceURL);
78 void destroyWebSurface();
79 glm::vec2 getWindowSize(
const TypedEntityPointer& entity)
const;
82 enum class ContentType {
87 static ContentType getContentType(
const QString& urlString);
88 ContentType _contentType { ContentType::NoContent };
90 QSharedPointer<OffscreenQmlSurface> _webSurface {
nullptr };
91 bool _cachedWebSurface {
false };
92 gpu::TexturePointer _texture;
93 QString _tryingToBuildURL;
96 float _alpha { 1.0f };
97 PulsePropertyGroup _pulseProperties;
103 bool _useBackground {
false };
105 WebInputMode _inputMode { WebInputMode::TOUCH };
107 glm::vec3 _contextPosition;
110 uint64_t _lastRenderTime { 0 };
112 std::vector<QMetaObject::Connection> _connections;
114 static std::function<void(QString,
bool, QSharedPointer<OffscreenQmlSurface>&,
bool&)> _acquireWebSurfaceOperator;
115 static std::function<void(QSharedPointer<OffscreenQmlSurface>&,
bool&, std::vector<QMetaObject::Connection>&)> _releaseWebSurfaceOperator;
118 void emitScriptEvent(
const QVariant& scriptMessage)
override;
121 void scriptEventReceived(
const QVariant& message);
122 void webEventReceived(
const QVariant& message);
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:30