mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:42:44 +00:00 
			
		
		
		
	LibWeb: Implement the :seeking pseudo-class
				
					
				
			This matches while a media element is seeking.
This commit is contained in:
		
							parent
							
								
									4df5e24926
								
							
						
					
					
						commit
						7b4ae43b91
					
				
					 7 changed files with 28 additions and 3 deletions
				
			
		|  | @ -503,6 +503,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec | ||||||
|             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Paused); |             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Paused); | ||||||
|         if (pseudo_name.equals_ignoring_ascii_case("root"sv)) |         if (pseudo_name.equals_ignoring_ascii_case("root"sv)) | ||||||
|             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Root); |             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Root); | ||||||
|  |         if (pseudo_name.equals_ignoring_ascii_case("seeking"sv)) | ||||||
|  |             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Seeking); | ||||||
|         if (pseudo_name.equals_ignoring_ascii_case("host"sv)) |         if (pseudo_name.equals_ignoring_ascii_case("host"sv)) | ||||||
|             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Host); |             return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Host); | ||||||
|         if (pseudo_name.equals_ignoring_ascii_case("visited"sv)) |         if (pseudo_name.equals_ignoring_ascii_case("visited"sv)) | ||||||
|  |  | ||||||
|  | @ -233,6 +233,7 @@ ErrorOr<String> Selector::SimpleSelector::serialize() const | ||||||
|         case Selector::SimpleSelector::PseudoClass::Type::Defined: |         case Selector::SimpleSelector::PseudoClass::Type::Defined: | ||||||
|         case Selector::SimpleSelector::PseudoClass::Type::Playing: |         case Selector::SimpleSelector::PseudoClass::Type::Playing: | ||||||
|         case Selector::SimpleSelector::PseudoClass::Type::Paused: |         case Selector::SimpleSelector::PseudoClass::Type::Paused: | ||||||
|  |         case Selector::SimpleSelector::PseudoClass::Type::Seeking: | ||||||
|             // If the pseudo-class does not accept arguments append ":" (U+003A), followed by the name of the pseudo-class, to s.
 |             // 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(':')); | ||||||
|             TRY(s.try_append(pseudo_class_name(pseudo_class.type))); |             TRY(s.try_append(pseudo_class_name(pseudo_class.type))); | ||||||
|  |  | ||||||
|  | @ -117,6 +117,7 @@ public: | ||||||
|                 Defined, |                 Defined, | ||||||
|                 Playing, |                 Playing, | ||||||
|                 Paused, |                 Paused, | ||||||
|  |                 Seeking, | ||||||
|             }; |             }; | ||||||
|             Type type; |             Type type; | ||||||
| 
 | 
 | ||||||
