[live-preview] Add a minimum for audio level in the mic meter to render appropriately
Also shows no value bar when the mic is muted.
Change-Id: I1854536789775c43b3c3f2bbcc7cc5e52b70ce9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5251389
Commit-Queue: Ahmed Moussa <ahmedmoussa@google.com>
Reviewed-by: Bryant Chandler <bryantchandler@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254279}
diff --git a/chrome/browser/ui/views/media_preview/mic_preview/audio_stream_view.cc b/chrome/browser/ui/views/media_preview/mic_preview/audio_stream_view.cc
index 83eed20..447608b 100644
--- a/chrome/browser/ui/views/media_preview/mic_preview/audio_stream_view.cc
+++ b/chrome/browser/ui/views/media_preview/mic_preview/audio_stream_view.cc
@@ -34,19 +34,26 @@
}
void AudioStreamView::OnPaint(gfx::Canvas* canvas) {
- const int rect_height = height() / 2;
- const int x = 0;
- const int y = rect_height / 2;
+ const float rect_height = height() / 2;
+ const float x = 0;
+ const float y = rect_height / 2;
gfx::RectF base_rect(x, y, width(), rect_height);
cc::PaintFlags base_rect_flags;
base_rect_flags.setColor(GetColorProvider()->GetColor(ui::kColorSysSurface5));
canvas->DrawRoundRect(base_rect, rounded_radius_, base_rect_flags);
- gfx::RectF value_rect(x, y, width() * last_audio_level_, rect_height);
- cc::PaintFlags value_rect_flags;
- value_rect_flags.setColor(GetColorProvider()->GetColor(ui::kColorSysPrimary));
- canvas->DrawRoundRect(value_rect, rounded_radius_, value_rect_flags);
+ if (last_audio_level_ != 0) {
+ float rect_width = width() * last_audio_level_;
+ // Ensure that the smallest possible colored bar is a circle.
+ rect_width = std::max(rect_width, rect_height);
+
+ gfx::RectF value_rect(x, y, rect_width, rect_height);
+ cc::PaintFlags value_rect_flags;
+ value_rect_flags.setColor(
+ GetColorProvider()->GetColor(ui::kColorSysPrimary));
+ canvas->DrawRoundRect(value_rect, rounded_radius_, value_rect_flags);
+ }
}
BEGIN_METADATA(AudioStreamView)