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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 } | 461 } |
462 | 462 |
463 if (node->isPseudoElement()) { | 463 if (node->isPseudoElement()) { |
464 *errorString = "Cannot edit pseudo elements"; | 464 *errorString = "Cannot edit pseudo elements"; |
465 return 0; | 465 return 0; |
466 } | 466 } |
467 | 467 |
468 return node; | 468 return node; |
469 } | 469 } |
470 | 470 |
471 Node* InspectorDOMAgent::assertEditableChildNode(ErrorString* errorString, Eleme nt* parentElement, int nodeId) | |
472 { | |
473 Node* node = assertEditableNode(errorString, nodeId); | |
474 if (!node) | |
475 return 0; | |
476 if (node->parentNode() != parentElement) { | |
477 *errorString = "Anchor node must be child of the target element"; | |
478 return 0; | |
479 } | |
480 return node; | |
481 } | |
482 | |
471 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int nodeId) | 483 Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int nodeId) |
472 { | 484 { |
473 Element* element = assertElement(errorString, nodeId); | 485 Element* element = assertElement(errorString, nodeId); |
474 if (!element) | 486 if (!element) |
475 return 0; | 487 return 0; |
476 | 488 |
477 if (element->isInShadowTree() && userAgentShadowRoot(element)) { | 489 if (element->isInShadowTree() && userAgentShadowRoot(element)) { |
478 *errorString = "Cannot edit elements from user-agent shadow trees"; | 490 *errorString = "Cannot edit elements from user-agent shadow trees"; |
479 return 0; | 491 return 0; |
480 } | 492 } |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 highlightConfig->contentOutline = parseColor(outlineColor); | 1297 highlightConfig->contentOutline = parseColor(outlineColor); |
1286 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); | 1298 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); |
1287 } | 1299 } |
1288 } | 1300 } |
1289 | 1301 |
1290 void InspectorDOMAgent::hideHighlight(ErrorString*) | 1302 void InspectorDOMAgent::hideHighlight(ErrorString*) |
1291 { | 1303 { |
1292 m_overlay->hideHighlight(); | 1304 m_overlay->hideHighlight(); |
1293 } | 1305 } |
1294 | 1306 |
1295 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) | 1307 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, const bool* const deep, int* newNodeId) |
1296 { | 1308 { |
1297 Node* node = assertEditableNode(errorString, nodeId); | 1309 Node* node = assertEditableNode(errorString, nodeId); |
1298 if (!node) | 1310 if (!node) |
1299 return; | 1311 return; |
1300 | 1312 |
1301 Element* targetElement = assertEditableElement(errorString, targetElementId) ; | 1313 Element* targetElement = assertEditableElement(errorString, targetElementId) ; |
1302 if (!targetElement) | 1314 if (!targetElement) |
1303 return; | 1315 return; |
1304 | 1316 |
1305 Node* anchorNode = 0; | 1317 Node* anchorNode = 0; |
1306 if (anchorNodeId && *anchorNodeId) { | 1318 if (anchorNodeId && *anchorNodeId) { |
1307 anchorNode = assertEditableNode(errorString, *anchorNodeId); | 1319 anchorNode = assertEditableChildNode(errorString, targetElement, *anchor NodeId); |
1308 if (!anchorNode) | 1320 if (!anchorNode) |
1309 return; | 1321 return; |
1310 if (anchorNode->parentNode() != targetElement) { | 1322 } |
1311 *errorString = "Anchor node must be child of the target element"; | 1323 |
1312 return; | 1324 // The clone is deep by default. |
1325 RefPtrWillBeRawPtr<Node> clonedNode = node->cloneNode(!deep || *deep); | |
1326 if (!clonedNode) { | |
1327 *errorString = "Failed to clone node"; | |
1328 return; | |
1329 } | |
1330 if (!m_domEditor->insertBefore(targetElement, clonedNode, anchorNode, errorS tring)) | |
1331 return; | |
1332 | |
1333 *newNodeId = pushNodePathToFrontend(clonedNode.get()); | |
1334 } | |
1335 | |
1336 void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) | |
1337 { | |
1338 Node* node = assertEditableNode(errorString, nodeId); | |
1339 if (!node) | |
1340 return; | |
1341 | |
1342 Element* targetElement = assertEditableElement(errorString, targetElementId) ; | |
1343 if (!targetElement) | |
1344 return; | |
1345 | |
1346 Node* anchorNode = 0; | |
1347 if (anchorNodeId && *anchorNodeId) { | |
1348 if (anchorNodeId && *anchorNodeId) { | |
aandrey
2014/07/18 05:30:04
dup if-
apavlov
2014/07/18 09:02:07
Just to be absolutely sure :) Done.
| |
1349 anchorNode = assertEditableChildNode(errorString, targetElement, *an chorNodeId); | |
1350 if (!anchorNode) | |
1351 return; | |
1313 } | 1352 } |
1314 } | 1353 } |
1315 | 1354 |
1316 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString) ) | 1355 if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString) ) |
1317 return; | 1356 return; |
1318 | 1357 |
1319 *newNodeId = pushNodePathToFrontend(node); | 1358 *newNodeId = pushNodePathToFrontend(node); |
1320 } | 1359 } |
1321 | 1360 |
1322 void InspectorDOMAgent::undo(ErrorString* errorString) | 1361 void InspectorDOMAgent::undo(ErrorString* errorString) |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2118 if (!m_documentNodeToIdMap->contains(m_document.get())) { | 2157 if (!m_documentNodeToIdMap->contains(m_document.get())) { |
2119 RefPtr<TypeBuilder::DOM::Node> root; | 2158 RefPtr<TypeBuilder::DOM::Node> root; |
2120 getDocument(errorString, root); | 2159 getDocument(errorString, root); |
2121 return errorString->isEmpty(); | 2160 return errorString->isEmpty(); |
2122 } | 2161 } |
2123 return true; | 2162 return true; |
2124 } | 2163 } |
2125 | 2164 |
2126 } // namespace WebCore | 2165 } // namespace WebCore |
2127 | 2166 |
OLD | NEW |