| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 quad->setP1(FloatPoint(coordinates[0], coordinates[1])); | 150 quad->setP1(FloatPoint(coordinates[0], coordinates[1])); |
| 151 quad->setP2(FloatPoint(coordinates[2], coordinates[3])); | 151 quad->setP2(FloatPoint(coordinates[2], coordinates[3])); |
| 152 quad->setP3(FloatPoint(coordinates[4], coordinates[5])); | 152 quad->setP3(FloatPoint(coordinates[4], coordinates[5])); |
| 153 quad->setP4(FloatPoint(coordinates[6], coordinates[7])); | 153 quad->setP4(FloatPoint(coordinates[6], coordinates[7])); |
| 154 | 154 |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 Node* hoveredNodeForPoint(LocalFrame* frame, const IntPoint& pointInRootFrame, b
ool ignorePointerEventsNone) | |
| 159 { | |
| 160 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move | HitTestR
equest::ReadOnly | HitTestRequest::AllowChildFrameContent; | |
| 161 if (ignorePointerEventsNone) | |
| 162 hitType |= HitTestRequest::IgnorePointerEventsNone; | |
| 163 HitTestRequest request(hitType); | |
| 164 HitTestResult result(request, frame->view()->rootFrameToContents(pointInRoot
Frame)); | |
| 165 frame->contentLayoutObject()->hitTest(result); | |
| 166 Node* node = result.innerPossiblyPseudoNode(); | |
| 167 while (node && node->nodeType() == Node::TEXT_NODE) | |
| 168 node = node->parentNode(); | |
| 169 return node; | |
| 170 } | |
| 171 | |
| 172 Node* hoveredNodeForEvent(LocalFrame* frame, const PlatformGestureEvent& event,
bool ignorePointerEventsNone) | |
| 173 { | |
| 174 return hoveredNodeForPoint(frame, event.position(), ignorePointerEventsNone)
; | |
| 175 } | |
| 176 | |
| 177 Node* hoveredNodeForEvent(LocalFrame* frame, const PlatformMouseEvent& event, bo
ol ignorePointerEventsNone) | |
| 178 { | |
| 179 return hoveredNodeForPoint(frame, event.position(), ignorePointerEventsNone)
; | |
| 180 } | |
| 181 | |
| 182 Node* hoveredNodeForEvent(LocalFrame* frame, const PlatformTouchEvent& event, bo
ol ignorePointerEventsNone) | |
| 183 { | |
| 184 const Vector<PlatformTouchPoint>& points = event.touchPoints(); | |
| 185 if (!points.size()) | |
| 186 return nullptr; | |
| 187 return hoveredNodeForPoint(frame, roundedIntPoint(points[0].pos()), ignorePo
interEventsNone); | |
| 188 } | |
| 189 | |
| 190 ScriptValue nodeAsScriptValue(ScriptState* scriptState, Node* node) | 158 ScriptValue nodeAsScriptValue(ScriptState* scriptState, Node* node) |
| 191 { | 159 { |
| 192 ScriptState::Scope scope(scriptState); | 160 ScriptState::Scope scope(scriptState); |
| 193 v8::Isolate* isolate = scriptState->isolate(); | 161 v8::Isolate* isolate = scriptState->isolate(); |
| 194 ExceptionState exceptionState(ExceptionState::ExecutionContext, "nodeAsScrip
tValue", "InjectedScriptHost", scriptState->context()->Global(), isolate); | 162 ExceptionState exceptionState(ExceptionState::ExecutionContext, "nodeAsScrip
tValue", "InjectedScriptHost", scriptState->context()->Global(), isolate); |
| 195 if (!BindingSecurity::shouldAllowAccessToNode(isolate, node, exceptionState)
) | 163 if (!BindingSecurity::shouldAllowAccessToNode(isolate, node, exceptionState)
) |
| 196 return ScriptValue(scriptState, v8::Null(isolate)); | 164 return ScriptValue(scriptState, v8::Null(isolate)); |
| 197 return ScriptValue(scriptState, toV8(node, scriptState->context()->Global(),
isolate)); | 165 return ScriptValue(scriptState, toV8(node, scriptState->context()->Global(),
isolate)); |
| 198 } | 166 } |
| 199 | 167 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 274 } |
| 307 | 275 |
| 308 InspectorDOMAgent::InspectorDOMAgent(InspectorPageAgent* pageAgent, InjectedScri
ptManager* injectedScriptManager, Client* client) | 276 InspectorDOMAgent::InspectorDOMAgent(InspectorPageAgent* pageAgent, InjectedScri
ptManager* injectedScriptManager, Client* client) |
| 309 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM") | 277 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM") |
| 310 , m_pageAgent(pageAgent) | 278 , m_pageAgent(pageAgent) |
| 311 , m_injectedScriptManager(injectedScriptManager) | 279 , m_injectedScriptManager(injectedScriptManager) |
| 312 , m_client(client) | 280 , m_client(client) |
| 313 , m_domListener(nullptr) | 281 , m_domListener(nullptr) |
| 314 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap())) | 282 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap())) |
| 315 , m_lastNodeId(1) | 283 , m_lastNodeId(1) |
| 316 , m_searchingForNode(NotSearching) | |
| 317 , m_suppressAttributeModifiedEvent(false) | 284 , m_suppressAttributeModifiedEvent(false) |
| 318 , m_backendNodeIdToInspect(0) | 285 , m_backendNodeIdToInspect(0) |
| 319 { | 286 { |
| 320 } | 287 } |
| 321 | 288 |
| 322 InspectorDOMAgent::~InspectorDOMAgent() | 289 InspectorDOMAgent::~InspectorDOMAgent() |
| 323 { | 290 { |
| 324 #if !ENABLE(OILPAN) | 291 #if !ENABLE(OILPAN) |
| 325 setDocument(nullptr); | 292 setDocument(nullptr); |
| 326 ASSERT(m_searchingForNode == NotSearching); | 293 ASSERT(m_searchingForNode == NotSearching); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (!node) | 434 if (!node) |
| 468 return nullptr; | 435 return nullptr; |
| 469 | 436 |
| 470 if (!node->isElementNode()) { | 437 if (!node->isElementNode()) { |
| 471 *errorString = "Node is not an Element"; | 438 *errorString = "Node is not an Element"; |
| 472 return nullptr; | 439 return nullptr; |
| 473 } | 440 } |
| 474 return toElement(node); | 441 return toElement(node); |
| 475 } | 442 } |
| 476 | 443 |
| 477 static ShadowRoot* userAgentShadowRoot(Node* node) | 444 // static |
| 445 ShadowRoot* InspectorDOMAgent::userAgentShadowRoot(Node* node) |
| 478 { | 446 { |
| 479 if (!node || !node->isInShadowTree()) | 447 if (!node || !node->isInShadowTree()) |
| 480 return nullptr; | 448 return nullptr; |
| 481 | 449 |
| 482 Node* candidate = node; | 450 Node* candidate = node; |
| 483 while (candidate && !candidate->isShadowRoot()) | 451 while (candidate && !candidate->isShadowRoot()) |
| 484 candidate = candidate->parentOrShadowHostNode(); | 452 candidate = candidate->parentOrShadowHostNode(); |
| 485 ASSERT(candidate); | 453 ASSERT(candidate); |
| 486 ShadowRoot* shadowRoot = toShadowRoot(candidate); | 454 ShadowRoot* shadowRoot = toShadowRoot(candidate); |
| 487 | 455 |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 nodeIds = TypeBuilder::Array<int>::create(); | 1085 nodeIds = TypeBuilder::Array<int>::create(); |
| 1118 for (int i = fromIndex; i < toIndex; ++i) | 1086 for (int i = fromIndex; i < toIndex; ++i) |
| 1119 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get())); | 1087 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get())); |
| 1120 } | 1088 } |
| 1121 | 1089 |
| 1122 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI
d) | 1090 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI
d) |
| 1123 { | 1091 { |
| 1124 m_searchResults.remove(searchId); | 1092 m_searchResults.remove(searchId); |
| 1125 } | 1093 } |
| 1126 | 1094 |
| 1127 bool InspectorDOMAgent::handleMousePress() | |
| 1128 { | |
| 1129 if (m_searchingForNode == NotSearching) | |
| 1130 return false; | |
| 1131 | |
| 1132 if (m_hoveredNodeForInspectMode) { | |
| 1133 inspect(m_hoveredNodeForInspectMode.get()); | |
| 1134 m_hoveredNodeForInspectMode.clear(); | |
| 1135 return true; | |
| 1136 } | |
| 1137 return false; | |
| 1138 } | |
| 1139 | |
| 1140 bool InspectorDOMAgent::handleGestureEvent(LocalFrame* frame, const PlatformGest
ureEvent& event) | |
| 1141 { | |
| 1142 if (m_searchingForNode == NotSearching || event.type() != PlatformEvent::Ges
tureTap) | |
| 1143 return false; | |
| 1144 Node* node = hoveredNodeForEvent(frame, event, false); | |
| 1145 if (node && m_inspectModeHighlightConfig) { | |
| 1146 if (m_client) | |
| 1147 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig
hlightConfig, false); | |
| 1148 inspect(node); | |
| 1149 return true; | |
| 1150 } | |
| 1151 return false; | |
| 1152 } | |
| 1153 | |
| 1154 bool InspectorDOMAgent::handleTouchEvent(LocalFrame* frame, const PlatformTouchE
vent& event) | |
| 1155 { | |
| 1156 if (m_searchingForNode == NotSearching) | |
| 1157 return false; | |
| 1158 Node* node = hoveredNodeForEvent(frame, event, false); | |
| 1159 if (node && m_inspectModeHighlightConfig) { | |
| 1160 if (m_client) | |
| 1161 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig
hlightConfig, false); | |
| 1162 inspect(node); | |
| 1163 return true; | |
| 1164 } | |
| 1165 return false; | |
| 1166 } | |
| 1167 | 1095 |
| 1168 void InspectorDOMAgent::inspect(Node* inspectedNode) | 1096 void InspectorDOMAgent::inspect(Node* inspectedNode) |
| 1169 { | 1097 { |
| 1170 if (!inspectedNode) | 1098 if (!inspectedNode) |
| 1171 return; | 1099 return; |
| 1172 | 1100 |
| 1173 Node* node = inspectedNode; | 1101 Node* node = inspectedNode; |
| 1174 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i
sDocumentFragment()) | 1102 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i
sDocumentFragment()) |
| 1175 node = node->parentOrShadowHostNode(); | 1103 node = node->parentOrShadowHostNode(); |
| 1176 if (!node) | 1104 if (!node) |
| 1177 return; | 1105 return; |
| 1178 | 1106 |
| 1179 int backendNodeId = DOMNodeIds::idForNode(node); | 1107 int backendNodeId = DOMNodeIds::idForNode(node); |
| 1180 if (!frontend() || !enabled()) { | 1108 if (!frontend() || !enabled()) { |
| 1181 m_backendNodeIdToInspect = backendNodeId; | 1109 m_backendNodeIdToInspect = backendNodeId; |
| 1182 return; | 1110 return; |
| 1183 } | 1111 } |
| 1184 | 1112 |
| 1185 frontend()->inspectNodeRequested(backendNodeId); | 1113 frontend()->inspectNodeRequested(backendNodeId); |
| 1186 } | 1114 } |
| 1187 | 1115 |
| 1188 bool InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv
ent& event) | |
| 1189 { | |
| 1190 if (m_searchingForNode == NotSearching) | |
| 1191 return false; | |
| 1192 | |
| 1193 if (!frame->view() || !frame->contentLayoutObject()) | |
| 1194 return true; | |
| 1195 Node* node = hoveredNodeForEvent(frame, event, event.shiftKey()); | |
| 1196 | |
| 1197 // Do not highlight within user agent shadow root unless requested. | |
| 1198 if (m_searchingForNode != SearchingForUAShadow) { | |
| 1199 ShadowRoot* shadowRoot = userAgentShadowRoot(node); | |
| 1200 if (shadowRoot) | |
| 1201 node = shadowRoot->host(); | |
| 1202 } | |
| 1203 | |
| 1204 // Shadow roots don't have boxes - use host element instead. | |
| 1205 if (node && node->isShadowRoot()) | |
| 1206 node = node->parentOrShadowHostNode(); | |
| 1207 | |
| 1208 if (!node) | |
| 1209 return true; | |
| 1210 | |
| 1211 Node* eventTarget = event.shiftKey() ? hoveredNodeForEvent(frame, event, fal
se) : nullptr; | |
| 1212 if (eventTarget == node) | |
| 1213 eventTarget = 0; | |
| 1214 | |
| 1215 if (node && m_inspectModeHighlightConfig) { | |
| 1216 m_hoveredNodeForInspectMode = node; | |
| 1217 if (m_client) | |
| 1218 m_client->highlightNode(node, eventTarget, *m_inspectModeHighlightCo
nfig, event.ctrlKey() || event.metaKey()); | |
| 1219 } | |
| 1220 return true; | |
| 1221 } | |
| 1222 | 1116 |
| 1223 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode
searchMode, JSONObject* highlightInspectorObject) | 1117 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode
searchMode, JSONObject* highlightInspectorObject) |
| 1224 { | 1118 { |
| 1225 // TODO(dgozman): move this to overlay. | |
| 1226 m_searchingForNode = searchMode; | |
| 1227 if (m_client) | 1119 if (m_client) |
| 1228 m_client->setInspectModeEnabled(searchMode != NotSearching); | 1120 m_client->setInspectMode(searchMode, searchMode != NotSearching ? highli
ghtConfigFromInspectorObject(errorString, highlightInspectorObject) : nullptr); |
| 1229 if (searchMode != NotSearching) { | |
| 1230 m_inspectModeHighlightConfig = highlightConfigFromInspectorObject(errorS
tring, highlightInspectorObject); | |
| 1231 } else { | |
| 1232 m_hoveredNodeForInspectMode.clear(); | |
| 1233 hideHighlight(errorString); | |
| 1234 } | |
| 1235 } | 1121 } |
| 1236 | 1122 |
| 1237 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe
ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject) | 1123 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe
ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject) |
| 1238 { | 1124 { |
| 1239 if (!highlightInspectorObject) { | 1125 if (!highlightInspectorObject) { |
| 1240 *errorString = "Internal error: highlight configuration parameter is mis
sing"; | 1126 *errorString = "Internal error: highlight configuration parameter is mis
sing"; |
| 1241 return nullptr; | 1127 return nullptr; |
| 1242 } | 1128 } |
| 1243 | 1129 |
| 1244 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig
hlightConfig()); | 1130 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig
hlightConfig()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 *errorString = "Either nodeId or objectId must be specified"; | 1242 *errorString = "Either nodeId or objectId must be specified"; |
| 1357 | 1243 |
| 1358 if (!node) | 1244 if (!node) |
| 1359 return; | 1245 return; |
| 1360 | 1246 |
| 1361 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec
torObject(errorString, highlightInspectorObject.get()); | 1247 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec
torObject(errorString, highlightInspectorObject.get()); |
| 1362 if (!highlightConfig) | 1248 if (!highlightConfig) |
| 1363 return; | 1249 return; |
| 1364 | 1250 |
| 1365 if (m_client) | 1251 if (m_client) |
| 1366 m_client->highlightNode(node, 0 /* eventTarget */, *highlightConfig, fal
se); | 1252 m_client->highlightNode(node, *highlightConfig, false); |
| 1367 } | 1253 } |
| 1368 | 1254 |
| 1369 void InspectorDOMAgent::highlightFrame( | 1255 void InspectorDOMAgent::highlightFrame( |
| 1370 ErrorString*, | 1256 ErrorString*, |
| 1371 const String& frameId, | 1257 const String& frameId, |
| 1372 const RefPtr<JSONObject>* color, | 1258 const RefPtr<JSONObject>* color, |
| 1373 const RefPtr<JSONObject>* outlineColor) | 1259 const RefPtr<JSONObject>* outlineColor) |
| 1374 { | 1260 { |
| 1375 LocalFrame* frame = IdentifiersFactory::frameById(m_pageAgent->inspectedFram
e(), frameId); | 1261 LocalFrame* frame = IdentifiersFactory::frameById(m_pageAgent->inspectedFram
e(), frameId); |
| 1376 // FIXME: Inspector doesn't currently work cross process. | 1262 // FIXME: Inspector doesn't currently work cross process. |
| 1377 if (frame && frame->deprecatedLocalOwner()) { | 1263 if (frame && frame->deprecatedLocalOwner()) { |
| 1378 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto
rHighlightConfig()); | 1264 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto
rHighlightConfig()); |
| 1379 highlightConfig->showInfo = true; // Always show tooltips for frames. | 1265 highlightConfig->showInfo = true; // Always show tooltips for frames. |
| 1380 highlightConfig->content = parseColor(color); | 1266 highlightConfig->content = parseColor(color); |
| 1381 highlightConfig->contentOutline = parseColor(outlineColor); | 1267 highlightConfig->contentOutline = parseColor(outlineColor); |
| 1382 if (m_client) | 1268 if (m_client) |
| 1383 m_client->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTar
get */, *highlightConfig, false); | 1269 m_client->highlightNode(frame->deprecatedLocalOwner(), *highlightCon
fig, false); |
| 1384 } | 1270 } |
| 1385 } | 1271 } |
| 1386 | 1272 |
| 1387 void InspectorDOMAgent::hideHighlight(ErrorString*) | 1273 void InspectorDOMAgent::hideHighlight(ErrorString*) |
| 1388 { | 1274 { |
| 1389 if (m_client) | 1275 if (m_client) |
| 1390 m_client->hideHighlight(); | 1276 m_client->hideHighlight(); |
| 1391 } | 1277 } |
| 1392 | 1278 |
| 1393 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE
lementId, const int* const anchorNodeId, int* newNodeId) | 1279 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE
lementId, const int* const anchorNodeId, int* newNodeId) |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 visitor->trace(m_injectedScriptManager); | 2135 visitor->trace(m_injectedScriptManager); |
| 2250 #if ENABLE(OILPAN) | 2136 #if ENABLE(OILPAN) |
| 2251 visitor->trace(m_documentNodeToIdMap); | 2137 visitor->trace(m_documentNodeToIdMap); |
| 2252 visitor->trace(m_danglingNodeToIdMaps); | 2138 visitor->trace(m_danglingNodeToIdMaps); |
| 2253 visitor->trace(m_idToNode); | 2139 visitor->trace(m_idToNode); |
| 2254 visitor->trace(m_idToNodesMap); | 2140 visitor->trace(m_idToNodesMap); |
| 2255 visitor->trace(m_document); | 2141 visitor->trace(m_document); |
| 2256 visitor->trace(m_revalidateTask); | 2142 visitor->trace(m_revalidateTask); |
| 2257 visitor->trace(m_searchResults); | 2143 visitor->trace(m_searchResults); |
| 2258 #endif | 2144 #endif |
| 2259 visitor->trace(m_hoveredNodeForInspectMode); | |
| 2260 visitor->trace(m_history); | 2145 visitor->trace(m_history); |
| 2261 visitor->trace(m_domEditor); | 2146 visitor->trace(m_domEditor); |
| 2262 InspectorBaseAgent::trace(visitor); | 2147 InspectorBaseAgent::trace(visitor); |
| 2263 } | 2148 } |
| 2264 | 2149 |
| 2265 } // namespace blink | 2150 } // namespace blink |
| OLD | NEW |