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 "core/editing/InputMethodController.h" | 5 #include "core/editing/InputMethodController.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/Range.h" | 10 #include "core/dom/Range.h" |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 Vector<CompositionUnderline> empty_underlines; | 1512 Vector<CompositionUnderline> empty_underlines; |
1513 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 8)); | 1513 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 8)); |
1514 Controller().CommitText(String(""), empty_underlines, 0); | 1514 Controller().CommitText(String(""), empty_underlines, 0); |
1515 EXPECT_STREQ("Abc Ghi", input->value().Utf8().data()); | 1515 EXPECT_STREQ("Abc Ghi", input->value().Utf8().data()); |
1516 | 1516 |
1517 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 7)); | 1517 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 7)); |
1518 Controller().CommitText(String("1"), empty_underlines, 0); | 1518 Controller().CommitText(String("1"), empty_underlines, 0); |
1519 EXPECT_STREQ("Abc 1", input->value().Utf8().data()); | 1519 EXPECT_STREQ("Abc 1", input->value().Utf8().data()); |
1520 } | 1520 } |
1521 | 1521 |
1522 static String GetMarkedText( | 1522 TEST_F(InputMethodControllerTest, ContentDependentMarker_ReplaceStartOfMarker) { |
1523 DocumentMarkerController& document_marker_controller, | |
1524 Node* node, | |
1525 int marker_index) { | |
1526 DocumentMarker* marker = document_marker_controller.Markers()[marker_index]; | |
1527 return node->textContent().Substring( | |
1528 marker->StartOffset(), marker->EndOffset() - marker->StartOffset()); | |
1529 } | |
1530 | |
1531 TEST_F(InputMethodControllerTest, | |
1532 Marker_WhitespaceFixupAroundMarkerNotContainingSpace) { | |
1533 Element* div = InsertHTMLElement( | |
1534 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | |
1535 | |
1536 // Add marker under "text" (use TextMatch since Composition markers don't | |
1537 // persist across editing operations) | |
1538 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); | |
1539 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | |
1540 marker_range.EndPosition(), | |
1541 DocumentMarker::kTextMatch); | |
1542 // Delete "Initial" | |
1543 Vector<CompositionUnderline> empty_underlines; | |
1544 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | |
1545 Controller().CommitText(String(""), empty_underlines, 0); | |
1546 | |
1547 // Delete "blah" | |
1548 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | |
1549 Controller().CommitText(String(""), empty_underlines, 0); | |
1550 | |
1551 // Check that the marker is still attached to "text" and doesn't include | |
1552 // either space around it | |
1553 EXPECT_EQ(1u, GetDocument().Markers().MarkersFor(div->firstChild()).size()); | |
1554 EXPECT_STREQ("text", | |
1555 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1556 .Utf8() | |
1557 .data()); | |
1558 } | |
1559 | |
1560 TEST_F(InputMethodControllerTest, | |
1561 Marker_WhitespaceFixupAroundMarkerBeginningWithSpace) { | |
1562 Element* div = InsertHTMLElement( | |
1563 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | |
1564 | |
1565 // Add marker under " text" (use TextMatch since Composition markers don't | |
1566 // persist across editing operations) | |
1567 EphemeralRange marker_range = PlainTextRange(7, 12).CreateRange(*div); | |
1568 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | |
1569 marker_range.EndPosition(), | |
1570 DocumentMarker::kTextMatch); | |
1571 // Delete "Initial" | |
1572 Vector<CompositionUnderline> empty_underlines; | |
1573 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | |
1574 Controller().CommitText(String(""), empty_underlines, 0); | |
1575 | |
1576 // Delete "blah" | |
1577 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | |
1578 Controller().CommitText(String(""), empty_underlines, 0); | |
1579 | |
1580 // Check that the marker is still attached to " text" and includes the space | |
1581 // before "text" but not the space after | |
1582 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | |
1583 ASSERT_STREQ("\xC2\xA0text", | |
1584 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1585 .Utf8() | |
1586 .data()); | |
1587 } | |
1588 | |
1589 TEST_F(InputMethodControllerTest, | |
1590 Marker_WhitespaceFixupAroundMarkerEndingWithSpace) { | |
1591 Element* div = InsertHTMLElement( | |
1592 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | |
1593 | |
1594 // Add marker under "text " (use TextMatch since Composition markers don't | |
1595 // persist across editing operations) | |
1596 EphemeralRange marker_range = PlainTextRange(8, 13).CreateRange(*div); | |
1597 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | |
1598 marker_range.EndPosition(), | |
1599 DocumentMarker::kTextMatch); | |
1600 // Delete "Initial" | |
1601 Vector<CompositionUnderline> empty_underlines; | |
1602 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | |
1603 Controller().CommitText(String(""), empty_underlines, 0); | |
1604 | |
1605 // Delete "blah" | |
1606 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | |
1607 Controller().CommitText(String(""), empty_underlines, 0); | |
1608 | |
1609 // Check that the marker is still attached to "text " and includes the space | |
1610 // after "text" but not the space before | |
1611 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | |
1612 ASSERT_STREQ("text\xC2\xA0", | |
1613 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1614 .Utf8() | |
1615 .data()); | |
1616 } | |
1617 | |
1618 TEST_F(InputMethodControllerTest, | |
1619 Marker_WhitespaceFixupAroundMarkerBeginningAndEndingWithSpaces) { | |
1620 Element* div = InsertHTMLElement( | |
1621 "<div id='sample' contenteditable>Initial text blah</div>", "sample"); | |
1622 | |
1623 // Add marker under " text " (use TextMatch since Composition markers don't | |
1624 // persist across editing operations) | |
1625 EphemeralRange marker_range = PlainTextRange(7, 13).CreateRange(*div); | |
1626 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | |
1627 marker_range.EndPosition(), | |
1628 DocumentMarker::kTextMatch); | |
1629 | |
1630 // Delete "Initial" | |
1631 Vector<CompositionUnderline> empty_underlines; | |
1632 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | |
1633 Controller().CommitText(String(""), empty_underlines, 0); | |
1634 | |
1635 // Delete "blah" | |
1636 Controller().SetCompositionFromExistingText(empty_underlines, 6, 10); | |
1637 Controller().CommitText(String(""), empty_underlines, 0); | |
1638 | |
1639 // Check that the marker is still attached to " text " and includes both the | |
1640 // space before "text" and the space after | |
1641 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | |
1642 ASSERT_STREQ("\xC2\xA0text\xC2\xA0", | |
1643 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1644 .Utf8() | |
1645 .data()); | |
1646 } | |
1647 | |
1648 TEST_F(InputMethodControllerTest, Marker_ReplaceStartOfMarker) { | |
1649 Element* div = InsertHTMLElement( | 1523 Element* div = InsertHTMLElement( |
1650 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1524 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1651 | 1525 |
1652 // Add marker under "Initial text" | 1526 // Add marker under "Initial text" |
1653 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); | 1527 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); |
1654 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1528 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1655 marker_range.EndPosition(), | 1529 marker_range.EndPosition(), |
1656 DocumentMarker::kTextMatch); | 1530 DocumentMarker::kTextMatch); |
1657 | 1531 |
1658 // Replace "Initial" with "Original" | 1532 // Replace "Initial" with "Original" |
1659 Vector<CompositionUnderline> empty_underlines; | 1533 Vector<CompositionUnderline> empty_underlines; |
1660 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); | 1534 Controller().SetCompositionFromExistingText(empty_underlines, 0, 7); |
1661 Controller().CommitText(String("Original"), empty_underlines, 0); | 1535 Controller().CommitText(String("Original"), empty_underlines, 0); |
1662 | 1536 |
1663 // Verify marker is under "Original text" | 1537 // Verify marker was removed |
1664 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1538 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1665 ASSERT_STREQ("Original text", | |
1666 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1667 .Utf8() | |
1668 .data()); | |
1669 } | 1539 } |
1670 | 1540 |
1671 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsStartOfMarker) { | 1541 TEST_F(InputMethodControllerTest, |
| 1542 ContentDependentMarker_ReplaceTextContainsStartOfMarker) { |
1672 Element* div = InsertHTMLElement( | 1543 Element* div = InsertHTMLElement( |
1673 "<div id='sample' contenteditable>This is some initial text</div>", | 1544 "<div id='sample' contenteditable>This is some initial text</div>", |
1674 "sample"); | 1545 "sample"); |
1675 | 1546 |
1676 // Add marker under "initial text" | 1547 // Add marker under "initial text" |
1677 EphemeralRange marker_range = PlainTextRange(13, 25).CreateRange(*div); | 1548 EphemeralRange marker_range = PlainTextRange(13, 25).CreateRange(*div); |
1678 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1549 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1679 marker_range.EndPosition(), | 1550 marker_range.EndPosition(), |
1680 DocumentMarker::kTextMatch); | 1551 DocumentMarker::kTextMatch); |
1681 | 1552 |
1682 // Replace "some initial" with "boring" | 1553 // Replace "some initial" with "boring" |
1683 Vector<CompositionUnderline> empty_underlines; | 1554 Vector<CompositionUnderline> empty_underlines; |
1684 Controller().SetCompositionFromExistingText(empty_underlines, 8, 20); | 1555 Controller().SetCompositionFromExistingText(empty_underlines, 8, 20); |
1685 Controller().CommitText(String("boring"), empty_underlines, 0); | 1556 Controller().CommitText(String("boring"), empty_underlines, 0); |
1686 | 1557 |
1687 // Verify marker is under " text" | 1558 // Verify marker was removed |
1688 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1559 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1689 EXPECT_STREQ(" text", | |
1690 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1691 .Utf8() | |
1692 .data()); | |
1693 } | 1560 } |
1694 | 1561 |
1695 TEST_F(InputMethodControllerTest, Marker_ReplaceEndOfMarker) { | 1562 TEST_F(InputMethodControllerTest, ContentDependentMarker_ReplaceEndOfMarker) { |
1696 Element* div = InsertHTMLElement( | 1563 Element* div = InsertHTMLElement( |
1697 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1564 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1698 | 1565 |
1699 // Add marker under "Initial text" | 1566 // Add marker under "Initial text" |
1700 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); | 1567 EphemeralRange marker_range = PlainTextRange(0, 12).CreateRange(*div); |
1701 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1568 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1702 marker_range.EndPosition(), | 1569 marker_range.EndPosition(), |
1703 DocumentMarker::kTextMatch); | 1570 DocumentMarker::kTextMatch); |
1704 | 1571 |
1705 // Replace "text" with "string" | 1572 // Replace "text" with "string" |
1706 Vector<CompositionUnderline> empty_underlines; | 1573 Vector<CompositionUnderline> empty_underlines; |
1707 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); | 1574 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); |
1708 Controller().CommitText(String("string"), empty_underlines, 0); | 1575 Controller().CommitText(String("string"), empty_underlines, 0); |
1709 | 1576 |
1710 // Verify marker is under "Initial string" | 1577 // Verify marker was removed |
1711 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1578 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1712 ASSERT_STREQ("Initial string", | |
1713 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1714 .Utf8() | |
1715 .data()); | |
1716 } | 1579 } |
1717 | 1580 |
1718 TEST_F(InputMethodControllerTest, Marker_ReplaceTextContainsEndOfMarker) { | 1581 TEST_F(InputMethodControllerTest, |
| 1582 ContentDependentMarker_ReplaceTextContainsEndOfMarker) { |
1719 Element* div = InsertHTMLElement( | 1583 Element* div = InsertHTMLElement( |
1720 "<div id='sample' contenteditable>This is some initial text</div>", | 1584 "<div id='sample' contenteditable>This is some initial text</div>", |
1721 "sample"); | 1585 "sample"); |
1722 | 1586 |
1723 // Add marker under "some initial" | 1587 // Add marker under "some initial" |
1724 EphemeralRange marker_range = PlainTextRange(8, 20).CreateRange(*div); | 1588 EphemeralRange marker_range = PlainTextRange(8, 20).CreateRange(*div); |
1725 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1589 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1726 marker_range.EndPosition(), | 1590 marker_range.EndPosition(), |
1727 DocumentMarker::kTextMatch); | 1591 DocumentMarker::kTextMatch); |
1728 | 1592 |
1729 // Replace "initial text" with "content" | 1593 // Replace "initial text" with "content" |
1730 Vector<CompositionUnderline> empty_underlines; | 1594 Vector<CompositionUnderline> empty_underlines; |
1731 Controller().SetCompositionFromExistingText(empty_underlines, 13, 25); | 1595 Controller().SetCompositionFromExistingText(empty_underlines, 13, 25); |
1732 Controller().CommitText(String("content"), empty_underlines, 0); | 1596 Controller().CommitText(String("content"), empty_underlines, 0); |
1733 | 1597 |
1734 EXPECT_STREQ("This is some content", div->innerHTML().Utf8().data()); | 1598 EXPECT_STREQ("This is some content", div->innerHTML().Utf8().data()); |
1735 | 1599 |
1736 // Verify marker is under "some " | 1600 // Verify marker was removed |
1737 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1601 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1738 EXPECT_STREQ("some ", | |
1739 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1740 .Utf8() | |
1741 .data()); | |
1742 } | 1602 } |
1743 | 1603 |
1744 TEST_F(InputMethodControllerTest, Marker_ReplaceEntireMarker) { | 1604 TEST_F(InputMethodControllerTest, ContentDependentMarker_ReplaceEntireMarker) { |
1745 Element* div = InsertHTMLElement( | 1605 Element* div = InsertHTMLElement( |
1746 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1606 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1747 | 1607 |
1748 // Add marker under "text" | 1608 // Add marker under "text" |
1749 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); | 1609 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); |
1750 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1610 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1751 marker_range.EndPosition(), | 1611 marker_range.EndPosition(), |
1752 DocumentMarker::kTextMatch); | 1612 DocumentMarker::kTextMatch); |
1753 | 1613 |
1754 // Replace "text" with "string" | 1614 // Replace "text" with "string" |
1755 Vector<CompositionUnderline> empty_underlines; | 1615 Vector<CompositionUnderline> empty_underlines; |
1756 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); | 1616 Controller().SetCompositionFromExistingText(empty_underlines, 8, 12); |
1757 Controller().CommitText(String("string"), empty_underlines, 0); | 1617 Controller().CommitText(String("string"), empty_underlines, 0); |
1758 | 1618 |
1759 // Verify marker is under "string" | 1619 // Verify marker was removed |
1760 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1620 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1761 ASSERT_STREQ("string", | |
1762 GetMarkedText(GetDocument().Markers(), div->firstChild(), 0) | |
1763 .Utf8() | |
1764 .data()); | |
1765 } | 1621 } |
1766 | 1622 |
1767 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtBeginning) { | 1623 TEST_F(InputMethodControllerTest, |
| 1624 ContentDependentMarker_ReplaceTextWithMarkerAtBeginning) { |
1768 Element* div = InsertHTMLElement( | 1625 Element* div = InsertHTMLElement( |
1769 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1626 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1770 | 1627 |
1771 // Add marker under "Initial" | 1628 // Add marker under "Initial" |
1772 EphemeralRange marker_range = PlainTextRange(0, 7).CreateRange(*div); | 1629 EphemeralRange marker_range = PlainTextRange(0, 7).CreateRange(*div); |
1773 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1630 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1774 marker_range.EndPosition(), | 1631 marker_range.EndPosition(), |
1775 DocumentMarker::kTextMatch); | 1632 DocumentMarker::kTextMatch); |
1776 | 1633 |
1777 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1634 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1778 | 1635 |
1779 // Replace "Initial text" with "New string" | 1636 // Replace "Initial text" with "New string" |
1780 Vector<CompositionUnderline> empty_underlines; | 1637 Vector<CompositionUnderline> empty_underlines; |
1781 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); | 1638 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); |
1782 Controller().CommitText(String("New string"), empty_underlines, 0); | 1639 Controller().CommitText(String("New string"), empty_underlines, 0); |
1783 | 1640 |
1784 // Verify marker was removed | 1641 // Verify marker was removed |
1785 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); | 1642 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1786 } | 1643 } |
1787 | 1644 |
1788 TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) { | 1645 TEST_F(InputMethodControllerTest, |
| 1646 ContentDependentMarker_ReplaceTextWithMarkerAtEnd) { |
1789 Element* div = InsertHTMLElement( | 1647 Element* div = InsertHTMLElement( |
1790 "<div id='sample' contenteditable>Initial text</div>", "sample"); | 1648 "<div id='sample' contenteditable>Initial text</div>", "sample"); |
1791 | 1649 |
1792 // Add marker under "text" | 1650 // Add marker under "text" |
1793 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); | 1651 EphemeralRange marker_range = PlainTextRange(8, 12).CreateRange(*div); |
1794 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1652 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1795 marker_range.EndPosition(), | 1653 marker_range.EndPosition(), |
1796 DocumentMarker::kTextMatch); | 1654 DocumentMarker::kTextMatch); |
1797 | 1655 |
1798 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1656 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1799 | 1657 |
1800 // Replace "Initial text" with "New string" | 1658 // Replace "Initial text" with "New string" |
1801 Vector<CompositionUnderline> empty_underlines; | 1659 Vector<CompositionUnderline> empty_underlines; |
1802 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); | 1660 Controller().SetCompositionFromExistingText(empty_underlines, 0, 12); |
1803 Controller().CommitText(String("New string"), empty_underlines, 0); | 1661 Controller().CommitText(String("New string"), empty_underlines, 0); |
1804 | 1662 |
1805 // Verify marker was removed | 1663 // Verify marker was removed |
1806 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); | 1664 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1807 } | 1665 } |
1808 | 1666 |
1809 TEST_F(InputMethodControllerTest, Marker_Deletions) { | 1667 TEST_F(InputMethodControllerTest, ContentDependentMarker_Deletions) { |
1810 Element* div = InsertHTMLElement( | 1668 Element* div = InsertHTMLElement( |
1811 "<div id='sample' contenteditable>1111122222333334444455555</div>", | 1669 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
1812 "sample"); | 1670 "sample"); |
1813 | 1671 |
1814 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); | 1672 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
1815 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1673 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1816 marker_range.EndPosition(), | 1674 marker_range.EndPosition(), |
1817 DocumentMarker::kTextMatch); | 1675 DocumentMarker::kTextMatch); |
1818 | 1676 |
1819 marker_range = PlainTextRange(5, 10).CreateRange(*div); | 1677 marker_range = PlainTextRange(5, 10).CreateRange(*div); |
(...skipping 17 matching lines...) Expand all Loading... |
1837 DocumentMarker::kTextMatch); | 1695 DocumentMarker::kTextMatch); |
1838 | 1696 |
1839 EXPECT_EQ(5u, GetDocument().Markers().Markers().size()); | 1697 EXPECT_EQ(5u, GetDocument().Markers().Markers().size()); |
1840 | 1698 |
1841 // Delete third marker and portions of second and fourth | 1699 // Delete third marker and portions of second and fourth |
1842 Vector<CompositionUnderline> empty_underlines; | 1700 Vector<CompositionUnderline> empty_underlines; |
1843 Controller().SetCompositionFromExistingText(empty_underlines, 8, 17); | 1701 Controller().SetCompositionFromExistingText(empty_underlines, 8, 17); |
1844 Controller().CommitText(String(""), empty_underlines, 0); | 1702 Controller().CommitText(String(""), empty_underlines, 0); |
1845 | 1703 |
1846 // Verify markers were updated correctly | 1704 // Verify markers were updated correctly |
1847 EXPECT_EQ(4u, GetDocument().Markers().Markers().size()); | 1705 EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); |
1848 | 1706 |
1849 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); | 1707 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); |
1850 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); | 1708 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); |
1851 | 1709 |
1852 EXPECT_EQ(5u, GetDocument().Markers().Markers()[1]->StartOffset()); | 1710 EXPECT_EQ(11u, GetDocument().Markers().Markers()[1]->StartOffset()); |
1853 EXPECT_EQ(8u, GetDocument().Markers().Markers()[1]->EndOffset()); | 1711 EXPECT_EQ(16u, GetDocument().Markers().Markers()[1]->EndOffset()); |
1854 | |
1855 EXPECT_EQ(8u, GetDocument().Markers().Markers()[2]->StartOffset()); | |
1856 EXPECT_EQ(11u, GetDocument().Markers().Markers()[2]->EndOffset()); | |
1857 | |
1858 EXPECT_EQ(11u, GetDocument().Markers().Markers()[3]->StartOffset()); | |
1859 EXPECT_EQ(16u, GetDocument().Markers().Markers()[3]->EndOffset()); | |
1860 } | 1712 } |
1861 | 1713 |
1862 TEST_F(InputMethodControllerTest, Marker_DeleteExactlyOnMarker) { | 1714 TEST_F(InputMethodControllerTest, |
| 1715 ContentDependentMarker_DeleteExactlyOnMarker) { |
1863 Element* div = InsertHTMLElement( | 1716 Element* div = InsertHTMLElement( |
1864 "<div id='sample' contenteditable>1111122222333334444455555</div>", | 1717 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
1865 "sample"); | 1718 "sample"); |
1866 | 1719 |
1867 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); | 1720 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); |
1868 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1721 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1869 marker_range.EndPosition(), | 1722 marker_range.EndPosition(), |
1870 DocumentMarker::kTextMatch); | 1723 DocumentMarker::kTextMatch); |
1871 | 1724 |
1872 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1725 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); |
1873 | 1726 |
1874 // Delete exactly on the marker | 1727 // Delete exactly on the marker |
1875 Vector<CompositionUnderline> empty_underlines; | 1728 Vector<CompositionUnderline> empty_underlines; |
1876 Controller().SetCompositionFromExistingText(empty_underlines, 5, 10); | 1729 Controller().SetCompositionFromExistingText(empty_underlines, 5, 10); |
1877 Controller().CommitText(String(""), empty_underlines, 0); | 1730 Controller().CommitText(String(""), empty_underlines, 0); |
1878 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); | 1731 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1879 } | 1732 } |
1880 | 1733 |
1881 TEST_F(InputMethodControllerTest, Marker_DeleteMiddleOfMarker) { | 1734 TEST_F(InputMethodControllerTest, ContentDependentMarker_DeleteMiddleOfMarker) { |
1882 Element* div = InsertHTMLElement( | 1735 Element* div = InsertHTMLElement( |
1883 "<div id='sample' contenteditable>1111122222333334444455555</div>", | 1736 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
1884 "sample"); | 1737 "sample"); |
1885 | 1738 |
1886 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); | 1739 EphemeralRange marker_range = PlainTextRange(5, 10).CreateRange(*div); |
1887 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1740 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1888 marker_range.EndPosition(), | 1741 marker_range.EndPosition(), |
1889 DocumentMarker::kTextMatch); | 1742 DocumentMarker::kTextMatch); |
1890 | 1743 |
1891 // Delete middle of marker | 1744 // Delete middle of marker |
1892 Vector<CompositionUnderline> empty_underlines; | 1745 Vector<CompositionUnderline> empty_underlines; |
1893 Controller().SetCompositionFromExistingText(empty_underlines, 6, 9); | 1746 Controller().SetCompositionFromExistingText(empty_underlines, 6, 9); |
1894 Controller().CommitText(String(""), empty_underlines, 0); | 1747 Controller().CommitText(String(""), empty_underlines, 0); |
1895 | 1748 |
1896 EXPECT_EQ(1u, GetDocument().Markers().Markers().size()); | 1749 // Verify marker was removed |
1897 | 1750 EXPECT_EQ(0u, GetDocument().Markers().Markers().size()); |
1898 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->StartOffset()); | |
1899 EXPECT_EQ(7u, GetDocument().Markers().Markers()[0]->EndOffset()); | |
1900 } | 1751 } |
1901 | 1752 |
1902 TEST_F(InputMethodControllerTest, Marker_InsertInMarkerInterior) { | 1753 TEST_F(InputMethodControllerTest, |
| 1754 ContentDependentMarker_InsertInMarkerInterior) { |
1903 Element* div = InsertHTMLElement( | 1755 Element* div = InsertHTMLElement( |
1904 "<div id='sample' contenteditable>1111122222333334444455555</div>", | 1756 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
1905 "sample"); | 1757 "sample"); |
1906 | 1758 |
1907 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); | 1759 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
1908 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1760 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1909 marker_range.EndPosition(), | 1761 marker_range.EndPosition(), |
1910 DocumentMarker::kTextMatch); | 1762 DocumentMarker::kTextMatch); |
1911 | 1763 |
1912 marker_range = PlainTextRange(5, 10).CreateRange(*div); | 1764 marker_range = PlainTextRange(5, 10).CreateRange(*div); |
1913 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1765 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1914 marker_range.EndPosition(), | 1766 marker_range.EndPosition(), |
1915 DocumentMarker::kTextMatch); | 1767 DocumentMarker::kTextMatch); |
1916 | 1768 |
1917 marker_range = PlainTextRange(10, 15).CreateRange(*div); | 1769 marker_range = PlainTextRange(10, 15).CreateRange(*div); |
1918 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1770 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1919 marker_range.EndPosition(), | 1771 marker_range.EndPosition(), |
1920 DocumentMarker::kTextMatch); | 1772 DocumentMarker::kTextMatch); |
1921 | 1773 |
1922 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); | 1774 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); |
1923 | 1775 |
1924 // insert in middle of second marker | 1776 // insert in middle of second marker |
1925 Vector<CompositionUnderline> empty_underlines; | 1777 Vector<CompositionUnderline> empty_underlines; |
1926 Controller().SetComposition("", empty_underlines, 7, 7); | 1778 Controller().SetComposition("", empty_underlines, 7, 7); |
1927 Controller().CommitText(String("66666"), empty_underlines, -7); | 1779 Controller().CommitText(String("66666"), empty_underlines, -7); |
1928 | 1780 |
1929 EXPECT_EQ(3u, GetDocument().Markers().Markers().size()); | 1781 EXPECT_EQ(2u, GetDocument().Markers().Markers().size()); |
1930 | 1782 |
1931 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); | 1783 EXPECT_EQ(0u, GetDocument().Markers().Markers()[0]->StartOffset()); |
1932 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); | 1784 EXPECT_EQ(5u, GetDocument().Markers().Markers()[0]->EndOffset()); |
1933 | 1785 |
1934 EXPECT_EQ(5u, GetDocument().Markers().Markers()[1]->StartOffset()); | 1786 EXPECT_EQ(15u, GetDocument().Markers().Markers()[1]->StartOffset()); |
1935 EXPECT_EQ(15u, GetDocument().Markers().Markers()[1]->EndOffset()); | 1787 EXPECT_EQ(20u, GetDocument().Markers().Markers()[1]->EndOffset()); |
1936 | |
1937 EXPECT_EQ(15u, GetDocument().Markers().Markers()[2]->StartOffset()); | |
1938 EXPECT_EQ(20u, GetDocument().Markers().Markers()[2]->EndOffset()); | |
1939 } | 1788 } |
1940 | 1789 |
1941 TEST_F(InputMethodControllerTest, Marker_InsertBetweenMarkers) { | 1790 TEST_F(InputMethodControllerTest, ContentDependentMarker_InsertBetweenMarkers) { |
1942 Element* div = InsertHTMLElement( | 1791 Element* div = InsertHTMLElement( |
1943 "<div id='sample' contenteditable>1111122222333334444455555</div>", | 1792 "<div id='sample' contenteditable>1111122222333334444455555</div>", |
1944 "sample"); | 1793 "sample"); |
1945 | 1794 |
1946 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); | 1795 EphemeralRange marker_range = PlainTextRange(0, 5).CreateRange(*div); |
1947 GetDocument().Markers().AddMarker(marker_range.StartPosition(), | 1796 GetDocument().Markers().AddMarker(marker_range.StartPosition(), |
1948 marker_range.EndPosition(), | 1797 marker_range.EndPosition(), |
1949 DocumentMarker::kTextMatch); | 1798 DocumentMarker::kTextMatch); |
1950 | 1799 |
1951 marker_range = PlainTextRange(5, 15).CreateRange(*div); | 1800 marker_range = PlainTextRange(5, 15).CreateRange(*div); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1984 // Set selection before BODY(editable). | 1833 // Set selection before BODY(editable). |
1985 GetFrame().Selection().SetSelection( | 1834 GetFrame().Selection().SetSelection( |
1986 SelectionInDOMTree::Builder() | 1835 SelectionInDOMTree::Builder() |
1987 .Collapse(Position(GetDocument().documentElement(), 0)) | 1836 .Collapse(Position(GetDocument().documentElement(), 0)) |
1988 .Build()); | 1837 .Build()); |
1989 | 1838 |
1990 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); | 1839 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); |
1991 } | 1840 } |
1992 | 1841 |
1993 } // namespace blink | 1842 } // namespace blink |
OLD | NEW |