Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: ui/views/touchui/touch_selection_controller_impl_unittest.cc

Issue 177173007: Change type of touch selection handles to POPUP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d57205245a4daf8f3c62ffe8a2eb30949fe6162a..8246d84257fdb6551a9cbb88dd48a666d70ffe7b 100644
--- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
+++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
@@ -82,9 +82,12 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
}
protected:
+ 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());
}
@@ -93,6 +96,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().
@@ -110,6 +121,10 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
controller->dragging_handle_ = NULL;
}
+ gfx::NativeView GetCursorHandleNativeView() {
+ return GetSelectionController()->GetCursorHandleNativeView();
+ }
+
gfx::Point GetSelectionHandle1Position() {
return GetSelectionController()->GetSelectionHandle1Position();
}
@@ -138,6 +153,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* widget_;
Textfield* textfield_;
@@ -487,4 +511,50 @@ TEST_F(TouchSelectionControllerImplTest,
VERIFY_HANDLE_POSITIONS(false);
}
+TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) {
+ ui::EventTarget* root = GetContext();
+ ui::EventTargeter* targeter = root->GetEventTargeter();
+
+ // Create the first window containing a Views::Textfield.
+ CreateTextfield();
+ widget_->Show();
+ aura::Window* window1 = 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(targeter->FindTargetForEvent(root, &test_event1),
+ GetCursorHandleNativeView());
sadrul 2014/03/14 18:30:07 The alignment here is confusing. It should be alig
mohsen 2014/03/14 19:15:25 Yep, my mistake in both cases. Fixed.
+ EndTouchEditing();
+
+ // Create the second (empty) window over the first one.
+ Widget* second_widget = new Widget;
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params.bounds = gfx::Rect(0, 0, 200, 200);
+ second_widget->Init(params);
+ second_widget->Show();
+ aura::Window* window2 = second_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(targeter->FindTargetForEvent(root, &test_event2), window2);
+
+ // 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(targeter->FindTargetForEvent(root, &test_event3),
+ GetCursorHandleNativeView());
+
+ widget_->Close();
+ second_widget->Close();
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698