| 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (!node) | 416 if (!node) |
| 417 return 0; | 417 return 0; |
| 418 | 418 |
| 419 if (node->nodeType() != Node::ELEMENT_NODE) { | 419 if (node->nodeType() != Node::ELEMENT_NODE) { |
| 420 *errorString = "Node is not an Element"; | 420 *errorString = "Node is not an Element"; |
| 421 return 0; | 421 return 0; |
| 422 } | 422 } |
| 423 return toElement(node); | 423 return toElement(node); |
| 424 } | 424 } |
| 425 | 425 |
| 426 static ShadowRoot* userAgentShadowRoot(Node* node) |
| 427 { |
| 428 if (!node || !node->isInShadowTree()) |
| 429 return 0; |
| 430 |
| 431 Node* candidate = node; |
| 432 while (candidate && !candidate->isShadowRoot()) |
| 433 candidate = candidate->parentOrShadowHostNode(); |
| 434 ASSERT(candidate); |
| 435 ShadowRoot* shadowRoot = toShadowRoot(candidate); |
| 436 |
| 437 return shadowRoot->type() == ShadowRoot::UserAgentShadowRoot ? shadowRoot :
0; |
| 438 } |
| 439 |
| 426 Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId
) | 440 Node* InspectorDOMAgent::assertEditableNode(ErrorString* errorString, int nodeId
) |
| 427 { | 441 { |
| 428 Node* node = assertNode(errorString, nodeId); | 442 Node* node = assertNode(errorString, nodeId); |
| 429 if (!node) | 443 if (!node) |
| 430 return 0; | 444 return 0; |
| 431 | 445 |
| 432 if (node->isInShadowTree()) { | 446 if (node->isInShadowTree()) { |
| 433 if (node->isShadowRoot()) { | 447 if (node->isShadowRoot()) { |
| 434 *errorString = "Cannot edit shadow roots"; | 448 *errorString = "Cannot edit shadow roots"; |
| 435 return 0; | 449 return 0; |
| 436 } | 450 } |
| 437 Node* candidate = node; | 451 if (userAgentShadowRoot(node)) { |
| 438 while (candidate && !candidate->isShadowRoot()) | |
| 439 candidate = candidate->parentElementOrShadowRoot(); | |
| 440 if (!candidate || (candidate->isShadowRoot() && toShadowRoot(candidate)-
>type() == ShadowRoot::UserAgentShadowRoot)) { | |
| 441 *errorString = "Cannot edit nodes from user-agent shadow trees"; | 452 *errorString = "Cannot edit nodes from user-agent shadow trees"; |
| 442 return 0; | 453 return 0; |
| 443 } | 454 } |
| 444 } | 455 } |
| 445 | 456 |
| 446 if (node->isPseudoElement()) { | 457 if (node->isPseudoElement()) { |
| 447 *errorString = "Cannot edit pseudo elements"; | 458 *errorString = "Cannot edit pseudo elements"; |
| 448 return 0; | 459 return 0; |
| 449 } | 460 } |
| 450 | 461 |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 } | 1131 } |
| 1121 return false; | 1132 return false; |
| 1122 } | 1133 } |
| 1123 | 1134 |
| 1124 void InspectorDOMAgent::inspect(Node* inspectedNode) | 1135 void InspectorDOMAgent::inspect(Node* inspectedNode) |
| 1125 { | 1136 { |
| 1126 if (!m_frontend || !inspectedNode) | 1137 if (!m_frontend || !inspectedNode) |
| 1127 return; | 1138 return; |
| 1128 | 1139 |
| 1129 Node* node = inspectedNode; | 1140 Node* node = inspectedNode; |
| 1130 if (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCU
MENT_NODE) | 1141 while (node && node->nodeType() != Node::ELEMENT_NODE && node->nodeType() !=
Node::DOCUMENT_NODE && node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) |
| 1131 node = node->parentNode(); | 1142 node = node->parentOrShadowHostNode(); |
| 1143 |
| 1144 if (!node) |
| 1145 return; |
| 1132 | 1146 |
| 1133 int nodeId = pushNodePathToFrontend(node); | 1147 int nodeId = pushNodePathToFrontend(node); |
| 1134 if (nodeId) | 1148 if (nodeId) |
| 1135 m_frontend->inspectNodeRequested(nodeId); | 1149 m_frontend->inspectNodeRequested(nodeId); |
| 1136 } | 1150 } |
| 1137 | 1151 |
| 1138 void InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv
ent& event) | 1152 void InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv
ent& event) |
| 1139 { | 1153 { |
| 1140 if (m_searchingForNode == NotSearching) | 1154 if (m_searchingForNode == NotSearching) |
| 1141 return; | 1155 return; |
| 1142 | 1156 |
| 1143 if (!frame->view() || !frame->contentRenderer()) | 1157 if (!frame->view() || !frame->contentRenderer()) |
| 1144 return; | 1158 return; |
| 1145 Node* node = hoveredNodeForEvent(frame, event, event.shiftKey()); | 1159 Node* node = hoveredNodeForEvent(frame, event, event.shiftKey()); |
| 1146 | 1160 |
| 1147 while (m_searchingForNode != SearchingForShadow && node && node->isInShadowT
ree()) | 1161 // Do not highlight within UA shadow root unless requested. |
| 1162 if (m_searchingForNode != SearchingForUAShadow) { |
| 1163 ShadowRoot* uaShadowRoot = userAgentShadowRoot(node); |
| 1164 if (uaShadowRoot) |
| 1165 node = uaShadowRoot->host(); |
| 1166 } |
| 1167 |
| 1168 // Shadow roots don't have boxes - use host element instead. |
| 1169 if (node && node->isShadowRoot()) |
| 1148 node = node->parentOrShadowHostNode(); | 1170 node = node->parentOrShadowHostNode(); |
| 1149 | 1171 |
| 1172 if (!node) |
| 1173 return; |
| 1174 |
| 1150 Node* eventTarget = event.shiftKey() ? hoveredNodeForEvent(frame, event, fal
se) : 0; | 1175 Node* eventTarget = event.shiftKey() ? hoveredNodeForEvent(frame, event, fal
se) : 0; |
| 1151 if (eventTarget == node) | 1176 if (eventTarget == node) |
| 1152 eventTarget = 0; | 1177 eventTarget = 0; |
| 1153 | 1178 |
| 1154 if (node && m_inspectModeHighlightConfig) | 1179 if (node && m_inspectModeHighlightConfig) |
| 1155 m_overlay->highlightNode(node, eventTarget, *m_inspectModeHighlightConfi
g); | 1180 m_overlay->highlightNode(node, eventTarget, *m_inspectModeHighlightConfi
g); |
| 1156 } | 1181 } |
| 1157 | 1182 |
| 1158 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode
searchMode, JSONObject* highlightInspectorObject) | 1183 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode
searchMode, JSONObject* highlightInspectorObject) |
| 1159 { | 1184 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1186 highlightConfig->showRulers = showRulers; | 1211 highlightConfig->showRulers = showRulers; |
| 1187 highlightConfig->content = parseConfigColor("contentColor", highlightInspect
orObject); | 1212 highlightConfig->content = parseConfigColor("contentColor", highlightInspect
orObject); |
| 1188 highlightConfig->contentOutline = parseConfigColor("contentOutlineColor", hi
ghlightInspectorObject); | 1213 highlightConfig->contentOutline = parseConfigColor("contentOutlineColor", hi
ghlightInspectorObject); |
| 1189 highlightConfig->padding = parseConfigColor("paddingColor", highlightInspect
orObject); | 1214 highlightConfig->padding = parseConfigColor("paddingColor", highlightInspect
orObject); |
| 1190 highlightConfig->border = parseConfigColor("borderColor", highlightInspector
Object); | 1215 highlightConfig->border = parseConfigColor("borderColor", highlightInspector
Object); |
| 1191 highlightConfig->margin = parseConfigColor("marginColor", highlightInspector
Object); | 1216 highlightConfig->margin = parseConfigColor("marginColor", highlightInspector
Object); |
| 1192 highlightConfig->eventTarget = parseConfigColor("eventTargetColor", highligh
tInspectorObject); | 1217 highlightConfig->eventTarget = parseConfigColor("eventTargetColor", highligh
tInspectorObject); |
| 1193 return highlightConfig.release(); | 1218 return highlightConfig.release(); |
| 1194 } | 1219 } |
| 1195 | 1220 |
| 1196 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena
bled, const bool* inspectShadowDOM, const RefPtr<JSONObject>* highlightConfig) | 1221 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena
bled, const bool* inspectUAShadowDOM, const RefPtr<JSONObject>* highlightConfig) |
| 1197 { | 1222 { |
| 1198 if (enabled && !pushDocumentUponHandlelessOperation(errorString)) | 1223 if (enabled && !pushDocumentUponHandlelessOperation(errorString)) |
| 1199 return; | 1224 return; |
| 1200 SearchMode searchMode = enabled ? (inspectShadowDOM && *inspectShadowDOM ? S
earchingForShadow : SearchingForNormal) : NotSearching; | 1225 SearchMode searchMode = enabled ? (inspectUAShadowDOM && *inspectUAShadowDOM
? SearchingForUAShadow : SearchingForNormal) : NotSearching; |
| 1201 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf
ig->get() : 0); | 1226 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf
ig->get() : 0); |
| 1202 } | 1227 } |
| 1203 | 1228 |
| 1204 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int
height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor
) | 1229 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int
height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor
) |
| 1205 { | 1230 { |
| 1206 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh
t))); | 1231 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh
t))); |
| 1207 innerHighlightQuad(quad.release(), color, outlineColor); | 1232 innerHighlightQuad(quad.release(), color, outlineColor); |
| 1208 } | 1233 } |
| 1209 | 1234 |
| 1210 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO
NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o
utlineColor) | 1235 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO
NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o
utlineColor) |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2072 if (!m_documentNodeToIdMap.contains(m_document)) { | 2097 if (!m_documentNodeToIdMap.contains(m_document)) { |
| 2073 RefPtr<TypeBuilder::DOM::Node> root; | 2098 RefPtr<TypeBuilder::DOM::Node> root; |
| 2074 getDocument(errorString, root); | 2099 getDocument(errorString, root); |
| 2075 return errorString->isEmpty(); | 2100 return errorString->isEmpty(); |
| 2076 } | 2101 } |
| 2077 return true; | 2102 return true; |
| 2078 } | 2103 } |
| 2079 | 2104 |
| 2080 } // namespace WebCore | 2105 } // namespace WebCore |
| 2081 | 2106 |
| OLD | NEW |