Exemple #1
0
        void _handleMethodCall(string method, List <JSONNode> args)
        {
            if (TextInput._currentConnection == null)
            {
                return;
            }
            int client = args[0].AsInt;

            if (client != TextInput._currentConnection._id)
            {
                return;
            }

            using (TextInput._currentConnection._window.getScope()) {
                switch (method)
                {
                case "TextInputClient.updateEditingState":
                    TextInput._updateEditingState(client, TextEditingValue.fromJson(args[1].AsObject));
                    break;

                case "TextInputClient.performAction":
                    TextInput._performAction(client, TextInputUtils._toTextInputAction(args[1].Value));
                    break;

                default:
                    throw new UIWidgetsError($"unknown method ${method}");
                }
            }
        }
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (this._client == 0)
            {
                return;
            }


            var currentEvent = Event.current;
            var oldValue     = this._value;

            if (currentEvent != null && currentEvent.type == EventType.KeyDown)
            {
                if (currentEvent.keyCode == KeyCode.Backspace)
                {
                    if (this._value.selection.isValid)
                    {
                        this._value = this._value.deleteSelection(true);
                    }
                }
                else if (currentEvent.character != '\0')
                {
                    this._value = this._value.clearCompose();
                    char ch = currentEvent.character;
                    if (ch == '\r' || ch == 3)
                    {
                        ch = '\n';
                    }

                    if (ch == '\n')
                    {
                        Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); });
                    }

                    if (_validateCharacter(ch))
                    {
                        this._value = this._value.insert(new string(ch, 1));
                    }
                }
                else if (!string.IsNullOrEmpty(Input.compositionString))
                {
                    this._value = this._value.compose(Input.compositionString);
                }

                currentEvent.Use();
            }

            if (this._value != oldValue)
            {
                Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
            }
        }
Exemple #3
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (this._client == 0)
            {
                return;
            }

            var currentEvent = Event.current;


            if (currentEvent != null && currentEvent.type == EventType.KeyDown)
            {
                var action = TextInputUtils.getInputAction(currentEvent);
                if (action != null)
                {
                    Window.instance.run(() => { TextInput._performAction(this._client, action.Value); });
                }

                if (action == null || action == TextInputAction.newline)
                {
                    if (currentEvent.keyCode == KeyCode.None)
                    {
                        char ch = currentEvent.character;
                        if (ch == '\r' || ch == 3)
                        {
                            ch = '\n';
                        }
                        this._value = this._value.clearCompose();
                        if (_validateCharacter(ch))
                        {
                            this._value = this._value.insert(new string(ch, 1));
                        }
                        Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
                    }
                }

                currentEvent.Use();
            }

            if (!string.IsNullOrEmpty(Input.compositionString) &&
                this._lastCompositionString != Input.compositionString)
            {
                this._value = this._value.compose(Input.compositionString);
                Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
            }

            this._lastCompositionString = Input.compositionString;
        }
Exemple #4
0
        public void Update()
        {
            if (this._client == 0 || this._keyboard == null)
            {
                return;
            }

            if (this._keyboard.canSetSelection && this._pendingSelection != null)
            {
                this._keyboard.selection = this._pendingSelection.Value;
                this._pendingSelection   = null;
            }

            if (this._keyboard.status == TouchScreenKeyboard.Status.Done)
            {
                if (!this._screenKeyboardDone)
                {
                    this._screenKeyboardDone = true;
                    Window.instance.run(() => {
                        TextInput._performAction(this._client,
                                                 TextInputAction.done);
                    });
                }
            }
            else if (this._keyboard.status == TouchScreenKeyboard.Status.Visible)
            {
                var keyboardSelection = this._keyboard.selection;
                var newValue          = new TextEditingValue(
                    this._keyboard.text,
                    this._keyboard.canGetSelection
                        ? new TextSelection(keyboardSelection.start, keyboardSelection.end)
                        : TextSelection.collapsed(0)
                    );
                var changed = this._value != newValue;

                this._value = newValue;
                if (changed)
                {
                    Window.instance.run(() => {
                        TextInput._updateEditingState(this._client,
                                                      this._value);
                    });
                }
            }
        }
