hooks.dart 3.9 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();
}

A
Adam Barth 已提交
29
void _pushRoute(String route) {
H
Hixie 已提交
30 31
  assert(window._defaultRouteName == null);
  window._defaultRouteName = route;
A
Adam Barth 已提交
32 33 34 35 36 37 38
  // 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();
39 40
}

41 42 43 44 45
void _dispatchPointerDataPacket(ByteData packet) {
  if (window.onPointerDataPacket != null)
    window.onPointerDataPacket(_unpackPointerDataPacket(packet));
}

A
Adam Barth 已提交
46 47 48 49
void _beginFrame(int microseconds) {
  if (window.onBeginFrame != null)
    window.onBeginFrame(new Duration(microseconds: microseconds));
}
50 51 52 53 54

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

56 57 58 59
// If this value changes, update the encoding code in the following files:
//
//  * pointer_data.cc
//  * FlutterView.java
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
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 已提交
89
      tilt: packet.getFloat64(kStride * offset++, _kFakeHostEndian)
90 91 92 93 94
    );
    assert(offset == (i + 1) * _kPointerDataFieldCount);
  }
  return new PointerDataPacket(pointers: pointers);
}