1use crate::{
2 error::AtspiError,
3 events::{Accessible, EventBodyOwned, GenericEvent, HasMatchRule, HasRegistryEventString},
4 Event,
5};
6use zvariant::ObjectPath;
7
8#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
9pub enum DocumentEvents {
10 /// See: [`LoadCompleteEvent`].
11 LoadComplete(LoadCompleteEvent),
12 /// See: [`ReloadEvent`].
13 Reload(ReloadEvent),
14 /// See: [`LoadStoppedEvent`].
15 LoadStopped(LoadStoppedEvent),
16 /// See: [`ContentChangedEvent`].
17 ContentChanged(ContentChangedEvent),
18 /// See: [`AttributesChangedEvent`].
19 AttributesChanged(AttributesChangedEvent),
20 /// See: [`PageChangedEvent`].
21 PageChanged(PageChangedEvent),
22}
23impl_from_interface_event_enum_for_event!(DocumentEvents, Event::Document);
24impl_try_from_event_for_user_facing_event_type!(DocumentEvents, Event::Document);
25event_wrapper_test_cases!(DocumentEvents, LoadCompleteEvent);
26
27impl HasMatchRule for DocumentEvents {
28 const MATCH_RULE_STRING: &'static str =
29 "type='signal',interface='org.a11y.atspi.Event.Document'";
30}
31
32/// An event triggered by the completion of a document load action.
33/// For example: a web page has finished loading its initial payload, or
34/// `LibreOffice` has loaded a document from disk.
35#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
36pub struct LoadCompleteEvent {
37 /// The [`Accessible`] which the event applies to.
38 pub item: crate::events::Accessible,
39}
40
41/// An event triggered by a reloading of a document.
42/// For example: pressing F5, or `Control + r` will reload a page in a web browser.
43#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
44pub struct ReloadEvent {
45 /// The [`Accessible`] which the event applies to.
46 pub item: crate::events::Accessible,
47}
48
49/// An event triggered by the cancelling of a document load.
50/// For example: during the loading of a large web page, a user may press `Escape` to stop loading the page.
51#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
52pub struct LoadStoppedEvent {
53 /// The [`Accessible`] which the event applies to.
54 pub item: crate::events::Accessible,
55}
56
57#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
58pub struct ContentChangedEvent {
59 /// The [`Accessible`] which the event applies to.
60 pub item: crate::events::Accessible,
61}
62
63#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
64pub struct AttributesChangedEvent {
65 /// The [`Accessible`] which the event applies to.
66 pub item: crate::events::Accessible,
67}
68
69#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
70pub struct PageChangedEvent {
71 /// The [`Accessible`] which the event applies to.
72 pub item: crate::events::Accessible,
73}
74
75impl GenericEvent<'_> for LoadCompleteEvent {
76 const DBUS_MEMBER: &'static str = "LoadComplete";
77 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
78 const MATCH_RULE_STRING: &'static str =
79 "type='signal',interface='org.a11y.atspi.Event.Document',member='LoadComplete'";
80 const REGISTRY_EVENT_STRING: &'static str = "Document:";
81
82 type Body = EventBodyOwned;
83
84 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
85 Ok(Self { item })
86 }
87 fn sender(&self) -> String {
88 self.item.name.clone()
89 }
90 fn path<'a>(&self) -> ObjectPath<'_> {
91 self.item.path.clone().into()
92 }
93 fn body(&self) -> Self::Body {
94 let copy: LoadCompleteEvent = self.clone();
95 copy.into()
96 }
97}
98
99impl GenericEvent<'_> for ReloadEvent {
100 const DBUS_MEMBER: &'static str = "Reload";
101 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
102 const MATCH_RULE_STRING: &'static str =
103 "type='signal',interface='org.a11y.atspi.Event.Document',member='Reload'";
104 const REGISTRY_EVENT_STRING: &'static str = "Document:";
105
106 type Body = EventBodyOwned;
107
108 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
109 Ok(Self { item })
110 }
111 fn sender(&self) -> String {
112 self.item.name.clone()
113 }
114 fn path<'a>(&self) -> ObjectPath<'_> {
115 self.item.path.clone().into()
116 }
117 fn body(&self) -> Self::Body {
118 let copy: ReloadEvent = self.clone();
119 copy.into()
120 }
121}
122
123impl GenericEvent<'_> for LoadStoppedEvent {
124 const DBUS_MEMBER: &'static str = "LoadStopped";
125 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
126 const MATCH_RULE_STRING: &'static str =
127 "type='signal',interface='org.a11y.atspi.Event.Document',member='LoadStopped'";
128 const REGISTRY_EVENT_STRING: &'static str = "Document:";
129
130 type Body = EventBodyOwned;
131
132 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
133 Ok(Self { item })
134 }
135 fn sender(&self) -> String {
136 self.item.name.clone()
137 }
138 fn path<'a>(&self) -> ObjectPath<'_> {
139 self.item.path.clone().into()
140 }
141 fn body(&self) -> Self::Body {
142 let copy: LoadStoppedEvent = self.clone();
143 copy.into()
144 }
145}
146
147impl GenericEvent<'_> for ContentChangedEvent {
148 const DBUS_MEMBER: &'static str = "ContentChanged";
149 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
150 const MATCH_RULE_STRING: &'static str =
151 "type='signal',interface='org.a11y.atspi.Event.Document',member='ContentChanged'";
152 const REGISTRY_EVENT_STRING: &'static str = "Document:";
153
154 type Body = EventBodyOwned;
155
156 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
157 Ok(Self { item })
158 }
159 fn sender(&self) -> String {
160 self.item.name.clone()
161 }
162 fn path<'a>(&self) -> ObjectPath<'_> {
163 self.item.path.clone().into()
164 }
165 fn body(&self) -> Self::Body {
166 let copy: ContentChangedEvent = self.clone();
167 copy.into()
168 }
169}
170
171impl GenericEvent<'_> for AttributesChangedEvent {
172 const DBUS_MEMBER: &'static str = "AttributesChanged";
173 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
174 const MATCH_RULE_STRING: &'static str =
175 "type='signal',interface='org.a11y.atspi.Event.Document',member='AttributesChanged'";
176 const REGISTRY_EVENT_STRING: &'static str = "Document:";
177
178 type Body = EventBodyOwned;
179
180 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
181 Ok(Self { item })
182 }
183 fn sender(&self) -> String {
184 self.item.name.clone()
185 }
186 fn path<'a>(&self) -> ObjectPath<'_> {
187 self.item.path.clone().into()
188 }
189 fn body(&self) -> Self::Body {
190 let copy: AttributesChangedEvent = self.clone();
191 copy.into()
192 }
193}
194
195impl GenericEvent<'_> for PageChangedEvent {
196 const DBUS_MEMBER: &'static str = "PageChanged";
197 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
198 const MATCH_RULE_STRING: &'static str =
199 "type='signal',interface='org.a11y.atspi.Event.Document',member='PageChanged'";
200 const REGISTRY_EVENT_STRING: &'static str = "Document:";
201
202 type Body = EventBodyOwned;
203
204 fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> {
205 Ok(Self { item })
206 }
207 fn sender(&self) -> String {
208 self.item.name.clone()
209 }
210 fn path<'a>(&self) -> ObjectPath<'_> {
211 self.item.path.clone().into()
212 }
213 fn body(&self) -> Self::Body {
214 let copy: PageChangedEvent = self.clone();
215 copy.into()
216 }
217}
218
219#[cfg(feature = "zbus")]
220impl TryFrom<&zbus::Message> for DocumentEvents {
221 type Error = AtspiError;
222 fn try_from(ev: &zbus::Message) -> Result<Self, Self::Error> {
223 let member: MemberName<'_> = ev
224 .member()
225 .ok_or(err:AtspiError::MemberMatch("Event without member".into()))?;
226 match member.as_str() {
227 "LoadComplete" => Ok(DocumentEvents::LoadComplete(ev.try_into()?)),
228 "Reload" => Ok(DocumentEvents::Reload(ev.try_into()?)),
229 "LoadStopped" => Ok(DocumentEvents::LoadStopped(ev.try_into()?)),
230 "ContentChanged" => Ok(DocumentEvents::ContentChanged(ev.try_into()?)),
231 "AttributesChanged" => Ok(DocumentEvents::AttributesChanged(ev.try_into()?)),
232 "PageChanged" => Ok(DocumentEvents::PageChanged(ev.try_into()?)),
233 _ => Err(AtspiError::MemberMatch("No matching member for Document".into())),
234 }
235 }
236}
237
238impl_from_user_facing_event_for_interface_event_enum!(
239 LoadCompleteEvent,
240 DocumentEvents,
241 DocumentEvents::LoadComplete
242);
243impl_from_user_facing_type_for_event_enum!(LoadCompleteEvent, Event::Document);
244impl_try_from_event_for_user_facing_type!(
245 LoadCompleteEvent,
246 DocumentEvents::LoadComplete,
247 Event::Document
248);
249
250event_test_cases!(LoadCompleteEvent);
251impl_to_dbus_message!(LoadCompleteEvent);
252impl_from_dbus_message!(LoadCompleteEvent);
253impl From<LoadCompleteEvent> for EventBodyOwned {
254 fn from(_event: LoadCompleteEvent) -> Self {
255 EventBodyOwned {
256 properties: std::collections::HashMap::new(),
257 kind: String::default(),
258 detail1: i32::default(),
259 detail2: i32::default(),
260 any_data: zvariant::Value::U8(0).into(),
261 }
262 }
263}
264
265impl_from_user_facing_event_for_interface_event_enum!(
266 ReloadEvent,
267 DocumentEvents,
268 DocumentEvents::Reload
269);
270impl_from_user_facing_type_for_event_enum!(ReloadEvent, Event::Document);
271impl_try_from_event_for_user_facing_type!(ReloadEvent, DocumentEvents::Reload, Event::Document);
272
273event_test_cases!(ReloadEvent);
274impl_to_dbus_message!(ReloadEvent);
275impl_from_dbus_message!(ReloadEvent);
276impl From<ReloadEvent> for EventBodyOwned {
277 fn from(_event: ReloadEvent) -> Self {
278 EventBodyOwned {
279 properties: std::collections::HashMap::new(),
280 kind: String::default(),
281 detail1: i32::default(),
282 detail2: i32::default(),
283 any_data: zvariant::Value::U8(0).into(),
284 }
285 }
286}
287
288impl_from_user_facing_event_for_interface_event_enum!(
289 LoadStoppedEvent,
290 DocumentEvents,
291 DocumentEvents::LoadStopped
292);
293impl_from_user_facing_type_for_event_enum!(LoadStoppedEvent, Event::Document);
294impl_try_from_event_for_user_facing_type!(
295 LoadStoppedEvent,
296 DocumentEvents::LoadStopped,
297 Event::Document
298);
299
300event_test_cases!(LoadStoppedEvent);
301impl_to_dbus_message!(LoadStoppedEvent);
302impl_from_dbus_message!(LoadStoppedEvent);
303impl From<LoadStoppedEvent> for EventBodyOwned {
304 fn from(_event: LoadStoppedEvent) -> Self {
305 EventBodyOwned {
306 properties: std::collections::HashMap::new(),
307 kind: String::default(),
308 detail1: i32::default(),
309 detail2: i32::default(),
310 any_data: zvariant::Value::U8(0).into(),
311 }
312 }
313}
314
315impl_from_user_facing_event_for_interface_event_enum!(
316 ContentChangedEvent,
317 DocumentEvents,
318 DocumentEvents::ContentChanged
319);
320impl_from_user_facing_type_for_event_enum!(ContentChangedEvent, Event::Document);
321impl_try_from_event_for_user_facing_type!(
322 ContentChangedEvent,
323 DocumentEvents::ContentChanged,
324 Event::Document
325);
326
327event_test_cases!(ContentChangedEvent);
328impl_to_dbus_message!(ContentChangedEvent);
329impl_from_dbus_message!(ContentChangedEvent);
330impl From<ContentChangedEvent> for EventBodyOwned {
331 fn from(_event: ContentChangedEvent) -> Self {
332 EventBodyOwned {
333 properties: std::collections::HashMap::new(),
334 kind: String::default(),
335 detail1: i32::default(),
336 detail2: i32::default(),
337 any_data: zvariant::Value::U8(0).into(),
338 }
339 }
340}
341
342impl_from_user_facing_event_for_interface_event_enum!(
343 AttributesChangedEvent,
344 DocumentEvents,
345 DocumentEvents::AttributesChanged
346);
347impl_from_user_facing_type_for_event_enum!(AttributesChangedEvent, Event::Document);
348impl_try_from_event_for_user_facing_type!(
349 AttributesChangedEvent,
350 DocumentEvents::AttributesChanged,
351 Event::Document
352);
353
354event_test_cases!(AttributesChangedEvent);
355impl_to_dbus_message!(AttributesChangedEvent);
356impl_from_dbus_message!(AttributesChangedEvent);
357impl From<AttributesChangedEvent> for EventBodyOwned {
358 fn from(_event: AttributesChangedEvent) -> Self {
359 EventBodyOwned {
360 properties: std::collections::HashMap::new(),
361 kind: String::default(),
362 detail1: i32::default(),
363 detail2: i32::default(),
364 any_data: zvariant::Value::U8(0).into(),
365 }
366 }
367}
368
369impl_from_user_facing_event_for_interface_event_enum!(
370 PageChangedEvent,
371 DocumentEvents,
372 DocumentEvents::PageChanged
373);
374impl_from_user_facing_type_for_event_enum!(PageChangedEvent, Event::Document);
375impl_try_from_event_for_user_facing_type!(
376 PageChangedEvent,
377 DocumentEvents::PageChanged,
378 Event::Document
379);
380
381event_test_cases!(PageChangedEvent);
382impl_to_dbus_message!(PageChangedEvent);
383impl_from_dbus_message!(PageChangedEvent);
384impl From<PageChangedEvent> for EventBodyOwned {
385 fn from(_event: PageChangedEvent) -> Self {
386 EventBodyOwned {
387 properties: std::collections::HashMap::new(),
388 kind: String::default(),
389 detail1: i32::default(),
390 detail2: i32::default(),
391 any_data: zvariant::Value::U8(0).into(),
392 }
393 }
394}
395
396impl HasRegistryEventString for DocumentEvents {
397 const REGISTRY_EVENT_STRING: &'static str = "Document:";
398}
399