gesture.dart 3.3 KB
Newer Older
1 2 3 4
// 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.

5
import 'find.dart';
6
import 'message.dart';
7

8
/// Taps on a target widget located by [finder].
9
class Tap extends CommandWithTarget {
10
  @override
11 12
  final String kind = 'tap';

13
  /// Creates a tap command to tap on a widget located by [finder].
14
  Tap(SerializableFinder finder, {Duration timeout}) : super(finder, timeout: timeout);
15

16
  /// Deserializes this command from JSON generated by [serialize].
17
  Tap.deserialize(Map<String, String> json) : super.deserialize(json);
18

19
  @override
20
  Map<String, String> serialize() => super.serialize();
21 22
}

23
/// The result of a [Tap] command.
24
class TapResult extends Result {
25
  /// Deserializes this result from JSON.
26 27 28 29
  static TapResult fromJson(Map<String, dynamic> json) {
    return new TapResult();
  }

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


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

40 41
  /// Creates a scroll command that will attempt to scroll a scrollable view by
  /// dragging a widget located by the given [finder].
42
  Scroll(
43
    SerializableFinder finder,
44 45 46
    this.dx,
    this.dy,
    this.duration,
47 48 49
    this.frequency,
    {Duration timeout}
  ) : super(finder, timeout: timeout);
50

51
  /// Deserializes this command from JSON generated by [serialize].
52
  Scroll.deserialize(Map<String, String> json)
53 54 55 56 57
      : this.dx = double.parse(json['dx']),
        this.dy = double.parse(json['dy']),
        this.duration = new Duration(microseconds: int.parse(json['duration'])),
        this.frequency = int.parse(json['frequency']),
        super.deserialize(json);
58 59 60 61 62 63 64 65 66 67 68 69 70

  /// 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;

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

80 81 82 83 84 85 86 87 88 89 90
/// The result of a [Scroll] command.
class ScrollResult extends Result {
  /// Deserializes this result from JSON.
  static ScrollResult fromJson(Map<String, dynamic> json) {
    return new ScrollResult();
  }

  @override
  Map<String, dynamic> toJson() => <String, dynamic>{};
}

91 92 93 94 95 96
/// 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';

97 98
  /// Creates this command given a [finder] used to locate the widget to be
  /// scrolled into view.
99
  ScrollIntoView(SerializableFinder finder, { this.alignment: 0.0, Duration timeout }) : super(finder, timeout: timeout);
100

101
  /// Deserializes this command from JSON generated by [serialize].
102
  ScrollIntoView.deserialize(Map<String, String> json)
103 104 105 106
      : this.alignment = double.parse(json['alignment']),
        super.deserialize(json);

  final double alignment;
107

108
  @override
109 110 111
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'alignment': '$alignment',
  });
112
}