Initial integration of libtxt with Flutter alongside Blink.#3771
Initial integration of libtxt with Flutter alongside Blink.#3771GaryQian merged 25 commits intoflutter:masterfrom GaryQian:master
Conversation
BUILD.gn
Outdated
| "//lib/ftl:ftl_unittests", | ||
| "//lib/txt/examples:txt_example($host_toolchain)", | ||
| "//lib/txt/tests/txt($host_toolchain)", # txt_unittests | ||
| "//lib/txt/tests/unittest($host_toolchain)", # minikin_unittest |
There was a problem hiding this comment.
It would be cleaner if these could be referenced as //lib/txt/examples and //lib/txt/tests, respectively. That will give us more freedom to add more examples and tests over time without changing both repos.
DEPS
Outdated
| Var('fuchsia_git') + '/zip' + '@' + '92dc87ca645fe8e9f5151ef6dac86d8311a7222f', | ||
|
|
||
| 'src/lib/txt': | ||
| Var('fuchsia_git') + '/txt' + '@' + 'Id71461bd96e08eae0e24ab35a040874d960af8e0', |
lib/ui/text.dart
Outdated
|
|
||
| // Toggles between Blink text shaping backend and libtxt backend. This allows | ||
| // for debugging and development and is not intended to be a final feature. | ||
| void toggleTxt() native "Paragraph_toggleTxt"; |
There was a problem hiding this comment.
We shouldn't expose this to Dart. These APIs are meant to be stable. Instead, we should use a command line flag to enable libtxt.
There was a problem hiding this comment.
I have removed this function for now and started with the flag. I'll finish up the command line flag in a later patch. This pr is getting really big!
There was a problem hiding this comment.
We can't land this patch with this function here.
lib/ui/text/paragraph.cc
Outdated
|
|
||
| Paragraph::Paragraph(PassOwnPtr<RenderView> renderView) | ||
| : m_renderView(renderView) {} | ||
| bool Paragraph::m_usingBlink = true; |
There was a problem hiding this comment.
I'd move this bool to the Settings object.
lib/ui/text/paragraph.h
Outdated
| #define FLUTTER_LIB_UI_TEXT_PARAGRAPH_H_ | ||
|
|
||
| #include "flutter/lib/ui/painting/canvas.h" | ||
| #include "flutter/lib/ui/text/paragraph_builder.h" |
There was a problem hiding this comment.
Why do we need knowledge of the paragraph builder?
There was a problem hiding this comment.
Oops, left over from before!
lib/ui/text/paragraph_builder.cc
Outdated
| style.ellipsis = ellipsis; | ||
|
|
||
| m_paragraphBuilder.SetParagraphStyle(style); | ||
| } |
There was a problem hiding this comment.
I'd put this in an "else". We shouldn't do the blink-related work in the non-blink case.
There was a problem hiding this comment.
Moved them all to elses
lib/ui/text/paragraph_builder.cc
Outdated
| } | ||
|
|
||
| m_paragraphBuilder.PushStyle(tstyle); | ||
| } |
lib/ui/text/paragraph_impl.h
Outdated
|
|
||
| #include "flutter/lib/ui/painting/canvas.h" | ||
| #include "flutter/lib/ui/text/text_box.h" | ||
| #include "flutter/sky/engine/core/rendering/RenderView.h" |
There was a problem hiding this comment.
The base class shouldn't know about RenderView.
lib/ui/text/paragraph_impl.h
Outdated
| class ParagraphImpl { | ||
| public: | ||
| virtual void setRenderView(PassOwnPtr<RenderView> renderView, | ||
| std::unique_ptr<txt::Paragraph>& paragraph) = 0; |
There was a problem hiding this comment.
This function should move to ParagraphImplBlink.
There was a problem hiding this comment.
Restructured the inheritance to be better. No longer need this function!
lib/ui/text/paragraph_impl_blink.cc
Outdated
|
|
||
| namespace blink { | ||
|
|
||
| IMPLEMENT_WRAPPERTYPEINFO(ui, ParagraphImplBlink); |
There was a problem hiding this comment.
This shouldn't need a WRAPPERTYPEINFO. The Paragraph is the object with the Dart wrapper, not this object.
lib/ui/text/paragraph_impl_blink.h
Outdated
| ParagraphImplBlink(); | ||
|
|
||
| void setRenderView(PassOwnPtr<RenderView> renderView, | ||
| std::unique_ptr<txt::Paragraph>& paragraph); |
lib/ui/text/paragraph_impl_blink.h
Outdated
| class ParagraphImplBlink : public ParagraphImpl, | ||
| public ftl::RefCountedThreadSafe<ParagraphImplBlink>, | ||
| public tonic::DartWrappable { | ||
| DEFINE_WRAPPERTYPEINFO(); |
There was a problem hiding this comment.
No need for this start wrapper stuff.
lib/ui/text/paragraph_impl_blink.h
Outdated
| namespace blink { | ||
|
|
||
| class ParagraphImplBlink : public ParagraphImpl, | ||
| public ftl::RefCountedThreadSafe<ParagraphImplBlink>, |
There was a problem hiding this comment.
Why is this object ref counted? It seems like it should just be owned by the Paragraph object.
| private: | ||
| friend class ParagraphBuilder; | ||
|
|
||
| std::unique_ptr<ParagraphImpl> m_paragraphImpl; |
There was a problem hiding this comment.
Yes, you're holding the ParagraphImpl with a unique_ptr, which means they shouldn't inherit from refcounted or do any of that sort of stuff.
lib/ui/text/paragraph_impl_txt.cc
Outdated
| } | ||
|
|
||
| void ParagraphImplTxt::paint(Canvas* canvas, double x, double y) { | ||
| SkCanvas* skCanvas = canvas->canvas(); |
There was a problem hiding this comment.
The style guys says to use names_like_this for local variables. That means this variable should be called sk_canvas.
lib/ui/text/paragraph_impl_txt.cc
Outdated
| SkCanvas* skCanvas = canvas->canvas(); | ||
| if (!skCanvas) | ||
| return; | ||
| txt::ParagraphStyle pStyle = m_paragraph->GetParagraphStyle(); |
lib/ui/text/paragraph_impl_txt.cc
Outdated
|
|
||
| Dart_Handle ParagraphImplTxt::getPositionForOffset(double dx, | ||
| double dy) { // TODO. | ||
| return NULL; |
lib/ui/text/paragraph_impl_txt.cc
Outdated
| } | ||
|
|
||
| Dart_Handle ParagraphImplTxt::getWordBoundary(unsigned offset) { // TODO. | ||
| return NULL; |
|
@abarth @chinmaygarde Should be ready for review again. |
lib/ui/text/paragraph.cc
Outdated
| m_paragraphImpl = std::make_unique<ParagraphImplBlink>(renderView); | ||
| } | ||
|
|
||
| Paragraph::Paragraph(std::unique_ptr<txt::Paragraph>* paragraph) { |
There was a problem hiding this comment.
This should be a std::unique_ptrtxt::Paragraph not a std::unique_ptrtxt::Paragraph*
lib/ui/text/paragraph.cc
Outdated
| Paragraph::Paragraph(PassOwnPtr<RenderView> renderView) | ||
| : m_renderView(renderView) {} | ||
| Paragraph::Paragraph(PassOwnPtr<RenderView> renderView) { | ||
| m_paragraphImpl = std::make_unique<ParagraphImplBlink>(renderView); |
There was a problem hiding this comment.
I'd move this to the initializer list.
lib/ui/text/paragraph.cc
Outdated
| } | ||
|
|
||
| Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph) { | ||
| m_paragraphImpl = std::make_unique<ParagraphImplTxt>(std::move(paragraph)); |
lib/ui/text/paragraph_impl_blink.cc
Outdated
| namespace blink { | ||
|
|
||
| ParagraphImplBlink::ParagraphImplBlink(PassOwnPtr<RenderView> renderView) { | ||
| m_renderView = renderView; |
There was a problem hiding this comment.
I'd move this to the intializer list.
lib/ui/text/paragraph_impl_blink.h
Outdated
|
|
||
| class ParagraphImplBlink : public ParagraphImpl { | ||
| public: | ||
| ~ParagraphImplBlink(); |
|
|
||
| namespace blink { | ||
|
|
||
| class ParagraphImpl { |
There was a problem hiding this comment.
Needs a virtual destructor.
lib/ui/text/paragraph_impl_blink.h
Outdated
| double maxIntrinsicWidth(); | ||
| double alphabeticBaseline(); | ||
| double ideographicBaseline(); | ||
| bool didExceedMaxLines(); |
There was a problem hiding this comment.
These should all be marked override
lib/ui/text/paragraph_impl_txt.cc
Outdated
| } | ||
|
|
||
| double ParagraphImplTxt::minIntrinsicWidth() { | ||
| // TODO(garyq): Implement in the library. |
There was a problem hiding this comment.
I'd probably remove these TODOs from here. They seem to belong in libtxt given that's where the code is missing.
| } | ||
|
|
||
| Dart_Handle ParagraphImplTxt::getPositionForOffset(double dx, double dy) { | ||
| // TODO(garyq): Implement in the library. |
There was a problem hiding this comment.
These I'd keep here because the code is missing from here.
lib/ui/text/paragraph_impl_txt.h
Outdated
|
|
||
| class ParagraphImplTxt : public ParagraphImpl { | ||
| public: | ||
| ~ParagraphImplTxt(); |
There was a problem hiding this comment.
Also missing a bunch of overrides here
* Revert "Initial integration of libtxt with Flutter alongside Blink. (#3771)" This reverts commit c548c65. * Revert "Call Selection.removeSelection if the framework has cleared the selection (#3782)" This reverts commit e5b79ba. * Revert "Update switches to use StringView. (#3781)" This reverts commit 07d4357.
|
Part of flutter/flutter#10476. |

No description provided.