OLD | NEW |
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 "content/browser/renderer_host/input/touch_selection_controller.h" | 5 #include "ui/touch_selection/touch_selection_controller.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 | 9 |
10 using ui::test::MockMotionEvent; | 10 using ui::test::MockMotionEvent; |
11 | 11 |
12 namespace content { | 12 namespace ui { |
13 namespace { | 13 namespace { |
14 | 14 |
15 const int kDefaultTapTimeoutMs = 200; | 15 const int kDefaultTapTimeoutMs = 200; |
16 const float kDefaulTapSlop = 10.f; | 16 const float kDefaulTapSlop = 10.f; |
17 | 17 |
18 class MockTouchHandleDrawable : public TouchHandleDrawable { | 18 class MockTouchHandleDrawable : public TouchHandleDrawable { |
19 public: | 19 public: |
20 explicit MockTouchHandleDrawable(bool* contains_point) | 20 explicit MockTouchHandleDrawable(bool* contains_point) |
21 : intersects_rect_(contains_point) {} | 21 : intersects_rect_(contains_point) {} |
22 ~MockTouchHandleDrawable() override {} | 22 ~MockTouchHandleDrawable() override {} |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { | 92 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { |
93 return scoped_ptr<TouchHandleDrawable>( | 93 return scoped_ptr<TouchHandleDrawable>( |
94 new MockTouchHandleDrawable(&dragging_enabled_)); | 94 new MockTouchHandleDrawable(&dragging_enabled_)); |
95 } | 95 } |
96 | 96 |
97 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } | 97 void SetAnimationEnabled(bool enabled) { animation_enabled_ = enabled; } |
98 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } | 98 void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } |
99 | 99 |
100 void ClearSelection() { | 100 void ClearSelection() { |
101 controller_->OnSelectionBoundsChanged(cc::ViewportSelectionBound(), | 101 controller_->OnSelectionBoundsChanged(SelectionBound(), |
102 cc::ViewportSelectionBound()); | 102 SelectionBound()); |
103 } | 103 } |
104 | 104 |
105 void ClearInsertion() { ClearSelection(); } | 105 void ClearInsertion() { ClearSelection(); } |
106 | 106 |
107 void ChangeInsertion(const gfx::RectF& rect, bool visible) { | 107 void ChangeInsertion(const gfx::RectF& rect, bool visible) { |
108 cc::ViewportSelectionBound bound; | 108 SelectionBound bound; |
109 bound.type = cc::SELECTION_BOUND_CENTER; | 109 bound.set_type(SelectionBound::CENTER); |
110 bound.edge_top = rect.origin(); | 110 bound.SetEdge(rect.origin(), rect.bottom_left()); |
111 bound.edge_bottom = rect.bottom_left(); | 111 bound.set_visible(visible); |
112 bound.visible = visible; | |
113 controller_->OnSelectionBoundsChanged(bound, bound); | 112 controller_->OnSelectionBoundsChanged(bound, bound); |
114 } | 113 } |
115 | 114 |
116 void ChangeSelection(const gfx::RectF& start_rect, | 115 void ChangeSelection(const gfx::RectF& start_rect, |
117 bool start_visible, | 116 bool start_visible, |
118 const gfx::RectF& end_rect, | 117 const gfx::RectF& end_rect, |
119 bool end_visible) { | 118 bool end_visible) { |
120 cc::ViewportSelectionBound start_bound, end_bound; | 119 SelectionBound start_bound, end_bound; |
121 start_bound.type = cc::SELECTION_BOUND_LEFT; | 120 start_bound.set_type(SelectionBound::LEFT); |
122 end_bound.type = cc::SELECTION_BOUND_RIGHT; | 121 end_bound.set_type(SelectionBound::RIGHT); |
123 start_bound.edge_top = start_rect.origin(); | 122 start_bound.SetEdge(start_rect.origin(), start_rect.bottom_left()); |
124 start_bound.edge_bottom = start_rect.bottom_left(); | 123 end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left()); |
125 end_bound.edge_top = end_rect.origin(); | 124 start_bound.set_visible(start_visible); |
126 end_bound.edge_bottom = end_rect.bottom_left(); | 125 end_bound.set_visible(end_visible); |
127 start_bound.visible = start_visible; | |
128 end_bound.visible = end_visible; | |
129 controller_->OnSelectionBoundsChanged(start_bound, end_bound); | 126 controller_->OnSelectionBoundsChanged(start_bound, end_bound); |
130 } | 127 } |
131 | 128 |
132 void Animate() { | 129 void Animate() { |
133 base::TimeTicks now = base::TimeTicks::Now(); | 130 base::TimeTicks now = base::TimeTicks::Now(); |
134 while (needs_animate_) { | 131 while (needs_animate_) { |
135 needs_animate_ = controller_->Animate(now); | 132 needs_animate_ = controller_->Animate(now); |
136 now += base::TimeDelta::FromMilliseconds(16); | 133 now += base::TimeDelta::FromMilliseconds(16); |
137 } | 134 } |
138 } | 135 } |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 controller().OnSelectionEditable(true); | 832 controller().OnSelectionEditable(true); |
836 controller().OnSelectionEmpty(false); | 833 controller().OnSelectionEmpty(false); |
837 controller().HideAndDisallowShowingAutomatically(); | 834 controller().HideAndDisallowShowingAutomatically(); |
838 gfx::RectF insertion_rect(5, 5, 0, 10); | 835 gfx::RectF insertion_rect(5, 5, 0, 10); |
839 ChangeInsertion(insertion_rect, visible); | 836 ChangeInsertion(insertion_rect, visible); |
840 controller().AllowShowingFromCurrentSelection(); | 837 controller().AllowShowingFromCurrentSelection(); |
841 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); | 838 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); |
842 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 839 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); |
843 } | 840 } |
844 | 841 |
845 } // namespace content | 842 } // namespace ui |
OLD | NEW |