summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/paint/inline_text_box_painter.h
blob: 533bc38b2f4be5468fff9901edaa57aa737007b0 (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
// Copyright 2014 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_INLINE_TEXT_BOX_PAINTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_INLINE_TEXT_BOX_PAINTER_H_

#include "third_party/blink/renderer/core/editing/markers/document_marker.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"

namespace blink {

struct PaintInfo;

class Color;
class ComputedStyle;
class Font;
class GraphicsContext;
class InlineTextBox;
class LayoutObject;
class LayoutPoint;
class LayoutTextCombine;
class StyleableMarker;
class TextMatchMarker;

enum class DocumentMarkerPaintPhase { kForeground, kBackground };

class InlineTextBoxPainter {
  STACK_ALLOCATED();

 public:
  InlineTextBoxPainter(const InlineTextBox& inline_text_box)
      : inline_text_box_(inline_text_box) {}

  void Paint(const PaintInfo&, const LayoutPoint& paint_offset);

  // We don't paint composition or spelling markers that overlap a suggestion
  // marker (to match the native Android behavior). This method lets us throw
  // out the overlapping composition and spelling markers in O(N log N) time
  // where N is the total number of DocumentMarkers in this node.
  DocumentMarkerVector ComputeMarkersToPaint() const;

  void PaintDocumentMarkers(const DocumentMarkerVector& markers_to_paint,
                            const PaintInfo&,
                            const LayoutPoint& box_origin,
                            const ComputedStyle&,
                            const Font&,
                            DocumentMarkerPaintPhase);
  void PaintDocumentMarker(GraphicsContext&,
                           const LayoutPoint& box_origin,
                           const DocumentMarker&,
                           const ComputedStyle&,
                           const Font&,
                           bool grammar);
  void PaintTextMatchMarkerForeground(const PaintInfo&,
                                      const LayoutPoint& box_origin,
                                      const TextMatchMarker&,
                                      const ComputedStyle&,
                                      const Font&);
  void PaintTextMatchMarkerBackground(const PaintInfo&,
                                      const LayoutPoint& box_origin,
                                      const TextMatchMarker&,
                                      const ComputedStyle&,
                                      const Font&);

 private:
  enum class PaintOptions { kNormal, kCombinedText };

  void PaintSingleMarkerBackgroundRun(GraphicsContext&,
                                      const LayoutPoint& box_origin,
                                      const ComputedStyle&,
                                      const Font&,
                                      Color background_color,
                                      int start_pos,
                                      int end_pos);
  template <PaintOptions>
  void PaintSelection(GraphicsContext&,
                      const LayoutRect& box_rect,
                      const ComputedStyle&,
                      const Font&,
                      Color text_color,
                      LayoutTextCombine* = nullptr);

  template <PaintOptions>
  LayoutRect GetSelectionRect(GraphicsContext&,
                              const LayoutRect& box_rect,
                              const ComputedStyle&,
                              const Font&,
                              LayoutTextCombine* = nullptr);

  void PaintStyleableMarkerUnderline(GraphicsContext&,
                                     const LayoutPoint& box_origin,
                                     const StyleableMarker&,
                                     const ComputedStyle&,
                                     const Font&);
  struct PaintOffsets {
    unsigned start;
    unsigned end;
  };
  PaintOffsets ApplyTruncationToPaintOffsets(const PaintOffsets&);
  // For markers that shouldn't draw over a truncation ellipsis (i.e., not
  // text match markers, which do draw over said ellipsis)
  PaintOffsets MarkerPaintStartAndEnd(const DocumentMarker&);

  bool ShouldPaintTextBox(const PaintInfo&);
  void ExpandToIncludeNewlineForSelection(LayoutRect&);
  LayoutObject& InlineLayoutObject() const;

  const InlineTextBox& inline_text_box_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_INLINE_TEXT_BOX_PAINTER_H_