Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/html/track/vtt/VTTRegion.h" | 31 #include "core/html/track/vtt/VTTRegion.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionMessages.h" | 33 #include "bindings/core/v8/ExceptionMessages.h" |
| 34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "core/dom/ClientRect.h" | 35 #include "core/dom/ClientRect.h" |
| 36 #include "core/dom/DOMTokenList.h" | 36 #include "core/dom/DOMTokenList.h" |
| 37 #include "core/dom/ElementTraversal.h" | 37 #include "core/dom/ElementTraversal.h" |
| 38 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/TaskRunnerHelper.h" | |
| 39 #include "core/html/HTMLDivElement.h" | 40 #include "core/html/HTMLDivElement.h" |
| 40 #include "core/html/track/vtt/VTTParser.h" | 41 #include "core/html/track/vtt/VTTParser.h" |
| 41 #include "core/html/track/vtt/VTTScanner.h" | 42 #include "core/html/track/vtt/VTTScanner.h" |
| 42 #include "wtf/MathExtras.h" | 43 #include "wtf/MathExtras.h" |
| 43 #include "wtf/text/StringBuilder.h" | 44 #include "wtf/text/StringBuilder.h" |
| 44 | 45 |
| 45 #define VTT_LOG_LEVEL 3 | 46 #define VTT_LOG_LEVEL 3 |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 } | 85 } |
| 85 | 86 |
| 86 VTTRegion::VTTRegion() | 87 VTTRegion::VTTRegion() |
| 87 : m_id(emptyString), | 88 : m_id(emptyString), |
| 88 m_width(defaultWidth), | 89 m_width(defaultWidth), |
| 89 m_heightInLines(defaultHeightInLines), | 90 m_heightInLines(defaultHeightInLines), |
| 90 m_regionAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), | 91 m_regionAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), |
| 91 m_viewportAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), | 92 m_viewportAnchor(FloatPoint(defaultAnchorPointX, defaultAnchorPointY)), |
| 92 m_scroll(defaultScroll), | 93 m_scroll(defaultScroll), |
| 93 m_track(nullptr), | 94 m_track(nullptr), |
| 94 m_currentTop(0), | 95 m_currentTop(0) {} |
| 95 m_scrollTimer(this, &VTTRegion::scrollTimerFired) {} | |
| 96 | 96 |
| 97 VTTRegion::~VTTRegion() {} | 97 VTTRegion::~VTTRegion() {} |
| 98 | 98 |
| 99 void VTTRegion::setTrack(TextTrack* track) { | 99 void VTTRegion::setTrack(TextTrack* track) { |
| 100 m_track = track; | 100 m_track = track; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void VTTRegion::setId(const String& id) { | 103 void VTTRegion::setId(const String& id) { |
| 104 m_id = id; | 104 m_id = id; |
| 105 } | 105 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionShadowPseudoId, | 312 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionShadowPseudoId, |
| 313 ("-webkit-media-text-track-region")); | 313 ("-webkit-media-text-track-region")); |
| 314 | 314 |
| 315 return trackRegionShadowPseudoId; | 315 return trackRegionShadowPseudoId; |
| 316 } | 316 } |
| 317 | 317 |
| 318 HTMLDivElement* VTTRegion::getDisplayTree(Document& document) { | 318 HTMLDivElement* VTTRegion::getDisplayTree(Document& document) { |
| 319 if (!m_regionDisplayTree) { | 319 if (!m_regionDisplayTree) { |
| 320 m_regionDisplayTree = HTMLDivElement::create(document); | 320 m_regionDisplayTree = HTMLDivElement::create(document); |
| 321 prepareRegionDisplayTree(); | 321 prepareRegionDisplayTree(); |
| 322 prepareScrollTimer(document); | |
| 322 } | 323 } |
| 323 | 324 |
| 324 return m_regionDisplayTree; | 325 return m_regionDisplayTree; |
| 325 } | 326 } |
| 326 | 327 |
| 327 void VTTRegion::willRemoveVTTCueBox(VTTCueBox* box) { | 328 void VTTRegion::willRemoveVTTCueBox(VTTCueBox* box) { |
| 328 DVLOG(VTT_LOG_LEVEL) << "willRemoveVTTCueBox"; | 329 DVLOG(VTT_LOG_LEVEL) << "willRemoveVTTCueBox"; |
| 329 DCHECK(m_cueContainer->contains(box)); | 330 DCHECK(m_cueContainer->contains(box)); |
| 330 | 331 |
| 331 double boxHeight = box->getBoundingClientRect()->bottom() - | 332 double boxHeight = box->getBoundingClientRect()->bottom() - |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 350 } | 351 } |
| 351 | 352 |
| 352 void VTTRegion::displayLastVTTCueBox() { | 353 void VTTRegion::displayLastVTTCueBox() { |
| 353 DVLOG(VTT_LOG_LEVEL) << "displayLastVTTCueBox"; | 354 DVLOG(VTT_LOG_LEVEL) << "displayLastVTTCueBox"; |
| 354 DCHECK(m_cueContainer); | 355 DCHECK(m_cueContainer); |
| 355 | 356 |
| 356 // FIXME: This should not be causing recalc styles in a loop to set the "top" | 357 // FIXME: This should not be causing recalc styles in a loop to set the "top" |
| 357 // css property to move elements. We should just scroll the text track cues on | 358 // css property to move elements. We should just scroll the text track cues on |
| 358 // the compositor with an animation. | 359 // the compositor with an animation. |
| 359 | 360 |
| 360 if (m_scrollTimer.isActive()) | 361 if (!m_scrollTimer || m_scrollTimer->isActive()) |
| 361 return; | 362 return; |
| 362 | 363 |
| 363 // If it's a scrolling region, add the scrolling class. | 364 // If it's a scrolling region, add the scrolling class. |
| 364 if (isScrollingRegion()) | 365 if (isScrollingRegion()) |
| 365 m_cueContainer->classList().add(textTrackCueContainerScrollingClass(), | 366 m_cueContainer->classList().add(textTrackCueContainerScrollingClass(), |
| 366 ASSERT_NO_EXCEPTION); | 367 ASSERT_NO_EXCEPTION); |
| 367 | 368 |
| 368 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); | 369 float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); |
| 369 | 370 |
| 370 // Find first cue that is not entirely displayed and scroll it upwards. | 371 // Find first cue that is not entirely displayed and scroll it upwards. |
| 371 for (Element* child = ElementTraversal::firstChild(*m_cueContainer); | 372 for (Element* child = ElementTraversal::firstChild(*m_cueContainer); |
| 372 child && !m_scrollTimer.isActive(); | 373 child && !m_scrollTimer->isActive(); |
| 373 child = ElementTraversal::nextSibling(*child)) { | 374 child = ElementTraversal::nextSibling(*child)) { |
| 374 ClientRect* clientRect = child->getBoundingClientRect(); | 375 ClientRect* clientRect = child->getBoundingClientRect(); |
| 375 float childTop = clientRect->top(); | 376 float childTop = clientRect->top(); |
| 376 float childBottom = clientRect->bottom(); | 377 float childBottom = clientRect->bottom(); |
| 377 | 378 |
| 378 if (regionBottom >= childBottom) | 379 if (regionBottom >= childBottom) |
| 379 continue; | 380 continue; |
| 380 | 381 |
| 381 float height = childBottom - childTop; | 382 float height = childBottom - childTop; |
| 382 | 383 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, 0.0, | 433 m_cueContainer->setInlineStyleProperty(CSSPropertyTop, 0.0, |
| 433 CSSPrimitiveValue::UnitType::Pixels); | 434 CSSPrimitiveValue::UnitType::Pixels); |
| 434 | 435 |
| 435 m_cueContainer->setShadowPseudoId(textTrackCueContainerShadowPseudoId()); | 436 m_cueContainer->setShadowPseudoId(textTrackCueContainerShadowPseudoId()); |
| 436 m_regionDisplayTree->appendChild(m_cueContainer); | 437 m_regionDisplayTree->appendChild(m_cueContainer); |
| 437 | 438 |
| 438 // 7.5 Every WebVTT region object is initialised with the following CSS | 439 // 7.5 Every WebVTT region object is initialised with the following CSS |
| 439 m_regionDisplayTree->setShadowPseudoId(textTrackRegionShadowPseudoId()); | 440 m_regionDisplayTree->setShadowPseudoId(textTrackRegionShadowPseudoId()); |
| 440 } | 441 } |
| 441 | 442 |
| 443 void VTTRegion::prepareScrollTimer(Document& document) { | |
|
fs
2017/02/08 11:57:54
Maybe just fold this into startTimer(), and possib
| |
| 444 DCHECK(!m_scrollTimer); | |
| 445 m_scrollTimer = WTF::makeUnique<TaskRunnerTimer<VTTRegion>>( | |
| 446 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document), this, | |
|
haraken
2017/02/08 11:49:40
foolip@ should know better but I guess this is not
fs
2017/02/08 11:57:54
AFAIK, this timer is an implementation detail, so
foolip
2017/02/08 13:46:38
Yep, I think so too. If that means that the &docum
| |
| 447 &VTTRegion::scrollTimerFired); | |
| 448 } | |
| 449 | |
| 442 void VTTRegion::startTimer() { | 450 void VTTRegion::startTimer() { |
| 451 DCHECK(m_scrollTimer); | |
| 443 DVLOG(VTT_LOG_LEVEL) << "startTimer"; | 452 DVLOG(VTT_LOG_LEVEL) << "startTimer"; |
| 444 | 453 |
| 445 if (m_scrollTimer.isActive()) | 454 if (m_scrollTimer->isActive()) |
| 446 return; | 455 return; |
| 447 | 456 |
| 448 double duration = isScrollingRegion() ? scrollTime : 0; | 457 double duration = isScrollingRegion() ? scrollTime : 0; |
| 449 m_scrollTimer.startOneShot(duration, BLINK_FROM_HERE); | 458 m_scrollTimer->startOneShot(duration, BLINK_FROM_HERE); |
| 450 } | 459 } |
| 451 | 460 |
| 452 void VTTRegion::stopTimer() { | 461 void VTTRegion::stopTimer() { |
| 453 DVLOG(VTT_LOG_LEVEL) << "stopTimer"; | 462 DVLOG(VTT_LOG_LEVEL) << "stopTimer"; |
| 454 m_scrollTimer.stop(); | 463 m_scrollTimer->stop(); |
| 455 } | 464 } |
| 456 | 465 |
| 457 void VTTRegion::scrollTimerFired(TimerBase*) { | 466 void VTTRegion::scrollTimerFired(TimerBase*) { |
| 458 DVLOG(VTT_LOG_LEVEL) << "scrollTimerFired"; | 467 DVLOG(VTT_LOG_LEVEL) << "scrollTimerFired"; |
| 459 | 468 |
| 460 stopTimer(); | 469 stopTimer(); |
| 461 displayLastVTTCueBox(); | 470 displayLastVTTCueBox(); |
| 462 } | 471 } |
| 463 | 472 |
| 464 DEFINE_TRACE(VTTRegion) { | 473 DEFINE_TRACE(VTTRegion) { |
| 465 visitor->trace(m_cueContainer); | 474 visitor->trace(m_cueContainer); |
| 466 visitor->trace(m_regionDisplayTree); | 475 visitor->trace(m_regionDisplayTree); |
| 467 visitor->trace(m_track); | 476 visitor->trace(m_track); |
| 468 } | 477 } |
| 469 | 478 |
| 470 } // namespace blink | 479 } // namespace blink |
| OLD | NEW |