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/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/display/mouse_cursor_event_filter.h" | 10 #include "ash/display/mouse_cursor_event_filter.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/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "ui/aura/client/capture_client.h" | |
| 16 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
| 17 #include "ui/aura/window_targeter.h" | 16 #include "ui/aura/window_targeter.h" |
| 18 #include "ui/compositor/paint_recorder.h" | 17 #include "ui/compositor/paint_recorder.h" |
| 19 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
| 20 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 21 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/event_handler.h" | 21 #include "ui/events/event_handler.h" |
| 23 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 25 #include "ui/wm/core/cursor_manager.h" | 24 #include "ui/wm/core/cursor_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 55 display::Screen::GetScreen()->GetDisplayNearestPoint(location); | 54 display::Screen::GetScreen()->GetDisplayNearestPoint(location); |
| 56 | 55 |
| 57 aura::Window* root_window = Shell::GetInstance() | 56 aura::Window* root_window = Shell::GetInstance() |
| 58 ->window_tree_host_manager() | 57 ->window_tree_host_manager() |
| 59 ->GetRootWindowForDisplayId(display.id()); | 58 ->GetRootWindowForDisplayId(display.id()); |
| 60 | 59 |
| 61 position_client->ConvertPointFromScreen(root_window, &location); | 60 position_client->ConvertPointFromScreen(root_window, &location); |
| 62 | 61 |
| 63 gfx::Point target_location = event->location(); | 62 gfx::Point target_location = event->location(); |
| 64 event->set_location(location); | 63 event->set_location(location); |
| 65 | |
| 66 // Ignore capture window when finding the target for located event. | |
|
Evan Stade
2016/10/06 16:32:34
so I noticed this bit of code as well, which seems
oshima
2016/10/06 20:07:53
This is to deal with menu windows, so please do no
| |
| 67 aura::client::CaptureClient* original_capture_client = | |
| 68 aura::client::GetCaptureClient(root_window); | |
| 69 aura::client::SetCaptureClient(root_window, nullptr); | |
| 70 | |
| 71 aura::Window* selected = | 64 aura::Window* selected = |
| 72 static_cast<aura::Window*>(FindTargetForEvent(root_window, event)); | 65 static_cast<aura::Window*>(FindTargetForEvent(root_window, event)); |
| 73 | 66 |
| 74 // Restore State. | 67 // Restore State. |
| 75 aura::client::SetCaptureClient(root_window, original_capture_client); | |
| 76 event->set_location(target_location); | 68 event->set_location(target_location); |
| 77 return selected; | 69 return selected; |
| 78 } | 70 } |
| 79 | 71 |
| 80 private: | 72 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(ScreenshotWindowTargeter); | 73 DISALLOW_COPY_AND_ASSIGN(ScreenshotWindowTargeter); |
| 82 }; | 74 }; |
| 83 | 75 |
| 84 } // namespace | 76 } // namespace |
| 85 | 77 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 CancelScreenshotSession(); | 240 CancelScreenshotSession(); |
| 249 Shell::GetInstance()->RemovePreTargetHandler(this); | 241 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 250 } | 242 } |
| 251 | 243 |
| 252 void ScreenshotController::StartWindowScreenshotSession( | 244 void ScreenshotController::StartWindowScreenshotSession( |
| 253 ScreenshotDelegate* screenshot_delegate) { | 245 ScreenshotDelegate* screenshot_delegate) { |
| 254 if (screenshot_delegate_) { | 246 if (screenshot_delegate_) { |
| 255 DCHECK_EQ(screenshot_delegate_, screenshot_delegate); | 247 DCHECK_EQ(screenshot_delegate_, screenshot_delegate); |
| 256 return; | 248 return; |
| 257 } | 249 } |
| 250 | |
| 251 for (aura::Window* root : Shell::GetAllRootWindows()) { | |
| 252 // Since we'll be pre-handling all mouse events, break any existing | |
| 253 // captures. | |
| 254 aura::client::GetCaptureClient(root)->SetCapture(nullptr); | |
| 255 layers_[root] = base::MakeUnique<ScreenshotLayer>( | |
| 256 Shell::GetContainer(root, kShellWindowId_OverlayContainer)->layer(), | |
| 257 true); | |
| 258 } | |
| 259 | |
| 258 screenshot_delegate_ = screenshot_delegate; | 260 screenshot_delegate_ = screenshot_delegate; |
| 259 mode_ = WINDOW; | 261 mode_ = WINDOW; |
| 260 | 262 |
| 261 display::Screen::GetScreen()->AddObserver(this); | 263 display::Screen::GetScreen()->AddObserver(this); |
| 262 for (aura::Window* root : Shell::GetAllRootWindows()) { | |
| 263 layers_[root] = base::MakeUnique<ScreenshotLayer>( | |
| 264 Shell::GetContainer(root, kShellWindowId_OverlayContainer)->layer(), | |
| 265 true); | |
| 266 } | |
| 267 SetSelectedWindow(wm::GetActiveWindow()); | 264 SetSelectedWindow(wm::GetActiveWindow()); |
| 268 | 265 |
| 269 cursor_setter_.reset(new ScopedCursorSetter( | 266 cursor_setter_.reset(new ScopedCursorSetter( |
| 270 Shell::GetInstance()->cursor_manager(), ui::kCursorCross)); | 267 Shell::GetInstance()->cursor_manager(), ui::kCursorCross)); |
| 271 | 268 |
| 272 EnableMouseWarp(true); | 269 EnableMouseWarp(true); |
| 273 } | 270 } |
| 274 | 271 |
| 275 void ScreenshotController::StartPartialScreenshotSession( | 272 void ScreenshotController::StartPartialScreenshotSession( |
| 276 ScreenshotDelegate* screenshot_delegate, | 273 ScreenshotDelegate* screenshot_delegate, |
| 277 bool draw_overlay_immediately) { | 274 bool draw_overlay_immediately) { |
| 278 // Already in a screenshot session. | 275 // Already in a screenshot session. |
| 279 if (screenshot_delegate_) { | 276 if (screenshot_delegate_) { |
| 280 DCHECK_EQ(screenshot_delegate_, screenshot_delegate); | 277 DCHECK_EQ(screenshot_delegate_, screenshot_delegate); |
| 281 return; | 278 return; |
| 282 } | 279 } |
| 283 | 280 |
| 281 for (aura::Window* root : Shell::GetAllRootWindows()) { | |
| 282 // Since we'll be pre-handling all mouse events, break any existing | |
| 283 // captures. | |
| 284 aura::client::GetCaptureClient(root)->SetCapture(nullptr); | |
| 285 layers_[root] = base::MakeUnique<ScreenshotLayer>( | |
| 286 Shell::GetContainer(root, kShellWindowId_OverlayContainer)->layer(), | |
| 287 draw_overlay_immediately); | |
| 288 } | |
| 289 | |
| 284 screenshot_delegate_ = screenshot_delegate; | 290 screenshot_delegate_ = screenshot_delegate; |
| 285 mode_ = PARTIAL; | 291 mode_ = PARTIAL; |
| 286 display::Screen::GetScreen()->AddObserver(this); | 292 display::Screen::GetScreen()->AddObserver(this); |
| 287 for (aura::Window* root : Shell::GetAllRootWindows()) { | |
| 288 layers_[root] = base::MakeUnique<ScreenshotLayer>( | |
| 289 Shell::GetContainer(root, kShellWindowId_OverlayContainer)->layer(), | |
| 290 draw_overlay_immediately); | |
| 291 } | |
| 292 | 293 |
| 293 if (!pen_events_only_) { | 294 if (!pen_events_only_) { |
| 294 cursor_setter_.reset(new ScopedCursorSetter( | 295 cursor_setter_.reset(new ScopedCursorSetter( |
| 295 Shell::GetInstance()->cursor_manager(), ui::kCursorCross)); | 296 Shell::GetInstance()->cursor_manager(), ui::kCursorCross)); |
| 296 } | 297 } |
| 297 | 298 |
| 298 EnableMouseWarp(false); | 299 EnableMouseWarp(false); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void ScreenshotController::CancelScreenshotSession() { | 302 void ScreenshotController::CancelScreenshotSession() { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 event->StopPropagation(); | 436 event->StopPropagation(); |
| 436 } else if (event->key_code() == ui::VKEY_RETURN && mode_ == WINDOW) { | 437 } else if (event->key_code() == ui::VKEY_RETURN && mode_ == WINDOW) { |
| 437 CompleteWindowScreenshot(); | 438 CompleteWindowScreenshot(); |
| 438 event->StopPropagation(); | 439 event->StopPropagation(); |
| 439 } | 440 } |
| 440 } | 441 } |
| 441 | 442 |
| 442 // Stop all key events except if the user is using a pointer, in which case | 443 // Stop all key events except if the user is using a pointer, in which case |
| 443 // they should be able to continue manipulating the screen. | 444 // they should be able to continue manipulating the screen. |
| 444 if (!pen_events_only_) | 445 if (!pen_events_only_) |
| 445 event->StopPropagation(); | 446 event->StopPropagation(); |
|
oshima
2016/10/06 20:07:53
how about passing through the event that is requir
Evan Stade
2016/10/06 20:21:19
I don't think that would fix the tab dragging case
| |
| 446 } | 447 } |
| 447 | 448 |
| 448 void ScreenshotController::OnMouseEvent(ui::MouseEvent* event) { | 449 void ScreenshotController::OnMouseEvent(ui::MouseEvent* event) { |
| 449 if (!screenshot_delegate_ || !ShouldProcessEvent(event->pointer_details())) | 450 if (!screenshot_delegate_ || !ShouldProcessEvent(event->pointer_details())) |
| 450 return; | 451 return; |
| 451 switch (mode_) { | 452 switch (mode_) { |
| 452 case NONE: | 453 case NONE: |
| 453 NOTREACHED(); | 454 NOTREACHED(); |
| 454 break; | 455 break; |
| 455 case WINDOW: | 456 case WINDOW: |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 | 543 |
| 543 void ScreenshotController::OnDisplayMetricsChanged( | 544 void ScreenshotController::OnDisplayMetricsChanged( |
| 544 const display::Display& display, | 545 const display::Display& display, |
| 545 uint32_t changed_metrics) {} | 546 uint32_t changed_metrics) {} |
| 546 | 547 |
| 547 void ScreenshotController::OnWindowDestroying(aura::Window* window) { | 548 void ScreenshotController::OnWindowDestroying(aura::Window* window) { |
| 548 SetSelectedWindow(nullptr); | 549 SetSelectedWindow(nullptr); |
| 549 } | 550 } |
| 550 | 551 |
| 551 } // namespace ash | 552 } // namespace ash |
| OLD | NEW |