Skip to content

Commit

Permalink
[web] Migrate Flutter Web to JS static interop - 10. (flutter#32596)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualitt authored Apr 21, 2022
1 parent d439bc8 commit 1d6874e
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,10 @@ extension TypefaceFontProviderExtension on SkFontMgr {

@JS()
@anonymous
class SkLineMetrics {
@staticInterop
class SkLineMetrics {}

extension SkLineMetricsExtension on SkLineMetrics {
external int get startIndex;
external int get endIndex;
external int get endExcludingWhitespaces;
Expand Down Expand Up @@ -2149,48 +2152,70 @@ class SkParagraph {
}

@JS()
class SkTextPosition {
@staticInterop
class SkTextPosition {}

extension SkTextPositionExtnsion on SkTextPosition {
external SkAffinity get affinity;
external int get pos;
}

@JS()
class SkTextRange {
@staticInterop
class SkTextRange {}

extension SkTextRangeExtension on SkTextRange {
external int get start;
external int get end;
}

@JS()
@anonymous
class SkVertices {
@staticInterop
class SkVertices {}

extension SkVerticesExtension on SkVertices {
external void delete();
}

@JS()
@anonymous
@staticInterop
class SkTonalColors {
external factory SkTonalColors({
required Float32List ambient,
required Float32List spot,
});
}

extension SkTonalColorsExtension on SkTonalColors {
external Float32List get ambient;
external Float32List get spot;
}

@JS()
class SkFontMgrNamespace {
@staticInterop
class SkFontMgrNamespace {}

extension SkFontMgrNamespaceExtension on SkFontMgrNamespace {
// TODO(yjbanov): can this be made non-null? It returns null in our unit-tests right now.
external SkFontMgr? FromData(List<Uint8List> fonts);
}

@JS()
class TypefaceFontProviderNamespace {
@staticInterop
class TypefaceFontProviderNamespace {}

extension TypefaceFontProviderNamespaceExtension on TypefaceFontProviderNamespace {
external TypefaceFontProvider Make();
}

@JS()
@anonymous
class SkTypefaceFactory {
@staticInterop
class SkTypefaceFactory {}

extension SkTypefaceFactoryExtension on SkTypefaceFactory {
external SkTypeface? MakeFreeTypeFaceFromData(ByteBuffer fontData);
}

Expand Down Expand Up @@ -2401,10 +2426,14 @@ class JsConstructor {
/// 5. The finalizer function is called with the SkPaint as the sole argument.
/// 6. We call `delete` on SkPaint.
@JS('window.FinalizationRegistry')
@staticInterop
class SkObjectFinalizationRegistry {
// TODO(hterkelsen): Add a type for the `cleanup` function when
// native constructors support type parameters.
external SkObjectFinalizationRegistry(Function cleanup);
external factory SkObjectFinalizationRegistry(Function cleanup);
}

extension SkObjectFinalizationRegistryExtension on SkObjectFinalizationRegistry {
external void register(Object ckObject, Object skObject);
}

Expand All @@ -2422,7 +2451,10 @@ void debugResetBrowserSupportsFinalizationRegistry() {
}

@JS()
class SkData {
@staticInterop
class SkData {}

extension SkDataExtension on SkData {
external int size();
external bool isEmpty();
external Uint8List bytes();
Expand All @@ -2431,6 +2463,7 @@ class SkData {

@JS()
@anonymous
@staticInterop
class SkImageInfo {
external factory SkImageInfo({
required int width,
Expand All @@ -2439,6 +2472,9 @@ class SkImageInfo {
required SkAlphaType alphaType,
required ColorSpace colorSpace,
});
}

extension SkImageInfoExtension on SkImageInfo {
external SkAlphaType get alphaType;
external ColorSpace get colorSpace;
external SkColorType get colorType;
Expand All @@ -2455,6 +2491,7 @@ class SkImageInfo {

@JS()
@anonymous
@staticInterop
class SkPartialImageInfo {
external factory SkPartialImageInfo({
required int width,
Expand All @@ -2463,6 +2500,9 @@ class SkPartialImageInfo {
required SkAlphaType alphaType,
required ColorSpace colorSpace,
});
}

extension SkPartialImageInfoExtension on SkPartialImageInfo {
external SkAlphaType get alphaType;
external ColorSpace get colorSpace;
external SkColorType get colorType;
Expand Down

0 comments on commit 1d6874e

Please sign in to comment.