Commit 9bb50d51 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

capture_mode: Copy image to clipboard

BUG=1116137
TEST=Manual

Change-Id: Ifdf59fb05064b8902a3d8562f8523c2b186c6b4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2393014
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805015}
parent b03d9c9f
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "ui/base/clipboard/clipboard_data.h"
#include "ui/base/clipboard/clipboard_non_backed.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
...@@ -168,6 +170,15 @@ void ShowFailureNotification() { ...@@ -168,6 +170,15 @@ void ShowFailureNotification() {
/*optional_fields=*/{}, /*delegate=*/nullptr); /*optional_fields=*/{}, /*delegate=*/nullptr);
} }
// Copies the bitmap representation of the given |image| to the clipboard.
void CopyImageToClipboard(const gfx::Image& image) {
auto* clipboard = ui::ClipboardNonBacked::GetForCurrentThread();
DCHECK(clipboard);
auto clipboard_data = std::make_unique<ui::ClipboardData>();
clipboard_data->SetBitmapData(image.AsBitmap());
clipboard->WriteClipboardData(std::move(clipboard_data));
}
} // namespace } // namespace
CaptureModeController::CaptureModeController( CaptureModeController::CaptureModeController(
...@@ -337,8 +348,9 @@ void CaptureModeController::OnImageFileSaved( ...@@ -337,8 +348,9 @@ void CaptureModeController::OnImageFileSaved(
} }
DCHECK(png_bytes && png_bytes->size()); DCHECK(png_bytes && png_bytes->size());
// TODO(afakhry): Save image to clipboard. const auto image = gfx::Image::CreateFrom1xPNGBytes(png_bytes);
ShowPreviewNotification(path, gfx::Image::CreateFrom1xPNGBytes(png_bytes)); CopyImageToClipboard(image);
ShowPreviewNotification(path, image);
} }
void CaptureModeController::ShowPreviewNotification( void CaptureModeController::ShowPreviewNotification(
......
...@@ -90,8 +90,9 @@ class ASH_EXPORT CaptureModeController { ...@@ -90,8 +90,9 @@ class ASH_EXPORT CaptureModeController {
// Called back when an attempt to save the image file has been completed, with // Called back when an attempt to save the image file has been completed, with
// |success| indicating whether the attempt succeeded for failed. |png_bytes| // |success| indicating whether the attempt succeeded for failed. |png_bytes|
// is the buffer containing the captured image in a PNG format, which will be // is the buffer containing the captured image in a PNG format, which will be
// used to show a preview of the image in a notification. If saving was // used to show a preview of the image in a notification, and save it as a
// successful, then the image was saved in |path|. // bitmap in the clipboard. If saving was successful, then the image was saved
// in |path|.
void OnImageFileSaved(scoped_refptr<base::RefCountedMemory> png_bytes, void OnImageFileSaved(scoped_refptr<base::RefCountedMemory> png_bytes,
const base::FilePath& path, const base::FilePath& path,
bool success); bool success);
......
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