psuedo classes

This commit is contained in:
Will McGugan
2021-10-28 16:47:07 +01:00
parent f0e96b680c
commit ff0dd3e4fc
2 changed files with 20 additions and 7 deletions

View File

@@ -9,8 +9,6 @@ from .parse import parse
from .styles import Styles
from .types import Specificity3
from ..widget import Widget
@rich.repr.auto
class Stylesheet:
@@ -57,19 +55,24 @@ class Stylesheet:
node_path = node.css_path
nodes = iter(node_path)
node, siblings = next(nodes)
node_siblings = next(nodes, None)
if node_siblings is None:
return False
node, siblings = node_siblings
for selector in selectors:
if selector.type == SelectorType.UNIVERSAL:
continue
elif selector.type == SelectorType.TYPE:
while node.css_type != selector.name:
node, siblings = next(nodes)
if node is None:
node_siblings = next(nodes, None)
if node_siblings is None:
return False
node, siblings = node_siblings
elif selector.type == SelectorType.CLASS:
while node.css_type != selector.name:
node, siblings = next(nodes)
if node is None:
node_siblings = next(nodes, None)
if node_siblings is None:
return False
node, siblings = node_siblings
return True

View File

@@ -70,3 +70,13 @@ class DOMNode(MessagePump):
def toggle_class(self, *class_names: str) -> None:
"""Toggle class names"""
self._classes.symmetric_difference_update(class_names)
def has_psuedo_class(self, class_name: str) -> bool:
"""Check for psuedo class (such as hover, focus etc)"""
classes = self.get_psuedo_classes()
has_psuedo_class = class_name in classes
return has_psuedo_class
def get_psuedo_classes(self) -> set[str]:
"""Get a set of all psuedo classes"""
return set()