Index: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
index 3d5cff44270ef8cc0f3189a9601eb66169b10e9c..f1412e532ccabe46e398c64534d6f34c2e58772f 100644 |
--- a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
+++ b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
@@ -29,6 +29,9 @@ |
#include "bindings/core/v8/ExceptionState.h" |
#include "core/dom/ClientRect.h" |
#include "core/dom/Fullscreen.h" |
+#include "core/dom/ResizeObserver.h" |
+#include "core/dom/ResizeObserverCallback.h" |
+#include "core/dom/ResizeObserverEntry.h" |
#include "core/dom/TaskRunnerHelper.h" |
#include "core/events/MouseEvent.h" |
#include "core/frame/Settings.h" |
@@ -45,6 +48,18 @@ |
namespace blink { |
+namespace { |
+constexpr int kOverlayPlayButtonWidth = 48; |
mlamouri (slow - plz ping)
2017/02/27 18:22:58
style: leave empty line above `constexpr`
steimel
2017/02/28 00:59:47
Done.
|
+constexpr int kOverlayPlayButtonHeight = 48; |
+constexpr int kOverlayBottomMargin = 10; |
+constexpr int kAndroidMediaPanelHeight = 48; |
+ |
+constexpr int kMinWidthForOverlayPlayButton = kOverlayPlayButtonWidth; |
+constexpr int kMinHeightForOverlayPlayButton = kOverlayPlayButtonHeight + |
+ (2 * kAndroidMediaPanelHeight) + |
+ (2 * kOverlayBottomMargin); |
+} // namespace |
mlamouri (slow - plz ping)
2017/02/27 18:22:58
style: empty line + "anonymous namespace"
steimel
2017/02/28 00:59:47
Done.
|
+ |
// If you change this value, then also update the corresponding value in |
// LayoutTests/media/media-controls.js. |
static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
@@ -114,6 +129,33 @@ class MediaControls::BatchedControlUpdate { |
// Count of number open batches for controls visibility. |
int MediaControls::BatchedControlUpdate::s_batchDepth = 0; |
+class MediaControls::MediaControlsResizeObserverCallback |
mlamouri (slow - plz ping)
2017/02/27 18:22:58
nit: add `final`
steimel
2017/02/28 00:59:46
Done.
|
+ : public ResizeObserverCallback { |
+ public: |
+ explicit MediaControlsResizeObserverCallback(MediaControls* controls) |
+ : m_controls(controls) { |
+ DCHECK(controls); |
+ } |
+ ~MediaControlsResizeObserverCallback() override = default; |
+ |
+ void handleEvent(const HeapVector<Member<ResizeObserverEntry>>& entries, |
+ ResizeObserver* observer) override { |
+ DCHECK_EQ(1u, entries.size()); |
+ DCHECK_EQ(entries[0]->target(), m_controls->m_mediaElement); |
+ ClientRect* contentRect = entries[0]->contentRect(); |
+ m_controls->notifyElementSizeChanged(contentRect->width(), |
+ contentRect->height()); |
+ } |
+ |
+ DEFINE_INLINE_TRACE() { |
+ visitor->trace(m_controls); |
+ ResizeObserverCallback::trace(visitor); |
+ } |
+ |
+ private: |
+ Member<MediaControls> m_controls; |
+}; |
+ |
MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
: HTMLDivElement(mediaElement.document()), |
m_mediaElement(&mediaElement), |
@@ -146,12 +188,19 @@ MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
m_hideTimerBehaviorFlags(IgnoreNone), |
m_isMouseOverControls(false), |
m_isPausedForScrubbing(false), |
- m_panelWidthChangedTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, |
- &mediaElement.document()), |
- this, |
- &MediaControls::panelWidthChangedTimerFired), |
- m_panelWidth(0), |
- m_keepShowingUntilTimerFires(false) {} |
+ m_resizeObserver(ResizeObserver::create( |
+ mediaElement.document(), |
+ new MediaControlsResizeObserverCallback(this))), |
+ m_sizingInitialized(false), |
+ m_elementSizeChangedTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, |
+ &mediaElement.document()), |
+ this, |
+ &MediaControls::elementSizeChangedTimerFired), |
+ m_effectiveWidth(0), |
+ m_effectiveHeight(0), |
+ m_keepShowingUntilTimerFires(false) { |
+ m_resizeObserver->observe(m_mediaElement); |
+} |
MediaControls* MediaControls::create(HTMLMediaElement& mediaElement, |
ShadowRoot& shadowRoot) { |
@@ -788,25 +837,28 @@ void MediaControls::onExitedFullscreen() { |
startHideMediaControlsTimer(); |
} |
-void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { |
- // Don't bother to do any work if this matches the most recent panel |
- // width, since we're called after layout. |
+void MediaControls::notifyElementSizeChanged(int newWidth, int newHeight) { |
// Note that this code permits a bad frame on resize, since it is |
// run after the relayout / paint happens. It would be great to improve |
// this, but it would be even greater to move this code entirely to |
// JS and fix it there. |
- m_panelWidth = newWidth.toInt(); |
// Adjust for effective zoom. |
if (!m_panel->layoutObject() || !m_panel->layoutObject()->style()) |
return; |
- m_panelWidth = |
- ceil(m_panelWidth / m_panel->layoutObject()->style()->effectiveZoom()); |
- m_panelWidthChangedTimer.startOneShot(0, BLINK_FROM_HERE); |
+ int oldWidth = m_effectiveWidth; |
+ int oldHeight = m_effectiveHeight; |
+ m_effectiveWidth = |
+ ceil(newWidth / m_panel->layoutObject()->style()->effectiveZoom()); |
+ m_effectiveHeight = newHeight; |
+ |
+ // Don't bother to do any work if this matches the most recent size. |
+ if (oldWidth != m_effectiveWidth || oldHeight != m_effectiveHeight) |
+ m_elementSizeChangedTimer.startOneShot(0, BLINK_FROM_HERE); |
} |
-void MediaControls::panelWidthChangedTimerFired(TimerBase*) { |
+void MediaControls::elementSizeChangedTimerFired(TimerBase*) { |
computeWhichControlsFit(); |
} |
@@ -834,7 +886,7 @@ void MediaControls::computeWhichControlsFit() { |
// element. |
const int sliderMargin = 36; // Sliders have 18px margin on each side. |
- if (!m_panelWidth) { |
+ if (!m_effectiveWidth) { |
// No layout yet -- hide everything, then make them show up later. |
// This prevents the wrong controls from being shown briefly |
// immediately after the first layout and paint, but before we have |
@@ -879,7 +931,7 @@ void MediaControls::computeWhichControlsFit() { |
width += sliderMargin; |
element->shouldShowButtonInOverflowMenu(false); |
if (element->isWanted()) { |
- if (usedWidth + width <= m_panelWidth) { |
+ if (usedWidth + width <= m_effectiveWidth) { |
element->setDoesFit(true); |
usedWidth += width; |
} else { |
@@ -907,13 +959,20 @@ void MediaControls::computeWhichControlsFit() { |
if ((firstDisplacedElement == m_timeline.get()) || |
(firstDisplacedElement == m_volumeSlider.get())) |
width += sliderMargin; |
- if (usedWidth + width <= m_panelWidth) |
+ if (usedWidth + width <= m_effectiveWidth) |
firstDisplacedElement->setDoesFit(true); |
} |
} else if (overflowElements.size() == 1) { |
m_overflowMenu->setIsWanted(false); |
overflowElements.front()->setDoesFit(true); |
} |
+ |
+ // Decide if the overlay play button fits. |
+ if (m_effectiveWidth && m_effectiveHeight && m_overlayPlayButton) { |
+ bool doesFit = m_effectiveWidth >= kMinWidthForOverlayPlayButton && |
+ m_effectiveHeight >= kMinHeightForOverlayPlayButton; |
+ m_overlayPlayButton->setDoesFit(doesFit); |
+ } |
} |
void MediaControls::invalidate(Element* element) { |
@@ -935,6 +994,11 @@ void MediaControls::networkStateChanged() { |
invalidate(m_volumeSlider); |
} |
+void MediaControls::onLayout(int width, int height) { |
+ if (!m_sizingInitialized) |
+ notifyElementSizeChanged(width, height); |
mlamouri (slow - plz ping)
2017/02/27 18:22:58
I'm a bit concerned by this because you basically
steimel
2017/02/28 00:59:47
Done.
|
+} |
+ |
bool MediaControls::overflowMenuVisible() { |
return m_overflowList ? m_overflowList->isWanted() : false; |
} |
@@ -957,6 +1021,7 @@ void MediaControls::hideAllMenus() { |
} |
DEFINE_TRACE(MediaControls) { |
+ visitor->trace(m_resizeObserver); |
visitor->trace(m_mediaElement); |
visitor->trace(m_panel); |
visitor->trace(m_overlayPlayButton); |