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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutMedia.cpp

Issue 2470503003: Media controls max width is the width of the viewport. (Closed)
Patch Set: w/ tests Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutMedia.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/layout/LayoutMedia.h" 26 #include "core/layout/LayoutMedia.h"
27 27
28 #include "core/frame/FrameHost.h"
29 #include "core/frame/FrameView.h"
30 #include "core/frame/VisualViewport.h"
28 #include "core/html/HTMLMediaElement.h" 31 #include "core/html/HTMLMediaElement.h"
29 #include "core/html/shadow/MediaControls.h" 32 #include "core/html/shadow/MediaControls.h"
30 #include "core/layout/LayoutView.h" 33 #include "core/layout/LayoutView.h"
34 #include "core/page/Page.h"
31 35
32 namespace blink { 36 namespace blink {
33 37
34 LayoutMedia::LayoutMedia(HTMLMediaElement* video) : LayoutImage(video) { 38 LayoutMedia::LayoutMedia(HTMLMediaElement* video) : LayoutImage(video) {
35 setImageResource(LayoutImageResource::create()); 39 setImageResource(LayoutImageResource::create());
36 } 40 }
37 41
38 LayoutMedia::~LayoutMedia() {} 42 LayoutMedia::~LayoutMedia() {}
39 43
40 HTMLMediaElement* LayoutMedia::mediaElement() const { 44 HTMLMediaElement* LayoutMedia::mediaElement() const {
41 return toHTMLMediaElement(node()); 45 return toHTMLMediaElement(node());
42 } 46 }
43 47
44 void LayoutMedia::layout() { 48 void LayoutMedia::layout() {
45 LayoutSize oldSize = contentBoxRect().size(); 49 LayoutSize oldSize = contentBoxRect().size();
46 50
47 LayoutImage::layout(); 51 LayoutImage::layout();
48 52
49 LayoutRect newRect = contentBoxRect(); 53 LayoutRect newRect = contentBoxRect();
50 54
51 LayoutState state(*this); 55 LayoutState state(*this);
52 56
57 Optional<LayoutUnit> newPanelWidth;
58
53 // Iterate the children in reverse order so that the media controls are laid 59 // Iterate the children in reverse order so that the media controls are laid
54 // out before the text track container. This is to ensure that the text 60 // out before the text track container. This is to ensure that the text
55 // track rendering has an up-to-date position of the media controls for 61 // track rendering has an up-to-date position of the media controls for
56 // overlap checking, see LayoutVTTCue. 62 // overlap checking, see LayoutVTTCue.
57 #if ENABLE(ASSERT) 63 #if ENABLE(ASSERT)
58 bool seenTextTrackContainer = false; 64 bool seenTextTrackContainer = false;
59 #endif 65 #endif
60 for (LayoutObject* child = m_children.lastChild(); child; 66 for (LayoutObject* child = m_children.lastChild(); child;
61 child = child->previousSibling()) { 67 child = child->previousSibling()) {
62 #if ENABLE(ASSERT) 68 #if ENABLE(ASSERT)
63 if (child->node()->isMediaControls()) 69 if (child->node()->isMediaControls())
64 ASSERT(!seenTextTrackContainer); 70 ASSERT(!seenTextTrackContainer);
65 else if (child->node()->isTextTrackContainer()) 71 else if (child->node()->isTextTrackContainer())
66 seenTextTrackContainer = true; 72 seenTextTrackContainer = true;
67 else 73 else
68 ASSERT_NOT_REACHED(); 74 ASSERT_NOT_REACHED();
69 #endif 75 #endif
70 76
77 // 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
79 // visible viewport has changed for example.
71 if (newRect.size() == oldSize && !child->needsLayout()) 80 if (newRect.size() == oldSize && !child->needsLayout())
72 continue; 81 continue;
73 82
83 LayoutUnit width = newRect.width();
84 if (child->node()->isMediaControls()) {
85 width = computePanelWidth(newRect);
86 if (width != oldSize.width())
87 newPanelWidth = width;
88 }
89
74 LayoutBox* layoutBox = toLayoutBox(child); 90 LayoutBox* layoutBox = toLayoutBox(child);
75 layoutBox->setLocation(newRect.location()); 91 layoutBox->setLocation(newRect.location());
76 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS 92 // TODO(foolip): Remove the mutableStyleRef() and depend on CSS
77 // width/height: inherit to match the media element size. 93 // width/height: inherit to match the media element size.
78 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed)); 94 layoutBox->mutableStyleRef().setHeight(Length(newRect.height(), Fixed));
79 layoutBox->mutableStyleRef().setWidth(Length(newRect.width(), Fixed)); 95 layoutBox->mutableStyleRef().setWidth(Length(width, Fixed));
96
80 layoutBox->forceLayout(); 97 layoutBox->forceLayout();
81 } 98 }
82 99
83 clearNeedsLayout(); 100 clearNeedsLayout();
84 101
85 // Notify our MediaControls that a layout has happened. 102 // Notify our MediaControls that a layout has happened.
86 if (mediaElement() && mediaElement()->mediaControls() && 103 if (mediaElement() && mediaElement()->mediaControls() &&
87 newRect.width() != oldSize.width()) 104 newPanelWidth.has_value()) {
88 mediaElement()->mediaControls()->notifyPanelWidthChanged(newRect.width()); 105 mediaElement()->mediaControls()->notifyPanelWidthChanged(
106 newPanelWidth.value());
107 }
89 } 108 }
90 109
91 bool LayoutMedia::isChildAllowed(LayoutObject* child, 110 bool LayoutMedia::isChildAllowed(LayoutObject* child,
92 const ComputedStyle&) const { 111 const ComputedStyle&) const {
93 // Two types of child layout objects are allowed: media controls 112 // Two types of child layout objects are allowed: media controls
94 // and the text track container. Filter children by node type. 113 // and the text track container. Filter children by node type.
95 ASSERT(child->node()); 114 ASSERT(child->node());
96 115
97 // The user agent stylesheet (mediaControls.css) has 116 // The user agent stylesheet (mediaControls.css) has
98 // ::-webkit-media-controls { display: flex; }. If author style 117 // ::-webkit-media-controls { display: flex; }. If author style
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 element->notifyPositionMayHaveChanged(visibleRect); 151 element->notifyPositionMayHaveChanged(visibleRect);
133 } 152 }
134 153
135 void LayoutMedia::setRequestPositionUpdates(bool want) { 154 void LayoutMedia::setRequestPositionUpdates(bool want) {
136 if (want) 155 if (want)
137 view()->registerMediaForPositionChangeNotification(*this); 156 view()->registerMediaForPositionChangeNotification(*this);
138 else 157 else
139 view()->unregisterMediaForPositionChangeNotification(*this); 158 view()->unregisterMediaForPositionChangeNotification(*this);
140 } 159 }
141 160
161 LayoutUnit LayoutMedia::computePanelWidth(const LayoutRect& mediaRect) const {
162 FrameHost* frameHost = document().frameHost();
163 LocalFrame* mainFrame = document().page()->deprecatedLocalMainFrame();
164 FrameView* pageView = mainFrame ? mainFrame->view() : nullptr;
165 if (!frameHost || !mainFrame || !pageView)
166 return mediaRect.width();
167
168 if (pageView->horizontalScrollbarMode() != ScrollbarAlwaysOff)
169 return mediaRect.width();
170
171 // On desktop, this will include scrollbars when they stay visible.
172 const LayoutUnit visibleWidth(frameHost->visualViewport().visibleWidth());
173 const LayoutUnit absoluteXOffset(
174 localToAbsolute(
175 FloatPoint(mediaRect.location()),
176 UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries)
177 .x());
178
179 return std::min(mediaRect.width(), visibleWidth - absoluteXOffset);
eae 2016/11/01 16:56:25 Can visibleWidth - absoluteXOffset ever go negativ
180 }
181
142 } // namespace blink 182 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutMedia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698