summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/paint/ng/ng_box_fragment_painter.h
blob: 440d6ad9892c905544178bf389c94d58a9363e01 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// 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_PAINT_NG_NG_BOX_FRAGMENT_PAINTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_NG_NG_BOX_FRAGMENT_PAINTER_H_

#include "third_party/blink/renderer/core/layout/api/hit_test_action.h"
#include "third_party/blink/renderer/core/layout/background_bleed_avoidance.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_border_edges.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/box_painter_base.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/platform/geometry/layout_point.h"
#include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"

namespace blink {

class FillLayer;
class HitTestLocation;
class HitTestRequest;
class HitTestResult;
class LayoutRect;
class NGPhysicalFragment;
class ScopedPaintState;
struct PaintInfo;

// Painter for LayoutNG box fragments, paints borders and background. Delegates
// to NGTextFragmentPainter to paint line box fragments.
class NGBoxFragmentPainter : public BoxPainterBase {
  STACK_ALLOCATED();

 public:
  NGBoxFragmentPainter(const NGPaintFragment&);

  void Paint(const PaintInfo&);
  void PaintObject(const PaintInfo&,
                   const LayoutPoint&,
                   bool suppress_box_decoration_background = false);

  // Hit tests this box fragment.
  // @param physical_offset Physical offset of this box fragment in paint layer.
  // TODO(eae): Change to take a HitTestResult pointer instead as it mutates.
  bool NodeAtPoint(HitTestResult&,
                   const HitTestLocation& location_in_container,
                   const LayoutPoint& physical_offset,
                   HitTestAction);

 protected:
  LayoutRectOutsets ComputeBorders() const override;
  LayoutRectOutsets ComputePadding() const override;
  BoxPainterBase::FillLayerInfo GetFillLayerInfo(
      const Color&,
      const FillLayer&,
      BackgroundBleedAvoidance) const override;

  void PaintTextClipMask(GraphicsContext&,
                         const IntRect& mask_rect,
                         const LayoutPoint& paint_offset,
                         bool object_has_multiple_boxes) override;
  LayoutRect AdjustRectForScrolledContent(const PaintInfo&,
                                          const BoxPainterBase::FillLayerInfo&,
                                          const LayoutRect&) override;

 private:
  bool IsPaintingScrollingBackground(const NGPaintFragment&, const PaintInfo&);
  bool ShouldPaint(const ScopedPaintState&) const;

  void PaintBoxDecorationBackground(const PaintInfo&,
                                    const LayoutPoint& paint_offset);
  void PaintBoxDecorationBackgroundWithRect(const PaintInfo&,
                                            const LayoutRect&);
  bool BackgroundIsKnownToBeOpaque(const PaintInfo&);

  void PaintAllPhasesAtomically(const PaintInfo&,
                                bool is_self_painting);
  void PaintBlockChildren(const PaintInfo&);
  void PaintLineBoxChildren(NGPaintFragment::ChildList,
                            const PaintInfo&,
                            const LayoutPoint& paint_offset);
  void PaintInlineChildren(NGPaintFragment::ChildList,
                           const PaintInfo&,
                           const LayoutPoint& paint_offset);
  void PaintInlineChildrenOutlines(NGPaintFragment::ChildList,
                                   const PaintInfo&,
                                   const LayoutPoint& paint_offset);
  void PaintInlineChildBoxUsingLegacyFallback(const NGPhysicalFragment&,
                                              const PaintInfo&);
  void PaintBlockFlowContents(const PaintInfo&,
                              const LayoutPoint& paint_offset);
  void PaintInlineChild(const NGPaintFragment&,
                        const PaintInfo&,
                        const LayoutPoint& paint_offset);
  void PaintAtomicInlineChild(const NGPaintFragment&, const PaintInfo&);
  void PaintTextChild(const NGPaintFragment&,
                      const PaintInfo&,
                      const LayoutPoint& paint_offset);
  void PaintFloatingChildren(NGPaintFragment::ChildList, const PaintInfo&);
  void PaintFloats(const PaintInfo&);
  void PaintMask(const PaintInfo&, const LayoutPoint& paint_offset);
  void PaintOverflowControlsIfNeeded(const PaintInfo&,
                                     const LayoutPoint& paint_offset);
  void PaintAtomicInline(const PaintInfo&);
  void PaintBackground(const PaintInfo&,
                       const LayoutRect&,
                       const Color& background_color,
                       BackgroundBleedAvoidance = kBackgroundBleedNone);
  void PaintSymbol(const NGPaintFragment&,
                   const PaintInfo&,
                   const LayoutPoint& paint_offset);
  void PaintCarets(const PaintInfo&, const LayoutPoint& paint_offset);

  void RecordHitTestData(const PaintInfo& paint_info,
                         const LayoutPoint& paint_offset);

  bool IsInSelfHitTestingPhase(HitTestAction) const;
  bool VisibleToHitTestRequest(const HitTestRequest&) const;

  // Hit tests the children of a container fragment, which is either
  // |box_fragment_|, or one of its child line box fragments.
  // @param physical_offset Physical offset of the container fragment's content
  // box in paint layer. Note that this includes scrolling offset when the
  // container has 'overflow: scroll'.
  bool HitTestChildren(HitTestResult&,
                       NGPaintFragment::ChildList,
                       const HitTestLocation& location_in_container,
                       const LayoutPoint& physical_offset,
                       HitTestAction);

  // Hit tests a box fragment, which is a child of either |box_fragment_|, or
  // one of its child line box fragments.
  // @param physical_offset Physical offset of the given box fragment in the
  // paint layer.
  bool HitTestChildBoxFragment(HitTestResult&,
                               const NGPaintFragment&,
                               const HitTestLocation& location_in_container,
                               const LayoutPoint& physical_offset,
                               HitTestAction);

  // Hit tests the given text fragment.
  // @param physical_offset Physical offset of the text fragment in paint layer.
  bool HitTestTextFragment(HitTestResult&,
                           const NGPaintFragment&,
                           const HitTestLocation& location_in_container,
                           const LayoutPoint& physical_offset,
                           HitTestAction);

  // Hit tests the given line box fragment.
  // @param physical_offset Physical offset of the line box fragment in paint
  // layer.
  bool HitTestLineBoxFragment(HitTestResult&,
                              const NGPaintFragment&,
                              const HitTestLocation& location_in_container,
                              const LayoutPoint& physical_offset,
                              HitTestAction);

  // Returns whether the hit test location is completely outside the border box,
  // which possibly has rounded corners.
  bool HitTestClippedOutByBorder(const HitTestLocation&,
                                 const LayoutPoint& border_box_location) const;

  LayoutPoint FlipForWritingModeForChild(
      const NGPhysicalFragment& child_fragment,
      const LayoutPoint& offset);

  const NGPhysicalBoxFragment& PhysicalFragment() const;

  const NGPaintFragment& box_fragment_;
  NGBorderEdges border_edges_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_NG_NG_BOX_FRAGMENT_PAINTER_H_