File: axis.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 (105 lines) | stat: -rw-r--r-- 3,801 bytes parent folder | download | duplicates (6)
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
// Copyright 2021 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_LAYOUT_GEOMETRY_AXIS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_GEOMETRY_AXIS_H_

#include "base/types/strong_alias.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"

namespace blink {

enum class LogicalAxis : uint8_t { kInline = 0b01, kBlock = 0b10 };
enum class PhysicalAxis : uint8_t { kHorizontal = 0b01, kVertical = 0b10 };

using PhysicalAxes = base::StrongAlias<class PhysicalAxesTag, uint8_t>;
using LogicalAxes = base::StrongAlias<class LogicalAxesTag, uint8_t>;

inline constexpr LogicalAxes operator|(LogicalAxes a, LogicalAxes b) {
  return LogicalAxes(a.value() | b.value());
}

inline constexpr LogicalAxes& operator|=(LogicalAxes& a, LogicalAxes b) {
  a.value() |= b.value();
  return a;
}

inline constexpr LogicalAxes operator&(LogicalAxes a, LogicalAxes b) {
  return LogicalAxes(a.value() & b.value());
}

inline constexpr LogicalAxes operator&=(LogicalAxes& a, LogicalAxes b) {
  a.value() &= b.value();
  return a;
}

inline constexpr PhysicalAxes operator|(PhysicalAxes a, PhysicalAxes b) {
  return PhysicalAxes(a.value() | b.value());
}

inline constexpr PhysicalAxes& operator|=(PhysicalAxes& a, PhysicalAxes b) {
  a.value() |= b.value();
  return a;
}

inline constexpr PhysicalAxes operator&(PhysicalAxes a, PhysicalAxes b) {
  return PhysicalAxes(a.value() & b.value());
}

inline constexpr PhysicalAxes operator&=(PhysicalAxes& a, PhysicalAxes b) {
  a.value() &= b.value();
  return a;
}

inline constexpr PhysicalAxes operator^(PhysicalAxes a, PhysicalAxes b) {
  return PhysicalAxes(a.value() ^ b.value());
}

inline constexpr PhysicalAxes operator^=(PhysicalAxes& a, PhysicalAxes b) {
  a.value() ^= b.value();
  return a;
}

inline constexpr LogicalAxes kLogicalAxesNone = LogicalAxes(0);
inline constexpr LogicalAxes kLogicalAxesInline =
    LogicalAxes(static_cast<uint8_t>(LogicalAxis::kInline));
inline constexpr LogicalAxes kLogicalAxesBlock =
    LogicalAxes(static_cast<uint8_t>(LogicalAxis::kBlock));
inline constexpr LogicalAxes kLogicalAxesBoth =
    kLogicalAxesInline | kLogicalAxesBlock;

inline constexpr PhysicalAxes kPhysicalAxesNone = PhysicalAxes(0);
inline constexpr PhysicalAxes kPhysicalAxesHorizontal =
    PhysicalAxes(static_cast<uint8_t>(PhysicalAxis::kHorizontal));
inline constexpr PhysicalAxes kPhysicalAxesVertical =
    PhysicalAxes(static_cast<uint8_t>(PhysicalAxis::kVertical));
inline constexpr PhysicalAxes kPhysicalAxesBoth =
    kPhysicalAxesHorizontal | kPhysicalAxesVertical;

// ConvertAxes relies on the fact that the underlying values for
// for Inline/Horizontal are the same, and that the underlying values for
// Block/Vertical are the same.
static_assert(kLogicalAxesNone.value() == kPhysicalAxesNone.value());
static_assert(kLogicalAxesInline.value() == kPhysicalAxesHorizontal.value());
static_assert(kLogicalAxesBlock.value() == kPhysicalAxesVertical.value());
static_assert(kLogicalAxesBoth.value() == kPhysicalAxesBoth.value());

template <typename FromType, typename ToType>
inline ToType ConvertAxes(FromType from, WritingMode mode) {
  // Reverse the bits if |mode| is a vertical writing mode.
  int shift = !IsHorizontalWritingMode(mode);
  return ToType(((from.value() >> shift) & 1) | ((from.value() << shift) & 2));
}

inline PhysicalAxes ToPhysicalAxes(LogicalAxes logical, WritingMode mode) {
  return ConvertAxes<LogicalAxes, PhysicalAxes>(logical, mode);
}

inline LogicalAxes ToLogicalAxes(PhysicalAxes physical, WritingMode mode) {
  return ConvertAxes<PhysicalAxes, LogicalAxes>(physical, mode);
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_GEOMETRY_AXIS_H_