Commit 83b9fc9e authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

Delay Picture-in-Picture window controls bounds update

This CL makes sure that Picture-in-Picture window controls bounds are
not updated too rapidly, causing UX/UI issues. When a Media Session
change happens, controls visibility will still be updated as before but
bounds now will be updated all at once after a small delay.

Bug: 960164
Change-Id: I6a66e4db76d8aeb2d56277fd46d51db1263e6c65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1598334Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#660924}
parent c195bf78
...@@ -2046,6 +2046,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest, ...@@ -2046,6 +2046,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
EXPECT_TRUE( EXPECT_TRUE(
overlay_window->next_track_controls_view_for_testing()->IsDrawn()); overlay_window->next_track_controls_view_for_testing()->IsDrawn());
gfx::Rect next_track_bounds =
overlay_window->next_track_controls_view_for_testing()
->GetContentsBounds();
// Unset action handler and check that Next Track button is not displayed when // Unset action handler and check that Next Track button is not displayed when
// video plays and mouse is hovering over the window. // video plays and mouse is hovering over the window.
ASSERT_TRUE(content::ExecuteScript( ASSERT_TRUE(content::ExecuteScript(
...@@ -2054,6 +2058,11 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest, ...@@ -2054,6 +2058,11 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
MoveMouseOver(overlay_window); MoveMouseOver(overlay_window);
EXPECT_FALSE( EXPECT_FALSE(
overlay_window->next_track_controls_view_for_testing()->IsDrawn()); overlay_window->next_track_controls_view_for_testing()->IsDrawn());
// Next Track button is still at the same previous location.
EXPECT_EQ(next_track_bounds,
overlay_window->next_track_controls_view_for_testing()
->GetContentsBounds());
} }
// Tests that a Previous Track button is displayed in the Picture-in-Picture // Tests that a Previous Track button is displayed in the Picture-in-Picture
...@@ -2092,6 +2101,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest, ...@@ -2092,6 +2101,10 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
EXPECT_TRUE( EXPECT_TRUE(
overlay_window->previous_track_controls_view_for_testing()->IsDrawn()); overlay_window->previous_track_controls_view_for_testing()->IsDrawn());
gfx::Rect previous_track_bounds =
overlay_window->previous_track_controls_view_for_testing()
->GetContentsBounds();
// Unset action handler and check that Previous Track button is not displayed // Unset action handler and check that Previous Track button is not displayed
// when video plays and mouse is hovering over the window. // when video plays and mouse is hovering over the window.
ASSERT_TRUE(content::ExecuteScript( ASSERT_TRUE(content::ExecuteScript(
...@@ -2100,6 +2113,11 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest, ...@@ -2100,6 +2113,11 @@ IN_PROC_BROWSER_TEST_F(MediaSessionPictureInPictureWindowControllerBrowserTest,
MoveMouseOver(overlay_window); MoveMouseOver(overlay_window);
EXPECT_FALSE( EXPECT_FALSE(
overlay_window->previous_track_controls_view_for_testing()->IsDrawn()); overlay_window->previous_track_controls_view_for_testing()->IsDrawn());
// Previous Track button is still at the same previous location.
EXPECT_EQ(previous_track_bounds,
overlay_window->previous_track_controls_view_for_testing()
->GetContentsBounds());
} }
// Tests that clicking the Skip Ad button in the Picture-in-Picture window // Tests that clicking the Skip Ad button in the Picture-in-Picture window
......
...@@ -79,6 +79,10 @@ const int kSecondaryControlBottomMargin = 16; ...@@ -79,6 +79,10 @@ const int kSecondaryControlBottomMargin = 16;
// Margin between controls. // Margin between controls.
const int kControlMargin = 32; const int kControlMargin = 32;
// Delay in milliseconds before controls bounds are updated. It is the same as
// HIDE_NOTIFICATION_DELAY_MILLIS in MediaSessionTabHelper.java
const int kUpdateControlsBoundsDelayMs = 1000;
// Returns the quadrant the OverlayWindowViews is primarily in on the current // Returns the quadrant the OverlayWindowViews is primarily in on the current
// work area. // work area.
OverlayWindowViews::WindowQuadrant GetCurrentWindowQuadrant( OverlayWindowViews::WindowQuadrant GetCurrentWindowQuadrant(
...@@ -511,6 +515,15 @@ void OverlayWindowViews::UpdateControlsVisibility(bool is_visible) { ...@@ -511,6 +515,15 @@ void OverlayWindowViews::UpdateControlsVisibility(bool is_visible) {
} }
void OverlayWindowViews::UpdateControlsBounds() { void OverlayWindowViews::UpdateControlsBounds() {
update_controls_bounds_timer_.reset(new base::OneShotTimer());
update_controls_bounds_timer_->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kUpdateControlsBoundsDelayMs),
base::BindOnce(&OverlayWindowViews::OnUpdateControlsBounds,
base::Unretained(this)));
}
void OverlayWindowViews::OnUpdateControlsBounds() {
// Adding an extra pixel to width/height makes sure the scrim covers the // Adding an extra pixel to width/height makes sure the scrim covers the
// entire window when the platform has fractional scaling applied. // entire window when the platform has fractional scaling applied.
gfx::Rect larger_window_bounds = gfx::Rect larger_window_bounds =
...@@ -689,6 +702,9 @@ void OverlayWindowViews::ShowInactive() { ...@@ -689,6 +702,9 @@ void OverlayWindowViews::ShowInactive() {
} }
#endif #endif
// Update immediately controls bounds.
OnUpdateControlsBounds();
// If this is not the first time the window is shown, this will be a no-op. // If this is not the first time the window is shown, this will be a no-op.
has_been_shown_ = true; has_been_shown_ = true;
} }
......
...@@ -121,6 +121,9 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -121,6 +121,9 @@ class OverlayWindowViews : public content::OverlayWindow,
// Updates the bounds of the controls. // Updates the bounds of the controls.
void UpdateControlsBounds(); void UpdateControlsBounds();
// Called when the bounds of the controls should be updated.
void OnUpdateControlsBounds();
// Update the size of each controls view as the size of the window changes. // Update the size of each controls view as the size of the window changes.
void UpdateButtonControlsSize(); void UpdateButtonControlsSize();
...@@ -218,6 +221,9 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -218,6 +221,9 @@ class OverlayWindowViews : public content::OverlayWindow,
// Automatically hides the controls a few seconds after user tap gesture. // Automatically hides the controls a few seconds after user tap gesture.
base::RetainingOneShotTimer hide_controls_timer_; base::RetainingOneShotTimer hide_controls_timer_;
// Timer used to update controls bounds.
std::unique_ptr<base::OneShotTimer> update_controls_bounds_timer_;
// Current playback state on the video in Picture-in-Picture window. It is // Current playback state on the video in Picture-in-Picture window. It is
// used to toggle play/pause/replay button. // used to toggle play/pause/replay button.
PlaybackState playback_state_for_testing_ = kEndOfVideo; PlaybackState playback_state_for_testing_ = kEndOfVideo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment