gesture.dart 3.18 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) : super(finder);
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 47
    this.dx,
    this.dy,
    this.duration,
    this.frequency
48
  ) : super(finder);
49

50
  /// Deserializes this command from JSON generated by [serialize].
51
  Scroll.deserialize(Map<String, String> json)
52 53 54 55 56
      : 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);
57 58 59 60 61 62 63 64 65 66 67 68 69

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

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

79 80 81 82 83 84 85 86 87 88 89
/// 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>{};
}

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

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

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

  final double alignment;
106

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