Commit 5f1eb84f authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Chromium LUCI CQ

capture_mode: Disable video recording button when recording is in progress

Since we can't have more than one recording at a time, we should
disabled the video recording toggle button when the capture mode
session starts while recording is in progress.

BUG=1160343
TEST=Manually, added a new test.

Change-Id: Ib6b169c584b1fdf84926995a94fa07000be66c48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601856Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839150}
parent dff0f7c1
......@@ -307,6 +307,12 @@ void CaptureModeController::SetSource(CaptureModeSource source) {
}
void CaptureModeController::SetType(CaptureModeType type) {
if (is_recording_in_progress_ && type == CaptureModeType::kVideo) {
// Overwrite video capture types to image, as we can't have more than one
// recording at a time.
type = CaptureModeType::kImage;
}
if (type == type_)
return;
......@@ -324,6 +330,12 @@ void CaptureModeController::Start(CaptureModeEntryType entry_type) {
return;
}
// Before we start the session, if video recording is in progress, we need to
// set the current type to image, as we can't have more than one recording at
// a time. The video toggle button in the capture mode bar will be disabled.
if (is_recording_in_progress_)
SetType(CaptureModeType::kImage);
RecordCaptureModeEntryType(entry_type);
// Reset the user capture region if enough time has passed as it can be
// annoying to still have the old capture region from the previous session
......
......@@ -70,6 +70,11 @@ void CaptureModeToggleButton::SetIcon(const gfx::VectorIcon& icon) {
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, normal_color));
SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(
icon, color_provider->GetDisabledColor(normal_color)));
// Note that a disabled button cannot be toggled, so we don't need to set a
// toggled icon for the disabled state.
const auto toggled_icon = gfx::CreateVectorIcon(icon, toggled_color);
SetToggledImage(views::Button::STATE_NORMAL, &toggled_icon);
}
......
......@@ -52,7 +52,10 @@ CaptureModeTypeView::CaptureModeTypeView()
kButtonSpacing));
box_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
OnCaptureTypeChanged(CaptureModeController::Get()->type());
auto* controller = CaptureModeController::Get();
// We can't have more than one recording at the same time.
video_toggle_button_->SetEnabled(!controller->is_recording_in_progress());
OnCaptureTypeChanged(controller->type());
image_toggle_button_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_TOOLTIP_SCREENSHOT));
......@@ -63,6 +66,8 @@ CaptureModeTypeView::CaptureModeTypeView()
CaptureModeTypeView::~CaptureModeTypeView() = default;
void CaptureModeTypeView::OnCaptureTypeChanged(CaptureModeType new_type) {
DCHECK(!CaptureModeController::Get()->is_recording_in_progress() ||
new_type == CaptureModeType::kImage);
image_toggle_button_->SetToggled(new_type == CaptureModeType::kImage);
video_toggle_button_->SetToggled(new_type == CaptureModeType::kVideo);
DCHECK_NE(image_toggle_button_->GetToggled(),
......@@ -75,8 +80,10 @@ void CaptureModeTypeView::OnImageToggle() {
}
void CaptureModeTypeView::OnVideoToggle() {
auto* controller = CaptureModeController::Get();
DCHECK(!controller->is_recording_in_progress());
RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kScreenRecord);
CaptureModeController::Get()->SetType(CaptureModeType::kVideo);
controller->SetType(CaptureModeType::kVideo);
}
BEGIN_METADATA(CaptureModeTypeView, views::View)
......
......@@ -2259,4 +2259,38 @@ TEST_F(CaptureModeTest, QuickActionHistograms) {
CaptureQuickAction::kBacklight, 1);
}
TEST_F(CaptureModeTest, CannotDoMultipleRecordings) {
StartCaptureSession(CaptureModeSource::kFullscreen, CaptureModeType::kVideo);
auto* controller = CaptureModeController::Get();
controller->StartVideoRecordingImmediatelyForTesting();
EXPECT_TRUE(controller->is_recording_in_progress());
EXPECT_EQ(CaptureModeType::kVideo, controller->type());
// Start a new session with the current type which set to kVideo, the type
// should be switched automatically to kImage, and video toggle button should
// be disabled.
controller->Start(CaptureModeEntryType::kQuickSettings);
EXPECT_TRUE(controller->IsActive());
EXPECT_EQ(CaptureModeType::kImage, controller->type());
EXPECT_TRUE(GetImageToggleButton()->GetToggled());
EXPECT_FALSE(GetVideoToggleButton()->GetToggled());
EXPECT_FALSE(GetVideoToggleButton()->GetEnabled());
// Clicking on the video button should do nothing.
ClickOnView(GetVideoToggleButton(), GetEventGenerator());
EXPECT_TRUE(GetImageToggleButton()->GetToggled());
EXPECT_FALSE(GetVideoToggleButton()->GetToggled());
EXPECT_EQ(CaptureModeType::kImage, controller->type());
// Things should go back to normal when there's no recording going on.
controller->Stop();
controller->EndVideoRecording(EndRecordingReason::kStopRecordingButton);
StartCaptureSession(CaptureModeSource::kFullscreen, CaptureModeType::kVideo);
EXPECT_EQ(CaptureModeType::kVideo, controller->type());
EXPECT_FALSE(GetImageToggleButton()->GetToggled());
EXPECT_TRUE(GetVideoToggleButton()->GetToggled());
EXPECT_TRUE(GetVideoToggleButton()->GetEnabled());
}
} // namespace ash
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