| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 for (++it; it != m_mediaElements.end(); ++it) | 127 for (++it; it != m_mediaElements.end(); ++it) |
| 128 playedRanges->unionWith((*it)->played().get()); | 128 playedRanges->unionWith((*it)->played().get()); |
| 129 return playedRanges; | 129 return playedRanges; |
| 130 } | 130 } |
| 131 | 131 |
| 132 double MediaController::duration() const | 132 double MediaController::duration() const |
| 133 { | 133 { |
| 134 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value | 134 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value |
| 135 // when the slaved media elements' durations change. | 135 // when the slaved media elements' durations change. |
| 136 double maxDuration = 0; | 136 double maxDuration = 0; |
| 137 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { | 137 for (const HTMLMediaElement* element : m_mediaElements) { |
| 138 double duration = (*it)->duration(); | 138 double duration = element->duration(); |
| 139 if (std::isnan(duration)) | 139 if (std::isnan(duration)) |
| 140 continue; | 140 continue; |
| 141 maxDuration = std::max(maxDuration, duration); | 141 maxDuration = std::max(maxDuration, duration); |
| 142 } | 142 } |
| 143 return maxDuration; | 143 return maxDuration; |
| 144 } | 144 } |
| 145 | 145 |
| 146 double MediaController::currentTime() const | 146 double MediaController::currentTime() const |
| 147 { | 147 { |
| 148 if (m_mediaElements.isEmpty()) | 148 if (m_mediaElements.isEmpty()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 166 | 166 |
| 167 // If the new playback position is greater than the media controller duratio
n, then set it | 167 // If the new playback position is greater than the media controller duratio
n, then set it |
| 168 // to the media controller duration. | 168 // to the media controller duration. |
| 169 time = std::min(time, duration()); | 169 time = std::min(time, duration()); |
| 170 | 170 |
| 171 // Set the media controller position to the new playback position. | 171 // Set the media controller position to the new playback position. |
| 172 m_position = time; | 172 m_position = time; |
| 173 m_clock->setCurrentTime(time); | 173 m_clock->setCurrentTime(time); |
| 174 | 174 |
| 175 // Seek each slaved media element to the new playback position relative to t
he media element timeline. | 175 // Seek each slaved media element to the new playback position relative to t
he media element timeline. |
| 176 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 176 for (HTMLMediaElement* element : m_mediaElements) |
| 177 (*it)->seek(time); | 177 element->seek(time); |
| 178 | 178 |
| 179 scheduleTimeupdateEvent(); | 179 scheduleTimeupdateEvent(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void MediaController::unpause() | 182 void MediaController::unpause() |
| 183 { | 183 { |
| 184 // When the unpause() method is invoked, if the MediaController is a paused
media controller, | 184 // When the unpause() method is invoked, if the MediaController is a paused
media controller, |
| 185 if (!m_paused) | 185 if (!m_paused) |
| 186 return; | 186 return; |
| 187 | 187 |
| 188 // the user agent must change the MediaController into a playing media contr
oller, | 188 // the user agent must change the MediaController into a playing media contr
oller, |
| 189 m_paused = false; | 189 m_paused = false; |
| 190 // queue a task to fire a simple event named play at the MediaController, | 190 // queue a task to fire a simple event named play at the MediaController, |
| 191 scheduleEvent(EventTypeNames::play); | 191 scheduleEvent(EventTypeNames::play); |
| 192 // and then report the controller state of the MediaController. | 192 // and then report the controller state of the MediaController. |
| 193 reportControllerState(); | 193 reportControllerState(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void MediaController::play() | 196 void MediaController::play() |
| 197 { | 197 { |
| 198 // When the play() method is invoked, the user agent must invoke the play me
thod of each | 198 // When the play() method is invoked, the user agent must invoke the play me
thod of each |
| 199 // slaved media element in turn, | 199 // slaved media element in turn, |
| 200 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 200 for (HTMLMediaElement* element : m_mediaElements) |
| 201 (*it)->play(); | 201 element->play(); |
| 202 | 202 |
| 203 // and then invoke the unpause method of the MediaController. | 203 // and then invoke the unpause method of the MediaController. |
| 204 unpause(); | 204 unpause(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void MediaController::pause() | 207 void MediaController::pause() |
| 208 { | 208 { |
| 209 // When the pause() method is invoked, if the MediaController is a playing m
edia controller, | 209 // When the pause() method is invoked, if the MediaController is a playing m
edia controller, |
| 210 if (m_paused) | 210 if (m_paused) |
| 211 return; | 211 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 238 | 238 |
| 239 void MediaController::setPlaybackRate(double rate) | 239 void MediaController::setPlaybackRate(double rate) |
| 240 { | 240 { |
| 241 if (m_clock->playRate() == rate) | 241 if (m_clock->playRate() == rate) |
| 242 return; | 242 return; |
| 243 | 243 |
| 244 // The playbackRate attribute, on setting, must set the MediaController's me
dia controller | 244 // The playbackRate attribute, on setting, must set the MediaController's me
dia controller |
| 245 // playback rate to the new value, | 245 // playback rate to the new value, |
| 246 m_clock->setPlayRate(rate); | 246 m_clock->setPlayRate(rate); |
| 247 | 247 |
| 248 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 248 for (HTMLMediaElement* element : m_mediaElements) |
| 249 (*it)->updatePlaybackRate(); | 249 element->updatePlaybackRate(); |
| 250 | 250 |
| 251 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. | 251 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. |
| 252 scheduleEvent(EventTypeNames::ratechange); | 252 scheduleEvent(EventTypeNames::ratechange); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void MediaController::setVolume(double level, ExceptionState& exceptionState) | 255 void MediaController::setVolume(double level, ExceptionState& exceptionState) |
| 256 { | 256 { |
| 257 if (m_volume == level) | 257 if (m_volume == level) |
| 258 return; | 258 return; |
| 259 | 259 |
| 260 // If the new value is outside the range 0.0 to 1.0 inclusive, then, on sett
ing, an | 260 // If the new value is outside the range 0.0 to 1.0 inclusive, then, on sett
ing, an |
| 261 // IndexSizeError exception must be raised instead. | 261 // IndexSizeError exception must be raised instead. |
| 262 if (level < 0 || level > 1) { | 262 if (level < 0 || level > 1) { |
| 263 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde
xOutsideRange("volume", level, 0.0, ExceptionMessages::InclusiveBound, 1.0, Exce
ptionMessages::InclusiveBound)); | 263 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde
xOutsideRange("volume", level, 0.0, ExceptionMessages::InclusiveBound, 1.0, Exce
ptionMessages::InclusiveBound)); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 | 266 |
| 267 // The volume attribute, on setting, if the new value is in the range 0.0 to
1.0 inclusive, | 267 // The volume attribute, on setting, if the new value is in the range 0.0 to
1.0 inclusive, |
| 268 // must set the MediaController's media controller volume multiplier to the
new value | 268 // must set the MediaController's media controller volume multiplier to the
new value |
| 269 m_volume = level; | 269 m_volume = level; |
| 270 | 270 |
| 271 // and queue a task to fire a simple event named volumechange at the MediaCo
ntroller. | 271 // and queue a task to fire a simple event named volumechange at the MediaCo
ntroller. |
| 272 scheduleEvent(EventTypeNames::volumechange); | 272 scheduleEvent(EventTypeNames::volumechange); |
| 273 | 273 |
| 274 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 274 for (HTMLMediaElement* element : m_mediaElements) |
| 275 (*it)->updateVolume(); | 275 element->updateVolume(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void MediaController::setMuted(bool flag) | 278 void MediaController::setMuted(bool flag) |
| 279 { | 279 { |
| 280 if (m_muted == flag) | 280 if (m_muted == flag) |
| 281 return; | 281 return; |
| 282 | 282 |
| 283 // The muted attribute, on setting, must set the MediaController's media con
troller mute override | 283 // The muted attribute, on setting, must set the MediaController's media con
troller mute override |
| 284 // to the new value | 284 // to the new value |
| 285 m_muted = flag; | 285 m_muted = flag; |
| 286 | 286 |
| 287 // and queue a task to fire a simple event named volumechange at the MediaCo
ntroller. | 287 // and queue a task to fire a simple event named volumechange at the MediaCo
ntroller. |
| 288 scheduleEvent(EventTypeNames::volumechange); | 288 scheduleEvent(EventTypeNames::volumechange); |
| 289 | 289 |
| 290 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 290 for (HTMLMediaElement* element : m_mediaElements) |
| 291 (*it)->updateVolume(); | 291 element->updateVolume(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 static const AtomicString& playbackStateWaiting() | 294 static const AtomicString& playbackStateWaiting() |
| 295 { | 295 { |
| 296 DEFINE_STATIC_LOCAL(AtomicString, waiting, ("waiting", AtomicString::Constru
ctFromLiteral)); | 296 DEFINE_STATIC_LOCAL(AtomicString, waiting, ("waiting", AtomicString::Constru
ctFromLiteral)); |
| 297 return waiting; | 297 return waiting; |
| 298 } | 298 } |
| 299 | 299 |
| 300 static const AtomicString& playbackStatePlaying() | 300 static const AtomicString& playbackStatePlaying() |
| 301 { | 301 { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 scheduleEvent(eventName); | 464 scheduleEvent(eventName); |
| 465 | 465 |
| 466 // Let the MediaController's most recently reported playback state be new pl
ayback state. | 466 // Let the MediaController's most recently reported playback state be new pl
ayback state. |
| 467 m_playbackState = newPlaybackState; | 467 m_playbackState = newPlaybackState; |
| 468 | 468 |
| 469 updateMediaElements(); | 469 updateMediaElements(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void MediaController::updateMediaElements() | 472 void MediaController::updateMediaElements() |
| 473 { | 473 { |
| 474 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) | 474 for (HTMLMediaElement* element : m_mediaElements) |
| 475 (*it)->updatePlayState(); | 475 element->updatePlayState(); |
| 476 } | 476 } |
| 477 | 477 |
| 478 void MediaController::bringElementUpToSpeed(HTMLMediaElement* element) | 478 void MediaController::bringElementUpToSpeed(HTMLMediaElement* element) |
| 479 { | 479 { |
| 480 ASSERT(element); | 480 ASSERT(element); |
| 481 ASSERT(m_mediaElements.contains(element)); | 481 ASSERT(m_mediaElements.contains(element)); |
| 482 | 482 |
| 483 // When the user agent is to bring a media element up to speed with its new
media controller, | 483 // When the user agent is to bring a media element up to speed with its new
media controller, |
| 484 // it must seek that media element to the MediaController's media controller
position relative | 484 // it must seek that media element to the MediaController's media controller
position relative |
| 485 // to the media element's timeline. | 485 // to the media element's timeline. |
| 486 element->seek(currentTime()); | 486 element->seek(currentTime()); |
| 487 | 487 |
| 488 // Update volume to take controller volume and mute into account. | 488 // Update volume to take controller volume and mute into account. |
| 489 element->updateVolume(); | 489 element->updateVolume(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 bool MediaController::isRestrained() const | 492 bool MediaController::isRestrained() const |
| 493 { | 493 { |
| 494 ASSERT(!m_mediaElements.isEmpty()); | 494 ASSERT(!m_mediaElements.isEmpty()); |
| 495 | 495 |
| 496 // A MediaController is a restrained media controller if the MediaController
is a playing media | 496 // A MediaController is a restrained media controller if the MediaController
is a playing media |
| 497 // controller, | 497 // controller, |
| 498 if (m_paused) | 498 if (m_paused) |
| 499 return false; | 499 return false; |
| 500 | 500 |
| 501 bool anyAutoplayingAndPaused = false; | 501 bool anyAutoplayingAndPaused = false; |
| 502 bool allPaused = true; | 502 bool allPaused = true; |
| 503 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { | 503 for (const HTMLMediaElement* element : m_mediaElements) { |
| 504 HTMLMediaElement* element = *it; | |
| 505 | |
| 506 if (element->isAutoplaying() && element->paused()) | 504 if (element->isAutoplaying() && element->paused()) |
| 507 anyAutoplayingAndPaused = true; | 505 anyAutoplayingAndPaused = true; |
| 508 | 506 |
| 509 if (!element->paused()) | 507 if (!element->paused()) |
| 510 allPaused = false; | 508 allPaused = false; |
| 511 } | 509 } |
| 512 | 510 |
| 513 // but either at least one of its slaved media elements whose autoplaying fl
ag is true still has | 511 // but either at least one of its slaved media elements whose autoplaying fl
ag is true still has |
| 514 // its paused attribute set to true, or, all of its slaved media elements ha
ve their paused | 512 // its paused attribute set to true, or, all of its slaved media elements ha
ve their paused |
| 515 // attribute set to true. | 513 // attribute set to true. |
| 516 return anyAutoplayingAndPaused || allPaused; | 514 return anyAutoplayingAndPaused || allPaused; |
| 517 } | 515 } |
| 518 | 516 |
| 519 bool MediaController::isBlocked() const | 517 bool MediaController::isBlocked() const |
| 520 { | 518 { |
| 521 ASSERT(!m_mediaElements.isEmpty()); | 519 ASSERT(!m_mediaElements.isEmpty()); |
| 522 | 520 |
| 523 // A MediaController is a blocked media controller if the MediaController is
a paused media | 521 // A MediaController is a blocked media controller if the MediaController is
a paused media |
| 524 // controller, | 522 // controller, |
| 525 if (m_paused) | 523 if (m_paused) |
| 526 return true; | 524 return true; |
| 527 | 525 |
| 528 bool allPaused = true; | 526 bool allPaused = true; |
| 529 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { | 527 for (const HTMLMediaElement* element : m_mediaElements) { |
| 530 HTMLMediaElement* element = *it; | |
| 531 | |
| 532 // or if any of its slaved media elements are blocked media elements, | 528 // or if any of its slaved media elements are blocked media elements, |
| 533 if (element->isBlocked()) | 529 if (element->isBlocked()) |
| 534 return true; | 530 return true; |
| 535 | 531 |
| 536 // or if any of its slaved media elements whose autoplaying flag is true
still have their | 532 // or if any of its slaved media elements whose autoplaying flag is true
still have their |
| 537 // paused attribute set to true, | 533 // paused attribute set to true, |
| 538 if (element->isAutoplaying() && element->paused()) | 534 if (element->isAutoplaying() && element->paused()) |
| 539 return true; | 535 return true; |
| 540 | 536 |
| 541 if (!element->paused()) | 537 if (!element->paused()) |
| 542 allPaused = false; | 538 allPaused = false; |
| 543 } | 539 } |
| 544 | 540 |
| 545 // or if all of its slaved media elements have their paused attribute set to
true. | 541 // or if all of its slaved media elements have their paused attribute set to
true. |
| 546 return allPaused; | 542 return allPaused; |
| 547 } | 543 } |
| 548 | 544 |
| 549 bool MediaController::hasEnded() const | 545 bool MediaController::hasEnded() const |
| 550 { | 546 { |
| 551 // If the ... media controller playback rate is positive or zero | 547 // If the ... media controller playback rate is positive or zero |
| 552 if (m_clock->playRate() < 0) | 548 if (m_clock->playRate() < 0) |
| 553 return false; | 549 return false; |
| 554 | 550 |
| 555 // [and] all of the MediaController's slaved media elements have ended playb
ack ... let new | 551 // [and] all of the MediaController's slaved media elements have ended playb
ack ... let new |
| 556 // playback state be ended. | 552 // playback state be ended. |
| 557 if (m_mediaElements.isEmpty()) | 553 if (m_mediaElements.isEmpty()) |
| 558 return false; | 554 return false; |
| 559 | 555 |
| 560 bool allHaveEnded = true; | 556 bool allHaveEnded = true; |
| 561 for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it !
= m_mediaElements.end(); ++it) { | 557 for (const HTMLMediaElement* element : m_mediaElements) { |
| 562 if (!(*it)->ended()) | 558 if (!element->ended()) |
| 563 allHaveEnded = false; | 559 allHaveEnded = false; |
| 564 } | 560 } |
| 565 return allHaveEnded; | 561 return allHaveEnded; |
| 566 } | 562 } |
| 567 | 563 |
| 568 void MediaController::scheduleEvent(const AtomicString& eventName) | 564 void MediaController::scheduleEvent(const AtomicString& eventName) |
| 569 { | 565 { |
| 570 m_pendingEventsQueue->enqueueEvent(Event::createCancelable(eventName)); | 566 m_pendingEventsQueue->enqueueEvent(Event::createCancelable(eventName)); |
| 571 } | 567 } |
| 572 | 568 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 { | 609 { |
| 614 #if ENABLE(OILPAN) | 610 #if ENABLE(OILPAN) |
| 615 visitor->trace(m_mediaElements); | 611 visitor->trace(m_mediaElements); |
| 616 visitor->trace(m_pendingEventsQueue); | 612 visitor->trace(m_pendingEventsQueue); |
| 617 visitor->trace(m_executionContext); | 613 visitor->trace(m_executionContext); |
| 618 #endif | 614 #endif |
| 619 EventTargetWithInlineData::trace(visitor); | 615 EventTargetWithInlineData::trace(visitor); |
| 620 } | 616 } |
| 621 | 617 |
| 622 } | 618 } |
| OLD | NEW |