Fix bad reference (#3484)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
Amy
2022-11-16 19:15:15 +00:00
committed by GitHub
parent bb137d69a2
commit fac1b2c469
4 changed files with 76 additions and 12 deletions

View File

@@ -143,6 +143,8 @@ namespace Robust.Client.WebView.Cef
private const int ScrollSpeed = 50;
private bool _textInputActive;
private readonly RobustRequestHandler _requestHandler = new(Logger.GetSawmill("root"));
private LiveData? _data;
private string _startUrl = "about:blank";
@@ -360,24 +362,21 @@ namespace Robust.Client.WebView.Cef
return modifiers;
}
public void TextEntered(GUITextEventArgs args)
public void TextEntered(GUITextEnteredEventArgs args)
{
if (_data == null)
return;
var host = _data.Browser.GetHost();
Span<char> buf = stackalloc char[2];
var written = args.AsRune.EncodeToUtf16(buf);
for (var i = 0; i < written; i++)
foreach (var chr in args.Text)
{
host.SendKeyEvent(new CefKeyEvent
{
EventType = CefKeyEventType.Char,
WindowsKeyCode = buf[i],
Character = buf[i],
UnmodifiedCharacter = buf[i]
WindowsKeyCode = chr,
Character = chr,
UnmodifiedCharacter = chr
});
}
}
@@ -481,6 +480,32 @@ namespace Robust.Client.WebView.Cef
_requestHandler.RemoveBeforeBrowseHandler(handler);
}
public void FocusEntered()
{
if (_textInputActive)
_clyde.TextInputStart();
}
public void FocusExited()
{
if (_textInputActive)
_clyde.TextInputStop();
}
public void TextInputStart()
{
_textInputActive = true;
if (Owner.HasKeyboardFocus())
_clyde.TextInputStart();
}
public void TextInputStop()
{
_textInputActive = false;
if (Owner.HasKeyboardFocus())
_clyde.TextInputStop();
}
private sealed class LiveData
{
public OwnedTexture Texture;
@@ -579,6 +604,22 @@ namespace Robust.Client.WebView.Cef
if (_control.Owner.Disposed)
return;
}
protected override void OnVirtualKeyboardRequested(CefBrowser browser, CefTextInputMode inputMode)
{
base.OnVirtualKeyboardRequested(browser, inputMode);
// Treat virtual keyboard requests as a guide for whether we should accept text input.
if (inputMode == CefTextInputMode.None)
{
_control.TextInputStop();
}
else
{
_control.TextInputStart();
}
}
}
}
}

View File

@@ -106,7 +106,7 @@ namespace Robust.Client.WebView.Headless
return false;
}
public void TextEntered(GUITextEventArgs args)
public void TextEntered(GUITextEnteredEventArgs args)
{
}
@@ -125,6 +125,14 @@ namespace Robust.Client.WebView.Headless
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
{
}
public void FocusEntered()
{
}
public void FocusExited()
{
}
}
private sealed class WebViewWindowDummy : DummyBase, IWebViewWindow

View File

@@ -15,10 +15,12 @@ namespace Robust.Client.WebView
void MouseExited();
void MouseWheel(GUIMouseWheelEventArgs args);
bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent);
void TextEntered(GUITextEventArgs args);
void TextEntered(GUITextEnteredEventArgs args);
void Resized();
void Draw(DrawingHandleScreen handle);
void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
void FocusEntered();
void FocusExited();
}
}

View File

@@ -1,7 +1,6 @@
using System;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.WebView.Cef;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
@@ -76,13 +75,27 @@ namespace Robust.Client.WebView
return _controlImpl.RawKeyEvent(guiRawEvent);
}
protected internal override void TextEntered(GUITextEventArgs args)
protected internal override void TextEntered(GUITextEnteredEventArgs args)
{
base.TextEntered(args);
_controlImpl.TextEntered(args);
}
protected internal override void KeyboardFocusEntered()
{
base.KeyboardFocusEntered();
_controlImpl.FocusEntered();
}
protected internal override void KeyboardFocusExited()
{
base.KeyboardFocusExited();
_controlImpl.FocusExited();
}
protected override void Resized()
{
base.Resized();