mirror_window_controller.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (c) 2013 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_MIRROR_WINDOW_CONTROLLER_H_
  5. #define ASH_DISPLAY_MIRROR_WINDOW_CONTROLLER_H_
  6. #include <stdint.h>
  7. #include <map>
  8. #include <memory>
  9. #include <vector>
  10. #include "ash/ash_export.h"
  11. #include "ash/host/ash_window_tree_host_delegate.h"
  12. #include "ui/aura/window.h"
  13. #include "ui/aura/window_tree_host_observer.h"
  14. #include "ui/display/manager/display_manager.h"
  15. #include "ui/display/manager/managed_display_info.h"
  16. namespace aura {
  17. class Window;
  18. namespace client {
  19. class ScreenPositionClient;
  20. }
  21. }
  22. namespace display {
  23. class Display;
  24. class ManagedDisplayInfo;
  25. }
  26. namespace ash {
  27. class AshWindowTreeHost;
  28. class MirrorWindowTestApi;
  29. // An object that copies the content of the primary root window to a
  30. // mirror window. This also draws a mouse cursor as the mouse cursor
  31. // is typically drawn by the window system.
  32. class ASH_EXPORT MirrorWindowController : public aura::WindowTreeHostObserver,
  33. public AshWindowTreeHostDelegate {
  34. public:
  35. MirrorWindowController();
  36. MirrorWindowController(const MirrorWindowController&) = delete;
  37. MirrorWindowController& operator=(const MirrorWindowController&) = delete;
  38. ~MirrorWindowController() override;
  39. // Updates the root window's bounds using |display_info|.
  40. // Creates the new root window if one doesn't exist.
  41. void UpdateWindow(
  42. const std::vector<display::ManagedDisplayInfo>& display_info);
  43. // Same as above, but using existing display info
  44. // for the mirrored display.
  45. void UpdateWindow();
  46. // Close the mirror window if they're not necessary any longer.
  47. void CloseIfNotNecessary();
  48. // aura::WindowTreeHostObserver overrides:
  49. void OnHostResized(aura::WindowTreeHost* host) override;
  50. // Returns the display::Display for the mirroring root window.
  51. display::Display GetDisplayForRootWindow(const aura::Window* root) const;
  52. // Returns the AshWindwoTreeHost created for |display_id|.
  53. AshWindowTreeHost* GetAshWindowTreeHostForDisplayId(int64_t display_id);
  54. // Returns all root windows hosting mirroring displays.
  55. aura::Window::Windows GetAllRootWindows() const;
  56. // AshWindowTreeHostDelegate:
  57. const display::Display* GetDisplayById(int64_t display_id) const override;
  58. void SetCurrentEventTargeterSourceHost(
  59. aura::WindowTreeHost* targeter_src_host) override;
  60. const aura::WindowTreeHost* current_event_targeter_src_host() const {
  61. return current_event_targeter_src_host_;
  62. }
  63. private:
  64. friend class MirrorWindowTestApi;
  65. struct MirroringHostInfo;
  66. // Close the mirror window. When |delay_host_deletion| is true, the window
  67. // tree host will be deleted in an another task on UI thread. This is
  68. // necessary to safely delete the WTH that is currently handling input events.
  69. void Close(bool delay_host_deletion);
  70. void CloseAndDeleteHost(MirroringHostInfo* host_info,
  71. bool delay_host_deletion);
  72. typedef std::map<int64_t, MirroringHostInfo*> MirroringHostInfoMap;
  73. MirroringHostInfoMap mirroring_host_info_map_;
  74. aura::WindowTreeHost* current_event_targeter_src_host_;
  75. display::DisplayManager::MultiDisplayMode multi_display_mode_;
  76. // The id of the display being mirrored.
  77. int64_t reflecting_source_id_ = display::kInvalidDisplayId;
  78. std::unique_ptr<aura::client::ScreenPositionClient> screen_position_client_;
  79. };
  80. } // namespace ash
  81. #endif // ASH_DISPLAY_MIRROR_WINDOW_CONTROLLER_H_