فهرست منبع

LibWeb: Implement the `:muted` pseudo-class

Sam Atkins 2 سال پیش
والد
کامیت
c8a51f232d

+ 2 - 0
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -493,6 +493,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec
             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::LastOfType);
         if (pseudo_name.equals_ignoring_ascii_case("link"sv))
             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Link);
+        if (pseudo_name.equals_ignoring_ascii_case("muted"sv))
+            return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Muted);
         if (pseudo_name.equals_ignoring_ascii_case("only-child"sv))
             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::OnlyChild);
         if (pseudo_name.equals_ignoring_ascii_case("only-of-type"sv))

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Selector.cpp

@@ -234,6 +234,7 @@ ErrorOr<String> Selector::SimpleSelector::serialize() const
         case Selector::SimpleSelector::PseudoClass::Type::Playing:
         case Selector::SimpleSelector::PseudoClass::Type::Paused:
         case Selector::SimpleSelector::PseudoClass::Type::Seeking:
+        case Selector::SimpleSelector::PseudoClass::Type::Muted:
             // If the pseudo-class does not accept arguments append ":" (U+003A), followed by the name of the pseudo-class, to s.
             TRY(s.try_append(':'));
             TRY(s.try_append(pseudo_class_name(pseudo_class.type)));

+ 3 - 0
Userland/Libraries/LibWeb/CSS/Selector.h

@@ -118,6 +118,7 @@ public:
                 Playing,
                 Paused,
                 Seeking,
+                Muted,
             };
             Type type;
 
@@ -313,6 +314,8 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
         return "paused"sv;
     case Selector::SimpleSelector::PseudoClass::Type::Seeking:
         return "seeking"sv;
+    case Selector::SimpleSelector::PseudoClass::Type::Muted:
+        return "muted"sv;
     }
     VERIFY_NOT_REACHED();
 }

+ 6 - 0
Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp

@@ -395,6 +395,12 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
         auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
         return media_element.seeking();
     }
+    case CSS::Selector::SimpleSelector::PseudoClass::Type::Muted: {
+        if (!is<HTML::HTMLMediaElement>(element))
+            return false;
+        auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element);
+        return media_element.muted();
+    }
     }
 
     return false;

+ 3 - 0
Userland/Libraries/LibWeb/Dump.cpp

@@ -551,6 +551,9 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
                 case CSS::Selector::SimpleSelector::PseudoClass::Type::Seeking:
                     pseudo_class_description = "Seeking";
                     break;
+                case CSS::Selector::SimpleSelector::PseudoClass::Type::Muted:
+                    pseudo_class_description = "Muted";
+                    break;
                 }
 
                 builder.appendff(" pseudo_class={}", pseudo_class_description);

+ 1 - 0
Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp

@@ -414,6 +414,7 @@ void HTMLMediaElement::set_muted(bool muted)
 
     m_muted = muted;
     volume_or_muted_attribute_changed();
+    set_needs_style_update(true);
 }
 
 // https://html.spec.whatwg.org/multipage/media.html#user-interface:dom-media-volume-3