Skip to content
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

Support sequential focus navigation #15936

Closed
wants to merge 1 commit into from
Closed

Support sequential focus navigation #15936

wants to merge 1 commit into from

Conversation

nox
Copy link
Contributor

@nox nox commented Mar 14, 2017

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/document.rs, components/script/dom/htmlanchorelement.rs, components/script/dom/element.rs
  • @KiChjang: components/script/dom/document.rs, components/script/dom/htmlanchorelement.rs, components/script/dom/element.rs

@highfive
Copy link

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 14, 2017
@nox nox mentioned this pull request Mar 14, 2017
4 tasks
@nox
Copy link
Contributor Author

nox commented Mar 14, 2017

I've tested this locally, it works, but it cycles through every focusable element, not just form elements. Do we care?

@nox
Copy link
Contributor Author

nox commented Mar 14, 2017

r? @jdm

I can't always be taking tasks from you Josh, sometimes I need to give some to you.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good start, but there are a bunch of tricky details that we should sort out before merging this, I think.

if event.type_() == atom!("keydown") {
match key_event.get_key() {
Some(Key::Enter) => {
follow_hyperlink(self.upcast::<Element>(), Some(String::new()), None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be calling into activation_behaviour here, which will need to be updated to account for non-mouse activations. We should also handle space key events similarly.

fn handle_event(&self, event: &Event) {
if let Some(key_event) = event.downcast::<KeyboardEvent>() {
if event.type_() == atom!("keydown") {
let key = key_event.get_key().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwrap looks scary here.

@@ -592,6 +596,24 @@ impl Document {
}
}

/// Add a focusable element to this document's ordering focus list.
pub fn add_focusable_element(&self, element: &Element) {
self.focus_list.borrow_mut().push(JS::from_ref(element));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not account for the tree ordering of the elements, such as if a control is inserted dynamically into the tree after the initial page is parsed. Also, it doesn't protect against duplicates.


if let Some(index) = index {
list.remove(index);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to ensure that the current focused index is updated to account for this change.


for child in children {
if let Some(element) = child.downcast::<Element>() {
if element.is_focusable_area() && !element.disabled_state() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to account for elements that have their disabled state modified dynamically, too.

@@ -1343,6 +1365,9 @@ impl Document {
event.fire(target);
let mut cancel_state = event.get_cancel_state();

self.handle_event(event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should inline the code from handle_event in here instead. No need to call a different method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdm If we move the code from handle_event here, I think we don't need impl VirtualMethods for Document?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and remove it if that's the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll try it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this comment in the most original PR from @nox , I think that's why nox made it inside VirtualMethods.
However, after trying to make the code in here, the focus sequential still works.
Not sure if there's any concerns about moving the code in here instead of inside VirtualMethods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment you point out was made in a version that did not include the parent type's handle_event call, which is required when using VirtualMethods. I don't think we need to use VirtualMethods for that code, however.

Copy link
Member

@CYBAI CYBAI Dec 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. We can handle the event without VirtualMethods but I didn't know too much about it; thus, I left the comment.
Now, I think it should be okay to remove it :)
Thanks!

@@ -1343,6 +1365,9 @@ impl Document {
event.fire(target);
let mut cancel_state = event.get_cancel_state();

self.handle_event(event);
self.commit_focus_transaction(FocusType::Element);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this for every single key event that is processed seems odd.


if self.is_focusable_area() {
let doc = document_from_node(self);
let children = self.upcast::<Node>().traverse_preorder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to iterate over all the children here, since they should have their own bind_to_tree methods called already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only try to find the starting point of focusable elements, I'll expect we don't need to traverse the children here and add them into the list.

@@ -2260,10 +2274,14 @@ impl VirtualMethods for Element {
}

let doc = document_from_node(self);

doc.remove_focusable_element(self);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only call this if we know that this element is has previously been added to the list.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-new-owner The PR has been abandoned by the original author. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 20, 2017
@jdm
Copy link
Member

jdm commented Apr 12, 2017

Closing since nobody is working on this.

@jdm jdm closed this Apr 12, 2017
// Step 1
// Step 2
// TODO: Implement the sequential focus navigation starting point.
// This can be used to change the starting point for navigation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdm I'm stuck by the add_focusable_element and remove_focusable_element methods above.

According to the spec,

When the user requests that focus move from the currently focused area of a top-level browsing context to the next or previous focusable area (e.g. as the default action of pressing the tab key), or when the user requests that focus sequentially move to a top-level browsing context in the first place (e.g. from the browser's location bar), the user agent must use the following algorithm

Thus, maybe we don't need to save a focus_list inside Document? We might only need to know the starting point?

I'm wondering if it's possible to calculate the starting point and also its next and previous focus candidate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we store the node for the starting point and not the list and starting index then it might be easier, like you suggest. It would require:

  • determining and storing the new starting point if the current starting point ever becomes unfocusable
  • recalculating the list every time we need to change the current starting point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdm Thanks for your confirmation. I'll try to only store the starting point for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-new-owner The PR has been abandoned by the original author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants