Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Unified Diff: third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp

Issue 1980013002: Simplify LoadableTextTrack::trackElementIndex (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a for-loop Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/track/LoadableTextTrack.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp
diff --git a/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp b/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp
index c61c4fd9a6b425d5b5dad9a559e28296d4db28e3..98aafb77d566ddd548e000794381b109d381336d 100644
--- a/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp
+++ b/third_party/WebKit/Source/core/html/track/LoadableTextTrack.cpp
@@ -35,6 +35,7 @@ LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track)
: TextTrack(subtitlesKeyword(), emptyAtom, emptyAtom, emptyAtom, TrackElement)
, m_trackElement(track)
{
+ DCHECK(m_trackElement);
}
LoadableTextTrack::~LoadableTextTrack()
@@ -43,7 +44,6 @@ LoadableTextTrack::~LoadableTextTrack()
bool LoadableTextTrack::isDefault() const
{
- ASSERT(m_trackElement);
return m_trackElement->fastHasAttribute(HTMLNames::defaultAttr);
}
@@ -62,22 +62,16 @@ void LoadableTextTrack::addRegions(const HeapVector<Member<VTTRegion>>& newRegio
}
}
-size_t LoadableTextTrack::trackElementIndex()
+size_t LoadableTextTrack::trackElementIndex() const
{
- ASSERT(m_trackElement);
- ASSERT(m_trackElement->parentNode());
-
+ // Count the number of preceding <track> elements (== the index.)
size_t index = 0;
- for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_trackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibling(*track)) {
- if (!track->parentNode())
- continue;
- if (track == m_trackElement)
- return index;
+ for (const HTMLTrackElement* track = Traversal<HTMLTrackElement>::previousSibling(*m_trackElement);
+ track;
+ track = Traversal<HTMLTrackElement>::previousSibling(*track))
++index;
- }
- ASSERT_NOT_REACHED();
- return 0;
+ return index;
}
DEFINE_TRACE(LoadableTextTrack)
« no previous file with comments | « third_party/WebKit/Source/core/html/track/LoadableTextTrack.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698