Skip to content

servoview: Focus the view when a touch input occurs.#40049

Merged
jdm merged 1 commit intoservo:mainfrom
jdm:servoview-focus
Oct 21, 2025
Merged

servoview: Focus the view when a touch input occurs.#40049
jdm merged 1 commit intoservo:mainfrom
jdm:servoview-focus

Conversation

@jdm
Copy link
Copy Markdown
Member

@jdm jdm commented Oct 21, 2025

Focusing the location bar in the Android app shows the onscreen keyboard, but clicking on a link in the current document does not make it disappear. This change ensures the input focus is reset appropriately and ensures the keyboard disappear when the location bar is not being edited.

Testing: Manually tested. No automated tests for Android app at this time.
Fixes: #40008

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 21, 2025

@Override
public boolean onTouchEvent(final MotionEvent e) {
requestFocus();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have to request focus on each touch event? Also, I noticed that the focus change listener we add in the activity here never gets called. Could this be related to the current issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm having trouble imagining what alternatives there are to requesting focus on input. Also, the focus listener is definitely called in my testing—how are you determining that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm having trouble imagining what alternatives there are to requesting focus on input.

My concern was that requestFocus might be too costly to be called on every touch event, so maybe there could be an alternative where we requestFocus only when we know the view doesn't have it already. I don't know about the actual cost of requestFocus though.

Also, the focus listener is definitely called in my testing—how are you determining that?

Yep, it does get called. I was using assert false as the body, but I didn't realize assertions are disabled in release builds. The debug build confirms that it is called.

Copy link
Copy Markdown
Member

@mukilan mukilan left a comment

Choose a reason for hiding this comment

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

I couldn't come up with a better approach, so lets go with this.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 21, 2025
@jdm jdm added this pull request to the merge queue Oct 21, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 21, 2025
Merged via the queue into servo:main with commit cf077ef Oct 21, 2025
34 checks passed
@jdm jdm deleted the servoview-focus branch October 21, 2025 08:17
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't unfocus location bar without navigating

3 participants