53#if defined(__has_include) && __has_include(<pulp/host/plugin_slot.hpp>)
54#define PULP_VIEW_HAS_HOSTED_EDITOR_ATTACHMENT 1
65class EditorAttachment {
67 EditorAttachment(
const EditorAttachment&) =
delete;
68 EditorAttachment& operator=(
const EditorAttachment&) =
delete;
70 EditorAttachment(EditorAttachment&& other) noexcept
71 : slot_(std::move(
other.slot_)), host_(
other.host_), editor_(std::move(
other.editor_)),
73 attached_(
other.attached_) {
75 other.host_ =
nullptr;
76 other.attached_ =
false;
79 install_resize_handler();
82 EditorAttachment& operator=(EditorAttachment&& other)
noexcept {
85 slot_ = std::move(
other.slot_);
87 editor_ = std::move(
other.editor_);
90 width_ =
other.width_;
91 height_ =
other.height_;
92 attached_ =
other.attached_;
94 other.host_ =
nullptr;
95 other.attached_ =
false;
96 install_resize_handler();
101 ~EditorAttachment() {
110 static std::unique_ptr<EditorAttachment> create(std::shared_ptr<host::PluginSlot> slot,
111 WindowHost* host,
float x = 0.0f,
115 auto editor = slot->create_hosted_editor(host->native_window_handle());
116 if (!editor || !
editor->native_handle) {
118 slot->destroy_hosted_editor(std::move(editor));
121 const float w =
static_cast<float>(
editor->width);
122 const float h =
static_cast<float>(
editor->height);
123 const bool ok = host->attach_native_child_view(
editor->native_handle, x, y, w, h);
125 slot->destroy_hosted_editor(std::move(editor));
129 std::unique_ptr<EditorAttachment> attachment(
130 new EditorAttachment(std::move(slot), host, std::move(editor), x, y));
131 attachment->install_resize_handler();
136 const host::PluginSlot::HostedEditor*
editor()
const {
137 return editor_.get();
141 bool is_attached()
const {
148 bool set_bounds(
float x,
float y,
float width,
float height) {
149 if (!attached_ || !host_ || !editor_)
152 host_->set_native_child_view_bounds(editor_->native_handle, x, y, width, height);
167 slot_->set_editor_resize_request_handler(
nullptr);
171 if (editor_ && slot_) {
172 slot_->destroy_hosted_editor(std::move(editor_));
178 if (host_ && editor_) {
179 host_->detach_native_child_view(editor_->native_handle);
182 if (slot_ && editor_) {
183 slot_->destroy_hosted_editor(std::move(editor_));
195 float width()
const {
203 EditorAttachment(std::shared_ptr<host::PluginSlot> slot, WindowHost* host,
204 std::unique_ptr<host::PluginSlot::HostedEditor> editor,
float x,
float y)
205 : slot_(std::
move(slot)), host_(host), editor_(std::
move(
editor)), x_(
x), y_(
y),
206 width_(static_cast<float>(editor_ ? editor_->
width : 0)),
207 height_(static_cast<float>(editor_ ? editor_->
height : 0)), attached_(true) {}
214 void install_resize_handler() {
217 slot_->set_editor_resize_request_handler([
this](uint32_t width, uint32_t height) {
218 return set_bounds(x_, y_,
static_cast<float>(width),
static_cast<float>(height));
222 std::shared_ptr<host::PluginSlot> slot_;
223 WindowHost* host_ =
nullptr;
224 std::unique_ptr<host::PluginSlot::HostedEditor> editor_;
228 float height_ = 0.0f;
229 bool attached_ =
false;
235#define PULP_VIEW_HAS_HOSTED_EDITOR_ATTACHMENT 0
@ ok
Definition analyzer_provider.hpp:58
@ other
Definition udev_monitor.hpp:26
@ width
Definition config.hpp:225
@ move
Definition web_event_translate.hpp:110
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ h
Definition input_events.hpp:39
@ y
Definition input_events.hpp:42
@ x
Definition input_events.hpp:41
@ w
Definition input_events.hpp:41
@ height
Definition css_animation.hpp:128