Skip to content

Truly independent web browser

2.3 KB
Raw Blame
/*
 * Copyright (c) 2024, Shannon Booth <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/HTML/FormAssociatedElement.h>

namespace Web::HTML {

// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#validitystate
class ValidityState final : public Bindings::GCAllocatedWrappable {
    WEB_WRAPPABLE(ValidityState, Bindings::GCAllocatedWrappable);
    GC_DECLARE_ALLOCATOR(ValidityState);

public:
    [[nodiscard]] static GC::Ref<ValidityState> create(FormAssociatedElement const&);

    virtual ~ValidityState() override = default;

    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-valuemissing
    bool value_missing() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-typemismatch
    bool type_mismatch() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-patternmismatch
    bool pattern_mismatch() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-toolong
    bool too_long() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-tooshort
    bool too_short() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-rangeunderflow
    bool range_underflow() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-rangeoverflow
    bool range_overflow() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-stepmismatch
    bool step_mismatch() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-badinput
    bool bad_input() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-customerror
    bool custom_error() const;
    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-validitystate-valid
    bool valid() const;

private:
    ValidityState(FormAssociatedElement const&);

    virtual void visit_edges(GC::Cell::Visitor&) override;

    FormAssociatedElement const& m_control;
};

}