From 09420406b8c21cbe0a9a81361d67f33c882632fb Mon Sep 17 00:00:00 2001 From: Simek Date: Sat, 2 Nov 2024 19:17:20 +0100 Subject: [PATCH] LibWeb: Do not allow focusing "Actually Disabled" elements --- Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp | 5 +++++ Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h | 4 +++- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 5 +++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.h | 4 +++- Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 6 ++++++ Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h | 4 +++- Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp | 5 +++++ Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h | 5 ++++- 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index ae9cf1e16ad..3f9e2e2db1e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -107,4 +107,9 @@ void HTMLButtonElement::activation_behavior(DOM::Event const& event) // 4. FIXME: Run the popover target attribute activation behavior given element. } +bool HTMLButtonElement::is_focusable() const +{ + return enabled(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h index 1f7c0f27aeb..f8664de7aba 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -40,7 +40,9 @@ public: // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element - virtual bool is_focusable() const override { return true; } + // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area + // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled + virtual bool is_focusable() const override; // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index aba99092c11..6715942fab4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -2590,4 +2590,9 @@ HTMLInputElement::ValueAttributeMode HTMLInputElement::value_attribute_mode() co return value_attribute_mode_for_type_state(type_state()); } +bool HTMLInputElement::is_focusable() const +{ + return m_type != TypeAttributeState::Hidden && enabled(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 05e04a80ab2..0e57698f2f7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -155,7 +155,9 @@ public: // ^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; } + // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area + // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled + virtual bool is_focusable() const override; // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 335e66ebf3d..358692829c0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -613,4 +613,10 @@ void HTMLSelectElement::update_selectedness(JS::GCPtr l } update_inner_text_element(); } + +bool HTMLSelectElement::is_focusable() const +{ + return enabled(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 5959b985048..d856f6606bf 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -59,7 +59,9 @@ public: // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element - virtual bool is_focusable() const override { return true; } + // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area + // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled + virtual bool is_focusable() const override; // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 05f5f1af570..017324e823a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -478,4 +478,9 @@ void HTMLTextAreaElement::queue_firing_input_event() }); } +bool HTMLTextAreaElement::is_focusable() const +{ + return enabled(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h index 88b4db1cc4f..bf365757708 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h @@ -42,7 +42,10 @@ public: // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element - virtual bool is_focusable() const override { return true; } + // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area + // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled + virtual bool is_focusable() const override; + virtual void did_lose_focus() override; virtual void did_receive_focus() override;