use crate::{
error::AtspiError,
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties,
};
use zbus_names::UniqueName;
use zvariant::{ObjectPath, OwnedValue};
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
pub enum DocumentEvents {
LoadComplete(LoadCompleteEvent),
Reload(ReloadEvent),
LoadStopped(LoadStoppedEvent),
ContentChanged(ContentChangedEvent),
AttributesChanged(AttributesChangedEvent),
PageChanged(PageChangedEvent),
}
impl EventTypeProperties for DocumentEvents {
fn member(&self) -> &'static str {
match self {
Self::LoadComplete(inner) => inner.member(),
Self::Reload(inner) => inner.member(),
Self::LoadStopped(inner) => inner.member(),
Self::ContentChanged(inner) => inner.member(),
Self::AttributesChanged(inner) => inner.member(),
Self::PageChanged(inner) => inner.member(),
}
}
fn interface(&self) -> &'static str {
match self {
Self::LoadComplete(inner) => inner.interface(),
Self::Reload(inner) => inner.interface(),
Self::LoadStopped(inner) => inner.interface(),
Self::ContentChanged(inner) => inner.interface(),
Self::AttributesChanged(inner) => inner.interface(),
Self::PageChanged(inner) => inner.interface(),
}
}
fn match_rule(&self) -> &'static str {
match self {
Self::LoadComplete(inner) => inner.match_rule(),
Self::Reload(inner) => inner.match_rule(),
Self::LoadStopped(inner) => inner.match_rule(),
Self::ContentChanged(inner) => inner.match_rule(),
Self::AttributesChanged(inner) => inner.match_rule(),
Self::PageChanged(inner) => inner.match_rule(),
}
}
fn registry_string(&self) -> &'static str {
match self {
Self::LoadComplete(inner) => inner.registry_string(),
Self::Reload(inner) => inner.registry_string(),
Self::LoadStopped(inner) => inner.registry_string(),
Self::ContentChanged(inner) => inner.registry_string(),
Self::AttributesChanged(inner) => inner.registry_string(),
Self::PageChanged(inner) => inner.registry_string(),
}
}
}
impl EventProperties for DocumentEvents {
fn path(&self) -> ObjectPath<'_> {
match self {
Self::LoadComplete(inner) => inner.path(),
Self::Reload(inner) => inner.path(),
Self::LoadStopped(inner) => inner.path(),
Self::ContentChanged(inner) => inner.path(),
Self::AttributesChanged(inner) => inner.path(),
Self::PageChanged(inner) => inner.path(),
}
}
fn sender(&self) -> UniqueName<'_> {
match self {
Self::LoadComplete(inner) => inner.sender(),
Self::Reload(inner) => inner.sender(),
Self::LoadStopped(inner) => inner.sender(),
Self::ContentChanged(inner) => inner.sender(),
Self::AttributesChanged(inner) => inner.sender(),
Self::PageChanged(inner) => inner.sender(),
}
}
}
impl_from_interface_event_enum_for_event!(DocumentEvents, Event::Document);
impl_try_from_event_for_user_facing_event_type!(DocumentEvents, Event::Document);
event_wrapper_test_cases!(DocumentEvents, LoadCompleteEvent);
impl HasMatchRule for DocumentEvents {
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document'";
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct LoadCompleteEvent {
pub item: crate::events::ObjectRef,
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct ReloadEvent {
pub item: crate::events::ObjectRef,
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct LoadStoppedEvent {
pub item: crate::events::ObjectRef,
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct ContentChangedEvent {
pub item: crate::events::ObjectRef,
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct AttributesChangedEvent {
pub item: crate::events::ObjectRef,
}
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
pub struct PageChangedEvent {
pub item: crate::events::ObjectRef,
}
impl BusProperties for LoadCompleteEvent {
const DBUS_MEMBER: &'static str = "LoadComplete";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='LoadComplete'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
impl BusProperties for ReloadEvent {
const DBUS_MEMBER: &'static str = "Reload";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='Reload'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
impl BusProperties for LoadStoppedEvent {
const DBUS_MEMBER: &'static str = "LoadStopped";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='LoadStopped'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
impl BusProperties for ContentChangedEvent {
const DBUS_MEMBER: &'static str = "ContentChanged";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='ContentChanged'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
impl BusProperties for AttributesChangedEvent {
const DBUS_MEMBER: &'static str = "AttributesChanged";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='AttributesChanged'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
impl BusProperties for PageChangedEvent {
const DBUS_MEMBER: &'static str = "PageChanged";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document";
const MATCH_RULE_STRING: &'static str =
"type='signal',interface='org.a11y.atspi.Event.Document',member='PageChanged'";
const REGISTRY_EVENT_STRING: &'static str = "Document:";
type Body = EventBodyOwned;
fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
Ok(Self { item })
}
fn body(&self) -> Self::Body {
let copy = self.clone();
copy.into()
}
}
#[cfg(feature = "zbus")]
impl TryFrom<&zbus::Message> for DocumentEvents {
type Error = AtspiError;
fn try_from(ev: &zbus::Message) -> Result<Self, Self::Error> {
let header = ev.header();
let member = header
.member()
.ok_or(AtspiError::MemberMatch("Event without member".into()))?;
match member.as_str() {
"LoadComplete" => Ok(DocumentEvents::LoadComplete(ev.try_into()?)),
"Reload" => Ok(DocumentEvents::Reload(ev.try_into()?)),
"LoadStopped" => Ok(DocumentEvents::LoadStopped(ev.try_into()?)),
"ContentChanged" => Ok(DocumentEvents::ContentChanged(ev.try_into()?)),
"AttributesChanged" => Ok(DocumentEvents::AttributesChanged(ev.try_into()?)),
"PageChanged" => Ok(DocumentEvents::PageChanged(ev.try_into()?)),
_ => Err(AtspiError::MemberMatch("No matching member for Document".into())),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
LoadCompleteEvent,
DocumentEvents,
DocumentEvents::LoadComplete
);
impl_from_user_facing_type_for_event_enum!(LoadCompleteEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(
LoadCompleteEvent,
DocumentEvents::LoadComplete,
Event::Document
);
event_test_cases!(LoadCompleteEvent);
impl_to_dbus_message!(LoadCompleteEvent);
impl_from_dbus_message!(LoadCompleteEvent);
impl_event_properties!(LoadCompleteEvent);
impl From<LoadCompleteEvent> for EventBodyOwned {
fn from(_event: LoadCompleteEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
ReloadEvent,
DocumentEvents,
DocumentEvents::Reload
);
impl_from_user_facing_type_for_event_enum!(ReloadEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(ReloadEvent, DocumentEvents::Reload, Event::Document);
event_test_cases!(ReloadEvent);
impl_to_dbus_message!(ReloadEvent);
impl_from_dbus_message!(ReloadEvent);
impl_event_properties!(ReloadEvent);
impl From<ReloadEvent> for EventBodyOwned {
fn from(_event: ReloadEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
LoadStoppedEvent,
DocumentEvents,
DocumentEvents::LoadStopped
);
impl_from_user_facing_type_for_event_enum!(LoadStoppedEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(
LoadStoppedEvent,
DocumentEvents::LoadStopped,
Event::Document
);
event_test_cases!(LoadStoppedEvent);
impl_to_dbus_message!(LoadStoppedEvent);
impl_from_dbus_message!(LoadStoppedEvent);
impl_event_properties!(LoadStoppedEvent);
impl From<LoadStoppedEvent> for EventBodyOwned {
fn from(_event: LoadStoppedEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
ContentChangedEvent,
DocumentEvents,
DocumentEvents::ContentChanged
);
impl_from_user_facing_type_for_event_enum!(ContentChangedEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(
ContentChangedEvent,
DocumentEvents::ContentChanged,
Event::Document
);
event_test_cases!(ContentChangedEvent);
impl_to_dbus_message!(ContentChangedEvent);
impl_from_dbus_message!(ContentChangedEvent);
impl_event_properties!(ContentChangedEvent);
impl From<ContentChangedEvent> for EventBodyOwned {
fn from(_event: ContentChangedEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
AttributesChangedEvent,
DocumentEvents,
DocumentEvents::AttributesChanged
);
impl_from_user_facing_type_for_event_enum!(AttributesChangedEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(
AttributesChangedEvent,
DocumentEvents::AttributesChanged,
Event::Document
);
event_test_cases!(AttributesChangedEvent);
impl_to_dbus_message!(AttributesChangedEvent);
impl_from_dbus_message!(AttributesChangedEvent);
impl_event_properties!(AttributesChangedEvent);
impl From<AttributesChangedEvent> for EventBodyOwned {
fn from(_event: AttributesChangedEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl_from_user_facing_event_for_interface_event_enum!(
PageChangedEvent,
DocumentEvents,
DocumentEvents::PageChanged
);
impl_from_user_facing_type_for_event_enum!(PageChangedEvent, Event::Document);
impl_try_from_event_for_user_facing_type!(
PageChangedEvent,
DocumentEvents::PageChanged,
Event::Document
);
event_test_cases!(PageChangedEvent);
impl_to_dbus_message!(PageChangedEvent);
impl_from_dbus_message!(PageChangedEvent);
impl_event_properties!(PageChangedEvent);
impl From<PageChangedEvent> for EventBodyOwned {
fn from(_event: PageChangedEvent) -> Self {
EventBodyOwned {
properties: std::collections::HashMap::new(),
kind: String::default(),
detail1: i32::default(),
detail2: i32::default(),
any_data: OwnedValue::from(0u8),
}
}
}
impl HasRegistryEventString for DocumentEvents {
const REGISTRY_EVENT_STRING: &'static str = "Document:";
}