summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/layout_ng_mixin.h
blob: 477d924a18b398a09fa8e4843edc91e1903944fd (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
114
115
116
117
118
119
120
121
122
123
124
// 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 LayoutNGMixin_h
#define LayoutNGMixin_h

#include <type_traits>

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_table_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"

namespace blink {

enum class NGBaselineAlgorithmType;
class NGBreakToken;
class NGConstraintSpace;
class NGLayoutResult;
class NGPaintFragment;
class NGPhysicalFragment;
struct NGBaseline;
struct NGInlineNodeData;
struct NGPhysicalOffset;

// This mixin holds code shared between LayoutNG subclasses of
// LayoutBlockFlow.

template <typename Base>
class LayoutNGMixin : public Base {
 public:
  explicit LayoutNGMixin(Element* element);
  ~LayoutNGMixin() override;

  bool IsLayoutNGObject() const final { return true; }

  NGInlineNodeData* TakeNGInlineNodeData() final;
  NGInlineNodeData* GetNGInlineNodeData() const final;
  void ResetNGInlineNodeData() final;
  bool HasNGInlineNodeData() const final { return ng_inline_node_data_.get(); }

  LayoutUnit FirstLineBoxBaseline() const final;
  LayoutUnit InlineBlockBaseline(LineDirectionMode) const final;

  void InvalidateDisplayItemClients(PaintInvalidationReason) const final;

  void Paint(const PaintInfo&) const final;

  bool NodeAtPoint(HitTestResult&,
                   const HitTestLocation& location_in_container,
                   const LayoutPoint& accumulated_offset,
                   HitTestAction) final;

  PositionWithAffinity PositionForPoint(const LayoutPoint&) const final;

  // Returns the last layout result for this block flow with the given
  // constraint space and break token, or null if it is not up-to-date or
  // otherwise unavailable.
  scoped_refptr<NGLayoutResult> CachedLayoutResult(
      const NGConstraintSpace&,
      const NGBreakToken*) const final;

  void SetCachedLayoutResult(const NGConstraintSpace&,
                             const NGBreakToken*,
                             const NGLayoutResult&) final;
  void ClearCachedLayoutResult() final;

  // For testing only.
  scoped_refptr<const NGLayoutResult> CachedLayoutResultForTesting() final;

  NGPaintFragment* PaintFragment() const final { return paint_fragment_.get(); }
  void SetPaintFragment(const NGBreakToken*,
                        scoped_refptr<const NGPhysicalFragment>,
                        NGPhysicalOffset) final;
  void UpdatePaintFragmentFromCachedLayoutResult(
      const NGBreakToken*,
      scoped_refptr<const NGPhysicalFragment>,
      NGPhysicalOffset) final;

 protected:
  bool IsOfType(LayoutObject::LayoutObjectType) const override;

  void AddVisualOverflowFromChildren() final;
  void AddLayoutOverflowFromChildren() final;

 private:
  void AddScrollingOverflowFromChildren();
  void SetPaintFragment(scoped_refptr<const NGPhysicalFragment> fragment,
                        NGPhysicalOffset offset,
                        scoped_refptr<NGPaintFragment>* current);

 protected:
  void AddOutlineRects(Vector<LayoutRect>&,
                       const LayoutPoint& additional_offset,
                       NGOutlineType) const final;

  const NGPhysicalBoxFragment* CurrentFragment() const final;

  const NGBaseline* FragmentBaseline(NGBaselineAlgorithmType) const;

  void DirtyLinesFromChangedChild(LayoutObject* child,
                                  MarkingBehavior marking_behavior) final;

  std::unique_ptr<NGInlineNodeData> ng_inline_node_data_;

  scoped_refptr<const NGLayoutResult> cached_result_;
  scoped_refptr<NGPaintFragment> paint_fragment_;

  friend class NGBaseLayoutAlgorithmTest;
};

extern template class CORE_EXTERN_TEMPLATE_EXPORT
    LayoutNGMixin<LayoutBlockFlow>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    LayoutNGMixin<LayoutTableCaption>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
    LayoutNGMixin<LayoutTableCell>;

}  // namespace blink

#endif  // LayoutNGMixin_h