Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ui/events/test/motion_event_test_utils.cc

Issue 502993004: Remove abstract Clone and Cancel methods from MotionEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Owner for BUILD.gn Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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
5 #include "ui/events/test/motion_event_test_utils.h"
6
7 #include <sstream>
8
9 #include "ui/events/gesture_detection/bitset_32.h"
10 #include "ui/events/gesture_detection/motion_event.h"
11
12 namespace ui {
13
14 bool operator==(const MotionEvent& lhs, const MotionEvent& rhs) {
15 // Re-using the string conversion for equality testing is sensible because it
16 // 1) is only used in testing (where performance is not a chief concern), and
17 // 2) simplifies maintenance by consolidating the necessary property checks.
18 std::stringstream lhs_ss, rhs_ss;
19 lhs_ss << lhs;
20 rhs_ss << rhs;
21 return lhs_ss.str() == rhs_ss.str();
22 }
23
24 std::ostream& operator<<(std::ostream& os, const MotionEvent& event) {
25 os << "MotionEvent {"
26 << "\n ID: " << event.GetId() << "\n Action: " << event.GetAction()
27 << "\n ActionIndex: " << event.GetActionIndex()
28 << "\n Flags: " << event.GetFlags()
29 << "\n ButtonState: " << event.GetButtonState() << "\n Pointers: [";
30 const size_t pointer_count = event.GetPointerCount();
31 const size_t history_size = event.GetHistorySize();
32
33 BitSet32 pointer_ids;
34 for (size_t i = 0; i < pointer_count; ++i) {
35 pointer_ids.mark_bit(event.GetPointerId(i));
36
37 // Print the pointers sorted by id.
38 while (!pointer_ids.is_empty()) {
39 int pi = event.FindPointerIndexOfId(pointer_ids.first_marked_bit());
40 DCHECK_GE(pi, 0);
41 pointer_ids.clear_first_marked_bit();
42 os << "{"
43 << "\n Pos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
44 << "\n RawPos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
45 << "\n Size: (" << event.GetTouchMajor(pi) << ", "
46 << event.GetTouchMinor(pi) << ")"
47 << "\n Orientation: " << event.GetOrientation(pi)
48 << "\n Pressure: " << event.GetOrientation(pi)
49 << "\n Tool: " << event.GetToolType(pi);
50 if (history_size) {
51 os << "\n History: [";
52 for (size_t h = 0; h < history_size; ++h) {
53 os << "\n { " << event.GetHistoricalX(pi, h) << ", "
54 << event.GetHistoricalY(pi, h) << ", "
55 << event.GetHistoricalTouchMajor(pi, h) << ", "
56 << event.GetHistoricalEventTime(pi).ToInternalValue() << " }";
57 if (h + 1 < history_size)
58 os << ",";
59 }
60 os << "\n ]";
61 }
62 os << "\n }";
63 if (i + 1 < pointer_count)
64 os << ", ";
65 }
66 os << "]\n}";
67 }
68
69 return os;
70 }
71
72 } // namespace ui
OLDNEW
« ui/events/test/motion_event_test_utils.h ('K') | « ui/events/test/motion_event_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698