| Index: ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| index f79020a6946a98face783c39d3dba4842f7286d0..41bf733a25428640174f0c2c890237de873f84a9 100644
|
| --- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| +++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| @@ -103,13 +103,17 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
|
| protected:
|
| static bool IsCursorHandleVisibleFor(
|
| ui::TouchSelectionController* controller) {
|
| - return static_cast<TouchSelectionControllerImpl*>(
|
| - controller)->IsCursorHandleVisible();
|
| + TouchSelectionControllerImpl* impl =
|
| + static_cast<TouchSelectionControllerImpl*>(controller);
|
| + return impl->IsCursorHandleVisible();
|
| + }
|
| +
|
| + gfx::Rect GetCursorRect(const gfx::SelectionModel& sel) {
|
| + return textfield_->GetRenderText()->GetCursorBounds(sel, true);
|
| }
|
|
|
| gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) {
|
| - gfx::RenderText* render_text = textfield_->GetRenderText();
|
| - gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true);
|
| + gfx::Rect cursor_bounds = GetCursorRect(sel);
|
| return gfx::Point(cursor_bounds.x(), cursor_bounds.y());
|
| }
|
|
|
| @@ -118,6 +122,14 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
|
| textfield_->touch_selection_controller_.get());
|
| }
|
|
|
| + void StartTouchEditing() {
|
| + textfield_->CreateTouchSelectionControllerAndNotifyIt();
|
| + }
|
| +
|
| + void EndTouchEditing() {
|
| + textfield_->touch_selection_controller_.reset();
|
| + }
|
| +
|
| void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) {
|
| TouchSelectionControllerImpl* controller = GetSelectionController();
|
| // Do the work of OnMousePressed().
|
| @@ -135,6 +147,10 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
|
| controller->dragging_handle_ = NULL;
|
| }
|
|
|
| + gfx::NativeView GetCursorHandleNativeView() {
|
| + return GetSelectionController()->GetCursorHandleNativeView();
|
| + }
|
| +
|
| gfx::Point GetSelectionHandle1Position() {
|
| return GetSelectionController()->GetSelectionHandle1Position();
|
| }
|
| @@ -163,6 +179,15 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
|
| return textfield_->GetRenderText();
|
| }
|
|
|
| + gfx::Point GetCursorHandleDragPoint() {
|
| + gfx::Point point = GetCursorHandlePosition();
|
| + const gfx::SelectionModel& sel = textfield_->GetSelectionModel();
|
| + int cursor_height = GetCursorRect(sel).height();
|
| + point.Offset(GetHandleImageSize().width() / 2 + kPadding,
|
| + GetHandleImageSize().height() / 2 + cursor_height);
|
| + return point;
|
| + }
|
| +
|
| Widget* textfield_widget_;
|
| Widget* widget_;
|
|
|
| @@ -644,4 +669,42 @@ TEST_F(TouchSelectionControllerImplTest,
|
| touch_selection_controller.reset();
|
| }
|
|
|
| +TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) {
|
| + ui::EventTarget* root = GetContext();
|
| + ui::EventTargeter* targeter = root->GetEventTargeter();
|
| +
|
| + // Create the first window containing a Views::Textfield.
|
| + CreateTextfield();
|
| + aura::Window* window1 = textfield_widget_->GetNativeView();
|
| +
|
| + // Start touch editing, check that the handle is above the first window, and
|
| + // end touch editing.
|
| + StartTouchEditing();
|
| + gfx::Point test_point = GetCursorHandleDragPoint();
|
| + ui::MouseEvent test_event1(ui::ET_MOUSE_MOVED, test_point, test_point,
|
| + ui::EF_NONE, ui::EF_NONE);
|
| + EXPECT_EQ(GetCursorHandleNativeView(),
|
| + targeter->FindTargetForEvent(root, &test_event1));
|
| + EndTouchEditing();
|
| +
|
| + // Create the second (empty) window over the first one.
|
| + CreateWidget();
|
| + aura::Window* window2 = widget_->GetNativeView();
|
| +
|
| + // Start touch editing (in the first window) and check that the handle is not
|
| + // above the second window.
|
| + StartTouchEditing();
|
| + ui::MouseEvent test_event2(ui::ET_MOUSE_MOVED, test_point, test_point,
|
| + ui::EF_NONE, ui::EF_NONE);
|
| + EXPECT_EQ(window2, targeter->FindTargetForEvent(root, &test_event2));
|
| +
|
| + // Move the first window to top and check that the handle is kept above the
|
| + // first window.
|
| + window1->GetRootWindow()->StackChildAtTop(window1);
|
| + ui::MouseEvent test_event3(ui::ET_MOUSE_MOVED, test_point, test_point,
|
| + ui::EF_NONE, ui::EF_NONE);
|
| + EXPECT_EQ(GetCursorHandleNativeView(),
|
| + targeter->FindTargetForEvent(root, &test_event3));
|
| +}
|
| +
|
| } // namespace views
|
|
|