Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 } | 463 } |
| 464 | 464 |
| 465 if (node->isPseudoElement()) { | 465 if (node->isPseudoElement()) { |
| 466 *errorString = "Cannot edit pseudo elements"; | 466 *errorString = "Cannot edit pseudo elements"; |
| 467 return 0; | 467 return 0; |
| 468 } | 468 } |
| 469 | 469 |
| 470 return node; | 470 return node; |
| 471 } | 471 } |
| 472 | 472 |
| 473 Node* InspectorDOMAgent::assertEditableChildNode(ErrorString* errorString, Eleme nt* parentElement, int nodeId) | |
| 474 { | |
| 475 Node* node = assertEditableNode(errorString, nodeId); | |
| 476 if (!node) | |
| 477 return 0; | |
| 478 if (node->parentNode() != parentElement) { | |
| 479 *errorString = "Anchor node must be child of the target element"; | |
| 480 return 0; | |
| 481 } | |
| 482 return node; | |
| 483 } | |
| 484 | |
| 473 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int nodeId) | 485 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int nodeId) |
| 474 { | 486 { |
| 475 Element* element = assertElement(errorString, nodeId); | 487 Element* element = assertElement(errorString, nodeId); |
| 476 if (!element) | 488 if (!element) |
| 477 return 0; | 489 return 0; |
| 478 | 490 |
| 479 if (element->isInShadowTree() && userAgentShadowRoot(element)) { | 491 if (element->isInShadowTree() && userAgentShadowRoot(element)) { |
| 480 *errorString = "Cannot edit elements from user-agent shadow trees"; | 492 *errorString = "Cannot edit elements from user-agent shadow trees"; |
| 481 return 0; | 493 return 0; |
| 482 } | 494 } |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1287 highlightConfig->contentOutline = parseColor(outlineColor); | 1299 highlightConfig->contentOutline = parseColor(outlineColor); |
| 1288 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); | 1300 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); |
| 1289 } | 1301 } |
| 1290 } | 1302 } |
| 1291 | 1303 |
| 1292 void InspectorDOMAgent::hideHighlight(ErrorString*) | 1304 void InspectorDOMAgent::hideHighlight(ErrorString*) |
| 1293 { | 1305 { |
| 1294 m_overlay->hideHighlight(); | 1306 m_overlay->hideHighlight(); |
| 1295 } | 1307 } |
| 1296 | 1308 |
| 1297 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) | 1309 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) |
| 1298 { | 1310 { |
| 1299 Node* node = assertEditableNode(errorString, nodeId); | 1311 Node* node = assertEditableNode(errorString, nodeId); |
| 1300 if (!node) | 1312 if (!node) |
| 1301 return; | 1313 return; |
| 1302 | 1314 |
| 1303 Element* targetElement = assertEditableElement(errorString, targetElementId) ; | 1315 Element* targetElement = assertEditableElement(errorString, targetElementId) ; |
| 1304 if (!targetElement) | 1316 if (!targetElement) |
| 1305 return; | 1317 return; |
| 1306 | 1318 |
| 1307 Node* anchorNode = 0; | 1319 Node* anchorNode = 0; |
| 1308 if (anchorNodeId && *anchorNodeId) { | 1320 if (anchorNodeId && *anchorNodeId) { |
| 1309 anchorNode = assertEditableNode(errorString, *anchorNodeId); | 1321 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor NodeId); |
| 1310 if (!anchorNode) | 1322 if (!anchorNode) |
| 1311 return; | 1323 return; |
| 1312 if (anchorNode->parentNode() != targetElement) { | 1324 } |
| 1313 *errorString = "Anchor node must be child of the target element"; | 1325 |
| 1326 // The clone is deep by default. | |
| 1327 RefPtrWillBeRawPtr<Node> clonedNode = node->cloneNode(true); | |
|
aandrey
2014/07/25 13:32:54
what if node==targetElement? should it be a noop?
apavlov
2014/07/25 15:04:47
No - a clone of the node with its children will be
| |
| 1328 if (!clonedNode) { | |
| 1329 *errorString = "Failed to clone node"; | |
| 1330 return; | |
| 1331 } | |
| 1332 if (!m_domEditor->insertBefore(targetElement, clonedNode, anchorNode, errorS tring)) | |
| 1333 return; | |
| 1334 | |
| 1335 *newNodeId = pushNodePathToFrontend(clonedNode.get()); | |
| 1336 } | |
| 1337 | |
| 1338 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) | |
| 1339 { | |
| 1340 Node* node = assertEditableNode(errorString, nodeId); | |
| 1341 if (!node) | |
| 1342 return; | |
| 1343 | |
| 1344 Element* targetElement = assertEditableElement(errorString, targetElementId) ; | |
| 1345 if (!targetElement) | |
| 1346 return; | |
| 1347 | |
| 1348 Node* current = targetElement; | |
| 1349 while (current && current != node) | |
| 1350 current = current->parentNode(); | |
| 1351 if (current == node) { | |
|
aandrey
2014/07/25 13:32:54
nit: i'd move this check inside the loop
apavlov
2014/07/25 15:04:47
Done.
| |
| 1352 *errorString = "Unable to move node into self or descendant"; | |
|
aandrey
2014/07/25 13:32:54
i'd expect moving node to self to be a noop w/o er
apavlov
2014/07/25 15:04:47
Moving a node to its own list of children is defin
| |
| 1353 return; | |
| 1354 } | |
| 1355 | |
| 1356 Node* anchorNode = 0; | |
| 1357 if (anchorNodeId && *anchorNodeId) { | |
| 1358 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor NodeId); | |
| 1359 if (!anchorNode) | |
| 1314 return; | 1360 return; |
| 1315 } | |
| 1316 } | 1361 } |
| 1317 | 1362 |
| 1318 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString) ) | 1363 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString) ) |
| 1319 return; | 1364 return; |
| 1320 | 1365 |
| 1321 *newNodeId = pushNodePathToFrontend(node); | 1366 *newNodeId = pushNodePathToFrontend(node); |
| 1322 } | 1367 } |
| 1323 | 1368 |
| 1324 void InspectorDOMAgent::undo(ErrorString* errorString) | 1369 void InspectorDOMAgent::undo(ErrorString* errorString) |
| 1325 { | 1370 { |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2138 visitor->trace(m_searchResults); | 2183 visitor->trace(m_searchResults); |
| 2139 #endif | 2184 #endif |
| 2140 visitor->trace(m_history); | 2185 visitor->trace(m_history); |
| 2141 visitor->trace(m_domEditor); | 2186 visitor->trace(m_domEditor); |
| 2142 visitor->trace(m_listener); | 2187 visitor->trace(m_listener); |
| 2143 InspectorBaseAgent::trace(visitor); | 2188 InspectorBaseAgent::trace(visitor); |
| 2144 } | 2189 } |
| 2145 | 2190 |
| 2146 } // namespace blink | 2191 } // namespace blink |
| 2147 | 2192 |
| OLD | NEW |