summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_text_fragment_builder.cc
blob: 8f9707628578a33e0b79d05cf8840946ca10a313 (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
// 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.

#include "third_party/blink/renderer/core/layout/ng/inline/ng_text_fragment_builder.h"

#include "third_party/blink/renderer/core/layout/layout_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_item_result.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/platform/fonts/shaping/shape_result_view.h"

namespace blink {

NGTextFragmentBuilder::NGTextFragmentBuilder(
    const NGPhysicalTextFragment& fragment)
    : NGFragmentBuilder(fragment),
      text_(fragment.text_),
      text_offset_(fragment.TextOffset()),
      shape_result_(fragment.TextShapeResult()),
      text_type_(fragment.TextType()) {}

void NGTextFragmentBuilder::SetItem(
    const String& text_content,
    const NGInlineItem& item,
    scoped_refptr<const ShapeResultView> shape_result,
    const NGTextOffset& text_offset,
    const LogicalSize& size) {
  DCHECK_NE(item.TextType(), NGTextType::kLayoutGenerated)
      << "Please use SetText() instead.";
  DCHECK(item.Style());

  text_type_ = item.TextType();
  text_ = text_content;
  text_offset_ = text_offset;
  resolved_direction_ = item.Direction();
  SetStyle(item.Style(), item.StyleVariant());
  size_ = size;
  shape_result_ = std::move(shape_result);
  layout_object_ = item.GetLayoutObject();
}

void NGTextFragmentBuilder::SetText(
    LayoutObject* layout_object,
    const String& text,
    scoped_refptr<const ComputedStyle> style,
    NGStyleVariant style_variant,
    scoped_refptr<const ShapeResultView> shape_result,
    const LogicalSize& size) {
  DCHECK(layout_object);
  DCHECK(style);
  DCHECK(shape_result);

  text_type_ = NGTextType::kLayoutGenerated;
  text_ = text;
  text_offset_ = {shape_result->StartIndex(), shape_result->EndIndex()};
  resolved_direction_ = shape_result->Direction();
  SetStyle(style, style_variant);
  size_ = size;
  shape_result_ = std::move(shape_result);
  layout_object_ = layout_object;
}

scoped_refptr<const NGPhysicalTextFragment>
NGTextFragmentBuilder::ToTextFragment() {
  scoped_refptr<const NGPhysicalTextFragment> fragment =
      base::AdoptRef(new NGPhysicalTextFragment(this));
  return fragment;
}

}  // namespace blink