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

Side by Side Diff: Source/core/html/track/TextTrackContainer.cpp

Issue 949203002: Separate the text track container from the media controls (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: same size as media controls Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "config.h"
31 #include "core/html/track/TextTrackContainer.h"
32
33 #include "core/html/HTMLVideoElement.h"
34 #include "core/html/track/CueTimeline.h"
35 #include "core/layout/LayoutTextTrackContainer.h"
36 #include "core/layout/LayoutVideo.h"
37
38 namespace blink {
39
40 TextTrackContainer::TextTrackContainer(Document& document)
41 : HTMLDivElement(document)
42 , m_fontSize(0)
43 {
44 }
45
46 PassRefPtrWillBeRawPtr<TextTrackContainer> TextTrackContainer::create(Document& document)
47 {
48 RefPtrWillBeRawPtr<TextTrackContainer> element = adoptRefWillBeNoop(new Text TrackContainer(document));
49 element->setShadowPseudoId(AtomicString("-webkit-media-text-track-container" , AtomicString::ConstructFromLiteral));
philipj_slow 2015/02/26 09:51:52 Maybe this should still be under html/shadow/ beca
50 return element.release();
51 }
52
53 LayoutObject* TextTrackContainer::createRenderer(const LayoutStyle&)
54 {
55 return new LayoutTextTrackContainer(this);
56 }
57
58 void TextTrackContainer::updateDisplay(HTMLMediaElement& mediaElement)
59 {
60 if (!mediaElement.closedCaptionsVisible()) {
61 removeChildren();
62 return;
63 }
64
65 // 1. If the media element is an audio element, or is another playback
66 // mechanism with no rendering area, abort these steps. There is nothing to
67 // render.
68 if (isHTMLAudioElement(mediaElement))
69 return;
70
71 // 2. Let video be the media element or other playback mechanism.
72 HTMLVideoElement& video = toHTMLVideoElement(mediaElement);
73
74 // 3. Let output be an empty list of absolutely positioned CSS block boxes.
75
76 // 4. If the user agent is exposing a user interface for video, add to
77 // output one or more completely transparent positioned CSS block boxes that
78 // cover the same region as the user interface.
79
80 // 5. If the last time these rules were run, the user agent was not exposing
81 // a user interface for video, but now it is, let reset be true. Otherwise,
82 // let reset be false.
83
84 // There is nothing to be done explicitly for 4th and 5th steps, as
85 // everything is handled through CSS. The caption box is on top of the
86 // controls box, in a container set with the -webkit-box display property.
87
88 // 6. Let tracks be the subset of video's list of text tracks that have as
89 // their rules for updating the text track rendering these rules for
90 // updating the display of WebVTT text tracks, and whose text track mode is
91 // showing or showing by default.
92 // 7. Let cues be an empty list of text track cues.
93 // 8. For each track track in tracks, append to cues all the cues from
94 // track's list of cues that have their text track cue active flag set.
95 CueList activeCues = video.cueTimeline().currentlyActiveCues();
96
97 // 9. If reset is false, then, for each text track cue cue in cues: if cue's
98 // text track cue display state has a set of CSS boxes, then add those boxes
99 // to output, and remove cue from cues.
100
101 // There is nothing explicitly to be done here, as all the caching occurs
102 // within the TextTrackCue instance itself. If parameters of the cue change,
103 // the display tree is cleared.
104
105 // 10. For each text track cue cue in cues that has not yet had
106 // corresponding CSS boxes added to output, in text track cue order, run the
107 // following substeps:
108 for (size_t i = 0; i < activeCues.size(); ++i) {
109 TextTrackCue* cue = activeCues[i].data();
110
111 ASSERT(cue->isActive());
112 if (!cue->track() || !cue->track()->isRendered() || !cue->isActive())
113 continue;
114
115 cue->updateDisplay(*this);
116 }
117
118 // 11. Return output.
119 }
120
121 void TextTrackContainer::updateSizes(HTMLMediaElement& mediaElement)
122 {
123 if (!document().isActive())
124 return;
125
126 IntRect videoBox;
127
128 if (!mediaElement.renderer() || !mediaElement.renderer()->isVideo())
129 return;
130 videoBox = toLayoutVideo(mediaElement.renderer())->videoBox();
philipj_slow 2015/02/26 09:51:52 I don't understand why the video size is used here
fs 2015/02/26 12:30:51 AFAIK though this is only used for the thing below
philipj_slow 2015/02/27 07:13:51 I've added a FIXME clarifying what I found odd her
131
132 if (m_videoDisplaySize == videoBox)
133 return;
134 m_videoDisplaySize = videoBox;
135
136 float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_vid eoDisplaySize.size().width());
137
138 float fontSize = smallestDimension * 0.05f;
139 if (fontSize != m_fontSize) {
140 m_fontSize = fontSize;
141 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue: :CSS_PX);
142 }
143 }
144
145 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698