mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:07:43 +00:00
LibHTML: Support the :empty pseudo class
This commit is contained in:
parent
a32cae4c3b
commit
085cafd80a
5 changed files with 35 additions and 0 deletions
26
Base/home/anon/www/empty.html
Normal file
26
Base/home/anon/www/empty.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>:empty test</title>
|
||||||
|
<style>
|
||||||
|
.box {
|
||||||
|
background-color: pink;
|
||||||
|
height: 80px;
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box:empty {
|
||||||
|
background-color: lime;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="box"><!-- I will be lime. --></div>
|
||||||
|
<div class="box">I will be pink.</div>
|
||||||
|
<div class="box">
|
||||||
|
<!-- I will be pink in older browsers because of the whitespace around this comment. -->
|
||||||
|
</div>
|
||||||
|
<div class="box">
|
||||||
|
<p><!-- I will be pink in all browsers because of the non-collapsible whitespace and elements around this comment. --></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -26,6 +26,7 @@ h1 {
|
||||||
<li><a href="small.html">small</a></li>
|
<li><a href="small.html">small</a></li>
|
||||||
<li><a href="first-child.html">:first-child</a></li>
|
<li><a href="first-child.html">:first-child</a></li>
|
||||||
<li><a href="last-child.html">:last-child</a></li>
|
<li><a href="last-child.html">:last-child</a></li>
|
||||||
|
<li><a href="empty.html">:empty</a></li>
|
||||||
<li><a href="form.html">form</a></li>
|
<li><a href="form.html">form</a></li>
|
||||||
<li><a href="borders.html">borders</a></li>
|
<li><a href="borders.html">borders</a></li>
|
||||||
<li><a href="css.html">css</a></li>
|
<li><a href="css.html">css</a></li>
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
Hover,
|
Hover,
|
||||||
FirstChild,
|
FirstChild,
|
||||||
LastChild,
|
LastChild,
|
||||||
|
Empty,
|
||||||
};
|
};
|
||||||
PseudoClass pseudo_class { PseudoClass::None };
|
PseudoClass pseudo_class { PseudoClass::None };
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <LibHTML/CSS/SelectorEngine.h>
|
#include <LibHTML/CSS/SelectorEngine.h>
|
||||||
#include <LibHTML/DOM/Document.h>
|
#include <LibHTML/DOM/Document.h>
|
||||||
#include <LibHTML/DOM/Element.h>
|
#include <LibHTML/DOM/Element.h>
|
||||||
|
#include <LibHTML/DOM/Text.h>
|
||||||
|
|
||||||
namespace SelectorEngine {
|
namespace SelectorEngine {
|
||||||
|
|
||||||
|
@ -35,6 +36,10 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
|
||||||
if (element.next_element_sibling())
|
if (element.next_element_sibling())
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
case Selector::SimpleSelector::PseudoClass::Empty:
|
||||||
|
if (element.first_child_of_type<Element>() || element.first_child_of_type<Text>())
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (component.attribute_match_type) {
|
switch (component.attribute_match_type) {
|
||||||
|
|
|
@ -325,6 +325,8 @@ public:
|
||||||
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::FirstChild;
|
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::FirstChild;
|
||||||
else if (pseudo_name == "last-child")
|
else if (pseudo_name == "last-child")
|
||||||
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::LastChild;
|
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::LastChild;
|
||||||
|
else if (pseudo_name == "empty")
|
||||||
|
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return simple_selector;
|
return simple_selector;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue