summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_text_fragment_builder.h
blob: 7e90f264e2f45cac56b0976482d0f0a7dde17c00 (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
// 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_INLINE_NG_TEXT_FRAGMENT_BUILDER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_TEXT_FRAGMENT_BUILDER_H_

#include "third_party/blink/renderer/core/layout/geometry/logical_size.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_fragment_builder.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace blink {

class LayoutObject;
class ShapeResultView;

class CORE_EXPORT NGTextFragmentBuilder final : public NGFragmentBuilder {
  STACK_ALLOCATED();

 public:
  explicit NGTextFragmentBuilder(WritingMode writing_mode)
      : NGFragmentBuilder({writing_mode, TextDirection::kLtr}) {}

  NGTextFragmentBuilder(const NGPhysicalTextFragment& fragment);

  TextDirection ResolvedDirection() const { return resolved_direction_; }

  // NOTE: Takes ownership of the shape result within the item result.
  void SetItem(const String& text_content,
               const NGInlineItem& inline_item,
               scoped_refptr<const ShapeResultView> shape_result,
               const NGTextOffset& text_offset,
               const LogicalSize& size);

  // Set text for generated text, e.g. hyphen and ellipsis.
  void SetText(LayoutObject*,
               const String& text,
               scoped_refptr<const ComputedStyle>,
               NGStyleVariant style_variant,
               scoped_refptr<const ShapeResultView>,
               const LogicalSize& size);

  // Creates the fragment. Can only be called once.
  scoped_refptr<const NGPhysicalTextFragment> ToTextFragment();

 private:
  String text_;
  NGTextOffset text_offset_;
  scoped_refptr<const ShapeResultView> shape_result_;

  NGTextType text_type_ = NGTextType::kNormal;

  // Set from |NGInlineItem| by |SetItem()|.
  TextDirection resolved_direction_ = TextDirection::kLtr;

  friend class NGPhysicalTextFragment;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_TEXT_FRAGMENT_BUILDER_H_