| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 | |
| 5 #ifndef UI_DISPLAY_MANAGER_DISPLAY_LAYOUT_H_ | |
| 6 #define UI_DISPLAY_MANAGER_DISPLAY_LAYOUT_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/macros.h" | |
| 15 #include "base/strings/string_piece.h" | |
| 16 #include "ui/display/display_export.h" | |
| 17 | |
| 18 namespace display { | |
| 19 class Display; | |
| 20 | |
| 21 // An identifier used to manage display layout in DisplayManager / | |
| 22 // DisplayLayoutStore. | |
| 23 using DisplayIdList = std::vector<int64_t>; | |
| 24 | |
| 25 using Displays = std::vector<Display>; | |
| 26 | |
| 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. | |
| 31 // | |
| 32 // + +--------+ | |
| 33 // offset | | | | |
| 34 // + | D +--------+ | |
| 35 // | | | | |
| 36 // +--------+ P | | |
| 37 // | | | |
| 38 // +--------+ | |
| 39 // | |
| 40 struct DISPLAY_EXPORT DisplayPlacement { | |
| 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. | |
| 48 enum Position { TOP, RIGHT, BOTTOM, LEFT }; | |
| 49 Position position; | |
| 50 | |
| 51 // The offset of the position with respect to the parent. | |
| 52 int offset; | |
| 53 | |
| 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 | |
| 59 DisplayPlacement(); | |
| 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 | |
| 70 DisplayPlacement(const DisplayPlacement& placement); | |
| 71 | |
| 72 DisplayPlacement& Swap(); | |
| 73 | |
| 74 std::string ToString() const; | |
| 75 | |
| 76 static std::string PositionToString(Position position); | |
| 77 static bool StringToPosition(const base::StringPiece& string, | |
| 78 Position* position); | |
| 79 }; | |
| 80 | |
| 81 class DISPLAY_EXPORT DisplayLayout final { | |
| 82 public: | |
| 83 DisplayLayout(); | |
| 84 ~DisplayLayout(); | |
| 85 | |
| 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. | |
| 90 void ApplyToDisplayList(Displays* display_list, | |
| 91 std::vector<int64_t>* updated_ids, | |
| 92 int minimum_offset_overlap) const; | |
| 93 | |
| 94 // Validates the layout object. | |
| 95 static bool Validate(const DisplayIdList& list, const DisplayLayout& layout); | |
| 96 | |
| 97 std::vector<DisplayPlacement> placement_list; | |
| 98 | |
| 99 // True if displays are mirrored. | |
| 100 bool mirrored; | |
| 101 | |
| 102 // True if multi displays should default to unified mode. | |
| 103 bool default_unified; | |
| 104 | |
| 105 // The id of the display used as a primary display. | |
| 106 int64_t primary_id; | |
| 107 | |
| 108 std::unique_ptr<DisplayLayout> Copy() const; | |
| 109 | |
| 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 | |
| 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; | |
| 120 | |
| 121 private: | |
| 122 // Apply the display placement to |display_list|. | |
| 123 // Returns true if the display bounds were updated. | |
| 124 static bool ApplyDisplayPlacement(const DisplayPlacement& placement, | |
| 125 Displays* display_list, | |
| 126 int minimum_offset_overlap); | |
| 127 | |
| 128 DISALLOW_COPY_AND_ASSIGN(DisplayLayout); | |
| 129 }; | |
| 130 | |
| 131 } // namespace display | |
| 132 | |
| 133 #endif // UI_DISPLAY_MANAGER_DISPLAY_LAYOUT_H_ | |
| OLD | NEW |