robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame^] | 5 | #ifndef UI_DISPLAY_DISPLAY_LAYOUT_H_ |
| 6 | #define UI_DISPLAY_DISPLAY_LAYOUT_H_ |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 7 | |
avi | db567a8a | 2015-12-20 17:07:24 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 11 | #include <string> |
oshima | 4763f82 | 2016-02-01 20:19:18 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 13 | |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 14 | #include "base/macros.h" |
robliao | 8c912b53 | 2016-03-21 21:34:15 | [diff] [blame] | 15 | #include "base/strings/string_piece.h" |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 16 | #include "ui/display/display_export.h" |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 17 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 18 | namespace display { |
oshima | 06b3960 | 2016-05-11 02:40:10 | [diff] [blame] | 19 | class Display; |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 20 | |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 21 | // An identifier used to manage display layout in DisplayManager / |
| 22 | // DisplayLayoutStore. |
| 23 | using DisplayIdList = std::vector<int64_t>; |
| 24 | |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 25 | using Displays = std::vector<Display>; |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 26 | |
robliao | ec805556 | 2016-05-11 22:55:40 | [diff] [blame] | 27 | // DisplayPlacement specifies where the display (D) is placed relative to |
| 28 | // parent (P) display. In the following example, D given by |display_id| is |
| 29 | // placed at the left side of P given by |parent_display_id|, with a negative |
| 30 | // offset and a top-left offset reference. |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 31 | // |
| 32 | // + +--------+ |
| 33 | // offset | | | |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 34 | // + | D +--------+ |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 35 | // | | | |
| 36 | // +--------+ P | |
| 37 | // | | |
| 38 | // +--------+ |
| 39 | // |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 40 | struct DISPLAY_EXPORT DisplayPlacement { |
oshima | 61af6e1 | 2016-02-12 01:00:52 | [diff] [blame] | 41 | // The id of the display this placement will be applied to. |
| 42 | int64_t display_id; |
| 43 | |
| 44 | // The parent display id to which the above display is placed. |
| 45 | int64_t parent_display_id; |
| 46 | |
| 47 | // To which side the parent display the display is positioned. |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 48 | enum Position { TOP, RIGHT, BOTTOM, LEFT }; |
| 49 | Position position; |
| 50 | |
robliao | ec805556 | 2016-05-11 22:55:40 | [diff] [blame] | 51 | // The offset of the position with respect to the parent. |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 52 | int offset; |
| 53 | |
robliao | ec805556 | 2016-05-11 22:55:40 | [diff] [blame] | 54 | // Determines if the offset is relative to the TOP_LEFT or the BOTTOM_RIGHT. |
| 55 | // Defaults to TOP_LEFT. |
| 56 | enum OffsetReference { TOP_LEFT, BOTTOM_RIGHT }; |
| 57 | OffsetReference offset_reference; |
| 58 | |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 59 | DisplayPlacement(); |
robliao | ec805556 | 2016-05-11 22:55:40 | [diff] [blame] | 60 | DisplayPlacement(Position position, int offset); |
| 61 | DisplayPlacement(Position position, |
| 62 | int offset, |
| 63 | OffsetReference offset_reference); |
| 64 | DisplayPlacement(int64_t display_id, |
| 65 | int64_t parent_display_id, |
| 66 | Position position, |
| 67 | int offset, |
| 68 | OffsetReference offset_reference); |
| 69 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 70 | DisplayPlacement(const DisplayPlacement& placement); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 71 | |
| 72 | DisplayPlacement& Swap(); |
| 73 | |
| 74 | std::string ToString() const; |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 75 | |
robliao | 8c912b53 | 2016-03-21 21:34:15 | [diff] [blame] | 76 | static std::string PositionToString(Position position); |
| 77 | static bool StringToPosition(const base::StringPiece& string, |
| 78 | Position* position); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 79 | }; |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 80 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 81 | class DISPLAY_EXPORT DisplayLayout final { |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 82 | public: |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 83 | DisplayLayout(); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 84 | ~DisplayLayout(); |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 85 | |
robliao | 4567a867 | 2016-04-12 16:45:39 | [diff] [blame] | 86 | // Applies the layout to the displays in |display_list|. |
| 87 | // |updated_ids| (optional) contains the ids for displays whose bounds have |
| 88 | // changed. |minimum_offset_overlap| represents the minimum required overlap |
| 89 | // between displays. |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 90 | void ApplyToDisplayList(Displays* display_list, |
robliao | 4567a867 | 2016-04-12 16:45:39 | [diff] [blame] | 91 | std::vector<int64_t>* updated_ids, |
| 92 | int minimum_offset_overlap) const; |
| 93 | |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 94 | // Validates the layout object. |
| 95 | static bool Validate(const DisplayIdList& list, const DisplayLayout& layout); |
| 96 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 97 | std::vector<DisplayPlacement> placement_list; |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 98 | |
| 99 | // True if displays are mirrored. |
| 100 | bool mirrored; |
| 101 | |
oshima | bba2d99 | 2015-05-22 19:21:39 | [diff] [blame] | 102 | // True if multi displays should default to unified mode. |
| 103 | bool default_unified; |
| 104 | |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 105 | // The id of the display used as a primary display. |
avi | db567a8a | 2015-12-20 17:07:24 | [diff] [blame] | 106 | int64_t primary_id; |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 107 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 108 | std::unique_ptr<DisplayLayout> Copy() const; |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 109 | |
oshima | f571c4a | 2016-02-24 18:51:05 | [diff] [blame] | 110 | // Test if the |layout| has the same placement list. Other fields such |
| 111 | // as mirrored, primary_id are ignored. |
| 112 | bool HasSamePlacementList(const DisplayLayout& layout) const; |
| 113 | |
| 114 | // Returns string representation of the layout for debugging/testing. |
| 115 | std::string ToString() const; |
| 116 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 117 | // Returns the DisplayPlacement entry matching |display_id| if it exists, |
| 118 | // otherwise returns a DisplayPlacement with an invalid display id. |
| 119 | DisplayPlacement FindPlacementById(int64_t display_id) const; |
stevenjb | 209a1775 | 2016-02-29 23:53:33 | [diff] [blame] | 120 | |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 121 | private: |
robliao | 4567a867 | 2016-04-12 16:45:39 | [diff] [blame] | 122 | // Apply the display placement to |display_list|. |
| 123 | // Returns true if the display bounds were updated. |
| 124 | static bool ApplyDisplayPlacement(const DisplayPlacement& placement, |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 125 | Displays* display_list, |
robliao | 4567a867 | 2016-04-12 16:45:39 | [diff] [blame] | 126 | int minimum_offset_overlap); |
| 127 | |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 128 | DISALLOW_COPY_AND_ASSIGN(DisplayLayout); |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 129 | }; |
| 130 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 131 | } // namespace display |
[email protected] | 93c7e562 | 2013-06-28 15:12:06 | [diff] [blame] | 132 | |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame^] | 133 | #endif // UI_DISPLAY_DISPLAY_LAYOUT_H_ |