summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/geometry/ng_logical_size.h
blob: 344170e609ec6d58930fe21e9f7339ed8fff06da (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
// Copyright 2016 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 NGLogicalSize_h
#define NGLogicalSize_h

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_box_strut.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_logical_offset.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"

namespace blink {

struct NGLogicalOffset;
#define NGSizeIndefinite LayoutUnit(-1)

// NGLogicalSize is the size of rect (typically a fragment) in the logical
// coordinate system.
struct CORE_EXPORT NGLogicalSize {
  NGLogicalSize() = default;
  NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size)
      : inline_size(inline_size), block_size(block_size) {}

  // Use ToNGPhysicalSize to convert to a physical size.

  LayoutUnit inline_size;
  LayoutUnit block_size;

  bool operator==(const NGLogicalSize& other) const {
    return std::tie(other.inline_size, other.block_size) ==
           std::tie(inline_size, block_size);
  }
  bool operator!=(const NGLogicalSize& other) const {
    return !(*this == other);
  }

  bool IsEmpty() const {
    return inline_size == LayoutUnit() || block_size == LayoutUnit();
  }

  void Flip() { std::swap(inline_size, block_size); }
};

inline NGLogicalSize& operator-=(NGLogicalSize& a, const NGBoxStrut& b) {
  a.inline_size -= b.InlineSum();
  a.block_size -= b.BlockSum();
  return a;
}

CORE_EXPORT std::ostream& operator<<(std::ostream&, const NGLogicalSize&);

// NGLogicalDelta resolves the ambiguity of subtractions.
//
// "offset - offset" is ambiguous because both of below are true:
//   offset + offset = offset
//   offset + size = offset
//
// NGLogicalDelta resolves this ambiguity by allowing implicit conversions both
// to NGLogicalOffset and to NGLogicalSize.
struct CORE_EXPORT NGLogicalDelta : public NGLogicalSize {
 public:
  using NGLogicalSize::NGLogicalSize;
  operator NGLogicalOffset() const { return {inline_size, block_size}; }
};

}  // namespace blink

#endif  // NGLogicalSize_h