mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibHTML: Support the :only-child pseudo class
This commit is contained in:
parent
085cafd80a
commit
91ba94fbd4
5 changed files with 36 additions and 0 deletions
28
Base/home/anon/www/only-child.html
Normal file
28
Base/home/anon/www/only-child.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>:only-child test</title>
|
||||||
|
<style>
|
||||||
|
div:only-child {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 6px;
|
||||||
|
border-width: 1px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<div>I am an only child.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div>I am the 1st sibling.</div>
|
||||||
|
<div>I am the 2nd sibling.</div>
|
||||||
|
<div>I am the 3rd sibling, <div>but this is an only child.</div></div>
|
||||||
|
</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="only-child.html">:only-child</a></li>
|
||||||
<li><a href="empty.html">:empty</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>
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
Hover,
|
Hover,
|
||||||
FirstChild,
|
FirstChild,
|
||||||
LastChild,
|
LastChild,
|
||||||
|
OnlyChild,
|
||||||
Empty,
|
Empty,
|
||||||
};
|
};
|
||||||
PseudoClass pseudo_class { PseudoClass::None };
|
PseudoClass pseudo_class { PseudoClass::None };
|
||||||
|
|
|
@ -36,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::OnlyChild:
|
||||||
|
if (element.previous_element_sibling() || element.next_element_sibling())
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
case Selector::SimpleSelector::PseudoClass::Empty:
|
case Selector::SimpleSelector::PseudoClass::Empty:
|
||||||
if (element.first_child_of_type<Element>() || element.first_child_of_type<Text>())
|
if (element.first_child_of_type<Element>() || element.first_child_of_type<Text>())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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 == "only-child")
|
||||||
|
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::OnlyChild;
|
||||||
else if (pseudo_name == "empty")
|
else if (pseudo_name == "empty")
|
||||||
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty;
|
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue