OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1444 | 1444 |
1445 SendKeyEvent('b'); | 1445 SendKeyEvent('b'); |
1446 EXPECT_STR_EQ("ab", textfield_->text()); | 1446 EXPECT_STR_EQ("ab", textfield_->text()); |
1447 x = GetCursorBounds().x(); | 1447 x = GetCursorBounds().x(); |
1448 EXPECT_LT(prev_x, x); | 1448 EXPECT_LT(prev_x, x); |
1449 prev_x = x; | 1449 prev_x = x; |
1450 | 1450 |
1451 SendKeyEvent(0x05E1); | 1451 SendKeyEvent(0x05E1); |
1452 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); | 1452 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); |
1453 x = GetCursorBounds().x(); | 1453 x = GetCursorBounds().x(); |
1454 EXPECT_EQ(prev_x, x); | 1454 EXPECT_GE(1, std::abs(x - prev_x)); |
msw
2014/11/24 21:51:00
If I read this right, entering an RTL character in
ckocagil
2014/11/25 01:39:47
When the cursor is placed between two glyphs, we p
msw
2014/11/25 04:52:06
Add an explanatory comment and/or TODO.
| |
1455 | 1455 |
1456 SendKeyEvent(0x05E2); | 1456 SendKeyEvent(0x05E2); |
1457 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); | 1457 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); |
1458 x = GetCursorBounds().x(); | 1458 x = GetCursorBounds().x(); |
1459 EXPECT_EQ(prev_x, x); | 1459 EXPECT_GE(1, std::abs(x - prev_x)); |
1460 | 1460 |
1461 // Clear text. | 1461 // Clear text. |
1462 SendKeyEvent(ui::VKEY_A, false, true); | 1462 SendKeyEvent(ui::VKEY_A, false, true); |
1463 SendKeyEvent('\n'); | 1463 SendKeyEvent('\n'); |
1464 | 1464 |
1465 // RTL-LTR string in LTR context. | 1465 // RTL-LTR string in LTR context. |
1466 SendKeyEvent(0x05E1); | 1466 SendKeyEvent(0x05E1); |
1467 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); | 1467 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); |
1468 x = GetCursorBounds().x(); | 1468 x = GetCursorBounds().x(); |
1469 EXPECT_EQ(GetDisplayRect().x(), x); | 1469 EXPECT_EQ(GetDisplayRect().x(), x); |
1470 prev_x = x; | 1470 prev_x = x; |
1471 | 1471 |
1472 SendKeyEvent(0x05E2); | 1472 SendKeyEvent(0x05E2); |
1473 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); | 1473 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); |
1474 x = GetCursorBounds().x(); | 1474 x = GetCursorBounds().x(); |
1475 EXPECT_EQ(prev_x, x); | 1475 EXPECT_GE(1, std::abs(x - prev_x)); |
1476 | 1476 |
1477 SendKeyEvent('a'); | 1477 SendKeyEvent('a'); |
1478 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"a"), textfield_->text()); | 1478 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"a"), textfield_->text()); |
1479 x = GetCursorBounds().x(); | 1479 x = GetCursorBounds().x(); |
1480 EXPECT_LT(prev_x, x); | 1480 EXPECT_LT(prev_x, x); |
1481 prev_x = x; | 1481 prev_x = x; |
1482 | 1482 |
1483 SendKeyEvent('b'); | 1483 SendKeyEvent('b'); |
1484 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1484 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1485 x = GetCursorBounds().x(); | 1485 x = GetCursorBounds().x(); |
1486 EXPECT_LT(prev_x, x); | 1486 EXPECT_LT(prev_x, x); |
1487 } | 1487 } |
1488 | 1488 |
1489 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { | 1489 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { |
1490 std::string locale = l10n_util::GetApplicationLocale(""); | 1490 std::string locale = l10n_util::GetApplicationLocale(""); |
1491 base::i18n::SetICUDefaultLocale("he"); | 1491 base::i18n::SetICUDefaultLocale("he"); |
1492 | 1492 |
1493 InitTextfield(); | 1493 InitTextfield(); |
1494 // LTR-RTL string in RTL context. | 1494 // LTR-RTL string in RTL context. |
1495 SendKeyEvent('a'); | 1495 SendKeyEvent('a'); |
1496 EXPECT_STR_EQ("a", textfield_->text()); | 1496 EXPECT_STR_EQ("a", textfield_->text()); |
1497 int x = GetCursorBounds().x(); | 1497 int x = GetCursorBounds().x(); |
1498 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1498 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
1499 int prev_x = x; | 1499 int prev_x = x; |
1500 | 1500 |
1501 SendKeyEvent('b'); | 1501 SendKeyEvent('b'); |
1502 EXPECT_STR_EQ("ab", textfield_->text()); | 1502 EXPECT_STR_EQ("ab", textfield_->text()); |
1503 x = GetCursorBounds().x(); | 1503 x = GetCursorBounds().x(); |
1504 EXPECT_EQ(prev_x, x); | 1504 EXPECT_GE(1, std::abs(x - prev_x)); |
1505 | 1505 |
1506 SendKeyEvent(0x05E1); | 1506 SendKeyEvent(0x05E1); |
1507 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); | 1507 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); |
1508 x = GetCursorBounds().x(); | 1508 x = GetCursorBounds().x(); |
1509 EXPECT_GT(prev_x, x); | 1509 EXPECT_GT(prev_x, x); |
1510 prev_x = x; | 1510 prev_x = x; |
1511 | 1511 |
1512 SendKeyEvent(0x05E2); | 1512 SendKeyEvent(0x05E2); |
1513 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); | 1513 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); |
1514 x = GetCursorBounds().x(); | 1514 x = GetCursorBounds().x(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1525 | 1525 |
1526 SendKeyEvent(0x05E2); | 1526 SendKeyEvent(0x05E2); |
1527 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); | 1527 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); |
1528 x = GetCursorBounds().x(); | 1528 x = GetCursorBounds().x(); |
1529 EXPECT_GT(prev_x, x); | 1529 EXPECT_GT(prev_x, x); |
1530 prev_x = x; | 1530 prev_x = x; |
1531 | 1531 |
1532 SendKeyEvent('a'); | 1532 SendKeyEvent('a'); |
1533 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"a"), textfield_->text()); | 1533 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"a"), textfield_->text()); |
1534 x = GetCursorBounds().x(); | 1534 x = GetCursorBounds().x(); |
1535 EXPECT_EQ(prev_x, x); | 1535 EXPECT_GE(1, std::abs(x - prev_x)); |
1536 prev_x = x; | 1536 prev_x = x; |
1537 | 1537 |
1538 SendKeyEvent('b'); | 1538 SendKeyEvent('b'); |
1539 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1539 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1540 x = GetCursorBounds().x(); | 1540 x = GetCursorBounds().x(); |
1541 EXPECT_EQ(prev_x, x); | 1541 EXPECT_EQ(prev_x, x); |
1542 | 1542 |
1543 // Reset locale. | 1543 // Reset locale. |
1544 base::i18n::SetICUDefaultLocale(locale); | 1544 base::i18n::SetICUDefaultLocale(locale); |
1545 } | 1545 } |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2070 TextfieldDestroyerController controller(textfield_); | 2070 TextfieldDestroyerController controller(textfield_); |
2071 EXPECT_TRUE(controller.target()); | 2071 EXPECT_TRUE(controller.target()); |
2072 | 2072 |
2073 // Send a key to trigger OnKeyEvent(). | 2073 // Send a key to trigger OnKeyEvent(). |
2074 SendKeyEvent('X'); | 2074 SendKeyEvent('X'); |
2075 | 2075 |
2076 EXPECT_FALSE(controller.target()); | 2076 EXPECT_FALSE(controller.target()); |
2077 } | 2077 } |
2078 | 2078 |
2079 } // namespace views | 2079 } // namespace views |
OLD | NEW |