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

Unified Diff: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp

Issue 2701433003: Hide overlay play button if it can't be shown without clipping (Closed)
Patch Set: mlamouri feedback Created 3 years, 10 months 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 side-by-side diff with in-line comments
Download patch
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..702dcb99e01414105939cd47c5cdac18b407f5a0 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,20 @@
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);
+
+} // anonymous namespace
+
// If you change this value, then also update the corresponding value in
// LayoutTests/media/media-controls.js.
static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3;
@@ -114,6 +131,31 @@ class MediaControls::BatchedControlUpdate {
// Count of number open batches for controls visibility.
int MediaControls::BatchedControlUpdate::s_batchDepth = 0;
+class MediaControls::MediaControlsResizeObserverCallback final
+ : 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);
+ m_controls->notifyElementSizeChanged(entries[0]->contentRect());
+ }
+
+ 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,18 @@ 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_elementSizeChangedTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer,
+ &mediaElement.document()),
+ this,
+ &MediaControls::elementSizeChangedTimerFired),
+ m_effectiveWidth(0),
+ m_effectiveHeight(0),
mlamouri (slow - plz ping) 2017/02/28 16:03:14 m_size is set to (0,0) by default
steimel 2017/03/01 15:58:31 Acknowledged.
+ m_keepShowingUntilTimerFires(false) {
+ m_resizeObserver->observe(m_mediaElement);
+}
MediaControls* MediaControls::create(HTMLMediaElement& mediaElement,
ShadowRoot& shadowRoot) {
@@ -788,25 +836,31 @@ 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(ClientRect* newSize) {
// 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();
+
+ int oldWidth = m_effectiveWidth;
+ int oldHeight = m_effectiveHeight;
+ m_effectiveWidth = newSize->width();
+ m_effectiveHeight = newSize->height();
mlamouri (slow - plz ping) 2017/02/28 16:03:14 IntSize oldSize = m_size; m_size = newSize; // or
steimel 2017/03/01 15:58:31 Done.
// Adjust for effective zoom.
- if (!m_panel->layoutObject() || !m_panel->layoutObject()->style())
- return;
- m_panelWidth =
- ceil(m_panelWidth / m_panel->layoutObject()->style()->effectiveZoom());
+ if (m_panel->layoutObject() && m_panel->layoutObject()->style()) {
+ m_effectiveWidth = ceil(m_effectiveWidth /
+ m_panel->layoutObject()->style()->effectiveZoom());
+ m_effectiveHeight = ceil(m_effectiveHeight /
+ m_panel->layoutObject()->style()->effectiveZoom());
+ }
- m_panelWidthChangedTimer.startOneShot(0, BLINK_FROM_HERE);
+ // Don't bother to do any work if this matches the most recent size.
+ if (oldWidth != m_effectiveWidth || oldHeight != m_effectiveHeight)
mlamouri (slow - plz ping) 2017/02/28 16:03:14 if (oldSize != newSize)
steimel 2017/03/01 15:58:31 Done.
+ m_elementSizeChangedTimer.startOneShot(0, BLINK_FROM_HERE);
}
-void MediaControls::panelWidthChangedTimerFired(TimerBase*) {
+void MediaControls::elementSizeChangedTimerFired(TimerBase*) {
computeWhichControlsFit();
}
@@ -834,7 +888,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 +933,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 +961,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) {
mlamouri (slow - plz ping) 2017/02/28 16:03:14 `if (!m_size.isEmpty() && m_overlayPlayButton) {`
steimel 2017/03/01 15:58:31 Done.
+ bool doesFit = m_effectiveWidth >= kMinWidthForOverlayPlayButton &&
+ m_effectiveHeight >= kMinHeightForOverlayPlayButton;
+ m_overlayPlayButton->setDoesFit(doesFit);
+ }
}
void MediaControls::invalidate(Element* element) {
@@ -957,6 +1018,7 @@ void MediaControls::hideAllMenus() {
}
DEFINE_TRACE(MediaControls) {
+ visitor->trace(m_resizeObserver);
visitor->trace(m_mediaElement);
visitor->trace(m_panel);
visitor->trace(m_overlayPlayButton);

Powered by Google App Engine
This is Rietveld 408576698