Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1110)

Unified Diff: Source/core/html/track/TextTrackContainer.cpp

Issue 988763002: Start separating the text track container from the media controls (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/track/TextTrackContainer.h ('k') | Source/core/layout/LayoutMediaControls.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/track/TextTrackContainer.cpp
diff --git a/Source/core/html/track/TextTrackContainer.cpp b/Source/core/html/track/TextTrackContainer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..36335c4bc2d26ef3da15827c3b39bc156bd91bcf
--- /dev/null
+++ b/Source/core/html/track/TextTrackContainer.cpp
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "core/html/track/TextTrackContainer.h"
+
+#include "core/html/HTMLVideoElement.h"
+#include "core/html/track/CueTimeline.h"
+#include "core/layout/LayoutTextTrackContainer.h"
+#include "core/layout/LayoutVideo.h"
+
+namespace blink {
+
+TextTrackContainer::TextTrackContainer(Document& document)
+ : HTMLDivElement(document)
+ , m_fontSize(0)
+{
+}
+
+PassRefPtrWillBeRawPtr<TextTrackContainer> TextTrackContainer::create(Document& document)
+{
+ RefPtrWillBeRawPtr<TextTrackContainer> element = adoptRefWillBeNoop(new TextTrackContainer(document));
+ element->setShadowPseudoId(AtomicString("-webkit-media-text-track-container", AtomicString::ConstructFromLiteral));
+ element->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
+ return element.release();
+}
+
+LayoutObject* TextTrackContainer::createLayoutObject(const LayoutStyle&)
+{
+ return new LayoutTextTrackContainer(this);
+}
+
+void TextTrackContainer::updateDisplay(HTMLMediaElement& mediaElement)
+{
+ if (!mediaElement.closedCaptionsVisible()) {
+ removeChildren();
+ return;
+ }
+
+ // 1. If the media element is an audio element, or is another playback
+ // mechanism with no rendering area, abort these steps. There is nothing to
+ // render.
+ if (isHTMLAudioElement(mediaElement))
+ return;
+
+ // 2. Let video be the media element or other playback mechanism.
+ HTMLVideoElement& video = toHTMLVideoElement(mediaElement);
+
+ // 3. Let output be an empty list of absolutely positioned CSS block boxes.
+
+ // 4. If the user agent is exposing a user interface for video, add to
+ // output one or more completely transparent positioned CSS block boxes that
+ // cover the same region as the user interface.
+
+ // 5. If the last time these rules were run, the user agent was not exposing
+ // a user interface for video, but now it is, let reset be true. Otherwise,
+ // let reset be false.
+
+ // There is nothing to be done explicitly for 4th and 5th steps, as
+ // everything is handled through CSS. The caption box is on top of the
+ // controls box, in a container set with the -webkit-box display property.
+
+ // 6. Let tracks be the subset of video's list of text tracks that have as
+ // their rules for updating the text track rendering these rules for
+ // updating the display of WebVTT text tracks, and whose text track mode is
+ // showing or showing by default.
+ // 7. Let cues be an empty list of text track cues.
+ // 8. For each track track in tracks, append to cues all the cues from
+ // track's list of cues that have their text track cue active flag set.
+ CueList activeCues = video.cueTimeline().currentlyActiveCues();
+
+ // 9. If reset is false, then, for each text track cue cue in cues: if cue's
+ // text track cue display state has a set of CSS boxes, then add those boxes
+ // to output, and remove cue from cues.
+
+ // There is nothing explicitly to be done here, as all the caching occurs
+ // within the TextTrackCue instance itself. If parameters of the cue change,
+ // the display tree is cleared.
+
+ // 10. For each text track cue cue in cues that has not yet had
+ // corresponding CSS boxes added to output, in text track cue order, run the
+ // following substeps:
+ for (size_t i = 0; i < activeCues.size(); ++i) {
+ TextTrackCue* cue = activeCues[i].data();
+
+ ASSERT(cue->isActive());
+ if (!cue->track() || !cue->track()->isRendered() || !cue->isActive())
+ continue;
+
+ cue->updateDisplay(*this);
+ }
+
+ // 11. Return output.
+ if (hasChildren())
+ removeInlineStyleProperty(CSSPropertyDisplay);
+ else
+ setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
+}
+
+void TextTrackContainer::updateSizes(LayoutObject* mediaElementLayoutObject)
+{
+ if (!document().isActive())
+ return;
+
+ if (!mediaElementLayoutObject || !mediaElementLayoutObject->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
+ IntSize videoSize = toLayoutVideo(mediaElementLayoutObject)->videoBox().size();
+
+ if (m_videoSize == videoSize)
+ return;
+ m_videoSize = videoSize;
+
+ float smallestDimension = std::min(m_videoSize.height(), m_videoSize.width());
+
+ float fontSize = smallestDimension * 0.05f;
+ if (fontSize != m_fontSize) {
+ m_fontSize = fontSize;
+ setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue::CSS_PX);
+ }
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/html/track/TextTrackContainer.h ('k') | Source/core/layout/LayoutMediaControls.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698