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); |
| 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) { |
| 1350 if (current == node) { |
| 1351 *errorString = "Unable to move node into self or descendant"; |
1314 return; | 1352 return; |
1315 } | 1353 } |
| 1354 current = current->parentNode(); |
| 1355 } |
| 1356 |
| 1357 Node* anchorNode = 0; |
| 1358 if (anchorNodeId && *anchorNodeId) { |
| 1359 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor
NodeId); |
| 1360 if (!anchorNode) |
| 1361 return; |
1316 } | 1362 } |
1317 | 1363 |
1318 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString)
) | 1364 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString)
) |
1319 return; | 1365 return; |
1320 | 1366 |
1321 *newNodeId = pushNodePathToFrontend(node); | 1367 *newNodeId = pushNodePathToFrontend(node); |
1322 } | 1368 } |
1323 | 1369 |
1324 void InspectorDOMAgent::undo(ErrorString* errorString) | 1370 void InspectorDOMAgent::undo(ErrorString* errorString) |
1325 { | 1371 { |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 visitor->trace(m_searchResults); | 2184 visitor->trace(m_searchResults); |
2139 #endif | 2185 #endif |
2140 visitor->trace(m_history); | 2186 visitor->trace(m_history); |
2141 visitor->trace(m_domEditor); | 2187 visitor->trace(m_domEditor); |
2142 visitor->trace(m_listener); | 2188 visitor->trace(m_listener); |
2143 InspectorBaseAgent::trace(visitor); | 2189 InspectorBaseAgent::trace(visitor); |
2144 } | 2190 } |
2145 | 2191 |
2146 } // namespace blink | 2192 } // namespace blink |
2147 | 2193 |
OLD | NEW |