Skip to content

Commit

Permalink
fix: Derive Debug for adapters (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcrawford authored Feb 6, 2025
1 parent aa17717 commit 753d904
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 22 deletions.
4 changes: 2 additions & 2 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use crate::iterators::{
};
use crate::tree::State as TreeState;

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) struct ParentAndIndex(pub(crate) NodeId, pub(crate) usize);

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct NodeState {
pub(crate) parent_and_index: Option<ParentAndIndex>,
pub(crate) data: Arc<NodeData>,
Expand Down
3 changes: 2 additions & 1 deletion consumer/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use immutable_chunkmap::map::MapM as ChunkMap;

use crate::node::{Node, NodeState, ParentAndIndex};

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct State {
pub(crate) nodes: ChunkMap<NodeId, NodeState>,
pub(crate) data: TreeData,
Expand Down Expand Up @@ -229,6 +229,7 @@ pub trait ChangeHandler {
fn node_removed(&mut self, node: &Node);
}

#[derive(Debug)]
pub struct Tree {
state: State,
}
Expand Down
26 changes: 18 additions & 8 deletions platforms/atspi-common/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.

use crate::{
context::{ActionHandlerNoMut, ActionHandlerWrapper, AppContext, Context},
filters::filter,
node::{NodeIdOrRoot, NodeWrapper, PlatformNode, PlatformRoot},
util::WindowBounds,
AdapterCallback, Event, ObjectEvent, WindowEvent,
};
use accesskit::{ActionHandler, NodeId, Role, TreeUpdate};
use accesskit_consumer::{FilterResult, Node, Tree, TreeChangeHandler, TreeState};
use atspi_common::{InterfaceSet, Live, State};
use std::fmt::{Debug, Formatter};
use std::{
collections::HashSet,
sync::{
Expand All @@ -19,14 +27,6 @@ use std::{
},
};

use crate::{
context::{ActionHandlerNoMut, ActionHandlerWrapper, AppContext, Context},
filters::filter,
node::{NodeIdOrRoot, NodeWrapper, PlatformNode, PlatformRoot},
util::WindowBounds,
AdapterCallback, Event, ObjectEvent, WindowEvent,
};

struct AdapterChangeHandler<'a> {
adapter: &'a Adapter,
added_nodes: HashSet<NodeId>,
Expand Down Expand Up @@ -320,6 +320,16 @@ pub struct Adapter {
context: Arc<Context>,
}

impl Debug for Adapter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Adapter")
.field("id", &self.id)
.field("callback", &"AdapterCallback")
.field("context", &self.context)
.finish()
}
}

impl Adapter {
pub fn new(
app_context: &Arc<RwLock<AppContext>>,
Expand Down
13 changes: 13 additions & 0 deletions platforms/atspi-common/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use accesskit::{ActionHandler, ActionRequest};
use accesskit_consumer::Tree;
use std::fmt::{Debug, Formatter};
use std::sync::{Arc, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};

use crate::WindowBounds;
Expand Down Expand Up @@ -38,6 +39,17 @@ pub(crate) struct Context {
pub(crate) root_window_bounds: RwLock<WindowBounds>,
}

impl Debug for Context {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Context")
.field("app_context", &self.app_context)
.field("tree", &self.tree)
.field("action_handler", &"ActionHandler")
.field("root_window_bounds", &self.root_window_bounds)
.finish()
}
}

impl Context {
pub(crate) fn new(
app_context: &Arc<RwLock<AppContext>>,
Expand Down Expand Up @@ -74,6 +86,7 @@ impl Context {
}
}

#[derive(Debug)]
pub struct AppContext {
pub(crate) name: Option<String>,
pub(crate) toolkit_name: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion platforms/atspi-common/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use atspi_common::{CoordType, Granularity};

use crate::Error;

#[derive(Clone, Copy, Default)]
#[derive(Clone, Copy, Default, Debug)]
pub struct WindowBounds {
pub outer: Rect,
pub inner: Rect,
Expand Down
45 changes: 37 additions & 8 deletions platforms/macos/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use crate::{
context::{ActionHandlerNoMut, ActionHandlerWrapper, Context},
event::{focus_event, EventGenerator, QueuedEvents},
filters::filter,
node::can_be_focused,
util::*,
};
use accesskit::{
ActionHandler, ActionRequest, ActivationHandler, Node as NodeProvider, NodeId, Role,
Tree as TreeData, TreeUpdate,
Expand All @@ -11,16 +18,9 @@ use accesskit_consumer::{FilterResult, Tree};
use objc2::rc::{Id, WeakId};
use objc2_app_kit::NSView;
use objc2_foundation::{MainThreadMarker, NSArray, NSObject, NSPoint};
use std::fmt::{Debug, Formatter};
use std::{ffi::c_void, ptr::null_mut, rc::Rc};

use crate::{
context::{ActionHandlerNoMut, ActionHandlerWrapper, Context},
event::{focus_event, EventGenerator, QueuedEvents},
filters::filter,
node::can_be_focused,
util::*,
};

const PLACEHOLDER_ROOT_ID: NodeId = NodeId(0);

enum State {
Expand All @@ -38,12 +38,41 @@ enum State {
Active(Rc<Context>),
}

impl Debug for State {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
State::Inactive {
view,
is_view_focused,
action_handler: _,
mtm,
} => f
.debug_struct("Inactive")
.field("view", view)
.field("is_view_focused", is_view_focused)
.field("mtm", mtm)
.finish(),
State::Placeholder {
placeholder_context,
is_view_focused,
action_handler: _,
} => f
.debug_struct("Placeholder")
.field("placeholder_context", placeholder_context)
.field("is_view_focused", is_view_focused)
.finish(),
State::Active(context) => f.debug_struct("Active").field("context", context).finish(),
}
}
}

struct PlaceholderActionHandler;

impl ActionHandler for PlaceholderActionHandler {
fn do_action(&mut self, _request: ActionRequest) {}
}

#[derive(Debug)]
pub struct Adapter {
state: State,
}
Expand Down
16 changes: 14 additions & 2 deletions platforms/macos/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use crate::node::PlatformNode;
use accesskit::{ActionHandler, ActionRequest, NodeId};
use accesskit_consumer::Tree;
use hashbrown::HashMap;
use objc2::rc::{Id, WeakId};
use objc2_app_kit::*;
use objc2_foundation::MainThreadMarker;
use std::fmt::Debug;
use std::{cell::RefCell, rc::Rc};

use crate::node::PlatformNode;

pub(crate) trait ActionHandlerNoMut {
fn do_action(&self, request: ActionRequest);
}
Expand All @@ -39,6 +39,18 @@ pub(crate) struct Context {
pub(crate) mtm: MainThreadMarker,
}

impl Debug for Context {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Context")
.field("view", &self.view)
.field("tree", &self.tree)
.field("action_handler", &"ActionHandler")
.field("platform_nodes", &self.platform_nodes)
.field("mtm", &self.mtm)
.finish()
}
}

impl Context {
pub(crate) fn new(
view: WeakId<NSView>,
Expand Down
1 change: 1 addition & 0 deletions platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ pub(crate) struct PlatformNodeIvars {
}

declare_class!(
#[derive(Debug)]
pub(crate) struct PlatformNode;

unsafe impl ClassType for PlatformNode {
Expand Down
30 changes: 30 additions & 0 deletions platforms/unix/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use accesskit_atspi_common::{
#[cfg(not(feature = "tokio"))]
use async_channel::Sender;
use atspi::InterfaceSet;
use std::fmt::{Debug, Formatter};
use std::sync::{Arc, Mutex};
#[cfg(feature = "tokio")]
use tokio::sync::mpsc::UnboundedSender as Sender;
Expand Down Expand Up @@ -71,6 +72,35 @@ pub(crate) enum AdapterState {
Active(AdapterImpl),
}

impl Debug for AdapterState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
AdapterState::Inactive {
is_window_focused,
root_window_bounds,
action_handler: _,
} => f
.debug_struct("Inactive")
.field("is_window_focused", is_window_focused)
.field("root_window_bounds", root_window_bounds)
.field("action_handler", &"ActionHandler")
.finish(),
AdapterState::Pending {
is_window_focused,
root_window_bounds,
action_handler: _,
} => f
.debug_struct("Pending")
.field("is_window_focused", is_window_focused)
.field("root_window_bounds", root_window_bounds)
.field("action_handler", &"ActionHandler")
.finish(),
AdapterState::Active(r#impl) => f.debug_tuple("Active").field(r#impl).finish(),
}
}
}

#[derive(Debug)]
pub struct Adapter {
messages: Sender<Message>,
id: usize,
Expand Down
21 changes: 21 additions & 0 deletions platforms/windows/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use accesskit::{
};
use accesskit_consumer::{FilterResult, Node, Tree, TreeChangeHandler};
use hashbrown::HashSet;
use std::fmt::{Debug, Formatter};
use std::sync::{atomic::Ordering, Arc};
use windows::Win32::{
Foundation::*,
Expand Down Expand Up @@ -150,6 +151,26 @@ enum State {
Active(Arc<Context>),
}

impl Debug for State {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
State::Inactive {
hwnd,
is_window_focused,
action_handler: _,
} => f
.debug_struct("Inactive")
.field("hwnd", hwnd)
.field("is_window_focused", is_window_focused)
.field("action_handler", &"ActionHandler")
.finish(),
State::Placeholder(context) => f.debug_tuple("Placeholder").field(context).finish(),
State::Active(context) => f.debug_tuple("Active").field(context).finish(),
}
}
}

#[derive(Debug)]
pub struct Adapter {
state: State,
}
Expand Down
12 changes: 12 additions & 0 deletions platforms/windows/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use accesskit::{ActionHandler, ActionRequest, Point};
use accesskit_consumer::Tree;
use std::fmt::{Debug, Formatter};
use std::sync::{atomic::AtomicBool, Arc, Mutex, RwLock, RwLockReadGuard};

use crate::{util::*, window_handle::WindowHandle};
Expand Down Expand Up @@ -34,6 +35,17 @@ pub(crate) struct Context {
pub(crate) is_placeholder: AtomicBool,
}

impl Debug for Context {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Context")
.field("hwnd", &self.hwnd)
.field("tree", &self.tree)
.field("action_handler", &"ActionHandler")
.field("is_placeholder", &self.is_placeholder)
.finish()
}
}

impl Context {
pub(crate) fn new(
hwnd: WindowHandle,
Expand Down

0 comments on commit 753d904

Please sign in to comment.