| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 2431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2442 double buffered = 0; | 2442 double buffered = 0; |
| 2443 RefPtr<TimeRanges> timeRanges = m_player->buffered(); | 2443 RefPtr<TimeRanges> timeRanges = m_player->buffered(); |
| 2444 for (unsigned i = 0; i < timeRanges->length(); ++i) { | 2444 for (unsigned i = 0; i < timeRanges->length(); ++i) { |
| 2445 double start = timeRanges->start(i, IGNORE_EXCEPTION); | 2445 double start = timeRanges->start(i, IGNORE_EXCEPTION); |
| 2446 double end = timeRanges->end(i, IGNORE_EXCEPTION); | 2446 double end = timeRanges->end(i, IGNORE_EXCEPTION); |
| 2447 buffered += end - start; | 2447 buffered += end - start; |
| 2448 } | 2448 } |
| 2449 return buffered / duration; | 2449 return buffered / duration; |
| 2450 } | 2450 } |
| 2451 | 2451 |
| 2452 void HTMLMediaElement::mediaPlayerDidAddTrack(WebInbandTextTrack* webTrack) | 2452 void HTMLMediaElement::mediaPlayerDidAddTextTrack(WebInbandTextTrack* webTrack) |
| 2453 { | 2453 { |
| 2454 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2454 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
| 2455 return; | 2455 return; |
| 2456 | 2456 |
| 2457 // 4.8.10.12.2 Sourcing in-band text tracks | 2457 // 4.8.10.12.2 Sourcing in-band text tracks |
| 2458 // 1. Associate the relevant data with a new text track and its correspondin
g new TextTrack object. | 2458 // 1. Associate the relevant data with a new text track and its correspondin
g new TextTrack object. |
| 2459 RefPtr<InbandTextTrack> textTrack = InbandTextTrack::create(document(), this
, webTrack); | 2459 RefPtr<InbandTextTrack> textTrack = InbandTextTrack::create(document(), this
, webTrack); |
| 2460 | 2460 |
| 2461 // 2. Set the new text track's kind, label, and language based on the semant
ics of the relevant data, | 2461 // 2. Set the new text track's kind, label, and language based on the semant
ics of the relevant data, |
| 2462 // as defined by the relevant specification. If there is no label in that da
ta, then the label must | 2462 // as defined by the relevant specification. If there is no label in that da
ta, then the label must |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2474 | 2474 |
| 2475 // 7. Set the new text track's mode to the mode consistent with the user's p
references and the requirements of | 2475 // 7. Set the new text track's mode to the mode consistent with the user's p
references and the requirements of |
| 2476 // the relevant specification for the data. | 2476 // the relevant specification for the data. |
| 2477 // - This will happen in configureTextTracks() | 2477 // - This will happen in configureTextTracks() |
| 2478 scheduleDelayedAction(LoadTextTrackResource); | 2478 scheduleDelayedAction(LoadTextTrackResource); |
| 2479 | 2479 |
| 2480 // 8. Add the new text track to the media element's list of text tracks. | 2480 // 8. Add the new text track to the media element's list of text tracks. |
| 2481 // 9. Fire an event with the name addtrack, that does not bubble and is not
cancelable, and that uses the TrackEvent | 2481 // 9. Fire an event with the name addtrack, that does not bubble and is not
cancelable, and that uses the TrackEvent |
| 2482 // interface, with the track attribute initialized to the text track's TextT
rack object, at the media element's | 2482 // interface, with the track attribute initialized to the text track's TextT
rack object, at the media element's |
| 2483 // textTracks attribute's TextTrackList object. | 2483 // textTracks attribute's TextTrackList object. |
| 2484 addTrack(textTrack.get()); | 2484 addTextTrack(textTrack); |
| 2485 } | 2485 } |
| 2486 | 2486 |
| 2487 void HTMLMediaElement::mediaPlayerDidRemoveTrack(WebInbandTextTrack* webTrack) | 2487 void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac
k) |
| 2488 { | 2488 { |
| 2489 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2489 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
| 2490 return; | 2490 return; |
| 2491 | 2491 |
| 2492 if (!m_textTracks) | 2492 if (!m_textTracks) |
| 2493 return; | 2493 return; |
| 2494 | 2494 |
| 2495 // This cast is safe because we created the InbandTextTrack with the WebInba
ndTextTrack | 2495 // This cast is safe because we created the InbandTextTrack with the WebInba
ndTextTrack |
| 2496 // passed to mediaPlayerDidAddTrack. | 2496 // passed to mediaPlayerDidAddTrack. |
| 2497 RefPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack*>(webTrack->
client()); | 2497 RefPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack*>(webTrack->
client()); |
| 2498 if (!textTrack) | 2498 if (!textTrack) |
| 2499 return; | 2499 return; |
| 2500 | 2500 |
| 2501 removeTrack(textTrack.get()); | 2501 removeTextTrack(textTrack.get()); |
| 2502 } | 2502 } |
| 2503 | 2503 |
| 2504 void HTMLMediaElement::closeCaptionTracksChanged() | 2504 void HTMLMediaElement::closeCaptionTracksChanged() |
| 2505 { | 2505 { |
| 2506 if (hasMediaControls()) | 2506 if (hasMediaControls()) |
| 2507 mediaControls()->closedCaptionTracksChanged(); | 2507 mediaControls()->closedCaptionTracksChanged(); |
| 2508 } | 2508 } |
| 2509 | 2509 |
| 2510 void HTMLMediaElement::addTrack(TextTrack* track) | 2510 void HTMLMediaElement::addTextTrack(PassRefPtr<TextTrack> track) |
| 2511 { | 2511 { |
| 2512 textTracks()->append(track); | 2512 textTracks()->append(track); |
| 2513 | 2513 |
| 2514 closeCaptionTracksChanged(); | 2514 closeCaptionTracksChanged(); |
| 2515 } | 2515 } |
| 2516 | 2516 |
| 2517 void HTMLMediaElement::removeTrack(TextTrack* track) | 2517 void HTMLMediaElement::removeTextTrack(TextTrack* track) |
| 2518 { | 2518 { |
| 2519 TrackDisplayUpdateScope scope(this); | 2519 TrackDisplayUpdateScope scope(this); |
| 2520 TextTrackCueList* cues = track->cues(); | 2520 TextTrackCueList* cues = track->cues(); |
| 2521 if (cues) | 2521 if (cues) |
| 2522 textTrackRemoveCues(track, cues); | 2522 textTrackRemoveCues(track, cues); |
| 2523 m_textTracks->remove(track); | 2523 m_textTracks->remove(track); |
| 2524 | 2524 |
| 2525 closeCaptionTracksChanged(); | 2525 closeCaptionTracksChanged(); |
| 2526 } | 2526 } |
| 2527 | 2527 |
| 2528 void HTMLMediaElement::removeAllInbandTracks() | 2528 void HTMLMediaElement::removeAllInbandTracks() |
| 2529 { | 2529 { |
| 2530 if (!m_textTracks) | 2530 if (!m_textTracks) |
| 2531 return; | 2531 return; |
| 2532 | 2532 |
| 2533 TrackDisplayUpdateScope scope(this); | 2533 TrackDisplayUpdateScope scope(this); |
| 2534 for (int i = m_textTracks->length() - 1; i >= 0; --i) { | 2534 for (int i = m_textTracks->length() - 1; i >= 0; --i) { |
| 2535 TextTrack* track = m_textTracks->item(i); | 2535 TextTrack* track = m_textTracks->item(i); |
| 2536 | 2536 |
| 2537 if (track->trackType() == TextTrack::InBand) | 2537 if (track->trackType() == TextTrack::InBand) |
| 2538 removeTrack(track); | 2538 removeTextTrack(track); |
| 2539 } | 2539 } |
| 2540 } | 2540 } |
| 2541 | 2541 |
| 2542 PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicString& kind, c
onst AtomicString& label, const AtomicString& language, ExceptionState& exceptio
nState) | 2542 PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicString& kind, c
onst AtomicString& label, const AtomicString& language, ExceptionState& exceptio
nState) |
| 2543 { | 2543 { |
| 2544 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); | 2544 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); |
| 2545 | 2545 |
| 2546 // 4.8.10.12.4 Text track API | 2546 // 4.8.10.12.4 Text track API |
| 2547 // The addTextTrack(kind, label, language) method of media elements, when in
voked, must run the following steps: | 2547 // The addTextTrack(kind, label, language) method of media elements, when in
voked, must run the following steps: |
| 2548 | 2548 |
| 2549 // 1. If kind is not one of the following strings, then throw a SyntaxError
exception and abort these steps | 2549 // 1. If kind is not one of the following strings, then throw a SyntaxError
exception and abort these steps |
| 2550 if (!TextTrack::isValidKindKeyword(kind)) { | 2550 if (!TextTrack::isValidKindKeyword(kind)) { |
| 2551 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); | 2551 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 2552 return 0; | 2552 return 0; |
| 2553 } | 2553 } |
| 2554 | 2554 |
| 2555 // 2. If the label argument was omitted, let label be the empty string. | 2555 // 2. If the label argument was omitted, let label be the empty string. |
| 2556 // 3. If the language argument was omitted, let language be the empty string
. | 2556 // 3. If the language argument was omitted, let language be the empty string
. |
| 2557 // 4. Create a new TextTrack object. | 2557 // 4. Create a new TextTrack object. |
| 2558 | 2558 |
| 2559 // 5. Create a new text track corresponding to the new object, and set its t
ext track kind to kind, its text | 2559 // 5. Create a new text track corresponding to the new object, and set its t
ext track kind to kind, its text |
| 2560 // track label to label, its text track language to language... | 2560 // track label to label, its text track language to language... |
| 2561 RefPtr<TextTrack> textTrack = TextTrack::create(document(), this, kind, labe
l, language); | 2561 RefPtr<TextTrack> textTrack = TextTrack::create(document(), this, kind, labe
l, language); |
| 2562 | 2562 |
| 2563 // Note, due to side effects when changing track parameters, we have to | 2563 // Note, due to side effects when changing track parameters, we have to |
| 2564 // first append the track to the text track list. | 2564 // first append the track to the text track list. |
| 2565 | 2565 |
| 2566 // 6. Add the new text track to the media element's list of text tracks. | 2566 // 6. Add the new text track to the media element's list of text tracks. |
| 2567 addTrack(textTrack.get()); | 2567 addTextTrack(textTrack); |
| 2568 | 2568 |
| 2569 // ... its text track readiness state to the text track loaded state ... | 2569 // ... its text track readiness state to the text track loaded state ... |
| 2570 textTrack->setReadinessState(TextTrack::Loaded); | 2570 textTrack->setReadinessState(TextTrack::Loaded); |
| 2571 | 2571 |
| 2572 // ... its text track mode to the text track hidden mode, and its text track
list of cues to an empty list ... | 2572 // ... its text track mode to the text track hidden mode, and its text track
list of cues to an empty list ... |
| 2573 textTrack->setMode(TextTrack::hiddenKeyword()); | 2573 textTrack->setMode(TextTrack::hiddenKeyword()); |
| 2574 | 2574 |
| 2575 return textTrack.release(); | 2575 return textTrack.release(); |
| 2576 } | 2576 } |
| 2577 | 2577 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2593 return; | 2593 return; |
| 2594 | 2594 |
| 2595 // 4.8.10.12.3 Sourcing out-of-band text tracks | 2595 // 4.8.10.12.3 Sourcing out-of-band text tracks |
| 2596 // When a track element's parent element changes and the new parent is a med
ia element, | 2596 // When a track element's parent element changes and the new parent is a med
ia element, |
| 2597 // then the user agent must add the track element's corresponding text track
to the | 2597 // then the user agent must add the track element's corresponding text track
to the |
| 2598 // media element's list of text tracks ... [continues in TextTrackList::appe
nd] | 2598 // media element's list of text tracks ... [continues in TextTrackList::appe
nd] |
| 2599 RefPtr<TextTrack> textTrack = trackElement->track(); | 2599 RefPtr<TextTrack> textTrack = trackElement->track(); |
| 2600 if (!textTrack) | 2600 if (!textTrack) |
| 2601 return; | 2601 return; |
| 2602 | 2602 |
| 2603 addTrack(textTrack.get()); | 2603 addTextTrack(textTrack); |
| 2604 | 2604 |
| 2605 // Do not schedule the track loading until parsing finishes so we don't star
t before all tracks | 2605 // Do not schedule the track loading until parsing finishes so we don't star
t before all tracks |
| 2606 // in the markup have been added. | 2606 // in the markup have been added. |
| 2607 if (!m_parsingInProgress) | 2607 if (!m_parsingInProgress) |
| 2608 scheduleDelayedAction(LoadTextTrackResource); | 2608 scheduleDelayedAction(LoadTextTrackResource); |
| 2609 | 2609 |
| 2610 if (hasMediaControls()) | 2610 if (hasMediaControls()) |
| 2611 mediaControls()->closedCaptionTracksChanged(); | 2611 mediaControls()->closedCaptionTracksChanged(); |
| 2612 } | 2612 } |
| 2613 | 2613 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2631 | 2631 |
| 2632 textTrack->setHasBeenConfigured(false); | 2632 textTrack->setHasBeenConfigured(false); |
| 2633 | 2633 |
| 2634 if (!m_textTracks) | 2634 if (!m_textTracks) |
| 2635 return; | 2635 return; |
| 2636 | 2636 |
| 2637 // 4.8.10.12.3 Sourcing out-of-band text tracks | 2637 // 4.8.10.12.3 Sourcing out-of-band text tracks |
| 2638 // When a track element's parent element changes and the old parent was a me
dia element, | 2638 // When a track element's parent element changes and the old parent was a me
dia element, |
| 2639 // then the user agent must remove the track element's corresponding text tr
ack from the | 2639 // then the user agent must remove the track element's corresponding text tr
ack from the |
| 2640 // media element's list of text tracks. | 2640 // media element's list of text tracks. |
| 2641 removeTrack(textTrack.get()); | 2641 removeTextTrack(textTrack.get()); |
| 2642 | 2642 |
| 2643 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get()); | 2643 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get()); |
| 2644 if (index != kNotFound) | 2644 if (index != kNotFound) |
| 2645 m_textTracksWhenResourceSelectionBegan.remove(index); | 2645 m_textTracksWhenResourceSelectionBegan.remove(index); |
| 2646 } | 2646 } |
| 2647 | 2647 |
| 2648 static int textTrackLanguageSelectionScore(const TextTrack& track) | 2648 static int textTrackLanguageSelectionScore(const TextTrack& track) |
| 2649 { | 2649 { |
| 2650 if (track.language().isEmpty()) | 2650 if (track.language().isEmpty()) |
| 2651 return 0; | 2651 return 0; |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3925 { | 3925 { |
| 3926 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); | 3926 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); |
| 3927 } | 3927 } |
| 3928 | 3928 |
| 3929 bool HTMLMediaElement::isInteractiveContent() const | 3929 bool HTMLMediaElement::isInteractiveContent() const |
| 3930 { | 3930 { |
| 3931 return fastHasAttribute(controlsAttr); | 3931 return fastHasAttribute(controlsAttr); |
| 3932 } | 3932 } |
| 3933 | 3933 |
| 3934 } | 3934 } |
| OLD | NEW |