OLD | NEW |
(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)); |
| 50 element->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 51 return element.release(); |
| 52 } |
| 53 |
| 54 LayoutObject* TextTrackContainer::createRenderer(const LayoutStyle&) |
| 55 { |
| 56 return new LayoutTextTrackContainer(this); |
| 57 } |
| 58 |
| 59 void TextTrackContainer::updateDisplay(HTMLMediaElement& mediaElement) |
| 60 { |
| 61 if (!mediaElement.closedCaptionsVisible()) { |
| 62 removeChildren(); |
| 63 return; |
| 64 } |
| 65 |
| 66 // 1. If the media element is an audio element, or is another playback |
| 67 // mechanism with no rendering area, abort these steps. There is nothing to |
| 68 // render. |
| 69 if (isHTMLAudioElement(mediaElement)) |
| 70 return; |
| 71 |
| 72 // 2. Let video be the media element or other playback mechanism. |
| 73 HTMLVideoElement& video = toHTMLVideoElement(mediaElement); |
| 74 |
| 75 // 3. Let output be an empty list of absolutely positioned CSS block boxes. |
| 76 |
| 77 // 4. If the user agent is exposing a user interface for video, add to |
| 78 // output one or more completely transparent positioned CSS block boxes that |
| 79 // cover the same region as the user interface. |
| 80 |
| 81 // 5. If the last time these rules were run, the user agent was not exposing |
| 82 // a user interface for video, but now it is, let reset be true. Otherwise, |
| 83 // let reset be false. |
| 84 |
| 85 // There is nothing to be done explicitly for 4th and 5th steps, as |
| 86 // everything is handled through CSS. The caption box is on top of the |
| 87 // controls box, in a container set with the -webkit-box display property. |
| 88 |
| 89 // 6. Let tracks be the subset of video's list of text tracks that have as |
| 90 // their rules for updating the text track rendering these rules for |
| 91 // updating the display of WebVTT text tracks, and whose text track mode is |
| 92 // showing or showing by default. |
| 93 // 7. Let cues be an empty list of text track cues. |
| 94 // 8. For each track track in tracks, append to cues all the cues from |
| 95 // track's list of cues that have their text track cue active flag set. |
| 96 CueList activeCues = video.cueTimeline().currentlyActiveCues(); |
| 97 |
| 98 // 9. If reset is false, then, for each text track cue cue in cues: if cue's |
| 99 // text track cue display state has a set of CSS boxes, then add those boxes |
| 100 // to output, and remove cue from cues. |
| 101 |
| 102 // There is nothing explicitly to be done here, as all the caching occurs |
| 103 // within the TextTrackCue instance itself. If parameters of the cue change, |
| 104 // the display tree is cleared. |
| 105 |
| 106 // 10. For each text track cue cue in cues that has not yet had |
| 107 // corresponding CSS boxes added to output, in text track cue order, run the |
| 108 // following substeps: |
| 109 for (size_t i = 0; i < activeCues.size(); ++i) { |
| 110 TextTrackCue* cue = activeCues[i].data(); |
| 111 |
| 112 ASSERT(cue->isActive()); |
| 113 if (!cue->track() || !cue->track()->isRendered() || !cue->isActive()) |
| 114 continue; |
| 115 |
| 116 cue->updateDisplay(*this); |
| 117 } |
| 118 |
| 119 // 11. Return output. |
| 120 if (hasChildren()) |
| 121 removeInlineStyleProperty(CSSPropertyDisplay); |
| 122 else |
| 123 setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 124 } |
| 125 |
| 126 void TextTrackContainer::updateSizes(LayoutObject* mediaElementLayoutObject) |
| 127 { |
| 128 if (!document().isActive()) |
| 129 return; |
| 130 |
| 131 if (!mediaElementLayoutObject || !mediaElementLayoutObject->isVideo()) |
| 132 return; |
| 133 |
| 134 // FIXME: The video size is used to calculate the font size (a workaround |
| 135 // for lack of per-spec vh/vw support) but the whole media element is used |
| 136 // for cue rendering. This is inconsistent. See also the somewhat related |
| 137 // spec bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28105 |
| 138 IntSize videoSize = toLayoutVideo(mediaElementLayoutObject)->videoBox().size
(); |
| 139 |
| 140 if (m_videoSize == videoSize) |
| 141 return; |
| 142 m_videoSize = videoSize; |
| 143 |
| 144 float smallestDimension = std::min(m_videoSize.height(), m_videoSize.width()
); |
| 145 |
| 146 float fontSize = smallestDimension * 0.05f; |
| 147 if (fontSize != m_fontSize) { |
| 148 m_fontSize = fontSize; |
| 149 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue:
:CSS_PX); |
| 150 } |
| 151 } |
| 152 |
| 153 } // namespace blink |
OLD | NEW |