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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 } | 472 } |
473 | 473 |
474 if (node->isPseudoElement()) { | 474 if (node->isPseudoElement()) { |
475 *errorString = "Cannot edit pseudo elements"; | 475 *errorString = "Cannot edit pseudo elements"; |
476 return 0; | 476 return 0; |
477 } | 477 } |
478 | 478 |
479 return node; | 479 return node; |
480 } | 480 } |
481 | 481 |
| 482 Node* InspectorDOMAgent::assertEditableChildNode(ErrorString* errorString, Eleme
nt* parentElement, int nodeId) |
| 483 { |
| 484 Node* node = assertEditableNode(errorString, nodeId); |
| 485 if (!node) |
| 486 return 0; |
| 487 if (node->parentNode() != parentElement) { |
| 488 *errorString = "Anchor node must be child of the target element"; |
| 489 return 0; |
| 490 } |
| 491 return node; |
| 492 } |
| 493 |
482 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int
nodeId) | 494 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int
nodeId) |
483 { | 495 { |
484 Element* element = assertElement(errorString, nodeId); | 496 Element* element = assertElement(errorString, nodeId); |
485 if (!element) | 497 if (!element) |
486 return 0; | 498 return 0; |
487 | 499 |
488 if (element->isInShadowTree() && userAgentShadowRoot(element)) { | 500 if (element->isInShadowTree() && userAgentShadowRoot(element)) { |
489 *errorString = "Cannot edit elements from user-agent shadow trees"; | 501 *errorString = "Cannot edit elements from user-agent shadow trees"; |
490 return 0; | 502 return 0; |
491 } | 503 } |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 highlightConfig->contentOutline = parseColor(outlineColor); | 1307 highlightConfig->contentOutline = parseColor(outlineColor); |
1296 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget
*/, *highlightConfig, false); | 1308 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget
*/, *highlightConfig, false); |
1297 } | 1309 } |
1298 } | 1310 } |
1299 | 1311 |
1300 void InspectorDOMAgent::hideHighlight(ErrorString*) | 1312 void InspectorDOMAgent::hideHighlight(ErrorString*) |
1301 { | 1313 { |
1302 m_overlay->hideHighlight(); | 1314 m_overlay->hideHighlight(); |
1303 } | 1315 } |
1304 | 1316 |
1305 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE
lementId, const int* const anchorNodeId, int* newNodeId) | 1317 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE
lementId, const int* const anchorNodeId, int* newNodeId) |
1306 { | 1318 { |
1307 Node* node = assertEditableNode(errorString, nodeId); | 1319 Node* node = assertEditableNode(errorString, nodeId); |
1308 if (!node) | 1320 if (!node) |
1309 return; | 1321 return; |
1310 | 1322 |
1311 Element* targetElement = assertEditableElement(errorString, targetElementId)
; | 1323 Element* targetElement = assertEditableElement(errorString, targetElementId)
; |
1312 if (!targetElement) | 1324 if (!targetElement) |
1313 return; | 1325 return; |
1314 | 1326 |
1315 Node* anchorNode = 0; | 1327 Node* anchorNode = 0; |
1316 if (anchorNodeId && *anchorNodeId) { | 1328 if (anchorNodeId && *anchorNodeId) { |
1317 anchorNode = assertEditableNode(errorString, *anchorNodeId); | 1329 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor
NodeId); |
1318 if (!anchorNode) | 1330 if (!anchorNode) |
1319 return; | 1331 return; |
1320 if (anchorNode->parentNode() != targetElement) { | 1332 } |
1321 *errorString = "Anchor node must be child of the target element"; | 1333 |
| 1334 // The clone is deep by default. |
| 1335 RefPtrWillBeRawPtr<Node> clonedNode = node->cloneNode(true); |
| 1336 if (!clonedNode) { |
| 1337 *errorString = "Failed to clone node"; |
| 1338 return; |
| 1339 } |
| 1340 if (!m_domEditor->insertBefore(targetElement, clonedNode, anchorNode, errorS
tring)) |
| 1341 return; |
| 1342 |
| 1343 *newNodeId = pushNodePathToFrontend(clonedNode.get()); |
| 1344 } |
| 1345 |
| 1346 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE
lementId, const int* const anchorNodeId, int* newNodeId) |
| 1347 { |
| 1348 Node* node = assertEditableNode(errorString, nodeId); |
| 1349 if (!node) |
| 1350 return; |
| 1351 |
| 1352 Element* targetElement = assertEditableElement(errorString, targetElementId)
; |
| 1353 if (!targetElement) |
| 1354 return; |
| 1355 |
| 1356 Node* current = targetElement; |
| 1357 while (current) { |
| 1358 if (current == node) { |
| 1359 *errorString = "Unable to move node into self or descendant"; |
1322 return; | 1360 return; |
1323 } | 1361 } |
| 1362 current = current->parentNode(); |
| 1363 } |
| 1364 |
| 1365 Node* anchorNode = 0; |
| 1366 if (anchorNodeId && *anchorNodeId) { |
| 1367 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor
NodeId); |
| 1368 if (!anchorNode) |
| 1369 return; |
1324 } | 1370 } |
1325 | 1371 |
1326 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString)
) | 1372 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString)
) |
1327 return; | 1373 return; |
1328 | 1374 |
1329 *newNodeId = pushNodePathToFrontend(node); | 1375 *newNodeId = pushNodePathToFrontend(node); |
1330 } | 1376 } |
1331 | 1377 |
1332 void InspectorDOMAgent::undo(ErrorString* errorString) | 1378 void InspectorDOMAgent::undo(ErrorString* errorString) |
1333 { | 1379 { |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 visitor->trace(m_searchResults); | 2193 visitor->trace(m_searchResults); |
2148 #endif | 2194 #endif |
2149 visitor->trace(m_history); | 2195 visitor->trace(m_history); |
2150 visitor->trace(m_domEditor); | 2196 visitor->trace(m_domEditor); |
2151 visitor->trace(m_listener); | 2197 visitor->trace(m_listener); |
2152 InspectorBaseAgent::trace(visitor); | 2198 InspectorBaseAgent::trace(visitor); |
2153 } | 2199 } |
2154 | 2200 |
2155 } // namespace blink | 2201 } // namespace blink |
2156 | 2202 |
OLD | NEW |