Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1294)

Unified Diff: Source/core/inspector/InspectorDOMAgent.cpp

Issue 397303002: DevTools: [Elements] Implement shortcut-based node cut-copy-pasting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make DOMAgent.copyTo hidden Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/inspector/InspectorDOMAgent.cpp
diff --git a/Source/core/inspector/InspectorDOMAgent.cpp b/Source/core/inspector/InspectorDOMAgent.cpp
index a6855bd138a2487b255c1ea3f32e20d7619d8d84..1d259726967abcf8a4bc7b1de53d35380c571b35 100644
--- a/Source/core/inspector/InspectorDOMAgent.cpp
+++ b/Source/core/inspector/InspectorDOMAgent.cpp
@@ -470,6 +470,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);
@@ -1294,7 +1306,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, int* newNodeId)
{
Node* node = assertEditableNode(errorString, nodeId);
if (!node)
@@ -1306,13 +1318,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(true);
aandrey 2014/07/25 13:32:54 what if node==targetElement? should it be a noop?
apavlov 2014/07/25 15:04:47 No - a clone of the node with its children will be
+ 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) {
aandrey 2014/07/25 13:32:54 nit: i'd move this check inside the loop
apavlov 2014/07/25 15:04:47 Done.
+ *errorString = "Unable to move node into self or descendant";
aandrey 2014/07/25 13:32:54 i'd expect moving node to self to be a noop w/o er
apavlov 2014/07/25 15:04:47 Moving a node to its own list of children is defin
+ return;
+ }
+
+ Node* anchorNode = 0;
+ if (anchorNodeId && *anchorNodeId) {
+ anchorNode = assertEditableChildNode(errorString, targetElement, *anchorNodeId);
+ if (!anchorNode)
return;
- }
}
if (!m_domEditor->insertBefore(targetElement, node, anchorNode, errorString))

Powered by Google App Engine
This is Rietveld 408576698