Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp |
| diff --git a/third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp b/third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp |
| index f5bf1fcc1dbac936fff2b804114640bf8c961ae0..d0ee2e8408d812e68783d51dec55610402a582e7 100644 |
| --- a/third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp |
| +++ b/third_party/WebKit/Source/core/html/track/TextTrackContainer.cpp |
| @@ -29,24 +29,94 @@ |
| #include "core/html/track/TextTrackContainer.h" |
| +#include "core/dom/ResizeObserver.h" |
| +#include "core/dom/ResizeObserverCallback.h" |
| +#include "core/dom/ResizeObserverEntry.h" |
| #include "core/html/HTMLVideoElement.h" |
| #include "core/html/track/CueTimeline.h" |
| -#include "core/layout/LayoutTextTrackContainer.h" |
| +#include "core/layout/LayoutBlockFlow.h" |
| +#include "core/layout/LayoutVideo.h" |
| namespace blink { |
| +namespace { |
| + |
| +class VideoElementResizeCallback final : public ResizeObserverCallback { |
| + public: |
| + VideoElementResizeCallback(TextTrackContainer& container) |
| + : ResizeObserverCallback(), m_textTrackContainer(container) {} |
| + |
| + void handleEvent(const HeapVector<Member<ResizeObserverEntry>>& entries, |
| + ResizeObserver*) override { |
| + DCHECK_EQ(entries.size(), 1u); |
| + DCHECK(isHTMLVideoElement(entries[0]->target())); |
| + m_textTrackContainer->updateDefaultFontSize( |
| + entries[0]->target()->layoutObject()); |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() { |
| + visitor->trace(m_textTrackContainer); |
| + ResizeObserverCallback::trace(visitor); |
| + } |
| + |
| + private: |
| + Member<TextTrackContainer> m_textTrackContainer; |
| +}; |
| +} |
|
mlamouri (slow - plz ping)
2017/04/08 12:57:57
style: leave empty line before end of namespace an
fs
2017/04/10 13:36:27
Done.
|
| + |
| TextTrackContainer::TextTrackContainer(Document& document) |
| - : HTMLDivElement(document) {} |
| + : HTMLDivElement(document), m_defaultFontSize(0) {} |
| -TextTrackContainer* TextTrackContainer::create(Document& document) { |
| - TextTrackContainer* element = new TextTrackContainer(document); |
| +DEFINE_TRACE(TextTrackContainer) { |
| + visitor->trace(m_videoSizeObserver); |
| + HTMLDivElement::trace(visitor); |
| +} |
| + |
| +TextTrackContainer* TextTrackContainer::create(HTMLMediaElement& mediaElement) { |
| + TextTrackContainer* element = new TextTrackContainer(mediaElement.document()); |
| element->setShadowPseudoId( |
| AtomicString("-webkit-media-text-track-container")); |
| + if (isHTMLVideoElement(mediaElement)) |
| + element->observeSizeChanges(mediaElement); |
| return element; |
| } |
| LayoutObject* TextTrackContainer::createLayoutObject(const ComputedStyle&) { |
| - return new LayoutTextTrackContainer(this); |
| + return new LayoutBlockFlow(this); |
| +} |
| + |
| +void TextTrackContainer::observeSizeChanges(Element& element) { |
| + m_videoSizeObserver = |
| + ResizeObserver::create(document(), new VideoElementResizeCallback(*this)); |
| + m_videoSizeObserver->observe(&element); |
| +} |
| + |
| +void TextTrackContainer::updateDefaultFontSize( |
| + LayoutObject* mediaLayoutObject) { |
| + if (!mediaLayoutObject || !mediaLayoutObject->isVideo()) |
| + return; |
| + // FIXME: The video size is used to calculate the font size (a workaround |
| + // for lack of per-spec vh/vw support) but the whole media element is used |
| + // for cue rendering. This is inconsistent. See also the somewhat related |
| + // spec bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28105 |
| + LayoutSize videoSize = |
| + toLayoutVideo(*mediaLayoutObject).replacedContentRect().size(); |
| + LayoutUnit smallestDimension = |
| + std::min(videoSize.height(), videoSize.width()); |
| + float fontSize = smallestDimension * 0.05f; |
| + |
| + // Avoid excessive FP precision issue. |
| + // C11 5.2.4.2.2:9 requires assignment and cast to remove extra precision, but |
| + // the behavior is currently not portable. fontSize may have precision higher |
| + // than m_fontSize thus straight comparison can fail despite they cast to the |
| + // same float value. |
| + volatile float& currentFontSize = m_defaultFontSize; |
| + float oldFontSize = currentFontSize; |
| + currentFontSize = fontSize; |
| + if (currentFontSize == oldFontSize) |
| + return; |
| + setInlineStyleProperty(CSSPropertyFontSize, m_defaultFontSize, |
| + CSSPrimitiveValue::UnitType::Pixels); |
| } |
| void TextTrackContainer::updateDisplay(HTMLMediaElement& mediaElement, |