1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

LibWeb: Make input element placeholders look better

We now create a flex container inside the input element's UA shadow tree
and add the placeholder and non-placeholder text as flex items (wrapped
in elements whose style we can manipulate).

This fixes the visual glitch where the placeholder would appear below
the bounding box of the input element. It also allows us to align the
text vertically inside the input element (like we're supposed to).

In order to achieve this, I had to make two small architectural changes
to layout tree building:

- Elements can now report that they represent a given pseudo element.
  This allows us to instantiate the ::placeholder pseudo element as an
  actual DOM element inside the input element's UA shadow tree.

- We no longer create a separate layout node for the shadow root itself.
  Instead, children of the shadow root are treated as if they were
  children of the DOM element itself for the purpose of layout tree
  building.
This commit is contained in:
Andreas Kling 2023-05-25 12:34:54 +02:00
parent 6fb661e781
commit 7d24c13d8b
5 changed files with 109 additions and 47 deletions

View file

@ -130,6 +130,9 @@ public:
virtual Optional<ARIA::Role> default_role() const override;
JS::GCPtr<Element> placeholder_element() { return m_placeholder_element; }
JS::GCPtr<Element const> placeholder_element() const { return m_placeholder_element; }
private:
HTMLInputElement(DOM::Document&, DOM::QualifiedName);
@ -156,6 +159,11 @@ private:
// https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm
DeprecatedString value_sanitization_algorithm(DeprecatedString) const;
void update_placeholder_visibility();
JS::GCPtr<DOM::Element> m_placeholder_element;
JS::GCPtr<DOM::Text> m_placeholder_text_node;
JS::GCPtr<DOM::Element> m_inner_text_element;
JS::GCPtr<DOM::Text> m_text_node;
bool m_checked { false };