Set larger maximum Picture-in-Picture window size

This CL makes sure the Picture-in-Picture window has a max size of
80% of the display width/height, not 50% anymore.

Bug: 1127555, 1318830, 1324436
Change-Id: I89d357219dec863d25be40218f5f0cb318a1499e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3904310
Reviewed-by: Tommy Steimel <steimel@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/main@{#1049221}
diff --git a/chrome/browser/ui/views/overlay/document_overlay_window_views_unittest.cc b/chrome/browser/ui/views/overlay/document_overlay_window_views_unittest.cc
index 37f94af3..2d78948 100644
--- a/chrome/browser/ui/views/overlay/document_overlay_window_views_unittest.cc
+++ b/chrome/browser/ui/views/overlay/document_overlay_window_views_unittest.cc
@@ -193,9 +193,9 @@
 
   // Must fit within the minimum height of 146. But with the aspect ratio of
   // 40:1 the width gets exceedingly big and must be limited to the maximum of
-  // 500. Thus, letterboxing is unavoidable.
-  EXPECT_EQ(gfx::Size(500, 100), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(500, 0),
+  // 800. Thus, letterboxing is unavoidable.
+  EXPECT_EQ(gfx::Size(800, 100), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(800, 0),
             overlay_window().document_layer_for_testing()->size());
 }
 
@@ -204,9 +204,9 @@
 
   // Must fit within the minimum width of 260. But with the aspect ratio of
   // 1:40 the height gets exceedingly big and must be limited to the maximum of
-  // 500. Thus, pillarboxing is unavoidable.
-  EXPECT_EQ(gfx::Size(200, 500), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(13, 470),
+  // 800. Thus, pillarboxing is unavoidable.
+  EXPECT_EQ(gfx::Size(200, 800), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(20, 770),
             overlay_window().document_layer_for_testing()->size());
 }
 
@@ -306,25 +306,25 @@
   // The initial size is determined by the work area and the video natural size
   // (aspect ratio).
   EXPECT_EQ(gfx::Size(1200, 800), overlay_window().GetBounds().size());
-  // The initial maximum size is a quarter of the work area.
-  EXPECT_EQ(gfx::Size(2000, 2000), overlay_window().GetMaximumSize());
+  // The initial maximum size is 80% of the work area.
+  EXPECT_EQ(gfx::Size(3200, 3200), overlay_window().GetMaximumSize());
 
   // If the maximum size increases then we should keep the existing window size.
   SetDisplayWorkArea({0, 0, 8000, 8000});
   EXPECT_EQ(gfx::Size(1200, 800), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(4000, 4000), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(6400, 6400), overlay_window().GetMaximumSize());
 
   // If the maximum size decreases then we should shrink to fit.
   SetDisplayWorkArea({0, 0, 1000, 2000});
-  EXPECT_EQ(gfx::Size(500, 800), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(500, 1000), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(800, 800), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(800, 1600), overlay_window().GetMaximumSize());
 }
 
 TEST_F(DocumentOverlayWindowViewsTest, IgnoreInvalidMaximumSize) {
-  ASSERT_EQ(gfx::Size(500, 500), overlay_window().GetMaximumSize());
+  ASSERT_EQ(gfx::Size(800, 800), overlay_window().GetMaximumSize());
 
   SetDisplayWorkArea({0, 0, 0, 0});
-  EXPECT_EQ(gfx::Size(500, 500), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(800, 800), overlay_window().GetMaximumSize());
 }
 
 TEST_F(DocumentOverlayWindowViewsTest, UpdateNaturalSizeDoesNotMoveWindow) {
@@ -342,9 +342,9 @@
 
   // The window should not move.
   // The window size will be adjusted according to the new aspect ratio, and
-  // clamped to 500x250 to fit within the maximum size for the work area of
+  // clamped to 600x300 to fit within the maximum size for the work area of
   // 1000x1000.
-  EXPECT_EQ(gfx::Rect(100, 100, 500, 250), overlay_window().GetBounds());
+  EXPECT_EQ(gfx::Rect(100, 100, 600, 300), overlay_window().GetBounds());
 }
 
 // Tests that the OverlayWindowFrameView does not accept events so they can
