OLD | NEW |
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/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/base/touch/touch_editing_controller.h" | 9 #include "ui/base/touch/touch_editing_controller.h" |
10 #include "ui/base/ui_base_switches.h" | 10 #include "ui/base/ui_base_switches.h" |
11 #include "ui/gfx/canvas.h" | |
12 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
13 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
14 #include "ui/gfx/render_text.h" | 13 #include "ui/gfx/render_text.h" |
| 14 #include "ui/views/controls/textfield/native_textfield_views.h" |
15 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/textfield/textfield.h" |
16 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
17 #include "ui/views/touchui/touch_selection_controller_impl.h" | 17 #include "ui/views/touchui/touch_selection_controller_impl.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
21 #include "ui/aura/test/event_generator.h" | 21 #include "ui/aura/test/event_generator.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 #endif | 23 #endif |
24 | 24 |
(...skipping 19 matching lines...) Expand all Loading... |
44 } | 44 } |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 namespace views { | 47 namespace views { |
48 | 48 |
49 class TouchSelectionControllerImplTest : public ViewsTestBase { | 49 class TouchSelectionControllerImplTest : public ViewsTestBase { |
50 public: | 50 public: |
51 TouchSelectionControllerImplTest() | 51 TouchSelectionControllerImplTest() |
52 : widget_(NULL), | 52 : widget_(NULL), |
53 textfield_(NULL), | 53 textfield_(NULL), |
| 54 textfield_view_(NULL), |
54 views_tsc_factory_(new ViewsTouchSelectionControllerFactory) { | 55 views_tsc_factory_(new ViewsTouchSelectionControllerFactory) { |
55 CommandLine::ForCurrentProcess()->AppendSwitch( | 56 CommandLine::ForCurrentProcess()->AppendSwitch( |
56 switches::kEnableTouchEditing); | 57 switches::kEnableTouchEditing); |
57 ui::TouchSelectionControllerFactory::SetInstance(views_tsc_factory_.get()); | 58 ui::TouchSelectionControllerFactory::SetInstance(views_tsc_factory_.get()); |
58 } | 59 } |
59 | 60 |
60 virtual ~TouchSelectionControllerImplTest() { | 61 virtual ~TouchSelectionControllerImplTest() { |
61 ui::TouchSelectionControllerFactory::SetInstance(NULL); | 62 ui::TouchSelectionControllerFactory::SetInstance(NULL); |
62 } | 63 } |
63 | 64 |
64 virtual void TearDown() { | 65 virtual void TearDown() { |
65 if (widget_) | 66 if (widget_) |
66 widget_->Close(); | 67 widget_->Close(); |
67 ViewsTestBase::TearDown(); | 68 ViewsTestBase::TearDown(); |
68 } | 69 } |
69 | 70 |
70 void CreateTextfield() { | 71 void CreateTextfield() { |
71 textfield_ = new Textfield(); | 72 textfield_ = new Textfield(); |
72 widget_ = new Widget; | 73 widget_ = new Widget; |
73 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 74 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
74 params.bounds = gfx::Rect(0, 0, 200, 200); | 75 params.bounds = gfx::Rect(0, 0, 200, 200); |
75 widget_->Init(params); | 76 widget_->Init(params); |
76 View* container = new View(); | 77 View* container = new View(); |
77 widget_->SetContentsView(container); | 78 widget_->SetContentsView(container); |
78 container->AddChildView(textfield_); | 79 container->AddChildView(textfield_); |
79 | 80 |
| 81 textfield_view_ = textfield_->GetTextfieldViewForTesting(); |
80 textfield_->SetBoundsRect(params.bounds); | 82 textfield_->SetBoundsRect(params.bounds); |
| 83 textfield_view_->SetBoundsRect(params.bounds); |
81 textfield_->set_id(1); | 84 textfield_->set_id(1); |
82 widget_->Show(); | 85 widget_->Show(); |
83 | 86 |
| 87 DCHECK(textfield_view_); |
84 textfield_->RequestFocus(); | 88 textfield_->RequestFocus(); |
85 } | 89 } |
86 | 90 |
87 protected: | 91 protected: |
88 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { | 92 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { |
89 gfx::RenderText* render_text = textfield_->GetRenderText(); | 93 gfx::RenderText* render_text = textfield_view_->GetRenderText(); |
90 gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true); | 94 gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true); |
91 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); | 95 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); |
92 } | 96 } |
93 | 97 |
94 TouchSelectionControllerImpl* GetSelectionController() { | 98 TouchSelectionControllerImpl* GetSelectionController() { |
95 return static_cast<TouchSelectionControllerImpl*>( | 99 return static_cast<TouchSelectionControllerImpl*>( |
96 textfield_->touch_selection_controller_.get()); | 100 textfield_view_->touch_selection_controller_.get()); |
97 } | 101 } |
98 | 102 |
99 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { | 103 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { |
100 TouchSelectionControllerImpl* controller = GetSelectionController(); | 104 TouchSelectionControllerImpl* controller = GetSelectionController(); |
101 // Do the work of OnMousePressed(). | 105 // Do the work of OnMousePressed(). |
102 if (selection_handle == 1) | 106 if (selection_handle == 1) |
103 controller->SetDraggingHandle(controller->selection_handle_1_.get()); | 107 controller->SetDraggingHandle(controller->selection_handle_1_.get()); |
104 else | 108 else |
105 controller->SetDraggingHandle(controller->selection_handle_2_.get()); | 109 controller->SetDraggingHandle(controller->selection_handle_2_.get()); |
106 | 110 |
(...skipping 24 matching lines...) Expand all Loading... |
131 | 135 |
132 bool IsSelectionHandle2Visible() { | 136 bool IsSelectionHandle2Visible() { |
133 return GetSelectionController()->IsSelectionHandle2Visible(); | 137 return GetSelectionController()->IsSelectionHandle2Visible(); |
134 } | 138 } |
135 | 139 |
136 bool IsCursorHandleVisible() { | 140 bool IsCursorHandleVisible() { |
137 return GetSelectionController()->IsCursorHandleVisible(); | 141 return GetSelectionController()->IsCursorHandleVisible(); |
138 } | 142 } |
139 | 143 |
140 gfx::RenderText* GetRenderText() { | 144 gfx::RenderText* GetRenderText() { |
141 return textfield_->GetRenderText(); | 145 return textfield_view_->GetRenderText(); |
142 } | 146 } |
143 | 147 |
144 Widget* widget_; | 148 Widget* widget_; |
145 | 149 |
146 Textfield* textfield_; | 150 Textfield* textfield_; |
| 151 NativeTextfieldViews* textfield_view_; |
147 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; | 152 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; |
148 | 153 |
149 private: | 154 private: |
150 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); | 155 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); |
151 }; | 156 }; |
152 | 157 |
153 // If textfield has selection, this macro verifies that the selection handles | 158 // If textfield has selection, this macro verifies that the selection handles |
154 // are visible and at the correct positions (at the end points of selection). | 159 // are visible and at the correct positions (at the end points of selection). |
155 // |cursor_at_selection_handle_1| is used to decide whether selection | 160 // |cursor_at_selection_handle_1| is used to decide whether selection |
156 // handle 1's position is matched against the start of selection or the end. | 161 // handle 1's position is matched against the start of selection or the end. |
157 #define VERIFY_HANDLE_POSITIONS(cursor_at_selection_handle_1) \ | 162 #define VERIFY_HANDLE_POSITIONS(cursor_at_selection_handle_1) \ |
158 { \ | 163 { \ |
159 gfx::SelectionModel sel = textfield_->GetSelectionModel(); \ | 164 gfx::SelectionModel sel = textfield_view_->GetSelectionModel(); \ |
160 if (textfield_->HasSelection()) { \ | 165 if (textfield_->HasSelection()) { \ |
161 EXPECT_TRUE(IsSelectionHandle1Visible()); \ | 166 EXPECT_TRUE(IsSelectionHandle1Visible()); \ |
162 EXPECT_TRUE(IsSelectionHandle2Visible()); \ | 167 EXPECT_TRUE(IsSelectionHandle2Visible()); \ |
163 EXPECT_FALSE(IsCursorHandleVisible()); \ | 168 EXPECT_FALSE(IsCursorHandleVisible()); \ |
164 gfx::SelectionModel sel_start = GetRenderText()-> \ | 169 gfx::SelectionModel sel_start = GetRenderText()-> \ |
165 GetSelectionModelForSelectionStart(); \ | 170 GetSelectionModelForSelectionStart(); \ |
166 gfx::Point selection_start = GetCursorPosition(sel_start); \ | 171 gfx::Point selection_start = GetCursorPosition(sel_start); \ |
167 gfx::Point selection_end = GetCursorPosition(sel); \ | 172 gfx::Point selection_end = GetCursorPosition(sel); \ |
168 gfx::Point sh1 = GetSelectionHandle1Position(); \ | 173 gfx::Point sh1 = GetSelectionHandle1Position(); \ |
169 gfx::Point sh2 = GetSelectionHandle2Position(); \ | 174 gfx::Point sh2 = GetSelectionHandle2Position(); \ |
(...skipping 18 matching lines...) Expand all Loading... |
188 } | 193 } |
189 | 194 |
190 // Tests that the selection handles are placed appropriately when selection in | 195 // Tests that the selection handles are placed appropriately when selection in |
191 // a Textfield changes. | 196 // a Textfield changes. |
192 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { | 197 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { |
193 CreateTextfield(); | 198 CreateTextfield(); |
194 textfield_->SetText(ASCIIToUTF16("some text")); | 199 textfield_->SetText(ASCIIToUTF16("some text")); |
195 // Tap the textfield to invoke touch selection. | 200 // Tap the textfield to invoke touch selection. |
196 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), | 201 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), |
197 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); | 202 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); |
198 textfield_->OnGestureEvent(&tap); | 203 textfield_view_->OnGestureEvent(&tap); |
199 | 204 |
200 // Test selecting a range. | 205 // Test selecting a range. |
201 textfield_->SelectRange(gfx::Range(3, 7)); | 206 textfield_->SelectRange(gfx::Range(3, 7)); |
202 VERIFY_HANDLE_POSITIONS(false); | 207 VERIFY_HANDLE_POSITIONS(false); |
203 | 208 |
204 // Test selecting everything. | 209 // Test selecting everything. |
205 textfield_->SelectAll(false); | 210 textfield_->SelectAll(false); |
206 VERIFY_HANDLE_POSITIONS(false); | 211 VERIFY_HANDLE_POSITIONS(false); |
207 | 212 |
208 // Test with no selection. | 213 // Test with no selection. |
209 textfield_->ClearSelection(); | 214 textfield_->ClearSelection(); |
210 VERIFY_HANDLE_POSITIONS(false); | 215 VERIFY_HANDLE_POSITIONS(false); |
211 | 216 |
212 // Test with lost focus. | 217 // Test with lost focus. |
213 widget_->GetFocusManager()->ClearFocus(); | 218 widget_->GetFocusManager()->ClearFocus(); |
214 EXPECT_FALSE(GetSelectionController()); | 219 EXPECT_FALSE(GetSelectionController()); |
215 | 220 |
216 // Test with focus re-gained. | 221 // Test with focus re-gained. |
217 widget_->GetFocusManager()->SetFocusedView(textfield_); | 222 widget_->GetFocusManager()->SetFocusedView(textfield_); |
218 EXPECT_FALSE(GetSelectionController()); | 223 EXPECT_FALSE(GetSelectionController()); |
219 textfield_->OnGestureEvent(&tap); | 224 textfield_view_->OnGestureEvent(&tap); |
220 VERIFY_HANDLE_POSITIONS(false); | 225 VERIFY_HANDLE_POSITIONS(false); |
221 } | 226 } |
222 | 227 |
223 // Tests that the selection handles are placed appropriately in bidi text. | 228 // Tests that the selection handles are placed appropriately in bidi text. |
224 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { | 229 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { |
225 CreateTextfield(); | 230 CreateTextfield(); |
226 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); | 231 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
227 // Tap the textfield to invoke touch selection. | 232 // Tap the textfield to invoke touch selection. |
228 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), | 233 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), |
229 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); | 234 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); |
230 textfield_->OnGestureEvent(&tap); | 235 textfield_view_->OnGestureEvent(&tap); |
231 | 236 |
232 // Test cursor at run boundary and with empty selection. | 237 // Test cursor at run boundary and with empty selection. |
233 textfield_->SelectSelectionModel( | 238 textfield_->SelectSelectionModel( |
234 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD)); | 239 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD)); |
235 VERIFY_HANDLE_POSITIONS(false); | 240 VERIFY_HANDLE_POSITIONS(false); |
236 | 241 |
237 // Test selection range inside one run and starts or ends at run boundary. | 242 // Test selection range inside one run and starts or ends at run boundary. |
238 textfield_->SelectRange(gfx::Range(2, 3)); | 243 textfield_->SelectRange(gfx::Range(2, 3)); |
239 VERIFY_HANDLE_POSITIONS(false); | 244 VERIFY_HANDLE_POSITIONS(false); |
240 | 245 |
(...skipping 27 matching lines...) Expand all Loading... |
268 } | 273 } |
269 | 274 |
270 // Tests if the SelectRect callback is called appropriately when selection | 275 // Tests if the SelectRect callback is called appropriately when selection |
271 // handles are moved. | 276 // handles are moved. |
272 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { | 277 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { |
273 CreateTextfield(); | 278 CreateTextfield(); |
274 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); | 279 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); |
275 // Tap the textfield to invoke touch selection. | 280 // Tap the textfield to invoke touch selection. |
276 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), | 281 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), |
277 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); | 282 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); |
278 textfield_->OnGestureEvent(&tap); | 283 textfield_view_->OnGestureEvent(&tap); |
279 textfield_->SelectRange(gfx::Range(3, 7)); | 284 textfield_->SelectRange(gfx::Range(3, 7)); |
280 | 285 |
281 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); | 286 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); |
282 VERIFY_HANDLE_POSITIONS(false); | 287 VERIFY_HANDLE_POSITIONS(false); |
283 | 288 |
284 // Drag selection handle 2 to right by 3 chars. | 289 // Drag selection handle 2 to right by 3 chars. |
285 const gfx::FontList& font_list = textfield_->GetFontList(); | 290 const gfx::Font& font = textfield_->GetPrimaryFont(); |
286 int x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("ld "), font_list); | 291 int x = font.GetStringWidth(ASCIIToUTF16("ld ")); |
287 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 292 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
288 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield "); | 293 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield "); |
289 VERIFY_HANDLE_POSITIONS(false); | 294 VERIFY_HANDLE_POSITIONS(false); |
290 | 295 |
291 // Drag selection handle 1 to the left by a large amount (selection should | 296 // Drag selection handle 1 to the left by a large amount (selection should |
292 // just stick to the beginning of the textfield). | 297 // just stick to the beginning of the textfield). |
293 SimulateSelectionHandleDrag(gfx::Point(-50, 0), 1); | 298 SimulateSelectionHandleDrag(gfx::Point(-50, 0), 1); |
294 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "textfield "); | 299 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "textfield "); |
295 VERIFY_HANDLE_POSITIONS(true); | 300 VERIFY_HANDLE_POSITIONS(true); |
296 | 301 |
297 // Drag selection handle 1 across selection handle 2. | 302 // Drag selection handle 1 across selection handle 2. |
298 x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("textfield with "), font_list); | 303 x = font.GetStringWidth(ASCIIToUTF16("textfield with ")); |
299 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); | 304 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); |
300 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with "); | 305 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with "); |
301 VERIFY_HANDLE_POSITIONS(true); | 306 VERIFY_HANDLE_POSITIONS(true); |
302 | 307 |
303 // Drag selection handle 2 across selection handle 1. | 308 // Drag selection handle 2 across selection handle 1. |
304 x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("with selected "), font_list); | 309 x = font.GetStringWidth(ASCIIToUTF16("with selected ")); |
305 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 310 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
306 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); | 311 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); |
307 VERIFY_HANDLE_POSITIONS(false); | 312 VERIFY_HANDLE_POSITIONS(false); |
308 } | 313 } |
309 | 314 |
310 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { | 315 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { |
311 CreateTextfield(); | 316 CreateTextfield(); |
312 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); | 317 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); |
313 // Tap the textfield to invoke touch selection. | 318 // Tap the textfield to invoke touch selection. |
314 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), | 319 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), |
315 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); | 320 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); |
316 textfield_->OnGestureEvent(&tap); | 321 textfield_view_->OnGestureEvent(&tap); |
317 | 322 |
318 // Select [c] from left to right. | 323 // Select [c] from left to right. |
319 textfield_->SelectRange(gfx::Range(2, 3)); | 324 textfield_->SelectRange(gfx::Range(2, 3)); |
320 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); | 325 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); |
321 VERIFY_HANDLE_POSITIONS(false); | 326 VERIFY_HANDLE_POSITIONS(false); |
322 | 327 |
323 // Drag selection handle 2 to right by 1 char. | 328 // Drag selection handle 2 to right by 1 char. |
324 const gfx::FontList& font_list = textfield_->GetFontList(); | 329 const gfx::Font& font = textfield_->GetPrimaryFont(); |
325 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list); | 330 int x = font.GetStringWidth(WideToUTF16(L"\x05e3")); |
326 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 331 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
327 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); | 332 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); |
328 VERIFY_HANDLE_POSITIONS(false); | 333 VERIFY_HANDLE_POSITIONS(false); |
329 | 334 |
330 // Drag selection handle 1 to left by 1 char. | 335 // Drag selection handle 1 to left by 1 char. |
331 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list); | 336 x = font.GetStringWidth(WideToUTF16(L"b")); |
332 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); | 337 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); |
333 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); | 338 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); |
334 VERIFY_HANDLE_POSITIONS(true); | 339 VERIFY_HANDLE_POSITIONS(true); |
335 | 340 |
336 // Select [c] from right to left. | 341 // Select [c] from right to left. |
337 textfield_->SelectRange(gfx::Range(3, 2)); | 342 textfield_->SelectRange(gfx::Range(3, 2)); |
338 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); | 343 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); |
339 VERIFY_HANDLE_POSITIONS(false); | 344 VERIFY_HANDLE_POSITIONS(false); |
340 | 345 |
341 // Drag selection handle 1 to right by 1 char. | 346 // Drag selection handle 1 to right by 1 char. |
342 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list); | 347 x = font.GetStringWidth(WideToUTF16(L"\x05e3")); |
343 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); | 348 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); |
344 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); | 349 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); |
345 VERIFY_HANDLE_POSITIONS(true); | 350 VERIFY_HANDLE_POSITIONS(true); |
346 | 351 |
347 // Drag selection handle 2 to left by 1 char. | 352 // Drag selection handle 2 to left by 1 char. |
348 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list); | 353 x = font.GetStringWidth(WideToUTF16(L"b")); |
349 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); | 354 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); |
350 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); | 355 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); |
351 VERIFY_HANDLE_POSITIONS(false); | 356 VERIFY_HANDLE_POSITIONS(false); |
352 | 357 |
353 // Select [\x5e1] from right to left. | 358 // Select [\x5e1] from right to left. |
354 textfield_->SelectRange(gfx::Range(3, 4)); | 359 textfield_->SelectRange(gfx::Range(3, 4)); |
355 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); | 360 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); |
356 VERIFY_HANDLE_POSITIONS(false); | 361 VERIFY_HANDLE_POSITIONS(false); |
357 | 362 |
358 /* TODO(xji): for bidi text "abcDEF" whose display is "abcFEDhij", when click | 363 /* TODO(xji): for bidi text "abcDEF" whose display is "abcFEDhij", when click |
359 right of 'D' and select [D] then move the left selection handle to left | 364 right of 'D' and select [D] then move the left selection handle to left |
360 by one character, it should select [ED], instead it selects [F]. | 365 by one character, it should select [ED], instead it selects [F]. |
361 Reason: click right of 'D' and left of 'h' return the same x-axis position, | 366 Reason: click right of 'D' and left of 'h' return the same x-axis position, |
362 pass this position to FindCursorPosition() returns index of 'h'. which | 367 pass this position to FindCursorPosition() returns index of 'h'. which |
363 means the selection start changed from 3 to 6. | 368 means the selection start changed from 3 to 6. |
364 Need further investigation on whether this is a bug in Pango and how to | 369 Need further investigation on whether this is a bug in Pango and how to |
365 work around it. | 370 work around it. |
366 // Drag selection handle 2 to left by 1 char. | 371 // Drag selection handle 2 to left by 1 char. |
367 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list); | 372 x = font.GetStringWidth(WideToUTF16(L"\x05e2")); |
368 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); | 373 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); |
369 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); | 374 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); |
370 VERIFY_HANDLE_POSITIONS(false); | 375 VERIFY_HANDLE_POSITIONS(false); |
371 */ | 376 */ |
372 | 377 |
373 // Drag selection handle 1 to right by 1 char. | 378 // Drag selection handle 1 to right by 1 char. |
374 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list); | 379 x = font.GetStringWidth(WideToUTF16(L"d")); |
375 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); | 380 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); |
376 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); | 381 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); |
377 VERIFY_HANDLE_POSITIONS(true); | 382 VERIFY_HANDLE_POSITIONS(true); |
378 | 383 |
379 // Select [\x5e1] from left to right. | 384 // Select [\x5e1] from left to right. |
380 textfield_->SelectRange(gfx::Range(4, 3)); | 385 textfield_->SelectRange(gfx::Range(4, 3)); |
381 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); | 386 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); |
382 VERIFY_HANDLE_POSITIONS(false); | 387 VERIFY_HANDLE_POSITIONS(false); |
383 | 388 |
384 /* TODO(xji): see detail of above commented out test case. | 389 /* TODO(xji): see detail of above commented out test case. |
385 // Drag selection handle 1 to left by 1 char. | 390 // Drag selection handle 1 to left by 1 char. |
386 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list); | 391 x = font.GetStringWidth(WideToUTF16(L"\x05e2")); |
387 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); | 392 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); |
388 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); | 393 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); |
389 VERIFY_HANDLE_POSITIONS(true); | 394 VERIFY_HANDLE_POSITIONS(true); |
390 */ | 395 */ |
391 | 396 |
392 // Drag selection handle 2 to right by 1 char. | 397 // Drag selection handle 2 to right by 1 char. |
393 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list); | 398 x = font.GetStringWidth(WideToUTF16(L"d")); |
394 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 399 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
395 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); | 400 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); |
396 VERIFY_HANDLE_POSITIONS(false); | 401 VERIFY_HANDLE_POSITIONS(false); |
397 | 402 |
398 // Select [\x05r3] from right to left. | 403 // Select [\x05r3] from right to left. |
399 textfield_->SelectRange(gfx::Range(5, 6)); | 404 textfield_->SelectRange(gfx::Range(5, 6)); |
400 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); | 405 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); |
401 VERIFY_HANDLE_POSITIONS(false); | 406 VERIFY_HANDLE_POSITIONS(false); |
402 | 407 |
403 // Drag selection handle 2 to left by 1 char. | 408 // Drag selection handle 2 to left by 1 char. |
404 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list); | 409 x = font.GetStringWidth(WideToUTF16(L"c")); |
405 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); | 410 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); |
406 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); | 411 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); |
407 VERIFY_HANDLE_POSITIONS(false); | 412 VERIFY_HANDLE_POSITIONS(false); |
408 | 413 |
409 // Drag selection handle 1 to right by 1 char. | 414 // Drag selection handle 1 to right by 1 char. |
410 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list); | 415 x = font.GetStringWidth(WideToUTF16(L"\x05e2")); |
411 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); | 416 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); |
412 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); | 417 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); |
413 VERIFY_HANDLE_POSITIONS(true); | 418 VERIFY_HANDLE_POSITIONS(true); |
414 | 419 |
415 // Select [\x05r3] from left to right. | 420 // Select [\x05r3] from left to right. |
416 textfield_->SelectRange(gfx::Range(6, 5)); | 421 textfield_->SelectRange(gfx::Range(6, 5)); |
417 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); | 422 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); |
418 VERIFY_HANDLE_POSITIONS(false); | 423 VERIFY_HANDLE_POSITIONS(false); |
419 | 424 |
420 // Drag selection handle 1 to left by 1 char. | 425 // Drag selection handle 1 to left by 1 char. |
421 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list); | 426 x = font.GetStringWidth(WideToUTF16(L"c")); |
422 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); | 427 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); |
423 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); | 428 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); |
424 VERIFY_HANDLE_POSITIONS(true); | 429 VERIFY_HANDLE_POSITIONS(true); |
425 | 430 |
426 // Drag selection handle 2 to right by 1 char. | 431 // Drag selection handle 2 to right by 1 char. |
427 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list); | 432 x = font.GetStringWidth(WideToUTF16(L"\x05e2")); |
428 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 433 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
429 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); | 434 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); |
430 VERIFY_HANDLE_POSITIONS(false); | 435 VERIFY_HANDLE_POSITIONS(false); |
431 } | 436 } |
432 | 437 |
433 TEST_F(TouchSelectionControllerImplTest, | 438 TEST_F(TouchSelectionControllerImplTest, |
434 HiddenSelectionHandleRetainsCursorPosition) { | 439 HiddenSelectionHandleRetainsCursorPosition) { |
435 // Create a textfield with lots of text in it. | 440 // Create a textfield with lots of text in it. |
436 CreateTextfield(); | 441 CreateTextfield(); |
437 std::string textfield_text("some text"); | 442 std::string textfield_text("some text"); |
438 for (int i = 0; i < 10; ++i) | 443 for (int i = 0; i < 10; ++i) |
439 textfield_text += textfield_text; | 444 textfield_text += textfield_text; |
440 textfield_->SetText(ASCIIToUTF16(textfield_text)); | 445 textfield_->SetText(ASCIIToUTF16(textfield_text)); |
441 | 446 |
442 // Tap the textfield to invoke selection. | 447 // Tap the textfield to invoke selection. |
443 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), | 448 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), |
444 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); | 449 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); |
445 textfield_->OnGestureEvent(&tap); | 450 textfield_view_->OnGestureEvent(&tap); |
446 | 451 |
447 // Select some text such that one handle is hidden. | 452 // Select some text such that one handle is hidden. |
448 textfield_->SelectRange(gfx::Range(10, textfield_text.length())); | 453 textfield_->SelectRange(gfx::Range(10, textfield_text.length())); |
449 | 454 |
450 // Check that one selection handle is hidden. | 455 // Check that one selection handle is hidden. |
451 EXPECT_FALSE(IsSelectionHandle1Visible()); | 456 EXPECT_FALSE(IsSelectionHandle1Visible()); |
452 EXPECT_TRUE(IsSelectionHandle2Visible()); | 457 EXPECT_TRUE(IsSelectionHandle2Visible()); |
453 EXPECT_EQ(gfx::Range(10, textfield_text.length()), | 458 EXPECT_EQ(gfx::Range(10, textfield_text.length()), |
454 textfield_->GetSelectedRange()); | 459 textfield_->GetSelectedRange()); |
455 | 460 |
(...skipping 30 matching lines...) Expand all Loading... |
486 gfx::Point cursor_pos = GetCursorHandlePosition(); | 491 gfx::Point cursor_pos = GetCursorHandlePosition(); |
487 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); | 492 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); |
488 generator.GestureTapAt(cursor_pos); | 493 generator.GestureTapAt(cursor_pos); |
489 generator.GestureTapAt(cursor_pos); | 494 generator.GestureTapAt(cursor_pos); |
490 EXPECT_TRUE(textfield_->HasSelection()); | 495 EXPECT_TRUE(textfield_->HasSelection()); |
491 VERIFY_HANDLE_POSITIONS(false); | 496 VERIFY_HANDLE_POSITIONS(false); |
492 } | 497 } |
493 #endif | 498 #endif |
494 | 499 |
495 } // namespace views | 500 } // namespace views |
OLD | NEW |