Commit 3193a5b6 authored by Katie D's avatar Katie D Committed by Commit Bot

Live Captions at the bottom of the window by default.

UX spec changed after discussion with PM.

Also fixes bug causing the bubble to end up in the wrong place
when the window shrinks extremely small in height and grows again,
by keeping the ratios from being calculated when the bubble is
not visible.

Bug: 1055150
Change-Id: I6f344e22a44ce57615994508897a79b69c1bae8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2157985
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarAbigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#761033}
parent ab1aeeb9
......@@ -45,7 +45,8 @@ static constexpr char kPrimaryFont[] = "Roboto";
static constexpr char kSecondaryFont[] = "Arial";
static constexpr char kTertiaryFont[] = "sans-serif";
static constexpr int kFontSizePx = 16;
static constexpr double kDefaultRatioInParent = 0.5;
static constexpr double kDefaultRatioInParentX = 0.5;
static constexpr double kDefaultRatioInParentY = 1;
static constexpr int kErrorImageSizeDip = 20;
// CaptionBubble implementation of BubbleFrameView.
......@@ -83,8 +84,8 @@ CaptionBubble::CaptionBubble(views::View* anchor,
views::BubbleBorder::FLOAT,
views::BubbleBorder::Shadow::NO_SHADOW),
destroyed_callback_(std::move(destroyed_callback)),
ratio_in_parent_x_(kDefaultRatioInParent),
ratio_in_parent_y_(kDefaultRatioInParent) {
ratio_in_parent_x_(kDefaultRatioInParentX),
ratio_in_parent_y_(kDefaultRatioInParentY) {
DialogDelegate::SetButtons(ui::DIALOG_BUTTON_NONE);
DialogDelegate::set_draggable(true);
}
......@@ -143,6 +144,13 @@ void CaptionBubble::OnWidgetBoundsChanged(views::Widget* widget,
SizeToContents();
return;
}
// Check the widget which changed size is our widget. It's possible for
// this to be called when another widget resizes.
// Also check that our widget is visible. If it is not visible then
// the user has not explicitly moved it (because the user can't see it),
// so we should take no action.
if (widget != GetWidget() || !GetWidget()->IsVisible())
return;
// The widget has moved within the window. Recalculate the desired ratio
// within the parent.
......
......@@ -54,10 +54,13 @@ class CaptionBubbleControllerViewsTest : public InProcessBrowserTest {
return controller_ ? controller_->caption_widget_ : nullptr;
}
// There may be some rounding errors. Check that points are almost the same.
void ExpectPointsApproximatelyEqual(gfx::Point first, gfx::Point second) {
EXPECT_LT(abs(first.x() - second.x()), 2);
EXPECT_LT(abs(first.y() - second.y()), 2);
// There may be some rounding errors as we do floating point math with ints.
// Check that points are almost the same.
void ExpectInBottomCenter(gfx::Rect anchor_bounds, gfx::Rect bubble_bounds) {
EXPECT_LT(
abs(bubble_bounds.CenterPoint().x() - anchor_bounds.CenterPoint().x()),
2);
EXPECT_EQ(bubble_bounds.bottom(), anchor_bounds.bottom() - 48);
}
bool IsBubbleErrorMessageVisible() {
......@@ -138,46 +141,44 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest,
browser()->window()->SetBounds(gfx::Rect(10, 10, 800, 600));
GetController()->OnCaptionReceived("Mantis shrimp have 12-16 photoreceptors");
ExpectPointsApproximatelyEqual(
contents_view->GetBoundsInScreen().CenterPoint(),
GetCaptionWidget()->GetClientAreaBoundsInScreen().CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_EQ(GetBubble()->GetBoundsInScreen().width(), 548);
// Move the window and the widget should stay centered.
browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 600));
ExpectPointsApproximatelyEqual(
contents_view->GetBoundsInScreen().CenterPoint(),
GetCaptionWidget()->GetClientAreaBoundsInScreen().CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_EQ(GetBubble()->GetBoundsInScreen().width(), 548);
// Shrink the window's height.
browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 300));
ExpectPointsApproximatelyEqual(
contents_view->GetBoundsInScreen().CenterPoint(),
GetCaptionWidget()->GetClientAreaBoundsInScreen().CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_EQ(GetBubble()->GetBoundsInScreen().width(), 548);
// Grow the height again.
// Shrink it super far, then grow it back up again, and it should still
// be in the right place.
browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 100));
browser()->window()->SetBounds(gfx::Rect(50, 50, 800, 500));
ExpectPointsApproximatelyEqual(
contents_view->GetBoundsInScreen().CenterPoint(),
GetCaptionWidget()->GetClientAreaBoundsInScreen().CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_EQ(GetBubble()->GetBoundsInScreen().width(), 548);
// Now shrink the width so that the caption bubble shrinks.
browser()->window()->SetBounds(gfx::Rect(50, 50, 500, 500));
gfx::Rect widget_bounds = GetCaptionWidget()->GetClientAreaBoundsInScreen();
gfx::Rect contents_bounds = contents_view->GetBoundsInScreen();
EXPECT_EQ(contents_bounds.CenterPoint(), widget_bounds.CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_LT(GetBubble()->GetBoundsInScreen().width(), 548);
EXPECT_EQ(20, widget_bounds.x() - contents_bounds.x());
EXPECT_EQ(20, contents_bounds.right() - widget_bounds.right());
// Make it bigger again and ensure it's visible and wide again.
browser()->window()->SetBounds(gfx::Rect(10, 10, 800, 600));
ExpectPointsApproximatelyEqual(
contents_view->GetBoundsInScreen().CenterPoint(),
GetCaptionWidget()->GetClientAreaBoundsInScreen().CenterPoint());
ExpectInBottomCenter(contents_view->GetBoundsInScreen(),
GetCaptionWidget()->GetClientAreaBoundsInScreen());
EXPECT_EQ(GetBubble()->GetBoundsInScreen().width(), 548);
// Now move the widget within the window.
......
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