Changeset 117359 in webkit
- Timestamp:
- May 16, 2012 4:24:34 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r117355 r117359 1 2012-05-16 Ryosuke Niwa <rniwa@webkit.org> 2 3 Merge nextRootInlineBox with nextLinePosition 4 https://bugs.webkit.org/show_bug.cgi?id=81593 5 6 Reviewed by Enrica Casucci. 7 8 Call previousRootInlineBox and nextRootInlineBox in previousLinePosition and nextLinePosition respectively 9 to share the code. Moved out the nullity check of startBox and extracted the renderer's node from the former 10 two, and added editableType to their argument lists to match the interface in both use cases. 11 12 Also moved out the code to extract root inline box using RenderedPosition from those two functions and 13 expanded in call sites since previousLinePosition and nextLinePosition need to return the candidate position 14 even when the root inline box doesn't exist. To this end, renamed previousRootInlineBox and nextRootInlineBox 15 to previousRootInlineBoxCandidatePosition and nextRootInlineBoxCandidatePosition respectively. 16 17 In addition, got rid of one version of nextLeafWithSameEditability that adjusted node with respect to offset 18 This variant did: 19 20 Node* child = node->childNode(offset); 21 node = child ? child->nextLeafNode() : node->lastDescendant()->nextLeafNode(); 22 23 instead of: 24 25 node = node->nextLeafNode(); 26 27 at the beginning of the function. Observe that the former code is logically equivalent to: 28 29 Node* child = node->childNode(offset); 30 node = child ? child : node->lastDescendant(); 31 node = node->nextLeafNode(); 32 33 Thus, the first two lines of this logically equivalent code is added in nextLinePosition wherein we used to 34 call the removed variant. 35 36 This refactoring with no behavioral change would help us resolving the bug 81490. 37 38 * editing/visible_units.cpp: 39 (WebCore::previousRootInlineBoxCandidatePosition): Renamed from previousRootInlineBox. 40 (WebCore::nextRootInlineBoxCandidatePosition): Renamed from nextRootInlineBox. 41 (WebCore::logicallyPreviousBox): Checks the nullity of startBox's renderer and node. Also extracts the root 42 inline box out of the position per the interface change. 43 (WebCore::logicallyNextBox): Ditto. 44 (WebCore::previousLinePosition): Calls previousRootInlineBoxCandidatePosition. 45 (WebCore::nextLinePosition): Calls nextRootInlineBoxCandidatePosition. 46 1 47 2012-05-16 Noel Gordon <noel.gordon@gmail.com> 2 48 -
trunk/Source/WebCore/editing/visible_units.cpp
r115788 r117359 70 70 } 71 71 72 static Node* nextLeafWithSameEditability(Node* node, int offset)73 {74 bool editable = node->rendererIsEditable();75 ASSERT(offset >= 0);76 Node* child = node->childNode(offset);77 node = child ? child->nextLeafNode() : node->lastDescendant()->nextLeafNode();78 while (node) {79 if (editable == node->rendererIsEditable())80 return node;81 node = node->nextLeafNode();82 }83 return 0;84 }85 86 72 static Node* nextLeafWithSameEditability(Node* node, EditableType editableType = ContentIsEditable) 87 73 { … … 100 86 101 87 // FIXME: consolidate with code in previousLinePosition. 102 static const RootInlineBox* previousRootInlineBox(const InlineBox* box, const VisiblePosition& visiblePosition) 103 { 104 Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), ContentIsEditable); 105 106 if (!box->renderer() || !box->renderer()->node()) 107 return 0; 108 109 Node* node = box->renderer()->node(); 88 static Position previousRootInlineBoxCandidatePosition(Node* node, const VisiblePosition& visiblePosition, EditableType editableType) 89 { 90 Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType); 110 91 Node* enclosingBlockNode = enclosingNodeWithNonInlineRenderer(node); 111 Node* previousNode = previousLeafWithSameEditability(node, ContentIsEditable);92 Node* previousNode = previousLeafWithSameEditability(node, editableType); 112 93 113 94 while (previousNode && enclosingBlockNode == enclosingNodeWithNonInlineRenderer(previousNode)) 114 previousNode = previousLeafWithSameEditability(previousNode, ContentIsEditable);95 previousNode = previousLeafWithSameEditability(previousNode, editableType); 115 96 116 97 while (previousNode && !previousNode->isShadowRoot()) { 117 if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), ContentIsEditable) != highestRoot)98 if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), editableType) != highestRoot) 118 99 break; 119 100 … … 121 102 createLegacyEditingPosition(previousNode, caretMaxOffset(previousNode)); 122 103 123 if (pos.isCandidate()) { 124 RenderedPosition renderedPos(pos, DOWNSTREAM); 125 RootInlineBox* root = renderedPos.rootBox(); 126 if (root) 127 return root; 128 } 129 130 previousNode = previousLeafWithSameEditability(previousNode, ContentIsEditable); 131 } 132 return 0; 133 } 134 135 static const RootInlineBox* nextRootInlineBox(const InlineBox* box, const VisiblePosition& visiblePosition) 136 { 137 Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), ContentIsEditable); 138 139 if (!box->renderer() || !box->renderer()->node()) 140 return 0; 141 142 Node* node = box->renderer()->node(); 104 if (pos.isCandidate()) 105 return pos; 106 107 previousNode = previousLeafWithSameEditability(previousNode, editableType); 108 } 109 return Position(); 110 } 111 112 static Position nextRootInlineBoxCandidatePosition(Node* node, const VisiblePosition& visiblePosition, EditableType editableType) 113 { 114 Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType); 143 115 Node* enclosingBlockNode = enclosingNodeWithNonInlineRenderer(node); 144 Node* nextNode = nextLeafWithSameEditability(node, ContentIsEditable);116 Node* nextNode = nextLeafWithSameEditability(node, editableType); 145 117 while (nextNode && enclosingBlockNode == enclosingNodeWithNonInlineRenderer(nextNode)) 146 118 nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable); 147 119 148 120 while (nextNode && !nextNode->isShadowRoot()) { 149 if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), ContentIsEditable) != highestRoot)121 if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), editableType) != highestRoot) 150 122 break; 151 123 … … 153 125 pos = createLegacyEditingPosition(nextNode, caretMinOffset(nextNode)); 154 126 155 if (pos.isCandidate()) { 156 RenderedPosition renderedPos(pos, DOWNSTREAM); 157 RootInlineBox* root = renderedPos.rootBox(); 158 if (root) 159 return root; 160 } 161 162 nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable); 163 } 164 return 0; 127 if (pos.isCandidate()) 128 return pos; 129 130 nextNode = nextLeafWithSameEditability(nextNode, editableType); 131 } 132 return Position(); 165 133 } 166 134 … … 258 226 return previousBox; 259 227 260 while (1) { 261 const RootInlineBox* previousRoot = previousRootInlineBox(startBox, visiblePosition); 228 while (1) { 229 Node* startNode = startBox->renderer() ? startBox->renderer()->node() : 0; 230 if (!startNode) 231 break; 232 233 Position position = previousRootInlineBoxCandidatePosition(startNode, visiblePosition, ContentIsEditable); 234 if (position.isNull()) 235 break; 236 237 RenderedPosition renderedPosition(position, DOWNSTREAM); 238 RootInlineBox* previousRoot = renderedPosition.rootBox(); 262 239 if (!previousRoot) 263 240 break; … … 290 267 return nextBox; 291 268 292 while (1) { 293 const RootInlineBox* nextRoot = nextRootInlineBox(startBox, visiblePosition); 269 while (1) { 270 Node* startNode = startBox->renderer() ? startBox->renderer()->node() : 0; 271 if (!startNode) 272 break; 273 274 Position position = nextRootInlineBoxCandidatePosition(startNode, visiblePosition, ContentIsEditable); 275 if (position.isNull()) 276 break; 277 278 RenderedPosition renderedPosition(position, DOWNSTREAM); 279 RootInlineBox* nextRoot = renderedPosition.rootBox(); 294 280 if (!nextRoot) 295 281 break; … … 952 938 Position p = visiblePosition.deepEquivalent(); 953 939 Node* node = p.deprecatedNode(); 954 Node* highestRoot = highestEditableRoot(p, editableType);955 940 956 941 if (!node) … … 976 961 977 962 if (!root) { 978 // This containing editable block does not have a previous line. 979 // Need to move back to previous containing editable block in this root editable 980 // block and find the last root line box in that block. 981 Node* startBlock = enclosingNodeWithNonInlineRenderer(node); 982 Node* n = previousLeafWithSameEditability(node, editableType); 983 while (n && startBlock == enclosingNodeWithNonInlineRenderer(n)) 984 n = previousLeafWithSameEditability(n, editableType); 985 while (n) { 986 if (highestEditableRoot(firstPositionInOrBeforeNode(n), editableType) != highestRoot) 987 break; 988 Position pos = n->hasTagName(brTag) ? positionBeforeNode(n) : createLegacyEditingPosition(n, caretMaxOffset(n)); 989 if (pos.isCandidate()) { 990 pos.getInlineBoxAndOffset(DOWNSTREAM, box, ignoredCaretOffset); 991 if (box) { 992 // previous root line box found 993 root = box->root(); 994 break; 995 } 996 997 return VisiblePosition(pos, DOWNSTREAM); 998 } 999 n = previousLeafWithSameEditability(n, editableType); 963 Position position = previousRootInlineBoxCandidatePosition(node, visiblePosition, editableType); 964 if (position.isNotNull()) { 965 RenderedPosition renderedPosition(position); 966 root = renderedPosition.rootBox(); 967 if (!root) 968 return position; 1000 969 } 1001 970 } … … 1020 989 } 1021 990 1022 1023 991 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, int lineDirectionPoint, EditableType editableType) 1024 992 { 1025 993 Position p = visiblePosition.deepEquivalent(); 1026 994 Node* node = p.deprecatedNode(); 1027 Node* highestRoot = highestEditableRoot(p, editableType);1028 995 1029 996 if (!node) … … 1049 1016 1050 1017 if (!root) { 1051 // This containing editable block does not have a next line. 1052 // Need to move forward to next containing editable block in this root editable 1053 // block and find the first root line box in that block. 1054 Node* startBlock = enclosingNodeWithNonInlineRenderer(node); 1055 Node* n = nextLeafWithSameEditability(node, p.deprecatedEditingOffset()); 1056 while (n && startBlock == enclosingNodeWithNonInlineRenderer(n)) 1057 n = nextLeafWithSameEditability(n, editableType); 1058 while (n) { 1059 if (highestEditableRoot(firstPositionInOrBeforeNode(n), editableType) != highestRoot) 1060 break; 1061 Position pos = createLegacyEditingPosition(n, caretMinOffset(n)); 1062 if (pos.isCandidate()) { 1063 ASSERT(n->renderer()); 1064 pos.getInlineBoxAndOffset(DOWNSTREAM, box, ignoredCaretOffset); 1065 if (box) { 1066 // next root line box found 1067 root = box->root(); 1068 break; 1069 } 1070 1071 return VisiblePosition(pos, DOWNSTREAM); 1072 } 1073 n = nextLeafWithSameEditability(n, editableType); 1018 // FIXME: We need do the same in previousLinePosition. 1019 Node* child = node->childNode(p.deprecatedEditingOffset()); 1020 node = child ? child : node->lastDescendant(); 1021 Position position = nextRootInlineBoxCandidatePosition(node, visiblePosition, editableType); 1022 if (position.isNotNull()) { 1023 RenderedPosition renderedPosition(position); 1024 root = renderedPosition.rootBox(); 1025 if (!root) 1026 return position; 1074 1027 } 1075 1028 }
Note: See TracChangeset
for help on using the changeset viewer.