From f46ef07c53263f7a3c23feb4faebe423703f3e37 Mon Sep 17 00:00:00 2001 From: "SmileSky (mzdk100)" Date: Tue, 14 Jan 2025 16:50:30 +0800 Subject: [PATCH 1/2] fix: Fix the issue where TAB cannot cycle through focus elements. Signed-off-by: SmileSky --- .changes/element-focus.md | 5 +++++ src/webview2/mod.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changes/element-focus.md diff --git a/.changes/element-focus.md b/.changes/element-focus.md new file mode 100644 index 000000000..ec8200fab --- /dev/null +++ b/.changes/element-focus.md @@ -0,0 +1,5 @@ +--- +'wry': 'patch:enhance' +--- + +Allow the use of TAB to cycle through focus elements in an HTML document. \ No newline at end of file diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index ca4bb96c7..1767497db 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -176,6 +176,16 @@ impl InnerWebView { wparam: WPARAM, lparam: LPARAM, ) -> LRESULT { + if msg == WM_SETFOCUS { + // Fix https://github.com/DioxusLabs/dioxus/issues/2900 + // Get the first child window of the window + let child = GetWindow(hwnd, GW_CHILD).unwrap_or_default(); + if child != HWND::default() { + // Set focus to the child window(WebView document) + let _ = SetFocus(child); + } + } + DefWindowProcW(hwnd, msg, wparam, lparam) } From 46621fc5d51e4330079959bb0ed46616e5ac3da6 Mon Sep 17 00:00:00 2001 From: SmileSky Date: Tue, 14 Jan 2025 18:05:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20Fix=20errors=20and=20warnings?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SmileSky --- src/webview2/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index bf0691380..dcc338ae3 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -179,8 +179,8 @@ impl InnerWebView { if msg == WM_SETFOCUS { // Fix https://github.com/DioxusLabs/dioxus/issues/2900 // Get the first child window of the window - let child = GetWindow(hwnd, GW_CHILD).unwrap_or_default(); - if child != HWND::default() { + let child = GetWindow(hwnd, GW_CHILD).ok(); + if child.is_some() { // Set focus to the child window(WebView document) let _ = SetFocus(child); } @@ -1681,14 +1681,19 @@ unsafe fn set_background_color( controller: &ICoreWebView2Controller, background_color: RGBA, ) -> Result<()> { - let (R, G, B, mut A) = background_color; - if is_windows_7() || A != 0 { - A = 255; + let (r, g, b, mut a) = background_color; + if is_windows_7() || a != 0 { + a = 255; } let controller2: ICoreWebView2Controller2 = controller.cast()?; controller2 - .SetDefaultBackgroundColor(COREWEBVIEW2_COLOR { R, G, B, A }) + .SetDefaultBackgroundColor(COREWEBVIEW2_COLOR { + R: r, + G: g, + B: b, + A: a, + }) .map_err(Into::into) }