unified_mouse_warp_controller.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_DISPLAY_UNIFIED_MOUSE_WARP_CONTROLLER_H_
  5. #define ASH_DISPLAY_UNIFIED_MOUSE_WARP_CONTROLLER_H_
  6. #include "ash/display/mouse_warp_controller.h"
  7. #include <stdint.h>
  8. #include <map>
  9. #include <vector>
  10. #include "ui/gfx/geometry/rect.h"
  11. namespace gfx {
  12. class Point;
  13. }
  14. namespace ash {
  15. // A MouseWarpController used in unified display mode.
  16. class ASH_EXPORT UnifiedMouseWarpController : public MouseWarpController {
  17. public:
  18. UnifiedMouseWarpController();
  19. UnifiedMouseWarpController(const UnifiedMouseWarpController&) = delete;
  20. UnifiedMouseWarpController& operator=(const UnifiedMouseWarpController&) =
  21. delete;
  22. ~UnifiedMouseWarpController() override;
  23. // MouseWarpController:
  24. bool WarpMouseCursor(ui::MouseEvent* event) override;
  25. void SetEnabled(bool enabled) override;
  26. private:
  27. friend class AshTestBase;
  28. friend class DisplayManagerTestApi;
  29. friend class UnifiedMouseWarpControllerTest;
  30. void ComputeBounds();
  31. // Warps the mouse cursor to an alternate root window when the
  32. // mouse location in |event|, hits the edge of the event target's root and
  33. // the mouse cursor is considered to be in an alternate display.
  34. // If |update_mouse_location_now| is true, the mouse location is updated
  35. // synchronously.
  36. // Returns true if the cursor was moved.
  37. bool WarpMouseCursorInNativeCoords(int64_t source_display,
  38. const gfx::Point& point_in_native,
  39. const gfx::Point& point_in_screen,
  40. bool update_mouse_location_now);
  41. void update_location_for_test() { update_location_for_test_ = true; }
  42. struct DisplayEdge {
  43. DisplayEdge(int64_t source_id,
  44. int64_t target_id,
  45. const gfx::Rect& edge_bounds)
  46. : source_display_id(source_id),
  47. target_display_id(target_id),
  48. edge_native_bounds_in_source_display(edge_bounds) {}
  49. // The ID of the display where the cursor is now.
  50. int64_t source_display_id;
  51. // The ID of the display with which there's an edge and the cursor would
  52. // move to if it resides in that edge.
  53. int64_t target_display_id;
  54. // The native bounds of the edge between the source and target displays
  55. // which is part of the source display.
  56. gfx::Rect edge_native_bounds_in_source_display;
  57. };
  58. // Maps a display by its ID to all the boundary edges that reside in it with
  59. // the surrounding displays.
  60. std::map<int64_t, std::vector<DisplayEdge>> displays_edges_map_;
  61. bool update_location_for_test_;
  62. // True if the edge boundaries between displays (where mouse cursor should
  63. // warp) have been computed.
  64. bool display_boundaries_computed_;
  65. };
  66. } // namespace ash
  67. #endif // ASH_DISPLAY_UNIFIED_MOUSE_WARP_CONTROLLER_H_