Browse Source

Revert 15603, add InputPaneActivationRequested in TextInputMethodClient (#19225)

* revert 15603, add InputPaneActivationRequested in TextInputMethodClient

* forward ShowInputPanel call to RaiseInputPaneActivationRequested
pull/19245/head
Emmanuel Hansen 7 months ago
committed by GitHub
parent
commit
01e09e4f98
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 17
      src/Android/Avalonia.Android/Platform/Input/AndroidInputMethod.cs
  2. 17
      src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs
  3. 2
      src/Avalonia.Controls/TextBox.cs
  4. 24
      src/Avalonia.Controls/TextBoxTextInputMethodClient.cs
  5. 19
      src/Browser/Avalonia.Browser/BrowserTextInputMethod.cs
  6. 8
      src/Tizen/Avalonia.Tizen/NuiAvaloniaViewTextEditable.cs

17
src/Android/Avalonia.Android/Platform/Input/AndroidInputMethod.cs

@ -72,6 +72,13 @@ namespace Avalonia.Android.Platform.Input
public void SetClient(TextInputMethodClient? client)
{
if(_client != null)
{
_client.SurroundingTextChanged -= _client_SurroundingTextChanged;
_client.SelectionChanged -= _client_SelectionChanged;
_client.InputPaneActivationRequested -= _client_InputPaneActivationRequested;
}
_client = client;
if (IsActive)
@ -86,16 +93,24 @@ namespace Avalonia.Android.Platform.Input
_client.SurroundingTextChanged += _client_SurroundingTextChanged;
_client.SelectionChanged += _client_SelectionChanged;
_client.InputPaneActivationRequested += _client_InputPaneActivationRequested;
}
else
{
_host.ClearFocus();
_imm.RestartInput(View);
_inputConnection = null;
_imm.HideSoftInputFromWindow(_host.WindowToken, HideSoftInputFlags.ImplicitOnly);
}
}
private void _client_InputPaneActivationRequested(object? sender, EventArgs e)
{
if(IsActive)
{
_imm.ShowSoftInput(_host, ShowFlags.Implicit);
}
}
private void _client_SelectionChanged(object? sender, EventArgs e)
{
if (_inputConnection is null || _inputConnection.IsInBatchEdit || _inputConnection.IsInUpdate)

17
src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs

@ -28,6 +28,11 @@ namespace Avalonia.Input.TextInput
/// Fires when client wants to reset IME state
/// </summary>
public event EventHandler? ResetRequested;
/// <summary>
/// Fires when client requests the input panel be opened.
/// </summary>
public event EventHandler? InputPaneActivationRequested;
/// <summary>
/// The visual that's showing the text
@ -78,7 +83,12 @@ namespace Avalonia.Input.TextInput
SetPreeditText(preeditText);
}
public virtual void ShowInputPanel() { }
//TODO12: remove
[Obsolete]
public virtual void ShowInputPanel()
{
RaiseInputPaneActivationRequested();
}
protected virtual void RaiseTextViewVisualChanged()
{
@ -99,6 +109,11 @@ namespace Avalonia.Input.TextInput
{
SelectionChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void RaiseInputPaneActivationRequested()
{
InputPaneActivationRequested?.Invoke(this, EventArgs.Empty);
}
protected virtual void RequestReset()
{

2
src/Avalonia.Controls/TextBox.cs

@ -1791,8 +1791,6 @@ namespace Avalonia.Controls
if (e.Pointer.Type != PointerType.Mouse && !_isDoubleTapped)
{
_imClient.ShowInputPanel();
var text = Text;
var clickInfo = e.GetCurrentPoint(this);
if (text != null && !(clickInfo.Pointer?.Captured is Border))

24
src/Avalonia.Controls/TextBoxTextInputMethodClient.cs

@ -13,7 +13,6 @@ namespace Avalonia.Controls
private TextPresenter? _presenter;
private bool _selectionChanged;
private bool _isInChange;
private ITextInputMethodImpl? _im;
public override Visual TextViewVisual => _presenter!;
@ -119,6 +118,7 @@ namespace Avalonia.Controls
if (_parent != null)
{
_parent.PropertyChanged -= OnParentPropertyChanged;
_parent.Tapped -= OnParentTapped;
}
_parent = parent;
@ -126,11 +126,7 @@ namespace Avalonia.Controls
if (_parent != null)
{
_parent.PropertyChanged += OnParentPropertyChanged;
_im = (_parent.VisualRoot as ITextInputMethodRoot)?.InputMethod;
}
else
{
_im = null;
_parent.Tapped += OnParentTapped;
}
var oldPresenter = _presenter;
@ -154,6 +150,11 @@ namespace Avalonia.Controls
RaiseCursorRectangleChanged();
}
private void OnParentTapped(object? sender, Input.TappedEventArgs e)
{
RaiseInputPaneActivationRequested();
}
public override void SetPreeditText(string? preeditText) => SetPreeditText(preeditText, null);
public override void SetPreeditText(string? preeditText, int? cursorPos)
@ -167,17 +168,6 @@ namespace Avalonia.Controls
_presenter.SetCurrentValue(TextPresenter.PreeditTextCursorPositionProperty, cursorPos);
}
public override void ShowInputPanel()
{
base.ShowInputPanel();
if (_parent is { } && _im is { })
{
_im.SetOptions(TextInputOptions.FromStyledElement(_parent));
_im.SetClient(this);
}
}
private static string GetTextLineText(TextLine textLine)
{
if (textLine.Length == 0)

19
src/Browser/Avalonia.Browser/BrowserTextInputMethod.cs

@ -29,11 +29,13 @@ internal class BrowserTextInputMethod(
if (_client != null)
{
_client.SurroundingTextChanged -= SurroundingTextChanged;
_client.InputPaneActivationRequested -= InputPaneActivationRequested;
}
if (client != null)
{
client.SurroundingTextChanged += SurroundingTextChanged;
client.InputPaneActivationRequested += InputPaneActivationRequested;
}
InputHelper.ClearInputElement(_inputElement);
@ -42,8 +44,7 @@ internal class BrowserTextInputMethod(
if (_client != null)
{
InputHelper.ShowElement(_inputElement);
InputHelper.FocusElement(_inputElement);
ShowIme();
var surroundingText = _client.SurroundingText ?? "";
var selection = _client.Selection;
@ -56,6 +57,20 @@ internal class BrowserTextInputMethod(
}
}
private void InputPaneActivationRequested(object? sender, EventArgs e)
{
if (_client != null)
{
ShowIme();
}
}
private void ShowIme()
{
InputHelper.ShowElement(_inputElement);
InputHelper.FocusElement(_inputElement);
}
private void SurroundingTextChanged(object? sender, EventArgs e)
{
if (_client != null)

8
src/Tizen/Avalonia.Tizen/NuiAvaloniaViewTextEditable.cs

@ -118,6 +118,7 @@ internal class NuiAvaloniaViewTextEditable
client.TextViewVisualChanged += OnTextViewVisualChanged;
client.SurroundingTextChanged += OnSurroundingTextChanged;
client.SelectionChanged += OnClientSelectionChanged;
client.InputPaneActivationRequested += OnInputPaneActivationRequested;
TextInput.SelectWholeText();
OnClientSelectionChanged(this, EventArgs.Empty);
@ -125,6 +126,12 @@ internal class NuiAvaloniaViewTextEditable
finally { _updating = false; }
}
private void OnInputPaneActivationRequested(object? sender, EventArgs e)
{
var inputContext = TextInput.GetInputMethodContext();
inputContext.ShowInputPanel();
}
private void OnClientSelectionChanged(object? sender, EventArgs e) => InvokeUpdate(client =>
{
if (client.Selection.End == 0 || client.Selection.Start == client.Selection.End)
@ -152,6 +159,7 @@ internal class NuiAvaloniaViewTextEditable
_client!.TextViewVisualChanged -= OnTextViewVisualChanged;
_client!.SurroundingTextChanged -= OnSurroundingTextChanged;
_client!.SelectionChanged -= OnClientSelectionChanged;
_client!.InputPaneActivationRequested -= OnInputPaneActivationRequested;
}
if (Window.Instance.GetDefaultLayer().Children.Contains((View)TextInput))

Loading…
Cancel
Save