浏览代码

refine globalkeyEventhandler

/main
xingwei.zhu 5 年前
当前提交
0a7a0c47
共有 4 个文件被更改,包括 66 次插入17 次删除
  1. 14
      Runtime/rendering/editable.cs
  2. 38
      Runtime/service/keyboard.cs
  3. 14
      Runtime/service/text_input.cs
  4. 17
      Runtime/widgets/editable_text.cs

14
Runtime/rendering/editable.cs


bool? enableInteractiveSelection = null,
EdgeInsets floatingCursorAddedMargin = null,
TextSelectionDelegate textSelectionDelegate = null,
Func<RawKeyEvent, bool> globalKeyEventHandler = null) {
GlobalKeyEventHandlerDelegate globalKeyEventHandler = null) {
floatingCursorAddedMargin = floatingCursorAddedMargin ?? EdgeInsets.fromLTRB(4, 4, 4, 5);
D.assert(textSelectionDelegate != null);
D.assert(minLines == null || minLines > 0);

}
public TextSelectionDelegate textSelectionDelegate;
public GlobalKeyEventHandlerDelegate globalKeyEventHandler;
Rect _lastCaretRect;

bool _resetCursor = false;
public Func<RawKeyEvent, bool> globalKeyEventHandler;
if (this.globalKeyEventHandler != null &&
this.globalKeyEventHandler.Invoke(keyEvent)) {
return;
}
if (keyEvent is RawKeyUpEvent) {
return;
}

this._baseOffset = this.selection.baseOffset;
}
if (this.globalKeyEventHandler?.Invoke(keyEvent, false)?.swallow ?? false) {
return;
}
KeyCode pressedKeyCode = keyEvent.data.unityEvent.keyCode;

38
Runtime/service/keyboard.cs


using UnityEngine;
namespace Unity.UIWidgets.service {
public delegate RawInputKeyResponse GlobalKeyEventHandlerDelegate(RawKeyEvent rawEvt, bool enableCustomAction = false);
public class RawInputKeyResponse {
public readonly bool swallow;
public readonly char input;
public readonly TextInputAction? inputAction;
public RawInputKeyResponse(bool swallow, char input = '\0', TextInputAction? inputAction = null) {
this.swallow = swallow;
this.input = input;
this.inputAction = inputAction;
}
public static RawInputKeyResponse convert(RawKeyEvent evt) {
return new RawInputKeyResponse(
false,
evt.data.unityEvent.character,
null);
}
public static readonly RawInputKeyResponse swallowResponse = new RawInputKeyResponse(true, '\0', null);
}
interface KeyboardDelegate: IDisposable {
void show();

var currentEvent = Event.current;
var oldValue = this._value;
if (currentEvent.keyCode == KeyCode.Backspace) {
var response = TextInput._handleGlobalInputKey(this._client,
new RawKeyDownEvent(new RawKeyEventData(currentEvent)));
if (response.swallow) {
if (response.inputAction != null) {
Window.instance.run(() => { TextInput._performAction(this._client, response.inputAction.Value); });
}
if (_validateCharacter(response.input)) {
this._value = this._value.insert(new string(response.input, 1));
}
} else if (currentEvent.keyCode == KeyCode.Backspace) {
if (this._value.selection.isValid) {
this._value = this._value.deleteSelection(true);
}

14
Runtime/service/text_input.cs


void performAction(TextInputAction action);
void updateFloatingCursor(RawFloatingCursorPoint point);
RawInputKeyResponse globalInputKeyHandler(RawKeyEvent evt);
}
public enum TextInputAction {

}
_currentConnection._client.performAction(action);
}
internal static RawInputKeyResponse _handleGlobalInputKey(int client, RawKeyEvent evt) {
if (_currentConnection == null) {
return RawInputKeyResponse.convert(evt);
}
if (client != _currentConnection._id) {
return RawInputKeyResponse.convert(evt);
}
return _currentConnection._client.globalInputKeyHandler(evt);
}
static bool _hidePending = false;

17
Runtime/widgets/editable_text.cs


DragStartBehavior dragStartBehavior = DragStartBehavior.down,
bool? enableInteractiveSelection = null,
ScrollPhysics scrollPhysics = null,
Func<RawKeyEvent, bool> globalCtrlKeyEventHandler = null
GlobalKeyEventHandlerDelegate globalCtrlKeyEventHandler = null
) : base(key) {
D.assert(controller != null);
D.assert(focusNode != null);

public readonly DragStartBehavior dragStartBehavior;
public readonly bool? enableInteractiveSelection;
public readonly ScrollPhysics scrollPhysics;
public readonly Func<RawKeyEvent, bool> globalKeyEventHandler;
public readonly GlobalKeyEventHandlerDelegate globalKeyEventHandler;
public bool selectionEnabled {
get { return this.enableInteractiveSelection ?? !this.obscureText; }

curve: Curves.decelerate);
break;
}
}
public RawInputKeyResponse globalInputKeyHandler(RawKeyEvent evt) {
return this.widget.globalKeyEventHandler?.Invoke(evt, true) ?? RawInputKeyResponse.convert(evt);
}
void _onFloatingCursorResetTick() {

enableInteractiveSelection: this.widget.enableInteractiveSelection == true,
textSelectionDelegate: this,
devicePixelRatio: this._devicePixelRatio,
globalKeyEventHandler: this.widget.globalKeyEventHandler
globalKeyEventHandler : this.widget.globalKeyEventHandler
)
)
);

public readonly TextSelectionDelegate textSelectionDelegate;
public readonly bool? paintCursorAboveText;
public readonly float? devicePixelRatio;
public readonly Func<RawKeyEvent, bool> globalKeyEventHandler;
public readonly GlobalKeyEventHandlerDelegate globalKeyEventHandler;
public _Editable(TextSpan textSpan = null,
TextEditingValue value = null,

bool enableInteractiveSelection = true,
bool? paintCursorAboveText = null,
float? devicePixelRatio = null,
Func<RawKeyEvent, bool> globalKeyEventHandler = null) : base(key) {
GlobalKeyEventHandlerDelegate globalKeyEventHandler = null) : base(key) {
this.textSpan = textSpan;
this.value = value;
this.cursorColor = cursorColor;

textSelectionDelegate: this.textSelectionDelegate,
paintCursorAboveText: this.paintCursorAboveText == true,
devicePixelRatio: this.devicePixelRatio ?? 1.0f,
globalKeyEventHandler: this.globalKeyEventHandler
globalKeyEventHandler : this.globalKeyEventHandler
);
}

正在加载...
取消
保存