[WebDriver] Add synchronization for key action#37403
Conversation
longvatrong111
left a comment
There was a problem hiding this comment.
I have some suggestion about implementing count.
My main idea is we should follow the spec and avoid making differences in function signature.
|
|
||
| // Step 1.3. Try to dispatch tick actions | ||
| self.dispatch_tick_actions(tick_actions, tick_duration)?; | ||
| let cnt = self.dispatch_tick_actions(tick_actions, tick_duration)?; |
There was a problem hiding this comment.
Is there any reason to return a count here?
If it's only a refactor so we should avoid changing function signature.
If it improves the couting logic, I recommend we can make a class variable and update anywhere in actions code.
There was a problem hiding this comment.
Hmm, my concern is that sometimes dispatch_keyup sometimes don't dispatch any event
Hence, I try to return if it's counted or not. I also have concern with differing with spec, but I don't really know how to handle this one.
There was a problem hiding this comment.
Actually not only in keyup, but also in the pointerdown and pointerup. Here
There was a problem hiding this comment.
As discussed offline, I add sent_action_count item in Handler to avoid returning i32 when dispatching actions. @longvatrong111
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct ServoKeyEvent { | ||
| pub event: KeyboardEvent, |
There was a problem hiding this comment.
This pattern is weird and also inconsistent with the other types of events.
Is it possible to add message id to the existing KeyboardEvent struct?
There was a problem hiding this comment.
Unfortunately KeyboardEvent is taken from keyboard_types crate. I don't know how to add the id unless we wrap the event into another struct.
There was a problem hiding this comment.
I see, thanks. Then wrapping it seems to be the only way to go.
- I'm still concerned about the inconsistent approaches between keyboard events and other events. But maybe I'm overthinking...
ServoKeyEventis still a weird name. Any better idea?
There was a problem hiding this comment.
For number one, I also think that the approach is weird, but I think we have to do it like this until in the future, if the design for waiting the action is changed for the better.
For number two, how about WrappedKeyEvent?
There was a problem hiding this comment.
I don't have a good idea. Maybe just call it KeyboardEventWithWebDriverMsgId, plus some comment what this is for and why, and a TODO for thinking about a better name.
A name should explain its role and usage. WrappedKeyEvent is therefore not informative enough, as readers still can't tell why it's wrapped.
There was a problem hiding this comment.
How about keep it KeyboardEvent? Because it still appears everywhere in Servo. Other parts don't need to care about webdriver_id we add inside.
There was a problem hiding this comment.
I think calling it KeyboardEvent makes sense.
There was a problem hiding this comment.
The problem with calling it KeyboardEvent is that in headed_window.rs, we already have KeyboardEvent from Servo. So I think there will be conflict of name.
There was a problem hiding this comment.
I'll go with Xiaocheng's suggestion for now.
Signed-off-by: PotatoCP <[email protected]>
longvatrong111
left a comment
There was a problem hiding this comment.
The purpose of wrapping a type is we pretend the wrapper type is the internal type.
We can expose everything of keyboard_types::KeyboardEvent in our embedder::KeyboardEvent, it seems a bit verbose here but help keeping the API input_events provides.
Or can we fix it in keyboard_types crate?
| /// Wrap the KeyboardEvent from crate to pair it with webdriver_id, | ||
| /// which is used for webdriver action synchronization. | ||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct KeyboardEventWithWebDriverId { |
There was a problem hiding this comment.
Can we do something like this? I believe it can minimize the change outside of this file.
| pub struct KeyboardEventWithWebDriverId { | |
| use keyboard_types::{CompositionEvent, KeyboardEvent as ExternalKeyboardEvent, Modifier}; | |
| pub struct KeyboardEvent { | |
| pub event: ExternalKeyboardEvent, | |
| pub modifiers: Modifier, | |
| ... | |
| } | |
| impl KeyboardEvent { | |
| pub fn new(event: ExternalKeyboardEvent) -> Self { | |
| Self { | |
| event: keyboard_event, | |
| modifiers: event.modifiers, | |
| webdriver_id: None, | |
| } | |
| } | |
| fn foo(&self) { | |
| self.event.foo() | |
| } | |
| } |
There was a problem hiding this comment.
This looks good. I think the event item is unneeded, since keyboard_types:KeyboardEvent has no method
The event field is still needed I guess, see below comment.
|
I have tried to disguise the wrapper struct. Maybe you can check later when you have time @longvatrong111. |
| pub struct ShortcutMatcher; | ||
| impl ShortcutMatcher { | ||
| pub fn from_event<T>(event: KeyboardEvent) -> ExternalShortcutMatcher<T> { | ||
| ExternalShortcutMatcher::from_event(event.event) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
This is for
servo/ports/servoshell/desktop/app_state.rs
Lines 315 to 323 in e69962e
Let me know if anyone has any better suggestion about this, since I has some doubts.
There was a problem hiding this comment.
If we can't totally remove keyboard_types::KeyboardEvent, I think it's good to convert between 2 events sometimes.
longvatrong111
left a comment
There was a problem hiding this comment.
Look mostly good to me. I have some more suggestions.
7d1c871 to
12080fd
Compare
Signed-off-by: PotatoCP <[email protected]>
| /// which is used for webdriver action synchronization. | ||
| #[derive(Clone, Debug, Default, Deserialize, Serialize)] | ||
| pub struct KeyboardEvent { | ||
| pub state: KeyState, |
There was a problem hiding this comment.
We can either wrap or unpack the external KeyboardEvent, but doing both at the same time looks really bad to me.
Let's go back to simply wrapping it so that we can reuse the abilities of the external KeyboardEvent.
There was a problem hiding this comment.
Thanks. I have made so that we only wrap the event but still making sure that code other than input_event only use input_event::KeyboardEvent instead of keyboard_types::KeyboardEvent
Signed-off-by: PotatoCP <[email protected]>
|
Build on OH failed. Could you fix the usage of |
Signed-off-by: PotatoCP <[email protected]>
|
Thanks for the notice. It should be good now @xiaochengh |
|
🔨 Triggering try run (#15726388444) for OpenHarmony |
|
✨ Try run (#15726388444) succeeded. |
Implement action synchronization for key event. Previously only done for pointer #36932 and wheel #37260.