Move snapshot to //flutter/lib/snapshot (flutter/engine#2905)
This change disentangles the build for the snapshotter from the main engine build. Also, we now have all the Dart files for dart:ui in the same directory.
This commit is contained in:
115
engine/src/flutter/lib/snapshot/BUILD.gn
Normal file
115
engine/src/flutter/lib/snapshot/BUILD.gn
Normal file
@@ -0,0 +1,115 @@
|
||||
# Copyright 2016 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.
|
||||
|
||||
import("//flutter/lib/jni/dart_jni.gni")
|
||||
import("//flutter/lib/snapshot/toolchain.gni")
|
||||
import("//flutter/lib/ui/dart_ui.gni")
|
||||
import("//flutter/lib/ui/dart_ui.gni")
|
||||
import("//mojo/dart/packages/mojo/sdk_ext_sources.gni")
|
||||
|
||||
bindings_output_dir = "$root_gen_dir/sky/bindings"
|
||||
|
||||
copy("generate_dart_ui") {
|
||||
sources = dart_ui_files
|
||||
|
||||
outputs = [
|
||||
"$bindings_output_dir/dart_ui/{{source_file_part}}",
|
||||
]
|
||||
}
|
||||
|
||||
copy("generate_dart_jni") {
|
||||
sources = dart_jni_files
|
||||
|
||||
outputs = [
|
||||
"$bindings_output_dir/dart_jni/{{source_file_part}}",
|
||||
]
|
||||
}
|
||||
|
||||
action("generate_snapshot_bin") {
|
||||
deps = [
|
||||
"//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
|
||||
":generate_dart_ui",
|
||||
":generate_dart_jni",
|
||||
]
|
||||
inputs = [
|
||||
"//dart/runtime/tools/create_snapshot_bin.py",
|
||||
"snapshot.dart",
|
||||
] + dart_ui_files
|
||||
+ dart_jni_files
|
||||
+ rebase_path(dart_mojo_internal_sdk_sources,
|
||||
"",
|
||||
"//mojo/dart/packages/mojo")
|
||||
vm_isolate_snapshot = "$target_gen_dir/vm_isolate_snapshot.bin"
|
||||
isolate_snapshot = "$target_gen_dir/isolate_snapshot.bin"
|
||||
outputs = [
|
||||
vm_isolate_snapshot,
|
||||
isolate_snapshot,
|
||||
]
|
||||
|
||||
dart_mojo_internal_path =
|
||||
rebase_path("//mojo/dart/packages/mojo/sdk_ext/internal.dart")
|
||||
rebased_dart_ui_path = rebase_path(dart_ui_path)
|
||||
rebased_dart_jni_path = rebase_path(dart_jni_path)
|
||||
|
||||
gen_snapshot_dir =
|
||||
get_label_info("//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
|
||||
"root_out_dir")
|
||||
script = "//dart/runtime/tools/create_snapshot_bin.py"
|
||||
|
||||
args = [
|
||||
"--executable",
|
||||
rebase_path("$gen_snapshot_dir/gen_snapshot"),
|
||||
"--package_root",
|
||||
rebase_path("$root_gen_dir"),
|
||||
"--script",
|
||||
rebase_path("snapshot.dart"),
|
||||
"--vm_output_bin",
|
||||
rebase_path(vm_isolate_snapshot, root_build_dir),
|
||||
"--output_bin",
|
||||
rebase_path(isolate_snapshot, root_build_dir),
|
||||
"--target_os",
|
||||
target_os,
|
||||
"--url_mapping=dart:mojo.internal,$dart_mojo_internal_path",
|
||||
"--url_mapping=dart:ui,$rebased_dart_ui_path",
|
||||
"--url_mapping=dart:jni,$rebased_dart_jni_path",
|
||||
]
|
||||
}
|
||||
|
||||
action("generate_snapshot_file") {
|
||||
deps = [
|
||||
":generate_snapshot_bin",
|
||||
]
|
||||
inputs = [
|
||||
"//dart/runtime/tools/create_snapshot_file.py",
|
||||
"snapshot.c.tmpl",
|
||||
"$target_gen_dir/vm_isolate_snapshot.bin",
|
||||
"$target_gen_dir/isolate_snapshot.bin",
|
||||
]
|
||||
output = "$target_gen_dir/snapshot.c"
|
||||
outputs = [
|
||||
output,
|
||||
]
|
||||
|
||||
script = "//dart/runtime/tools/create_snapshot_file.py"
|
||||
args = [
|
||||
"--vm_input_bin",
|
||||
rebase_path("$target_gen_dir/vm_isolate_snapshot.bin"),
|
||||
"--input_bin",
|
||||
rebase_path("$target_gen_dir/isolate_snapshot.bin"),
|
||||
"--input_cc",
|
||||
rebase_path("snapshot.c.tmpl"),
|
||||
"--output",
|
||||
rebase_path(output),
|
||||
]
|
||||
}
|
||||
|
||||
source_set("snapshot") {
|
||||
sources = [
|
||||
"$target_gen_dir/snapshot.c",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":generate_snapshot_file",
|
||||
]
|
||||
}
|
||||
21
engine/src/flutter/lib/snapshot/snapshot.c.tmpl
Normal file
21
engine/src/flutter/lib/snapshot/snapshot.c.tmpl
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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 <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// The string on the next line will be filled in with the contents of the
|
||||
// generated snapshot binary file for the vm isolate.
|
||||
// This string forms the content of the dart vm isolate snapshot which
|
||||
// is loaded into the vm isolate.
|
||||
const uint8_t kDartVmIsolateSnapshotBuffer[]
|
||||
__attribute__((visibility("default"), aligned(8), used)) = { %s };
|
||||
|
||||
// The string on the next line will be filled in with the contents of the
|
||||
// generated snapshot binary file for a regular dart isolate.
|
||||
// This string forms the content of a regular dart isolate snapshot which
|
||||
// is loaded into an isolate when it is created.
|
||||
const uint8_t kDartIsolateSnapshotBuffer[]
|
||||
__attribute__((visibility("default"), aligned(8), used)) = { %s };
|
||||
16
engine/src/flutter/lib/snapshot/snapshot.dart
Normal file
16
engine/src/flutter/lib/snapshot/snapshot.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:jni';
|
||||
import 'dart:math';
|
||||
import 'dart:mojo.internal';
|
||||
import 'dart:ui';
|
||||
import 'dart:typed_data';
|
||||
32
engine/src/flutter/lib/snapshot/toolchain.gni
Normal file
32
engine/src/flutter/lib/snapshot/toolchain.gni
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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.
|
||||
|
||||
import("//mojo/dart/packages/mojo/sdk_ext_sources.gni")
|
||||
import("//flutter/sky/engine/config.gni")
|
||||
|
||||
dart_host_toolchain = host_toolchain
|
||||
|
||||
# During precompilation, a 64 bit Dart VM cannot generate code for a 32 bit
|
||||
# architecture (and vice-versa). The snapshotter that is running on the host
|
||||
# needs to know about the target architecture and built accordingly.
|
||||
if (target_os == "ios" && !use_ios_simulator) {
|
||||
if (target_cpu == "arm") {
|
||||
dart_host_toolchain = "//build/toolchain/mac:clang_i386"
|
||||
} else if (target_cpu == "arm64") {
|
||||
dart_host_toolchain = "//build/toolchain/mac:clang_x64"
|
||||
} else {
|
||||
assert(false, "Unknown active architecture on iOS")
|
||||
}
|
||||
}
|
||||
|
||||
if (target_os == "android" && flutter_aot) {
|
||||
if (target_cpu == "arm") {
|
||||
if (host_os == "linux") {
|
||||
dart_host_toolchain = "//build/toolchain/linux:clang_x86"
|
||||
}
|
||||
if (host_os == "mac") {
|
||||
dart_host_toolchain = "//build/toolchain/mac:clang_i386"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,15 @@
|
||||
dart_ui_files = [
|
||||
"//flutter/lib/ui/compositing.dart",
|
||||
"//flutter/lib/ui/geometry.dart",
|
||||
"//flutter/lib/ui/hash_codes.dart",
|
||||
"//flutter/lib/ui/hooks.dart",
|
||||
"//flutter/lib/ui/lerp.dart",
|
||||
"//flutter/lib/ui/mojo_services.dart",
|
||||
"//flutter/lib/ui/natives.dart",
|
||||
"//flutter/lib/ui/painting.dart",
|
||||
"//flutter/lib/ui/text.dart",
|
||||
"//flutter/lib/ui/ui.dart",
|
||||
"//flutter/lib/ui/window.dart",
|
||||
]
|
||||
|
||||
dart_ui_path = "//flutter/lib/ui/ui.dart"
|
||||
|
||||
123
engine/src/flutter/lib/ui/hash_codes.dart
Normal file
123
engine/src/flutter/lib/ui/hash_codes.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
class _HashEnd { const _HashEnd(); }
|
||||
const _HashEnd _hashEnd = const _HashEnd();
|
||||
|
||||
/// Combine up to twenty values' hashCodes into one value.
|
||||
///
|
||||
/// If you only need to handle one value's hashCode, then just refer to its
|
||||
/// [hashCode] getter directly.
|
||||
///
|
||||
/// If you need to combine an arbitrary number of values from a List or other
|
||||
/// Iterable, use [hashList]. The output of hashList can be used as one of the
|
||||
/// arguments to this function.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// int hashCode => hashValues(foo, bar, hashList(quux), baz);
|
||||
int hashValues(
|
||||
Object arg01, Object arg02, [ Object arg03 = _hashEnd,
|
||||
Object arg04 = _hashEnd, Object arg05 = _hashEnd, Object arg06 = _hashEnd,
|
||||
Object arg07 = _hashEnd, Object arg08 = _hashEnd, Object arg09 = _hashEnd,
|
||||
Object arg10 = _hashEnd, Object arg11 = _hashEnd, Object arg12 = _hashEnd,
|
||||
Object arg13 = _hashEnd, Object arg14 = _hashEnd, Object arg15 = _hashEnd,
|
||||
Object arg16 = _hashEnd, Object arg17 = _hashEnd, Object arg18 = _hashEnd,
|
||||
Object arg19 = _hashEnd, Object arg20 = _hashEnd ]) {
|
||||
int result = 373;
|
||||
assert(arg01 is! Iterable);
|
||||
result = 37 * result + arg01.hashCode;
|
||||
assert(arg02 is! Iterable);
|
||||
result = 37 * result + arg02.hashCode;
|
||||
if (arg03 != _hashEnd) {
|
||||
assert(arg03 is! Iterable);
|
||||
result = 37 * result + arg03.hashCode;
|
||||
if (arg04 != _hashEnd) {
|
||||
assert(arg04 is! Iterable);
|
||||
result = 37 * result + arg04.hashCode;
|
||||
if (arg05 != _hashEnd) {
|
||||
assert(arg05 is! Iterable);
|
||||
result = 37 * result + arg05.hashCode;
|
||||
if (arg06 != _hashEnd) {
|
||||
assert(arg06 is! Iterable);
|
||||
result = 37 * result + arg06.hashCode;
|
||||
if (arg07 != _hashEnd) {
|
||||
assert(arg07 is! Iterable);
|
||||
result = 37 * result + arg07.hashCode;
|
||||
if (arg08 != _hashEnd) {
|
||||
assert(arg08 is! Iterable);
|
||||
result = 37 * result + arg08.hashCode;
|
||||
if (arg09 != _hashEnd) {
|
||||
assert(arg09 is! Iterable);
|
||||
result = 37 * result + arg09.hashCode;
|
||||
if (arg10 != _hashEnd) {
|
||||
assert(arg10 is! Iterable);
|
||||
result = 37 * result + arg10.hashCode;
|
||||
if (arg11 != _hashEnd) {
|
||||
assert(arg11 is! Iterable);
|
||||
result = 37 * result + arg11.hashCode;
|
||||
if (arg12 != _hashEnd) {
|
||||
assert(arg12 is! Iterable);
|
||||
result = 37 * result + arg12.hashCode;
|
||||
if (arg13 != _hashEnd) {
|
||||
assert(arg13 is! Iterable);
|
||||
result = 37 * result + arg13.hashCode;
|
||||
if (arg14 != _hashEnd) {
|
||||
assert(arg14 is! Iterable);
|
||||
result = 37 * result + arg14.hashCode;
|
||||
if (arg15 != _hashEnd) {
|
||||
assert(arg15 is! Iterable);
|
||||
result = 37 * result + arg15.hashCode;
|
||||
if (arg16 != _hashEnd) {
|
||||
assert(arg16 is! Iterable);
|
||||
result = 37 * result + arg16.hashCode;
|
||||
if (arg17 != _hashEnd) {
|
||||
assert(arg17 is! Iterable);
|
||||
result = 37 * result + arg17.hashCode;
|
||||
if (arg18 != _hashEnd) {
|
||||
assert(arg18 is! Iterable);
|
||||
result = 37 * result + arg18.hashCode;
|
||||
if (arg19 != _hashEnd) {
|
||||
assert(arg19 is! Iterable);
|
||||
result = 37 * result + arg19.hashCode;
|
||||
if (arg20 != _hashEnd) {
|
||||
assert(arg20 is! Iterable);
|
||||
result = 37 * result + arg20.hashCode;
|
||||
// I can see my house from here!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Combine the hashCodes of an arbitrary number of values from an Iterable into
|
||||
/// one value. This function will return the same value if given "null" as if
|
||||
/// given an empty list.
|
||||
int hashList(Iterable<Object> args) {
|
||||
int result = 373;
|
||||
if (args != null) {
|
||||
for (Object arg in args) {
|
||||
assert(arg is! Iterable);
|
||||
result = 37 * result + arg.hashCode;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
54
engine/src/flutter/lib/ui/hooks.dart
Normal file
54
engine/src/flutter/lib/ui/hooks.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
void _updateWindowMetrics(double devicePixelRatio,
|
||||
double width,
|
||||
double height,
|
||||
double top,
|
||||
double right,
|
||||
double bottom,
|
||||
double left) {
|
||||
window
|
||||
.._devicePixelRatio = devicePixelRatio
|
||||
.._size = new Size(width, height)
|
||||
.._padding = new WindowPadding._(
|
||||
top: top, right: right, bottom: bottom, left: left);
|
||||
if (window.onMetricsChanged != null)
|
||||
window.onMetricsChanged();
|
||||
}
|
||||
|
||||
void _updateLocale(String languageCode, String countryCode) {
|
||||
window._locale = new Locale(languageCode, countryCode);
|
||||
if (window.onLocaleChanged != null)
|
||||
window.onLocaleChanged();
|
||||
}
|
||||
|
||||
void _pushRoute(String route) {
|
||||
assert(window._defaultRouteName == null);
|
||||
window._defaultRouteName = route;
|
||||
// TODO(abarth): If we ever start calling _pushRoute other than before main,
|
||||
// we should add a change notification callback.
|
||||
}
|
||||
|
||||
void _popRoute() {
|
||||
if (window.onPopRoute != null)
|
||||
window.onPopRoute();
|
||||
}
|
||||
|
||||
void _dispatchPointerPacket(ByteData serializedPacket) {
|
||||
if (window.onPointerPacket != null)
|
||||
window.onPointerPacket(serializedPacket);
|
||||
}
|
||||
|
||||
void _beginFrame(int microseconds) {
|
||||
if (window.onBeginFrame != null)
|
||||
window.onBeginFrame(new Duration(microseconds: microseconds));
|
||||
}
|
||||
|
||||
void _onAppLifecycleStateChanged(int state) {
|
||||
if (window.onAppLifecycleStateChanged != null)
|
||||
window.onAppLifecycleStateChanged(AppLifecycleState.values[state]);
|
||||
}
|
||||
16
engine/src/flutter/lib/ui/lerp.dart
Normal file
16
engine/src/flutter/lib/ui/lerp.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
/// Linearly interpolate between two numbers.
|
||||
num lerpDouble(num a, num b, double t) {
|
||||
if (a == null && b == null)
|
||||
return null;
|
||||
if (a == null)
|
||||
a = 0.0;
|
||||
if (b == null)
|
||||
b = 0.0;
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
28
engine/src/flutter/lib/ui/mojo_services.dart
Normal file
28
engine/src/flutter/lib/ui/mojo_services.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
/// Mojo handles provided to the application at startup.
|
||||
///
|
||||
/// The application can take ownership of these handles by calling the static
|
||||
/// "take" functions on this object. Once taken, the application is responsible
|
||||
/// for managing the handles.
|
||||
class MojoServices {
|
||||
MojoServices._();
|
||||
|
||||
static int takeRootBundle() native "MojoServices_takeRootBundle";
|
||||
static int takeIncomingServices() native "MojoServices_takeIncomingServices";
|
||||
static int takeOutgoingServices() native "MojoServices_takeOutgoingServices";
|
||||
static int takeShell() native "MojoServices_takeShell";
|
||||
static int takeView() native "MojoServices_takeView";
|
||||
static int takeViewServices() native "MojoServices_takeViewServices";
|
||||
}
|
||||
|
||||
// TODO(abarth): Remove these once clients have migrated to [MojoServices].
|
||||
int takeRootBundleHandle() => MojoServices.takeRootBundle();
|
||||
int takeServicesProvidedByEmbedder() => MojoServices.takeIncomingServices();
|
||||
int takeServicesProvidedToEmbedder() => MojoServices.takeOutgoingServices();
|
||||
int takeShellProxyHandle() => MojoServices.takeShell();
|
||||
int takeViewHandle() => MojoServices.takeView();
|
||||
38
engine/src/flutter/lib/ui/natives.dart
Normal file
38
engine/src/flutter/lib/ui/natives.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
// Corelib 'print' implementation.
|
||||
void _print(arg) {
|
||||
_Logger._printString(arg.toString());
|
||||
}
|
||||
|
||||
class _Logger {
|
||||
static void _printString(String s) native "Logger_PrintString";
|
||||
}
|
||||
|
||||
void _setupHooks() {
|
||||
// Wire up timer implementation that is driven by MojoHandleWatcher.
|
||||
VMLibraryHooks.eventHandlerSendData = MojoHandleWatcher.timer;
|
||||
VMLibraryHooks.timerMillisecondClock = MojoCoreNatives.timerMillisecondClock;
|
||||
}
|
||||
|
||||
void _scheduleMicrotask(void callback()) native "ScheduleMicrotask";
|
||||
String _getBaseURLString() native "GetBaseURLString";
|
||||
Uri _getBaseURL() => Uri.parse(_getBaseURLString());
|
||||
|
||||
// Required for gen_snapshot to work correctly.
|
||||
int _isolateId;
|
||||
|
||||
_getPrintClosure() => _print;
|
||||
_getScheduleMicrotaskClosure() => _scheduleMicrotask;
|
||||
_getGetBaseURLClosure() => _getBaseURL;
|
||||
|
||||
// Though the "main" symbol is not included in any of the libraries imported
|
||||
// above, the builtin library will be included manually during VM setup. This
|
||||
// symbol is only necessary for precompilation. It is marked as a stanalone
|
||||
// entry point into the VM. This prevents the precompiler from tree shaking
|
||||
// away "main"
|
||||
_getMainClosure() => main;
|
||||
713
engine/src/flutter/lib/ui/text.dart
Normal file
713
engine/src/flutter/lib/ui/text.dart
Normal file
@@ -0,0 +1,713 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
/// Whether to slant the glyphs in the font
|
||||
enum FontStyle {
|
||||
/// Use the upright glyphs
|
||||
normal,
|
||||
|
||||
/// Use glyphs designed for slanting
|
||||
italic,
|
||||
}
|
||||
|
||||
/// The thickness of the glyphs used to draw the text
|
||||
class FontWeight {
|
||||
const FontWeight._(this.index);
|
||||
|
||||
/// The encoded integer value of this font weight.
|
||||
final int index;
|
||||
|
||||
/// Thin, the least thick
|
||||
static const FontWeight w100 = const FontWeight._(0);
|
||||
|
||||
/// Extra-light
|
||||
static const FontWeight w200 = const FontWeight._(1);
|
||||
|
||||
/// Light
|
||||
static const FontWeight w300 = const FontWeight._(2);
|
||||
|
||||
/// Normal / regular / plain
|
||||
static const FontWeight w400 = const FontWeight._(3);
|
||||
|
||||
/// Medium
|
||||
static const FontWeight w500 = const FontWeight._(4);
|
||||
|
||||
/// Semi-bold
|
||||
static const FontWeight w600 = const FontWeight._(5);
|
||||
|
||||
/// Bold
|
||||
static const FontWeight w700 = const FontWeight._(6);
|
||||
|
||||
/// Extra-bold
|
||||
static const FontWeight w800 = const FontWeight._(7);
|
||||
|
||||
/// Black, the most thick
|
||||
static const FontWeight w900 = const FontWeight._(8);
|
||||
|
||||
/// The default font weight.
|
||||
static const FontWeight normal = w400;
|
||||
|
||||
/// A commonly used font weight that is heavier than normal.
|
||||
static const FontWeight bold = w700;
|
||||
|
||||
/// A list of all the font weights.
|
||||
static const List<FontWeight> values = const [
|
||||
w100, w200, w300, w400, w500, w600, w700, w800, w900
|
||||
];
|
||||
|
||||
/// Linearly interpolates between two font weights.
|
||||
///
|
||||
/// Rather than using fractional weights, the interpolation rounds to the
|
||||
/// nearest weight.
|
||||
static FontWeight lerp(FontWeight begin, FontWeight end, double t) {
|
||||
return values[lerpDouble(begin?.index ?? normal.index, end?.index ?? normal.index, t.clamp(0.0, 1.0)).round()];
|
||||
}
|
||||
|
||||
String toString() {
|
||||
return const <int, String>{
|
||||
0: 'FontWeight.w100',
|
||||
1: 'FontWeight.w200',
|
||||
2: 'FontWeight.w300',
|
||||
3: 'FontWeight.w400',
|
||||
4: 'FontWeight.w500',
|
||||
5: 'FontWeight.w600',
|
||||
6: 'FontWeight.w700',
|
||||
7: 'FontWeight.w800',
|
||||
8: 'FontWeight.w900',
|
||||
}[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether to align text horizontally
|
||||
enum TextAlign {
|
||||
/// Align the text on the left edge of the container
|
||||
left,
|
||||
|
||||
/// Align the text on the right edge of the container
|
||||
right,
|
||||
|
||||
/// Align the text in the center of the container
|
||||
center
|
||||
}
|
||||
|
||||
/// A horizontal line used for aligning text
|
||||
enum TextBaseline {
|
||||
// The horizontal line used to align the bottom of glyphs for alphabetic characters
|
||||
alphabetic,
|
||||
|
||||
// The horizontal line used to align ideographic characters
|
||||
ideographic
|
||||
}
|
||||
|
||||
/// A linear decoration to draw near the text
|
||||
class TextDecoration {
|
||||
const TextDecoration._(this._mask);
|
||||
|
||||
/// Creates a decoration that paints the union of all the given decorations.
|
||||
factory TextDecoration.combine(List<TextDecoration> decorations) {
|
||||
int mask = 0;
|
||||
for (TextDecoration decoration in decorations)
|
||||
mask |= decoration._mask;
|
||||
return new TextDecoration._(mask);
|
||||
}
|
||||
|
||||
final int _mask;
|
||||
|
||||
/// Whether this decoration will paint at least as much decoration as the given decoration.
|
||||
bool contains(TextDecoration other) {
|
||||
return (_mask | other._mask) == _mask;
|
||||
}
|
||||
|
||||
/// Do not draw a decoration
|
||||
static const TextDecoration none = const TextDecoration._(0x0);
|
||||
|
||||
/// Draw a line underneath each line of text
|
||||
static const TextDecoration underline = const TextDecoration._(0x1);
|
||||
|
||||
/// Draw a line above each line of text
|
||||
static const TextDecoration overline = const TextDecoration._(0x2);
|
||||
|
||||
/// Draw a line through each line of text
|
||||
static const TextDecoration lineThrough = const TextDecoration._(0x4);
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other is! TextDecoration)
|
||||
return false;
|
||||
final TextDecoration typedOther = other;
|
||||
return _mask == typedOther._mask;
|
||||
}
|
||||
|
||||
int get hashCode => _mask.hashCode;
|
||||
|
||||
String toString() {
|
||||
if (_mask == 0)
|
||||
return 'TextDecoration.none';
|
||||
List<String> values = <String>[];
|
||||
if (_mask & underline._mask != 0)
|
||||
values.add('underline');
|
||||
if (_mask & overline._mask != 0)
|
||||
values.add('overline');
|
||||
if (_mask & lineThrough._mask != 0)
|
||||
values.add('lineThrough');
|
||||
if (values.length == 1)
|
||||
return 'TextDecoration.${values[0]}';
|
||||
return 'TextDecoration.combine([${values.join(", ")}])';
|
||||
}
|
||||
}
|
||||
|
||||
/// The style in which to draw a text decoration
|
||||
enum TextDecorationStyle {
|
||||
/// Draw a solid line
|
||||
solid,
|
||||
|
||||
/// Draw two lines
|
||||
double,
|
||||
|
||||
/// Draw a dotted line
|
||||
dotted,
|
||||
|
||||
/// Draw a dashed line
|
||||
dashed,
|
||||
|
||||
/// Draw a sinusoidal line
|
||||
wavy
|
||||
}
|
||||
|
||||
// This encoding must match the C++ version of ParagraphBuilder::pushStyle.
|
||||
//
|
||||
// The encoded array buffer has 7 elements.
|
||||
//
|
||||
// - Element 0: A bit field where the ith bit indicates wheter the ith element
|
||||
// has a non-null value. Bits 7 to 11 indicate whether |fontFamily|,
|
||||
// |fontSize|, |letterSpacing|, |wordSpacing|, and |height| are non-null,
|
||||
// respectively. Bit 0 is unused.
|
||||
//
|
||||
// - Element 1: The |color| in ARGB with 8 bits per channel.
|
||||
//
|
||||
// - Element 2: A bit field indicating which text decorations are present in
|
||||
// the |textDecoration| list. The ith bit is set if there's a TextDecoration
|
||||
// with enum index i in the list.
|
||||
//
|
||||
// - Element 3: The |decorationColor| in ARGB with 8 bits per channel.
|
||||
//
|
||||
// - Element 4: The bit field of the |decorationStyle|.
|
||||
//
|
||||
// - Element 5: The index of the |fontWeight|.
|
||||
//
|
||||
// - Element 6: The enum index of the |fontStyle|.
|
||||
//
|
||||
Int32List _encodeTextStyle(Color color,
|
||||
TextDecoration decoration,
|
||||
Color decorationColor,
|
||||
TextDecorationStyle decorationStyle,
|
||||
FontWeight fontWeight,
|
||||
FontStyle fontStyle,
|
||||
String fontFamily,
|
||||
double fontSize,
|
||||
double letterSpacing,
|
||||
double wordSpacing,
|
||||
double height) {
|
||||
Int32List result = new Int32List(7);
|
||||
if (color != null) {
|
||||
result[0] |= 1 << 1;
|
||||
result[1] = color.value;
|
||||
}
|
||||
if (decoration != null) {
|
||||
result[0] |= 1 << 2;
|
||||
result[2] = decoration._mask;
|
||||
}
|
||||
if (decorationColor != null) {
|
||||
result[0] |= 1 << 3;
|
||||
result[3] = decorationColor.value;
|
||||
}
|
||||
if (decorationStyle != null) {
|
||||
result[0] |= 1 << 4;
|
||||
result[4] = decorationStyle.index;
|
||||
}
|
||||
if (fontWeight != null) {
|
||||
result[0] |= 1 << 5;
|
||||
result[5] = fontWeight.index;
|
||||
}
|
||||
if (fontStyle != null) {
|
||||
result[0] |= 1 << 6;
|
||||
result[6] = fontStyle.index;
|
||||
}
|
||||
if (fontFamily != null) {
|
||||
result[0] |= 1 << 7;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (fontSize != null) {
|
||||
result[0] |= 1 << 8;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (letterSpacing != null) {
|
||||
result[0] |= 1 << 9;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (wordSpacing != null) {
|
||||
result[0] |= 1 << 10;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (height != null) {
|
||||
result[0] |= 1 << 11;
|
||||
// Passed separately to native.
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// An opaque object that determines the size, position, and rendering of text.
|
||||
class TextStyle {
|
||||
/// Creates a new TextStyle object.
|
||||
///
|
||||
/// * [color] The color to use when painting the text.
|
||||
/// * [decoration] The decorations to paint near the text (e.g., an underline).
|
||||
/// * [decorationColor] The color in which to paint the text decorations.
|
||||
/// * [decorationStyle] The style in which to paint the text decorations (e.g., dashed).
|
||||
/// * [fontWeight] The typeface thickness to use when painting the text (e.g., bold).
|
||||
/// * [fontStyle] The typeface variant to use when drawing the letters (e.g., italics).
|
||||
/// * [fontFamily] The name of the font to use when painting the text (e.g., Roboto).
|
||||
/// * [fontSize] The size of gyphs (in logical pixels) to use when painting the text.
|
||||
/// * [letterSpacing] The amount of space (in logical pixels) to add between each letter.
|
||||
/// * [wordSpacing] The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between each word).
|
||||
/// * [height] The height of this text span, as a multiple of the font size.
|
||||
TextStyle({
|
||||
Color color,
|
||||
TextDecoration decoration,
|
||||
Color decorationColor,
|
||||
TextDecorationStyle decorationStyle,
|
||||
FontWeight fontWeight,
|
||||
FontStyle fontStyle,
|
||||
String fontFamily,
|
||||
double fontSize,
|
||||
double letterSpacing,
|
||||
double wordSpacing,
|
||||
double height
|
||||
}) : _encoded = _encodeTextStyle(color,
|
||||
decoration,
|
||||
decorationColor,
|
||||
decorationStyle,
|
||||
fontWeight,
|
||||
fontStyle,
|
||||
fontFamily,
|
||||
fontSize,
|
||||
letterSpacing,
|
||||
wordSpacing,
|
||||
height),
|
||||
_fontFamily = fontFamily ?? '',
|
||||
_fontSize = fontSize,
|
||||
_letterSpacing = letterSpacing,
|
||||
_wordSpacing = wordSpacing,
|
||||
_height = height;
|
||||
|
||||
final Int32List _encoded;
|
||||
final String _fontFamily;
|
||||
final double _fontSize;
|
||||
final double _letterSpacing;
|
||||
final double _wordSpacing;
|
||||
final double _height;
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other is! TextStyle)
|
||||
return false;
|
||||
final TextStyle typedOther = other;
|
||||
if (_fontFamily != typedOther._fontFamily ||
|
||||
_fontSize != typedOther._fontSize ||
|
||||
_letterSpacing != typedOther._letterSpacing ||
|
||||
_wordSpacing != typedOther._wordSpacing ||
|
||||
_height != typedOther._height)
|
||||
return false;
|
||||
for (int index = 0; index < _encoded.length; index += 1) {
|
||||
if (_encoded[index] != typedOther._encoded[index])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int get hashCode => hashValues(hashList(_encoded), _fontFamily, _fontSize, _letterSpacing, _wordSpacing, _height);
|
||||
|
||||
String toString() {
|
||||
return 'TextStyle(${_encoded[0]}|'
|
||||
'color: ${ _encoded[0] & 0x001 == 0x001 ? new Color(_encoded[1]) : "unspecified"}, '
|
||||
'decoration: ${ _encoded[0] & 0x002 == 0x002 ? new TextDecoration._(_encoded[2]) : "unspecified"}, '
|
||||
'decorationColor: ${_encoded[0] & 0x004 == 0x004 ? new Color(_encoded[3]) : "unspecified"}, '
|
||||
'decorationStyle: ${_encoded[0] & 0x008 == 0x008 ? TextDecorationStyle.values[_encoded[4]] : "unspecified"}, '
|
||||
'fontWeight: ${ _encoded[0] & 0x010 == 0x010 ? FontWeight.values[_encoded[5]] : "unspecified"}, '
|
||||
'fontStyle: ${ _encoded[0] & 0x020 == 0x020 ? FontStyle.values[_encoded[6]] : "unspecified"}, '
|
||||
'fontFamily: ${ _encoded[0] & 0x040 == 0x040 ? _fontFamily : "unspecified"}, '
|
||||
'fontSize: ${ _encoded[0] & 0x080 == 0x080 ? _fontSize : "unspecified"}, '
|
||||
'letterSpacing: ${ _encoded[0] & 0x100 == 0x100 ? "${_letterSpacing}x" : "unspecified"}, '
|
||||
'wordSpacing: ${ _encoded[0] & 0x200 == 0x200 ? "${_wordSpacing}x" : "unspecified"}, '
|
||||
'height: ${ _encoded[0] & 0x400 == 0x400 ? "${_height}x" : "unspecified"}'
|
||||
')';
|
||||
}
|
||||
}
|
||||
|
||||
// This encoding must match the C++ version ParagraphBuilder::build.
|
||||
//
|
||||
// The encoded array buffer has 3 elements.
|
||||
//
|
||||
// - Element 0: A bit field where the ith bit indicates wheter the ith element
|
||||
// has a non-null value. Bit 3 indicates whether |lineHeight| is non-null.
|
||||
// Bit 0 is unused.
|
||||
//
|
||||
// - Element 1: The enum index of the |textAlign|.
|
||||
//
|
||||
// - Element 2: The enum index of the |textBaseline|.
|
||||
//
|
||||
Int32List _encodeParagraphStyle(TextAlign textAlign,
|
||||
TextBaseline textBaseline,
|
||||
FontWeight fontWeight,
|
||||
FontStyle fontStyle,
|
||||
String fontFamily,
|
||||
double fontSize,
|
||||
double lineHeight) {
|
||||
Int32List result = new Int32List(5);
|
||||
if (textAlign != null) {
|
||||
result[0] |= 1 << 1;
|
||||
result[1] = textAlign.index;
|
||||
}
|
||||
if (textBaseline != null) {
|
||||
result[0] |= 1 << 2;
|
||||
result[2] = textBaseline.index;
|
||||
}
|
||||
if (fontWeight != null) {
|
||||
result[0] |= 1 << 3;
|
||||
result[3] = fontWeight.index;
|
||||
}
|
||||
if (fontStyle != null) {
|
||||
result[0] |= 1 << 4;
|
||||
result[4] = fontStyle.index;
|
||||
}
|
||||
if (fontFamily != null) {
|
||||
result[0] |= 1 << 5;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (fontSize != null) {
|
||||
result[0] |= 1 << 6;
|
||||
// Passed separately to native.
|
||||
}
|
||||
if (lineHeight != null) {
|
||||
result[0] |= 1 << 7;
|
||||
// Passed separately to native.
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// An opaque object that determines the position of lines within a paragraph of text.
|
||||
class ParagraphStyle {
|
||||
/// Creates a new ParagraphStyle object.
|
||||
///
|
||||
/// * [textAlign] .
|
||||
/// * [textBaseline] .
|
||||
/// * [lineHeight] .
|
||||
ParagraphStyle({
|
||||
TextAlign textAlign,
|
||||
TextBaseline textBaseline,
|
||||
FontWeight fontWeight,
|
||||
FontStyle fontStyle,
|
||||
String fontFamily,
|
||||
double fontSize,
|
||||
double lineHeight
|
||||
}) : _encoded = _encodeParagraphStyle(textAlign,
|
||||
textBaseline,
|
||||
fontWeight,
|
||||
fontStyle,
|
||||
fontFamily,
|
||||
fontSize,
|
||||
lineHeight),
|
||||
_fontFamily = fontFamily,
|
||||
_fontSize = fontSize,
|
||||
_lineHeight = lineHeight;
|
||||
|
||||
final Int32List _encoded;
|
||||
final String _fontFamily;
|
||||
final double _fontSize;
|
||||
final double _lineHeight;
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other is! ParagraphStyle)
|
||||
return false;
|
||||
final ParagraphStyle typedOther = other;
|
||||
if ( _fontFamily != typedOther._fontFamily ||
|
||||
_fontSize != typedOther._fontSize ||
|
||||
_lineHeight != typedOther._lineHeight)
|
||||
return false;
|
||||
for (int index = 0; index < _encoded.length; index += 1) {
|
||||
if (_encoded[index] != typedOther._encoded[index])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int get hashCode => hashValues(hashList(_encoded), _lineHeight);
|
||||
|
||||
String toString() {
|
||||
return 'ParagraphStyle('
|
||||
'textAlign: ${ _encoded[0] & 0x001 == 0x001 ? TextAlign.values[_encoded[1]] : "unspecified"}, '
|
||||
'textBaseline: ${_encoded[0] & 0x002 == 0x002 ? TextBaseline.values[_encoded[2]] : "unspecified"}, '
|
||||
'fontWeight: ${ _encoded[0] & 0x002 == 0x002 ? FontWeight.values[_encoded[5]] : "unspecified"}, '
|
||||
'fontStyle: ${ _encoded[0] & 0x004 == 0x004 ? FontStyle.values[_encoded[6]] : "unspecified"}, '
|
||||
'fontFamily: ${ _encoded[0] & 0x008 == 0x008 ? _fontFamily : "unspecified"}, '
|
||||
'fontSize: ${ _encoded[0] & 0x010 == 0x010 ? _fontSize : "unspecified"}, '
|
||||
'lineHeight: ${ _encoded[0] & 0x020 == 0x020 ? "${_lineHeight}x" : "unspecified"}'
|
||||
')';
|
||||
}
|
||||
}
|
||||
|
||||
/// A direction in which text flows.
|
||||
enum TextDirection {
|
||||
/// The text flows from right to left (e.g. Arabic, Hebrew).
|
||||
rtl,
|
||||
|
||||
/// The text flows from left to right (e.g., English, French).
|
||||
ltr
|
||||
}
|
||||
|
||||
/// A rectangle enclosing a run of text.
|
||||
class TextBox {
|
||||
const TextBox.fromLTRBD(
|
||||
this.left,
|
||||
this.top,
|
||||
this.right,
|
||||
this.bottom,
|
||||
this.direction
|
||||
);
|
||||
|
||||
TextBox._(
|
||||
this.left,
|
||||
this.top,
|
||||
this.right,
|
||||
this.bottom,
|
||||
int directionIndex
|
||||
) : direction = TextDirection.values[directionIndex];
|
||||
|
||||
/// The left edge of the text box, irrespective of direction.
|
||||
final double left;
|
||||
|
||||
/// The top edge of the text box.
|
||||
final double top;
|
||||
|
||||
/// The right edge of the text box, irrespective of direction.
|
||||
final double right;
|
||||
|
||||
/// The bottom edge of the text box.
|
||||
final double bottom;
|
||||
|
||||
/// The direction in which text inside this box flows.
|
||||
final TextDirection direction;
|
||||
|
||||
/// Returns a rect of the same size as this box.
|
||||
Rect toRect() => new Rect.fromLTRB(left, top, right, bottom);
|
||||
|
||||
/// The left edge of the box for ltr text; the right edge of the box for rtl text.
|
||||
double get start {
|
||||
return (direction == TextDirection.ltr) ? left : right;
|
||||
}
|
||||
|
||||
/// The right edge of the box for ltr text; the left edge of the box for rtl text.
|
||||
double get end {
|
||||
return (direction == TextDirection.ltr) ? right : left;
|
||||
}
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other is! TextBox)
|
||||
return false;
|
||||
final TextBox typedOther = other;
|
||||
return typedOther.left == left
|
||||
&& typedOther.top == top
|
||||
&& typedOther.right == right
|
||||
&& typedOther.bottom == bottom
|
||||
&& typedOther.direction == direction;
|
||||
}
|
||||
|
||||
int get hashCode => hashValues(left, top, right, bottom, direction);
|
||||
|
||||
String toString() => 'TextBox.fromLTRBD(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)}, $direction)';
|
||||
}
|
||||
|
||||
/// Whether a [TextPosition] is visually upstream or downstream of its offset.
|
||||
///
|
||||
/// For example, when a text position exists at a line break, a single offset has
|
||||
/// two visual positions, one prior to the line break (at the end of the first
|
||||
/// line) and one after the line break (at the start of the second line). A text
|
||||
/// affinity disambiguates between those cases. (Something similar happens with
|
||||
/// between runs of bidirectional text.)
|
||||
enum TextAffinity {
|
||||
/// The position has affinity for the upstream side of the text position.
|
||||
///
|
||||
/// For example, if the offset of the text position is a line break, the
|
||||
/// position represents the end of the first line.
|
||||
upstream,
|
||||
|
||||
/// The position has affinity for the downstream side of the text position.
|
||||
///
|
||||
/// For example, if the offset of the text position is a line break, the
|
||||
/// position represents the start of the second line.
|
||||
downstream
|
||||
}
|
||||
|
||||
/// A visual position in a string of text.
|
||||
class TextPosition {
|
||||
const TextPosition({ this.offset, this.affinity: TextAffinity.downstream });
|
||||
|
||||
/// The index of the character just prior to the position.
|
||||
final int offset;
|
||||
|
||||
/// If the offset has more than one visual location (e.g., occurs at a line
|
||||
/// break), which of the two locations is represented by this position.
|
||||
final TextAffinity affinity;
|
||||
|
||||
String toString() {
|
||||
return '$runtimeType(offset: $offset, affinity: $affinity)';
|
||||
}
|
||||
}
|
||||
|
||||
/// Layout constraints for [Paragraph] objects.
|
||||
///
|
||||
/// Instances of this class are typically used with [Paragraph.layout].
|
||||
class ParagraphConstraints {
|
||||
/// Creates constraints for laying out a pargraph.
|
||||
///
|
||||
/// The [width] argument must not be null.
|
||||
ParagraphConstraints({ this.width }) {
|
||||
assert(width != null);
|
||||
}
|
||||
|
||||
/// The width the paragraph should use whey computing the positions of glyphs.
|
||||
///
|
||||
/// If possible, the paragraph will select a soft line break prior to reaching
|
||||
/// this width. If no soft line break is available, the paragraph will select
|
||||
/// a hard line break prior to reaching this width.
|
||||
///
|
||||
/// This width will also be used for positioning glyphs with [TextAlign].
|
||||
final double width;
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (other is! ParagraphConstraints)
|
||||
return false;
|
||||
final ParagraphConstraints typedOther = other;
|
||||
return typedOther.width == width;
|
||||
}
|
||||
|
||||
int get hashCode => width.hashCode;
|
||||
|
||||
String toString() => 'ParagraphConstraints(width: $width)';
|
||||
}
|
||||
|
||||
/// A paragraph of text.
|
||||
///
|
||||
/// A paragraph retains the size and position of each glyph in the text and can
|
||||
/// be efficiently resized and painted.
|
||||
///
|
||||
/// To create a Paragraph object, use a [ParagraphBuilder].
|
||||
///
|
||||
/// Paragraph objects can be displayed on a [Canvas] using the
|
||||
/// [Canvas.drawParagraph] method.
|
||||
abstract class Paragraph extends NativeFieldWrapperClass2 {
|
||||
/// Creates an uninitialized Paragraph object.
|
||||
///
|
||||
/// Calling the Paragraph constructor directly will not create a useable
|
||||
/// object. To create a Paragraph object, use a [ParagraphBuilder].
|
||||
Paragraph(); // (this constructor is here just so we can document it)
|
||||
|
||||
/// The amount of horizontal space this paragraph occupies.
|
||||
///
|
||||
/// Valid only after [layout] has been called.
|
||||
double get width native "Paragraph_width";
|
||||
|
||||
/// The amount of vertical space this paragraph occupies.
|
||||
///
|
||||
/// Valid only after [layout] has been called.
|
||||
double get height native "Paragraph_height";
|
||||
|
||||
/// The minimum width that this paragraph could be without failing to paint
|
||||
/// its contents within itself.
|
||||
///
|
||||
/// Valid only after [layout] has been called.
|
||||
double get minIntrinsicWidth native "Paragraph_minIntrinsicWidth";
|
||||
|
||||
/// Returns the smallest width beyond which increasing the width never
|
||||
/// decreases the height.
|
||||
///
|
||||
/// Valid only after [layout] has been called.
|
||||
double get maxIntrinsicWidth native "Paragraph_maxIntrinsicWidth";
|
||||
|
||||
/// The distance from the top of the paragraph to the alphabetic
|
||||
/// baseline of the first line, in logical pixels.
|
||||
double get alphabeticBaseline native "Paragraph_alphabeticBaseline";
|
||||
|
||||
/// The distance from the top of the paragraph to the ideographic
|
||||
/// baseline of the first line, in logical pixels.
|
||||
double get ideographicBaseline native "Paragraph_ideographicBaseline";
|
||||
|
||||
/// Computes the size and position of each glyph in the paragraph.
|
||||
void layout(ParagraphConstraints constraints) => _layout(constraints.width);
|
||||
void _layout(double width) native "Paragraph_layout";
|
||||
|
||||
/// Returns a list of text boxes that enclose the given text range.
|
||||
List<TextBox> getBoxesForRange(int start, int end) native "Paragraph_getRectsForRange";
|
||||
|
||||
/// Returns the text position closest to the given offset.
|
||||
TextPosition getPositionForOffset(Offset offset) {
|
||||
List<int> encoded = _getPositionForOffset(offset.dx, offset.dy);
|
||||
return new TextPosition(offset: encoded[0], affinity: TextAffinity.values[encoded[1]]);
|
||||
}
|
||||
List<int> _getPositionForOffset(double dx, double dy) native "Paragraph_getPositionForOffset";
|
||||
|
||||
/// Returns the [start, end] of the word at the given offset. Characters not
|
||||
/// part of a word, such as spaces, symbols, and punctuation, have word breaks
|
||||
/// on both sides. In such cases, this method will return [offset, offset+1].
|
||||
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
|
||||
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
|
||||
List<int> getWordBoundary(int offset) native "Paragraph_getWordBoundary";
|
||||
|
||||
// Redirecting the paint function in this way solves some dependency problems
|
||||
// in the C++ code. If we straighten out the C++ dependencies, we can remove
|
||||
// this indirection.
|
||||
void _paint(Canvas canvas, double x, double y) native "Paragraph_paint";
|
||||
}
|
||||
|
||||
/// Builds a [Paragraph] containing text with the given styling information.
|
||||
class ParagraphBuilder extends NativeFieldWrapperClass2 {
|
||||
/// Creates a [ParagraphBuilder] object, which is used to create a
|
||||
/// [Paragraph].
|
||||
ParagraphBuilder() { _constructor(); }
|
||||
void _constructor() native "ParagraphBuilder_constructor";
|
||||
|
||||
/// Applies the given style to the added text until [pop] is called.
|
||||
///
|
||||
/// See [pop] for details.
|
||||
void pushStyle(TextStyle style) => _pushStyle(style._encoded, style._fontFamily, style._fontSize, style._letterSpacing, style._wordSpacing, style._height);
|
||||
void _pushStyle(Int32List encoded, String fontFamily, double fontSize, double letterSpacing, double wordSpacing, double height) native "ParagraphBuilder_pushStyle";
|
||||
|
||||
/// Ends the effect of the most recent call to [pushStyle].
|
||||
///
|
||||
/// Internally, the paragraph builder maintains a stack of text styles. Text
|
||||
/// added to the paragraph is affected by all the styles in the stack. Calling
|
||||
/// [pop] removes the topmost style in the stack, leaving the remaining styles
|
||||
/// in effect.
|
||||
void pop() native "ParagraphBuilder_pop";
|
||||
|
||||
/// Adds the given text to the paragraph.
|
||||
///
|
||||
/// The text will be styled according to the current stack of text styles.
|
||||
void addText(String text) native "ParagraphBuilder_addText";
|
||||
|
||||
/// Applies the given paragraph style and returns a Paragraph containing the added text and associated styling.
|
||||
///
|
||||
/// After calling this function, the paragraph builder object is invalid and
|
||||
/// cannot be used further.
|
||||
Paragraph build(ParagraphStyle style) => _build(style._encoded, style._fontFamily, style._fontSize, style._lineHeight);
|
||||
Paragraph _build(Int32List encoded, String fontFamily, double fontSize, double lineHeight) native "ParagraphBuilder_build";
|
||||
}
|
||||
189
engine/src/flutter/lib/ui/window.dart
Normal file
189
engine/src/flutter/lib/ui/window.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
// 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.
|
||||
|
||||
part of dart_ui;
|
||||
|
||||
/// Signature of callbacks that have no arguments and return no data.
|
||||
typedef void VoidCallback();
|
||||
|
||||
/// Signature for [Window.onBeginFrame].
|
||||
typedef void FrameCallback(Duration duration);
|
||||
|
||||
/// Signature for [Window.onPointerPacket].
|
||||
typedef void PointerPacketCallback(ByteData serializedPacket);
|
||||
|
||||
/// Signature for [Window.onAppLifecycleStateChanged].
|
||||
typedef void AppLifecycleStateCallback(AppLifecycleState state);
|
||||
|
||||
/// States that an application can be in.
|
||||
enum AppLifecycleState {
|
||||
// These values must match the order of the values of
|
||||
// AppLifecycleState in sky_engine.mojom
|
||||
|
||||
/// The application is not currently visible to the user. When the
|
||||
/// application is in this state, the engine will not call the
|
||||
/// [onBeginFrame] callback.
|
||||
paused,
|
||||
|
||||
/// The application is visible to the user.
|
||||
resumed,
|
||||
}
|
||||
|
||||
/// A representation of distances for each of the four edges of a rectangle,
|
||||
/// used to encode the padding that applications should place around their user
|
||||
/// interface, as exposed by [Window.padding].
|
||||
///
|
||||
/// For a generic class that represents distances around a rectangle, see the
|
||||
/// [EdgeDims] class.
|
||||
class WindowPadding {
|
||||
const WindowPadding._({ this.left, this.top, this.right, this.bottom });
|
||||
|
||||
final double left;
|
||||
final double top;
|
||||
final double right;
|
||||
final double bottom;
|
||||
|
||||
static const WindowPadding zero = const WindowPadding._(left: 0.0, top: 0.0, right: 0.0, bottom: 0.0);
|
||||
}
|
||||
|
||||
/// An identifier used to select a user's language and formatting preferences,
|
||||
/// consisting of a language and a country. This is a subset of locale
|
||||
/// identifiers as defined by BCP 47.
|
||||
class Locale {
|
||||
/// Creates a new Locale object. The first argument is the
|
||||
/// primary language subtag, the second is the region subtag.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// const Locale swissFrench = const Locale('fr', 'CH');
|
||||
/// const Locale canadianFrench = const Locale('fr', 'CA');
|
||||
const Locale(this.languageCode, this.countryCode);
|
||||
|
||||
/// The primary language subtag for the locale.
|
||||
final String languageCode;
|
||||
|
||||
/// The region subtag for the locale.
|
||||
final String countryCode;
|
||||
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other is! Locale)
|
||||
return false;
|
||||
final Locale typedOther = other;
|
||||
return languageCode == typedOther.languageCode
|
||||
&& countryCode == typedOther.countryCode;
|
||||
}
|
||||
|
||||
int get hashCode {
|
||||
int result = 373;
|
||||
result = 37 * result + languageCode.hashCode;
|
||||
result = 37 * result + countryCode.hashCode;
|
||||
return result;
|
||||
}
|
||||
|
||||
String toString() => '${languageCode}_$countryCode';
|
||||
}
|
||||
|
||||
/// The most basic interface to the host operating system's user interface.
|
||||
///
|
||||
/// There is a single Window instance in the system, which you can
|
||||
/// obtain from the [window] property.
|
||||
class Window {
|
||||
Window._();
|
||||
|
||||
/// The number of device pixels for each logical pixel. This number might not
|
||||
/// be a power of two. Indeed, it might not even be an integer. For example,
|
||||
/// the Nexus 6 has a device pixel ratio of 3.5.
|
||||
double get devicePixelRatio => _devicePixelRatio;
|
||||
double _devicePixelRatio = 1.0;
|
||||
|
||||
/// The dimensions of the rectangle into which the application will be drawn,
|
||||
/// in logical pixels.
|
||||
///
|
||||
/// Logical pixels are roughly the same visual size across devices. Physical
|
||||
/// pixels are the size of the actual hardware pixels on the device. The
|
||||
/// number of physical pixels per logical pixel is described by the
|
||||
/// [devicePixelRatio].
|
||||
Size get size => _size;
|
||||
Size _size = Size.zero;
|
||||
|
||||
/// The number of pixels on each side of the display rectangle into which the
|
||||
/// application can render, but over which the operating system will likely
|
||||
/// place system UI (such as the Android system notification area), or which
|
||||
/// might be rendered outside of the physical display (e.g. overscan regions
|
||||
/// on television screens).
|
||||
WindowPadding get padding => _padding;
|
||||
WindowPadding _padding = WindowPadding.zero;
|
||||
|
||||
/// A callback that is invoked whenever the [devicePixelRatio], [size], or
|
||||
/// [padding] values change.
|
||||
VoidCallback onMetricsChanged;
|
||||
|
||||
/// The system-reported locale. This establishes the language and formatting
|
||||
/// conventions that application should, if possible, use to render their user
|
||||
/// interface.
|
||||
Locale get locale => _locale;
|
||||
Locale _locale;
|
||||
|
||||
/// A callback that is invoked whenever [locale] changes value.
|
||||
VoidCallback onLocaleChanged;
|
||||
|
||||
/// A callback that is invoked when there is a transition in the application's
|
||||
/// lifecycle (such as pausing or resuming).
|
||||
AppLifecycleStateCallback onAppLifecycleStateChanged;
|
||||
|
||||
/// A callback that is invoked to notify the application that it is an
|
||||
/// appropriate time to provide a scene using the [SceneBuilder] API and the
|
||||
/// [render()] method. When possible, this is driven by the hardware VSync
|
||||
/// signal. This is only called if [scheduleFrame()] has been called since the
|
||||
/// last time this callback was invoked.
|
||||
FrameCallback onBeginFrame;
|
||||
|
||||
/// A callback that is invoked when pointer data is available. The data is
|
||||
/// provided in the form of a raw byte stream containing an encoded mojo
|
||||
/// PointerPacket.
|
||||
PointerPacketCallback onPointerPacket;
|
||||
|
||||
/// The route or path that the operating system requested when the application
|
||||
/// was launched.
|
||||
String get defaultRouteName => _defaultRouteName;
|
||||
String _defaultRouteName;
|
||||
|
||||
/// A callback that is invoked when the operating system requests that the
|
||||
/// application goes "back" one step in its history. For example, on Android
|
||||
/// this is invoked in response to the "back" button.
|
||||
VoidCallback onPopRoute;
|
||||
|
||||
/// Requests that, at the next appropriate opportunity, the [onBeginFrame]
|
||||
/// callback be invoked.
|
||||
void scheduleFrame() native "Window_scheduleFrame";
|
||||
|
||||
/// Updates the application's rendering on the GPU with the newly provided
|
||||
/// [Scene]. This function must be called within the scope of the
|
||||
/// [onBeginFrame] callback being invoked. If this function is called multiple
|
||||
/// times during a single [onBeginFrame] callback or called outside the scope
|
||||
/// of an [onBeginFrame], the call will be ignored.
|
||||
///
|
||||
/// To record graphical operations, first create a
|
||||
/// [PictureRecorder], then construct a [Canvas], passing that
|
||||
/// [PictureRecorder] to its constructor. After issuing all the
|
||||
/// graphical operations, call the [endRecording] function on the
|
||||
/// [PictureRecorder] to obtain the final [Picture] that represents
|
||||
/// the issued graphical operations.
|
||||
///
|
||||
/// Next, create a [SceneBuilder], and add the [Picture] to it using
|
||||
/// [SceneBuilder.addPicture]. With the [SceneBuilder.build] method
|
||||
/// you can then obtain a [Scene] object, which you can display to
|
||||
/// the user via this [render] function.
|
||||
void render(Scene scene) native "Window_render";
|
||||
|
||||
/// Flushes pending real-time events, executing their callbacks.
|
||||
void flushRealTimeEvents() native "Scheduler_FlushRealTimeEvents";
|
||||
}
|
||||
|
||||
/// The [Window] singleton. This object exposes the size of the display, the
|
||||
/// core scheduler API, the input event callback, the graphics drawing API, and
|
||||
/// other such core services.
|
||||
final Window window = new Window._();
|
||||
@@ -2,7 +2,7 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//flutter/sky/engine/bindings/bindings.gni")
|
||||
import("//flutter/lib/snapshot/toolchain.gni")
|
||||
|
||||
group("sky") {
|
||||
testonly = true
|
||||
|
||||
@@ -64,7 +64,7 @@ dart_sdk_lib_copy("typed_data") {
|
||||
}
|
||||
|
||||
copy("copy_dart_ui") {
|
||||
sources = core_dart_files + dart_ui_files
|
||||
sources = dart_ui_files
|
||||
|
||||
outputs = [
|
||||
"$root_gen_dir/dart-pkg/sky_engine/dart_ui/{{source_file_part}}",
|
||||
|
||||
@@ -10,10 +10,10 @@ executable("sky_snapshot") {
|
||||
deps = [
|
||||
"//dart/runtime:libdart",
|
||||
"//dart/runtime/vm:libdart_platform",
|
||||
"//flutter/lib/snapshot",
|
||||
"//lib/ftl",
|
||||
"//lib/tonic/converter",
|
||||
"//lib/tonic/file_loader",
|
||||
"//flutter/sky/engine/bindings:snapshot_cc",
|
||||
]
|
||||
|
||||
if (!is_ios && !is_mac) {
|
||||
|
||||
Reference in New Issue
Block a user