@@ -435,7 +435,7 @@
 }
 
 TEST_F(DocumentOverlayWindowViewsTest, SmallDisplayWorkAreaDoesNotCrash) {
-  SetDisplayWorkArea({0, 0, 300, 200});
+  SetDisplayWorkArea({0, 0, 240, 120});
   overlay_window().UpdateNaturalSize({400, 300});
 
   // Since the work area would force a max size smaller than the minimum size,
diff --git a/chrome/browser/ui/views/overlay/overlay_window_views.cc b/chrome/browser/ui/views/overlay/overlay_window_views.cc
index 15073cc..15e2692 100644
--- a/chrome/browser/ui/views/overlay/overlay_window_views.cc
+++ b/chrome/browser/ui/views/overlay/overlay_window_views.cc
@@ -521,7 +521,8 @@
   if (work_area.IsEmpty())
     return;
 
-  auto new_max_size = gfx::Size(work_area.width() / 2, work_area.height() / 2);
+  auto new_max_size =
+      gfx::Size(work_area.width() * 0.8, work_area.height() * 0.8);
 
   // Ensure |new_max_size| is not smaller than |min_size_|, or else we will
   // crash.
diff --git a/chrome/browser/ui/views/overlay/video_overlay_window_views_unittest.cc b/chrome/browser/ui/views/overlay/video_overlay_window_views_unittest.cc
index ca6307f3..8ae2b0c1 100644
--- a/chrome/browser/ui/views/overlay/video_overlay_window_views_unittest.cc
+++ b/chrome/browser/ui/views/overlay/video_overlay_window_views_unittest.cc
@@ -158,9 +158,9 @@
 
   // Must fit within the minimum height of 146. But with the aspect ratio of
   // 40:1 the width gets exceedingly big and must be limited to the maximum of
-  // 500. Thus, letterboxing is unavoidable.
-  EXPECT_EQ(gfx::Size(500, 100), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(500, 13),
+  // 800. Thus, letterboxing is unavoidable.
+  EXPECT_EQ(gfx::Size(800, 100), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(800, 20),
             overlay_window().video_layer_for_testing()->size());
 }
 
@@ -169,9 +169,9 @@
 
   // Must fit within the minimum width of 260. But with the aspect ratio of
   // 1:40 the height gets exceedingly big and must be limited to the maximum of
-  // 500. Thus, pillarboxing is unavoidable.
-  EXPECT_EQ(gfx::Size(200, 500), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(13, 500),
+  // 800. Thus, pillarboxing is unavoidable.
+  EXPECT_EQ(gfx::Size(200, 800), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(20, 800),
             overlay_window().video_layer_for_testing()->size());
 }
 
@@ -271,25 +271,25 @@
   // The initial size is determined by the work area and the video natural size
   // (aspect ratio).
   EXPECT_EQ(gfx::Size(1200, 800), overlay_window().GetBounds().size());
-  // The initial maximum size is a quarter of the work area.
-  EXPECT_EQ(gfx::Size(2000, 2000), overlay_window().GetMaximumSize());
+  // The initial maximum size is 80% of the work area.
+  EXPECT_EQ(gfx::Size(3200, 3200), overlay_window().GetMaximumSize());
 
   // If the maximum size increases then we should keep the existing window size.
   SetDisplayWorkArea({0, 0, 8000, 8000});
   EXPECT_EQ(gfx::Size(1200, 800), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(4000, 4000), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(6400, 6400), overlay_window().GetMaximumSize());
 
   // If the maximum size decreases then we should shrink to fit.
   SetDisplayWorkArea({0, 0, 1000, 2000});
-  EXPECT_EQ(gfx::Size(500, 800), overlay_window().GetBounds().size());
-  EXPECT_EQ(gfx::Size(500, 1000), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(800, 800), overlay_window().GetBounds().size());
+  EXPECT_EQ(gfx::Size(800, 1600), overlay_window().GetMaximumSize());
 }
 
 TEST_F(VideoOverlayWindowViewsTest, IgnoreInvalidMaximumSize) {
-  ASSERT_EQ(gfx::Size(500, 500), overlay_window().GetMaximumSize());
+  ASSERT_EQ(gfx::Size(800, 800), overlay_window().GetMaximumSize());
 
   SetDisplayWorkArea({0, 0, 0, 0});
-  EXPECT_EQ(gfx::Size(500, 500), overlay_window().GetMaximumSize());
+  EXPECT_EQ(gfx::Size(800, 800), overlay_window().GetMaximumSize());
 }
 
 // Tests that Next Track button bounds are updated right away when window
@@ -345,9 +345,9 @@
 
   // The window should not move.
   // The window size will be adjusted according to the new aspect ratio, and
-  // clamped to 500x250 to fit within the maximum size for the work area of
+  // clamped to 600x300 to fit within the maximum size for the work area of
   // 1000x1000.
-  EXPECT_EQ(gfx::Rect(100, 100, 500, 250), overlay_window().GetBounds());
+  EXPECT_EQ(gfx::Rect(100, 100, 600, 300), overlay_window().GetBounds());
 }
 
 // Tests that the OverlayWindowFrameView does not accept events so they can
@@ -438,7 +438,7 @@
 }
 
 TEST_F(VideoOverlayWindowViewsTest, SmallDisplayWorkAreaDoesNotCrash) {
-  SetDisplayWorkArea({0, 0, 300, 200});
+  SetDisplayWorkArea({0, 0, 240, 120});
   overlay_window().UpdateNaturalSize({400, 300});
 
   // Since the work area would force a max size smaller than the minimum size,