OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 int TextTrack::trackIndexRelativeToRenderedTracks() | 410 int TextTrack::trackIndexRelativeToRenderedTracks() |
411 { | 411 { |
412 ASSERT(m_mediaElement); | 412 ASSERT(m_mediaElement); |
413 | 413 |
414 if (m_renderedTrackIndex == invalidTrackIndex) | 414 if (m_renderedTrackIndex == invalidTrackIndex) |
415 m_renderedTrackIndex = m_mediaElement->textTracks()->getTrackIndexRelati
veToRenderedTracks(this); | 415 m_renderedTrackIndex = m_mediaElement->textTracks()->getTrackIndexRelati
veToRenderedTracks(this); |
416 | 416 |
417 return m_renderedTrackIndex; | 417 return m_renderedTrackIndex; |
418 } | 418 } |
419 | 419 |
420 bool TextTrack::hasCue(TextTrackCue* cue) | |
421 { | |
422 if (cue->startTime() < 0 || cue->endTime() < 0) | |
423 return false; | |
424 | |
425 if (!m_cues || !m_cues->length()) | |
426 return false; | |
427 | |
428 size_t searchStart = 0; | |
429 size_t searchEnd = m_cues->length(); | |
430 | |
431 while (1) { | |
432 ASSERT(searchStart <= m_cues->length()); | |
433 ASSERT(searchEnd <= m_cues->length()); | |
434 | |
435 TextTrackCue* existingCue; | |
436 | |
437 // Cues in the TextTrackCueList are maintained in start time order. | |
438 if (searchStart == searchEnd) { | |
439 if (!searchStart) | |
440 return false; | |
441 | |
442 // If there is more than one cue with the same start time, back up t
o first one so we | |
443 // consider all of them. | |
444 while (searchStart >= 2 && cue->startTime() == m_cues->item(searchSt
art - 2)->startTime()) | |
445 --searchStart; | |
446 | |
447 bool firstCompare = true; | |
448 while (1) { | |
449 if (!firstCompare) | |
450 ++searchStart; | |
451 firstCompare = false; | |
452 if (searchStart > m_cues->length()) | |
453 return false; | |
454 | |
455 existingCue = m_cues->item(searchStart - 1); | |
456 if (!existingCue || cue->startTime() > existingCue->startTime()) | |
457 return false; | |
458 | |
459 if (*existingCue != *cue) | |
460 continue; | |
461 | |
462 return true; | |
463 } | |
464 } | |
465 | |
466 size_t index = (searchStart + searchEnd) / 2; | |
467 existingCue = m_cues->item(index); | |
468 if (cue->startTime() < existingCue->startTime() || (cue->startTime() ==
existingCue->startTime() && cue->endTime() > existingCue->endTime())) | |
469 searchEnd = index; | |
470 else | |
471 searchStart = index + 1; | |
472 } | |
473 | |
474 ASSERT_NOT_REACHED(); | |
475 return false; | |
476 } | |
477 | |
478 const AtomicString& TextTrack::interfaceName() const | 420 const AtomicString& TextTrack::interfaceName() const |
479 { | 421 { |
480 return EventTargetNames::TextTrack; | 422 return EventTargetNames::TextTrack; |
481 } | 423 } |
482 | 424 |
483 ExecutionContext* TextTrack::executionContext() const | 425 ExecutionContext* TextTrack::executionContext() const |
484 { | 426 { |
485 return m_document; | 427 return m_document; |
486 } | 428 } |
487 | 429 |
488 } // namespace WebCore | 430 } // namespace WebCore |
489 | 431 |
OLD | NEW |