ladybird/Libraries/LibWeb/DOM/InputEventsTarget.h
Timothy Flynn 5f0f97b3cc LibWeb: Do not insert "return" key presses into input element values
When the return key is pressed, we try to handle it as a commit action
for input elements. However, we would then go on to actually insert the
return key's code point (U+000D) into the input element. This would be
sanitized out, but would leave the input element in a state where it
thinks it has text to commit. This would result in a change event being
fired when the return key is pressed multiple times in a row.

We were also firing the beforeinput/input events twice for all return
key presses.

To fix this, this patch changes the input event target to signify if it
actually handled the return key. If not (i.e. for textarea elements),
only then do we insert the code point. We also must not fall through to
the generic key handler, to avoid the repeated input events.
2025-03-22 17:27:45 +01:00

45 lines
1.3 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGC/Ptr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Page/EventResult.h>
namespace Web {
class InputEventsTarget {
public:
virtual ~InputEventsTarget() = default;
virtual GC::Ref<JS::Cell> as_cell() = 0;
virtual void handle_insert(String const&) = 0;
virtual EventResult handle_return_key() = 0;
enum class DeleteDirection {
Backward,
Forward,
};
virtual void handle_delete(DeleteDirection) = 0;
virtual void select_all() = 0;
virtual void set_selection_anchor(GC::Ref<DOM::Node>, size_t offset) = 0;
virtual void set_selection_focus(GC::Ref<DOM::Node>, size_t offset) = 0;
enum class CollapseSelection {
No,
Yes,
};
virtual void move_cursor_to_start(CollapseSelection) = 0;
virtual void move_cursor_to_end(CollapseSelection) = 0;
virtual void increment_cursor_position_offset(CollapseSelection) = 0;
virtual void decrement_cursor_position_offset(CollapseSelection) = 0;
virtual void increment_cursor_position_to_next_word(CollapseSelection) = 0;
virtual void decrement_cursor_position_to_previous_word(CollapseSelection) = 0;
};
}