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

Unified Diff: ui/snapshot/screenshot_grabber.cc

Issue 2167613003: Hide mouse cursor when screenshot is taking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit adjustment Created 4 years, 5 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
« no previous file with comments | « ui/snapshot/screenshot_grabber.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/screenshot_grabber.cc
diff --git a/ui/snapshot/screenshot_grabber.cc b/ui/snapshot/screenshot_grabber.cc
index 4534a857b4beab8a5b77dc15a825a6098b8a508e..ebccaaec342ee6d821c737c3ba8f6dba3412dbec 100644
--- a/ui/snapshot/screenshot_grabber.cc
+++ b/ui/snapshot/screenshot_grabber.cc
@@ -24,6 +24,7 @@
#include "ui/snapshot/snapshot.h"
#if defined(USE_AURA)
+#include "ui/aura/client/cursor_client.h"
#include "ui/aura/window.h"
#endif
@@ -108,6 +109,35 @@ void ScreenshotGrabberDelegate::PrepareFileAndRunOnBlockingPool(
base::Bind(EnsureLocalDirectoryExists, path, callback_on_blocking_pool));
}
+#if defined(USE_AURA)
+class ScreenshotGrabber::ScopedCursorHider {
+ public:
+ // The nullptr might be returned when GetCursorClient is nullptr.
+ static std::unique_ptr<ScopedCursorHider> Create(aura::Window* window) {
+ DCHECK(window->IsRootWindow());
+ aura::client::CursorClient* cursor_client =
+ aura::client::GetCursorClient(window);
+ if (!cursor_client)
+ return nullptr;
+ cursor_client->HideCursor();
+ return std::unique_ptr<ScopedCursorHider>(
+ base::WrapUnique(new ScopedCursorHider(window)));
+ }
+
+ ~ScopedCursorHider() {
+ aura::client::CursorClient* cursor_client =
+ aura::client::GetCursorClient(window_);
+ cursor_client->ShowCursor();
+ }
+
+ private:
+ explicit ScopedCursorHider(aura::Window* window) : window_(window) {}
+ aura::Window* window_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider);
+};
+#endif
+
ScreenshotGrabber::ScreenshotGrabber(
ScreenshotGrabberDelegate* client,
scoped_refptr<base::TaskRunner> blocking_task_runner)
@@ -134,6 +164,8 @@ void ScreenshotGrabber::TakeScreenshot(gfx::NativeWindow window,
aura::Window* aura_window = static_cast<aura::Window*>(window);
is_partial = rect.size() != aura_window->bounds().size();
window_identifier = aura_window->GetBoundsInScreen().ToString();
+
+ cursor_hider_ = ScopedCursorHider::Create(aura_window->GetRootWindow());
#endif
ui::GrabWindowSnapshotAsync(
window, rect, blocking_task_runner_,
@@ -152,6 +184,9 @@ void ScreenshotGrabber::NotifyScreenshotCompleted(
ScreenshotGrabberObserver::Result screenshot_result,
const base::FilePath& screenshot_path) {
DCHECK(base::MessageLoopForUI::IsCurrent());
+#if defined(USE_AURA)
+ cursor_hider_.reset();
+#endif
FOR_EACH_OBSERVER(ScreenshotGrabberObserver, observers_,
OnScreenshotCompleted(screenshot_result, screenshot_path));
}
« no previous file with comments | « ui/snapshot/screenshot_grabber.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698