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

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2753193002: Editing: Indent command: Do not insert BLOCKQUOTE under the root HTML element. (Closed)
Patch Set: . Created 3 years, 9 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
OLDNEW
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 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 return PositionTemplate<Strategy>(); 1819 return PositionTemplate<Strategy>();
1820 1820
1821 if (isRenderedAsNonInlineTableImageOrHR(startNode)) 1821 if (isRenderedAsNonInlineTableImageOrHR(startNode))
1822 return PositionTemplate<Strategy>::beforeNode(startNode); 1822 return PositionTemplate<Strategy>::beforeNode(startNode);
1823 1823
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 const HTMLElement* body = startNode->document().body();
yosin_UTC9 2017/03/17 10:04:11 Could you move VisibleUnits.cpp change in another
1830 const bool startNodeIsInBody = body && Strategy::contains(*body, *startNode);
1829 1831
1830 Node* candidateNode = startNode; 1832 Node* candidateNode = startNode;
1831 PositionAnchorType candidateType = position.anchorType(); 1833 PositionAnchorType candidateType = position.anchorType();
1832 int candidateOffset = position.computeEditingOffset(); 1834 int candidateOffset = position.computeEditingOffset();
1833 1835
1834 Node* previousNodeIterator = startNode; 1836 Node* previousNodeIterator = startNode;
1835 while (previousNodeIterator) { 1837 while (previousNodeIterator) {
1836 if (boundaryCrossingRule == CannotCrossEditingBoundary && 1838 if (boundaryCrossingRule == CannotCrossEditingBoundary &&
1837 !nodeIsUserSelectAll(previousNodeIterator) && 1839 !nodeIsUserSelectAll(previousNodeIterator) &&
1838 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable) 1840 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable)
1839 break; 1841 break;
1840 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { 1842 if (boundaryCrossingRule == CanSkipOverEditingBoundary) {
1841 while (previousNodeIterator && 1843 while (previousNodeIterator &&
1842 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable) { 1844 hasEditableStyle(*previousNodeIterator) != startNodeIsEditable) {
1843 previousNodeIterator = 1845 previousNodeIterator =
1844 Strategy::previousPostOrder(*previousNodeIterator, startBlock); 1846 Strategy::previousPostOrder(*previousNodeIterator, startBlock);
1845 } 1847 }
1846 if (!previousNodeIterator || 1848 if (!previousNodeIterator ||
1847 !previousNodeIterator->isDescendantOf(highestRoot)) 1849 !previousNodeIterator->isDescendantOf(highestRoot))
1848 break; 1850 break;
1849 } 1851 }
1850 1852
1853 if (startNodeIsInBody !=
yosin_UTC9 2017/03/17 10:04:11 There are three occurrences of this pattern. Is it
1854 (body && Strategy::contains(*body, *previousNodeIterator)))
1855 break;
1856
1851 const LayoutItem layoutItem = 1857 const LayoutItem layoutItem =
1852 LayoutItem(previousNodeIterator->layoutObject()); 1858 LayoutItem(previousNodeIterator->layoutObject());
1853 if (layoutItem.isNull()) { 1859 if (layoutItem.isNull()) {
1854 previousNodeIterator = 1860 previousNodeIterator =
1855 Strategy::previousPostOrder(*previousNodeIterator, startBlock); 1861 Strategy::previousPostOrder(*previousNodeIterator, startBlock);
1856 continue; 1862 continue;
1857 } 1863 }
1858 const ComputedStyle& style = layoutItem.styleRef(); 1864 const ComputedStyle& style = layoutItem.styleRef();
1859 if (style.visibility() != EVisibility::kVisible) { 1865 if (style.visibility() != EVisibility::kVisible) {
1860 previousNodeIterator = 1866 previousNodeIterator =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 return PositionTemplate<Strategy>(); 1943 return PositionTemplate<Strategy>();
1938 1944
1939 if (isRenderedAsNonInlineTableImageOrHR(startNode)) 1945 if (isRenderedAsNonInlineTableImageOrHR(startNode))
1940 return PositionTemplate<Strategy>::afterNode(startNode); 1946 return PositionTemplate<Strategy>::afterNode(startNode);
1941 1947
1942 Element* const startBlock = enclosingBlock( 1948 Element* const startBlock = enclosingBlock(
1943 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode), 1949 PositionTemplate<Strategy>::firstPositionInOrBeforeNode(startNode),
1944 CannotCrossEditingBoundary); 1950 CannotCrossEditingBoundary);
1945 ContainerNode* const highestRoot = highestEditableRoot(position); 1951 ContainerNode* const highestRoot = highestEditableRoot(position);
1946 const bool startNodeIsEditable = hasEditableStyle(*startNode); 1952 const bool startNodeIsEditable = hasEditableStyle(*startNode);
1953 const HTMLElement* body = startNode->document().body();
1954 const bool startNodeIsInBody = body && Strategy::contains(*body, *startNode);
1947 1955
1948 Node* candidateNode = startNode; 1956 Node* candidateNode = startNode;
1949 PositionAnchorType candidateType = position.anchorType(); 1957 PositionAnchorType candidateType = position.anchorType();
1950 int candidateOffset = position.computeEditingOffset(); 1958 int candidateOffset = position.computeEditingOffset();
1951 1959
1952 Node* nextNodeIterator = startNode; 1960 Node* nextNodeIterator = startNode;
1953 while (nextNodeIterator) { 1961 while (nextNodeIterator) {
1954 if (boundaryCrossingRule == CannotCrossEditingBoundary && 1962 if (boundaryCrossingRule == CannotCrossEditingBoundary &&
1955 !nodeIsUserSelectAll(nextNodeIterator) && 1963 !nodeIsUserSelectAll(nextNodeIterator) &&
1956 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable) 1964 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable)
1957 break; 1965 break;
1958 if (boundaryCrossingRule == CanSkipOverEditingBoundary) { 1966 if (boundaryCrossingRule == CanSkipOverEditingBoundary) {
1959 while (nextNodeIterator && 1967 while (nextNodeIterator &&
1960 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable) 1968 hasEditableStyle(*nextNodeIterator) != startNodeIsEditable)
1961 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); 1969 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock);
1962 if (!nextNodeIterator || !nextNodeIterator->isDescendantOf(highestRoot)) 1970 if (!nextNodeIterator || !nextNodeIterator->isDescendantOf(highestRoot))
1963 break; 1971 break;
1964 } 1972 }
1965 1973
1974 if (startNodeIsInBody !=
1975 (body && Strategy::contains(*body, *nextNodeIterator)))
1976 break;
1977
1966 LayoutObject* const layoutObject = nextNodeIterator->layoutObject(); 1978 LayoutObject* const layoutObject = nextNodeIterator->layoutObject();
1967 if (!layoutObject) { 1979 if (!layoutObject) {
1968 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); 1980 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock);
1969 continue; 1981 continue;
1970 } 1982 }
1971 const ComputedStyle& style = layoutObject->styleRef(); 1983 const ComputedStyle& style = layoutObject->styleRef();
1972 if (style.visibility() != EVisibility::kVisible) { 1984 if (style.visibility() != EVisibility::kVisible) {
1973 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock); 1985 nextNodeIterator = Strategy::next(*nextNodeIterator, startBlock);
1974 continue; 1986 continue;
1975 } 1987 }
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 if (!startNode) 2933 if (!startNode)
2922 return PositionTemplate<Strategy>(); 2934 return PositionTemplate<Strategy>();
2923 2935
2924 // iterate backward from there, looking for a qualified position 2936 // iterate backward from there, looking for a qualified position
2925 Node* boundary = enclosingVisualBoundary<Strategy>(startNode); 2937 Node* boundary = enclosingVisualBoundary<Strategy>(startNode);
2926 // FIXME: PositionIterator should respect Before and After positions. 2938 // FIXME: PositionIterator should respect Before and After positions.
2927 PositionIteratorAlgorithm<Strategy> lastVisible( 2939 PositionIteratorAlgorithm<Strategy> lastVisible(
2928 adjustPositionForBackwardIteration<Strategy>(position)); 2940 adjustPositionForBackwardIteration<Strategy>(position));
2929 PositionIteratorAlgorithm<Strategy> currentPos = lastVisible; 2941 PositionIteratorAlgorithm<Strategy> currentPos = lastVisible;
2930 bool startEditable = hasEditableStyle(*startNode); 2942 bool startEditable = hasEditableStyle(*startNode);
2943 const HTMLElement* body = startNode->document().body();
2944 const bool startNodeIsInBody = body && Strategy::contains(*body, *startNode);
2931 Node* lastNode = startNode; 2945 Node* lastNode = startNode;
2932 bool boundaryCrossed = false; 2946 bool boundaryCrossed = false;
2933 for (; !currentPos.atStart(); currentPos.decrement()) { 2947 for (; !currentPos.atStart(); currentPos.decrement()) {
2934 Node* currentNode = currentPos.node(); 2948 Node* currentNode = currentPos.node();
2935 // Don't check for an editability change if we haven't moved to a different 2949 // Don't check for an editability change if we haven't moved to a different
2936 // node, to avoid the expense of computing hasEditableStyle(). 2950 // node, to avoid the expense of computing hasEditableStyle().
2937 if (currentNode != lastNode) { 2951 if (currentNode != lastNode) {
2938 // Don't change editability. 2952 // Don't change editability.
2939 bool currentEditable = hasEditableStyle(*currentNode); 2953 bool currentEditable = hasEditableStyle(*currentNode);
2940 if (startEditable != currentEditable) { 2954 if (startEditable != currentEditable) {
2941 if (rule == CannotCrossEditingBoundary) 2955 if (rule == CannotCrossEditingBoundary)
2942 break; 2956 break;
2943 boundaryCrossed = true; 2957 boundaryCrossed = true;
2944 } 2958 }
2945 lastNode = currentNode; 2959 lastNode = currentNode;
2946 } 2960 }
2947 2961
2962 if (startNodeIsInBody != (body && Strategy::contains(*body, *currentNode)))
2963 break;
2964
2948 // If we've moved to a position that is visually distinct, return the last 2965 // If we've moved to a position that is visually distinct, return the last
2949 // saved position. There is code below that terminates early if we're 2966 // saved position. There is code below that terminates early if we're
2950 // *about* to move to a visually distinct position. 2967 // *about* to move to a visually distinct position.
2951 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && 2968 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) &&
2952 currentNode != boundary) 2969 currentNode != boundary)
2953 return lastVisible.deprecatedComputePosition(); 2970 return lastVisible.deprecatedComputePosition();
2954 2971
2955 // skip position in non-laid out or invisible node 2972 // skip position in non-laid out or invisible node
2956 LayoutObject* layoutObject = 2973 LayoutObject* layoutObject =
2957 associatedLayoutObjectOf(*currentNode, currentPos.offsetInLeafNode()); 2974 associatedLayoutObjectOf(*currentNode, currentPos.offsetInLeafNode());
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 if (rule == CannotCrossEditingBoundary) 3133 if (rule == CannotCrossEditingBoundary)
3117 break; 3134 break;
3118 boundaryCrossed = true; 3135 boundaryCrossed = true;
3119 } 3136 }
3120 3137
3121 lastNode = currentNode; 3138 lastNode = currentNode;
3122 } 3139 }
3123 3140
3124 // stop before going above the body, up into the head 3141 // stop before going above the body, up into the head
3125 // return the last visible streamer position 3142 // return the last visible streamer position
3126 if (isHTMLBodyElement(*currentNode) && currentPos.atEndOfNode()) 3143 if (currentNode->document().body() == currentNode &&
3144 currentPos.atEndOfNode())
3127 break; 3145 break;
3128 3146
3129 // Do not move to a visually distinct position. 3147 // Do not move to a visually distinct position.
3130 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && 3148 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) &&
3131 currentNode != boundary) 3149 currentNode != boundary)
3132 return lastVisible.deprecatedComputePosition(); 3150 return lastVisible.deprecatedComputePosition();
3133 // Do not move past a visually disinct position. 3151 // Do not move past a visually disinct position.
3134 // Note: The first position after the last in a node whose ends are visually 3152 // Note: The first position after the last in a node whose ends are visually
3135 // distinct positions will be [boundary->parentNode(), 3153 // distinct positions will be [boundary->parentNode(),
3136 // originalBlock->nodeIndex() + 1]. 3154 // originalBlock->nodeIndex() + 1].
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
3998 4016
3999 VisiblePositionInFlatTree previousPositionOf( 4017 VisiblePositionInFlatTree previousPositionOf(
4000 const VisiblePositionInFlatTree& visiblePosition, 4018 const VisiblePositionInFlatTree& visiblePosition,
4001 EditingBoundaryCrossingRule rule) { 4019 EditingBoundaryCrossingRule rule) {
4002 DCHECK(visiblePosition.isValid()) << visiblePosition; 4020 DCHECK(visiblePosition.isValid()) << visiblePosition;
4003 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( 4021 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(
4004 visiblePosition.deepEquivalent(), rule); 4022 visiblePosition.deepEquivalent(), rule);
4005 } 4023 }
4006 4024
4007 } // namespace blink 4025 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698