Changeset 122537 in webkit
- Timestamp:
- Jul 12, 2012 7:12:21 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r122532 r122537 1 2012-07-12 Eric Seidel <eric@webkit.org> 2 3 Incorrect behaviour calling Range setStart or setEnd with boundary in different document 4 https://bugs.webkit.org/show_bug.cgi?id=42517 5 6 Reviewed by Ojan Vafai. 7 8 Add a new test to cover this changed behavior, and correct a FIXME in an old test 9 which was documenting our incorrect behavior. 10 11 * fast/dom/Range/set-wrong-document-err-expected.txt: Added. 12 * fast/dom/Range/set-wrong-document-err.html: Added. 13 * fast/dom/move-nodes-across-documents.html: 14 1 15 2012-07-12 Konrad Piascik <kpiascik@rim.com> 2 16 -
trunk/LayoutTests/fast/dom/move-nodes-across-documents.html
r120792 r122537 182 182 }, 'HIERARCHY_REQUEST_ERR'); 183 183 184 // FIXME: This doesn't match http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Changing. 185 // Gecko implements it correctly. When setting a boundary of the range in a different 184 // When setting a boundary of the range in a different 186 185 // document, the call should succeed and the range should be collapsed. 187 186 runTest(function() { 188 187 rangeInIframe().setStart(elementInCurrentDocument('setStart'), 0); 189 } , 'WRONG_DOCUMENT_ERR');188 }); 190 189 runTest(function() { 191 190 rangeInIframe().setEnd(elementInCurrentDocument('setEnd'), 0); 192 } , 'WRONG_DOCUMENT_ERR');191 }); 193 192 runTest(function() { 194 193 rangeInIframe().setStartBefore(elementInCurrentDocument('setStartBefore'), 0); 195 } , 'WRONG_DOCUMENT_ERR');194 }); 196 195 runTest(function() { 197 196 rangeInIframe().setStartAfter(elementInCurrentDocument('setStartAfter'), 0); 198 } , 'WRONG_DOCUMENT_ERR');197 }); 199 198 runTest(function() { 200 199 rangeInIframe().setEndBefore(elementInCurrentDocument('setEndBefore'), 0); 201 } , 'WRONG_DOCUMENT_ERR');200 }); 202 201 runTest(function() { 203 202 rangeInIframe().setEndAfter(elementInCurrentDocument('setEndAfter'), 0); 204 } , 'WRONG_DOCUMENT_ERR');203 }); 205 204 206 205 // FIXME: isPointInRange isn't specced anywhere, but Gecko doesn't throw an exception here. -
trunk/Source/WebCore/ChangeLog
r122535 r122537 1 2012-07-12 Eric Seidel <eric@webkit.org> 2 3 Incorrect behaviour calling Range setStart or setEnd with boundary in different document 4 https://bugs.webkit.org/show_bug.cgi?id=42517 5 6 Reviewed by Ojan Vafai. 7 8 Added a new static inline "checkForDifferentRootContainer" to share some code 9 and made setStart/setEnd do the right thing in the x-document case. I removed 10 the bogus checks in set*After/set*Before functions, and since they just call 11 through to setStart/setEnd, they also now do the right thing. 12 13 Test: fast/dom/Range/set-wrong-document-err.html 14 15 * dom/Range.cpp: 16 (WebCore::checkForDifferentRootContainer): 17 (WebCore): 18 (WebCore::Range::setStart): 19 (WebCore::Range::setEnd): 20 (WebCore::Range::setStartAfter): 21 (WebCore::Range::setEndBefore): 22 (WebCore::Range::setEndAfter): 23 (WebCore::Range::setStartBefore): 24 1 25 2012-07-12 Erik Arvidsson <arv@chromium.org> 2 26 -
trunk/Source/WebCore/dom/Range.cpp
r119690 r122537 197 197 } 198 198 199 static inline bool checkForDifferentRootContainer(const RangeBoundaryPoint& start, const RangeBoundaryPoint& end) 200 { 201 Node* endRootContainer = end.container(); 202 while (endRootContainer->parentNode()) 203 endRootContainer = endRootContainer->parentNode(); 204 Node* startRootContainer = start.container(); 205 while (startRootContainer->parentNode()) 206 startRootContainer = startRootContainer->parentNode(); 207 208 return startRootContainer != endRootContainer || (Range::compareBoundaryPoints(start, end, ASSERT_NO_EXCEPTION) > 0); 209 } 210 199 211 void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec) 200 212 { … … 209 221 } 210 222 223 bool didMoveDocument = false; 211 224 if (refNode->document() != m_ownerDocument) { 212 ec = WRONG_DOCUMENT_ERR;213 return;225 setDocument(refNode->document()); 226 didMoveDocument = true; 214 227 } 215 228 … … 221 234 m_start.set(refNode, offset, childNode); 222 235 223 // check if different root container 224 Node* endRootContainer = m_end.container(); 225 while (endRootContainer->parentNode()) 226 endRootContainer = endRootContainer->parentNode(); 227 Node* startRootContainer = m_start.container(); 228 while (startRootContainer->parentNode()) 229 startRootContainer = startRootContainer->parentNode(); 230 if (startRootContainer != endRootContainer) 236 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) 231 237 collapse(true, ec); 232 // check if new start after end233 else if (compareBoundaryPoints(m_start, m_end, ec) > 0) {234 ASSERT(!ec);235 collapse(true, ec);236 }237 238 } 238 239 … … 249 250 } 250 251 252 bool didMoveDocument = false; 251 253 if (refNode->document() != m_ownerDocument) { 252 ec = WRONG_DOCUMENT_ERR;253 return;254 setDocument(refNode->document()); 255 didMoveDocument = true; 254 256 } 255 257 … … 261 263 m_end.set(refNode, offset, childNode); 262 264 263 // check if different root container 264 Node* endRootContainer = m_end.container(); 265 while (endRootContainer->parentNode()) 266 endRootContainer = endRootContainer->parentNode(); 267 Node* startRootContainer = m_start.container(); 268 while (startRootContainer->parentNode()) 269 startRootContainer = startRootContainer->parentNode(); 270 if (startRootContainer != endRootContainer) 265 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) 271 266 collapse(false, ec); 272 // check if new end before start273 if (compareBoundaryPoints(m_start, m_end, ec) > 0) {274 ASSERT(!ec);275 collapse(false, ec);276 }277 267 } 278 268 … … 1254 1244 } 1255 1245 1256 if (refNode->document() != m_ownerDocument) {1257 ec = WRONG_DOCUMENT_ERR;1258 return;1259 }1260 1261 1246 ec = 0; 1262 1247 checkNodeBA(refNode, ec); … … 1279 1264 } 1280 1265 1281 if (refNode->document() != m_ownerDocument) {1282 ec = WRONG_DOCUMENT_ERR;1283 return;1284 }1285 1286 1266 ec = 0; 1287 1267 checkNodeBA(refNode, ec); … … 1304 1284 } 1305 1285 1306 if (refNode->document() != m_ownerDocument) {1307 ec = WRONG_DOCUMENT_ERR;1308 return;1309 }1310 1311 1286 ec = 0; 1312 1287 checkNodeBA(refNode, ec); … … 1315 1290 1316 1291 setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, ec); 1317 1318 1292 } 1319 1293 … … 1530 1504 } 1531 1505 1532 if (refNode->document() != m_ownerDocument) {1533 ec = WRONG_DOCUMENT_ERR;1534 return;1535 }1536 1537 1506 ec = 0; 1538 1507 checkNodeBA(refNode, ec);
Note: See TracChangeset
for help on using the changeset viewer.