servo/components/script/clipboard_provider.rs
Martin Robinson 6031a12fd1
Move ScriptToConstellationMsg to constellation_traits (#36364)
This is the last big change necessary to create the
`constellation_traits` crate. This moves the data structure for messages
that originate from the `ScriptThread` and are sent to the
`Contellation` to `constellation_traits`, effectively splitting
`script_traits` in half. Before, `script_traits` was responsible for
exposing the API of both the `ScriptThread` and the `Constellation` to
the rest of Servo.

- Data structures that are used by `ScriptToConstellationMsg` are moved
  to `constellation_traits`. The dependency graph looks a bit like this:
  `script_layout_interface` depends on `script_traits` depends on
  `constellation_traits` depends on `embedder_traits`.
- Data structures that are used in the embedding layer
  (`UntrustedNodeAddress`, `CompositorHitTestResult`, `TouchEventResult`
  and `AnimationState`) are moved to embedder_traits, to avoid a
  dependency cycle between `webrender_traits` and
  `constellation_traits`.
- Types dealing with MessagePorts and serialization are moved to
  `constellation_traits::message_port`.

Testing: This is covered by existing tests as it just moves types
around.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-05 22:13:29 +00:00

41 lines
1.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::id::WebViewId;
use constellation_traits::{ScriptToConstellationChan, ScriptToConstellationMessage};
use embedder_traits::EmbedderMsg;
use ipc_channel::ipc::channel;
/// A trait which abstracts access to the embedder's clipboard in order to allow unit
/// testing clipboard-dependent parts of `script`.
pub trait ClipboardProvider {
/// Get the text content of the clipboard.
fn get_text(&mut self) -> Result<String, String>;
/// Set the text content of the clipboard.
fn set_text(&mut self, _: String);
}
pub(crate) struct EmbedderClipboardProvider {
pub constellation_sender: ScriptToConstellationChan,
pub webview_id: WebViewId,
}
impl ClipboardProvider for EmbedderClipboardProvider {
fn get_text(&mut self) -> Result<String, String> {
let (tx, rx) = channel().unwrap();
self.constellation_sender
.send(ScriptToConstellationMessage::ForwardToEmbedder(
EmbedderMsg::GetClipboardText(self.webview_id, tx),
))
.unwrap();
rx.recv().unwrap()
}
fn set_text(&mut self, s: String) {
self.constellation_sender
.send(ScriptToConstellationMessage::ForwardToEmbedder(
EmbedderMsg::SetClipboardText(self.webview_id, s),
))
.unwrap();
}
}