Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: chrome/browser/ui/ash/palette_delegate_chromeos.cc

Issue 2291913002: Allow the user to cancel the capture region action, and show its active status in the tray. (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/palette_delegate_chromeos.cc
diff --git a/chrome/browser/ui/ash/palette_delegate_chromeos.cc b/chrome/browser/ui/ash/palette_delegate_chromeos.cc
index 8a1d2648402f454cc4d27e4854000475f7b33b04..1b137bef5d037faef229518abc3adce2aeff14ff 100644
--- a/chrome/browser/ui/ash/palette_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/palette_delegate_chromeos.cc
@@ -25,6 +25,39 @@
namespace chromeos {
+class PaletteDelegateChromeOS::ProxyScreenshotDelegate
+ : public ash::ScreenshotDelegate {
+ public:
+ ProxyScreenshotDelegate(ash::ScreenshotDelegate* delegate,
+ const base::Closure& on_partial_screenshot_taken)
+ : delegate_(delegate),
+ on_partial_screenshot_taken_(on_partial_screenshot_taken) {}
+ ~ProxyScreenshotDelegate() override {}
+
+ private:
+ // ash::ScreenshotDelegate:
+ void HandleTakeScreenshotForAllRootWindows() override {
+ return delegate_->HandleTakeScreenshotForAllRootWindows();
+ }
+ void HandleTakePartialScreenshot(aura::Window* window,
+ const gfx::Rect& rect) override {
+ delegate_->HandleTakePartialScreenshot(window, rect);
+
+ // Run the delegate last, as it may delete this object.
+ if (on_partial_screenshot_taken_)
+ on_partial_screenshot_taken_.Run();
+ }
+ void HandleTakeWindowScreenshot(aura::Window* window) override {
+ return delegate_->HandleTakeWindowScreenshot(window);
oshima 2016/09/02 13:55:19 just q: are you going to do the same for this mode
jdufault 2016/09/02 19:46:31 Not planned right now, because that is an instanta
+ }
+ bool CanTakeScreenshot() override { return delegate_->CanTakeScreenshot(); }
+
+ ash::ScreenshotDelegate* delegate_;
oshima 2016/09/02 13:55:19 nit: document ownership
jdufault 2016/09/02 19:46:31 Done.
+ base::Closure on_partial_screenshot_taken_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProxyScreenshotDelegate);
+};
+
// static
std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() {
if (!ash::IsPaletteFeatureEnabled())
@@ -32,7 +65,7 @@ std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() {
return base::WrapUnique(new PaletteDelegateChromeOS());
}
-PaletteDelegateChromeOS::PaletteDelegateChromeOS() {
+PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) {
registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
@@ -124,6 +157,13 @@ void PaletteDelegateChromeOS::SetProfile(Profile* profile) {
OnPaletteEnabledPrefChanged();
}
+void PaletteDelegateChromeOS::OnPartialScreenshotDone(
+ const base::Closure& then) {
+ proxy_screenshot_delegate_.reset();
+ if (then)
+ then.Run();
+}
+
void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) {
ash::PartialMagnificationController* controller =
ash::Shell::GetInstance()->partial_magnification_controller();
@@ -156,16 +196,25 @@ void PaletteDelegateChromeOS::TakeScreenshot() {
screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
}
-void PaletteDelegateChromeOS::TakePartialScreenshot() {
+void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) {
auto* screenshot_controller =
ash::Shell::GetInstance()->screenshot_controller();
auto* screenshot_delegate = ash::Shell::GetInstance()
->accelerator_controller_delegate()
->screenshot_delegate();
+ proxy_screenshot_delegate_ = base::MakeUnique<ProxyScreenshotDelegate>(
+ screenshot_delegate,
+ base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone,
+ weak_factory_.GetWeakPtr(), done));
+
screenshot_controller->set_pen_events_only(true);
screenshot_controller->StartPartialScreenshotSession(
- screenshot_delegate, false /* draw_overlay_immediately */);
+ proxy_screenshot_delegate_.get(), false /* draw_overlay_immediately */);
+}
+
+void PaletteDelegateChromeOS::CancelPartialScreenshot() {
+ ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession();
}
void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) {
« ash/shell/shell_delegate_impl.cc ('K') | « chrome/browser/ui/ash/palette_delegate_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698