mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibWeb: Implement the :placeholder-shown
pseudo-class
This matches if the element has a placeholder, and that placeholder is currently visible. This applies to `<input>` and `<textarea>` elements, but our `<textarea>` is very limited so does not support placeholders.
This commit is contained in:
parent
9f5b1e6614
commit
7bc5949e35
5 changed files with 34 additions and 0 deletions
9
Tests/LibWeb/Ref/css-placeholder-shown-selector-ref.html
Normal file
9
Tests/LibWeb/Ref/css-placeholder-shown-selector-ref.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<style>
|
||||||
|
.placeholder-shown {
|
||||||
|
background-color: yellow;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<input type="text" placeholder="hi" class="placeholder-shown">
|
||||||
|
<input type="text" placeholder="hi" value="I like turtles">
|
||||||
|
<input type="text">
|
||||||
|
<input type="text" value="I like turtles">
|
9
Tests/LibWeb/Ref/css-placeholder-shown-selector.html
Normal file
9
Tests/LibWeb/Ref/css-placeholder-shown-selector.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<style>
|
||||||
|
:placeholder-shown {
|
||||||
|
background-color: yellow;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<input type="text" placeholder="hi">
|
||||||
|
<input type="text" placeholder="hi" value="I like turtles">
|
||||||
|
<input type="text">
|
||||||
|
<input type="text" value="I like turtles">
|
|
@ -9,6 +9,7 @@
|
||||||
"css-gradient-currentcolor.html": "css-gradient-currentcolor-ref.html",
|
"css-gradient-currentcolor.html": "css-gradient-currentcolor-ref.html",
|
||||||
"css-lang-selector.html": "css-lang-selector-ref.html",
|
"css-lang-selector.html": "css-lang-selector-ref.html",
|
||||||
"css-local-link-selector.html": "css-local-link-selector-ref.html",
|
"css-local-link-selector.html": "css-local-link-selector-ref.html",
|
||||||
|
"css-placeholder-shown-selector.html": "css-placeholder-shown-selector-ref.html",
|
||||||
"css-gradients.html": "css-gradients-ref.html",
|
"css-gradients.html": "css-gradients-ref.html",
|
||||||
"css-read-only-read-write-selectors.html": "css-read-only-read-write-selectors-ref.html",
|
"css-read-only-read-write-selectors.html": "css-read-only-read-write-selectors-ref.html",
|
||||||
"svg-symbol.html": "svg-symbol-ref.html",
|
"svg-symbol.html": "svg-symbol-ref.html",
|
||||||
|
|
|
@ -95,6 +95,9 @@
|
||||||
"paused": {
|
"paused": {
|
||||||
"argument": ""
|
"argument": ""
|
||||||
},
|
},
|
||||||
|
"placeholder-shown": {
|
||||||
|
"argument": ""
|
||||||
|
},
|
||||||
"playing": {
|
"playing": {
|
||||||
"argument": ""
|
"argument": ""
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
#include <LibWeb/CSS/SelectorEngine.h>
|
#include <LibWeb/CSS/SelectorEngine.h>
|
||||||
|
#include <LibWeb/CSS/StyleProperties.h>
|
||||||
#include <LibWeb/CSS/ValueID.h>
|
#include <LibWeb/CSS/ValueID.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Element.h>
|
#include <LibWeb/DOM/Element.h>
|
||||||
|
@ -497,6 +498,17 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
|
||||||
return !matches_read_write_pseudo_class(element);
|
return !matches_read_write_pseudo_class(element);
|
||||||
case CSS::PseudoClass::ReadWrite:
|
case CSS::PseudoClass::ReadWrite:
|
||||||
return matches_read_write_pseudo_class(element);
|
return matches_read_write_pseudo_class(element);
|
||||||
|
case CSS::PseudoClass::PlaceholderShown: {
|
||||||
|
// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-placeholder-shown
|
||||||
|
// The :placeholder-shown pseudo-class must match any element falling into one of the following categories:
|
||||||
|
// - input elements that have a placeholder attribute whose value is currently being presented to the user.
|
||||||
|
if (is<HTML::HTMLInputElement>(element) && element.has_attribute(HTML::AttributeNames::placeholder)) {
|
||||||
|
auto const& input_element = static_cast<HTML::HTMLInputElement const&>(element);
|
||||||
|
return input_element.placeholder_element() && input_element.placeholder_value().has_value();
|
||||||
|
}
|
||||||
|
// - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue