Commit eb93d50a authored by warx's avatar warx Committed by Commit bot

Hide mouse cursor when screenshot is taking

BUG=597270
TEST=device test saw bug away

Review-Url: https://codereview.chromium.org/2167613003
Cr-Commit-Position: refs/heads/master@{#407325}
parent 388b9dc5
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ui/snapshot/snapshot.h" #include "ui/snapshot/snapshot.h"
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#endif #endif
...@@ -108,6 +109,35 @@ void ScreenshotGrabberDelegate::PrepareFileAndRunOnBlockingPool( ...@@ -108,6 +109,35 @@ void ScreenshotGrabberDelegate::PrepareFileAndRunOnBlockingPool(
base::Bind(EnsureLocalDirectoryExists, path, callback_on_blocking_pool)); 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( ScreenshotGrabber::ScreenshotGrabber(
ScreenshotGrabberDelegate* client, ScreenshotGrabberDelegate* client,
scoped_refptr<base::TaskRunner> blocking_task_runner) scoped_refptr<base::TaskRunner> blocking_task_runner)
...@@ -134,6 +164,8 @@ void ScreenshotGrabber::TakeScreenshot(gfx::NativeWindow window, ...@@ -134,6 +164,8 @@ void ScreenshotGrabber::TakeScreenshot(gfx::NativeWindow window,
aura::Window* aura_window = static_cast<aura::Window*>(window); aura::Window* aura_window = static_cast<aura::Window*>(window);
is_partial = rect.size() != aura_window->bounds().size(); is_partial = rect.size() != aura_window->bounds().size();
window_identifier = aura_window->GetBoundsInScreen().ToString(); window_identifier = aura_window->GetBoundsInScreen().ToString();
cursor_hider_ = ScopedCursorHider::Create(aura_window->GetRootWindow());
#endif #endif
ui::GrabWindowSnapshotAsync( ui::GrabWindowSnapshotAsync(
window, rect, blocking_task_runner_, window, rect, blocking_task_runner_,
...@@ -152,6 +184,9 @@ void ScreenshotGrabber::NotifyScreenshotCompleted( ...@@ -152,6 +184,9 @@ void ScreenshotGrabber::NotifyScreenshotCompleted(
ScreenshotGrabberObserver::Result screenshot_result, ScreenshotGrabberObserver::Result screenshot_result,
const base::FilePath& screenshot_path) { const base::FilePath& screenshot_path) {
DCHECK(base::MessageLoopForUI::IsCurrent()); DCHECK(base::MessageLoopForUI::IsCurrent());
#if defined(USE_AURA)
cursor_hider_.reset();
#endif
FOR_EACH_OBSERVER(ScreenshotGrabberObserver, observers_, FOR_EACH_OBSERVER(ScreenshotGrabberObserver, observers_,
OnScreenshotCompleted(screenshot_result, screenshot_path)); OnScreenshotCompleted(screenshot_result, screenshot_path));
} }
......
...@@ -76,6 +76,10 @@ class SNAPSHOT_EXPORT ScreenshotGrabber { ...@@ -76,6 +76,10 @@ class SNAPSHOT_EXPORT ScreenshotGrabber {
bool HasObserver(const ScreenshotGrabberObserver* observer) const; bool HasObserver(const ScreenshotGrabberObserver* observer) const;
private: private:
#if defined(USE_AURA)
class ScopedCursorHider;
#endif
void GrabWindowSnapshotAsyncCallback( void GrabWindowSnapshotAsyncCallback(
const std::string& window_identifier, const std::string& window_identifier,
base::FilePath screenshot_path, base::FilePath screenshot_path,
...@@ -91,6 +95,11 @@ class SNAPSHOT_EXPORT ScreenshotGrabber { ...@@ -91,6 +95,11 @@ class SNAPSHOT_EXPORT ScreenshotGrabber {
// Task runner for blocking tasks. // Task runner for blocking tasks.
scoped_refptr<base::TaskRunner> blocking_task_runner_; scoped_refptr<base::TaskRunner> blocking_task_runner_;
#if defined(USE_AURA)
// The object to hide cursor when taking screenshot.
std::unique_ptr<ScopedCursorHider> cursor_hider_;
#endif
base::ObserverList<ScreenshotGrabberObserver> observers_; base::ObserverList<ScreenshotGrabberObserver> observers_;
base::WeakPtrFactory<ScreenshotGrabber> factory_; base::WeakPtrFactory<ScreenshotGrabber> factory_;
......
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