From 0f9274e84126644a063415782b4f183a9ba53581 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 14 Aug 2019 15:53:28 -0700 Subject: [PATCH] Remove the ParagraphImpl class from the text API ParagraphImpl was used to switch between libtxt and Blink implementations of text rendering and is now obsolete. --- ci/licenses_golden/licenses_flutter | 4 - lib/ui/BUILD.gn | 4 - lib/ui/text/paragraph.cc | 54 ++++++++++---- lib/ui/text/paragraph.h | 4 +- lib/ui/text/paragraph_impl.cc | 7 -- lib/ui/text/paragraph_impl.h | 53 -------------- lib/ui/text/paragraph_impl_txt.cc | 110 ---------------------------- lib/ui/text/paragraph_impl_txt.h | 48 ------------ 8 files changed, 39 insertions(+), 245 deletions(-) delete mode 100644 lib/ui/text/paragraph_impl.cc delete mode 100644 lib/ui/text/paragraph_impl.h delete mode 100644 lib/ui/text/paragraph_impl_txt.cc delete mode 100644 lib/ui/text/paragraph_impl_txt.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 443f865c5d4a3..d728f62ce4136 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -325,10 +325,6 @@ FILE: ../../../flutter/lib/ui/text/paragraph.cc FILE: ../../../flutter/lib/ui/text/paragraph.h FILE: ../../../flutter/lib/ui/text/paragraph_builder.cc FILE: ../../../flutter/lib/ui/text/paragraph_builder.h -FILE: ../../../flutter/lib/ui/text/paragraph_impl.cc -FILE: ../../../flutter/lib/ui/text/paragraph_impl.h -FILE: ../../../flutter/lib/ui/text/paragraph_impl_txt.cc -FILE: ../../../flutter/lib/ui/text/paragraph_impl_txt.h FILE: ../../../flutter/lib/ui/text/text_box.cc FILE: ../../../flutter/lib/ui/text/text_box.h FILE: ../../../flutter/lib/ui/ui.dart diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index b6033292acd7b..a11ed9116e8b9 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -84,10 +84,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_txt.cc", - "text/paragraph_impl_txt.h", "text/text_box.cc", "text/text_box.h", "ui_dart_state.cc", diff --git a/lib/ui/text/paragraph.cc b/lib/ui/text/paragraph.cc index 3821d4bc4e9ea..a14fe896c93f7 100644 --- a/lib/ui/text/paragraph.cc +++ b/lib/ui/text/paragraph.cc @@ -38,8 +38,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph); DART_BIND_ALL(Paragraph, FOR_EACH_BINDING) Paragraph::Paragraph(std::unique_ptr paragraph) - : m_paragraphImpl( - std::make_unique(std::move(paragraph))) {} + : m_paragraph(std::move(paragraph)) {} Paragraph::~Paragraph() = default; @@ -51,64 +50,87 @@ size_t Paragraph::GetAllocationSize() { } double Paragraph::width() { - return m_paragraphImpl->width(); + return m_paragraph->GetMaxWidth(); } double Paragraph::height() { - return m_paragraphImpl->height(); + return m_paragraph->GetHeight(); } double Paragraph::longestLine() { - return m_paragraphImpl->longestLine(); + return m_paragraph->GetLongestLine(); } double Paragraph::minIntrinsicWidth() { - return m_paragraphImpl->minIntrinsicWidth(); + return m_paragraph->GetMinIntrinsicWidth(); } double Paragraph::maxIntrinsicWidth() { - return m_paragraphImpl->maxIntrinsicWidth(); + return m_paragraph->GetMaxIntrinsicWidth(); } double Paragraph::alphabeticBaseline() { - return m_paragraphImpl->alphabeticBaseline(); + return m_paragraph->GetAlphabeticBaseline(); } double Paragraph::ideographicBaseline() { - return m_paragraphImpl->ideographicBaseline(); + return m_paragraph->GetIdeographicBaseline(); } bool Paragraph::didExceedMaxLines() { - return m_paragraphImpl->didExceedMaxLines(); + return m_paragraph->DidExceedMaxLines(); } void Paragraph::layout(double width) { - m_paragraphImpl->layout(width); + m_paragraph->Layout(width); } void Paragraph::paint(Canvas* canvas, double x, double y) { - m_paragraphImpl->paint(canvas, x, y); + SkCanvas* sk_canvas = canvas->canvas(); + if (!sk_canvas) + return; + m_paragraph->Paint(sk_canvas, x, y); } std::vector Paragraph::getRectsForRange(unsigned start, unsigned end, unsigned boxHeightStyle, unsigned boxWidthStyle) { - return m_paragraphImpl->getRectsForRange( + std::vector result; + std::vector boxes = m_paragraph->GetRectsForRange( start, end, static_cast(boxHeightStyle), static_cast(boxWidthStyle)); + for (const txt::Paragraph::TextBox& box : boxes) { + result.emplace_back(box.rect, static_cast(box.direction)); + } + return result; } std::vector Paragraph::getRectsForPlaceholders() { - return m_paragraphImpl->getRectsForPlaceholders(); + std::vector result; + std::vector boxes = + m_paragraph->GetRectsForPlaceholders(); + for (const txt::Paragraph::TextBox& box : boxes) { + result.emplace_back(box.rect, static_cast(box.direction)); + } + return result; } Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { - return m_paragraphImpl->getPositionForOffset(dx, dy); + Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); + txt::Paragraph::PositionWithAffinity pos = + m_paragraph->GetGlyphPositionAtCoordinate(dx, dy); + Dart_ListSetAt(result, 0, ToDart(pos.position)); + Dart_ListSetAt(result, 1, ToDart(static_cast(pos.affinity))); + return result; } Dart_Handle Paragraph::getWordBoundary(unsigned offset) { - return m_paragraphImpl->getWordBoundary(offset); + txt::Paragraph::Range point = m_paragraph->GetWordBoundary(offset); + Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); + Dart_ListSetAt(result, 0, ToDart(point.start)); + Dart_ListSetAt(result, 1, ToDart(point.end)); + return result; } } // namespace flutter diff --git a/lib/ui/text/paragraph.h b/lib/ui/text/paragraph.h index 3fea79b224503..7787100ca8539 100644 --- a/lib/ui/text/paragraph.h +++ b/lib/ui/text/paragraph.h @@ -8,8 +8,6 @@ #include "flutter/fml/message_loop.h" #include "flutter/lib/ui/dart_wrapper.h" #include "flutter/lib/ui/painting/canvas.h" -#include "flutter/lib/ui/text/paragraph_impl.h" -#include "flutter/lib/ui/text/paragraph_impl_txt.h" #include "flutter/lib/ui/text/text_box.h" #include "flutter/third_party/txt/src/txt/paragraph.h" @@ -56,7 +54,7 @@ class Paragraph : public RefCountedDartWrappable { static void RegisterNatives(tonic::DartLibraryNatives* natives); private: - std::unique_ptr m_paragraphImpl; + std::unique_ptr m_paragraph; explicit Paragraph(std::unique_ptr paragraph); }; diff --git a/lib/ui/text/paragraph_impl.cc b/lib/ui/text/paragraph_impl.cc deleted file mode 100644 index b54f195b59f30..0000000000000 --- a/lib/ui/text/paragraph_impl.cc +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2013 The Flutter 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 "flutter/lib/ui/text/paragraph_impl.h" - -namespace flutter {} // namespace flutter diff --git a/lib/ui/text/paragraph_impl.h b/lib/ui/text/paragraph_impl.h deleted file mode 100644 index c0dd8e4811f57..0000000000000 --- a/lib/ui/text/paragraph_impl.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_H_ -#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_H_ - -#include "flutter/lib/ui/painting/canvas.h" -#include "flutter/lib/ui/text/text_box.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" - -namespace flutter { - -class ParagraphImpl { - public: - virtual ~ParagraphImpl(){}; - - virtual double width() = 0; - - virtual double height() = 0; - - virtual double longestLine() = 0; - - virtual double minIntrinsicWidth() = 0; - - virtual double maxIntrinsicWidth() = 0; - - virtual double alphabeticBaseline() = 0; - - virtual double ideographicBaseline() = 0; - - virtual bool didExceedMaxLines() = 0; - - virtual void layout(double width) = 0; - - virtual void paint(Canvas* canvas, double x, double y) = 0; - - virtual std::vector getRectsForRange( - unsigned start, - unsigned end, - txt::Paragraph::RectHeightStyle rect_height_style, - txt::Paragraph::RectWidthStyle rect_width_style) = 0; - - virtual std::vector getRectsForPlaceholders() = 0; - - virtual Dart_Handle getPositionForOffset(double dx, double dy) = 0; - - virtual Dart_Handle getWordBoundary(unsigned offset) = 0; -}; - -} // namespace flutter - -#endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_H_ diff --git a/lib/ui/text/paragraph_impl_txt.cc b/lib/ui/text/paragraph_impl_txt.cc deleted file mode 100644 index ab9467a572fcc..0000000000000 --- a/lib/ui/text/paragraph_impl_txt.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2013 The Flutter 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 "flutter/lib/ui/text/paragraph_impl_txt.h" - -#include "flutter/common/task_runners.h" -#include "flutter/fml/logging.h" -#include "flutter/fml/task_runner.h" -#include "flutter/lib/ui/text/paragraph.h" -#include "flutter/lib/ui/text/paragraph_impl.h" -#include "third_party/skia/include/core/SkPoint.h" -#include "third_party/tonic/converter/dart_converter.h" - -using tonic::ToDart; - -namespace flutter { - -ParagraphImplTxt::ParagraphImplTxt(std::unique_ptr paragraph) - : m_paragraph(std::move(paragraph)) {} - -ParagraphImplTxt::~ParagraphImplTxt() {} - -double ParagraphImplTxt::width() { - return m_paragraph->GetMaxWidth(); -} - -double ParagraphImplTxt::height() { - return m_paragraph->GetHeight(); -} - -double ParagraphImplTxt::longestLine() { - return m_paragraph->GetLongestLine(); -} - -double ParagraphImplTxt::minIntrinsicWidth() { - return m_paragraph->GetMinIntrinsicWidth(); -} - -double ParagraphImplTxt::maxIntrinsicWidth() { - return m_paragraph->GetMaxIntrinsicWidth(); -} - -double ParagraphImplTxt::alphabeticBaseline() { - return m_paragraph->GetAlphabeticBaseline(); -} - -double ParagraphImplTxt::ideographicBaseline() { - return m_paragraph->GetIdeographicBaseline(); -} - -bool ParagraphImplTxt::didExceedMaxLines() { - return m_paragraph->DidExceedMaxLines(); -} - -void ParagraphImplTxt::layout(double width) { - m_width = width; - m_paragraph->Layout(width); -} - -void ParagraphImplTxt::paint(Canvas* canvas, double x, double y) { - SkCanvas* sk_canvas = canvas->canvas(); - if (!sk_canvas) - return; - m_paragraph->Paint(sk_canvas, x, y); -} - -std::vector ParagraphImplTxt::getRectsForRange( - unsigned start, - unsigned end, - txt::Paragraph::RectHeightStyle rect_height_style, - txt::Paragraph::RectWidthStyle rect_width_style) { - std::vector result; - std::vector boxes = m_paragraph->GetRectsForRange( - start, end, rect_height_style, rect_width_style); - for (const txt::Paragraph::TextBox& box : boxes) { - result.emplace_back(box.rect, static_cast(box.direction)); - } - return result; -} - -std::vector ParagraphImplTxt::getRectsForPlaceholders() { - std::vector result; - std::vector boxes = - m_paragraph->GetRectsForPlaceholders(); - for (const txt::Paragraph::TextBox& box : boxes) { - result.emplace_back(box.rect, - static_cast(box.direction)); - } - return result; -} - -Dart_Handle ParagraphImplTxt::getPositionForOffset(double dx, double dy) { - Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); - txt::Paragraph::PositionWithAffinity pos = - m_paragraph->GetGlyphPositionAtCoordinate(dx, dy); - Dart_ListSetAt(result, 0, ToDart(pos.position)); - Dart_ListSetAt(result, 1, ToDart(static_cast(pos.affinity))); - return result; -} - -Dart_Handle ParagraphImplTxt::getWordBoundary(unsigned offset) { - txt::Paragraph::Range point = m_paragraph->GetWordBoundary(offset); - Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); - Dart_ListSetAt(result, 0, ToDart(point.start)); - Dart_ListSetAt(result, 1, ToDart(point.end)); - return result; -} - -} // namespace flutter diff --git a/lib/ui/text/paragraph_impl_txt.h b/lib/ui/text/paragraph_impl_txt.h deleted file mode 100644 index e1323202b3d16..0000000000000 --- a/lib/ui/text/paragraph_impl_txt.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_TXT_H_ -#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_TXT_H_ - -#include "flutter/lib/ui/painting/canvas.h" -#include "flutter/lib/ui/text/paragraph_impl.h" -#include "flutter/lib/ui/text/text_box.h" - -namespace flutter { - -class ParagraphImplTxt : public ParagraphImpl { - public: - ~ParagraphImplTxt() override; - - explicit ParagraphImplTxt(std::unique_ptr paragraph); - - double width() override; - double height() override; - double longestLine() override; - double minIntrinsicWidth() override; - double maxIntrinsicWidth() override; - double alphabeticBaseline() override; - double ideographicBaseline() override; - bool didExceedMaxLines() override; - - void layout(double width) override; - void paint(Canvas* canvas, double x, double y) override; - - std::vector getRectsForRange( - unsigned start, - unsigned end, - txt::Paragraph::RectHeightStyle rect_height_style, - txt::Paragraph::RectWidthStyle rect_width_style) override; - std::vector getRectsForPlaceholders() override; - Dart_Handle getPositionForOffset(double dx, double dy) override; - Dart_Handle getWordBoundary(unsigned offset) override; - - private: - std::unique_ptr m_paragraph; - double m_width = -1.0; -}; - -} // namespace flutter - -#endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_IMPL_TXT_H_