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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views_unittest.cc

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 clipboard_writer.WriteText(ASCIIToUTF16(text)); 262 clipboard_writer.WriteText(ASCIIToUTF16(text));
263 } 263 }
264 264
265 View* GetFocusedView() { 265 View* GetFocusedView() {
266 return widget_->GetFocusManager()->GetFocusedView(); 266 return widget_->GetFocusManager()->GetFocusedView();
267 } 267 }
268 268
269 int GetCursorPositionX(int cursor_pos) { 269 int GetCursorPositionX(int cursor_pos) {
270 gfx::RenderText* render_text = textfield_view_->GetRenderText(); 270 gfx::RenderText* render_text = textfield_view_->GetRenderText();
271 return render_text->GetCursorBounds( 271 return render_text->GetCursorBounds(
272 gfx::SelectionModel(cursor_pos), false).x(); 272 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x();
273 } 273 }
274 274
275 // Get the current cursor bounds. 275 // Get the current cursor bounds.
276 gfx::Rect GetCursorBounds() { 276 gfx::Rect GetCursorBounds() {
277 gfx::RenderText* render_text = textfield_view_->GetRenderText(); 277 gfx::RenderText* render_text = textfield_view_->GetRenderText();
278 gfx::Rect bounds = render_text->GetUpdatedCursorBounds(); 278 gfx::Rect bounds = render_text->GetUpdatedCursorBounds();
279 return bounds; 279 return bounds;
280 } 280 }
281 281
282 // Get the cursor bounds of |sel|. 282 // Get the cursor bounds of |sel|.
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 // Reset locale. 1343 // Reset locale.
1344 base::i18n::SetICUDefaultLocale(locale); 1344 base::i18n::SetICUDefaultLocale(locale);
1345 } 1345 }
1346 1346
1347 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) { 1347 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) {
1348 InitTextfield(Textfield::STYLE_DEFAULT); 1348 InitTextfield(Textfield::STYLE_DEFAULT);
1349 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); 1349 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
1350 std::vector<gfx::Rect> cursor_bounds; 1350 std::vector<gfx::Rect> cursor_bounds;
1351 1351
1352 // Save each cursor bound. 1352 // Save each cursor bound.
1353 gfx::SelectionModel sel(0, 0, gfx::SelectionModel::LEADING); 1353 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD);
1354 cursor_bounds.push_back(GetCursorBounds(sel)); 1354 cursor_bounds.push_back(GetCursorBounds(sel));
1355 1355
1356 sel = gfx::SelectionModel(1, 0, gfx::SelectionModel::TRAILING); 1356 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD);
1357 gfx::Rect bound = GetCursorBounds(sel); 1357 gfx::Rect bound = GetCursorBounds(sel);
1358 sel = gfx::SelectionModel(1, 1, gfx::SelectionModel::LEADING); 1358 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD);
1359 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); 1359 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x());
1360 cursor_bounds.push_back(bound); 1360 cursor_bounds.push_back(bound);
1361 1361
1362 // Check that a cursor at the end of the Latin portion of the text is at the 1362 // Check that a cursor at the end of the Latin portion of the text is at the
1363 // same position as a cursor placed at the end of the RTL Hebrew portion. 1363 // same position as a cursor placed at the end of the RTL Hebrew portion.
1364 sel = gfx::SelectionModel(2, 1, gfx::SelectionModel::TRAILING); 1364 sel = gfx::SelectionModel(2, gfx::CURSOR_BACKWARD);
1365 bound = GetCursorBounds(sel); 1365 bound = GetCursorBounds(sel);
1366 sel = gfx::SelectionModel(4, 3, gfx::SelectionModel::TRAILING); 1366 sel = gfx::SelectionModel(4, gfx::CURSOR_BACKWARD);
1367 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); 1367 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x());
1368 cursor_bounds.push_back(bound); 1368 cursor_bounds.push_back(bound);
1369 1369
1370 sel = gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING); 1370 sel = gfx::SelectionModel(3, gfx::CURSOR_BACKWARD);
1371 bound = GetCursorBounds(sel); 1371 bound = GetCursorBounds(sel);
1372 sel = gfx::SelectionModel(3, 3, gfx::SelectionModel::LEADING); 1372 sel = gfx::SelectionModel(3, gfx::CURSOR_FORWARD);
1373 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); 1373 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x());
1374 cursor_bounds.push_back(bound); 1374 cursor_bounds.push_back(bound);
1375 1375
1376 sel = gfx::SelectionModel(2, 2, gfx::SelectionModel::LEADING); 1376 sel = gfx::SelectionModel(2, gfx::CURSOR_FORWARD);
1377 bound = GetCursorBounds(sel); 1377 bound = GetCursorBounds(sel);
1378 sel = gfx::SelectionModel(4, 2, gfx::SelectionModel::LEADING); 1378 sel = gfx::SelectionModel(4, gfx::CURSOR_FORWARD);
1379 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); 1379 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x());
1380 cursor_bounds.push_back(bound); 1380 cursor_bounds.push_back(bound);
1381 1381
1382 // Expected cursor position when clicking left and right of each character. 1382 // Expected cursor position when clicking left and right of each character.
1383 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2}; 1383 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2};
1384 1384
1385 int index = 0; 1385 int index = 0;
1386 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) { 1386 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) {
1387 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2; 1387 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2;
1388 MouseClick(cursor_bounds[i], half_width / 2); 1388 MouseClick(cursor_bounds[i], half_width / 2);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 #else 1568 #else
1569 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1569 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1570 #endif 1570 #endif
1571 #endif // !defined(OS_WIN) 1571 #endif // !defined(OS_WIN)
1572 1572
1573 // Reset locale. 1573 // Reset locale.
1574 base::i18n::SetICUDefaultLocale(locale); 1574 base::i18n::SetICUDefaultLocale(locale);
1575 } 1575 }
1576 1576
1577 } // namespace views 1577 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698