void VTTRegion::displayLastVTTCueBox() { WTF_LOG(Media, "VTTRegion::displayLastVTTCueBox"); ASSERT(m_cueContainer); // FIXME: This should not be causing recalc styles in a loop to set the "top" css // property to move elements. We should just scroll the text track cues on the // compositor with an animation. if (m_scrollTimer.isActive()) return; // If it's a scrolling region, add the scrolling class. if (isScrollingRegion()) m_cueContainer->classList().add(textTrackCueContainerScrollingClass(), ASSERT_NO_EXCEPTION); float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); // Find first cue that is not entirely displayed and scroll it upwards. for (Element* child = ElementTraversal::firstChild(*m_cueContainer); child && !m_scrollTimer.isActive(); child = ElementTraversal::nextSibling(*child)) { ClientRect* clientRect = child->getBoundingClientRect(); float childTop = clientRect->top(); float childBottom = clientRect->bottom(); if (regionBottom >= childBottom) continue; float height = childBottom - childTop; m_currentTop -= std::min(height, childBottom - regionBottom); m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::UnitType::Pixels); startTimer(); } }
void TextTrackRegion::displayLastTextTrackCueBox() { LOG(Media, "TextTrackRegion::displayLastTextTrackCueBox"); ASSERT(m_cueContainer); // The container needs to be rendered, if it is not empty and the region is not currently scrolling. if (!m_cueContainer->renderer() || !m_cueContainer->childNodeCount() || m_scrollTimer.isActive()) return; // If it's a scrolling region, add the scrolling class. if (isScrollingRegion()) m_cueContainer->classList()->add(textTrackCueContainerScrollingClass(), IGNORE_EXCEPTION); float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); // Find first cue that is not entirely displayed and scroll it upwards. for (int i = 0; i < m_cueContainer->childNodeCount() && !m_scrollTimer.isActive(); ++i) { float childTop = static_cast<HTMLDivElement*>(m_cueContainer->childNode(i))->getBoundingClientRect()->top(); float childBottom = static_cast<HTMLDivElement*>(m_cueContainer->childNode(i))->getBoundingClientRect()->bottom(); if (regionBottom >= childBottom) continue; float height = childBottom - childTop; m_currentTop -= std::min(height, childBottom - regionBottom); m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::CSS_PX); startTimer(); } }
void VTTRegion::displayLastTextTrackCueBox() { ASSERT(m_cueContainer); // The container needs to be rendered, if it is not empty and the region is not currently scrolling. if (!m_cueContainer->renderer() || !m_cueContainer->hasChildNodes() || m_scrollTimer.isActive()) return; // If it's a scrolling region, add the scrolling class. if (isScrollingRegion()) m_cueContainer->classList().add(textTrackCueContainerScrollingClass(), IGNORE_EXCEPTION); float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); // Find first cue that is not entirely displayed and scroll it upwards. for (auto& child : childrenOfType<Element>(*m_cueContainer)) { Ref<ClientRect> rect = child.getBoundingClientRect(); float childTop = rect->top(); float childBottom = rect->bottom(); if (regionBottom >= childBottom) continue; float height = childBottom - childTop; m_currentTop -= std::min(height, childBottom - regionBottom); m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::CSS_PX); startTimer(); break; } }
void VTTRegion::willRemoveVTTCueBox(VTTCueBox* box) { WTF_LOG(Media, "VTTRegion::willRemoveVTTCueBox"); ASSERT(m_cueContainer->contains(box)); double boxHeight = box->getBoundingClientRect()->bottom() - box->getBoundingClientRect()->top(); m_cueContainer->classList().remove(textTrackCueContainerScrollingClass(), ASSERT_NO_EXCEPTION); m_currentTop += boxHeight; m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::UnitType::Pixels); }
void TextTrackRegion::willRemoveTextTrackCueBox(TextTrackCueBox* box) { LOG(Media, "TextTrackRegion::willRemoveTextTrackCueBox"); ASSERT(m_cueContainer->contains(box)); double boxHeight = box->getBoundingClientRect()->bottom() - box->getBoundingClientRect()->top(); float regionBottom = m_regionDisplayTree->getBoundingClientRect()->bottom(); m_cueContainer->classList()->remove(textTrackCueContainerScrollingClass(), IGNORE_EXCEPTION); m_currentTop += boxHeight; m_cueContainer->setInlineStyleProperty(CSSPropertyTop, m_currentTop, CSSPrimitiveValue::CSS_PX); }