hooks.dart 6.1 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
A
Adam Barth 已提交
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// TODO(dnfield): Remove unused_import ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.

7

V
vsmenon 已提交
8
// @dart = 2.12
A
Adam Barth 已提交
9
part of dart.ui;
A
Adam Barth 已提交
10

C
Chris Bracken 已提交
11
@pragma('vm:entry-point')
12
// ignore: unused_element
13
void _updateWindowMetrics(
14
  Object id,
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  double devicePixelRatio,
  double width,
  double height,
  double viewPaddingTop,
  double viewPaddingRight,
  double viewPaddingBottom,
  double viewPaddingLeft,
  double viewInsetTop,
  double viewInsetRight,
  double viewInsetBottom,
  double viewInsetLeft,
  double systemGestureInsetTop,
  double systemGestureInsetRight,
  double systemGestureInsetBottom,
  double systemGestureInsetLeft,
30
) {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  PlatformDispatcher.instance._updateWindowMetrics(
    id,
    devicePixelRatio,
    width,
    height,
    viewPaddingTop,
    viewPaddingRight,
    viewPaddingBottom,
    viewPaddingLeft,
    viewInsetTop,
    viewInsetRight,
    viewInsetBottom,
    viewInsetLeft,
    systemGestureInsetTop,
    systemGestureInsetRight,
    systemGestureInsetBottom,
    systemGestureInsetLeft,
  );
49 50
}

51 52
typedef _LocaleClosure = String Function();

C
Chris Bracken 已提交
53
@pragma('vm:entry-point')
54
// ignore: unused_element
55
_LocaleClosure? _getLocaleClosure() => PlatformDispatcher.instance._localeClosure;
56

C
Chris Bracken 已提交
57
@pragma('vm:entry-point')
58
// ignore: unused_element
59
void _updateLocales(List<String> locales) {
60
  PlatformDispatcher.instance._updateLocales(locales);
61 62
}

C
Chris Bracken 已提交
63
@pragma('vm:entry-point')
64
// ignore: unused_element
65
void _updateUserSettingsData(String jsonData) {
66
  PlatformDispatcher.instance._updateUserSettingsData(jsonData);
67 68
}

69 70
@pragma('vm:entry-point')
// ignore: unused_element
71
void _updateLifecycleState(String state) {
72
  PlatformDispatcher.instance._updateLifecycleState(state);
73 74
}

C
Chris Bracken 已提交
75
@pragma('vm:entry-point')
76
// ignore: unused_element
77
void _updateSemanticsEnabled(bool enabled) {
78
  PlatformDispatcher.instance._updateSemanticsEnabled(enabled);
79 80
}

C
Chris Bracken 已提交
81
@pragma('vm:entry-point')
82
// ignore: unused_element
83
void _updateAccessibilityFeatures(int values) {
84
  PlatformDispatcher.instance._updateAccessibilityFeatures(values);
85 86
}

C
Chris Bracken 已提交
87
@pragma('vm:entry-point')
88
// ignore: unused_element
89
void _dispatchPlatformMessage(String name, ByteData? data, int responseId) {
90
  PlatformDispatcher.instance._dispatchPlatformMessage(name, data, responseId);
A
Adam Barth 已提交
91 92
}

C
Chris Bracken 已提交
93
@pragma('vm:entry-point')
94
// ignore: unused_element
95
void _dispatchPointerDataPacket(ByteData packet) {
96
  PlatformDispatcher.instance._dispatchPointerDataPacket(packet);
97 98
}

99 100 101 102 103 104
@pragma('vm:entry-point')
// ignore: unused_element
void _dispatchKeyData(ByteData packet, int responseId) {
  PlatformDispatcher.instance._dispatchKeyData(packet, responseId);
}

C
Chris Bracken 已提交
105
@pragma('vm:entry-point')
106
// ignore: unused_element
107
void _dispatchSemanticsAction(int id, int action, ByteData? args) {
108
  PlatformDispatcher.instance._dispatchSemanticsAction(id, action, args);
109 110
}

C
Chris Bracken 已提交
111
@pragma('vm:entry-point')
112
// ignore: unused_element
113
void _beginFrame(int microseconds) {
114
  PlatformDispatcher.instance._beginFrame(microseconds);
A
Adam Barth 已提交
115
}
116

