| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1347 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1348 std::vector<gfx::Rect> cursor_bounds; | 1348 std::vector<gfx::Rect> cursor_bounds; |
| 1349 | 1349 |
| 1350 // Save each cursor bound. | 1350 // Save each cursor bound. |
| 1351 gfx::SelectionModel sel(0, 0, gfx::SelectionModel::LEADING); | 1351 gfx::SelectionModel sel(0, 0, gfx::SelectionModel::LEADING); |
| 1352 cursor_bounds.push_back(GetCursorBounds(sel)); | 1352 cursor_bounds.push_back(GetCursorBounds(sel)); |
| 1353 | 1353 |
| 1354 sel = gfx::SelectionModel(1, 0, gfx::SelectionModel::TRAILING); | 1354 sel = gfx::SelectionModel(1, 0, gfx::SelectionModel::TRAILING); |
| 1355 gfx::Rect bound = GetCursorBounds(sel); | 1355 gfx::Rect bound = GetCursorBounds(sel); |
| 1356 sel = gfx::SelectionModel(1, 1, gfx::SelectionModel::LEADING); | 1356 sel = gfx::SelectionModel(1, 1, gfx::SelectionModel::LEADING); |
| 1357 EXPECT_EQ(bound, GetCursorBounds(sel)); | 1357 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
| 1358 cursor_bounds.push_back(bound); | 1358 cursor_bounds.push_back(bound); |
| 1359 | 1359 |
| 1360 // Check that a cursor at the end of the Latin portion of the text is at the |
| 1361 // same position as a cursor placed at the end of the RTL Hebrew portion. |
| 1360 sel = gfx::SelectionModel(2, 1, gfx::SelectionModel::TRAILING); | 1362 sel = gfx::SelectionModel(2, 1, gfx::SelectionModel::TRAILING); |
| 1361 bound = GetCursorBounds(sel); | 1363 bound = GetCursorBounds(sel); |
| 1362 sel = gfx::SelectionModel(4, 3, gfx::SelectionModel::TRAILING); | 1364 sel = gfx::SelectionModel(4, 3, gfx::SelectionModel::TRAILING); |
| 1363 EXPECT_EQ(bound, GetCursorBounds(sel)); | 1365 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
| 1364 cursor_bounds.push_back(bound); | 1366 cursor_bounds.push_back(bound); |
| 1365 | 1367 |
| 1366 sel = gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING); | 1368 sel = gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING); |
| 1367 bound = GetCursorBounds(sel); | 1369 bound = GetCursorBounds(sel); |
| 1368 sel = gfx::SelectionModel(3, 3, gfx::SelectionModel::LEADING); | 1370 sel = gfx::SelectionModel(3, 3, gfx::SelectionModel::LEADING); |
| 1369 EXPECT_EQ(bound, GetCursorBounds(sel)); | 1371 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
| 1370 cursor_bounds.push_back(bound); | 1372 cursor_bounds.push_back(bound); |
| 1371 | 1373 |
| 1372 sel = gfx::SelectionModel(2, 2, gfx::SelectionModel::LEADING); | 1374 sel = gfx::SelectionModel(2, 2, gfx::SelectionModel::LEADING); |
| 1373 bound = GetCursorBounds(sel); | 1375 bound = GetCursorBounds(sel); |
| 1374 sel = gfx::SelectionModel(4, 2, gfx::SelectionModel::LEADING); | 1376 sel = gfx::SelectionModel(4, 2, gfx::SelectionModel::LEADING); |
| 1375 EXPECT_EQ(bound, GetCursorBounds(sel)); | 1377 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
| 1376 cursor_bounds.push_back(bound); | 1378 cursor_bounds.push_back(bound); |
| 1377 | 1379 |
| 1378 // Expected cursor position when clicking left and right of each character. | 1380 // Expected cursor position when clicking left and right of each character. |
| 1379 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2}; | 1381 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2}; |
| 1380 | 1382 |
| 1381 int index = 0; | 1383 int index = 0; |
| 1382 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) { | 1384 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) { |
| 1383 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2; | 1385 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2; |
| 1384 MouseClick(cursor_bounds[i], half_width / 2); | 1386 MouseClick(cursor_bounds[i], half_width / 2); |
| 1385 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); | 1387 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 #else | 1566 #else |
| 1565 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1567 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1566 #endif | 1568 #endif |
| 1567 #endif // !defined(OS_WIN) | 1569 #endif // !defined(OS_WIN) |
| 1568 | 1570 |
| 1569 // Reset locale. | 1571 // Reset locale. |
| 1570 base::i18n::SetICUDefaultLocale(locale); | 1572 base::i18n::SetICUDefaultLocale(locale); |
| 1571 } | 1573 } |
| 1572 | 1574 |
| 1573 } // namespace views | 1575 } // namespace views |
| OLD | NEW |