Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/HTML/FormAssociatedElement.h (C/C++)

Code before:
    void form_node_attribute_changed(FlyString const&, Optional<String> const&);

private:
    void reset_form_owner();

    WeakPtr<HTMLFormElement> m_form;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#parser-inserted-flag
    bool m_parser_inserted { false };

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#custom-validity-error-message
    String m_custom_validity_error_message;
};

enum class SelectionSource {
    UI,
    DOM,
};

class FormAssociatedTextControlElement
    : public FormAssociatedElement
    , public InputEventsTarget {
public:
    struct PositionInLine {
        int previous_newline_index = 0;
        int column_code_point = 0;
    };

    PositionInLine find_cursor_position_in_line(size_t offset);

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-relevant-value
    virtual Utf16String relevant_value() = 0;
    virtual WebIDL::ExceptionOr<void> set_relevant_value(Utf16String const&) = 0;

    virtual void set_dirty_value_flag(bool flag) = 0;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-select
    WebIDL::ExceptionOr<void> select();

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
    Optional<WebIDL::UnsignedLong> selection_start_binding() const;
    WebIDL::ExceptionOr<void> set_selection_start_binding(Optional<WebIDL::UnsignedLong> const&);
    WebIDL::UnsignedLong selection_start() const;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionend
    Optional<WebIDL::UnsignedLong> selection_end_binding() const;
    WebIDL::ExceptionOr<void> set_selection_end_binding(Optional<WebIDL::UnsignedLong> const&);
    WebIDL::UnsignedLong selection_end() const;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectiondirection
    Optional<String> selection_direction() const;

Review comment (suggestion):
Can these ever be negative? If not, let's use size_t
(we also use brace initialization for struct members:)
```c++
struct PositionInLine {
    size_t previous_newline_index { 0 };
    size_t column_code_point { 0 };
};
```

Code after:
    void form_node_attribute_changed(FlyString const&, Optional<String> const&);

private:
    void reset_form_owner();

    WeakPtr<HTMLFormElement> m_form;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#parser-inserted-flag
    bool m_parser_inserted { false };

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#custom-validity-error-message
    String m_custom_validity_error_message;
};

enum class SelectionSource {
    UI,
    DOM,
};

class FormAssociatedTextControlElement
    : public FormAssociatedElement
    , public InputEventsTarget {
public:
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-relevant-value
    virtual Utf16String relevant_value() = 0;
    virtual WebIDL::ExceptionOr<void> set_relevant_value(Utf16String const&) = 0;

    virtual void set_dirty_value_flag(bool flag) = 0;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-select
    WebIDL::ExceptionOr<void> select();

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
    Optional<WebIDL::UnsignedLong> selection_start_binding() const;
    WebIDL::ExceptionOr<void> set_selection_start_binding(Optional<WebIDL::UnsignedLong> const&);
    WebIDL::UnsignedLong selection_start() const;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionend
    Optional<WebIDL::UnsignedLong> selection_end_binding() const;
    WebIDL::ExceptionOr<void> set_selection_end_binding(Optional<WebIDL::UnsignedLong> const&);
    WebIDL::UnsignedLong selection_end() const;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectiondirection
    Optional<String> selection_direction() const;
    void set_selection_direction(Optional<String> direction);
    WebIDL::ExceptionOr<void> set_selection_direction_binding(Optional<String> direction);
    SelectionDirection selection_direction_state() const { return m_selection_direction; }

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-setrangetext
    WebIDL::ExceptionOr<void> set_range_text_binding(Utf16String const& replacement);
    WebIDL::ExceptionOr<void> set_range_text_binding(Utf16String const& replacement, WebIDL::UnsignedLong start, WebIDL::UnsignedLong end, Bindings::SelectionMode = Bindings::SelectionMode::Preserve);