| Index: Source/core/inspector/InspectorDOMAgent.cpp
|
| diff --git a/Source/core/inspector/InspectorDOMAgent.cpp b/Source/core/inspector/InspectorDOMAgent.cpp
|
| index 19115bd984bc1da04c89f73c744716f9c3f60a57..63c25d3534e8e4493c444d10749b13fd6469b157 100644
|
| --- a/Source/core/inspector/InspectorDOMAgent.cpp
|
| +++ b/Source/core/inspector/InspectorDOMAgent.cpp
|
| @@ -468,6 +468,18 @@ Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId
|
| return node;
|
| }
|
|
|
| +Node* InspectorDOMAgent::assertEditableChildNode(ErrorString* errorString, Element* parentElement, int nodeId)
|
| +{
|
| + Node* node = assertEditableNode(errorString, nodeId);
|
| + if (!node)
|
| + return 0;
|
| + if (node->parentNode() != parentElement) {
|
| + *errorString = "Anchor node must be child of the target element";
|
| + return 0;
|
| + }
|
| + return node;
|
| +}
|
| +
|
| Element* InspectorDOMAgent::assertEditableElement(ErrorString* errorString, int nodeId)
|
| {
|
| Element* element = assertElement(errorString, nodeId);
|
| @@ -1292,7 +1304,7 @@ void InspectorDOMAgent::hideHighlight(ErrorString*)
|
| m_overlay->hideHighlight();
|
| }
|
|
|
| -void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetElementId, const int* const anchorNodeId, int* newNodeId)
|
| +void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetElementId, const int* const anchorNodeId, const bool* const deep, int* newNodeId)
|
| {
|
| Node* node = assertEditableNode(errorString, nodeId);
|
| if (!node)
|
| @@ -1304,13 +1316,46 @@ void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetE
|
|
|
| Node* anchorNode = 0;
|
| if (anchorNodeId && *anchorNodeId) {
|
| - anchorNode = assertEditableNode(errorString, *anchorNodeId);
|
| + anchorNode = assertEditableChildNode(errorString, targetElement, *anchorNodeId);
|
| if (!anchorNode)
|
| return;
|
| - if (anchorNode->parentNode() != targetElement) {
|
| - *errorString = "Anchor node must be child of the target element";
|
| + }
|
| +
|
| + // The clone is deep by default.
|
| + RefPtrWillBeRawPtr<Node> clonedNode = node->cloneNode(!deep || *deep);
|
| + if (!clonedNode) {
|
| + *errorString = "Failed to clone node";
|
| + return;
|
| + }
|
| + if (!m_domEditor->insertBefore(targetElement, clonedNode, anchorNode, errorString))
|
| + return;
|
| +
|
| + *newNodeId = pushNodePathToFrontend(clonedNode.get());
|
| +}
|
| +
|
| +void InspectorDOMAgent::moveTo(ErrorString* errorString, int nodeId, int targetElementId, const int* const anchorNodeId, int* newNodeId)
|
| +{
|
| + Node* node = assertEditableNode(errorString, nodeId);
|
| + if (!node)
|
| + return;
|
| +
|
| + Element* targetElement = assertEditableElement(errorString, targetElementId);
|
| + if (!targetElement)
|
| + return;
|
| +
|
| + Node* current = targetElement;
|
| + while (current && current != node)
|
| + current = current->parentNode();
|
| + if (current == node) {
|
| + *errorString = "Unable to move node into self or descendant";
|
| + return;
|
| + }
|
| +
|
| + Node* anchorNode = 0;
|
| + if (anchorNodeId && *anchorNodeId) {
|
| + anchorNode = assertEditableChildNode(errorString, targetElement, *anchorNodeId);
|
| + if (!anchorNode)
|
| return;
|
| - }
|
| }
|
|
|
| if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString))
|
|
|