Commit 3aa57306 authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Ensure that Live Caption text does not render blurrily in

the MediaDialogView.

The MediaDialogView paints to layer in order to ensure that corners are
rounded (introduced due to crbug.com/992869). The Live Caption toggle
label paints to a transparent background, which caused a bug due to
subpixel rendering not occurring. This CL takes two approaches:
1. The new EnableMDRounedCornersOnDialogs flag enables rounded corners
   without needing to paint to layer. When that flag is enabled, we
   stop painting to layer.
2. When the flag is not enabled, set the background of the Live Caption
   toggle container to the native theme background so that the
   background color is opaque rather than transparent.

Bug: 1055150, 1139395
Change-Id: Iaf9675e50671b3464c213412698aea3616534643
AX-Relnotes: N/A (Feature not launched yet)
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490225Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#820218}
parent 2d9c4e12
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/views_features.h"
using media_session::mojom::MediaSessionAction; using media_session::mojom::MediaSessionAction;
...@@ -131,17 +132,16 @@ void MediaDialogView::HideMediaDialog() { ...@@ -131,17 +132,16 @@ void MediaDialogView::HideMediaDialog() {
void MediaDialogView::AddedToWidget() { void MediaDialogView::AddedToWidget() {
int corner_radius = int corner_radius =
views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH); views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH);
views::BubbleFrameView* frame = GetBubbleFrameView(); views::BubbleFrameView* frame = GetBubbleFrameView();
if (frame) { if (frame)
frame->SetCornerRadius(corner_radius); frame->SetCornerRadius(corner_radius);
if (!base::FeatureList::IsEnabled(
views::features::kEnableMDRoundedCornersOnDialogs)) {
SetPaintToLayer();
layer()->SetRoundedCornerRadius(gfx::RoundedCornersF(corner_radius));
if (base::FeatureList::IsEnabled(media::kLiveCaption))
layer()->SetFillsBoundsOpaquely(false);
} }
SetPaintToLayer();
layer()->SetRoundedCornerRadius(gfx::RoundedCornersF(corner_radius));
if (IsLiveCaptionEnabled())
layer()->SetFillsBoundsOpaquely(false);
service_->SetDialogDelegate(this); service_->SetDialogDelegate(this);
} }
...@@ -158,7 +158,7 @@ gfx::Size MediaDialogView::CalculatePreferredSize() const { ...@@ -158,7 +158,7 @@ gfx::Size MediaDialogView::CalculatePreferredSize() const {
void MediaDialogView::UpdateBubbleSize() { void MediaDialogView::UpdateBubbleSize() {
SizeToContents(); SizeToContents();
if (!IsLiveCaptionEnabled()) if (!base::FeatureList::IsEnabled(media::kLiveCaption))
return; return;
const int width = GetPreferredSize().width(); const int width = GetPreferredSize().width();
...@@ -230,7 +230,7 @@ MediaDialogView::~MediaDialogView() { ...@@ -230,7 +230,7 @@ MediaDialogView::~MediaDialogView() {
void MediaDialogView::Init() { void MediaDialogView::Init() {
// Remove margins. // Remove margins.
set_margins(gfx::Insets()); set_margins(gfx::Insets());
if (!IsLiveCaptionEnabled()) { if (!base::FeatureList::IsEnabled(media::kLiveCaption)) {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
return; return;
} }
...@@ -246,6 +246,13 @@ void MediaDialogView::Init() { ...@@ -246,6 +246,13 @@ void MediaDialogView::Init() {
gfx::Insets(kLiveCaptionHorizontalMarginDip, gfx::Insets(kLiveCaptionHorizontalMarginDip,
kLiveCaptionVerticalMarginDip), kLiveCaptionVerticalMarginDip),
kLiveCaptionBetweenChildSpacing)); kLiveCaptionBetweenChildSpacing));
if (!base::FeatureList::IsEnabled(
views::features::kEnableMDRoundedCornersOnDialogs)) {
SkColor native_theme_bg_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_BubbleBackground);
live_caption_container->SetBackground(
views::CreateSolidBackground(native_theme_bg_color));
}
views::ImageView* live_caption_image = new views::ImageView(); views::ImageView* live_caption_image = new views::ImageView();
live_caption_image->SetImage( live_caption_image->SetImage(
...@@ -287,7 +294,3 @@ void MediaDialogView::ToggleLiveCaption(const ui::Event& event) { ...@@ -287,7 +294,3 @@ void MediaDialogView::ToggleLiveCaption(const ui::Event& event) {
profile_->GetPrefs()->SetBoolean(prefs::kLiveCaptionEnabled, enabled); profile_->GetPrefs()->SetBoolean(prefs::kLiveCaptionEnabled, enabled);
live_caption_button_->SetIsOn(enabled); live_caption_button_->SetIsOn(enabled);
} }
bool MediaDialogView::IsLiveCaptionEnabled() {
return base::FeatureList::IsEnabled(media::kLiveCaption);
}
...@@ -92,7 +92,6 @@ class MediaDialogView : public views::BubbleDialogDelegateView, ...@@ -92,7 +92,6 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
void ToggleLiveCaption(const ui::Event& event); void ToggleLiveCaption(const ui::Event& event);
void UpdateBubbleSize(); void UpdateBubbleSize();
bool IsLiveCaptionEnabled();
MediaNotificationService* const service_; MediaNotificationService* const service_;
......
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