117 118
@pragma('vm:entry-point')
// ignore: unused_element
119
void _reportTimings(List<int> timings) {
120
  PlatformDispatcher.instance._reportTimings(timings);
121 122
}

C
Chris Bracken 已提交
123
@pragma('vm:entry-point')
124
// ignore: unused_element
125
void _drawFrame() {
126
  PlatformDispatcher.instance._drawFrame();
Y
Yegor 已提交
127 128
}

129
// ignore: always_declare_return_types, prefer_generic_function_type_aliases
130
typedef _ListStringArgFunction(List<String> args);
131

C
Chris Bracken 已提交
132
@pragma('vm:entry-point')
133
// ignore: unused_element
134 135 136
void _runMainZoned(Function startMainIsolateFunction,
                   Function userMainFunction,
                   List<String> args) {
137
  startMainIsolateFunction(() {
138
    runZonedGuarded<void>(() {
139
      if (userMainFunction is _ListStringArgFunction) {
140
        (userMainFunction as dynamic)(args);
141 142 143
      } else {
        userMainFunction();
      }
144
    }, (Object error, StackTrace stackTrace) {
145 146 147 148 149
      _reportUnhandledException(error.toString(), stackTrace.toString());
    });
  }, null);
}

150
void _reportUnhandledException(String error, String stackTrace) native 'PlatformConfiguration_reportUnhandledException';
151

Y
Yegor 已提交
152
/// Invokes [callback] inside the given [zone].
153 154
void _invoke(void Function()? callback, Zone zone) {
  if (callback == null) {
Y
Yegor 已提交
155
    return;
156
  }
Y
Yegor 已提交
157

M
Michael Goderbauer 已提交
158
  assert(zone != null);
Y
Yegor 已提交
159 160 161 162 163 164 165 166 167

  if (identical(zone, Zone.current)) {
    callback();
  } else {
    zone.runGuarded(callback);
  }
}

/// Invokes [callback] inside the given [zone] passing it [arg].
168 169 170 171
///
/// The 1 in the name refers to the number of arguments expected by
/// the callback (and thus passed to this function, in addition to the
/// callback itself and the zone in which the callback is executed).
172 173
void _invoke1<A>(void Function(A a)? callback, Zone zone, A arg) {
  if (callback == null) {
Y
Yegor 已提交
174
    return;
175
  }
Y
Yegor 已提交
176

M
Michael Goderbauer 已提交
177
  assert(zone != null);
Y
Yegor 已提交
178 179 180 181

  if (identical(zone, Zone.current)) {
    callback(arg);
  } else {
182
    zone.runUnaryGuarded<A>(callback, arg);
Y
Yegor 已提交
183 184 185
  }
}

186 187 188 189 190 191 192 193 194 195
/// Invokes [callback] inside the given [zone] passing it [arg1] and [arg2].
///
/// The 2 in the name refers to the number of arguments expected by
/// the callback (and thus passed to this function, in addition to the
/// callback itself and the zone in which the callback is executed).
void _invoke2<A1, A2>(void Function(A1 a1, A2 a2)? callback, Zone zone, A1 arg1, A2 arg2) {
  if (callback == null) {
    return;
  }

M
Michael Goderbauer 已提交
196
  assert(zone != null);
197 198 199 200 201 202 203 204 205 206

  if (identical(zone, Zone.current)) {
    callback(arg1, arg2);
  } else {
    zone.runGuarded(() {
      callback(arg1, arg2);
    });
  }
}

207
/// Invokes [callback] inside the given [zone] passing it [arg1], [arg2], and [arg3].
208 209 210 211 212
///
/// The 3 in the name refers to the number of arguments expected by
/// the callback (and thus passed to this function, in addition to the
/// callback itself and the zone in which the callback is executed).
void _invoke3<A1, A2, A3>(void Function(A1 a1, A2 a2, A3 a3)? callback, Zone zone, A1 arg1, A2 arg2, A3 arg3) {
213
  if (callback == null) {
Y
Yegor 已提交
214
    return;
215
  }
Y
Yegor 已提交
216

M
Michael Goderbauer 已提交
217
  assert(zone != null);
Y
Yegor 已提交
218 219 220 221 222 223 224 225

  if (identical(zone, Zone.current)) {
    callback(arg1, arg2, arg3);
  } else {
    zone.runGuarded(() {
      callback(arg1, arg2, arg3);
    });
  }
226
}