summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/list/ng_unpositioned_list_marker.h
blob: 8305cac2cf6579c71853dbb7295f17af8baa9c6e (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
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
// Copyright 2017 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_LAYOUT_NG_LIST_NG_UNPOSITIONED_LIST_MARKER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LIST_NG_UNPOSITIONED_LIST_MARKER_H_

#include "base/memory/scoped_refptr.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/platform/fonts/font_baseline.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace blink {

class ComputedStyle;
class LayoutNGListMarker;
class LayoutUnit;
class NGBlockNode;
class NGConstraintSpace;
class NGBoxFragmentBuilder;
class NGLayoutResult;
class NGPhysicalFragment;

struct LogicalOffset;
struct NGLineHeightMetrics;

// Represents an unpositioned list marker.
//
// A list item can have either block children or inline children. Because
// NGBLockLayoutAlgorithm handles the former while NGInlineLayoutAlgorithm
// handles the latter, list marker can appear in either algorithm.
//
// To handle these two cases consistently, when list markers appear in these
// algorithm, they are set as "unpositioned", and are propagated to ancestors
// through NGLayoutResult until they meet the corresponding list items.
//
// In order to adjust with the other content of LI, marker will be handled
// after other children.
// First, try to find the adjusted content_metrics for the marker. See
// |CanAddToBox()| for details.
// If found, layout marker, compute the content adjusted offset and float
// intuded offset. See |AddToBox()| for details.
// If not, layout marker and deal with it in |AddToBoxWithoutLineBoxes()|.
//
// In addition, marker makes LI non self-collapsing. If the BFC block-offset of
// LI isn't resolved after layout marker, we'll resolve it. See
// |NGBlockLayoutAlgorithm::PositionOrPropagateListMarker()| and
// |NGBlockLayoutAlgorithm::PositionListMarkerWithoutLineBoxes()| for details.
class CORE_EXPORT NGUnpositionedListMarker final {
  DISALLOW_NEW();

 public:
  NGUnpositionedListMarker() : marker_layout_object_(nullptr) {}
  explicit NGUnpositionedListMarker(LayoutNGListMarker*);
  explicit NGUnpositionedListMarker(const NGBlockNode&);

  explicit operator bool() const { return marker_layout_object_; }

  // Returns true if the list marker can be added to box. False indicates
  // that the child content does not have a baseline to align to, and that
  // caller should try next child, or "WithoutLineBoxes" version.
  bool CanAddToBox(const NGConstraintSpace&,
                   FontBaseline,
                   const NGPhysicalFragment& content,
                   NGLineHeightMetrics* content_metrics) const;
  // Add a fragment for an outside list marker.
  void AddToBox(const NGConstraintSpace&,
                FontBaseline,
                const NGPhysicalFragment& content,
                const NGBoxStrut&,
                const NGLineHeightMetrics& content_metrics,
                const NGLayoutResult& marker_layout_result,
                LogicalOffset* content_offset,
                NGBoxFragmentBuilder*) const;

  // Add a fragment for an outside list marker when the list item has no line
  // boxes.
  // Returns the block size of the list marker.
  LayoutUnit AddToBoxWithoutLineBoxes(
      const NGConstraintSpace&,
      FontBaseline,
      const NGLayoutResult& marker_layout_result,
      NGBoxFragmentBuilder*) const;
  LayoutUnit InlineOffset(const LayoutUnit marker_inline_size) const;

  bool operator==(const NGUnpositionedListMarker& other) const {
    return marker_layout_object_ == other.marker_layout_object_;
  }

  scoped_refptr<const NGLayoutResult> Layout(
      const NGConstraintSpace& parent_space,
      const ComputedStyle& parent_style,
      FontBaseline) const;

#if DCHECK_IS_ON()
  void CheckMargin() const;
#endif

 private:
  bool IsImage() const;

  LayoutUnit ComputeIntrudedFloatOffset(const NGConstraintSpace&,
                                        const NGBoxFragmentBuilder*,
                                        const NGBoxStrut&,
                                        LayoutUnit) const;

  LayoutNGListMarker* marker_layout_object_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LIST_NG_UNPOSITIONED_LIST_MARKER_H_