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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "ui/aura/test/event_generator.h" 8 #include "ui/aura/test/event_generator.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 container->AddChildView(textfield_); 75 container->AddChildView(textfield_);
76 76
77 textfield_->SetBoundsRect(params.bounds); 77 textfield_->SetBoundsRect(params.bounds);
78 textfield_->set_id(1); 78 textfield_->set_id(1);
79 widget_->Show(); 79 widget_->Show();
80 80
81 textfield_->RequestFocus(); 81 textfield_->RequestFocus();
82 } 82 }
83 83
84 protected: 84 protected:
85 gfx::Rect GetCursorRect(const gfx::SelectionModel& sel) {
86 return textfield_->GetRenderText()->GetCursorBounds(sel, true);
87 }
88
85 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { 89 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) {
86 gfx::RenderText* render_text = textfield_->GetRenderText(); 90 gfx::Rect cursor_bounds = GetCursorRect(sel);
87 gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true);
88 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); 91 return gfx::Point(cursor_bounds.x(), cursor_bounds.y());
89 } 92 }
90 93
91 TouchSelectionControllerImpl* GetSelectionController() { 94 TouchSelectionControllerImpl* GetSelectionController() {
92 return static_cast<TouchSelectionControllerImpl*>( 95 return static_cast<TouchSelectionControllerImpl*>(
93 textfield_->touch_selection_controller_.get()); 96 textfield_->touch_selection_controller_.get());
94 } 97 }
95 98
99 void StartTouchEditing() {
100 textfield_->CreateTouchSelectionControllerAndNotifyIt();
101 }
102
103 void EndTouchEditing() {
104 textfield_->touch_selection_controller_.reset();
105 }
106
96 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { 107 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) {
97 TouchSelectionControllerImpl* controller = GetSelectionController(); 108 TouchSelectionControllerImpl* controller = GetSelectionController();
98 // Do the work of OnMousePressed(). 109 // Do the work of OnMousePressed().
99 if (selection_handle == 1) 110 if (selection_handle == 1)
100 controller->SetDraggingHandle(controller->selection_handle_1_.get()); 111 controller->SetDraggingHandle(controller->selection_handle_1_.get());
101 else 112 else
102 controller->SetDraggingHandle(controller->selection_handle_2_.get()); 113 controller->SetDraggingHandle(controller->selection_handle_2_.get());
103 114
104 // Offset the drag position by the selection handle radius since it is 115 // Offset the drag position by the selection handle radius since it is
105 // supposed to be in the coordinate system of the handle. 116 // supposed to be in the coordinate system of the handle.
106 p.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); 117 p.Offset(GetHandleImageSize().width() / 2 + kPadding, 0);
107 controller->SelectionHandleDragged(p); 118 controller->SelectionHandleDragged(p);
108 119
109 // Do the work of OnMouseReleased(). 120 // Do the work of OnMouseReleased().
110 controller->dragging_handle_ = NULL; 121 controller->dragging_handle_ = NULL;
111 } 122 }
112 123
124 gfx::NativeView GetCursorHandleNativeView() {
125 return GetSelectionController()->GetCursorHandleNativeView();
126 }
127
113 gfx::Point GetSelectionHandle1Position() { 128 gfx::Point GetSelectionHandle1Position() {
114 return GetSelectionController()->GetSelectionHandle1Position(); 129 return GetSelectionController()->GetSelectionHandle1Position();
115 } 130 }
116 131
117 gfx::Point GetSelectionHandle2Position() { 132 gfx::Point GetSelectionHandle2Position() {
118 return GetSelectionController()->GetSelectionHandle2Position(); 133 return GetSelectionController()->GetSelectionHandle2Position();
119 } 134 }
120 135
121 gfx::Point GetCursorHandlePosition() { 136 gfx::Point GetCursorHandlePosition() {
122 return GetSelectionController()->GetCursorHandlePosition(); 137 return GetSelectionController()->GetCursorHandlePosition();
123 } 138 }
124 139
125 bool IsSelectionHandle1Visible() { 140 bool IsSelectionHandle1Visible() {
126 return GetSelectionController()->IsSelectionHandle1Visible(); 141 return GetSelectionController()->IsSelectionHandle1Visible();
127 } 142 }
128 143
129 bool IsSelectionHandle2Visible() { 144 bool IsSelectionHandle2Visible() {
130 return GetSelectionController()->IsSelectionHandle2Visible(); 145 return GetSelectionController()->IsSelectionHandle2Visible();
131 } 146 }
132 147
133 bool IsCursorHandleVisible() { 148 bool IsCursorHandleVisible() {
134 return GetSelectionController()->IsCursorHandleVisible(); 149 return GetSelectionController()->IsCursorHandleVisible();
135 } 150 }
136 151
137 gfx::RenderText* GetRenderText() { 152 gfx::RenderText* GetRenderText() {
138 return textfield_->GetRenderText(); 153 return textfield_->GetRenderText();
139 } 154 }
140 155
156 gfx::Point GetCursorHandleDragPoint() {
157 gfx::Point point = GetCursorHandlePosition();
158 const gfx::SelectionModel& sel = textfield_->GetSelectionModel();
159 int cursor_height = GetCursorRect(sel).height();
160 point.Offset(GetHandleImageSize().width() / 2 + kPadding,
161 GetHandleImageSize().height() / 2 + cursor_height);
162 return point;
163 }
164
141 Widget* widget_; 165 Widget* widget_;
142 166
143 Textfield* textfield_; 167 Textfield* textfield_;
144 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; 168 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
145 169
146 private: 170 private:
147 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); 171 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest);
148 }; 172 };
149 173
150 // If textfield has selection, this macro verifies that the selection handles 174 // If textfield has selection, this macro verifies that the selection handles
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // handle is not eating the event and that the event is falling through to the 504 // handle is not eating the event and that the event is falling through to the
481 // textfield. 505 // textfield.
482 gfx::Point cursor_pos = GetCursorHandlePosition(); 506 gfx::Point cursor_pos = GetCursorHandlePosition();
483 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); 507 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0);
484 generator.GestureTapAt(cursor_pos); 508 generator.GestureTapAt(cursor_pos);
485 generator.GestureTapAt(cursor_pos); 509 generator.GestureTapAt(cursor_pos);
486 EXPECT_TRUE(textfield_->HasSelection()); 510 EXPECT_TRUE(textfield_->HasSelection());
487 VERIFY_HANDLE_POSITIONS(false); 511 VERIFY_HANDLE_POSITIONS(false);
488 } 512 }
489 513
514 TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) {
515 ui::EventTarget* root = GetContext();
516 ui::EventTargeter* targeter = root->GetEventTargeter();
517
518 // Create the first window containing a Views::Textfield.
519 CreateTextfield();
520 widget_->Show();
521 aura::Window* window1 = widget_->GetNativeView();
522
523 // Start touch editing, check that the handle is above the first window, and
524 // end touch editing.
525 StartTouchEditing();
526 gfx::Point test_point = GetCursorHandleDragPoint();
527 ui::MouseEvent test_event1(ui::ET_MOUSE_MOVED, test_point, test_point,
528 ui::EF_NONE, ui::EF_NONE);
529 EXPECT_EQ(targeter->FindTargetForEvent(root, &test_event1),
530 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.
531 EndTouchEditing();
532
533 // Create the second (empty) window over the first one.
534 Widget* second_widget = new Widget;
535 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
536 params.bounds = gfx::Rect(0, 0, 200, 200);
537 second_widget->Init(params);
538 second_widget->Show();
539 aura::Window* window2 = second_widget->GetNativeView();
540
541 // Start touch editing (in the first window) and check that the handle is not
542 // above the second window.
543 StartTouchEditing();
544 ui::MouseEvent test_event2(ui::ET_MOUSE_MOVED, test_point, test_point,
545 ui::EF_NONE, ui::EF_NONE);
546 EXPECT_EQ(targeter->FindTargetForEvent(root, &test_event2), window2);
547
548 // Move the first window to top and check that the handle is kept above the
549 // first window.
550 window1->GetRootWindow()->StackChildAtTop(window1);
551 ui::MouseEvent test_event3(ui::ET_MOUSE_MOVED, test_point, test_point,
552 ui::EF_NONE, ui::EF_NONE);
553 EXPECT_EQ(targeter->FindTargetForEvent(root, &test_event3),
554 GetCursorHandleNativeView());
555
556 widget_->Close();
557 second_widget->Close();
558 }
559
490 } // namespace views 560 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698