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

Side by Side Diff: ash/utility/screenshot_controller.cc

Issue 2857963003: Add {Lock,Unlock,Show,Hide}Cursor() to the window manager mojom. (Closed)
Patch Set: sky comments Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ash/shell_port.h ('k') | ash/wm/lock_state_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_) {
213 // No action; we didn't lock the cursor because it was already locked.
214 } else {
215 ShellPort::Get()->UnlockCursor();
216 }
217 }
218
219 private:
220 void InitializeWithCursorManager(::wm::CursorManager* cursor_manager,
221 ui::CursorType cursor) {
222 if (cursor_manager->IsCursorLocked()) {
223 already_locked_ = true;
204 return; 224 return;
225 }
205 gfx::NativeCursor original_cursor = cursor_manager->GetCursor(); 226 gfx::NativeCursor original_cursor = cursor_manager->GetCursor();
206 cursor_manager_ = cursor_manager; 227 cursor_manager_ = cursor_manager;
207 if (cursor == ui::CursorType::kNone) { 228 if (cursor == ui::CursorType::kNone) {
208 cursor_manager_->HideCursor(); 229 cursor_manager_->HideCursor();
209 } else { 230 } else {
210 cursor_manager_->SetCursor(cursor); 231 cursor_manager_->SetCursor(cursor);
211 cursor_manager_->ShowCursor(); 232 cursor_manager_->ShowCursor();
212 } 233 }
213 cursor_manager_->LockCursor(); 234 cursor_manager_->LockCursor();
214 // Set/ShowCursor does not make any effects at this point but it sets 235 // Set/ShowCursor does not make any effects at this point but it sets
215 // back to the original cursor when unlocked. 236 // back to the original cursor when unlocked.
216 cursor_manager_->SetCursor(original_cursor); 237 cursor_manager_->SetCursor(original_cursor);
217 cursor_manager_->ShowCursor(); 238 cursor_manager_->ShowCursor();
218 } 239 }
219 240
220 ~ScopedCursorSetter() { 241 void InitializeWithShellPort(ui::CursorType cursor) {
221 if (cursor_manager_) 242 // No cursor manager. We are in mus mode.
222 cursor_manager_->UnlockCursor(); 243 ShellPort* port = ShellPort::Get();
244 if (cursor == ui::CursorType::kNone) {
245 port->HideCursor();
246 } else {
247 port->SetGlobalOverrideCursor(ui::CursorData(cursor));
248 port->ShowCursor();
249 }
250 port->LockCursor();
251
252 // Set/ShowCursor does not make any effects at this point but it sets
253 // back to the original cursor when unlocked.
254 port->SetGlobalOverrideCursor(base::nullopt);
255 port->ShowCursor();
223 } 256 }
224 257
225 private: 258 // If the cursor is already locked, don't try to lock it again.
226 ::wm::CursorManager* cursor_manager_; 259 bool already_locked_ = false;
260
261 // If we were given a valid CursorManager, and the cursor wasn't locked, keep
262 // track of the CursorManager we sent a LockCursor() call to so we can unlock
263 // it in the destructor.
264 ::wm::CursorManager* cursor_manager_ = nullptr;
227 265
228 DISALLOW_COPY_AND_ASSIGN(ScopedCursorSetter); 266 DISALLOW_COPY_AND_ASSIGN(ScopedCursorSetter);
229 }; 267 };
230 268
231 ScreenshotController::ScreenshotController() 269 ScreenshotController::ScreenshotController()
232 : mode_(NONE), 270 : mode_(NONE),
233 root_window_(nullptr), 271 root_window_(nullptr),
234 selected_(nullptr), 272 selected_(nullptr),
235 screenshot_delegate_(nullptr) { 273 screenshot_delegate_(nullptr) {
236 // Keep this here and don't move it to StartPartialScreenshotSession(), as it 274 // Keep this here and don't move it to StartPartialScreenshotSession(), as it
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 583
546 void ScreenshotController::OnDisplayMetricsChanged( 584 void ScreenshotController::OnDisplayMetricsChanged(
547 const display::Display& display, 585 const display::Display& display,
548 uint32_t changed_metrics) {} 586 uint32_t changed_metrics) {}
549 587
550 void ScreenshotController::OnWindowDestroying(aura::Window* window) { 588 void ScreenshotController::OnWindowDestroying(aura::Window* window) {
551 SetSelectedWindow(nullptr); 589 SetSelectedWindow(nullptr);
552 } 590 }
553 591
554 } // namespace ash 592 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell_port.h ('k') | ash/wm/lock_state_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698