OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/html/track/CueTimeline.h" | 6 #include "core/html/track/CueTimeline.h" |
7 | 7 |
8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
10 #include "core/html/HTMLTrackElement.h" | 10 #include "core/html/HTMLTrackElement.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // track order. | 95 // track order. |
96 if (a.second->track() != b.second->track()) | 96 if (a.second->track() != b.second->track()) |
97 return trackIndexCompare(a.second->track(), b.second->track()); | 97 return trackIndexCompare(a.second->track(), b.second->track()); |
98 | 98 |
99 // 12 - Further sort tasks in events that have the same time by the | 99 // 12 - Further sort tasks in events that have the same time by the |
100 // relative text track cue order of the text track cues associated | 100 // relative text track cue order of the text track cues associated |
101 // with these tasks. | 101 // with these tasks. |
102 return a.second->cueIndex() - b.second->cueIndex() < 0; | 102 return a.second->cueIndex() - b.second->cueIndex() < 0; |
103 } | 103 } |
104 | 104 |
| 105 static PassRefPtrWillBeRawPtr<Event> createEventWithTarget(const AtomicString& e
ventName, PassRefPtrWillBeRawPtr<EventTarget> eventTarget) |
| 106 { |
| 107 RefPtrWillBeRawPtr<Event> event = Event::create(eventName); |
| 108 event->setTarget(eventTarget); |
| 109 return event.release(); |
| 110 } |
| 111 |
105 void CueTimeline::updateActiveCues(double movieTime) | 112 void CueTimeline::updateActiveCues(double movieTime) |
106 { | 113 { |
107 // 4.8.10.8 Playing the media resource | 114 // 4.8.10.8 Playing the media resource |
108 | 115 |
109 // If the current playback position changes while the steps are running, | 116 // If the current playback position changes while the steps are running, |
110 // then the user agent must wait for the steps to complete, and then must | 117 // then the user agent must wait for the steps to complete, and then must |
111 // immediately rerun the steps. | 118 // immediately rerun the steps. |
112 if (ignoreUpdateRequests()) | 119 if (ignoreUpdateRequests()) |
113 return; | 120 return; |
114 | 121 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 263 |
257 // 12 - Sort the tasks in events in ascending time order (tasks with earlier | 264 // 12 - Sort the tasks in events in ascending time order (tasks with earlier |
258 // times first). | 265 // times first). |
259 nonCopyingSort(eventTasks.begin(), eventTasks.end(), eventTimeCueCompare); | 266 nonCopyingSort(eventTasks.begin(), eventTasks.end(), eventTimeCueCompare); |
260 | 267 |
261 for (size_t i = 0; i < eventTasks.size(); ++i) { | 268 for (size_t i = 0; i < eventTasks.size(); ++i) { |
262 if (!affectedTracks.contains(eventTasks[i].second->track())) | 269 if (!affectedTracks.contains(eventTasks[i].second->track())) |
263 affectedTracks.append(eventTasks[i].second->track()); | 270 affectedTracks.append(eventTasks[i].second->track()); |
264 | 271 |
265 // 13 - Queue each task in events, in list order. | 272 // 13 - Queue each task in events, in list order. |
266 RefPtrWillBeRawPtr<Event> event = nullptr; | |
267 | 273 |
268 // Each event in eventTasks may be either an enterEvent or an exitEvent, | 274 // Each event in eventTasks may be either an enterEvent or an exitEvent, |
269 // depending on the time that is associated with the event. This | 275 // depending on the time that is associated with the event. This |
270 // correctly identifies the type of the event, if the startTime is | 276 // correctly identifies the type of the event, if the startTime is |
271 // less than the endTime in the cue. | 277 // less than the endTime in the cue. |
272 if (eventTasks[i].second->startTime() >= eventTasks[i].second->endTime()
) { | 278 if (eventTasks[i].second->startTime() >= eventTasks[i].second->endTime()
) { |
273 event = Event::create(EventTypeNames::enter); | 279 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::ent
er, eventTasks[i].second)); |
274 event->setTarget(eventTasks[i].second); | 280 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::exi
t, eventTasks[i].second)); |
275 mediaElement.scheduleEvent(event.release()); | |
276 | |
277 event = Event::create(EventTypeNames::exit); | |
278 event->setTarget(eventTasks[i].second); | |
279 mediaElement.scheduleEvent(event.release()); | |
280 } else { | 281 } else { |
281 if (eventTasks[i].first == eventTasks[i].second->startTime()) | 282 bool isEnterEvent = eventTasks[i].first == eventTasks[i].second->sta
rtTime(); |
282 event = Event::create(EventTypeNames::enter); | 283 AtomicString eventName = isEnterEvent ? EventTypeNames::enter : Even
tTypeNames::exit; |
283 else | 284 mediaElement.scheduleEvent(createEventWithTarget(eventName, eventTas
ks[i].second)); |
284 event = Event::create(EventTypeNames::exit); | |
285 | |
286 event->setTarget(eventTasks[i].second); | |
287 mediaElement.scheduleEvent(event.release()); | |
288 } | 285 } |
289 } | 286 } |
290 | 287 |
291 // 14 - Sort affected tracks in the same order as the text tracks appear in | 288 // 14 - Sort affected tracks in the same order as the text tracks appear in |
292 // the media element's list of text tracks, and remove duplicates. | 289 // the media element's list of text tracks, and remove duplicates. |
293 nonCopyingSort(affectedTracks.begin(), affectedTracks.end(), trackIndexCompa
re); | 290 nonCopyingSort(affectedTracks.begin(), affectedTracks.end(), trackIndexCompa
re); |
294 | 291 |
295 // 15 - For each text track in affected tracks, in the list order, queue a | 292 // 15 - For each text track in affected tracks, in the list order, queue a |
296 // task to fire a simple event named cuechange at the TextTrack object, and,
... | 293 // task to fire a simple event named cuechange at the TextTrack object, and,
... |
297 for (size_t i = 0; i < affectedTracks.size(); ++i) { | 294 for (size_t i = 0; i < affectedTracks.size(); ++i) { |
298 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::cuechang
e); | 295 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cuechan
ge, affectedTracks[i])); |
299 event->setTarget(affectedTracks[i]); | |
300 | |
301 mediaElement.scheduleEvent(event.release()); | |
302 | 296 |
303 // ... if the text track has a corresponding track element, to then fire
a | 297 // ... if the text track has a corresponding track element, to then fire
a |
304 // simple event named cuechange at the track element as well. | 298 // simple event named cuechange at the track element as well. |
305 if (affectedTracks[i]->trackType() == TextTrack::TrackElement) { | 299 if (affectedTracks[i]->trackType() == TextTrack::TrackElement) { |
306 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::cuec
hange); | |
307 HTMLTrackElement* trackElement = static_cast<LoadableTextTrack*>(aff
ectedTracks[i].get())->trackElement(); | 300 HTMLTrackElement* trackElement = static_cast<LoadableTextTrack*>(aff
ectedTracks[i].get())->trackElement(); |
308 ASSERT(trackElement); | 301 ASSERT(trackElement); |
309 event->setTarget(trackElement); | 302 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cue
change, trackElement)); |
310 | |
311 mediaElement.scheduleEvent(event.release()); | |
312 } | 303 } |
313 } | 304 } |
314 | 305 |
315 // 16 - Set the text track cue active flag of all the cues in the current | 306 // 16 - Set the text track cue active flag of all the cues in the current |
316 // cues, and unset the text track cue active flag of all the cues in the | 307 // cues, and unset the text track cue active flag of all the cues in the |
317 // other cues. | 308 // other cues. |
318 for (size_t i = 0; i < currentCuesSize; ++i) | 309 for (size_t i = 0; i < currentCuesSize; ++i) |
319 currentCues[i].data()->setIsActive(true); | 310 currentCues[i].data()->setIsActive(true); |
320 | 311 |
321 for (size_t i = 0; i < previousCuesSize; ++i) { | 312 for (size_t i = 0; i < previousCuesSize; ++i) { |
(...skipping 20 matching lines...) Expand all Loading... |
342 if (!m_ignoreUpdate && mediaElement().inActiveDocument()) | 333 if (!m_ignoreUpdate && mediaElement().inActiveDocument()) |
343 updateActiveCues(mediaElement().currentTime()); | 334 updateActiveCues(mediaElement().currentTime()); |
344 } | 335 } |
345 | 336 |
346 DEFINE_TRACE(CueTimeline) | 337 DEFINE_TRACE(CueTimeline) |
347 { | 338 { |
348 visitor->trace(m_mediaElement); | 339 visitor->trace(m_mediaElement); |
349 } | 340 } |
350 | 341 |
351 } // namespace blink | 342 } // namespace blink |
OLD | NEW |