Commit ab40ae54 authored by Mahesh Machavolu's avatar Mahesh Machavolu Committed by Commit Bot

Return Visible Touch Handle height for RWHVA::GetTouchHandleHeight

ShowSelectionMenu queries for TouchHandle height while passing this
information to Java for positioning the Floating Popup Menu. Only
Start Handle height is being queried at all times. During an active
selection, it is possible Start Handle is hidden but End handle is
only visible. In these cases, Start handle height would be zero.
So, return end handle height in these cases.

Bug: 851346
Change-Id: I087d12d95b86abfc1068d4fb9f331837912ca7a9
Reviewed-on: https://chromium-review.googlesource.com/1094818
Commit-Queue: AJITH KUMAR V <ajith.v@samsung.com>
Reviewed-by: default avatarAJITH KUMAR V <ajith.v@samsung.com>
Reviewed-by: default avatarMohsen Izadi <mohsen@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566355}
parent 72b6f10a
......@@ -701,8 +701,7 @@ bool RenderWidgetHostViewAndroid::OnTouchHandleEvent(
int RenderWidgetHostViewAndroid::GetTouchHandleHeight() {
if (!touch_selection_controller_)
return 0;
return static_cast<int>(
touch_selection_controller_->GetStartHandleRect().height());
return static_cast<int>(touch_selection_controller_->GetTouchHandleHeight());
}
void RenderWidgetHostViewAndroid::ResetGestureDetection() {
......
......@@ -280,6 +280,18 @@ gfx::RectF TouchSelectionController::GetEndHandleRect() const {
return gfx::RectF();
}
float TouchSelectionController::GetTouchHandleHeight() const {
if (active_status_ == INSERTION_ACTIVE)
return insertion_handle_->GetVisibleBounds().height();
if (active_status_ == SELECTION_ACTIVE) {
if (GetStartVisible())
return start_selection_handle_->GetVisibleBounds().height();
if (GetEndVisible())
return end_selection_handle_->GetVisibleBounds().height();
}
return 0.f;
}
float TouchSelectionController::GetActiveHandleMiddleY() const {
const gfx::SelectionBound* bound = nullptr;
if (active_status_ == INSERTION_ACTIVE && insertion_handle_->IsActive())
......
......@@ -124,6 +124,10 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
gfx::RectF GetStartHandleRect() const;
gfx::RectF GetEndHandleRect() const;
// Return the handle height of visible touch handle. This value will be zero
// when no handle is visible.
float GetTouchHandleHeight() const;
// Returns the focal point of the start and end bounds, as defined by
// their bottom coordinate.
const gfx::PointF& GetStartPosition() const;
......
......@@ -1168,6 +1168,51 @@ TEST_F(TouchSelectionControllerTest, RectBetweenBounds) {
EXPECT_EQ(gfx::RectF(), controller().GetRectBetweenBounds());
}
TEST_F(TouchSelectionControllerTest, TouchHandleHeight) {
OnLongPressEvent();
SetDraggingEnabled(true);
gfx::RectF start_rect(5, 5, 0, 10);
gfx::RectF end_rect(50, 5, 0, 10);
// Handle height should be zero when there is no selection/ insertion.
EXPECT_EQ(0.f, controller().GetTouchHandleHeight());
// Insertion case - Handle shown.
ChangeInsertion(start_rect, true);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_SHOWN));
EXPECT_NE(0.f, controller().GetTouchHandleHeight());
// Insertion case - Handle moved.
start_rect.Offset(1, 0);
ChangeInsertion(start_rect, true);
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_MOVED));
EXPECT_NE(0.f, controller().GetTouchHandleHeight());
ClearInsertion();
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_HANDLE_CLEARED));
EXPECT_EQ(0.f, controller().GetTouchHandleHeight());
// Selection case - Start and End are visible.
ChangeSelection(start_rect, true, end_rect, true);
ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_SHOWN));
EXPECT_NE(0.f, controller().GetTouchHandleHeight());
// Selection case - Only Start is visible.
ChangeSelection(start_rect, true, end_rect, false);
ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
EXPECT_NE(0.f, controller().GetTouchHandleHeight());
// Selection case - Only End is visible.
ChangeSelection(start_rect, false, end_rect, true);
ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_MOVED));
EXPECT_NE(0.f, controller().GetTouchHandleHeight());
ClearSelection();
ASSERT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_HANDLES_CLEARED));
EXPECT_EQ(0.f, controller().GetTouchHandleHeight());
}
TEST_F(TouchSelectionControllerTest, SelectionNoOrientationChangeWhenSwapped) {
TouchSelectionControllerTestApi test_controller(&controller());
base::TimeTicks event_time = base::TimeTicks::Now();
......
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