namespace content {
namespace {
+const int kDefaultTapTimeoutMs = 200;
+const float kDefaulTapSlop = 10.f;
+
class MockTouchHandleDrawable : public TouchHandleDrawable {
public:
explicit MockTouchHandleDrawable(bool* contains_point)
// testing::Test implementation.
virtual void SetUp() OVERRIDE {
- controller_.reset(new TouchSelectionController(this));
+ controller_.reset(new TouchSelectionController(
+ this,
+ base::TimeDelta::FromMilliseconds(kDefaultTapTimeoutMs),
+ kDefaulTapSlop));
}
virtual void TearDown() OVERRIDE { controller_.reset(); }
void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; }
void ClearSelection() {
- controller_->OnSelectionBoundsChanged(gfx::RectF(),
- TOUCH_HANDLE_ORIENTATION_UNDEFINED,
- false,
- gfx::RectF(),
- TOUCH_HANDLE_ORIENTATION_UNDEFINED,
- false);
+ controller_->OnSelectionBoundsChanged(cc::ViewportSelectionBound(),
+ cc::ViewportSelectionBound());
}
void ClearInsertion() { ClearSelection(); }
- void ChangeInsertion(const gfx::RectF& rect,
- TouchHandleOrientation orientation,
- bool visible) {
- controller_->OnSelectionBoundsChanged(
- rect, orientation, visible, rect, orientation, visible);
- }
-
void ChangeInsertion(const gfx::RectF& rect, bool visible) {
- ChangeInsertion(rect, TOUCH_HANDLE_CENTER, visible);
+ cc::ViewportSelectionBound bound;
+ bound.type = cc::SELECTION_BOUND_CENTER;
+ bound.edge_top = rect.origin();
+ bound.edge_bottom = rect.bottom_left();
+ bound.visible = visible;
+ controller_->OnSelectionBoundsChanged(bound, bound);
}
void ChangeSelection(const gfx::RectF& start_rect,
- TouchHandleOrientation start_orientation,
bool start_visible,
const gfx::RectF& end_rect,
- TouchHandleOrientation end_orientation,
bool end_visible) {
- controller_->OnSelectionBoundsChanged(start_rect,
- start_orientation,
- start_visible,
- end_rect,
- end_orientation,
- end_visible);
- }
-
- void ChangeSelection(const gfx::RectF& start_rect,
- bool start_visible,
- const gfx::RectF& end_rect,
- bool end_visible) {
- ChangeSelection(start_rect,
- TOUCH_HANDLE_LEFT,
- start_visible,
- end_rect,
- TOUCH_HANDLE_RIGHT,
- end_visible);
+ cc::ViewportSelectionBound start_bound, end_bound;
+ start_bound.type = cc::SELECTION_BOUND_LEFT;
+ end_bound.type = cc::SELECTION_BOUND_RIGHT;
+ start_bound.edge_top = start_rect.origin();
+ start_bound.edge_bottom = start_rect.bottom_left();
+ end_bound.edge_top = end_rect.origin();
+ end_bound.edge_bottom = end_rect.bottom_left();
+ start_bound.visible = start_visible;
+ end_bound.visible = end_visible;
+ controller_->OnSelectionBoundsChanged(start_bound, end_bound);
}
void Animate() {
ChangeInsertion(insertion_rect, visible);
EXPECT_EQ(INSERTION_SHOWN, GetLastEventType());
EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor());
+
+ // Single Tap on an empty edit field should clear insertion handle.
+ controller().OnTapEvent();
+ EXPECT_EQ(INSERTION_CLEARED, GetLastEventType());
}
TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) {
ChangeInsertion(start_rect, visible);
ASSERT_EQ(INSERTION_SHOWN, GetLastEventType());
+ // No tap should be signalled if the drag was too long.
+ event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, 100, 0);
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 100, 0);
+ EXPECT_TRUE(controller().WillHandleTouchEvent(event));
+ EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
+
+ // Reset the insertion.
+ ClearInsertion();
+ controller().OnTapEvent();
+ ChangeInsertion(start_rect, visible);
+ ASSERT_EQ(INSERTION_SHOWN, GetLastEventType());
+
// No tap should be signalled if the touch sequence is cancelled.
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetNeedsAnimate());
}
+TEST_F(TouchSelectionControllerTest, SelectionClearOnTap) {
+ gfx::RectF start_rect(5, 5, 0, 10);
+ gfx::RectF end_rect(50, 5, 0, 10);
+ bool visible = true;
+
+ controller().OnLongPressEvent();
+ ChangeSelection(start_rect, visible, end_rect, visible);
+
+ // Selection should not be cleared if the selection bounds have not changed.
+ controller().OnTapEvent();
+ EXPECT_EQ(SELECTION_SHOWN, GetLastEventType());
+ EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor());
+
+ controller().OnTapEvent();
+ ClearSelection();
+ EXPECT_EQ(SELECTION_CLEARED, GetLastEventType());
+ EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
+}
+
} // namespace content