LibWeb: Implement <input type=file> behavior

This includes punting on the actual file picker implementation all the
way out to the PageClient. It's likely that some of the real details
should be implemented somewhere closer, like the BrowsingContext or the
Page, but we'll get there.

For now, this allows https://copy.sh/v86 to load the emulation of the
preselected images all the way until it hits a call to
URL.createObjectURL.
This commit is contained in:
Andrew Kaster 2022-10-03 23:39:53 -06:00 committed by Andreas Kling
parent ffab9fb44e
commit 636602a54e
Notes: sideshowbarker 2024-07-17 06:21:52 +09:00
5 changed files with 171 additions and 6 deletions

View file

@ -7,8 +7,10 @@
#pragma once
#include <LibWeb/FileAPI/FileList.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::HTML {
@ -62,7 +64,7 @@ public:
String name() const { return attribute(HTML::AttributeNames::name); }
String value() const;
void set_value(String);
WebIDL::ExceptionOr<void> set_value(String);
bool checked() const { return m_checked; }
enum class ChangeSource {
@ -76,6 +78,15 @@ public:
void did_edit_text_node(Badge<BrowsingContext>);
JS::GCPtr<FileAPI::FileList> files();
void set_files(JS::GCPtr<FileAPI::FileList>);
// NOTE: User interaction
// https://html.spec.whatwg.org/multipage/input.html#update-the-file-selection
void update_the_file_selection(JS::NonnullGCPtr<FileAPI::FileList>);
WebIDL::ExceptionOr<void> show_picker();
// ^EventTarget
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-input-element
virtual bool is_focusable() const override { return m_type != TypeAttributeState::Hidden; }
@ -135,6 +146,9 @@ private:
bool m_before_legacy_pre_activation_behavior_checked { false };
JS::GCPtr<HTMLInputElement> m_legacy_pre_activation_behavior_checked_element_in_group;
// https://html.spec.whatwg.org/multipage/input.html#concept-input-type-file-selected
JS::GCPtr<FileAPI::FileList> m_selected_files;
TypeAttributeState m_type { TypeAttributeState::Text };
String m_value;
};