gesture.dart 3.58 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// 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
/// A Flutter Driver command that taps on a target widget located by [finder].
9
class Tap extends CommandWithTarget {
10
  /// Creates a tap command to tap on a widget located by [finder].
11
  Tap(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout);
12

13
  /// Deserializes this command from the value generated by [serialize].
14
  Tap.deserialize(Map<String, String> json) : super.deserialize(json);
15 16

  @override
17
  String get kind => 'tap';
18 19
}

20
/// The result of a [Tap] command.
21
class TapResult extends Result {
22 23 24
  /// Creates a [TapResult].
  const TapResult();

25
  /// Deserializes this result from JSON.
26
  static TapResult fromJson(Map<String, dynamic> json) {
27
    return const TapResult();
28 29
  }

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


35
/// A Flutter Driver command that commands the driver to perform a scrolling action.
36
class Scroll extends CommandWithTarget {
37 38
  /// Creates a scroll command that will attempt to scroll a scrollable view by
  /// dragging a widget located by the given [finder].
39
  Scroll(
40
    SerializableFinder finder,
41 42 43
    this.dx,
    this.dy,
    this.duration,
44 45 46
    this.frequency, {
    Duration timeout,
  }) : super(finder, timeout: timeout);
47

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

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

68
  @override
69
  String get kind => 'scroll';
70

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
/// The result of a [Scroll] command.
class ScrollResult extends Result {
82 83 84
  /// Creates a [ScrollResult].
  const ScrollResult();

85 86
  /// Deserializes this result from JSON.
  static ScrollResult fromJson(Map<String, dynamic> json) {
87
    return const ScrollResult();
88 89 90 91 92 93
  }

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

94 95
/// A Flutter Driver command that commands the driver to ensure that the element
/// represented by [finder] has been scrolled completely into view.
96
class ScrollIntoView extends CommandWithTarget {
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 the value generated by [serialize].
102
  ScrollIntoView.deserialize(Map<String, String> json)
103 104
    : alignment = double.parse(json['alignment']),
      super.deserialize(json);
105

106 107 108 109 110 111
  /// How the widget should be aligned.
  ///
  /// This value is passed to [Scrollable.ensureVisible] as the value of its
  /// argument of the same name.
  ///
  /// Defaults to 0.0.
112
  final double alignment;
113

114
  @override
115
  String get kind => 'scrollIntoView';
116

117
  @override
118 119 120
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'alignment': '$alignment',
  });
121
}