1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GEOMETRY_NG_BFC_RECT_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GEOMETRY_NG_BFC_RECT_H_
7 
8 #include "third_party/blink/renderer/core/core_export.h"
9 #include "third_party/blink/renderer/core/layout/geometry/logical_size.h"
10 #include "third_party/blink/renderer/core/layout/ng/geometry/ng_bfc_offset.h"
11 #include "third_party/blink/renderer/platform/geometry/layout_unit.h"
12 
13 namespace blink {
14 
15 // NGBfcRect is the position and size of a rect (typically a fragment)
16 // relative to a block formatting context.
17 struct CORE_EXPORT NGBfcRect {
NGBfcRectNGBfcRect18   NGBfcRect(const NGBfcOffset& start_offset, const NGBfcOffset& end_offset)
19       : start_offset(start_offset), end_offset(end_offset) {
20     DCHECK_GE(end_offset.line_offset, start_offset.line_offset);
21     DCHECK_GE(end_offset.block_offset, start_offset.block_offset);
22   }
23 
LineStartOffsetNGBfcRect24   LayoutUnit LineStartOffset() const { return start_offset.line_offset; }
LineEndOffsetNGBfcRect25   LayoutUnit LineEndOffset() const { return end_offset.line_offset; }
BlockStartOffsetNGBfcRect26   LayoutUnit BlockStartOffset() const { return start_offset.block_offset; }
BlockEndOffsetNGBfcRect27   LayoutUnit BlockEndOffset() const { return end_offset.block_offset; }
28 
BlockSizeNGBfcRect29   LayoutUnit BlockSize() const {
30     if (end_offset.block_offset == LayoutUnit::Max())
31       return LayoutUnit::Max();
32 
33     return end_offset.block_offset - start_offset.block_offset;
34   }
InlineSizeNGBfcRect35   LayoutUnit InlineSize() const {
36     if (end_offset.line_offset == LayoutUnit::Max())
37       return LayoutUnit::Max();
38 
39     return end_offset.line_offset - start_offset.line_offset;
40   }
41 
42   bool operator==(const NGBfcRect& other) const {
43     return start_offset == other.start_offset && end_offset == other.end_offset;
44   }
45 
46   bool operator!=(const NGBfcRect& other) const { return !(*this == other); }
47 
48   NGBfcOffset start_offset;
49   NGBfcOffset end_offset;
50 };
51 
52 }  // namespace blink
53 
54 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GEOMETRY_NG_BFC_RECT_H_
55