| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 Element* const startBlock = enclosingBlock( | 1824 Element* const startBlock = enclosingBlock( |
| 1825 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode), | 1825 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode), |
| 1826 CannotCrossEditingBoundary); | 1826 CannotCrossEditingBoundary); |
| 1827 ContainerNode* const highestRoot = highestEditableRoot(position); | 1827 ContainerNode* const highestRoot = highestEditableRoot(position); |
| 1828 const bool startNodeIsEditable = hasEditableStyle(*startNode); | 1828 const bool startNodeIsEditable = hasEditableStyle(*startNode); |
| 1829 | 1829 |
| 1830 Node* candidateNode = startNode; | 1830 Node* candidateNode = startNode; |
| 1831 PositionAnchorType candidateType = position.anchorType(); | 1831 PositionAnchorType candidateType = position.anchorType(); |
| 1832 int candidateOffset = position.computeEditingOffset(); | 1832 int candidateOffset = position.computeEditingOffset(); |
| 1833 | 1833 |
| 1834 Node* prevousNodeIterator = startNode; | 1834 Node* previousNodeIterator = startNode; |
| 1835 while (prevousNodeIterator) { | 1835 while (previousNodeIterator) { |
| 1836 if (boundaryCrossingRule == CannotCrossEditingBoundary && | 1836 if (boundaryCrossingRule == CannotCrossEditingBoundary && |
| 1837 !nodeIsUserSelectAll(prevousNodeIterator) && | 1837 !nodeIsUserSelectAll(previousNodeIterator) && |
| 1838 hasEditableStyle(*prevousNodeIterator) != startNodeIsEditable) | 1838 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable) |
| 1839 break; | 1839 break; |
| 1840 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { | 1840 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { |
| 1841 while (prevousNodeIterator && | 1841 while (previousNodeIterator && |
| 1842 hasEditableStyle(*prevousNodeIterator) != startNodeIsEditable) | 1842 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable) { |
| 1843 prevousNodeIterator = | 1843 previousNodeIterator = |
| 1844 Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1844 Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1845 if (!prevousNodeIterator || | 1845 } |
| 1846 !prevousNodeIterator->isDescendantOf(highestRoot)) | 1846 if (!previousNodeIterator || |
| 1847 !previousNodeIterator->isDescendantOf(highestRoot)) |
| 1847 break; | 1848 break; |
| 1848 } | 1849 } |
| 1849 | 1850 |
| 1850 const LayoutItem layoutItem = | 1851 const LayoutItem layoutItem = |
| 1851 LayoutItem(prevousNodeIterator->layoutObject()); | 1852 LayoutItem(previousNodeIterator->layoutObject()); |
| 1852 if (layoutItem.isNull()) { | 1853 if (layoutItem.isNull()) { |
| 1853 prevousNodeIterator = | 1854 previousNodeIterator = |
| 1854 Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1855 Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1855 continue; | 1856 continue; |
| 1856 } | 1857 } |
| 1857 const ComputedStyle& style = layoutItem.styleRef(); | 1858 const ComputedStyle& style = layoutItem.styleRef(); |
| 1858 if (style.visibility() != EVisibility::kVisible) { | 1859 if (style.visibility() != EVisibility::kVisible) { |
| 1859 prevousNodeIterator = | 1860 previousNodeIterator = |
| 1860 Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1861 Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1861 continue; | 1862 continue; |
| 1862 } | 1863 } |
| 1863 | 1864 |
| 1864 if (layoutItem.isBR() || isEnclosingBlock(prevousNodeIterator)) | 1865 if (layoutItem.isBR() || isEnclosingBlock(previousNodeIterator)) |
| 1865 break; | 1866 break; |
| 1866 | 1867 |
| 1867 if (layoutItem.isText() && | 1868 if (layoutItem.isText() && |
| 1868 toLayoutText(prevousNodeIterator->layoutObject()) | 1869 toLayoutText(previousNodeIterator->layoutObject()) |
| 1869 ->resolvedTextLength()) { | 1870 ->resolvedTextLength()) { |
| 1870 SECURITY_DCHECK(prevousNodeIterator->isTextNode()); | 1871 SECURITY_DCHECK(previousNodeIterator->isTextNode()); |
| 1871 if (style.preserveNewline()) { | 1872 if (style.preserveNewline()) { |
| 1872 LayoutText* text = toLayoutText(prevousNodeIterator->layoutObject()); | 1873 LayoutText* text = toLayoutText(previousNodeIterator->layoutObject()); |
| 1873 int index = text->textLength(); | 1874 int index = text->textLength(); |
| 1874 if (prevousNodeIterator == startNode && candidateOffset < index) | 1875 if (previousNodeIterator == startNode && candidateOffset < index) |
| 1875 index = max(0, candidateOffset); | 1876 index = max(0, candidateOffset); |
| 1876 while (--index >= 0) { | 1877 while (--index >= 0) { |
| 1877 if ((*text)[index] == '\n') | 1878 if ((*text)[index] == '\n') |
| 1878 return PositionTemplate<Strategy>(toText(prevousNodeIterator), | 1879 return PositionTemplate<Strategy>(toText(previousNodeIterator), |
| 1879 index + 1); | 1880 index + 1); |
| 1880 } | 1881 } |
| 1881 } | 1882 } |
| 1882 candidateNode = prevousNodeIterator; | 1883 candidateNode = previousNodeIterator; |
| 1883 candidateType = PositionAnchorType::OffsetInAnchor; | 1884 candidateType = PositionAnchorType::OffsetInAnchor; |
| 1884 candidateOffset = 0; | 1885 candidateOffset = 0; |
| 1885 prevousNodeIterator = | 1886 previousNodeIterator = |
| 1886 Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1887 Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1887 } else if (editingIgnoresContent(*prevousNodeIterator) || | 1888 } else if (editingIgnoresContent(*previousNodeIterator) || |
| 1888 isDisplayInsideTable(prevousNodeIterator)) { | 1889 isDisplayInsideTable(previousNodeIterator)) { |
| 1889 candidateNode = prevousNodeIterator; | 1890 candidateNode = previousNodeIterator; |
| 1890 candidateType = PositionAnchorType::BeforeAnchor; | 1891 candidateType = PositionAnchorType::BeforeAnchor; |
| 1891 prevousNodeIterator = | 1892 previousNodeIterator = |
| 1892 prevousNodeIterator->previousSibling() | 1893 previousNodeIterator->previousSibling() |
| 1893 ? prevousNodeIterator->previousSibling() | 1894 ? previousNodeIterator->previousSibling() |
| 1894 : Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1895 : Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1895 } else { | 1896 } else { |
| 1896 prevousNodeIterator = | 1897 previousNodeIterator = |
| 1897 Strategy::previousPostOrder(*prevousNodeIterator, startBlock); | 1898 Strategy::previousPostOrder(*previousNodeIterator, startBlock); |
| 1898 } | 1899 } |
| 1899 } | 1900 } |
| 1900 | 1901 |
| 1901 if (candidateType == PositionAnchorType::OffsetInAnchor) | 1902 if (candidateType == PositionAnchorType::OffsetInAnchor) |
| 1902 return PositionTemplate<Strategy>(candidateNode, candidateOffset); | 1903 return PositionTemplate<Strategy>(candidateNode, candidateOffset); |
| 1903 | 1904 |
| 1904 return PositionTemplate<Strategy>(candidateNode, candidateType); | 1905 return PositionTemplate<Strategy>(candidateNode, candidateType); |
| 1905 } | 1906 } |
| 1906 | 1907 |
| 1907 template <typename Strategy> | 1908 template <typename Strategy> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 Element* const startBlock = enclosingBlock( | 1942 Element* const startBlock = enclosingBlock( |
| 1942 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode), | 1943 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode), |
| 1943 CannotCrossEditingBoundary); | 1944 CannotCrossEditingBoundary); |
| 1944 ContainerNode* const highestRoot = highestEditableRoot(position); | 1945 ContainerNode* const highestRoot = highestEditableRoot(position); |
| 1945 const bool startNodeIsEditable = hasEditableStyle(*startNode); | 1946 const bool startNodeIsEditable = hasEditableStyle(*startNode); |
| 1946 | 1947 |
| 1947 Node* candidateNode = startNode; | 1948 Node* candidateNode = startNode; |
| 1948 PositionAnchorType candidateType = position.anchorType(); | 1949 PositionAnchorType candidateType = position.anchorType(); |
| 1949 int candidateOffset = position.computeEditingOffset(); | 1950 int candidateOffset = position.computeEditingOffset(); |
| 1950 | 1951 |
| 1951 Node* nextNodeItreator = startNode; | 1952 Node* nextNodeIterator = startNode; |
| 1952 while (nextNodeItreator) { | 1953 while (nextNodeIterator) { |
| 1953 if (boundaryCrossingRule == CannotCrossEditingBoundary && | 1954 if (boundaryCrossingRule == CannotCrossEditingBoundary && |
| 1954 !nodeIsUserSelectAll(nextNodeItreator) && | 1955 !nodeIsUserSelectAll(nextNodeIterator) && |
| 1955 hasEditableStyle(*nextNodeItreator) != startNodeIsEditable) | 1956 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable) |
| 1956 break; | 1957 break; |
| 1957 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { | 1958 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { |
| 1958 while (nextNodeItreator && | 1959 while (nextNodeIterator && |
| 1959 hasEditableStyle(*nextNodeItreator) != startNodeIsEditable) | 1960 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable) |
| 1960 nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); | 1961 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); |
| 1961 if (!nextNodeItreator || !nextNodeItreator->isDescendantOf(highestRoot)) | 1962 if (!nextNodeIterator || !nextNodeIterator->isDescendantOf(highestRoot)) |
| 1962 break; | 1963 break; |
| 1963 } | 1964 } |
| 1964 | 1965 |
| 1965 LayoutObject* const layoutObject = nextNodeItreator->layoutObject(); | 1966 LayoutObject* const layoutObject = nextNodeIterator->layoutObject(); |
| 1966 if (!layoutObject) { | 1967 if (!layoutObject) { |
| 1967 nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); | 1968 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); |
| 1968 continue; | 1969 continue; |
| 1969 } | 1970 } |
| 1970 const ComputedStyle& style = layoutObject->styleRef(); | 1971 const ComputedStyle& style = layoutObject->styleRef(); |
| 1971 if (style.visibility() != EVisibility::kVisible) { | 1972 if (style.visibility() != EVisibility::kVisible) { |
| 1972 nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); | 1973 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); |
| 1973 continue; | 1974 continue; |
| 1974 } | 1975 } |
| 1975 | 1976 |
| 1976 if (layoutObject->isBR() || isEnclosingBlock(nextNodeItreator)) | 1977 if (layoutObject->isBR() || isEnclosingBlock(nextNodeIterator)) |
| 1977 break; | 1978 break; |
| 1978 | 1979 |
| 1979 // FIXME: We avoid returning a position where the layoutObject can't accept | 1980 // FIXME: We avoid returning a position where the layoutObject can't accept |
| 1980 // the caret. | 1981 // the caret. |
| 1981 if (layoutObject->isText() && | 1982 if (layoutObject->isText() && |
| 1982 toLayoutText(layoutObject)->resolvedTextLength()) { | 1983 toLayoutText(layoutObject)->resolvedTextLength()) { |
| 1983 SECURITY_DCHECK(nextNodeItreator->isTextNode()); | 1984 SECURITY_DCHECK(nextNodeIterator->isTextNode()); |
| 1984 LayoutText* const text = toLayoutText(layoutObject); | 1985 LayoutText* const text = toLayoutText(layoutObject); |
| 1985 if (style.preserveNewline()) { | 1986 if (style.preserveNewline()) { |
| 1986 const int length = toLayoutText(layoutObject)->textLength(); | 1987 const int length = toLayoutText(layoutObject)->textLength(); |
| 1987 for (int i = (nextNodeItreator == startNode ? candidateOffset : 0); | 1988 for (int i = (nextNodeIterator == startNode ? candidateOffset : 0); |
| 1988 i < length; ++i) { | 1989 i < length; ++i) { |
| 1989 if ((*text)[i] == '\n') | 1990 if ((*text)[i] == '\n') |
| 1990 return PositionTemplate<Strategy>(toText(nextNodeItreator), | 1991 return PositionTemplate<Strategy>(toText(nextNodeIterator), |
| 1991 i + text->textStartOffset()); | 1992 i + text->textStartOffset()); |
| 1992 } | 1993 } |
| 1993 } | 1994 } |
| 1994 | 1995 |
| 1995 candidateNode = nextNodeItreator; | 1996 candidateNode = nextNodeIterator; |
| 1996 candidateType = PositionAnchorType::OffsetInAnchor; | 1997 candidateType = PositionAnchorType::OffsetInAnchor; |
| 1997 candidateOffset = | 1998 candidateOffset = |
| 1998 layoutObject->caretMaxOffset() + text->textStartOffset(); | 1999 layoutObject->caretMaxOffset() + text->textStartOffset(); |
| 1999 nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); | 2000 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); |
| 2000 } else if (editingIgnoresContent(*nextNodeItreator) || | 2001 } else if (editingIgnoresContent(*nextNodeIterator) || |
| 2001 isDisplayInsideTable(nextNodeItreator)) { | 2002 isDisplayInsideTable(nextNodeIterator)) { |
| 2002 candidateNode = nextNodeItreator; | 2003 candidateNode = nextNodeIterator; |
| 2003 candidateType = PositionAnchorType::AfterAnchor; | 2004 candidateType = PositionAnchorType::AfterAnchor; |
| 2004 nextNodeItreator = | 2005 nextNodeIterator = |
| 2005 Strategy::nextSkippingChildren(*nextNodeItreator, startBlock); | 2006 Strategy::nextSkippingChildren(*nextNodeIterator, startBlock); |
| 2006 } else { | 2007 } else { |
| 2007 nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); | 2008 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); |
| 2008 } | 2009 } |
| 2009 } | 2010 } |
| 2010 | 2011 |
| 2011 if (candidateType == PositionAnchorType::OffsetInAnchor) | 2012 if (candidateType == PositionAnchorType::OffsetInAnchor) |
| 2012 return PositionTemplate<Strategy>(candidateNode, candidateOffset); | 2013 return PositionTemplate<Strategy>(candidateNode, candidateOffset); |
| 2013 | 2014 |
| 2014 return PositionTemplate<Strategy>(candidateNode, candidateType); | 2015 return PositionTemplate<Strategy>(candidateNode, candidateType); |
| 2015 } | 2016 } |
| 2016 | 2017 |
| 2017 template <typename Strategy> | 2018 template <typename Strategy> |
| (...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3997 | 3998 |
| 3998 VisiblePositionInFlatTree previousPositionOf( | 3999 VisiblePositionInFlatTree previousPositionOf( |
| 3999 const VisiblePositionInFlatTree& visiblePosition, | 4000 const VisiblePositionInFlatTree& visiblePosition, |
| 4000 EditingBoundaryCrossingRule rule) { | 4001 EditingBoundaryCrossingRule rule) { |
| 4001 DCHECK(visiblePosition.isValid()) << visiblePosition; | 4002 DCHECK(visiblePosition.isValid()) << visiblePosition; |
| 4002 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( | 4003 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( |
| 4003 visiblePosition.deepEquivalent(), rule); | 4004 visiblePosition.deepEquivalent(), rule); |
| 4004 } | 4005 } |
| 4005 | 4006 |
| 4006 } // namespace blink | 4007 } // namespace blink |
| OLD | NEW |