Commit 441a7914 authored by ajith.v@samsung.com's avatar ajith.v@samsung.com

Properly reposition the paste popup after a resize

Normally, the paste popup is hidden when its position changes. However, there
are legitimate cases outside of scrolling where the position may change, e.g.,
due to a resize, where the popup should remain visible. Handle this case by
only hiding the popup if its position changes while scrolling.

BUG=380084

Review URL: https://codereview.chromium.org/312293002

Cr-Commit-Position: refs/heads/master@{#288404}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288404 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e1a2ec0
...@@ -18,3 +18,4 @@ DEFINE_SELECTION_EVENT_TYPE(INSERTION_SHOWN, 2) ...@@ -18,3 +18,4 @@ DEFINE_SELECTION_EVENT_TYPE(INSERTION_SHOWN, 2)
DEFINE_SELECTION_EVENT_TYPE(INSERTION_MOVED, 3) DEFINE_SELECTION_EVENT_TYPE(INSERTION_MOVED, 3)
DEFINE_SELECTION_EVENT_TYPE(INSERTION_TAPPED, 4) DEFINE_SELECTION_EVENT_TYPE(INSERTION_TAPPED, 4)
DEFINE_SELECTION_EVENT_TYPE(INSERTION_CLEARED, 5) DEFINE_SELECTION_EVENT_TYPE(INSERTION_CLEARED, 5)
DEFINE_SELECTION_EVENT_TYPE(INSERTION_DRAG_STARTED, 6)
...@@ -183,8 +183,10 @@ bool TouchSelectionController::Animate(base::TimeTicks frame_time) { ...@@ -183,8 +183,10 @@ bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
} }
void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
if (&handle == insertion_handle_.get()) if (&handle == insertion_handle_.get()) {
client_->OnSelectionEvent(INSERTION_DRAG_STARTED, GetStartPosition());
return; return;
}
if (&handle == start_selection_handle_.get()) { if (&handle == start_selection_handle_.get()) {
fixed_handle_position_ = end_selection_handle_->position() - fixed_handle_position_ = end_selection_handle_->position() -
......
...@@ -374,7 +374,8 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) { ...@@ -374,7 +374,8 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed.
EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
...@@ -394,7 +395,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) { ...@@ -394,7 +395,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
0, 0,
0); 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
// Reset the insertion. // Reset the insertion.
ClearInsertion(); ClearInsertion();
...@@ -407,7 +408,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) { ...@@ -407,7 +408,7 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
} }
TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
...@@ -426,7 +427,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { ...@@ -426,7 +427,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
controller().OnTapEvent(); controller().OnTapEvent();
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
...@@ -444,7 +445,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { ...@@ -444,7 +445,7 @@ TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
controller().OnSelectionEmpty(true); controller().OnSelectionEmpty(true);
event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event)); EXPECT_TRUE(controller().WillHandleTouchEvent(event));
EXPECT_EQ(INSERTION_MOVED, GetLastEventType()); EXPECT_EQ(INSERTION_DRAG_STARTED, GetLastEventType());
EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
......
...@@ -293,6 +293,7 @@ public class ContentViewCore ...@@ -293,6 +293,7 @@ public class ContentViewCore
// Lazily created paste popup menu, triggered either via long press in an // Lazily created paste popup menu, triggered either via long press in an
// editable region or from tapping the insertion handle. // editable region or from tapping the insertion handle.
private PastePopupMenu mPastePopupMenu; private PastePopupMenu mPastePopupMenu;
private boolean mWasPastePopupShowingOnInsertionDragStart;
private PopupTouchHandleDrawableDelegate mTouchHandleDelegate; private PopupTouchHandleDrawableDelegate mTouchHandleDelegate;
...@@ -2209,14 +2210,24 @@ public class ContentViewCore ...@@ -2209,14 +2210,24 @@ public class ContentViewCore
mHasInsertion = true; mHasInsertion = true;
break; break;
case SelectionEventType.INSERTION_MOVED: case SelectionEventType.INSERTION_DRAG_STARTED:
// TODO(jdduke): Handle case where movement triggered by focus. mWasPastePopupShowingOnInsertionDragStart =
mPastePopupMenu != null && mPastePopupMenu.isShowing();
hidePastePopup(); hidePastePopup();
break; break;
case SelectionEventType.INSERTION_MOVED:
if (mPastePopupMenu == null) break;
if (!isScrollInProgress() && mPastePopupMenu.isShowing()) {
showPastePopup((int) posXDip, (int) posYDip);
} else {
hidePastePopup();
}
break;
case SelectionEventType.INSERTION_TAPPED: case SelectionEventType.INSERTION_TAPPED:
if (getPastePopup().isShowing()) if (mWasPastePopupShowingOnInsertionDragStart)
mPastePopupMenu.hide(); hidePastePopup();
else else
showPastePopup((int) posXDip, (int) posYDip); showPastePopup((int) posXDip, (int) posYDip);
break; break;
......
...@@ -171,7 +171,11 @@ public class PastePopupMenu implements OnClickListener { ...@@ -171,7 +171,11 @@ public class PastePopupMenu implements OnClickListener {
coords[0] = Math.min(screenWidth - width, coords[0]); coords[0] = Math.min(screenWidth - width, coords[0]);
} }
mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], coords[1]); if (!isShowing()) {
mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], coords[1]);
} else {
mContainer.update(coords[0], coords[1], -1, -1);
}
} }
private int viewIndex(boolean onTop) { private int viewIndex(boolean onTop) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment