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; | 57 // Used to notify MediaControls of initial size. |
| 58 Optional<LayoutUnit> newWidth; |
| 59 Optional<LayoutUnit> newHeight; |
58 | 60 |
59 // Iterate the children in reverse order so that the media controls are laid | 61 // 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 | 62 // 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 | 63 // track rendering has an up-to-date position of the media controls for |
62 // overlap checking, see LayoutVTTCue. | 64 // overlap checking, see LayoutVTTCue. |
63 #if DCHECK_IS_ON() | 65 #if DCHECK_IS_ON() |
64 bool seenTextTrackContainer = false; | 66 bool seenTextTrackContainer = false; |
65 #endif | 67 #endif |
66 for (LayoutObject* child = m_children.lastChild(); child; | 68 for (LayoutObject* child = m_children.lastChild(); child; |
67 child = child->previousSibling()) { | 69 child = child->previousSibling()) { |
68 #if DCHECK_IS_ON() | 70 #if DCHECK_IS_ON() |
69 if (child->node()->isMediaControls()) | 71 if (child->node()->isMediaControls()) |
70 ASSERT(!seenTextTrackContainer); | 72 ASSERT(!seenTextTrackContainer); |
71 else if (child->node()->isTextTrackContainer()) | 73 else if (child->node()->isTextTrackContainer()) |
72 seenTextTrackContainer = true; | 74 seenTextTrackContainer = true; |
73 else | 75 else |
74 ASSERT_NOT_REACHED(); | 76 ASSERT_NOT_REACHED(); |
75 #endif | 77 #endif |
76 | 78 |
77 // TODO(mlamouri): we miss some layouts because needsLayout returns false in | 79 // 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 | 80 // some cases where we want to change the width of the controls because the |
79 // visible viewport has changed for example. | 81 // visible viewport has changed for example. |
80 if (newRect.size() == oldSize && !child->needsLayout()) | 82 if (newRect.size() == oldSize && !child->needsLayout()) |
81 continue; | 83 continue; |
82 | 84 |
83 LayoutUnit width = newRect.width(); | 85 LayoutUnit width = newRect.width(); |
84 if (child->node()->isMediaControls()) { | 86 if (child->node()->isMediaControls()) { |
85 width = computePanelWidth(newRect); | 87 width = computePanelWidth(newRect); |
86 newPanelWidth = width; | 88 newWidth = width; |
| 89 newHeight = newRect.height(); |
87 } | 90 } |
88 | 91 |
89 LayoutBox* layoutBox = toLayoutBox(child); | 92 LayoutBox* layoutBox = toLayoutBox(child); |
90 layoutBox->setLocation(newRect.location()); | 93 layoutBox->setLocation(newRect.location()); |
91 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS | 94 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS |
92 // width/height: inherit to match the media element size. | 95 // width/height: inherit to match the media element size. |
93 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed)); | 96 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed)); |
94 layoutBox->mutableStyleRef().setWidth(Length(width, Fixed)); | 97 layoutBox->mutableStyleRef().setWidth(Length(width, Fixed)); |
95 | 98 |
96 layoutBox->forceLayout(); | 99 layoutBox->forceLayout(); |
97 } | 100 } |
98 | 101 |
99 clearNeedsLayout(); | 102 clearNeedsLayout(); |
100 | 103 |
101 // Notify our MediaControls that a layout has happened. | 104 // Notify our MediaControls that a layout has happened. |
102 if (mediaElement() && mediaElement()->mediaControls() && | 105 if (mediaElement() && mediaElement()->mediaControls() && |
103 newPanelWidth.has_value()) { | 106 newWidth.has_value() && newHeight.has_value()) { |
104 if (!m_lastReportedPanelWidth.has_value() || | 107 mediaElement()->mediaControls()->onLayout(newWidth->toInt(), |
105 m_lastReportedPanelWidth.value() != newPanelWidth.value()) { | 108 newHeight->toInt()); |
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 } | 109 } |
112 } | 110 } |
113 | 111 |
114 bool LayoutMedia::isChildAllowed(LayoutObject* child, | 112 bool LayoutMedia::isChildAllowed(LayoutObject* child, |
115 const ComputedStyle& style) const { | 113 const ComputedStyle& style) const { |
116 // Two types of child layout objects are allowed: media controls | 114 // Two types of child layout objects are allowed: media controls |
117 // and the text track container. Filter children by node type. | 115 // and the text track container. Filter children by node type. |
118 ASSERT(child->node()); | 116 ASSERT(child->node()); |
119 | 117 |
120 // Out-of-flow positioned or floating child breaks layout hierarchy. | 118 // Out-of-flow positioned or floating child breaks layout hierarchy. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 .x()); | 167 .x()); |
170 const LayoutUnit newWidth = visibleWidth - absoluteXOffset; | 168 const LayoutUnit newWidth = visibleWidth - absoluteXOffset; |
171 | 169 |
172 if (newWidth < 0) | 170 if (newWidth < 0) |
173 return mediaRect.width(); | 171 return mediaRect.width(); |
174 | 172 |
175 return std::min(mediaRect.width(), visibleWidth - absoluteXOffset); | 173 return std::min(mediaRect.width(), visibleWidth - absoluteXOffset); |
176 } | 174 } |
177 | 175 |
178 } // namespace blink | 176 } // namespace blink |
OLD | NEW |