Commit 334e2935 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

capture_mode: Add notification for screen capture.

Currently notification code is not wired up yet.

Bug: 1115153
Change-Id: I4ec6456e86623d8236065336ec2658709f005b83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354558Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798773}
parent 667c433e
......@@ -2631,6 +2631,32 @@ Here are some things you can try to get started.
<message name="IDS_ASH_AMBIENT_MODE_WEATHER_TEMPERATURE_IN_CELSIUS" desc="Text of the weather temperature in Celsius.">
<ph name="TEMPERATURE_C">$1<ex>25</ex></ph>° C
</message>
<!-- Capture Mode -->
<message name="IDS_ASH_SCREEN_CAPTURE_DISPLAY_SOURCE" desc="The name that is the display source of the screen capture notification.">
Screen capture
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_SCREENSHOT_TITLE" desc="The title of the notificaton which shows after a screenshot is taken.">
Screenshot taken and saved to clipboard
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_RECORDING_TITLE" desc="The titile of the notification which shows after a screen recording is taken.">
Screen recording taken
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_MESSAGE" desc="The message shows in the screenshot or screen recording notification.">
Show in folder
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_BUTTON_SHARE" desc="The share button label for the screen capture notifiction.">
Share
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT" desc="The edit button label for the screen catpure notification.">
Edit
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_BUTTON_FLOAT_ON_TOP" desc="The float-on-top button label for the screen capture notification.">
Float on top
</message>
<message name="IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE" desc="The delete button label for the screen capture notificaiton.">
Delete
</message>
</messages>
</release>
</grit>
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
e4eb54cf5552f9a578ea7abfdf4dd24fca15e500
\ No newline at end of file
ac998dc1c50f46552c283f30c1d784b214f3f799
\ No newline at end of file
......@@ -8,9 +8,19 @@
#include <utility>
#include "ash/capture_mode/capture_mode_session.h"
#include "ash/public/cpp/capture_mode_delegate.h"
#include "ash/public/cpp/notification_utils.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"
namespace ash {
......@@ -18,6 +28,17 @@ namespace {
CaptureModeController* g_instance = nullptr;
const char kScreenCaptureNotificationId[] = "capture_mode_notification";
const char kScreenCaptureNotifierId[] = "ash.capture_mode_controller";
// The notification button index.
enum NotificationButtonIndex {
BUTTON_SHARE = 0,
BUTTON_EDIT,
BUTTON_FLOAT_ON_TOP,
BUTTON_DELETE,
};
} // namespace
CaptureModeController::CaptureModeController(
......@@ -80,4 +101,80 @@ void CaptureModeController::EndVideoRecording() {
// TODO(afakhry): Fill in here.
}
void CaptureModeController::ShowNotification(
const base::FilePath& screen_capture_path) {
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_field;
message_center::ButtonInfo share_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_SHARE));
optional_field.buttons.push_back(share_button);
message_center::ButtonInfo edit_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT));
optional_field.buttons.push_back(edit_button);
message_center::ButtonInfo float_on_top_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_FLOAT_ON_TOP));
optional_field.buttons.push_back(float_on_top_button);
message_center::ButtonInfo delete_button(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE));
optional_field.buttons.push_back(delete_button);
// TODO: Assign image for screenshot or screenrecording preview. For now it's
// an empty image.
optional_field.image = gfx::Image();
std::unique_ptr<message_center::Notification> notification =
CreateSystemNotification(
message_center::NOTIFICATION_TYPE_IMAGE, kScreenCaptureNotificationId,
title, message,
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_DISPLAY_SOURCE),
GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kScreenCaptureNotifierId),
optional_field,
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
base::BindRepeating(
&CaptureModeController::HandleNotificationClicked,
weak_ptr_factory_.GetWeakPtr(), screen_capture_path)),
kCaptureModeIcon,
message_center::SystemNotificationWarningLevel::NORMAL);
// Remove the previous notification before showing the new one if there is
// one.
message_center::MessageCenter::Get()->RemoveNotification(
kScreenCaptureNotificationId, /*by_user=*/false);
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
}
void CaptureModeController::HandleNotificationClicked(
const base::FilePath& screen_capture_path,
base::Optional<int> button_index) {
if (!button_index.has_value()) {
// Show the item in the folder.
delegate_->ShowScreenCaptureItemInFolder(screen_capture_path);
message_center::MessageCenter::Get()->RemoveNotification(
kScreenCaptureNotificationId, /*by_user=*/false);
return;
}
// TODO: fill in here.
switch (button_index.value()) {
case NotificationButtonIndex::BUTTON_SHARE:
break;
case NotificationButtonIndex::BUTTON_EDIT:
break;
case NotificationButtonIndex::BUTTON_FLOAT_ON_TOP:
break;
case NotificationButtonIndex::BUTTON_DELETE:
break;
}
}
} // namespace ash
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "ash/public/cpp/capture_mode_delegate.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
......@@ -61,6 +62,11 @@ class ASH_EXPORT CaptureModeController {
void EndVideoRecording();
private:
// Show notification for the newly taken screenshot or screen recording.
void ShowNotification(const base::FilePath& screen_capture_path);
void HandleNotificationClicked(const base::FilePath& screen_capture_path,
base::Optional<int> button_index);
std::unique_ptr<CaptureModeDelegate> delegate_;
CaptureModeType type_ = CaptureModeType::kImage;
......@@ -72,6 +78,8 @@ class ASH_EXPORT CaptureModeController {
gfx::Rect user_capture_region_;
std::unique_ptr<CaptureModeSession> capture_mode_session_;
base::WeakPtrFactory<CaptureModeController> weak_ptr_factory_{this};
};
} // namespace ash
......
......@@ -13,4 +13,7 @@ base::FilePath TestCaptureModeDelegate::GetActiveUserDownloadsDir() const {
return base::FilePath();
}
void TestCaptureModeDelegate::ShowScreenCaptureItemInFolder(
const base::FilePath& file_path) {}
} // namespace ash
......@@ -18,6 +18,7 @@ class TestCaptureModeDelegate : public CaptureModeDelegate {
// CaptureModeDelegate:
base::FilePath GetActiveUserDownloadsDir() const override;
void ShowScreenCaptureItemInFolder(const base::FilePath& file_path) override;
};
} // namespace ash
......
......@@ -23,6 +23,10 @@ class ASH_PUBLIC_EXPORT CaptureModeDelegate {
// Returns the path to the active user's downloads directory. This will never
// be called if the user is not logged in.
virtual base::FilePath GetActiveUserDownloadsDir() const = 0;
// Shows the screenshot or screen recording item in the screen capture folder.
virtual void ShowScreenCaptureItemInFolder(
const base::FilePath& file_path) = 0;
};
} // namespace ash
......
......@@ -6,6 +6,7 @@
#include "base/files/file_path.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/login/login_state/login_state.h"
......@@ -19,3 +20,9 @@ base::FilePath ChromeCaptureModeDelegate::GetActiveUserDownloadsDir() const {
DownloadPrefs::FromBrowserContext(ProfileManager::GetActiveUserProfile());
return download_prefs->DownloadPath();
}
void ChromeCaptureModeDelegate::ShowScreenCaptureItemInFolder(
const base::FilePath& file_path) {
platform_util::ShowItemInFolder(ProfileManager::GetActiveUserProfile(),
file_path);
}
......@@ -19,6 +19,7 @@ class ChromeCaptureModeDelegate : public ash::CaptureModeDelegate {
// ash::CaptureModeDelegate:
base::FilePath GetActiveUserDownloadsDir() const override;
void ShowScreenCaptureItemInFolder(const base::FilePath& file_path) override;
};
#endif // CHROME_BROWSER_UI_ASH_CHROME_CAPTURE_MODE_DELEGATE_H_
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