summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/style/grid_positions_resolver.h
blob: 54a6ffddca2b961483a27233b5caa9d6ea836f94 (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
// Copyright 2014 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 THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_GRID_POSITIONS_RESOLVER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_GRID_POSITIONS_RESOLVER_H_

#include "third_party/blink/renderer/core/style/grid_position.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace blink {

struct GridSpan;
class LayoutBox;
class ComputedStyle;

enum GridPositionSide {
  kColumnStartSide,
  kColumnEndSide,
  kRowStartSide,
  kRowEndSide
};

enum GridTrackSizingDirection { kForColumns, kForRows };

class NamedLineCollection {
 public:
  NamedLineCollection(const ComputedStyle&,
                      const String& named_line,
                      GridTrackSizingDirection,
                      wtf_size_t last_line,
                      wtf_size_t auto_repeat_tracks_count);

  bool HasNamedLines();
  wtf_size_t FirstPosition();

  bool Contains(wtf_size_t line);

 private:
  bool HasExplicitNamedLines();
  wtf_size_t FirstExplicitPosition();
  const Vector<wtf_size_t>* named_lines_indexes_ = nullptr;
  const Vector<wtf_size_t>* auto_repeat_named_lines_indexes_ = nullptr;
  const Vector<wtf_size_t>* implicit_named_lines_indexes_ = nullptr;

  wtf_size_t insertion_point_;
  wtf_size_t last_line_;
  wtf_size_t auto_repeat_total_tracks_;
  wtf_size_t auto_repeat_track_list_length_;

  NamedLineCollection(const NamedLineCollection&) = delete;
  NamedLineCollection& operator=(const NamedLineCollection&) = delete;
};

// This is a utility class with all the code related to grid items positions
// resolution.
class GridPositionsResolver {
  DISALLOW_NEW();

 public:
  static wtf_size_t ExplicitGridColumnCount(
      const ComputedStyle&,
      wtf_size_t auto_repeat_columns_count);
  static wtf_size_t ExplicitGridRowCount(const ComputedStyle&,
                                         wtf_size_t auto_repeat_rows_count);

  static GridPositionSide InitialPositionSide(GridTrackSizingDirection);
  static GridPositionSide FinalPositionSide(GridTrackSizingDirection);

  static wtf_size_t SpanSizeForAutoPlacedItem(const ComputedStyle&,
                                              GridTrackSizingDirection);
  static GridSpan ResolveGridPositionsFromStyle(
      const ComputedStyle&,
      const ComputedStyle&,
      GridTrackSizingDirection,
      wtf_size_t auto_repeat_tracks_count);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_GRID_POSITIONS_RESOLVER_H_