display_alignment_indicator.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2020 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_DISPLAY_ALIGNMENT_INDICATOR_H_
  5. #define ASH_DISPLAY_DISPLAY_ALIGNMENT_INDICATOR_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. #include "ui/views/widget/widget.h"
  10. namespace display {
  11. class Display;
  12. } // namespace display
  13. namespace ash {
  14. class IndicatorHighlightView;
  15. class IndicatorPillView;
  16. // DisplayAlignmentIndicator is a container for indicator highlighting a shared
  17. // edge between two displays and a pill that contains an arrow and target
  18. // display's name.
  19. class ASH_EXPORT DisplayAlignmentIndicator {
  20. public:
  21. // Construct and show indicator highlight without a pill.
  22. // |src_display| is the display that the indicator is shown in.
  23. // |bounds| is the position and size of the 1px thick shared edge between
  24. // |src_display| and target display.
  25. static std::unique_ptr<DisplayAlignmentIndicator> Create(
  26. const display::Display& src_display,
  27. const gfx::Rect& bounds);
  28. // Construct and show indicator highlight with a pill.
  29. // |src_display| is the display that the indicator is shown in.
  30. // |bounds| is the position and size of the 1px thick shared edge between
  31. // |src_display| and target display. |target_name| is the name of the adjacent
  32. // display that is displayed in the pill.
  33. static std::unique_ptr<DisplayAlignmentIndicator> CreateWithPill(
  34. const display::Display& src_display,
  35. const gfx::Rect& bounds,
  36. const std::string& target_name);
  37. DisplayAlignmentIndicator(const DisplayAlignmentIndicator&) = delete;
  38. DisplayAlignmentIndicator& operator=(const DisplayAlignmentIndicator&) =
  39. delete;
  40. ~DisplayAlignmentIndicator();
  41. int64_t display_id() const { return display_id_; }
  42. // Shows/Hides the indicator.
  43. void Show();
  44. void Hide();
  45. // Updates the position of the indicator according to |bounds|. Used to move
  46. // around preview indicators during dragging. The indicator must NOT have a
  47. // pill.
  48. void Update(const display::Display& display, gfx::Rect bounds);
  49. private:
  50. friend class DisplayAlignmentIndicatorTest;
  51. friend class DisplayAlignmentControllerTest;
  52. // Pill does not render if |target_name| is an empty string.
  53. DisplayAlignmentIndicator(const display::Display& src_display,
  54. const gfx::Rect& bounds,
  55. const std::string& target_name);
  56. // The ID of the display that the indicator is shown on.
  57. const int64_t display_id_;
  58. // View and Widget for showing the blue indicator highlights on the edge of
  59. // the display.
  60. IndicatorHighlightView* indicator_view_ = nullptr; // NOT OWNED
  61. views::Widget indicator_widget_;
  62. // View and Widget for showing a pill with name of the neighboring display and
  63. // an arrow pointing towards it. May not be initialized if ctor without
  64. // |target_name| is used (for preview indicator).
  65. IndicatorPillView* pill_view_ = nullptr; // NOT OWNED
  66. std::unique_ptr<views::Widget> pill_widget_;
  67. };
  68. } // namespace ash
  69. #endif // ASH_DISPLAY_DISPLAY_ALIGNMENT_INDICATOR_H_