| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 17 matching lines...) Expand all Loading... |
| 28 #include "core/dom/ElementTraversal.h" | 28 #include "core/dom/ElementTraversal.h" |
| 29 #include "core/html/HTMLTrackElement.h" | 29 #include "core/html/HTMLTrackElement.h" |
| 30 #include "core/html/track/vtt/VTTRegionList.h" | 30 #include "core/html/track/vtt/VTTRegionList.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track) | 34 LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track) |
| 35 : TextTrack(subtitlesKeyword(), emptyAtom, emptyAtom, emptyAtom, TrackElemen
t) | 35 : TextTrack(subtitlesKeyword(), emptyAtom, emptyAtom, emptyAtom, TrackElemen
t) |
| 36 , m_trackElement(track) | 36 , m_trackElement(track) |
| 37 { | 37 { |
| 38 DCHECK(m_trackElement); |
| 38 } | 39 } |
| 39 | 40 |
| 40 LoadableTextTrack::~LoadableTextTrack() | 41 LoadableTextTrack::~LoadableTextTrack() |
| 41 { | 42 { |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool LoadableTextTrack::isDefault() const | 45 bool LoadableTextTrack::isDefault() const |
| 45 { | 46 { |
| 46 ASSERT(m_trackElement); | |
| 47 return m_trackElement->fastHasAttribute(HTMLNames::defaultAttr); | 47 return m_trackElement->fastHasAttribute(HTMLNames::defaultAttr); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void LoadableTextTrack::setMode(const AtomicString& mode) | 50 void LoadableTextTrack::setMode(const AtomicString& mode) |
| 51 { | 51 { |
| 52 TextTrack::setMode(mode); | 52 TextTrack::setMode(mode); |
| 53 if (m_trackElement->getReadyState() == HTMLTrackElement::NONE) | 53 if (m_trackElement->getReadyState() == HTMLTrackElement::NONE) |
| 54 m_trackElement->scheduleLoad(); | 54 m_trackElement->scheduleLoad(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void LoadableTextTrack::addRegions(const HeapVector<Member<VTTRegion>>& newRegio
ns) | 57 void LoadableTextTrack::addRegions(const HeapVector<Member<VTTRegion>>& newRegio
ns) |
| 58 { | 58 { |
| 59 for (size_t i = 0; i < newRegions.size(); ++i) { | 59 for (size_t i = 0; i < newRegions.size(); ++i) { |
| 60 newRegions[i]->setTrack(this); | 60 newRegions[i]->setTrack(this); |
| 61 regions()->add(newRegions[i]); | 61 regions()->add(newRegions[i]); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 size_t LoadableTextTrack::trackElementIndex() | 65 size_t LoadableTextTrack::trackElementIndex() const |
| 66 { | 66 { |
| 67 ASSERT(m_trackElement); | 67 // Count the number of preceding <track> elements (== the index.) |
| 68 ASSERT(m_trackElement->parentNode()); | 68 size_t index = 0; |
| 69 for (const HTMLTrackElement* track = Traversal<HTMLTrackElement>::previousSi
bling(*m_trackElement); |
| 70 track; |
| 71 track = Traversal<HTMLTrackElement>::previousSibling(*track)) |
| 72 ++index; |
| 69 | 73 |
| 70 size_t index = 0; | 74 return index; |
| 71 for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_tr
ackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibli
ng(*track)) { | |
| 72 if (!track->parentNode()) | |
| 73 continue; | |
| 74 if (track == m_trackElement) | |
| 75 return index; | |
| 76 ++index; | |
| 77 } | |
| 78 ASSERT_NOT_REACHED(); | |
| 79 | |
| 80 return 0; | |
| 81 } | 75 } |
| 82 | 76 |
| 83 DEFINE_TRACE(LoadableTextTrack) | 77 DEFINE_TRACE(LoadableTextTrack) |
| 84 { | 78 { |
| 85 visitor->trace(m_trackElement); | 79 visitor->trace(m_trackElement); |
| 86 TextTrack::trace(visitor); | 80 TextTrack::trace(visitor); |
| 87 } | 81 } |
| 88 | 82 |
| 89 } // namespace blink | 83 } // namespace blink |
| OLD | NEW |