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

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

Issue 197283031: DevTools: fix author shadow dom inspection mode, speacial-case ua. Fix crash from the bug. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For landing Created 6 years, 9 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
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/devtools/front_end/DOMAgent.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorDOMAgent.cpp
diff --git a/Source/core/inspector/InspectorDOMAgent.cpp b/Source/core/inspector/InspectorDOMAgent.cpp
index cb1d0afc0ae75ea8051237193a85caaad8f10b54..17ad00b81e1fd45d2c8d8ea96973c7525fac7733 100644
--- a/Source/core/inspector/InspectorDOMAgent.cpp
+++ b/Source/core/inspector/InspectorDOMAgent.cpp
@@ -423,6 +423,20 @@ Element* InspectorDOMAgent::assertElement(ErrorString* errorString, int nodeId)
return toElement(node);
}
+static ShadowRoot* userAgentShadowRoot(Node* node)
+{
+ if (!node || !node->isInShadowTree())
+ return 0;
+
+ Node* candidate = node;
+ while (candidate && !candidate->isShadowRoot())
+ candidate = candidate->parentOrShadowHostNode();
+ ASSERT(candidate);
+ ShadowRoot* shadowRoot = toShadowRoot(candidate);
+
+ return shadowRoot->type() == ShadowRoot::UserAgentShadowRoot ? shadowRoot : 0;
+}
+
Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId)
{
Node* node = assertNode(errorString, nodeId);
@@ -434,10 +448,7 @@ Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId
*errorString = "Cannot edit shadow roots";
return 0;
}
- Node* candidate = node;
- while (candidate && !candidate->isShadowRoot())
- candidate = candidate->parentElementOrShadowRoot();
- if (!candidate || (candidate->isShadowRoot() && toShadowRoot(candidate)->type() == ShadowRoot::UserAgentShadowRoot)) {
+ if (userAgentShadowRoot(node)) {
*errorString = "Cannot edit nodes from user-agent shadow trees";
return 0;
}
@@ -1127,8 +1138,11 @@ void InspectorDOMAgent::inspect(Node* inspectedNode)
return;
Node* node = inspectedNode;
- if (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE)
- node = node->parentNode();
+ while (node && node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE && node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE)
+ node = node->parentOrShadowHostNode();
+
+ if (!node)
+ return;
int nodeId = pushNodePathToFrontend(node);
if (nodeId)
@@ -1144,9 +1158,20 @@ void InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv
return;
Node* node = hoveredNodeForEvent(frame, event, event.shiftKey());
- while (m_searchingForNode != SearchingForShadow && node && node->isInShadowTree())
+ // Do not highlight within UA shadow root unless requested.
+ if (m_searchingForNode != SearchingForUAShadow) {
+ ShadowRoot* uaShadowRoot = userAgentShadowRoot(node);
+ if (uaShadowRoot)
+ node = uaShadowRoot->host();
+ }
+
+ // Shadow roots don't have boxes - use host element instead.
+ if (node && node->isShadowRoot())
node = node->parentOrShadowHostNode();
+ if (!node)
+ return;
+
Node* eventTarget = event.shiftKey() ? hoveredNodeForEvent(frame, event, false) : 0;
if (eventTarget == node)
eventTarget = 0;
@@ -1193,11 +1218,11 @@ PassOwnPtr<HighlightConfig> InspectorDOMAgent::highlightConfigFromInspectorObjec
return highlightConfig.release();
}
-void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool enabled, const bool* inspectShadowDOM, const RefPtr<JSONObject>* highlightConfig)
+void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool enabled, const bool* inspectUAShadowDOM, const RefPtr<JSONObject>* highlightConfig)
{
if (enabled && !pushDocumentUponHandlelessOperation(errorString))
return;
- SearchMode searchMode = enabled ? (inspectShadowDOM && *inspectShadowDOM ? SearchingForShadow : SearchingForNormal) : NotSearching;
+ SearchMode searchMode = enabled ? (inspectUAShadowDOM && *inspectUAShadowDOM ? SearchingForUAShadow : SearchingForNormal) : NotSearching;
setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConfig->get() : 0);
}
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/devtools/front_end/DOMAgent.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698