| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | |
| 33 #if ENABLE(WEBVTT_REGIONS) | |
| 34 | |
| 35 #include "core/html/track/TextTrackRegion.h" | 32 #include "core/html/track/TextTrackRegion.h" |
| 36 | 33 |
| 37 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionState.h" |
| 38 #include "bindings/v8/ExceptionStatePlaceholder.h" | 35 #include "bindings/v8/ExceptionStatePlaceholder.h" |
| 39 #include "core/dom/ClientRect.h" | 36 #include "core/dom/ClientRect.h" |
| 40 #include "core/dom/DOMTokenList.h" | 37 #include "core/dom/DOMTokenList.h" |
| 41 #include "core/html/HTMLDivElement.h" | 38 #include "core/html/HTMLDivElement.h" |
| 42 #include "core/html/track/WebVTTParser.h" | 39 #include "core/html/track/WebVTTParser.h" |
| 43 #include "platform/Logging.h" | 40 #include "platform/Logging.h" |
| 44 #include "core/rendering/RenderInline.h" | 41 #include "core/rendering/RenderInline.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 { | 348 { |
| 352 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionShadowPseudoId, | 349 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionShadowPseudoId, |
| 353 ("-webkit-media-text-track-region", AtomicString::ConstructFromLiteral))
; | 350 ("-webkit-media-text-track-region", AtomicString::ConstructFromLiteral))
; |
| 354 | 351 |
| 355 return trackRegionShadowPseudoId; | 352 return trackRegionShadowPseudoId; |
| 356 } | 353 } |
| 357 | 354 |
| 358 PassRefPtr<HTMLDivElement> TextTrackRegion::getDisplayTree() | 355 PassRefPtr<HTMLDivElement> TextTrackRegion::getDisplayTree() |
| 359 { | 356 { |
| 360 if (!m_regionDisplayTree) { | 357 if (!m_regionDisplayTree) { |
| 361 m_regionDisplayTree = HTMLDivElement::create(ownerDocument()); | 358 m_regionDisplayTree = HTMLDivElement::create(*ownerDocument()); |
| 362 prepareRegionDisplayTree(); | 359 prepareRegionDisplayTree(); |
| 363 } | 360 } |
| 364 | 361 |
| 365 return m_regionDisplayTree; | 362 return m_regionDisplayTree; |
| 366 } | 363 } |
| 367 | 364 |
| 368 void TextTrackRegion::willRemoveTextTrackCueBox(TextTrackCueBox* box) | 365 void TextTrackRegion::willRemoveTextTrackCueBox(TextTrackCueBox* box) |
| 369 { | 366 { |
| 370 LOG(Media, "TextTrackRegion::willRemoveTextTrackCueBox"); | 367 LOG(Media, "TextTrackRegion::willRemoveTextTrackCueBox"); |
| 371 ASSERT(m_cueContainer->contains(box)); | 368 ASSERT(m_cueContainer->contains(box)); |
| 372 | 369 |
| 373 double boxHeight = box->getBoundingClientRect()->bottom() - box->getBounding
ClientRect()->top(); | 370 double boxHeight = box->getBoundingClientRect()->bottom() - box->getBounding
ClientRect()->top(); |
| 374 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); | 371 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); |
| 375 | 372 |
| 376 m_cueContainer->classList()->remove(textTrackCueContainerScrollingClass(), A
SSERT_NO_EXCEPTION); | 373 m_cueContainer->classList()->remove(textTrackCueContainerScrollingClass(), A
SSERT_NO_EXCEPTION); |
| 377 | 374 |
| 378 m_currentTop += boxHeight; | 375 m_currentTop += boxHeight; |
| 379 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrim
itiveValue::CSS_PX); | 376 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrim
itiveValue::CSS_PX); |
| 380 } | 377 } |
| 381 | 378 |
| 382 | 379 |
| 383 void TextTrackRegion::appendTextTrackCueBox(PassRefPtr<TextTrackCueBox> displayB
ox) | 380 void TextTrackRegion::appendTextTrackCueBox(PassRefPtr<TextTrackCueBox> displayB
ox) |
| 384 { | 381 { |
| 382 ASSERT(m_cueContainer); |
| 383 |
| 385 if (m_cueContainer->contains(displayBox.get())) | 384 if (m_cueContainer->contains(displayBox.get())) |
| 386 return; | 385 return; |
| 387 | 386 |
| 388 m_cueContainer->appendChild(displayBox); | 387 m_cueContainer->appendChild(displayBox); |
| 389 displayLastTextTrackCueBox(); | 388 displayLastTextTrackCueBox(); |
| 390 } | 389 } |
| 391 | 390 |
| 392 void TextTrackRegion::displayLastTextTrackCueBox() | 391 void TextTrackRegion::displayLastTextTrackCueBox() |
| 393 { | 392 { |
| 394 LOG(Media, "TextTrackRegion::displayLastTextTrackCueBox"); | 393 LOG(Media, "TextTrackRegion::displayLastTextTrackCueBox"); |
| 395 ASSERT(m_cueContainer); | 394 ASSERT(m_cueContainer); |
| 396 | 395 |
| 397 // FIXME: This should not be causing recalc styles in a loop to set the "top
" css | 396 // FIXME: This should not be causing recalc styles in a loop to set the "top
" css |
| 398 // property to move elements. We should just scroll the text track cues on t
he | 397 // property to move elements. We should just scroll the text track cues on t
he |
| 399 // compositor with an animation. | 398 // compositor with an animation. |
| 400 | 399 |
| 401 if (!m_scrollTimer.isActive()) | 400 if (m_scrollTimer.isActive()) |
| 402 return; | 401 return; |
| 403 | 402 |
| 404 // If it's a scrolling region, add the scrolling class. | 403 // If it's a scrolling region, add the scrolling class. |
| 405 if (isScrollingRegion()) | 404 if (isScrollingRegion()) |
| 406 m_cueContainer->classList()->add(textTrackCueContainerScrollingClass(),
ASSERT_NO_EXCEPTION); | 405 m_cueContainer->classList()->add(textTrackCueContainerScrollingClass(),
ASSERT_NO_EXCEPTION); |
| 407 | 406 |
| 408 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); | 407 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); |
| 409 | 408 |
| 410 // Find first cue that is not entirely displayed and scroll it upwards. | 409 // Find first cue that is not entirely displayed and scroll it upwards. |
| 411 for (int i = 0; i < m_cueContainer->childNodeCount() && !m_scrollTimer.isAct
ive(); ++i) { | 410 for (size_t i = 0; i < m_cueContainer->childNodeCount() && !m_scrollTimer.is
Active(); ++i) { |
| 412 float childTop = toHTMLDivElement(m_cueContainer->childNode(i))->getBoun
dingClientRect()->top(); | 411 float childTop = toHTMLDivElement(m_cueContainer->childNode(i))->getBoun
dingClientRect()->top(); |
| 413 float childBottom = toHTMLDivElement(m_cueContainer->childNode(i))->getB
oundingClientRect()->bottom(); | 412 float childBottom = toHTMLDivElement(m_cueContainer->childNode(i))->getB
oundingClientRect()->bottom(); |
| 414 | 413 |
| 415 if (regionBottom >= childBottom) | 414 if (regionBottom >= childBottom) |
| 416 continue; | 415 continue; |
| 417 | 416 |
| 418 float height = childBottom - childTop; | 417 float height = childBottom - childTop; |
| 419 | 418 |
| 420 m_currentTop -= std::min(height, childBottom - regionBottom); | 419 m_currentTop -= std::min(height, childBottom - regionBottom); |
| 421 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSS
PrimitiveValue::CSS_PX); | 420 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSS
PrimitiveValue::CSS_PX); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // anchor. Let topOffset be regionAnchorY multiplied by height divided by | 458 // anchor. Let topOffset be regionAnchorY multiplied by height divided by |
| 460 // 100.0. Let top be topOffset subtracted from 'viewportAnchorY vh'. | 459 // 100.0. Let top be topOffset subtracted from 'viewportAnchorY vh'. |
| 461 double topOffset = m_regionAnchor.y() * height / 100; | 460 double topOffset = m_regionAnchor.y() * height / 100; |
| 462 m_regionDisplayTree->setInlineStyleProperty(CSSPropertyTop, | 461 m_regionDisplayTree->setInlineStyleProperty(CSSPropertyTop, |
| 463 m_viewportAnchor.y() - topOffset, | 462 m_viewportAnchor.y() - topOffset, |
| 464 CSSPrimitiveValue::CSS_PERCENTAGE); | 463 CSSPrimitiveValue::CSS_PERCENTAGE); |
| 465 | 464 |
| 466 | 465 |
| 467 // The cue container is used to wrap the cues and it is the object which is | 466 // The cue container is used to wrap the cues and it is the object which is |
| 468 // gradually scrolled out as multiple cues are appended to the region. | 467 // gradually scrolled out as multiple cues are appended to the region. |
| 469 m_cueContainer = HTMLDivElement::create(ownerDocument()); | 468 m_cueContainer = HTMLDivElement::create(*ownerDocument()); |
| 470 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, | 469 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, |
| 471 0.0, | 470 0.0, |
| 472 CSSPrimitiveValue::CSS_PX); | 471 CSSPrimitiveValue::CSS_PX); |
| 473 | 472 |
| 474 m_cueContainer->setPart(textTrackCueContainerShadowPseudoId()); | 473 m_cueContainer->setPart(textTrackCueContainerShadowPseudoId()); |
| 475 m_regionDisplayTree->appendChild(m_cueContainer); | 474 m_regionDisplayTree->appendChild(m_cueContainer); |
| 476 | 475 |
| 477 // 7.5 Every WebVTT region object is initialised with the following CSS | 476 // 7.5 Every WebVTT region object is initialised with the following CSS |
| 478 m_regionDisplayTree->setPart(textTrackRegionShadowPseudoId()); | 477 m_regionDisplayTree->setPart(textTrackRegionShadowPseudoId()); |
| 479 } | 478 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 499 | 498 |
| 500 void TextTrackRegion::scrollTimerFired(Timer<TextTrackRegion>*) | 499 void TextTrackRegion::scrollTimerFired(Timer<TextTrackRegion>*) |
| 501 { | 500 { |
| 502 LOG(Media, "TextTrackRegion::scrollTimerFired"); | 501 LOG(Media, "TextTrackRegion::scrollTimerFired"); |
| 503 | 502 |
| 504 stopTimer(); | 503 stopTimer(); |
| 505 displayLastTextTrackCueBox(); | 504 displayLastTextTrackCueBox(); |
| 506 } | 505 } |
| 507 | 506 |
| 508 } // namespace WebCore | 507 } // namespace WebCore |
| 509 | |
| 510 #endif | |
| OLD | NEW |