1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_DISPLAY_DISPLAY_ALIGNMENT_INDICATOR_H_
6 #define ASH_DISPLAY_DISPLAY_ALIGNMENT_INDICATOR_H_
10 #include "ash/ash_export.h"
11 #include "base/memory/raw_ptr.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/views/widget/widget.h"
17 } // namespace display
21 class IndicatorHighlightView;
22 class IndicatorPillView;
24 // DisplayAlignmentIndicator is a container for indicator highlighting a shared
25 // edge between two displays and a pill that contains an arrow and target
27 class ASH_EXPORT DisplayAlignmentIndicator {
29 // Construct and show indicator highlight without a pill.
30 // |src_display| is the display that the indicator is shown in.
31 // |bounds| is the position and size of the 1px thick shared edge between
32 // |src_display| and target display.
33 static std::unique_ptr<DisplayAlignmentIndicator> Create(
34 const display::Display& src_display,
35 const gfx::Rect& bounds);
37 // Construct and show indicator highlight with a pill.
38 // |src_display| is the display that the indicator is shown in.
39 // |bounds| is the position and size of the 1px thick shared edge between
40 // |src_display| and target display. |target_name| is the name of the adjacent
41 // display that is displayed in the pill.
42 static std::unique_ptr<DisplayAlignmentIndicator> CreateWithPill(
43 const display::Display& src_display,
44 const gfx::Rect& bounds,
45 const std::string& target_name);
47 DisplayAlignmentIndicator(const DisplayAlignmentIndicator&) = delete;
48 DisplayAlignmentIndicator& operator=(const DisplayAlignmentIndicator&) =
50 ~DisplayAlignmentIndicator();
52 int64_t display_id() const { return display_id_; }
54 // Shows/Hides the indicator.
58 // Updates the position of the indicator according to |bounds|. Used to move
59 // around preview indicators during dragging. The indicator must NOT have a
61 void Update(const display::Display& display, gfx::Rect bounds);
64 friend class DisplayAlignmentIndicatorTest;
65 friend class DisplayAlignmentControllerTest;
67 // Pill does not render if |target_name| is an empty string.
68 DisplayAlignmentIndicator(const display::Display& src_display,
69 const gfx::Rect& bounds,
70 const std::string& target_name);
72 // The ID of the display that the indicator is shown on.
73 const int64_t display_id_;
75 // View and Widget for showing the blue indicator highlights on the edge of
77 raw_ptr<IndicatorHighlightView, DanglingUntriaged | ExperimentalAsh>
78 indicator_view_ = nullptr; // NOT OWNED
79 views::Widget indicator_widget_;
81 // View and Widget for showing a pill with name of the neighboring display and
82 // an arrow pointing towards it. May not be initialized if ctor without
83 // |target_name| is used (for preview indicator).
84 raw_ptr<IndicatorPillView, DanglingUntriaged | ExperimentalAsh> pill_view_ =
86 std::unique_ptr<views::Widget> pill_widget_;
91 #endif // ASH_DISPLAY_DISPLAY_ALIGNMENT_INDICATOR_H_