GithubHelp home page GithubHelp logo

Comments (7)

jscholes avatar jscholes commented on September 14, 2024

I managed to resolve this by calling the MoveFocus method of ICoreWebView2Controller. But not sure if:

  1. the library should make an assumption that focus should land on the browser by default;
  2. the library should just offer a FocusBrowser method or similar; and/or
  3. where to put this method call in the code.

I feel that, if the window is being created by the library as opposed to by the caller, as the browser will be the only thing in that window, it is the most accessible approach to have the library focus the browser by default.

from go-webview2.

jscholes avatar jscholes commented on September 14, 2024

Also, an additional note: while I can get focus to reliably move into the browser when the window is initially created, I can't get it to stay there. If I Alt+Tab to another window and then back, focus lands on the window again.

from go-webview2.

jchv avatar jchv commented on September 14, 2024

Sorry about this one. As far as I can tell, the most "correct" solution is simply make use of the very poorly named user32.IsDialogMessage in order to use the built-in Windows tab handling, which WebView2 can then use to give "correct" tab behavior.

The default event loop has been adjusted to do exactly this.

from go-webview2.

jscholes avatar jscholes commented on September 14, 2024

@jchv Thanks, this certainly fixes the case of not being able to Tab/Shift+Tab into the webview once created. But it is still desirable to:

  1. automatically place focus inside the webview when it is the only descendant of the window; and/or
  2. allow users of the library to programmatically set focus inside it.

Additionally, some of the problematic behaviour is still present, specifically:

while I can get focus to reliably move into the browser when the window is initially created, I can't get it to stay there. If I Alt+Tab to another window and then back, focus lands on the window again.

If focus is inside the webview when the user switches away from the window, it should also still be there when they switch back.

from go-webview2.

jchv avatar jchv commented on September 14, 2024

Understood. We can call MoveFocus on WM_ACTIVATE, which would probably accomplish what you are looking for. The change that was added is still useful since it allows us to have focus move from the window to the webview, if, for example, the user were to click the title bar explicitly. I'll take a look at it later today when I am off work and have a moment.

from go-webview2.

jscholes avatar jscholes commented on September 14, 2024

@jchv Thanks, sounds good.

from go-webview2.

jchv avatar jchv commented on September 14, 2024

It might be hard to fully resolve this issue, though at least it's a lot better than it was. I think the keyboard focus behavior should probably simply make sense by default, but for now I have put the new behavior behind an option, AutoFocus, which will cause go-webview2 to attempt to focus the Webview2 widget whenever the window is focused (including on initialization.) This may need to be tweaked as it is definitely not perfect, but I think it is closer.

from go-webview2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.