mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Messages that are sent to the `Constellation` have pretty ambiguous names. This change does two renames: - `ConstellationMsg` → `EmbedderToConstellationMessage` - `ScriptMsg` → `ScriptToConstellationMessage` This naming reflects that the `Constellation` stands in between the embedding layer and the script layer and can receive messages from both. Soon both of these message types will live in `constellation_traits`, reflecting the idea that the `_traits` variant for a crate is responsible for exposing the API for that crate. Testing: No new tests are necessary here as this just renames two enums. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com>
41 lines
1.5 KiB
Rust
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 embedder_traits::EmbedderMsg;
|
|
use ipc_channel::ipc::channel;
|
|
use script_traits::{ScriptToConstellationChan, ScriptToConstellationMessage};
|
|
|
|
/// 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();
|
|
}
|
|
}
|