From bd3a181dace6a69bc456c9d854d1eca567dfb818 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 25 Dec 2015 20:31:51 -0800 Subject: [PATCH] Remove IDL from engine/core/text Instead, use our new template magic. --- sky/engine/bindings/dart_ui.cc | 6 +++- sky/engine/core/core.gni | 2 -- sky/engine/core/dart/text.dart | 39 +++++++++++++++++++---- sky/engine/core/text/Paragraph.cpp | 26 +++++++++++++++ sky/engine/core/text/Paragraph.h | 19 ++++++----- sky/engine/core/text/Paragraph.idl | 22 ------------- sky/engine/core/text/ParagraphBuilder.cpp | 25 +++++++++++++++ sky/engine/core/text/ParagraphBuilder.h | 3 ++ sky/engine/core/text/ParagraphBuilder.idl | 15 --------- sky/engine/tonic/dart_args.h | 10 +++--- 10 files changed, 107 insertions(+), 60 deletions(-) delete mode 100644 sky/engine/core/text/Paragraph.idl delete mode 100644 sky/engine/core/text/ParagraphBuilder.idl diff --git a/sky/engine/bindings/dart_ui.cc b/sky/engine/bindings/dart_ui.cc index 3c94d5e8c..b7e71288c 100644 --- a/sky/engine/bindings/dart_ui.cc +++ b/sky/engine/bindings/dart_ui.cc @@ -9,6 +9,8 @@ #include "sky/engine/core/compositing/Scene.h" #include "sky/engine/core/compositing/SceneBuilder.h" #include "sky/engine/core/painting/painting.h" +#include "sky/engine/core/text/Paragraph.h" +#include "sky/engine/core/text/ParagraphBuilder.h" #include "sky/engine/core/window/window.h" #include "sky/engine/tonic/dart_converter.h" #include "sky/engine/tonic/dart_error.h" @@ -40,10 +42,12 @@ void DartUI::InitForIsolate() { if (!g_natives) { g_natives = new DartLibraryNatives(); DartRuntimeHooks::RegisterNatives(g_natives); - Window::RegisterNatives(g_natives); Painting::RegisterNatives(g_natives); + Paragraph::RegisterNatives(g_natives); + ParagraphBuilder::RegisterNatives(g_natives); Scene::RegisterNatives(g_natives); SceneBuilder::RegisterNatives(g_natives); + Window::RegisterNatives(g_natives); } DART_CHECK_VALID(Dart_SetNativeResolver( diff --git a/sky/engine/core/core.gni b/sky/engine/core/core.gni index 744e29433..a9f402c4d 100644 --- a/sky/engine/core/core.gni +++ b/sky/engine/core/core.gni @@ -250,8 +250,6 @@ core_idl_files = get_path_info([ "painting/Picture.idl", "painting/PictureRecorder.idl", "painting/Shader.idl", - "text/Paragraph.idl", - "text/ParagraphBuilder.idl", ], "abspath") diff --git a/sky/engine/core/dart/text.dart b/sky/engine/core/dart/text.dart index b162ed0f7..21063cd88 100644 --- a/sky/engine/core/dart/text.dart +++ b/sky/engine/core/dart/text.dart @@ -309,16 +309,41 @@ class ParagraphStyle { final double _lineHeight; } -class ParagraphBuilder extends _ParagraphBuilder { +abstract class Paragraph extends NativeFieldWrapperClass2 { + double get minWidth native "Paragraph_minWidth"; + void set minWidth(double value) native "Paragraph_setMinWidth"; + double get maxWidth native "Paragraph_maxWidth"; + void set maxWidth(double value) native "Paragraph_setMaxWidth"; + double get minHeight native "Paragraph_minHeight"; + void set minHeight(double value) native "Paragraph_setMinHeight"; + double get maxHeight native "Paragraph_maxHeight"; + void set maxHeight(double value) native "Paragraph_setMaxHeight"; + double get width native "Paragraph_width"; + double get height native "Paragraph_height"; + double get minIntrinsicWidth native "Paragraph_minIntrinsicWidth"; + double get maxIntrinsicWidth native "Paragraph_maxIntrinsicWidth"; + double get alphabeticBaseline native "Paragraph_alphabeticBaseline"; + double get ideographicBaseline native "Paragraph_ideographicBaseline"; + + void layout() native "Paragraph_layout"; + void paint(Canvas canvas, Offset offset) native "Paragraph_paint"; +} + +class ParagraphBuilder extends NativeFieldWrapperClass2 { + void _constructor() native "ParagraphBuilder_constructor"; + ParagraphBuilder() { _constructor(); } + + void _pushStyle(Int32List encoded, String fontFamily, double fontSize, double letterSpacing) native "ParagraphBuilder_pushStyle"; + void pushStyle(TextStyle style) { _pushStyle(style._encoded, style._fontFamily, style._fontSize, style._letterSpacing); } - void pop() => _pop(); - void addText(String text) => _addText(text); + void pop() native "ParagraphBuilder_pop"; + void addText(String text) native "ParagraphBuilder_addText"; - Paragraph build(ParagraphStyle style) { - Paragraph result = _build(style._encoded, style._lineHeight); - return result; - } + Paragraph _build(Int32List encoded, double lineHeight) native "ParagraphBuilder_build"; + + Paragraph build(ParagraphStyle style) => _build(style._encoded, style._lineHeight); } + diff --git a/sky/engine/core/text/Paragraph.cpp b/sky/engine/core/text/Paragraph.cpp index 90e30dc45..2ad362874 100644 --- a/sky/engine/core/text/Paragraph.cpp +++ b/sky/engine/core/text/Paragraph.cpp @@ -8,9 +8,35 @@ #include "sky/engine/core/rendering/style/RenderStyle.h" #include "sky/engine/platform/fonts/FontCache.h" #include "sky/engine/platform/graphics/GraphicsContext.h" +#include "sky/engine/tonic/dart_args.h" +#include "sky/engine/tonic/dart_binding_macros.h" +#include "sky/engine/tonic/dart_converter.h" +#include "sky/engine/tonic/dart_library_natives.h" namespace blink { +IMPLEMENT_WRAPPERTYPEINFO(Paragraph); + +#define FOR_EACH_BINDING(V) \ + V(Paragraph, minWidth) \ + V(Paragraph, setMinWidth) \ + V(Paragraph, maxWidth) \ + V(Paragraph, setMaxWidth) \ + V(Paragraph, minHeight) \ + V(Paragraph, setMinHeight) \ + V(Paragraph, maxHeight) \ + V(Paragraph, setMaxHeight) \ + V(Paragraph, width) \ + V(Paragraph, height) \ + V(Paragraph, minIntrinsicWidth) \ + V(Paragraph, maxIntrinsicWidth) \ + V(Paragraph, alphabeticBaseline) \ + V(Paragraph, ideographicBaseline) \ + V(Paragraph, layout) \ + V(Paragraph, paint) + +DART_BIND_ALL(Paragraph, FOR_EACH_BINDING) + Paragraph::Paragraph(PassOwnPtr renderView) : m_renderView(renderView) { diff --git a/sky/engine/core/text/Paragraph.h b/sky/engine/core/text/Paragraph.h index f7b733f82..e9791be58 100644 --- a/sky/engine/core/text/Paragraph.h +++ b/sky/engine/core/text/Paragraph.h @@ -13,6 +13,7 @@ #include "sky/engine/core/rendering/RenderView.h" namespace blink { +class DartLibraryNatives; class Paragraph : public RefCounted, public DartWrappable { DEFINE_WRAPPERTYPEINFO(); @@ -23,17 +24,17 @@ public: ~Paragraph() override; - LayoutUnit minWidth() const { return m_minWidth; } - void setMinWidth(LayoutUnit width) { m_minWidth = width; } + double minWidth() { return m_minWidth; } + void setMinWidth(double width) { m_minWidth = width; } - LayoutUnit maxWidth() const { return m_maxWidth; } - void setMaxWidth(LayoutUnit width) { m_maxWidth = width; } + double maxWidth() { return m_maxWidth; } + void setMaxWidth(double width) { m_maxWidth = width; } - LayoutUnit minHeight() const { return m_minHeight; } - void setMinHeight(LayoutUnit height) { m_minHeight = height; } + double minHeight() { return m_minHeight; } + void setMinHeight(double height) { m_minHeight = height; } - LayoutUnit maxHeight() const { return m_maxHeight; } - void setMaxHeight(LayoutUnit height) { m_maxHeight = height; } + double maxHeight() { return m_maxHeight; } + void setMaxHeight(double height) { m_maxHeight = height; } double width(); double height(); @@ -47,6 +48,8 @@ public: RenderView* renderView() const { return m_renderView.get(); } + static void RegisterNatives(DartLibraryNatives* natives); + private: RenderBox* firstChildBox() const { return m_renderView->firstChildBox(); } diff --git a/sky/engine/core/text/Paragraph.idl b/sky/engine/core/text/Paragraph.idl deleted file mode 100644 index 34c5693e9..000000000 --- a/sky/engine/core/text/Paragraph.idl +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -interface Paragraph { - // Inputs to layout - attribute double minWidth; - attribute double maxWidth; - attribute double minHeight; - attribute double maxHeight; - - // Outputs from layout - readonly attribute double width; - readonly attribute double height; - readonly attribute double minIntrinsicWidth; // Intrinsic width if all wrappable points wrap. - readonly attribute double maxIntrinsicWidth; // Intrinsic width if no wrappable points wrap. - readonly attribute double alphabeticBaseline; // Distance from top to alphabetic baseline of first line - readonly attribute double ideographicBaseline; // Distance from top to ideographic baseline of first line - - void layout(); - void paint(Canvas canvas, Offset offset); -}; diff --git a/sky/engine/core/text/ParagraphBuilder.cpp b/sky/engine/core/text/ParagraphBuilder.cpp index 46fcba4af..658692c6a 100644 --- a/sky/engine/core/text/ParagraphBuilder.cpp +++ b/sky/engine/core/text/ParagraphBuilder.cpp @@ -9,6 +9,10 @@ #include "sky/engine/core/rendering/RenderParagraph.h" #include "sky/engine/core/rendering/RenderText.h" #include "sky/engine/core/rendering/style/RenderStyle.h" +#include "sky/engine/tonic/dart_args.h" +#include "sky/engine/tonic/dart_binding_macros.h" +#include "sky/engine/tonic/dart_converter.h" +#include "sky/engine/tonic/dart_library_natives.h" namespace blink { namespace { @@ -67,6 +71,27 @@ const int kLineHeightMask = 1 << kLineHeightIndex; } // namespace +static void ParagraphBuilder_constructor(Dart_NativeArguments args) { + DartCallConstructor(&ParagraphBuilder::create, args); +} + +IMPLEMENT_WRAPPERTYPEINFO(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(DartLibraryNatives* natives) { + natives->Register({ + { "ParagraphBuilder_constructor", ParagraphBuilder_constructor, 1, true }, +FOR_EACH_BINDING(DART_REGISTER_NATIVE) + }); +} + ParagraphBuilder::ParagraphBuilder() { m_fontSelector = CSSFontSelector::create(); diff --git a/sky/engine/core/text/ParagraphBuilder.h b/sky/engine/core/text/ParagraphBuilder.h index cd1c9046b..899e8baf9 100644 --- a/sky/engine/core/text/ParagraphBuilder.h +++ b/sky/engine/core/text/ParagraphBuilder.h @@ -14,6 +14,7 @@ #include "sky/engine/wtf/RefCounted.h" namespace blink { +class DartLibraryNatives; class ParagraphBuilder : public RefCounted, public DartWrappable { DEFINE_WRAPPERTYPEINFO(); @@ -31,6 +32,8 @@ public: PassRefPtr build(Int32List& encoded, double lineHeight); + static void RegisterNatives(DartLibraryNatives* natives); + private: explicit ParagraphBuilder(); diff --git a/sky/engine/core/text/ParagraphBuilder.idl b/sky/engine/core/text/ParagraphBuilder.idl deleted file mode 100644 index 369accd7b..000000000 --- a/sky/engine/core/text/ParagraphBuilder.idl +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -[ - Constructor(), - PrivateDart, -] interface ParagraphBuilder { - void pushStyle(Int32List encoded, DOMString fontFamily, double fontSize, double letterSpacing); - void pop(); - - void addText(DOMString text); - - Paragraph build(Int32List encoded, double lineHeight); -}; diff --git a/sky/engine/tonic/dart_args.h b/sky/engine/tonic/dart_args.h index a2fd8ae57..0253e0757 100644 --- a/sky/engine/tonic/dart_args.h +++ b/sky/engine/tonic/dart_args.h @@ -90,6 +90,11 @@ struct DartArgHolder { : value(it->GetNext()) {} }; +template +void DartReturn(T result, Dart_NativeArguments args) { + DartConverter::SetReturnValue(args, result); +} + template class DartDispatcher { }; @@ -149,11 +154,6 @@ struct DartDispatcher, ResultType (C::*)(ArgTypes...)> } }; -template -void DartReturn(T result, Dart_NativeArguments args) { - DartConverter::SetReturnValue(args, result); -} - template void DartCall(Sig func, Dart_NativeArguments args) { DartArgIterator it(args); -- GitLab