-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gtk: Implementable implementation for AccessibleText #1789
gtk: Implementable implementation for AccessibleText #1789
Conversation
let mut c_ranges = glib::Slice::with_capacity(attrs.len()); | ||
let mut c_names = glib::StrV::with_capacity(attrs.len()); | ||
let mut c_values = glib::StrV::with_capacity(attrs.len()); | ||
|
||
for (range, name, value) in attrs { | ||
c_ranges.push(range); | ||
c_names.push(name); | ||
c_values.push(value); | ||
} | ||
|
||
*ranges = c_ranges.to_glib_container().0; | ||
*attribute_names = c_names.into_glib_ptr(); | ||
*attribute_values = c_values.into_glib_ptr(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having to juggle the collections like that here, and in get_default_attributes
, but having to return three Vec from this function would also be odd. Semantically these are triples, but they are supposed to be stored in three different arrays.
A wrapper type could solve the problem but I'm not sure we should introduce two of these just for this one-off.
dadc102
to
d3daa8a
Compare
I am a little unsure if it's ever ok to return null in get_contents(_at) or not. Should I return an empty gbytes instead? |
I don't have the time to review this right now but two questions:
|
We can postpone it for now.
Sure, that makes sense. It's quite an involved interface. |
&mut attribute_names, | ||
&mut attribute_values, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there are necessarily n_ranges
attribute names/values. Both are just NULL
-terminated string arrays. I'd assume both have the same length but otherwise they should be independent from the ranges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are. See https://docs.gtk.org/gtk4/vfunc.AccessibleText.get_attributes.html
Each attribute is composed by:
- a range
- a name
- a value
You have a buffer of text, and then you annotate a range with attribute / value pairs. If you had more names and values, where would the extra attributes apply to?
See https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/a11y/gtkatspitext.c#L173 for an implementation. It even calls n_ranges
n_attrs
🙈 .
I generally think this interface is quite confusing in that regard though, and it's very easy to get lost here. Which is the main reason why I've opted for the approach of only allowing triples here. Because having less attribute/name pairs than ranges actually immediately triggers a memory unsafety bug just in the code linked above.
} | ||
} | ||
|
||
fn parent_contents(&self, start: u32, end: u32) -> Option<glib::Bytes> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this must not return NULL
? Or at least the C functions is not annotated as such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the upstream implementation as reference. Yes, I think this might be an annotation issue. https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkaccessibletext.c#L20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be too much to ask if you could fix those missing nullable annotations? otherwise i can take care of that :)
end.as_mut_ptr(), | ||
); | ||
|
||
if !bytes.is_null() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not marked as nullable either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, another annotation issue. If I don't do this I get UB. https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkaccessibletext.c#L35
|
||
bytes.to_glib_full() | ||
} else { | ||
std::ptr::null_mut() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not marked as nullable in C
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d3daa8a
to
bd836ee
Compare
There is still one thing here that I don't particularly understand: The 'bytes' return value is supposed to be a |
bd836ee
to
54881a8
Compare
Maybe two wrapper objects for (range, attr, value) triples wouldn't be such a bad idea. When writing the example it was very cumbersome to change attributes, adding attributes by constants, etc. |
09c571c
to
90c127c
Compare
I think we can do that as a second step :) but yes, having to deal with constants is not ideal. But also not sure how we can do something that wouldn't be too far away from the original API. Maybe we can make those attributes an enum? then you would only have a |
90c127c
to
b2798f7
Compare
b2798f7
to
df3268e
Compare
impl AccessibleTextView {} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct AccessibleTextView(ObjectSubclass<imp::AccessibleTextView>) | ||
@extends gtk::Widget, gtk::TextView, | ||
@implements gtk::Accessible, gtk::AccessibleText, gtk::Buildable, gtk::ConstraintTarget, gtk::Scrollable; | ||
} | ||
|
||
impl AccessibleTextView {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl AccessibleTextView {} | |
} | |
glib::wrapper! { | |
pub struct AccessibleTextView(ObjectSubclass<imp::AccessibleTextView>) | |
@extends gtk::Widget, gtk::TextView, | |
@implements gtk::Accessible, gtk::AccessibleText, gtk::Buildable, gtk::ConstraintTarget, gtk::Scrollable; | |
} | |
impl AccessibleTextView {} | |
} | |
glib::wrapper! { | |
pub struct AccessibleTextView(ObjectSubclass<imp::AccessibleTextView>) | |
@extends gtk::Widget, gtk::TextView, | |
@implements gtk::Accessible, gtk::AccessibleText, gtk::Buildable, gtk::ConstraintTarget, gtk::Scrollable; | |
} |
} | ||
} | ||
|
||
fn parent_contents(&self, start: u32, end: u32) -> Option<glib::Bytes> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be too much to ask if you could fix those missing nullable annotations? otherwise i can take care of that :)
df3268e
to
d86d9dd
Compare
No description provided.