Skip to content

Commit fffe502

Browse files
authored
Revert libtxt integration (flutter#3802)
* Revert "Fix licenses_lib golden file (flutter#3798)" This reverts commit d8ac43c. * Revert "Remove ParagraphConstriants (flutter#3796)" This reverts commit 8ccf767. * Revert "Reland "Initial integration of libtxt with Flutter alongside Blink." (flutter#3793)" This reverts commit 3c04921.
1 parent 25c7a86 commit fffe502

File tree

20 files changed

+197
-947
lines changed

20 files changed

+197
-947
lines changed

BUILD.gn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ group("flutter") {
88
deps = [
99
"//flutter/lib/snapshot:generate_snapshot_bin",
1010
"//flutter/sky",
11-
"//lib/txt",
1211
]
1312

1413
if (is_fuchsia) {
@@ -31,8 +30,6 @@ group("flutter") {
3130
"//flutter/sky/engine/wtf:wtf_unittests",
3231
"//flutter/synchronization:synchronization_unittests",
3332
"//lib/ftl:ftl_unittests",
34-
"//lib/txt/examples:txt_example($host_toolchain)",
35-
"//lib/txt/tests($host_toolchain)", # txt_unittests
3633
]
3734
}
3835
}

DEPS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ deps = {
7171
'src/lib/zip':
7272
Var('fuchsia_git') + '/zip' + '@' + '92dc87ca645fe8e9f5151ef6dac86d8311a7222f',
7373

74-
'src/lib/txt':
75-
Var('fuchsia_git') + '/txt' + '@' + '95dc633d881d1b23b88e657bcb2f654459706412',
76-
7774
'src/third_party/gtest':
7875
Var('fuchsia_git') + '/third_party/gtest' + '@' + 'c00f82917331efbbd27124b537e4ccc915a02b72',
7976

common/settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct Settings {
2727
bool use_test_fonts = false;
2828
bool dart_non_checked_mode = false;
2929
bool enable_software_rendering = false;
30-
bool using_blink = true;
3130
std::string aot_snapshot_path;
3231
std::string aot_vm_snapshot_data_filename;
3332
std::string aot_vm_snapshot_instr_filename;

lib/ui/BUILD.gn

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# found in the LICENSE file.
44

55
source_set("ui") {
6-
76
sources = [
87
"compositing/scene.cc",
98
"compositing/scene.h",
@@ -56,12 +55,6 @@ source_set("ui") {
5655
"text/paragraph.h",
5756
"text/paragraph_builder.cc",
5857
"text/paragraph_builder.h",
59-
"text/paragraph_impl.cc",
60-
"text/paragraph_impl.h",
61-
"text/paragraph_impl_blink.cc",
62-
"text/paragraph_impl_blink.h",
63-
"text/paragraph_impl_txt.cc",
64-
"text/paragraph_impl_txt.h",
6558
"text/text_box.cc",
6659
"text/text_box.h",
6760
"ui_dart_state.cc",
@@ -90,6 +83,5 @@ source_set("ui") {
9083
"//lib/tonic",
9184
"//third_party/skia",
9285
"//third_party/skia:gpu",
93-
"//lib/txt",
9486
]
9587
}

lib/ui/text/paragraph.cc

Lines changed: 110 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
#include "flutter/lib/ui/text/paragraph.h"
66

7-
#include "flutter/common/settings.h"
87
#include "flutter/common/threads.h"
98
#include "flutter/sky/engine/core/rendering/PaintInfo.h"
10-
#include "flutter/sky/engine/core/rendering/RenderParagraph.h"
119
#include "flutter/sky/engine/core/rendering/RenderText.h"
10+
#include "flutter/sky/engine/core/rendering/RenderParagraph.h"
1211
#include "flutter/sky/engine/core/rendering/style/RenderStyle.h"
1312
#include "flutter/sky/engine/platform/fonts/FontCache.h"
1413
#include "flutter/sky/engine/platform/graphics/GraphicsContext.h"
1514
#include "flutter/sky/engine/platform/text/TextBoundaries.h"
16-
#include "flutter/sky/engine/wtf/PassOwnPtr.h"
1715
#include "lib/ftl/tasks/task_runner.h"
1816
#include "lib/tonic/converter/dart_converter.h"
1917
#include "lib/tonic/dart_args.h"
@@ -33,7 +31,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
3331
V(Paragraph, maxIntrinsicWidth) \
3432
V(Paragraph, alphabeticBaseline) \
3533
V(Paragraph, ideographicBaseline) \
36-
V(Paragraph, didExceedMaxLines) \
34+
V(Paragraph, didExceedMaxLines) \
3735
V(Paragraph, layout) \
3836
V(Paragraph, paint) \
3937
V(Paragraph, getWordBoundary) \
@@ -43,65 +41,155 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
4341
DART_BIND_ALL(Paragraph, FOR_EACH_BINDING)
4442

4543
Paragraph::Paragraph(PassOwnPtr<RenderView> renderView)
46-
: m_paragraphImpl(std::make_unique<ParagraphImplBlink>(renderView)) {}
47-
48-
Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)
49-
: m_paragraphImpl(
50-
std::make_unique<ParagraphImplTxt>(std::move(paragraph))) {}
44+
: m_renderView(renderView) {}
5145

5246
Paragraph::~Paragraph() {
5347
if (m_renderView) {
5448
RenderView* renderView = m_renderView.leakPtr();
55-
Threads::UI()->PostTask([renderView]() { renderView->destroy(); });
49+
Threads::UI()->PostTask(
50+
[renderView]() { renderView->destroy(); });
5651
}
5752
}
5853

5954
double Paragraph::width() {
60-
return m_paragraphImpl->width();
55+
return firstChildBox()->width();
6156
}
6257

6358
double Paragraph::height() {
64-
return m_paragraphImpl->height();
59+
return firstChildBox()->height();
6560
}
6661

6762
double Paragraph::minIntrinsicWidth() {
68-
return m_paragraphImpl->minIntrinsicWidth();
63+
return firstChildBox()->minPreferredLogicalWidth();
6964
}
7065

7166
double Paragraph::maxIntrinsicWidth() {
72-
return m_paragraphImpl->maxIntrinsicWidth();
67+
return firstChildBox()->maxPreferredLogicalWidth();
7368
}
7469

7570
double Paragraph::alphabeticBaseline() {
76-
return m_paragraphImpl->alphabeticBaseline();
71+
return firstChildBox()->firstLineBoxBaseline(
72+
FontBaselineOrAuto(AlphabeticBaseline));
7773
}
7874

7975
double Paragraph::ideographicBaseline() {
80-
return m_paragraphImpl->ideographicBaseline();
76+
return firstChildBox()->firstLineBoxBaseline(
77+
FontBaselineOrAuto(IdeographicBaseline));
8178
}
8279

8380
bool Paragraph::didExceedMaxLines() {
84-
return m_paragraphImpl->didExceedMaxLines();
81+
RenderBox* box = firstChildBox();
82+
ASSERT(box->isRenderParagraph());
83+
RenderParagraph* paragraph = static_cast<RenderParagraph*>(box);
84+
return paragraph->didExceedMaxLines();
8585
}
8686

8787
void Paragraph::layout(double width) {
88-
m_paragraphImpl->layout(width);
88+
FontCachePurgePreventer fontCachePurgePreventer;
89+
90+
int maxWidth = LayoutUnit(width); // Handles infinity properly.
91+
m_renderView->setFrameViewSize(IntSize(maxWidth, intMaxForLayoutUnit));
92+
m_renderView->layout();
8993
}
9094

9195
void Paragraph::paint(Canvas* canvas, double x, double y) {
92-
m_paragraphImpl->paint(canvas, x, y);
96+
SkCanvas* skCanvas = canvas->canvas();
97+
if (!skCanvas)
98+
return;
99+
100+
FontCachePurgePreventer fontCachePurgePreventer;
101+
102+
// Very simplified painting to allow painting an arbitrary (layer-less)
103+
// subtree.
104+
RenderBox* box = firstChildBox();
105+
skCanvas->translate(x, y);
106+
107+
GraphicsContext context(skCanvas);
108+
Vector<RenderBox*> layers;
109+
LayoutRect bounds = box->absoluteBoundingBoxRect();
110+
FTL_DCHECK(bounds.x() == 0 && bounds.y() == 0);
111+
PaintInfo paintInfo(&context, enclosingIntRect(bounds), box);
112+
box->paint(paintInfo, LayoutPoint(), layers);
113+
// Note we're ignoring any layers encountered.
114+
// TODO(abarth): Remove the concept of RenderLayers.
115+
116+
skCanvas->translate(-x, -y);
93117
}
94118

95119
std::vector<TextBox> Paragraph::getRectsForRange(unsigned start, unsigned end) {
96-
return m_paragraphImpl->getRectsForRange(start, end);
120+
if (end <= start || start == end)
121+
return std::vector<TextBox>();
122+
123+
unsigned offset = 0;
124+
std::vector<TextBox> boxes;
125+
for (RenderObject* object = m_renderView.get(); object;
126+
object = object->nextInPreOrder()) {
127+
if (!object->isText())
128+
continue;
129+
RenderText* text = toRenderText(object);
130+
unsigned length = text->textLength();
131+
if (offset + length > start) {
132+
unsigned startOffset = offset > start ? 0 : start - offset;
133+
unsigned endOffset = end - offset;
134+
text->appendAbsoluteTextBoxesForRange(boxes, startOffset, endOffset);
135+
}
136+
offset += length;
137+
if (offset >= end)
138+
break;
139+
}
140+
141+
return boxes;
142+
}
143+
144+
int Paragraph::absoluteOffsetForPosition(const PositionWithAffinity& position) {
145+
FTL_DCHECK(position.renderer());
146+
unsigned offset = 0;
147+
for (RenderObject* object = m_renderView.get(); object;
148+
object = object->nextInPreOrder()) {
149+
if (object == position.renderer())
150+
return offset + position.offset();
151+
if (object->isText()) {
152+
RenderText* text = toRenderText(object);
153+
offset += text->textLength();
154+
}
155+
}
156+
FTL_DCHECK(false);
157+
return 0;
97158
}
98159

99160
Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) {
100-
return m_paragraphImpl->getPositionForOffset(dx, dy);
161+
LayoutPoint point(dx, dy);
162+
PositionWithAffinity position = m_renderView->positionForPoint(point);
163+
Dart_Handle result = Dart_NewList(2);
164+
Dart_ListSetAt(result, 0, ToDart(absoluteOffsetForPosition(position)));
165+
Dart_ListSetAt(result, 1, ToDart(static_cast<int>(position.affinity())));
166+
return result;
101167
}
102168

103169
Dart_Handle Paragraph::getWordBoundary(unsigned offset) {
104-
return m_paragraphImpl->getWordBoundary(offset);
170+
String text;
171+
int start = 0, end = 0;
172+
173+
for (RenderObject* object = m_renderView.get(); object;
174+
object = object->nextInPreOrder()) {
175+
if (!object->isText())
176+
continue;
177+
RenderText* renderText = toRenderText(object);
178+
text.append(renderText->text());
179+
}
180+
181+
TextBreakIterator* it = wordBreakIterator(text, 0, text.length());
182+
if (it) {
183+
end = it->following(offset);
184+
if (end < 0)
185+
end = it->last();
186+
start = it->previous();
187+
}
188+
189+
Dart_Handle result = Dart_NewList(2);
190+
Dart_ListSetAt(result, 0, ToDart(start));
191+
Dart_ListSetAt(result, 1, ToDart(end));
192+
return result;
105193
}
106194

107195
} // namespace blink

lib/ui/text/paragraph.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_
77

88
#include "flutter/lib/ui/painting/canvas.h"
9-
#include "flutter/lib/ui/text/paragraph_impl.h"
10-
#include "flutter/lib/ui/text/paragraph_impl_blink.h"
11-
#include "flutter/lib/ui/text/paragraph_impl_txt.h"
129
#include "flutter/lib/ui/text/text_box.h"
1310
#include "flutter/sky/engine/core/rendering/RenderView.h"
14-
#include "flutter/sky/engine/wtf/PassOwnPtr.h"
1511
#include "lib/tonic/dart_wrappable.h"
16-
#include "lib/txt/src/paragraph.h"
1712

1813
namespace tonic {
1914
class DartLibraryNatives;
@@ -27,15 +22,10 @@ class Paragraph : public ftl::RefCountedThreadSafe<Paragraph>,
2722
FRIEND_MAKE_REF_COUNTED(Paragraph);
2823

2924
public:
30-
static ftl::RefPtr<Paragraph> Create(PassOwnPtr<RenderView> renderView) {
25+
static ftl::RefPtr<Paragraph> create(PassOwnPtr<RenderView> renderView) {
3126
return ftl::MakeRefCounted<Paragraph>(renderView);
3227
}
3328

34-
static ftl::RefPtr<Paragraph> Create(
35-
std::unique_ptr<txt::Paragraph> paragraph) {
36-
return ftl::MakeRefCounted<Paragraph>(std::move(paragraph));
37-
}
38-
3929
~Paragraph() override;
4030

4131
double width();
@@ -58,13 +48,11 @@ class Paragraph : public ftl::RefCountedThreadSafe<Paragraph>,
5848
static void RegisterNatives(tonic::DartLibraryNatives* natives);
5949

6050
private:
61-
std::unique_ptr<ParagraphImpl> m_paragraphImpl;
62-
6351
RenderBox* firstChildBox() const { return m_renderView->firstChildBox(); }
6452

65-
explicit Paragraph(PassOwnPtr<RenderView> renderView);
53+
int absoluteOffsetForPosition(const PositionWithAffinity& position);
6654

67-
explicit Paragraph(std::unique_ptr<txt::Paragraph> paragraph);
55+
explicit Paragraph(PassOwnPtr<RenderView> renderView);
6856

6957
OwnPtr<RenderView> m_renderView;
7058
};

0 commit comments

Comments
 (0)