Exemple #5
0
        public void Update()
        {
            if (_client == 0 || _keyboard == null)
            {
                return;
            }

            if (_keyboard.canSetSelection && _pendingSelection != null)
            {
                _keyboard.selection = _pendingSelection.Value;
                _pendingSelection   = null;
            }

            if (_keyboard.status == TouchScreenKeyboard.Status.Done)
            {
                if (!_screenKeyboardDone)
                {
                    _screenKeyboardDone = true;
                    Timer.create(TimeSpan.Zero, () => {
                        TextInput._performAction(_client,
                                                 TextInputAction.done);
                    });
                }
            }
            else if (_keyboard.status == TouchScreenKeyboard.Status.Visible)
            {
                var keyboardSelection = _keyboard.selection;
                var newValue          = new TextEditingValue(
                    _keyboard.text,
                    _keyboard.canGetSelection
                        ? new TextSelection(keyboardSelection.start, keyboardSelection.end)
                        : TextSelection.collapsed(0)
                    );
                var changed = _value != newValue;

                _value = newValue;
                if (changed)
                {
                    Timer.create(TimeSpan.Zero, () => {
                        TextInput._updateEditingState(_client,
                                                      _value);
                    });
                }
            }
        }
Exemple #6
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (_client == 0)
            {
                return;
            }


            while (!PointerEventConverter.KeyEvent.isEmpty())
            {
                var currentEvent = PointerEventConverter.KeyEvent.Dequeue();
                var oldValue     = _value;

                if (currentEvent != null && currentEvent.type == EventType.KeyDown)
                {
                    var response = TextInput._handleGlobalInputKey(_client,
                                                                   new RawKeyDownEvent(new RawKeyEventData(currentEvent)));

                    if (response.swallow)
                    {
                        if (response.inputAction != null)
                        {
                            Timer.create(TimeSpan.Zero,
                                         () => { TextInput._performAction(_client, response.inputAction.Value); });
                        }

                        if (_validateCharacter(response.input))
                        {
                            _value = _value.insert(new string(response.input, 1));
                        }
                    }
                    else if (currentEvent.keyCode == KeyCode.Backspace)
                    {
                        if (_value.selection.isValid)
                        {
                            _value = _value.deleteSelection(true);
                        }
                    }
                    else if (currentEvent.character != 0)
                    {
                        _value = _value.clearCompose();
                        char ch = currentEvent.character;
                        if (ch == '\r' || ch == 3)
                        {
                            ch = '\n';
                        }

                        if (ch == '\n')
                        {
                            Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client,
                                                                                         _textInputConfiguration?.inputAction ?? TextInputAction.newline); });
                        }

                        if (_validateCharacter(ch))
                        {
                            _value = _value.insert(new string(ch, 1));
                        }
                    }
                    else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString()))
                    {
                        isIMEInput = true;
                        _value     = _value.compose(currentEvent.keyCode.ToString());
                    }

                    currentEvent.Use();
                }

                if (_value != oldValue)
                {
                    if (this.isIMEInput)
                    {
                        var isIMEInput = this.isIMEInput;
                        Timer.create(TimeSpan.Zero,
                                     () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                        this.isIMEInput = false;
                    }
                    else
                    {
                        Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                    }
                }
            }
        }
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (this._client == 0)
            {
                return;
            }


            var currentEvent = Event.current;
            var oldValue     = this._value;

            if (currentEvent != null && currentEvent.type == EventType.KeyDown)
            {
                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);
                    }
                }
                else if (currentEvent.character != '\0')
                {
                    this._value = this._value.clearCompose();
                    char ch = currentEvent.character;
                    if (ch == '\r' || ch == 3)
                    {
                        ch = '\n';
                    }

                    if (ch == '\n')
                    {
                        Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); });
                    }

                    if (_validateCharacter(ch))
                    {
                        this._value = this._value.insert(new string(ch, 1));
                    }
                }
                else if (!string.IsNullOrEmpty(Input.compositionString))
                {
                    this.isIMEInput = true;
                    this._value     = this._value.compose(Input.compositionString);
                }

                currentEvent.Use();
            }

            if (this._value != oldValue)
            {
                if (this.isIMEInput)
                {
                    var isIMEInput = this.isIMEInput;
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value, isIMEInput); });
                    this.isIMEInput = false;
                }
                else
                {
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
                }
            }
        }