Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/utility/screenshot_controller.h" | 5 #include "ash/utility/screenshot_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/display/mouse_cursor_event_filter.h" | 9 #include "ash/display/mouse_cursor_event_filter.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "ash/screenshot_delegate.h" | 11 #include "ash/screenshot_delegate.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_port.h" | |
| 13 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
| 16 #include "ui/aura/client/screen_position_client.h" | 17 #include "ui/aura/client/screen_position_client.h" |
| 17 #include "ui/aura/window_targeter.h" | 18 #include "ui/aura/window_targeter.h" |
| 18 #include "ui/compositor/paint_recorder.h" | 19 #include "ui/compositor/paint_recorder.h" |
| 19 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
| 20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 21 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/event_handler.h" | 23 #include "ui/events/event_handler.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 gfx::Rect region_; | 192 gfx::Rect region_; |
| 192 | 193 |
| 193 gfx::Point cursor_location_in_root_; | 194 gfx::Point cursor_location_in_root_; |
| 194 | 195 |
| 195 DISALLOW_COPY_AND_ASSIGN(ScreenshotLayer); | 196 DISALLOW_COPY_AND_ASSIGN(ScreenshotLayer); |
| 196 }; | 197 }; |
| 197 | 198 |
| 198 class ScreenshotController::ScopedCursorSetter { | 199 class ScreenshotController::ScopedCursorSetter { |
| 199 public: | 200 public: |
| 200 ScopedCursorSetter(::wm::CursorManager* cursor_manager, | 201 ScopedCursorSetter(::wm::CursorManager* cursor_manager, |
| 201 gfx::NativeCursor cursor) | 202 ui::CursorType cursor) { |
| 202 : cursor_manager_(nullptr) { | 203 if (cursor_manager) |
| 203 if (cursor_manager->IsCursorLocked()) | 204 InitializeWithCursorManager(cursor_manager, cursor); |
| 205 else | |
| 206 InitializeWithShellPort(cursor); | |
| 207 } | |
| 208 | |
| 209 ~ScopedCursorSetter() { | |
| 210 if (cursor_manager_) | |
| 211 cursor_manager_->UnlockCursor(); | |
| 212 else if (already_locked_) | |
| 204 return; | 213 return; |
| 214 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
| |
| 215 ShellPort::Get()->UnlockCursor(); | |
| 216 } | |
| 217 | |
| 218 private: | |
| 219 void InitializeWithCursorManager(::wm::CursorManager* cursor_manager, | |
| 220 ui::CursorType cursor) { | |
| 221 if (cursor_manager->IsCursorLocked()) { | |
| 222 already_locked_ = true; | |
| 223 return; | |
| 224 } | |
| 205 gfx::NativeCursor original_cursor = cursor_manager->GetCursor(); | 225 gfx::NativeCursor original_cursor = cursor_manager->GetCursor(); |
| 206 cursor_manager_ = cursor_manager; | 226 cursor_manager_ = cursor_manager; |
| 207 if (cursor == ui::CursorType::kNone) { | 227 if (cursor == ui::CursorType::kNone) { |
| 208 cursor_manager_->HideCursor(); | 228 cursor_manager_->HideCursor(); |
| 209 } else { | 229 } else { |
| 210 cursor_manager_->SetCursor(cursor); | 230 cursor_manager_->SetCursor(cursor); |
| 211 cursor_manager_->ShowCursor(); | 231 cursor_manager_->ShowCursor(); |
| 212 } | 232 } |
| 213 cursor_manager_->LockCursor(); | 233 cursor_manager_->LockCursor(); |
| 214 // Set/ShowCursor does not make any effects at this point but it sets | 234 // Set/ShowCursor does not make any effects at this point but it sets |
| 215 // back to the original cursor when unlocked. | 235 // back to the original cursor when unlocked. |
| 216 cursor_manager_->SetCursor(original_cursor); | 236 cursor_manager_->SetCursor(original_cursor); |
| 217 cursor_manager_->ShowCursor(); | 237 cursor_manager_->ShowCursor(); |
| 218 } | 238 } |
| 219 | 239 |
| 220 ~ScopedCursorSetter() { | 240 void InitializeWithShellPort(ui::CursorType cursor) { |
| 221 if (cursor_manager_) | 241 // No cursor manager. We are in mus mode. |
| 222 cursor_manager_->UnlockCursor(); | 242 ShellPort* port = ShellPort::Get(); |
| 243 if (cursor == ui::CursorType::kNone) { | |
| 244 port->HideCursor(); | |
| 245 } else { | |
| 246 port->SetGlobalOverrideCursor(ui::CursorData(cursor)); | |
| 247 port->ShowCursor(); | |
| 248 } | |
| 249 port->LockCursor(); | |
| 250 | |
| 251 // Set/ShowCursor does not make any effects at this point but it sets | |
| 252 // back to the original cursor when unlocked. | |
| 253 port->SetGlobalOverrideCursor(base::nullopt); | |
| 254 port->ShowCursor(); | |
| 223 } | 255 } |
| 224 | 256 |
| 225 private: | 257 // If the cursor is already locked, don't try to lock it again. |
| 226 ::wm::CursorManager* cursor_manager_; | 258 bool already_locked_ = false; |
| 259 | |
| 260 // If we were given a valid CursorManager, and the cursor wasn't locked, keep | |
| 261 // track of the CursorManager we sent a LockCursor() call to so we can unlock | |
| 262 // it in the destructor. | |
| 263 ::wm::CursorManager* cursor_manager_ = nullptr; | |
| 227 | 264 |
| 228 DISALLOW_COPY_AND_ASSIGN(ScopedCursorSetter); | 265 DISALLOW_COPY_AND_ASSIGN(ScopedCursorSetter); |
| 229 }; | 266 }; |
| 230 | 267 |
| 231 ScreenshotController::ScreenshotController() | 268 ScreenshotController::ScreenshotController() |
| 232 : mode_(NONE), | 269 : mode_(NONE), |
| 233 root_window_(nullptr), | 270 root_window_(nullptr), |
| 234 selected_(nullptr), | 271 selected_(nullptr), |
| 235 screenshot_delegate_(nullptr) { | 272 screenshot_delegate_(nullptr) { |
| 236 // Keep this here and don't move it to StartPartialScreenshotSession(), as it | 273 // Keep this here and don't move it to StartPartialScreenshotSession(), as it |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 582 |
| 546 void ScreenshotController::OnDisplayMetricsChanged( | 583 void ScreenshotController::OnDisplayMetricsChanged( |
| 547 const display::Display& display, | 584 const display::Display& display, |
| 548 uint32_t changed_metrics) {} | 585 uint32_t changed_metrics) {} |
| 549 | 586 |
| 550 void ScreenshotController::OnWindowDestroying(aura::Window* window) { | 587 void ScreenshotController::OnWindowDestroying(aura::Window* window) { |
| 551 SetSelectedWindow(nullptr); | 588 SetSelectedWindow(nullptr); |
| 552 } | 589 } |
| 553 | 590 |
| 554 } // namespace ash | 591 } // namespace ash |
| OLD | NEW |