• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'enum_util.dart';
6import 'find.dart';
7import 'message.dart';
8
9/// Offset types that can be requested by [GetOffset].
10enum OffsetType {
11  /// The top left point.
12  topLeft,
13
14  /// The top right point.
15  topRight,
16
17  /// The bottom left point.
18  bottomLeft,
19
20  /// The bottom right point.
21  bottomRight,
22
23  /// The center point.
24  center,
25}
26
27EnumIndex<OffsetType> _offsetTypeIndex = EnumIndex<OffsetType>(OffsetType.values);
28
29/// A Flutter Driver command that returns the [offsetType] from the RenderObject
30/// identified by [finder].
31///
32/// The requested offset is returned in logical pixels, which can be translated
33/// to device pixels via [Window.devicePixelRatio].
34class GetOffset extends CommandWithTarget {
35  /// The `finder` looks for an element to get its rect.
36  GetOffset(SerializableFinder finder,  this.offsetType, { Duration timeout }) : super(finder, timeout: timeout);
37
38  /// Deserializes this command from the value generated by [serialize].
39  GetOffset.deserialize(Map<String, dynamic> json)
40      : offsetType = _offsetTypeIndex.lookupBySimpleName(json['offsetType']),
41        super.deserialize(json);
42
43  @override
44  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
45    'offsetType': _offsetTypeIndex.toSimpleName(offsetType),
46  });
47
48  /// The type of the requested offset.
49  final OffsetType offsetType;
50
51  @override
52  String get kind => 'get_offset';
53}
54
55/// The result of the [GetRect] command.
56///
57/// The offset is provided in logical pixels, which can be translated
58/// to device pixels via [Window.devicePixelRatio].
59class GetOffsetResult extends Result {
60  /// Creates a result with the offset defined by [dx] and [dy].
61  const GetOffsetResult({ this.dx = 0.0, this.dy = 0.0});
62
63  /// The x component of the offset in logical pixels.
64  ///
65  /// The value can be translated to device pixels via
66  /// [Window.devicePixelRatio].
67  final double dx;
68
69  /// The y component of the offset in logical pixels.
70  ///
71  /// The value can be translated to device pixels via
72  /// [Window.devicePixelRatio].
73  final double dy;
74
75  /// Deserializes the result from JSON.
76  static GetOffsetResult fromJson(Map<String, dynamic> json) {
77    return GetOffsetResult(
78      dx: json['dx'],
79      dy: json['dy'],
80    );
81  }
82
83  @override
84  Map<String, dynamic> toJson() => <String, double>{
85    'dx': dx,
86    'dy': dy,
87  };
88}
89