Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ DOM layer.

## Deferred surface

`reportValidity()` deliberately adds no native validation bubble or focus
movement. Selector reads and subject recascade are live, but this slice adds no
WebScene #708 adds interactive `reportValidity()` focus and feedback and uses
the retained validation anchor for both direct and form-level reports.
Selector reads and subject recascade are live, but this slice adds no
descendant-driven structural recascade for a form or fieldset whose aggregate
validity changed. Label association, ARIA reflection, `CustomStateSet`,
`HTMLFormElement.elements` integration, and a persisted session-history or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ custom error while `willValidate` is false; its validation message is empty and
its validation methods return true.

Both validation methods dispatch `invalid` at an invalid validation candidate.
The event is cancelable and does not bubble. `reportValidity()` currently has
the same observable dispatch and result as `checkValidity()` because native
validation UI is outside this slice.
The event is cancelable and does not bubble. WebScene #708 extends
`reportValidity()` with the bounded interactive behavior described in
`interactive-constraint-validation-20260919.md`; `checkValidity()` remains a
noninteractive validity query.

## State and invalidation bound

Expand All @@ -42,8 +43,8 @@ owns the native companion for prototype placement, wrapper identity and
liveness, flag projection, custom-error selector changes, event dispatch, and
barred-control behavior.

Form and fieldset aggregation, submission-time validation, interactive native
validation UI, `datetime-local`, file-input value-missing state, and the UI-only
Form and fieldset aggregation, submission-time validation, `datetime-local`,
file-input value-missing state, and the UI-only
bad-input and user-edited length transitions remain separate work.

Per task direction, no build, generated-binding check, native test, browser/WPT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ and form/fieldset elements never match `:user-valid` or `:user-invalid`.
`HTMLFormElement.checkValidity()` and `reportValidity()` statically validate all
owned candidates in tree order. Every invalid candidate receives the existing
cancelable, non-bubbling `invalid` event, and either method returns false when
any candidate was invalid. `reportValidity()` deliberately adds no native
validation UI in this slice.
any candidate was invalid. WebScene #708 subsequently adds bounded interactive
feedback to `reportValidity()` while leaving submit-attempt validation on this
noninteractive path.

Submit-button and implicit submission now set user validity on each owned
input, select, and textarea before validation. A failing validation dispatches
Expand Down
46 changes: 46 additions & 0 deletions docs/validation/interactive-constraint-validation-20260919.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Interactive constraint-validation source contract

## Implemented boundary

WebScene #708 makes `reportValidity()` interactive without changing
`checkValidity()` or submit-attempt validation. Form reports snapshot invalid
candidates in existing tree/form-owner order, dispatch one cancelable,
non-bubbling `invalid` event to every candidate, and choose the first
uncanceled candidate that remains connected and focusable after dispatch.
Control reports apply the same cancelation rule. A form-associated custom
element retains its validated descendant anchor so direct and form reports
focus and position feedback against the same element.

The selected target receives focus once. The document then owns at most one
validation message: a 1 KiB UTF-8-bounded string plus target and anchor IDs in
the document's existing lazy auxiliary allocation. The scene appends a clipped
overlay through existing retained rectangle, border, clip, and text commands;
it creates no author DOM and needs no presenter ABI. Normal scene publication
recomputes geometry from the current anchor, so layout, scrolling, and viewport
changes reposition feedback without timers, sustained frames, selector
matching, cascade, or visual-tree mutation.

The same bounded message produces one newest-wins assertive semantic live
event through the existing semantic ABI. It is consumed once and respects the
existing live-event count bound. Text content is not written to diagnostics.

## Lifetime and dismissal

Input or change on the target, custom-validity mutation, successful or repeated
interactive validation, focus transfer away from the target/anchor, target or
anchor subtree detachment, navigation, and teardown dismiss the retained
message. Navigation also retires any unconsumed semantic announcement. Stale
native IDs fail closed during scene construction, and a candidate removed by
an earlier `invalid` handler is skipped when focus is selected.

## Validation status and deferred boundary

The behavior follows the HTML interactive constraint-validation ordering and
cancelation model and reuses WebScene's existing focus, scene, and semantic
contracts. Per task direction, no build, native test, browser/WPT run, pixel
check, package gate, or CI job was run. Only `git diff --check` is used for this
commit, so the authored contract remains unexecuted source evidence.

Rich multi-line bubble layout, user-agent localization beyond the existing
validation messages, timed auto-dismissal, and structural selector
invalidation remain outside #708.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <limits>
#include <memory>
#include <memory_resource>
#include <optional>
#include <span>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -1458,6 +1459,7 @@ struct dom_node final {
struct form_control_data final {
std::string value;
std::string custom_validation_message;
uint32_t validation_anchor_id{0};
uint16_t element_internals_validity_flags{0};
size_t selection_start{0};
size_t selection_end{0};
Expand Down Expand Up @@ -2145,6 +2147,11 @@ class native_document final {
bool is_modal_dialog(const dom_node& node) const noexcept;
bool is_in_modal_layer(const dom_node& node) const noexcept;
bool is_inert(const dom_node& node) const noexcept;
void show_validation_message(
const dom_node& target, const dom_node& anchor, std::string message);
bool clear_validation_message() noexcept;
uint32_t validation_message_target_id() const noexcept;
uint32_t validation_message_anchor_id() const noexcept;
dom_node* hit_test(dom_node& root, float x, float y);
void clear();
void layout(float viewport_width, float viewport_height);
Expand Down Expand Up @@ -2582,9 +2589,18 @@ class native_document final {
// ever-growing pointer table.
std::vector<dom_node*> native_id_index_;
struct modal_dialog_entry final { uint32_t scope_id; uint32_t dialog_id; };
struct validation_message_state final {
uint32_t target_id{};
uint32_t anchor_id{};
std::string message;
};
// Most documents never open a modal. Keep the container allocation lazy
// and its implementation-specific vector footprint out of every document.
struct auxiliary_nodes { std::vector<modal_dialog_entry> dialogs; std::vector<dom_node*> media; };
struct auxiliary_nodes {
std::vector<modal_dialog_entry> dialogs;
std::vector<dom_node*> media;
std::optional<validation_message_state> validation_message;
};
std::unique_ptr<auxiliary_nodes> auxiliary_nodes_;
std::span<const modal_dialog_entry> modal_dialogs() const noexcept {
return auxiliary_nodes_ ? std::span<const modal_dialog_entry>(auxiliary_nodes_->dialogs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,59 @@ void native_document::build_scene(
append_scene(*modal, commands, strings, string_bytes, hidden,
false, false, nullptr, nullptr, ordered_canvas, true, capture_gpu_outputs);
}
// Interactive constraint feedback is engine-owned and therefore never
// enters the author DOM. Emit one retained overlay after all author and
// modal content. Its geometry is recomputed only when a scene is already
// being published, so scrolling/layout naturally repositions it without
// animation-frame demand or another cascade pass.
if (auxiliary_nodes_ && auxiliary_nodes_->validation_message) {
const auto& state = *auxiliary_nodes_->validation_message;
const auto* anchor = state.anchor_id == 0U
|| state.anchor_id > native_id_index_.size()
? nullptr : native_id_index_[state.anchor_id - 1U];
const auto* target = state.target_id == 0U
|| state.target_id > native_id_index_.size()
? nullptr : native_id_index_[state.target_id - 1U];
if (anchor != nullptr && target != nullptr
&& is_connected(*anchor) && is_connected(*target)
&& viewport_width_ > 0.0F && viewport_height_ > 0.0F) {
constexpr float padding = 9.0F;
constexpr float font_size = 13.0F;
constexpr float line_height = 18.0F;
constexpr float bubble_height = line_height + padding * 2.0F;
const auto text_width = measure_text_width(state.message, font_size);
const auto bubble_width = std::clamp(
text_width + padding * 2.0F,
std::min(160.0F, viewport_width_),
std::min(360.0F, viewport_width_));
const auto x = std::clamp(
anchor->layout.x, 0.0F, std::max(0.0F, viewport_width_ - bubble_width));
const auto below = anchor->layout.y + anchor->layout.height + 6.0F;
const auto above = anchor->layout.y - bubble_height - 6.0F;
const auto y = below + bubble_height <= viewport_height_
? below : std::max(0.0F, above);
commands.push_back(webscene_scene_command{
10U, 0U, x, y, bubble_width, bubble_height,
0x202124F2U, anchor->id, 5, 5, 5, 5, 0});
commands.push_back(webscene_scene_command{
11U, 0U, x, y, bubble_width, bubble_height,
0xFFFFFFFFU, anchor->id, 5, 5, 5, 5, 1});
commands.push_back(webscene_scene_command{
12U, 0U, x + padding, y + padding,
std::max(0.0F, bubble_width - padding * 2.0F), line_height,
0U, anchor->id});
const auto resource = std::to_string(font_size) + '\t'
+ std::to_string(line_height) + "\t600\tstart\tsans-serif\tauto\t"
+ state.message;
commands.push_back(webscene_scene_command{
3U, append_scene_string(resource, strings, string_bytes),
x + padding, y + padding,
std::max(0.0F, bubble_width - padding * 2.0F), line_height,
0xFFFFFFFFU, anchor->id, 0, 0, 0, 0, 0});
commands.push_back(webscene_scene_command{
13U, 0U, 0, 0, 0, 0, 0U, anchor->id});
}
}
}

void native_document::publish_gpu_canvas_image(dom_node& node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,51 @@ void native_document::clear()
body_->style.background_rgba = 0x131722FFU;
mark_dirty();
}

void native_document::show_validation_message(
const dom_node& target, const dom_node& anchor, std::string message)
{
constexpr size_t maximum_message_bytes = 1024U;
for (auto& character : message) {
if (character == '\t' || character == '\r' || character == '\n') character = ' ';
}
if (message.size() > maximum_message_bytes) {
message.resize(maximum_message_bytes);
auto lead = message.size() - 1U;
while (lead > 0U
&& (static_cast<unsigned char>(message[lead]) & 0xc0U) == 0x80U) {
--lead;
}
const auto first = static_cast<unsigned char>(message[lead]);
const auto expected = (first & 0x80U) == 0U ? 1U
: (first & 0xe0U) == 0xc0U ? 2U
: (first & 0xf0U) == 0xe0U ? 3U
: (first & 0xf8U) == 0xf0U ? 4U : 1U;
if (message.size() - lead < expected) message.resize(lead);
}
if (message.empty()) return;
if (!auxiliary_nodes_) auxiliary_nodes_ = std::make_unique<auxiliary_nodes>();
auxiliary_nodes_->validation_message = validation_message_state{
target.id, anchor.id, std::move(message)};
mark_scene_changed();
}

bool native_document::clear_validation_message() noexcept
{
if (!auxiliary_nodes_ || !auxiliary_nodes_->validation_message) return false;
auxiliary_nodes_->validation_message.reset();
mark_scene_changed();
return true;
}

uint32_t native_document::validation_message_target_id() const noexcept
{
return auxiliary_nodes_ && auxiliary_nodes_->validation_message
? auxiliary_nodes_->validation_message->target_id : 0U;
}

uint32_t native_document::validation_message_anchor_id() const noexcept
{
return auxiliary_nodes_ && auxiliary_nodes_->validation_message
? auxiliary_nodes_->validation_message->anchor_id : 0U;
}
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ struct v8_dom_runtime::implementation final {
v8::FunctionTemplate::New(isolate, validate_control));
element->PrototypeTemplate()->Set(
js_string(isolate, "reportValidity"),
v8::FunctionTemplate::New(isolate, validate_control));
v8::FunctionTemplate::New(isolate, report_control));
element->PrototypeTemplate()->Set(
js_string(isolate, "submit"),
v8::FunctionTemplate::New(isolate, form_submit));
Expand Down Expand Up @@ -3479,7 +3479,7 @@ struct v8_dom_runtime::implementation final {
record.validationMessage = validationMessage;
record.validationAnchor = anchor;
setElementInternalsValidity(
element, validityFlags, validationMessage);
element, validityFlags, validationMessage, anchor);
},
writable: true,
configurable: true
Expand All @@ -3494,8 +3494,9 @@ struct v8_dom_runtime::implementation final {
},
reportValidity: {
value() {
const {element} = associatedInternalsRecord(this);
return Boolean(validateElementInternals(element));
const {element, validationAnchor} = associatedInternalsRecord(this);
return Boolean(validateElementInternals(
element, true, validationAnchor));
},
writable: true,
configurable: true
Expand Down
Loading
Loading