OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. | 3 * Copyright (C) 2012 Google Inc. |
4 * All rights reserved. | 4 * All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 11 matching lines...) Expand all Loading... |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/layout/LayoutTextTrackContainer.h" | 29 #include "core/layout/LayoutTextTrackContainer.h" |
30 | 30 |
31 #include "core/frame/DeprecatedScheduleStyleRecalcDuringLayout.h" | 31 #include "core/frame/DeprecatedScheduleStyleRecalcDuringLayout.h" |
32 #include "core/html/HTMLMediaElement.h" | 32 #include "core/layout/LayoutVideo.h" |
33 #include "core/html/track/TextTrackContainer.h" | |
34 | 33 |
35 namespace blink { | 34 namespace blink { |
36 | 35 |
37 LayoutTextTrackContainer::LayoutTextTrackContainer(Element* element) | 36 LayoutTextTrackContainer::LayoutTextTrackContainer(Element* element) |
38 : LayoutBlockFlow(element) | 37 : LayoutBlockFlow(element) |
| 38 , m_fontSize(0) |
39 { | 39 { |
40 } | 40 } |
41 | 41 |
42 void LayoutTextTrackContainer::layout() | 42 void LayoutTextTrackContainer::layout() |
43 { | 43 { |
44 LayoutBlockFlow::layout(); | 44 LayoutBlockFlow::layout(); |
45 if (style()->display() == NONE) | 45 if (style()->display() == NONE) |
46 return; | 46 return; |
47 | 47 |
48 DeprecatedScheduleStyleRecalcDuringLayout marker(node()->document().lifecycl
e()); | 48 DeprecatedScheduleStyleRecalcDuringLayout marker(node()->document().lifecycl
e()); |
49 | 49 |
50 TextTrackContainer* textTrackContainer = toTextTrackContainer(node()); | |
51 ASSERT(textTrackContainer); | |
52 // Overlay enclosure -> Media controls -> Media element | 50 // Overlay enclosure -> Media controls -> Media element |
53 LayoutObject* mediaElementLayoutObject = parent()->parent()->parent(); | 51 LayoutObject* mediaElementLayoutObject = parent()->parent()->parent(); |
54 textTrackContainer->updateSizes(mediaElementLayoutObject); | 52 if (!mediaElementLayoutObject || !mediaElementLayoutObject->isVideo()) |
| 53 return; |
| 54 if (updateSizes(toLayoutVideo(*mediaElementLayoutObject))) |
| 55 toElement(node())->setInlineStyleProperty(CSSPropertyFontSize, m_fontSiz
e, CSSPrimitiveValue::CSS_PX); |
| 56 } |
| 57 |
| 58 bool LayoutTextTrackContainer::updateSizes(const LayoutVideo& videoLayoutObject) |
| 59 { |
| 60 // FIXME: The video size is used to calculate the font size (a workaround |
| 61 // for lack of per-spec vh/vw support) but the whole media element is used |
| 62 // for cue rendering. This is inconsistent. See also the somewhat related |
| 63 // spec bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28105 |
| 64 IntSize videoSize = videoLayoutObject.videoBox().size(); |
| 65 if (m_videoSize == videoSize) |
| 66 return false; |
| 67 m_videoSize = videoSize; |
| 68 |
| 69 float smallestDimension = std::min(m_videoSize.height(), m_videoSize.width()
); |
| 70 |
| 71 float fontSize = smallestDimension * 0.05f; |
| 72 if (m_fontSize == fontSize) |
| 73 return false; |
| 74 m_fontSize = fontSize; |
| 75 return true; |
55 } | 76 } |
56 | 77 |
57 } // namespace blink | 78 } // namespace blink |
OLD | NEW |