File: position_area.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (139 lines) | stat: -rw-r--r-- 4,919 bytes parent folder | download | duplicates (4)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2023 The Chromium Authors
// 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_POSITION_AREA_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_POSITION_AREA_H_

#include <optional>

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/anchor_query.h"
#include "third_party/blink/renderer/core/css/css_anchor_query_enums.h"
#include "third_party/blink/renderer/core/layout/geometry/box_sides.h"
#include "third_party/blink/renderer/core/layout/geometry/box_strut.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/style_self_alignment_data.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace blink {

class WritingDirectionMode;

// Possible region end points for a computed <position-area-span>
enum class PositionAreaRegion : uint8_t {
  kNone,
  kAll,
  kCenter,
  kStart,
  kEnd,
  kSelfStart,
  kSelfEnd,
  kInlineStart,
  kInlineEnd,
  kSelfInlineStart,
  kSelfInlineEnd,
  kBlockStart,
  kBlockEnd,
  kSelfBlockStart,
  kSelfBlockEnd,
  kTop,
  kBottom,
  kLeft,
  kRight,
  kXStart,
  kXEnd,
  kYStart,
  kYEnd,
  kXSelfStart,
  kXSelfEnd,
  kYSelfStart,
  kYSelfEnd,
};

// Represents the computed value for the position-area property. Each span is
// represented by two end points. That is:
//
//   "span-all" -> (kAll, kAll)
//   "center" -> (kCenter, kCenter)
//   "span-right" -> (kCenter, kRight)
//   "span-left" -> (kLeft, kCenter)
//   "top" -> (kTop, kTop)
//
// The axes are not ordered in a particular block/inline or vertical/
// horizontal order because the axes will be resolved at layout time (see
// ToPhysical() below).
class CORE_EXPORT PositionArea {
  DISALLOW_NEW();

 public:
  PositionArea() = default;
  PositionArea(PositionAreaRegion span1_start,
            PositionAreaRegion span1_end,
            PositionAreaRegion span2_start,
            PositionAreaRegion span2_end)
      : span1_start_(span1_start),
        span1_end_(span1_end),
        span2_start_(span2_start),
        span2_end_(span2_end) {}

  PositionAreaRegion FirstStart() const { return span1_start_; }
  PositionAreaRegion FirstEnd() const { return span1_end_; }
  PositionAreaRegion SecondStart() const { return span2_start_; }
  PositionAreaRegion SecondEnd() const { return span2_end_; }

  bool operator==(const PositionArea& other) const {
    return span1_start_ == other.span1_start_ &&
           span1_end_ == other.span1_end_ &&
           span2_start_ == other.span2_start_ && span2_end_ == other.span2_end_;
  }
  bool operator!=(const PositionArea& other) const { return !(*this == other); }
  bool IsNone() const { return span1_start_ == PositionAreaRegion::kNone; }

  // Convert the computed position-area into a physical representation where the
  // first span is always a top/center/bottom span, and the second is a
  // left/center/right span. If the position-area is not valid, all regions will be
  // PositionAreaRegion::kNone.
  PositionArea ToPhysical(
      const WritingDirectionMode& container_writing_direction,
      const WritingDirectionMode& self_writing_direction) const;

  // Anchored elements using position-area align towards the unused area through
  // different 'normal' behavior for align-self and justify-self. Compute the
  // alignments to be passed into ResolvedAlignSelf()/ResolvedJustifySelf().
  // Return value is an <align-self, justify-self> pair.
  std::pair<StyleSelfAlignmentData, StyleSelfAlignmentData>
  AlignJustifySelfFromPhysical(WritingDirectionMode container_writing_direction,
                               bool is_containing_block_scrollable) const;

  // Made public because they are used in unit test expectations.
  static AnchorQuery AnchorTop();
  static AnchorQuery AnchorBottom();
  static AnchorQuery AnchorLeft();
  static AnchorQuery AnchorRight();

 private:
  PositionAreaRegion span1_start_ = PositionAreaRegion::kNone;
  PositionAreaRegion span1_end_ = PositionAreaRegion::kNone;
  PositionAreaRegion span2_start_ = PositionAreaRegion::kNone;
  PositionAreaRegion span2_end_ = PositionAreaRegion::kNone;
};

// Used to store insets on ComputedStyle for adjusting the containing-block.
struct PositionAreaOffsets {
  PhysicalBoxStrut insets;
  PhysicalBoxSides behaves_as_auto;

  PositionAreaOffsets() = default;
  PositionAreaOffsets(PhysicalBoxStrut insets, PhysicalBoxSides behaves_as_auto)
      : insets(insets), behaves_as_auto(behaves_as_auto) {}

  bool operator==(const PositionAreaOffsets& other) const {
    return insets == other.insets && behaves_as_auto == other.behaves_as_auto;
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_POSITION_AREA_H_