summaryrefslogtreecommitdiffstats
path: root/ash/display/display_layout.h
blob: af80b68a7714fcfe387a065ca9f858013ce78703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_DISPLAY_DISPLAY_LAYOUT_H_
#define ASH_DISPLAY_DISPLAY_LAYOUT_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "ash/ash_export.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"

namespace gfx {
class Display;
}

namespace base {
class Value;
template <typename T> class JSONValueConverter;
}

namespace ash {

// An identifier used to manage display layout in DisplayManager /
// DisplayLayoutStore.
using DisplayIdList = std::vector<int64_t>;

using DisplayList = std::vector<gfx::Display>;

// DisplayPlacement specifies where the display (D) is placed relative
// to parent (P) display.  In the following example, the display (D)
// given by |display_id| is placed at the left side of the parent
// display (P) given by |parent_display_id|, with a negative offset.
//
//        +      +--------+
// offset |      |        |
//        +      |   D    +--------+
//               |        |        |
//               +--------+   P    |
//                        |        |
//                        +--------+
//
struct ASH_EXPORT DisplayPlacement {
  // The id of the display this placement will be applied to.
  int64_t display_id;

  // The parent display id to which the above display is placed.
  int64_t parent_display_id;

  // To which side the parent display the display is positioned.
  enum Position { TOP, RIGHT, BOTTOM, LEFT };
  Position position;

  // The offset of the position of the secondary display. The offset is
  // based on the top/left edge of the primary display.
  int offset;

  explicit DisplayPlacement(const DisplayPlacement& placement);
  DisplayPlacement(Position position, int offset);
  DisplayPlacement();

  DisplayPlacement& Swap();

  std::string ToString() const;

  // Used by JSONValueConverter to generate DisplayPlacement from a
  // JSON value.  See json_value_converter.h.
  static void RegisterJSONConverter(
      base::JSONValueConverter<DisplayPlacement>* converter);
};

class ASH_EXPORT DisplayLayout final {
 public:
  DisplayLayout();
  ~DisplayLayout();

  // Converter functions to/from base::Value.
  static bool ConvertFromValue(const base::Value& value, DisplayLayout* layout);
  static bool ConvertToValue(const DisplayLayout& layout, base::Value* value);

  // Used by JSONValueConverter to generate DisplayLayout from a
  // JSON value.  See json_value_converter.h.
  static void RegisterJSONConverter(
      base::JSONValueConverter<DisplayLayout>* converter);

  // Validates the layout object.
  static bool Validate(const DisplayIdList& list, const DisplayLayout& layout);

  ScopedVector<DisplayPlacement> placement_list;

  // True if displays are mirrored.
  bool mirrored;

  // True if multi displays should default to unified mode.
  bool default_unified;

  // The id of the display used as a primary display.
  int64_t primary_id;

  scoped_ptr<DisplayLayout> Copy() const;

  // Test if the |layout| has the same placement list. Other fields such
  // as mirrored, primary_id are ignored.
  bool HasSamePlacementList(const DisplayLayout& layout) const;

  // Returns string representation of the layout for debugging/testing.
  std::string ToString() const;

  // Returns the DisplayPlacement entry in |placement_list| matching
  // |display_id| if it exists, otherwise returns nullptr.
  const DisplayPlacement* FindPlacementById(int64_t display_id) const;

 private:
  DISALLOW_COPY_AND_ASSIGN(DisplayLayout);
};

}  // namespace ash

#endif