diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index 55ec7b29f8..f579a1ec66 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -66,7 +66,14 @@ source_set("ui") { "//mojo/services/asset_bundle/interfaces", ] - if (!is_fuchsia) { + if (is_fuchsia) { + sources += [ + "text/paragraph_builder_stub.cc", + "text/paragraph_builder_stub.h", + "text/paragraph_stub.cc", + "text/paragraph_stub.h", + ] + } else { sources += [ "text/paragraph_builder.cc", "text/paragraph_builder.h", diff --git a/engine/src/flutter/lib/ui/dart_ui.cc b/engine/src/flutter/lib/ui/dart_ui.cc index 8953c42563..54942de9b6 100644 --- a/engine/src/flutter/lib/ui/dart_ui.cc +++ b/engine/src/flutter/lib/ui/dart_ui.cc @@ -23,7 +23,10 @@ #include "lib/tonic/converter/dart_converter.h" #include "lib/tonic/logging/dart_error.h" -#if !defined(OS_FUCHSIA) +#if defined(OS_FUCHSIA) +#include "flutter/lib/ui/text/paragraph_builder_stub.h" +#include "flutter/lib/ui/text/paragraph_stub.h" +#else #include "flutter/lib/ui/text/paragraph_builder.h" #include "flutter/lib/ui/text/paragraph.h" #endif @@ -60,10 +63,8 @@ void DartUI::InitForGlobal() { ImageShader::RegisterNatives(g_natives); MaskFilter::RegisterNatives(g_natives); MojoServices::RegisterNatives(g_natives); -#if !defined(OS_FUCHSIA) Paragraph::RegisterNatives(g_natives); ParagraphBuilder::RegisterNatives(g_natives); -#endif Picture::RegisterNatives(g_natives); PictureRecorder::RegisterNatives(g_natives); Scene::RegisterNatives(g_natives); diff --git a/engine/src/flutter/lib/ui/mojo_services.cc b/engine/src/flutter/lib/ui/mojo_services.cc index 381a24572e..a03f7814df 100644 --- a/engine/src/flutter/lib/ui/mojo_services.cc +++ b/engine/src/flutter/lib/ui/mojo_services.cc @@ -22,27 +22,45 @@ MojoServices* GetMojoServices() { } void DartTakeRootBundle(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeRootBundle()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeRootBundle(); + Dart_SetIntegerReturnValue(args, handle); } void DartTakeIncomingServices(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeIncomingServices()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeIncomingServices(); + Dart_SetIntegerReturnValue(args, handle); } void DartTakeOutgoingServices(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeOutgoingServices()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeOutgoingServices(); + Dart_SetIntegerReturnValue(args, handle); } void DartTakeShell(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeShell()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeShell(); + Dart_SetIntegerReturnValue(args, handle); } void DartTakeView(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeView()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeView(); + Dart_SetIntegerReturnValue(args, handle); } void DartTakeViewServices(Dart_NativeArguments args) { - Dart_SetIntegerReturnValue(args, GetMojoServices()->TakeViewServices()); + int handle = MOJO_HANDLE_INVALID; + if (MojoServices* services = GetMojoServices()) + handle = services->TakeViewServices(); + Dart_SetIntegerReturnValue(args, handle); } } // namespace diff --git a/engine/src/flutter/lib/ui/text/paragraph_builder_stub.cc b/engine/src/flutter/lib/ui/text/paragraph_builder_stub.cc new file mode 100644 index 0000000000..53e3d08c4c --- /dev/null +++ b/engine/src/flutter/lib/ui/text/paragraph_builder_stub.cc @@ -0,0 +1,59 @@ +// 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. + +#include "flutter/lib/ui/text/paragraph_builder_stub.h" + +#include "lib/tonic/converter/dart_converter.h" +#include "lib/tonic/dart_args.h" +#include "lib/tonic/dart_binding_macros.h" +#include "lib/tonic/dart_library_natives.h" + +namespace blink { + +static void ParagraphBuilder_constructor(Dart_NativeArguments args) { + DartCallConstructor(&ParagraphBuilder::create, args); +} + +IMPLEMENT_WRAPPERTYPEINFO(ui, ParagraphBuilder); + +#define FOR_EACH_BINDING(V) \ + V(ParagraphBuilder, pushStyle) \ + V(ParagraphBuilder, pop) \ + V(ParagraphBuilder, addText) \ + V(ParagraphBuilder, build) + +FOR_EACH_BINDING(DART_NATIVE_CALLBACK) + +void ParagraphBuilder::RegisterNatives(tonic::DartLibraryNatives* natives) { + natives->Register( + {{"ParagraphBuilder_constructor", ParagraphBuilder_constructor, 1, true}, + FOR_EACH_BINDING(DART_REGISTER_NATIVE)}); +} + +ParagraphBuilder::ParagraphBuilder() {} + +ParagraphBuilder::~ParagraphBuilder() {} + +void ParagraphBuilder::pushStyle(tonic::Int32List& encoded, + const std::string& fontFamily, + double fontSize, + double letterSpacing, + double wordSpacing, + double height) { + encoded.Release(); +} + +void ParagraphBuilder::pop() {} + +void ParagraphBuilder::addText(const std::string& text) {} + +ftl::RefPtr ParagraphBuilder::build(tonic::Int32List& encoded, + const std::string& fontFamily, + double fontSize, + double lineHeight) { + encoded.Release(); + return Paragraph::create(); +} + +} // namespace blink diff --git a/engine/src/flutter/lib/ui/text/paragraph_builder_stub.h b/engine/src/flutter/lib/ui/text/paragraph_builder_stub.h new file mode 100644 index 0000000000..cee9717550 --- /dev/null +++ b/engine/src/flutter/lib/ui/text/paragraph_builder_stub.h @@ -0,0 +1,53 @@ +// 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. + +#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_STUB_H_ +#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_STUB_H_ + +#include "flutter/lib/ui/text/paragraph_stub.h" +#include "lib/tonic/dart_wrappable.h" +#include "lib/tonic/typed_data/int32_list.h" + +namespace tonic { +class DartLibraryNatives; +} // namespace tonic + +namespace blink { + +class ParagraphBuilder : public ftl::RefCountedThreadSafe, + public tonic::DartWrappable { + DEFINE_WRAPPERTYPEINFO(); + FRIEND_MAKE_REF_COUNTED(ParagraphBuilder); + + public: + static ftl::RefPtr create() { + return ftl::MakeRefCounted(); + } + + ~ParagraphBuilder() override; + + void pushStyle(tonic::Int32List& encoded, + const std::string& fontFamily, + double fontSize, + double letterSpacing, + double wordSpacing, + double height); + void pop(); + + void addText(const std::string& text); + + ftl::RefPtr build(tonic::Int32List& encoded, + const std::string& fontFamily, + double fontSize, + double lineHeight); + + static void RegisterNatives(tonic::DartLibraryNatives* natives); + + private: + ParagraphBuilder(); +}; + +} // namespace blink + +#endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_BUILDER_STUB_H_ diff --git a/engine/src/flutter/lib/ui/text/paragraph_stub.cc b/engine/src/flutter/lib/ui/text/paragraph_stub.cc new file mode 100644 index 0000000000..a718df8b38 --- /dev/null +++ b/engine/src/flutter/lib/ui/text/paragraph_stub.cc @@ -0,0 +1,81 @@ +// 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. + +#include "flutter/lib/ui/text/paragraph_stub.h" + +#include "lib/tonic/converter/dart_converter.h" +#include "lib/tonic/dart_args.h" +#include "lib/tonic/dart_binding_macros.h" +#include "lib/tonic/dart_library_natives.h" + +using tonic::ToDart; + +namespace blink { + +IMPLEMENT_WRAPPERTYPEINFO(ui, Paragraph); + +#define FOR_EACH_BINDING(V) \ + V(Paragraph, width) \ + V(Paragraph, height) \ + V(Paragraph, minIntrinsicWidth) \ + V(Paragraph, maxIntrinsicWidth) \ + V(Paragraph, alphabeticBaseline) \ + V(Paragraph, ideographicBaseline) \ + V(Paragraph, layout) \ + V(Paragraph, paint) \ + V(Paragraph, getWordBoundary) \ + V(Paragraph, getRectsForRange) \ + V(Paragraph, getPositionForOffset) + +DART_BIND_ALL(Paragraph, FOR_EACH_BINDING) + +Paragraph::Paragraph() {} + +Paragraph::~Paragraph() {} + +double Paragraph::width() { + return 0.0; +} + +double Paragraph::height() { + return 0.0; +} + +double Paragraph::minIntrinsicWidth() { + return 0.0; +} + +double Paragraph::maxIntrinsicWidth() { + return 0.0; +} + +double Paragraph::alphabeticBaseline() { + return 0.0; +} + +double Paragraph::ideographicBaseline() { + return 0.0; +} + +void Paragraph::layout(double width) {} + +void Paragraph::paint(Canvas* canvas, double x, double y) {} + +void Paragraph::getRectsForRange(unsigned start, unsigned end) {} + +Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { + Dart_Handle result = Dart_NewList(2); + Dart_ListSetAt(result, 0, ToDart(0)); + Dart_ListSetAt(result, 1, ToDart(0)); + return result; +} + +Dart_Handle Paragraph::getWordBoundary(unsigned offset) { + Dart_Handle result = Dart_NewList(2); + Dart_ListSetAt(result, 0, ToDart(0)); + Dart_ListSetAt(result, 1, ToDart(0)); + return result; +} + +} // namespace blink diff --git a/engine/src/flutter/lib/ui/text/paragraph_stub.h b/engine/src/flutter/lib/ui/text/paragraph_stub.h new file mode 100644 index 0000000000..2ae78920f1 --- /dev/null +++ b/engine/src/flutter/lib/ui/text/paragraph_stub.h @@ -0,0 +1,51 @@ +// 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. + +#ifndef FLUTTER_LIB_UI_TEXT_PARAGRAPH_STUB_H_ +#define FLUTTER_LIB_UI_TEXT_PARAGRAPH_STUB_H_ + +#include "flutter/lib/ui/painting/canvas.h" +#include "lib/tonic/dart_wrappable.h" + +namespace tonic { +class DartLibraryNatives; +} // namespace tonic + +namespace blink { + +class Paragraph : public ftl::RefCountedThreadSafe, + public tonic::DartWrappable { + DEFINE_WRAPPERTYPEINFO(); + FRIEND_MAKE_REF_COUNTED(Paragraph); + + public: + static ftl::RefPtr create() { + return ftl::MakeRefCounted(); + } + + ~Paragraph() override; + + double width(); + double height(); + double minIntrinsicWidth(); + double maxIntrinsicWidth(); + double alphabeticBaseline(); + double ideographicBaseline(); + + void layout(double width); + void paint(Canvas* canvas, double x, double y); + + void getRectsForRange(unsigned start, unsigned end); + Dart_Handle getPositionForOffset(double dx, double dy); + Dart_Handle getWordBoundary(unsigned offset); + + static void RegisterNatives(tonic::DartLibraryNatives* natives); + + private: + Paragraph(); +}; + +} // namespace blink + +#endif // FLUTTER_LIB_UI_TEXT_PARAGRAPH_STUB_H_