inset_embedder/client.rs
1//! Flutter counterpart: `dart:ui` `hooks.dart`.
2//!
3//! Dart's hooks are isolate-global functions the engine calls. Here they are
4//! methods on the embedder client so a host crate need not name `App`.
5
6use std::time::Duration;
7
8use crate::{
9 Frame, KeyData, PointerDataPacket, TextEditingValue, TextInputAction, ViewFocusEvent, ViewId,
10};
11
12/// Complete frames and typed view lifecycle notifications.
13///
14/// The platform updates its view registry before sending a lifecycle method,
15/// so the client can immediately query the affected view.
16pub trait EmbedderClient {
17 fn frame(&mut self, frame: Frame);
18 fn view_added(&mut self, id: ViewId);
19 fn view_metrics_changed(&mut self, id: ViewId);
20 fn view_removed(&mut self, id: ViewId);
21
22 /// Flutter `PlatformDispatcher.onViewFocusChange`.
23 fn view_focus_changed(&mut self, event: ViewFocusEvent) {
24 let _ = event;
25 }
26
27 /// Flutter `PlatformDispatcher.onPointerDataPacket`.
28 fn pointer_data_packet(&mut self, packet: PointerDataPacket);
29
30 /// Flutter `PlatformDispatcher.onKeyData`.
31 ///
32 /// Returns whether the framework handled the event; a host that shares the
33 /// keyboard with other native components should not propagate a handled one.
34 fn key_data(&mut self, data: KeyData) -> bool;
35
36 /// Flutter `PlatformDispatcher.onPlatformBrightnessChanged`: the host's light or dark
37 /// preference changed, and `Platform::platform_brightness` already answers the new one.
38 fn platform_brightness_changed(&mut self);
39
40 /// Flutter `PlatformDispatcher.onLocaleChanged`: the host's locale list changed, and
41 /// `Platform::locales` already answers the new one.
42 fn locales_changed(&mut self);
43
44 /// Flutter `PlatformDispatcher.onSystemFontsChanged`: the host registered faces the
45 /// framework did not have when text last laid out.
46 fn system_fonts_changed(&mut self) {}
47
48 /// A deadline requested through `Platform::wake_at` has passed.
49 ///
50 /// `elapsed` is the platform clock, the same one `Frame::elapsed` reports. Dart's
51 /// event loop runs due `Timer`s itself; here the client advances its own clock.
52 fn wake(&mut self, elapsed: Duration);
53
54 /// Flutter `TextInputClient.updateEditingValue`. The default drops it.
55 fn text_input_editing_value(&mut self, view: ViewId, value: TextEditingValue) {
56 let _ = (view, value);
57 }
58
59 /// Flutter `TextInputClient.performAction`. The default drops it.
60 fn text_input_action(&mut self, view: ViewId, action: TextInputAction) {
61 let _ = (view, action);
62 }
63
64 /// Flutter `TextInputClient.connectionClosed`. The default drops it.
65 fn text_input_closed(&mut self, view: ViewId) {
66 let _ = view;
67 }
68
69 /// Flutter `SystemContextMenuClient.handleSystemHide`. The default drops it.
70 fn system_context_menu_hidden(&mut self) {}
71
72 /// Flutter `SystemContextMenuClient.handleCustomContextMenuAction`. The default drops it.
73 fn custom_context_menu_action(&mut self, callback_id: &str) {
74 let _ = callback_id;
75 }
76}