paragraph_builder.h 2.7 KB
Newer Older
1 2 3 4
// Copyright 2015 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.

5 6
#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_
#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_
7

8
#include <memory>
9
#include "flutter/lib/ui/text/paragraph.h"
10 11 12
#include "flutter/sky/engine/core/rendering/RenderObject.h"
#include "flutter/sky/engine/wtf/OwnPtr.h"
#include "flutter/third_party/txt/src/txt/paragraph_builder.h"
13
#include "lib/tonic/dart_wrappable.h"
14
#include "lib/tonic/typed_data/int32_list.h"
15

16
namespace tonic {
A
Adam Barth 已提交
17
class DartLibraryNatives;
18 19 20
}  // namespace tonic

namespace blink {
21

22 23
class Paragraph;

24
class ParagraphBuilder : public fxl::RefCountedThreadSafe<ParagraphBuilder>,
25
                         public tonic::DartWrappable {
26
  DEFINE_WRAPPERTYPEINFO();
27
  FRIEND_MAKE_REF_COUNTED(ParagraphBuilder);
28

29
 public:
30
  static fxl::RefPtr<ParagraphBuilder> create(tonic::Int32List& encoded,
31 32 33
                                              const std::string& fontFamily,
                                              double fontSize,
                                              double lineHeight,
34
                                              const std::u16string& ellipsis,
35 36
                                              const std::string& locale,
                                              bool use_blink);
37

38
  ~ParagraphBuilder() override;
39

40 41 42 43 44
  void pushStyle(tonic::Int32List& encoded,
                 const std::string& fontFamily,
                 double fontSize,
                 double letterSpacing,
                 double wordSpacing,
45 46
                 double height,
                 const std::string& locale);
47

48
  void pop();
49

50
  Dart_Handle addText(const std::u16string& text);
51

52
  fxl::RefPtr<Paragraph> build();
A
Adam Barth 已提交
53

54
  static void RegisterNatives(tonic::DartLibraryNatives* natives);
55

56
 private:
57 58 59 60
  explicit ParagraphBuilder(tonic::Int32List& encoded,
                            const std::string& fontFamily,
                            double fontSize,
                            double lineHeight,
61
                            const std::u16string& ellipsis,
62 63
                            const std::string& locale,
                            bool use_blink);
64

65 66
  void createRenderView();

67 68 69 70
  // TODO: This can be removed when the render view association for the legacy
  // runtime is removed.
  fxl::RefPtr<fxl::TaskRunner> destruction_task_runner_ =
      UIDartState::Current()->GetTaskRunners().GetUITaskRunner();
71 72 73
  OwnPtr<RenderView> m_renderView;
  RenderObject* m_renderParagraph;
  RenderObject* m_currentRenderObject;
74
  std::unique_ptr<txt::ParagraphBuilder> m_paragraphBuilder;
75
  bool m_useBlink;
76 77
};

78
}  // namespace blink
79

80
#endif  // FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_H_