Chromium Code Reviews| Index: Source/core/inspector/InspectorDOMAgent.cpp |
| diff --git a/Source/core/inspector/InspectorDOMAgent.cpp b/Source/core/inspector/InspectorDOMAgent.cpp |
| index 19115bd984bc1da04c89f73c744716f9c3f60a57..8785fdd1917d92b95512bb35531d2f0c66abc066 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,12 +1316,39 @@ 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"; |
| - return; |
| + } |
| + |
| + // 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* anchorNode = 0; |
| + if (anchorNodeId && *anchorNodeId) { |
| + 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.
|
| + anchorNode = assertEditableChildNode(errorString, targetElement, *anchorNodeId); |
| + if (!anchorNode) |
| + return; |
| } |
| } |