Chromium Code Reviews| Index: ash/utility/screenshot_controller.cc |
| diff --git a/ash/utility/screenshot_controller.cc b/ash/utility/screenshot_controller.cc |
| index d8b3d29b8c298af2d8ef56a5f2a1dfdf02f9a1fe..be46b7a79a8d5188c3c9f16cad11dba83c7819ed 100644 |
| --- a/ash/utility/screenshot_controller.cc |
| +++ b/ash/utility/screenshot_controller.cc |
| @@ -10,6 +10,7 @@ |
| #include "ash/public/cpp/shell_window_ids.h" |
| #include "ash/screenshot_delegate.h" |
| #include "ash/shell.h" |
| +#include "ash/shell_port.h" |
| #include "ash/wm/window_util.h" |
| #include "base/memory/ptr_util.h" |
| #include "ui/aura/client/capture_client.h" |
| @@ -198,10 +199,29 @@ class ScreenshotController::ScreenshotLayer : public ui::LayerOwner, |
| class ScreenshotController::ScopedCursorSetter { |
| public: |
| ScopedCursorSetter(::wm::CursorManager* cursor_manager, |
| - gfx::NativeCursor cursor) |
| - : cursor_manager_(nullptr) { |
| - if (cursor_manager->IsCursorLocked()) |
| + ui::CursorType cursor) { |
| + if (cursor_manager) |
| + InitializeWithCursorManager(cursor_manager, cursor); |
| + else |
| + InitializeWithShellPort(cursor); |
| + } |
| + |
| + ~ScopedCursorSetter() { |
| + if (cursor_manager_) |
| + cursor_manager_->UnlockCursor(); |
| + else if (already_locked_) |
| return; |
| + else |
|
sky
2017/05/12 13:40:01
no else afte return.
Elliot Glaysher
2017/05/12 23:02:44
replaced with braces and a comment
|
| + ShellPort::Get()->UnlockCursor(); |
| + } |
| + |
| + private: |
| + void InitializeWithCursorManager(::wm::CursorManager* cursor_manager, |
| + ui::CursorType cursor) { |
| + if (cursor_manager->IsCursorLocked()) { |
| + already_locked_ = true; |
| + return; |
| + } |
| gfx::NativeCursor original_cursor = cursor_manager->GetCursor(); |
| cursor_manager_ = cursor_manager; |
| if (cursor == ui::CursorType::kNone) { |
| @@ -217,13 +237,30 @@ class ScreenshotController::ScopedCursorSetter { |
| cursor_manager_->ShowCursor(); |
| } |
| - ~ScopedCursorSetter() { |
| - if (cursor_manager_) |
| - cursor_manager_->UnlockCursor(); |
| + void InitializeWithShellPort(ui::CursorType cursor) { |
| + // No cursor manager. We are in mus mode. |
| + ShellPort* port = ShellPort::Get(); |
| + if (cursor == ui::CursorType::kNone) { |
| + port->HideCursor(); |
| + } else { |
| + port->SetGlobalOverrideCursor(ui::CursorData(cursor)); |
| + port->ShowCursor(); |
| + } |
| + port->LockCursor(); |
| + |
| + // Set/ShowCursor does not make any effects at this point but it sets |
| + // back to the original cursor when unlocked. |
| + port->SetGlobalOverrideCursor(base::nullopt); |
| + port->ShowCursor(); |
| } |
| - private: |
| - ::wm::CursorManager* cursor_manager_; |
| + // If the cursor is already locked, don't try to lock it again. |
| + bool already_locked_ = false; |
| + |
| + // If we were given a valid CursorManager, and the cursor wasn't locked, keep |
| + // track of the CursorManager we sent a LockCursor() call to so we can unlock |
| + // it in the destructor. |
| + ::wm::CursorManager* cursor_manager_ = nullptr; |
| DISALLOW_COPY_AND_ASSIGN(ScopedCursorSetter); |
| }; |