OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 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 20 matching lines...) Expand all Loading... |
31 #include "bindings/v8/ExceptionStatePlaceholder.h" | 31 #include "bindings/v8/ExceptionStatePlaceholder.h" |
32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
33 #include "core/events/GenericEventQueue.h" | 33 #include "core/events/GenericEventQueue.h" |
34 #include "core/html/HTMLMediaElement.h" | 34 #include "core/html/HTMLMediaElement.h" |
35 #include "core/html/TimeRanges.h" | 35 #include "core/html/TimeRanges.h" |
36 #include "platform/Clock.h" | 36 #include "platform/Clock.h" |
37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
38 #include "wtf/StdLibExtras.h" | 38 #include "wtf/StdLibExtras.h" |
39 #include "wtf/text/AtomicString.h" | 39 #include "wtf/text/AtomicString.h" |
40 | 40 |
41 using namespace std; | |
42 | |
43 namespace WebCore { | 41 namespace WebCore { |
44 | 42 |
45 PassRefPtrWillBeRawPtr<MediaController> MediaController::create(ExecutionContext
* context) | 43 PassRefPtrWillBeRawPtr<MediaController> MediaController::create(ExecutionContext
* context) |
46 { | 44 { |
47 return adoptRefWillBeRefCountedGarbageCollected(new MediaController(context)
); | 45 return adoptRefWillBeRefCountedGarbageCollected(new MediaController(context)
); |
48 } | 46 } |
49 | 47 |
50 MediaController::MediaController(ExecutionContext* context) | 48 MediaController::MediaController(ExecutionContext* context) |
51 : m_paused(false) | 49 : m_paused(false) |
52 , m_defaultPlaybackRate(1) | 50 , m_defaultPlaybackRate(1) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 130 |
133 double MediaController::duration() const | 131 double MediaController::duration() const |
134 { | 132 { |
135 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value | 133 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value |
136 // when the slaved media elements' durations change. | 134 // when the slaved media elements' durations change. |
137 double maxDuration = 0; | 135 double maxDuration = 0; |
138 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { | 136 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { |
139 double duration = (*it)->duration(); | 137 double duration = (*it)->duration(); |
140 if (std::isnan(duration)) | 138 if (std::isnan(duration)) |
141 continue; | 139 continue; |
142 maxDuration = max(maxDuration, duration); | 140 maxDuration = std::max(maxDuration, duration); |
143 } | 141 } |
144 return maxDuration; | 142 return maxDuration; |
145 } | 143 } |
146 | 144 |
147 double MediaController::currentTime() const | 145 double MediaController::currentTime() const |
148 { | 146 { |
149 if (m_mediaElements.isEmpty()) | 147 if (m_mediaElements.isEmpty()) |
150 return 0; | 148 return 0; |
151 | 149 |
152 if (m_position == MediaPlayer::invalidTime()) { | 150 if (m_position == MediaPlayer::invalidTime()) { |
153 // Some clocks may return times outside the range of [0..duration]. | 151 // Some clocks may return times outside the range of [0..duration]. |
154 m_position = max(0.0, min(duration(), m_clock->currentTime())); | 152 m_position = std::max(0.0, std::min(duration(), m_clock->currentTime()))
; |
155 m_clearPositionTimer.startOneShot(0, FROM_HERE); | 153 m_clearPositionTimer.startOneShot(0, FROM_HERE); |
156 } | 154 } |
157 | 155 |
158 return m_position; | 156 return m_position; |
159 } | 157 } |
160 | 158 |
161 void MediaController::setCurrentTime(double time, ExceptionState& exceptionState
) | 159 void MediaController::setCurrentTime(double time, ExceptionState& exceptionState
) |
162 { | 160 { |
163 // When the user agent is to seek the media controller to a particular new p
layback position, | 161 // When the user agent is to seek the media controller to a particular new p
layback position, |
164 // it must follow these steps: | 162 // it must follow these steps: |
165 // If the new playback position is less than zero, then set it to zero. | 163 // If the new playback position is less than zero, then set it to zero. |
166 time = max(0.0, time); | 164 time = std::max(0.0, time); |
167 | 165 |
168 // If the new playback position is greater than the media controller duratio
n, then set it | 166 // If the new playback position is greater than the media controller duratio
n, then set it |
169 // to the media controller duration. | 167 // to the media controller duration. |
170 time = min(time, duration()); | 168 time = std::min(time, duration()); |
171 | 169 |
172 // Set the media controller position to the new playback position. | 170 // Set the media controller position to the new playback position. |
173 m_position = time; | 171 m_position = time; |
174 m_clock->setCurrentTime(time); | 172 m_clock->setCurrentTime(time); |
175 | 173 |
176 // Seek each slaved media element to the new playback position relative to t
he media element timeline. | 174 // Seek each slaved media element to the new playback position relative to t
he media element timeline. |
177 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 175 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) |
178 (*it)->seek(time, exceptionState); | 176 (*it)->seek(time, exceptionState); |
179 | 177 |
180 scheduleTimeupdateEvent(); | 178 scheduleTimeupdateEvent(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 355 |
358 if (m_mediaElements.isEmpty()) { | 356 if (m_mediaElements.isEmpty()) { |
359 // If the MediaController has no slaved media elements, let new readines
s state be 0. | 357 // If the MediaController has no slaved media elements, let new readines
s state be 0. |
360 newReadyState = HTMLMediaElement::HAVE_NOTHING; | 358 newReadyState = HTMLMediaElement::HAVE_NOTHING; |
361 } else { | 359 } else { |
362 // Otherwise, let it have the lowest value of the readyState IDL attribu
tes of all of its | 360 // Otherwise, let it have the lowest value of the readyState IDL attribu
tes of all of its |
363 // slaved media elements. | 361 // slaved media elements. |
364 MediaElementSequence::const_iterator it = m_mediaElements.begin(); | 362 MediaElementSequence::const_iterator it = m_mediaElements.begin(); |
365 newReadyState = (*it)->readyState(); | 363 newReadyState = (*it)->readyState(); |
366 for (++it; it != m_mediaElements.end(); ++it) | 364 for (++it; it != m_mediaElements.end(); ++it) |
367 newReadyState = min(newReadyState, (*it)->readyState()); | 365 newReadyState = std::min(newReadyState, (*it)->readyState()); |
368 } | 366 } |
369 | 367 |
370 if (newReadyState == oldReadyState) | 368 if (newReadyState == oldReadyState) |
371 return; | 369 return; |
372 | 370 |
373 // If the MediaController's most recently reported readiness state is greate
r than new readiness | 371 // If the MediaController's most recently reported readiness state is greate
r than new readiness |
374 // state then queue a task to fire a simple event at the MediaController obj
ect, whose name is the | 372 // state then queue a task to fire a simple event at the MediaController obj
ect, whose name is the |
375 // event name corresponding to the value of new readiness state given in the
table below. [omitted] | 373 // event name corresponding to the value of new readiness state given in the
table below. [omitted] |
376 if (oldReadyState > newReadyState) { | 374 if (oldReadyState > newReadyState) { |
377 scheduleEvent(eventNameForReadyState(newReadyState)); | 375 scheduleEvent(eventNameForReadyState(newReadyState)); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 m_previousTimeupdateTime = now; | 609 m_previousTimeupdateTime = now; |
612 } | 610 } |
613 | 611 |
614 void MediaController::trace(Visitor* visitor) | 612 void MediaController::trace(Visitor* visitor) |
615 { | 613 { |
616 visitor->trace(m_mediaElements); | 614 visitor->trace(m_mediaElements); |
617 EventTargetWithInlineData::trace(visitor); | 615 EventTargetWithInlineData::trace(visitor); |
618 } | 616 } |
619 | 617 |
620 } | 618 } |
OLD | NEW |