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

Side by Side Diff: ui/touch_selection/touch_handle_unittest.cc

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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
« no previous file with comments | « ui/touch_selection/touch_handle.cc ('k') | ui/touch_selection/touch_selection_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/touch_selection/touch_handle.h" 5 #include "ui/touch_selection/touch_handle.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/test/motion_event_test_utils.h" 8 #include "ui/events/test/motion_event_test_utils.h"
9 #include "ui/gfx/geometry/rect_f.h" 9 #include "ui/gfx/geometry/rect_f.h"
10 #include "ui/touch_selection/touch_handle_orientation.h" 10 #include "ui/touch_selection/touch_handle_orientation.h"
11 11
12 using ui::test::MockMotionEvent; 12 using ui::test::MockMotionEvent;
13 13
14 namespace ui { 14 namespace ui {
15 namespace { 15 namespace {
16 16
17 const int kDefaultTapTimeoutMs = 200; 17 const int kDefaultTapTimeoutMs = 200;
18 const float kDefaultTapSlop = 10.f; 18 const double kDefaultTapSlop = 10.;
19 const float kDefaultDrawableSize = 10.f; 19 const float kDefaultDrawableSize = 10.f;
20 20
21 struct MockDrawableData { 21 struct MockDrawableData {
22 MockDrawableData() 22 MockDrawableData()
23 : orientation(TouchHandleOrientation::UNDEFINED), 23 : orientation(TouchHandleOrientation::UNDEFINED),
24 alpha(0.f), 24 alpha(0.f),
25 enabled(false), 25 enabled(false),
26 visible(false), 26 visible(false),
27 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {} 27 rect(0, 0, kDefaultDrawableSize, kDefaultDrawableSize) {}
28 TouchHandleOrientation orientation; 28 TouchHandleOrientation orientation;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 public: 67 public:
68 TouchHandleTest() 68 TouchHandleTest()
69 : dragging_(false), 69 : dragging_(false),
70 dragged_(false), 70 dragged_(false),
71 tapped_(false), 71 tapped_(false),
72 needs_animate_(false) {} 72 needs_animate_(false) {}
73 73
74 ~TouchHandleTest() override {} 74 ~TouchHandleTest() override {}
75 75
76 // TouchHandleClient implementation. 76 // TouchHandleClient implementation.
77 void OnHandleDragBegin(const TouchHandle& handle) override { 77 void OnDragBegin(const TouchSelectionDraggable& handler,
78 const gfx::PointF& drag_position) override {
78 dragging_ = true; 79 dragging_ = true;
79 } 80 }
80 81
81 void OnHandleDragUpdate(const TouchHandle& handle, 82 void OnDragUpdate(const TouchSelectionDraggable& handler,
82 const gfx::PointF& new_position) override { 83 const gfx::PointF& drag_position) override {
83 dragged_ = true; 84 dragged_ = true;
84 drag_position_ = new_position; 85 drag_position_ = drag_position;
85 } 86 }
86 87
87 void OnHandleDragEnd(const TouchHandle& handle) override { 88 void OnDragEnd(const TouchSelectionDraggable& handler) override {
88 dragging_ = false; 89 dragging_ = false;
89 } 90 }
90 91
92 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override {
93 return delta.LengthSquared() < (kDefaultTapSlop * kDefaultTapSlop);
94 }
95
91 void OnHandleTapped(const TouchHandle& handle) override { tapped_ = true; } 96 void OnHandleTapped(const TouchHandle& handle) override { tapped_ = true; }
92 97
93 void SetNeedsAnimate() override { needs_animate_ = true; } 98 void SetNeedsAnimate() override { needs_animate_ = true; }
94 99
95 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { 100 scoped_ptr<TouchHandleDrawable> CreateDrawable() override {
96 return make_scoped_ptr(new MockTouchHandleDrawable(&drawable_data_)); 101 return make_scoped_ptr(new MockTouchHandleDrawable(&drawable_data_));
97 } 102 }
98 103
99 base::TimeDelta GetTapTimeout() const override { 104 base::TimeDelta GetTapTimeout() const override {
100 return base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs); 105 return base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs);
101 } 106 }
102 107
103 float GetTapSlop() const override { return kDefaultTapSlop; }
104
105 void Animate(TouchHandle& handle) { 108 void Animate(TouchHandle& handle) {
106 needs_animate_ = false; 109 needs_animate_ = false;
107 base::TimeTicks now = base::TimeTicks::Now(); 110 base::TimeTicks now = base::TimeTicks::Now();
108 while (handle.Animate(now)) 111 while (handle.Animate(now))
109 now += base::TimeDelta::FromMilliseconds(16); 112 now += base::TimeDelta::FromMilliseconds(16);
110 } 113 }
111 114
112 bool GetAndResetHandleDragged() { 115 bool GetAndResetHandleDragged() {
113 bool dragged = dragged_; 116 bool dragged = dragged_;
114 dragged_ = false; 117 dragged_ = false;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 event = MockMotionEvent( 501 event = MockMotionEvent(
499 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0); 502 MockMotionEvent::ACTION_MOVE, event_time, kDefaultTapSlop * 2.f, 0);
500 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 503 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
501 event = MockMotionEvent( 504 event = MockMotionEvent(
502 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0); 505 MockMotionEvent::ACTION_UP, event_time, kDefaultTapSlop * 2.f, 0);
503 EXPECT_TRUE(handle.WillHandleTouchEvent(event)); 506 EXPECT_TRUE(handle.WillHandleTouchEvent(event));
504 EXPECT_FALSE(GetAndResetHandleTapped()); 507 EXPECT_FALSE(GetAndResetHandleTapped());
505 } 508 }
506 509
507 } // namespace ui 510 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_handle.cc ('k') | ui/touch_selection/touch_selection_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698