OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 void LayoutMedia::layout() { | 48 void LayoutMedia::layout() { |
49 LayoutSize oldSize = contentBoxRect().size(); | 49 LayoutSize oldSize = contentBoxRect().size(); |
50 | 50 |
51 LayoutImage::layout(); | 51 LayoutImage::layout(); |
52 | 52 |
53 LayoutRect newRect = contentBoxRect(); | 53 LayoutRect newRect = contentBoxRect(); |
54 | 54 |
55 LayoutState state(*this); | 55 LayoutState state(*this); |
56 | 56 |
57 Optional<LayoutUnit> newPanelWidth; | |
58 | |
59 // Iterate the children in reverse order so that the media controls are laid | 57 // Iterate the children in reverse order so that the media controls are laid |
60 // out before the text track container. This is to ensure that the text | 58 // out before the text track container. This is to ensure that the text |
61 // track rendering has an up-to-date position of the media controls for | 59 // track rendering has an up-to-date position of the media controls for |
62 // overlap checking, see LayoutVTTCue. | 60 // overlap checking, see LayoutVTTCue. |
63 #if DCHECK_IS_ON() | 61 #if DCHECK_IS_ON() |
64 bool seenTextTrackContainer = false; | 62 bool seenTextTrackContainer = false; |
65 #endif | 63 #endif |
66 for (LayoutObject* child = m_children.lastChild(); child; | 64 for (LayoutObject* child = m_children.lastChild(); child; |
67 child = child->previousSibling()) { | 65 child = child->previousSibling()) { |
68 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
69 if (child->node()->isMediaControls()) | 67 if (child->node()->isMediaControls()) |
70 ASSERT(!seenTextTrackContainer); | 68 ASSERT(!seenTextTrackContainer); |
71 else if (child->node()->isTextTrackContainer()) | 69 else if (child->node()->isTextTrackContainer()) |
72 seenTextTrackContainer = true; | 70 seenTextTrackContainer = true; |
73 else | 71 else |
74 ASSERT_NOT_REACHED(); | 72 ASSERT_NOT_REACHED(); |
75 #endif | 73 #endif |
76 | 74 |
77 // TODO(mlamouri): we miss some layouts because needsLayout returns false in | 75 // TODO(mlamouri): we miss some layouts because needsLayout returns false in |
78 // some cases where we want to change the width of the controls because the | 76 // some cases where we want to change the width of the controls because the |
79 // visible viewport has changed for example. | 77 // visible viewport has changed for example. |
80 if (newRect.size() == oldSize && !child->needsLayout()) | 78 if (newRect.size() == oldSize && !child->needsLayout()) |
81 continue; | 79 continue; |
82 | 80 |
83 LayoutUnit width = newRect.width(); | 81 LayoutUnit width = newRect.width(); |
84 if (child->node()->isMediaControls()) { | 82 if (child->node()->isMediaControls()) { |
85 width = computePanelWidth(newRect); | 83 width = computePanelWidth(newRect); |
86 newPanelWidth = width; | |
mlamouri (slow - plz ping)
2017/03/07 19:07:30
Here, we set `width` then pass it to `newPanelWidt
mlamouri (slow - plz ping)
2017/03/08 19:13:04
Scratch that comment :)
steimel
2017/03/09 16:42:24
Acknowledged.
| |
87 } | 84 } |
88 | 85 |
89 LayoutBox* layoutBox = toLayoutBox(child); | 86 LayoutBox* layoutBox = toLayoutBox(child); |
90 layoutBox->setLocation(newRect.location()); | 87 layoutBox->setLocation(newRect.location()); |
91 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS | 88 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS |
92 // width/height: inherit to match the media element size. | 89 // width/height: inherit to match the media element size. |
93 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed)); | 90 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed)); |
94 layoutBox->mutableStyleRef().setWidth(Length(width, Fixed)); | 91 layoutBox->mutableStyleRef().setWidth(Length(width, Fixed)); |
95 | 92 |
96 layoutBox->forceLayout(); | 93 layoutBox->forceLayout(); |
97 } | 94 } |
98 | 95 |
99 clearNeedsLayout(); | 96 clearNeedsLayout(); |
100 | |
101 // Notify our MediaControls that a layout has happened. | |
102 if (mediaElement() && mediaElement()->mediaControls() && | |
103 newPanelWidth.has_value()) { | |
104 if (!m_lastReportedPanelWidth.has_value() || | |
105 m_lastReportedPanelWidth.value() != newPanelWidth.value()) { | |
106 mediaElement()->mediaControls()->notifyPanelWidthChanged( | |
107 newPanelWidth.value()); | |
108 // Store the last value we reported, so we know if it has changed. | |
109 m_lastReportedPanelWidth = newPanelWidth.value(); | |
110 } | |
111 } | |
112 } | 97 } |
113 | 98 |
114 bool LayoutMedia::isChildAllowed(LayoutObject* child, | 99 bool LayoutMedia::isChildAllowed(LayoutObject* child, |
115 const ComputedStyle& style) const { | 100 const ComputedStyle& style) const { |
116 // Two types of child layout objects are allowed: media controls | 101 // Two types of child layout objects are allowed: media controls |
117 // and the text track container. Filter children by node type. | 102 // and the text track container. Filter children by node type. |
118 ASSERT(child->node()); | 103 ASSERT(child->node()); |
119 | 104 |
120 // Out-of-flow positioned or floating child breaks layout hierarchy. | 105 // Out-of-flow positioned or floating child breaks layout hierarchy. |
121 // This check can be removed if ::-webkit-media-controls is made internal. | 106 // This check can be removed if ::-webkit-media-controls is made internal. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 .x()); | 154 .x()); |
170 const LayoutUnit newWidth = visibleWidth - absoluteXOffset; | 155 const LayoutUnit newWidth = visibleWidth - absoluteXOffset; |
171 | 156 |
172 if (newWidth < 0) | 157 if (newWidth < 0) |
173 return mediaRect.width(); | 158 return mediaRect.width(); |
174 | 159 |
175 return std::min(mediaRect.width(), visibleWidth - absoluteXOffset); | 160 return std::min(mediaRect.width(), visibleWidth - absoluteXOffset); |
176 } | 161 } |
177 | 162 |
178 } // namespace blink | 163 } // namespace blink |
OLD | NEW |