-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
WPF - Use WpfImeKeyboardHandler for supported KeyboardLayoutIds #4439
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
base: master
Are you sure you want to change the base?
Conversation
✅ Build CefSharp 111.2.20-CI4733 completed (commit 04ba15bbee by @amaitland) |
fb2033a
to
3a34926
Compare
""" WalkthroughThe changes refactor and enhance the way keyboard handlers are managed in the WPF ChromiumWebBrowser component. A new virtual method, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ChromiumWebBrowser
participant WpfKeyboardHandler
participant WpfImeKeyboardHandler
participant InputLanguageManager
User->>ChromiumWebBrowser: Instantiate
ChromiumWebBrowser->>ChromiumWebBrowser: SetupWpfKeyboardHandler()
alt IME language detected
ChromiumWebBrowser->>WpfImeKeyboardHandler: Create instance
else Non-IME language
ChromiumWebBrowser->>WpfKeyboardHandler: Create instance
ChromiumWebBrowser->>InputLanguageManager: Subscribe InputLanguageChanged
end
InputLanguageManager-->>ChromiumWebBrowser: InputLanguageChanged event
ChromiumWebBrowser->>ChromiumWebBrowser: OnInputLangageChanged()
alt Switch to IME required
ChromiumWebBrowser->>WpfImeKeyboardHandler: Create new instance
ChromiumWebBrowser->>WpfKeyboardHandler: Dispose old handler
ChromiumWebBrowser->>InputLanguageManager: Unsubscribe InputLanguageChanged
end
User->>ChromiumWebBrowser: Dispose
ChromiumWebBrowser->>ChromiumWebBrowser: UnsubsribeInputLanguageChanged()
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
CefSharp.Wpf/Experimental/WpfIMEKeyboardHandler.cs (1)
470-489
: Well-designed IME detection method with clear documentationThis new method properly encapsulates the logic for determining whether to use the IME keyboard handler based on the keyboard layout ID. The method checks if the layout corresponds to Korean, Japanese, or Chinese languages which require IME support.
The XML documentation is clear and well-structured, though the
<see cref="System.Globalization.CultureInfo.KeyboardLayoutId"/>
reference should specify it's related to the parameter.-/// <param name="keyboardLayoutId">Keyboard Layout Id (obtained from <see cref="System.Globalization.CultureInfo.KeyboardLayoutId"/></param> +/// <param name="keyboardLayoutId">Keyboard Layout Id (obtained from <see cref="System.Globalization.CultureInfo.KeyboardLayoutId"/>)</param>CefSharp.Wpf/ChromiumWebBrowser.cs (3)
780-816
: Well-implemented keyboard handler setup with proper error handlingThis new method determines the appropriate keyboard handler based on the current input language, using the
WpfImeKeyboardHandler
for supported languages (Korean, Japanese, Chinese) and the default handler for others. The error handling is appropriate, falling back to the default handler if an exception occurs.However, there's an issue with the error message.
- Trace.TraceError($"Error unsubscribing from InputLanguageChanged {ex.ToString()}"); + Trace.TraceError($"Error initializing keyboard handler: {ex.ToString()}");The error message incorrectly indicates it's unsubscribing from InputLanguageChanged when it's actually in the setup method.
1799-1817
: Good implementation of input language change handlerThis method appropriately handles input language changes by checking if the new language requires the IME keyboard handler and switching handlers as needed. It also properly disposes of the old handler and unsubscribes from the event when switching to the IME handler.
There's a minor typo in the method name that should be fixed.
-private void OnInputLangageChanged(object sender, InputLanguageEventArgs e) +private void OnInputLanguageChanged(object sender, InputLanguageEventArgs e)Make sure to update all references to this method name elsewhere in the code.
2928-2956
: Good implementation of event unsubscription with UI thread safetyThis method safely unsubscribes from the input language change event, properly handling the fact that it might be called from a non-UI thread. The error handling is appropriate, capturing and logging any exceptions that might occur during unsubscription.
There's a typo in the method name that should be fixed.
-private void UnsubsribeInputLanguageChanged() +private void UnsubscribeInputLanguageChanged()Make sure to update all calls to this method elsewhere in the code.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CefSharp.Wpf/ChromiumWebBrowser.cs
(6 hunks)CefSharp.Wpf/Experimental/WpfIMEKeyboardHandler.cs
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
CefSharp.Wpf/Experimental/WpfIMEKeyboardHandler.cs (1)
CefSharp.Wpf/Internals/ImeNative.cs (1)
ImeNative
(10-133)
🔇 Additional comments (5)
CefSharp.Wpf/Experimental/WpfIMEKeyboardHandler.cs (1)
357-360
: Good refactoring to make PrimaryLangId staticMaking this method static is appropriate since it doesn't depend on instance state, improving reusability.
CefSharp.Wpf/ChromiumWebBrowser.cs (4)
6-6
: Adding System.Diagnostics namespace for error tracingAppropriate addition of System.Diagnostics namespace for using Trace.TraceError in the error handling code.
608-614
: Improved keyboard handler initializationThe code now calls the new
SetupWpfKeyboardHandler
method first, then falls back to the defaultWpfKeyboardHandler
only if needed. This allows for dynamic selection of the appropriate keyboard handler based on the current input language.
762-762
: Good cleanup of language event handlersAdding the call to
UnsubsribeInputLanguageChanged
during disposal ensures proper cleanup of event handlers, preventing memory leaks.
2942-2949
: Good thread safety with UI thread dispatchingThe code correctly uses
UiThreadRunAsync
to ensure the event handler is unsubscribed on the UI thread, which is necessary sinceInputLanguageManager.Current
is thread-specific.
❌ Build CefSharp 135.0.170-CI5222 failed (commit af9f9e4b48 by @amaitland) |
✅ Actions performedReviews resumed. |
1 similar comment
✅ Actions performedReviews resumed. |
Fixes: #1262
Summary:
Changes:
CurrentInputLanguage
How Has This Been Tested?
Minimal Testing, requires user feedback
Types of changes
Checklist:
Summary by CodeRabbit