gesture.dart 2.33 KB
Newer Older
1 2 3 4 5
// 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 'message.dart';
6
import 'find.dart';
7 8

class Tap extends CommandWithTarget {
9
  @override
10 11
  final String kind = 'tap';

12
  Tap(SerializableFinder finder) : super(finder);
13

14
  static Tap deserialize(Map<String, String> json) {
15
    return new Tap(SerializableFinder.deserialize(json));
16 17
  }

18
  @override
19
  Map<String, String> serialize() => super.serialize();
20 21 22 23 24 25 26
}

class TapResult extends Result {
  static TapResult fromJson(Map<String, dynamic> json) {
    return new TapResult();
  }

27
  @override
pq's avatar
pq committed
28
  Map<String, dynamic> toJson() => <String, dynamic>{};
29
}
30 31 32 33


/// Command the driver to perform a scrolling action.
class Scroll extends CommandWithTarget {
34
  @override
35 36 37
  final String kind = 'scroll';

  Scroll(
38
    SerializableFinder finder,
39 40 41 42
    this.dx,
    this.dy,
    this.duration,
    this.frequency
43
  ) : super(finder);
44

45
  static Scroll deserialize(Map<String, dynamic> json) {
46
    return new Scroll(
47
      SerializableFinder.deserialize(json),
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
      double.parse(json['dx']),
      double.parse(json['dy']),
      new Duration(microseconds: int.parse(json['duration'])),
      int.parse(json['frequency'])
    );
  }

  /// Delta X offset per move event.
  final double dx;

  /// Delta Y offset per move event.
  final double dy;

  /// The duration of the scrolling action
  final Duration duration;

  /// The frequency in Hz of the generated move events.
  final int frequency;

67
  @override
pq's avatar
pq committed
68
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
69 70 71 72
    'dx': '$dx',
    'dy': '$dy',
    'duration': '${duration.inMicroseconds}',
    'frequency': '$frequency',
73 74 75
  });
}

76 77 78 79 80 81 82 83 84 85 86 87 88
/// Command the driver to ensure that the element represented by [finder]
/// has been scrolled completely into view.
class ScrollIntoView extends CommandWithTarget {
  @override
  final String kind = 'scrollIntoView';

  ScrollIntoView(SerializableFinder finder) : super(finder);

  static ScrollIntoView deserialize(Map<String, dynamic> json) {
    return new ScrollIntoView(SerializableFinder.deserialize(json));
  }
}

89 90 91 92 93
class ScrollResult extends Result {
  static ScrollResult fromJson(Map<String, dynamic> json) {
    return new ScrollResult();
  }

94
  @override
pq's avatar
pq committed
95
  Map<String, dynamic> toJson() => <String, dynamic>{};
96
}