hooks.dart 4.5 KB
Newer Older
A
Adam Barth 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 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
A
Adam Barth 已提交
16
    .._physicalSize = new Size(width, height)
17
    .._padding = new WindowPadding._(
A
Adam Barth 已提交
18 19 20 21 22
      top: top, right: right, bottom: bottom, left: left);
  if (window.onMetricsChanged != null)
    window.onMetricsChanged();
}

23 24 25 26 27 28
void _updateLocale(String languageCode, String countryCode) {
  window._locale = new Locale(languageCode, countryCode);
  if (window.onLocaleChanged != null)
    window.onLocaleChanged();
}

29 30 31 32 33 34
void _updateSemanticsEnabled(bool enabled) {
  window._semanticsEnabled = enabled;
  if (window.onSemanticsEnabledChanged != null)
    window.onSemanticsEnabledChanged();
}

A
Adam Barth 已提交
35
void _pushRoute(String route) {
H
Hixie 已提交
36 37
  assert(window._defaultRouteName == null);
  window._defaultRouteName = route;
A
Adam Barth 已提交
38 39 40 41 42 43 44
  // 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();
45 46
}

A
Adam Barth 已提交
47 48 49 50 51 52 53 54 55 56
void _dispatchPlatformMessage(String name, ByteData data, int responseId) {
  if (window.onPlatformMessage != null) {
    window.onPlatformMessage(name, data, (ByteData responseData) {
      window._respondToPlatformMessage(responseId, responseData);
    });
  } else {
    window._respondToPlatformMessage(responseId, null);
  }
}

57 58 59 60 61
void _dispatchPointerDataPacket(ByteData packet) {
  if (window.onPointerDataPacket != null)
    window.onPointerDataPacket(_unpackPointerDataPacket(packet));
}

62 63 64 65 66
void _dispatchSemanticsAction(int id, int action) {
  if (window.onSemanticsAction != null)
    window.onSemanticsAction(id, SemanticsAction.values[action]);
}

A
Adam Barth 已提交
67 68 69 70
void _beginFrame(int microseconds) {
  if (window.onBeginFrame != null)
    window.onBeginFrame(new Duration(microseconds: microseconds));
}
71 72 73 74 75

void _onAppLifecycleStateChanged(int state) {
  if (window.onAppLifecycleStateChanged != null)
    window.onAppLifecycleStateChanged(AppLifecycleState.values[state]);
}
76

77 78 79 80
// If this value changes, update the encoding code in the following files:
//
//  * pointer_data.cc
//  * FlutterView.java
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
const int _kPointerDataFieldCount = 19;

PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
  const int kStride = Int64List.BYTES_PER_ELEMENT;
  const int kBytesPerPointerData = _kPointerDataFieldCount * kStride;
  final int length = packet.lengthInBytes ~/ kBytesPerPointerData;
  assert(length * kBytesPerPointerData == packet.lengthInBytes);
  List<PointerData> pointers = new List<PointerData>(length);
  for (int i = 0; i < length; ++i) {
    int offset = i * _kPointerDataFieldCount;
    pointers[i] = new PointerData(
      timeStamp: new Duration(microseconds: packet.getInt64(kStride * offset++, _kFakeHostEndian)),
      pointer: packet.getInt64(kStride * offset++, _kFakeHostEndian),
      change: PointerChange.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
      kind: PointerDeviceKind.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
      physicalX: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      physicalY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      buttons: packet.getInt64(kStride * offset++, _kFakeHostEndian),
      obscured: packet.getInt64(kStride * offset++, _kFakeHostEndian) != 0,
      pressure: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      pressureMin: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      pressureMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      distance: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      distanceMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      radiusMajor: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      radiusMinor: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      radiusMin: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      radiusMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
      orientation: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
A
Adam Barth 已提交
110
      tilt: packet.getFloat64(kStride * offset++, _kFakeHostEndian)
111 112 113 114 115
    );
    assert(offset == (i + 1) * _kPointerDataFieldCount);
  }
  return new PointerDataPacket(pointers: pointers);
}