Skip to content

Commit

Permalink
Revert "Initial integration of libtxt with Flutter alongside Blink." (f…
Browse files Browse the repository at this point in the history
…lutter#3785)

* Revert "Enable line join styles and miter limit. (flutter#3777)"

This reverts commit 5403f65.

* Revert "Revert "Update switches to use StringView." (flutter#3784)"

This reverts commit 80f039f.

* Revert "Initial integration of libtxt with Flutter alongside Blink. (flutter#3771)"

This reverts commit c548c65.
  • Loading branch information
ianloic authored Jun 16, 2017
1 parent 5403f65 commit d2c77f9
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 950 deletions.
3 changes: 0 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ group("flutter") {
deps = [
"//flutter/lib/snapshot:generate_snapshot_bin",
"//flutter/sky",
"//lib/txt",
]

if (is_fuchsia) {
Expand All @@ -31,8 +30,6 @@ group("flutter") {
"//flutter/sky/engine/wtf:wtf_unittests",
"//flutter/synchronization:synchronization_unittests",
"//lib/ftl:ftl_unittests",
"//lib/txt/examples:txt_example($host_toolchain)",
"//lib/txt/tests($host_toolchain)", # txt_unittests
]
}
}
Expand Down
3 changes: 0 additions & 3 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ deps = {
'src/lib/zip':
Var('fuchsia_git') + '/zip' + '@' + '92dc87ca645fe8e9f5151ef6dac86d8311a7222f',

'src/lib/txt':
Var('fuchsia_git') + '/txt' + '@' + 'b44e28c2fd75d7d4b9dcc862bb2c01a090bb53e1',

'src/third_party/gtest':
Var('fuchsia_git') + '/third_party/gtest' + '@' + 'c00f82917331efbbd27124b537e4ccc915a02b72',

Expand Down
1 change: 0 additions & 1 deletion common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct Settings {
bool use_test_fonts = false;
bool dart_non_checked_mode = false;
bool enable_software_rendering = false;
bool using_blink = true;
std::string aot_snapshot_path;
std::string aot_vm_snapshot_data_filename;
std::string aot_vm_snapshot_instr_filename;
Expand Down
8 changes: 0 additions & 8 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# found in the LICENSE file.

source_set("ui") {

sources = [
"compositing/scene.cc",
"compositing/scene.h",
Expand Down Expand Up @@ -56,12 +55,6 @@ source_set("ui") {
"text/paragraph.h",
"text/paragraph_builder.cc",
"text/paragraph_builder.h",
"text/paragraph_impl.cc",
"text/paragraph_impl.h",
"text/paragraph_impl_blink.cc",
"text/paragraph_impl_blink.h",
"text/paragraph_impl_txt.cc",
"text/paragraph_impl_txt.h",
"text/text_box.cc",
"text/text_box.h",
"ui_dart_state.cc",
Expand Down Expand Up @@ -90,6 +83,5 @@ source_set("ui") {
"//lib/tonic",
"//third_party/skia",
"//third_party/skia:gpu",
"//lib/txt",
]
}
132 changes: 110 additions & 22 deletions lib/ui/text/paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

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

#include "flutter/common/settings.h"
#include "flutter/common/threads.h"
#include "flutter/sky/engine/core/rendering/PaintInfo.h"
#include "flutter/sky/engine/core/rendering/RenderParagraph.h"
#include "flutter/sky/engine/core/rendering/RenderText.h"
#include "flutter/sky/engine/core/rendering/RenderParagraph.h"
#include "flutter/sky/engine/core/rendering/style/RenderStyle.h"
#include "flutter/sky/engine/platform/fonts/FontCache.h"
#include "flutter/sky/engine/platform/graphics/GraphicsContext.h"
#include "flutter/sky/engine/platform/text/TextBoundaries.h"
#include "flutter/sky/engine/wtf/PassOwnPtr.h"
#include "lib/ftl/tasks/task_runner.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/dart_args.h"
Expand All @@ -33,7 +31,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
V(Paragraph, maxIntrinsicWidth) \
V(Paragraph, alphabeticBaseline) \
V(Paragraph, ideographicBaseline) \
V(Paragraph, didExceedMaxLines) \
V(Paragraph, didExceedMaxLines) \
V(Paragraph, layout) \
V(Paragraph, paint) \
V(Paragraph, getWordBoundary) \
Expand All @@ -43,65 +41,155 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph);
DART_BIND_ALL(Paragraph, FOR_EACH_BINDING)

Paragraph::Paragraph(PassOwnPtr<RenderView> renderView)
: m_paragraphImpl(std::make_unique<ParagraphImplBlink>(renderView)) {}

Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)
: m_paragraphImpl(
std::make_unique<ParagraphImplTxt>(std::move(paragraph))) {}
: m_renderView(renderView) {}

Paragraph::~Paragraph() {
if (m_renderView) {
RenderView* renderView = m_renderView.leakPtr();
Threads::UI()->PostTask([renderView]() { renderView->destroy(); });
Threads::UI()->PostTask(
[renderView]() { renderView->destroy(); });
}
}

double Paragraph::width() {
return m_paragraphImpl->width();
return firstChildBox()->width();
}

double Paragraph::height() {
return m_paragraphImpl->height();
return firstChildBox()->height();
}

double Paragraph::minIntrinsicWidth() {
return m_paragraphImpl->minIntrinsicWidth();
return firstChildBox()->minPreferredLogicalWidth();
}

double Paragraph::maxIntrinsicWidth() {
return m_paragraphImpl->maxIntrinsicWidth();
return firstChildBox()->maxPreferredLogicalWidth();
}

double Paragraph::alphabeticBaseline() {
return m_paragraphImpl->alphabeticBaseline();
return firstChildBox()->firstLineBoxBaseline(
FontBaselineOrAuto(AlphabeticBaseline));
}

double Paragraph::ideographicBaseline() {
return m_paragraphImpl->ideographicBaseline();
return firstChildBox()->firstLineBoxBaseline(
FontBaselineOrAuto(IdeographicBaseline));
}

bool Paragraph::didExceedMaxLines() {
return m_paragraphImpl->didExceedMaxLines();
RenderBox* box = firstChildBox();
ASSERT(box->isRenderParagraph());
RenderParagraph* paragraph = static_cast<RenderParagraph*>(box);
return paragraph->didExceedMaxLines();
}

void Paragraph::layout(double width) {
m_paragraphImpl->layout(width);
FontCachePurgePreventer fontCachePurgePreventer;

int maxWidth = LayoutUnit(width); // Handles infinity properly.
m_renderView->setFrameViewSize(IntSize(maxWidth, intMaxForLayoutUnit));
m_renderView->layout();
}

void Paragraph::paint(Canvas* canvas, double x, double y) {
m_paragraphImpl->paint(canvas, x, y);
SkCanvas* skCanvas = canvas->canvas();
if (!skCanvas)
return;

FontCachePurgePreventer fontCachePurgePreventer;

// Very simplified painting to allow painting an arbitrary (layer-less)
// subtree.
RenderBox* box = firstChildBox();
skCanvas->translate(x, y);

GraphicsContext context(skCanvas);
Vector<RenderBox*> layers;
LayoutRect bounds = box->absoluteBoundingBoxRect();
FTL_DCHECK(bounds.x() == 0 && bounds.y() == 0);
PaintInfo paintInfo(&context, enclosingIntRect(bounds), box);
box->paint(paintInfo, LayoutPoint(), layers);
// Note we're ignoring any layers encountered.
// TODO(abarth): Remove the concept of RenderLayers.

skCanvas->translate(-x, -y);
}

std::vector<TextBox> Paragraph::getRectsForRange(unsigned start, unsigned end) {
return m_paragraphImpl->getRectsForRange(start, end);
if (end <= start || start == end)
return std::vector<TextBox>();

unsigned offset = 0;
std::vector<TextBox> boxes;
for (RenderObject* object = m_renderView.get(); object;
object = object->nextInPreOrder()) {
if (!object->isText())
continue;
RenderText* text = toRenderText(object);
unsigned length = text->textLength();
if (offset + length > start) {
unsigned startOffset = offset > start ? 0 : start - offset;
unsigned endOffset = end - offset;
text->appendAbsoluteTextBoxesForRange(boxes, startOffset, endOffset);
}
offset += length;
if (offset >= end)
break;
}

return boxes;
}

int Paragraph::absoluteOffsetForPosition(const PositionWithAffinity& position) {
FTL_DCHECK(position.renderer());
unsigned offset = 0;
for (RenderObject* object = m_renderView.get(); object;
object = object->nextInPreOrder()) {
if (object == position.renderer())
return offset + position.offset();
if (object->isText()) {
RenderText* text = toRenderText(object);
offset += text->textLength();
}
}
FTL_DCHECK(false);
return 0;
}

Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) {
return m_paragraphImpl->getPositionForOffset(dx, dy);
LayoutPoint point(dx, dy);
PositionWithAffinity position = m_renderView->positionForPoint(point);
Dart_Handle result = Dart_NewList(2);
Dart_ListSetAt(result, 0, ToDart(absoluteOffsetForPosition(position)));
Dart_ListSetAt(result, 1, ToDart(static_cast<int>(position.affinity())));
return result;
}

Dart_Handle Paragraph::getWordBoundary(unsigned offset) {
return m_paragraphImpl->getWordBoundary(offset);
String text;
int start = 0, end = 0;

for (RenderObject* object = m_renderView.get(); object;
object = object->nextInPreOrder()) {
if (!object->isText())
continue;
RenderText* renderText = toRenderText(object);
text.append(renderText->text());
}

TextBreakIterator* it = wordBreakIterator(text, 0, text.length());
if (it) {
end = it->following(offset);
if (end < 0)
end = it->last();
start = it->previous();
}

Dart_Handle result = Dart_NewList(2);
Dart_ListSetAt(result, 0, ToDart(start));
Dart_ListSetAt(result, 1, ToDart(end));
return result;
}

} // namespace blink
18 changes: 3 additions & 15 deletions lib/ui/text/paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_

#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/lib/ui/text/paragraph_impl.h"
#include "flutter/lib/ui/text/paragraph_impl_blink.h"
#include "flutter/lib/ui/text/paragraph_impl_txt.h"
#include "flutter/lib/ui/text/text_box.h"
#include "flutter/sky/engine/core/rendering/RenderView.h"
#include "flutter/sky/engine/wtf/PassOwnPtr.h"
#include "lib/tonic/dart_wrappable.h"
#include "lib/txt/src/paragraph.h"

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

public:
static ftl::RefPtr<Paragraph> Create(PassOwnPtr<RenderView> renderView) {
static ftl::RefPtr<Paragraph> create(PassOwnPtr<RenderView> renderView) {
return ftl::MakeRefCounted<Paragraph>(renderView);
}

static ftl::RefPtr<Paragraph> Create(
std::unique_ptr<txt::Paragraph> paragraph) {
return ftl::MakeRefCounted<Paragraph>(std::move(paragraph));
}

~Paragraph() override;

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

private:
std::unique_ptr<ParagraphImpl> m_paragraphImpl;

RenderBox* firstChildBox() const { return m_renderView->firstChildBox(); }

explicit Paragraph(PassOwnPtr<RenderView> renderView);
int absoluteOffsetForPosition(const PositionWithAffinity& position);

explicit Paragraph(std::unique_ptr<txt::Paragraph> paragraph);
explicit Paragraph(PassOwnPtr<RenderView> renderView);

OwnPtr<RenderView> m_renderView;
};
Expand Down
Loading

0 comments on commit d2c77f9

Please sign in to comment.