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 ShapeKey getShapeKey()
override;
65 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const override;
66 virtual void doRenderUpdateSynchronousTyped(
const ScenePointer& scene, Transaction& transaction,
const TypedEntityPointer& entity)
override;
67 virtual void doRender(RenderArgs* args)
override;
68 virtual bool isTransparent()
const override;
70 virtual bool wantsHandControllerPointerEvents()
const override {
return true; }
71 virtual bool wantsKeyboardFocus()
const override {
return _wantsKeyboardFocus; }
73 void handlePointerEventAsTouch(
const PointerEvent& event);
74 void handlePointerEventAsMouse(
const PointerEvent& event);
78 void buildWebSurface(
const EntityItemPointer& entity,
const QString& newSourceURL);
79 void destroyWebSurface();
80 glm::vec2 getWindowSize(
const TypedEntityPointer& entity)
const;
83 enum class ContentType {
88 static ContentType getContentType(
const QString& urlString);
89 ContentType _contentType { ContentType::NoContent };
91 QSharedPointer<OffscreenQmlSurface> _webSurface {
nullptr };
92 bool _cachedWebSurface {
false };
93 gpu::TexturePointer _texture;
94 QString _tryingToBuildURL;
97 float _alpha { 1.0f };
98 PulsePropertyGroup _pulseProperties;
104 bool _useBackground {
false };
106 WebInputMode _inputMode { WebInputMode::TOUCH };
107 bool _wantsKeyboardFocus {
true };
110 glm::vec3 _contextPosition;
113 uint64_t _lastRenderTime { 0 };
115 std::vector<QMetaObject::Connection> _connections;
117 static std::function<void(QString,
bool, QSharedPointer<OffscreenQmlSurface>&,
bool&)> _acquireWebSurfaceOperator;
118 static std::function<void(QSharedPointer<OffscreenQmlSurface>&,
bool&, std::vector<QMetaObject::Connection>&)> _releaseWebSurfaceOperator;
121 void emitScriptEvent(
const QVariant& scriptMessage)
override;
124 void scriptEventReceived(
const QVariant& message);
125 void webEventReceived(
const QVariant& message);
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:32