Commit 288772d2 authored by Cattalyya Nuengsigkapian's avatar Cattalyya Nuengsigkapian Committed by Commit Bot

capture_mode: remove an edit button from video notification.

- Show edit and delete buttons for screenshot preview notification.
- Show only an edit button for video preview notification.

# Testing
- Screen recording shows expected buttons in preview notification
for image and video, and correct behaviors when pressing each button.
https://drive.google.com/file/d/10KUoHfGgNk3hzZACNz2WOSZmkYGY4Cl9/view?usp=sharing

Bug: 1136666
Change-Id: Ia6efe6ce5862dc2be1163b994f5ef74966ee6c47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488365
Commit-Queue: Cattalyya Nuengsigkapian <cattalyya@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819915}
parent dd9e059d
......@@ -59,12 +59,17 @@ constexpr char kDateFmtStr[] = "%d-%02d-%02d";
constexpr char k24HourTimeFmtStr[] = "%02d.%02d.%02d";
constexpr char kAmPmTimeFmtStr[] = "%d.%02d.%02d";
// The notification button index.
enum NotificationButtonIndex {
// The screenshot notification button index.
enum ScreenshotNotificationButtonIndex {
BUTTON_EDIT = 0,
BUTTON_DELETE,
};
// The video notification button index.
enum VideoNotificationButtonIndex {
BUTTON_DELETE_VIDEO = 0,
};
// Returns the date extracted from |timestamp| as a string to be part of
// captured file names. Note that naturally formatted dates includes slashes
// (e.g. 2020/09/02), which will cause problems when used in file names since
......@@ -420,7 +425,7 @@ void CaptureModeController::OnImageFileSaved(
DCHECK(png_bytes && png_bytes->size());
const auto image = gfx::Image::CreateFrom1xPNGBytes(png_bytes);
CopyImageToClipboard(image);
ShowPreviewNotification(path, image);
ShowPreviewNotification(path, image, CaptureModeType::kImage);
if (features::IsTemporaryHoldingSpaceEnabled())
HoldingSpaceController::Get()->client()->AddScreenshot(path);
......@@ -440,7 +445,8 @@ void CaptureModeController::OnVideoFileSaved(bool success) {
if (!success)
ShowFailureNotification();
else
ShowPreviewNotification(current_video_file_path_, gfx::Image());
ShowPreviewNotification(current_video_file_path_, gfx::Image(),
CaptureModeType::kVideo);
current_video_file_path_.clear();
video_file_handler_.Reset();
......@@ -448,18 +454,19 @@ void CaptureModeController::OnVideoFileSaved(bool success) {
void CaptureModeController::ShowPreviewNotification(
const base::FilePath& screen_capture_path,
const gfx::Image& preview_image) {
const base::string16 title =
l10n_util::GetStringUTF16(type_ == CaptureModeType::kImage
? IDS_ASH_SCREEN_CAPTURE_SCREENSHOT_TITLE
: IDS_ASH_SCREEN_CAPTURE_RECORDING_TITLE);
const gfx::Image& preview_image,
const CaptureModeType type) {
const base::string16 title = l10n_util::GetStringUTF16(
type == CaptureModeType::kImage ? IDS_ASH_SCREEN_CAPTURE_SCREENSHOT_TITLE
: IDS_ASH_SCREEN_CAPTURE_RECORDING_TITLE);
const base::string16 message =
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_MESSAGE);
message_center::RichNotificationData optional_fields;
message_center::ButtonInfo edit_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT));
optional_fields.buttons.push_back(edit_button);
if (type == CaptureModeType::kImage)
optional_fields.buttons.push_back(edit_button);
message_center::ButtonInfo delete_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE));
optional_fields.buttons.push_back(delete_button);
......@@ -471,29 +478,45 @@ void CaptureModeController::ShowPreviewNotification(
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
base::BindRepeating(&CaptureModeController::HandleNotificationClicked,
weak_ptr_factory_.GetWeakPtr(),
screen_capture_path)));
screen_capture_path, type)));
}
void CaptureModeController::HandleNotificationClicked(
const base::FilePath& screen_capture_path,
const CaptureModeType type,
base::Optional<int> button_index) {
message_center::MessageCenter::Get()->RemoveNotification(
kScreenCaptureNotificationId, /*by_user=*/false);
if (!button_index.has_value()) {
// Show the item in the folder.
delegate_->ShowScreenCaptureItemInFolder(screen_capture_path);
} else {
// TODO(crbug.com/1136666): Remove edit button for video recording.
switch (button_index.value()) {
case NotificationButtonIndex::BUTTON_EDIT:
delegate_->OpenScreenshotInImageEditor(screen_capture_path);
break;
case NotificationButtonIndex::BUTTON_DELETE:
DeleteFileAsync(task_runner_, screen_capture_path);
break;
}
return;
}
message_center::MessageCenter::Get()->RemoveNotification(
kScreenCaptureNotificationId, /*by_user=*/false);
const int button_index_value = button_index.value();
// Handle a button clicked for a video preview notification.
if (type == CaptureModeType::kVideo) {
DCHECK_EQ(button_index_value,
VideoNotificationButtonIndex::BUTTON_DELETE_VIDEO);
DeleteFileAsync(task_runner_, screen_capture_path);
return;
}
// Handle a button clicked for an image preview notification.
DCHECK_EQ(type, CaptureModeType::kImage);
switch (button_index_value) {
case ScreenshotNotificationButtonIndex::BUTTON_EDIT:
delegate_->OpenScreenshotInImageEditor(screen_capture_path);
break;
case ScreenshotNotificationButtonIndex::BUTTON_DELETE:
DeleteFileAsync(task_runner_, screen_capture_path);
break;
default:
NOTREACHED();
break;
}
}
base::FilePath CaptureModeController::BuildImagePath(
......
......@@ -132,8 +132,10 @@ class ASH_EXPORT CaptureModeController {
// Shows a preview notification of the newly taken screenshot or screen
// recording.
void ShowPreviewNotification(const base::FilePath& screen_capture_path,
const gfx::Image& preview_image);
const gfx::Image& preview_image,
const CaptureModeType type);
void HandleNotificationClicked(const base::FilePath& screen_capture_path,
const CaptureModeType type,
base::Optional<int> button_index);
// Builds a path for a file of an image screenshot, or a video screen
......
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