|  | @ -310,6 +311,8 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty | ||||||
|         return "playing"sv; |         return "playing"sv; | ||||||
|     case Selector::SimpleSelector::PseudoClass::Type::Paused: |     case Selector::SimpleSelector::PseudoClass::Type::Paused: | ||||||
|         return "paused"sv; |         return "paused"sv; | ||||||
|  |     case Selector::SimpleSelector::PseudoClass::Type::Seeking: | ||||||
|  |         return "seeking"sv; | ||||||
|     } |     } | ||||||
|     VERIFY_NOT_REACHED(); |     VERIFY_NOT_REACHED(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -389,6 +389,12 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla | ||||||
|         auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element); |         auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element); | ||||||
|         return media_element.paused(); |         return media_element.paused(); | ||||||
|     } |     } | ||||||
|  |     case CSS::Selector::SimpleSelector::PseudoClass::Type::Seeking: { | ||||||
|  |         if (!is<HTML::HTMLMediaElement>(element)) | ||||||
|  |             return false; | ||||||
|  |         auto const& media_element = static_cast<HTML::HTMLMediaElement const&>(element); | ||||||
|  |         return media_element.seeking(); | ||||||
|  |     } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return false; |     return false; | ||||||
|  |  | ||||||
|  | @ -548,6 +548,9 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) | ||||||
|                 case CSS::Selector::SimpleSelector::PseudoClass::Type::Paused: |                 case CSS::Selector::SimpleSelector::PseudoClass::Type::Paused: | ||||||
|                     pseudo_class_description = "Paused"; |                     pseudo_class_description = "Paused"; | ||||||
|                     break; |                     break; | ||||||
|  |                 case CSS::Selector::SimpleSelector::PseudoClass::Type::Seeking: | ||||||
|  |                     pseudo_class_description = "Seeking"; | ||||||
|  |                     break; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 builder.appendff(" pseudo_class={}", pseudo_class_description); |                 builder.appendff(" pseudo_class={}", pseudo_class_description); | ||||||
|  |  | ||||||
|  | @ -212,6 +212,14 @@ WebIDL::ExceptionOr<Bindings::CanPlayTypeResult> HTMLMediaElement::can_play_type | ||||||
|     return Bindings::CanPlayTypeResult::Empty; |     return Bindings::CanPlayTypeResult::Empty; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void HTMLMediaElement::set_seeking(bool seeking) | ||||||
|  | { | ||||||
|  |     if (m_seeking == seeking) | ||||||
|  |         return; | ||||||
|  |     m_seeking = seeking; | ||||||
|  |     set_needs_style_update(true); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // https://html.spec.whatwg.org/multipage/media.html#dom-media-load
 | // https://html.spec.whatwg.org/multipage/media.html#dom-media-load
 | ||||||
| WebIDL::ExceptionOr<void> HTMLMediaElement::load() | WebIDL::ExceptionOr<void> HTMLMediaElement::load() | ||||||
| { | { | ||||||
|  | @ -505,7 +513,8 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element() | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // 7. If seeking is true, set it to false.
 |         // 7. If seeking is true, set it to false.
 | ||||||
|         m_seeking = false; |         if (seeking()) | ||||||
|  |             set_seeking(false); | ||||||
| 
 | 
 | ||||||
|         // 8. Set the current playback position to 0.
 |         // 8. Set the current playback position to 0.
 | ||||||
|         m_current_playback_position = 0; |         m_current_playback_position = 0; | ||||||
|  | @ -1490,7 +1499,7 @@ void HTMLMediaElement::seek_element(double playback_position, MediaSeekMode seek | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // 4. Set the seeking IDL attribute to true.
 |     // 4. Set the seeking IDL attribute to true.
 | ||||||
|     m_seeking = true; |     set_seeking(true); | ||||||
| 
 | 
 | ||||||
|     // FIXME: 5. If the seek was in response to a DOM method call or setting of an IDL attribute, then continue the script. The
 |     // FIXME: 5. If the seek was in response to a DOM method call or setting of an IDL attribute, then continue the script. The
 | ||||||
|     //           remainder of these steps must be run in parallel. With the exception of the steps marked with ⌛, they could be
 |     //           remainder of these steps must be run in parallel. With the exception of the steps marked with ⌛, they could be
 | ||||||
|  | @ -1534,7 +1543,7 @@ void HTMLMediaElement::seek_element(double playback_position, MediaSeekMode seek | ||||||
|     //            synchronous section are marked with ⌛.)
 |     //            synchronous section are marked with ⌛.)
 | ||||||
| 
 | 
 | ||||||
|     // 14. ⌛ Set the seeking IDL attribute to false.
 |     // 14. ⌛ Set the seeking IDL attribute to false.
 | ||||||
|     m_seeking = false; |     set_seeking(false); | ||||||
| 
 | 
 | ||||||
|     // 15. ⌛ Run the time marches on steps.
 |     // 15. ⌛ Run the time marches on steps.
 | ||||||
|     time_marches_on(TimeMarchesOnReason::Other); |     time_marches_on(TimeMarchesOnReason::Other); | ||||||
|  |  | ||||||
|  | @ -70,6 +70,7 @@ public: | ||||||
|     ReadyState ready_state() const { return m_ready_state; } |     ReadyState ready_state() const { return m_ready_state; } | ||||||
| 
 | 
 | ||||||
|     bool seeking() const { return m_seeking; } |     bool seeking() const { return m_seeking; } | ||||||
|  |     void set_seeking(bool); | ||||||
| 
 | 
 | ||||||
|     WebIDL::ExceptionOr<void> load(); |     WebIDL::ExceptionOr<void> load(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins