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 89f8b67ed7531bd47f8619d88d91b4e59aeef7df..60856e0ecc30d59615ed71c031ef76b9a1730743 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; |
+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 |
+ |
// If you change this value, then also update the corresponding value in |
// LayoutTests/media/media-controls.js. |
static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
@@ -106,8 +121,37 @@ class MediaControls::BatchedControlUpdate { |
// Count of number open batches for controls visibility. |
int MediaControls::BatchedControlUpdate::s_batchDepth = 0; |
+class MediaControls::MediaControlsResizeObserverCallback |
+ : public ResizeObserverCallback { |
+ public: |
+ explicit MediaControlsResizeObserverCallback(MediaControls* controls) |
+ : m_controls(controls) { |
+ DCHECK(controls); |
+ } |
+ ~MediaControlsResizeObserverCallback() override{}; |
mlamouri (slow - plz ping)
2017/02/22 11:48:08
nit: s/{};/ = default;/
steimel
2017/02/23 00:53:48
Done.
|
+ |
+ void handleEvent(const HeapVector<Member<ResizeObserverEntry>>& entries, |
+ ResizeObserver* observer) override { |
+ for (const auto& entry : entries) { |
mlamouri (slow - plz ping)
2017/02/22 11:48:08
Is more than one entry expected? Should we DCHECK(
steimel
2017/02/23 00:53:48
Discussed offline. After looking at the spec, ther
|
+ m_controls->notifyPanelSizeChanged((int)entry->contentRect()->width(), |
+ (int)entry->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_resizeObserver(ResizeObserver::create( |
+ mediaElement.document(), |
+ new MediaControlsResizeObserverCallback(this))), |
m_mediaElement(&mediaElement), |
m_overlayEnclosure(nullptr), |
m_overlayPlayButton(nullptr), |
@@ -138,12 +182,15 @@ 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_panelSizeChangedTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, |
+ &mediaElement.document()), |
+ this, |
+ &MediaControls::panelSizeChangedTimerFired), |
m_panelWidth(0), |
- m_keepShowingUntilTimerFires(false) {} |
+ m_panelHeight(0), |
+ m_keepShowingUntilTimerFires(false) { |
+ m_resizeObserver->observe(m_mediaElement); |
mlamouri (slow - plz ping)
2017/02/22 11:48:08
Would it make sense to initialise the current size
steimel
2017/02/23 00:53:48
Discussed offline, but re-adding some code in Layo
|
+} |
MediaControls* MediaControls::create(HTMLMediaElement& mediaElement, |
ShadowRoot& shadowRoot) { |
@@ -781,25 +828,27 @@ void MediaControls::onExitedFullscreen() { |
startHideMediaControlsTimer(); |
} |
-void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { |
+void MediaControls::notifyPanelSizeChanged(int newWidth, int newHeight) { |
// Don't bother to do any work if this matches the most recent panel |
- // width, since we're called after layout. |
+ // size, since we're called after layout. |
// 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(); |
+ m_panelWidth = newWidth; |
+ m_panelHeight = newHeight; |
mlamouri (slow - plz ping)
2017/02/22 11:48:08
Is it really still the panel width/height? Shouldn
steimel
2017/02/23 00:53:48
Done.
|
// 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); |
+ m_panelSizeChangedTimer.startOneShot(0, BLINK_FROM_HERE); |
} |
-void MediaControls::panelWidthChangedTimerFired(TimerBase*) { |
+void MediaControls::panelSizeChangedTimerFired(TimerBase*) { |
computeWhichControlsFit(); |
} |
@@ -910,6 +959,13 @@ void MediaControls::computeWhichControlsFit() { |
m_overflowMenu->setIsWanted(false); |
overflowElements.front()->setDoesFit(true); |
} |
+ |
+ // Decide if the overlay play button fits. |
+ if (m_panelWidth && m_panelHeight && m_overlayPlayButton) { |
+ bool doesFit = m_panelWidth >= kMinWidthForOverlayPlayButton && |
+ m_panelHeight >= kMinHeightForOverlayPlayButton; |
+ m_overlayPlayButton->setDoesFit(doesFit); |
+ } |
} |
void MediaControls::invalidate(Element* element) { |
@@ -953,6 +1009,7 @@ void MediaControls::hideAllMenus() { |
} |
DEFINE_TRACE(MediaControls) { |
+ visitor->trace(m_resizeObserver); |
visitor->trace(m_mediaElement); |
visitor->trace(m_panel); |
visitor->trace(m_overlayPlayButton); |