gesture.dart 3.48 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
/// 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 17

  @override
  final String kind = 'tap';
18 19
}

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

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


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

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

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

65 66 67
  @override
  final String kind = 'scroll';

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

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

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

88 89
/// A Flutter Driver command that commands the driver to ensure that the element
/// represented by [finder] has been scrolled completely into view.
90
class ScrollIntoView extends CommandWithTarget {
91 92
  /// Creates this command given a [finder] used to locate the widget to be
  /// scrolled into view.
93
  ScrollIntoView(SerializableFinder finder, { this.alignment = 0.0, Duration timeout }) : super(finder, timeout: timeout);
94

95
  /// Deserializes this command from the value generated by [serialize].
96
  ScrollIntoView.deserialize(Map<String, String> json)
97
      : alignment = double.parse(json['alignment']),
98 99
        super.deserialize(json);

100 101 102 103 104 105
  /// 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.
106
  final double alignment;
107

108 109 110
  @override
  final String kind = 'scrollIntoView';

111
  @override
112 113 114
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'alignment': '$alignment',
  });
115
}