blob: e9f85f75b95b2824f4c4e8f7f20f035a502b239d [file] [log] [blame]
robliaoc0dfd6b2016-04-07 21:33:561// Copyright 2016 The Chromium Authors. All rights reserved.
[email protected]93c7e5622013-06-28 15:12:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
kylechar731f85f92016-12-01 20:50:465#ifndef UI_DISPLAY_DISPLAY_LAYOUT_H_
6#define UI_DISPLAY_DISPLAY_LAYOUT_H_
[email protected]93c7e5622013-06-28 15:12:067
avidb567a8a2015-12-20 17:07:248#include <stdint.h>
9
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]93c7e5622013-06-28 15:12:0611#include <string>
oshima4763f822016-02-01 20:19:1812#include <vector>
[email protected]93c7e5622013-06-28 15:12:0613
oshima5df139f2016-02-17 08:56:2114#include "base/macros.h"
robliao8c912b532016-03-21 21:34:1515#include "base/strings/string_piece.h"
robliaoc0dfd6b2016-04-07 21:33:5616#include "ui/display/display_export.h"
[email protected]93c7e5622013-06-28 15:12:0617
robliaoc0dfd6b2016-04-07 21:33:5618namespace display {
oshima06b39602016-05-11 02:40:1019class Display;
[email protected]93c7e5622013-06-28 15:12:0620
oshima95d499b2016-02-10 03:49:5621// An identifier used to manage display layout in DisplayManager /
22// DisplayLayoutStore.
23using DisplayIdList = std::vector<int64_t>;
24
msw5e048a72016-09-07 18:55:3025using Displays = std::vector<Display>;
oshimaf571c4a2016-02-24 18:51:0526
robliaoec8055562016-05-11 22:55:4027// 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.
oshima95d499b2016-02-10 03:49:5631//
32// + +--------+
33// offset | | |
oshima61af6e12016-02-12 01:00:5234// + | D +--------+
oshima95d499b2016-02-10 03:49:5635// | | |
36// +--------+ P |
37// | |
38// +--------+
39//
robliaoc0dfd6b2016-04-07 21:33:5640struct DISPLAY_EXPORT DisplayPlacement {
oshima61af6e12016-02-12 01:00:5241 // 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.
oshima95d499b2016-02-10 03:49:5648 enum Position { TOP, RIGHT, BOTTOM, LEFT };
49 Position position;
50
robliaoec8055562016-05-11 22:55:4051 // The offset of the position with respect to the parent.
oshima95d499b2016-02-10 03:49:5652 int offset;
53
robliaoec8055562016-05-11 22:55:4054 // 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
oshimaf571c4a2016-02-24 18:51:0559 DisplayPlacement();
robliaoec8055562016-05-11 22:55:4060 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
robliaodf372032016-03-23 00:42:3470 DisplayPlacement(const DisplayPlacement& placement);
oshima95d499b2016-02-10 03:49:5671
72 DisplayPlacement& Swap();
73
74 std::string ToString() const;
oshimaf571c4a2016-02-24 18:51:0575
robliao8c912b532016-03-21 21:34:1576 static std::string PositionToString(Position position);
77 static bool StringToPosition(const base::StringPiece& string,
78 Position* position);
oshima95d499b2016-02-10 03:49:5679};
[email protected]93c7e5622013-06-28 15:12:0680
robliaoc0dfd6b2016-04-07 21:33:5681class DISPLAY_EXPORT DisplayLayout final {
oshima5df139f2016-02-17 08:56:2182 public:
[email protected]93c7e5622013-06-28 15:12:0683 DisplayLayout();
oshima95d499b2016-02-10 03:49:5684 ~DisplayLayout();
[email protected]93c7e5622013-06-28 15:12:0685
robliao4567a8672016-04-12 16:45:3986 // 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.
msw5e048a72016-09-07 18:55:3090 void ApplyToDisplayList(Displays* display_list,
robliao4567a8672016-04-12 16:45:3991 std::vector<int64_t>* updated_ids,
92 int minimum_offset_overlap) const;
93
oshimaf571c4a2016-02-24 18:51:0594 // Validates the layout object.
95 static bool Validate(const DisplayIdList& list, const DisplayLayout& layout);
96
robliaodf372032016-03-23 00:42:3497 std::vector<DisplayPlacement> placement_list;
[email protected]93c7e5622013-06-28 15:12:0698
99 // True if displays are mirrored.
100 bool mirrored;
101
oshimabba2d992015-05-22 19:21:39102 // True if multi displays should default to unified mode.
103 bool default_unified;
104
[email protected]93c7e5622013-06-28 15:12:06105 // The id of the display used as a primary display.
avidb567a8a2015-12-20 17:07:24106 int64_t primary_id;
[email protected]93c7e5622013-06-28 15:12:06107
danakj25c52c32016-04-12 21:51:08108 std::unique_ptr<DisplayLayout> Copy() const;
oshima5df139f2016-02-17 08:56:21109
oshimaf571c4a2016-02-24 18:51:05110 // 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
robliaodf372032016-03-23 00:42:34117 // 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;
stevenjb209a17752016-02-29 23:53:33120
oshima5df139f2016-02-17 08:56:21121 private:
robliao4567a8672016-04-12 16:45:39122 // Apply the display placement to |display_list|.
123 // Returns true if the display bounds were updated.
124 static bool ApplyDisplayPlacement(const DisplayPlacement& placement,
msw5e048a72016-09-07 18:55:30125 Displays* display_list,
robliao4567a8672016-04-12 16:45:39126 int minimum_offset_overlap);
127
oshima5df139f2016-02-17 08:56:21128 DISALLOW_COPY_AND_ASSIGN(DisplayLayout);
[email protected]93c7e5622013-06-28 15:12:06129};
130
robliaoc0dfd6b2016-04-07 21:33:56131} // namespace display
[email protected]93c7e5622013-06-28 15:12:06132
kylechar731f85f92016-12-01 20:50:46133#endif // UI_DISPLAY_DISPLAY_LAYOUT_H_