Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 194 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions platforms/macos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ default-target = "x86_64-apple-darwin"
accesskit = { version = "0.21.0", path = "../../common" }
accesskit_consumer = { version = "0.30.0", path = "../../consumer" }
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher"] }
objc2 = "0.5.1"
objc2-foundation = { version = "0.2.0", features = [
objc2 = "0.6.2"
objc2-foundation = { version = "0.3.1", features = [
"NSArray",
"NSDictionary",
"NSValue",
"NSThread",
] }
objc2-app-kit = { version = "0.2.0", features = [
objc2-app-kit = { version = "0.3.1", features = [
"NSAccessibility",
"NSAccessibilityConstants",
"NSAccessibilityElement",
Expand Down
24 changes: 12 additions & 12 deletions platforms/macos/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use accesskit::{
Tree as TreeData, TreeUpdate,
};
use accesskit_consumer::{FilterResult, Tree};
use objc2::rc::{Id, WeakId};
use objc2::rc::{Retained, Weak};
use objc2_app_kit::NSView;
use objc2_foundation::{MainThreadMarker, NSArray, NSObject, NSPoint};
use std::fmt::{Debug, Formatter};
Expand All @@ -25,7 +25,7 @@ const PLACEHOLDER_ROOT_ID: NodeId = NodeId(0);

enum State {
Inactive {
view: WeakId<NSView>,
view: Weak<NSView>,
is_view_focused: bool,
action_handler: Rc<dyn ActionHandlerNoMut>,
mtm: MainThreadMarker,
Expand Down Expand Up @@ -91,8 +91,8 @@ impl Adapter {
is_view_focused: bool,
action_handler: impl 'static + ActionHandler,
) -> Self {
let view = unsafe { Id::retain(view as *mut NSView) }.unwrap();
let view = WeakId::from_id(&view);
let view = unsafe { Retained::retain(view as *mut NSView) }.unwrap();
let view = Weak::from_retained(&view);
let mtm = MainThreadMarker::new().unwrap();
let state = State::Inactive {
view,
Expand Down Expand Up @@ -231,20 +231,20 @@ impl Adapter {
let state = tree.state();
let node = state.root();
let platform_nodes = if filter(&node) == FilterResult::Include {
vec![Id::into_super(Id::into_super(
vec![Retained::into_super(Retained::into_super(
context.get_or_create_platform_node(node.id()),
))]
} else {
node.filtered_children(filter)
.map(|node| {
Id::into_super(Id::into_super(
Retained::into_super(Retained::into_super(
context.get_or_create_platform_node(node.id()),
))
})
.collect::<Vec<Id<NSObject>>>()
.collect::<Vec<Retained<NSObject>>>()
};
let array = NSArray::from_vec(platform_nodes);
Id::autorelease_return(array)
let array = NSArray::from_retained_slice(&platform_nodes);
Retained::autorelease_return(array)
}

pub fn focus<H: ActivationHandler + ?Sized>(
Expand All @@ -256,14 +256,14 @@ impl Adapter {
let state = tree.state();
if let Some(node) = state.focus() {
if can_be_focused(&node) {
return Id::autorelease_return(context.get_or_create_platform_node(node.id()))
return Retained::autorelease_return(context.get_or_create_platform_node(node.id()))
as *mut _;
}
}
null_mut()
}

fn weak_view(&self) -> &WeakId<NSView> {
fn weak_view(&self) -> &Weak<NSView> {
match &self.state {
State::Inactive { view, .. } => view,
State::Placeholder {
Expand Down Expand Up @@ -292,6 +292,6 @@ impl Adapter {
let root = state.root();
let point = from_ns_point(&view, &root, point);
let node = root.node_at_point(point, &filter).unwrap_or(root);
Id::autorelease_return(context.get_or_create_platform_node(node.id())) as *mut _
Retained::autorelease_return(context.get_or_create_platform_node(node.id())) as *mut _
}
}
15 changes: 9 additions & 6 deletions platforms/macos/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::node::PlatformNode;
use accesskit::{ActionHandler, ActionRequest, NodeId};
use accesskit_consumer::Tree;
use hashbrown::HashMap;
use objc2::rc::{Id, WeakId};
use objc2::rc::{Retained, Weak};
use objc2_app_kit::*;
use objc2_foundation::MainThreadMarker;
use std::fmt::Debug;
Expand All @@ -32,10 +32,10 @@ impl<H: ActionHandler> ActionHandlerNoMut for ActionHandlerWrapper<H> {
}

pub(crate) struct Context {
pub(crate) view: WeakId<NSView>,
pub(crate) view: Weak<NSView>,
pub(crate) tree: RefCell<Tree>,
pub(crate) action_handler: Rc<dyn ActionHandlerNoMut>,
platform_nodes: RefCell<HashMap<NodeId, Id<PlatformNode>>>,
platform_nodes: RefCell<HashMap<NodeId, Retained<PlatformNode>>>,
pub(crate) mtm: MainThreadMarker,
}

Expand All @@ -53,7 +53,7 @@ impl Debug for Context {

impl Context {
pub(crate) fn new(
view: WeakId<NSView>,
view: Weak<NSView>,
tree: Tree,
action_handler: Rc<dyn ActionHandlerNoMut>,
mtm: MainThreadMarker,
Expand All @@ -67,7 +67,10 @@ impl Context {
})
}

pub(crate) fn get_or_create_platform_node(self: &Rc<Self>, id: NodeId) -> Id<PlatformNode> {
pub(crate) fn get_or_create_platform_node(
self: &Rc<Self>,
id: NodeId,
) -> Retained<PlatformNode> {
let mut platform_nodes = self.platform_nodes.borrow_mut();
if let Some(result) = platform_nodes.get(&id) {
return result.clone();
Expand All @@ -78,7 +81,7 @@ impl Context {
result
}

pub(crate) fn remove_platform_node(&self, id: NodeId) -> Option<Id<PlatformNode>> {
pub(crate) fn remove_platform_node(&self, id: NodeId) -> Option<Retained<PlatformNode>> {
let mut platform_nodes = self.platform_nodes.borrow_mut();
platform_nodes.remove(&id)
}
Expand Down
6 changes: 3 additions & 3 deletions platforms/macos/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ impl QueuedEvent {
Self::Announcement {
text: node.value().unwrap(),
priority: if node.live() == Live::Assertive {
NSAccessibilityPriorityLevel::NSAccessibilityPriorityHigh
NSAccessibilityPriorityLevel::High
} else {
NSAccessibilityPriorityLevel::NSAccessibilityPriorityMedium
NSAccessibilityPriorityLevel::Medium
},
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ impl QueuedEvent {
}
};

let mut user_info = NSMutableDictionary::<_, AnyObject>::new();
let user_info = NSMutableDictionary::<_, AnyObject>::new();
let text = NSString::from_str(&text);
unsafe {
user_info.setObject_forKey(
Expand Down
Loading