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 ShadowRoot* InspectorDOMAgent::userAgentShadowRoot(Node* node) |
dgozman
2015/09/01 00:53:29
// static
sergeyv
2015/09/01 03:41:20
Done.
| |
478 { | 445 { |
479 if (!node || !node->isInShadowTree()) | 446 if (!node || !node->isInShadowTree()) |
480 return nullptr; | 447 return nullptr; |
481 | 448 |
482 Node* candidate = node; | 449 Node* candidate = node; |
483 while (candidate && !candidate->isShadowRoot()) | 450 while (candidate && !candidate->isShadowRoot()) |
484 candidate = candidate->parentOrShadowHostNode(); | 451 candidate = candidate->parentOrShadowHostNode(); |
485 ASSERT(candidate); | 452 ASSERT(candidate); |
486 ShadowRoot* shadowRoot = toShadowRoot(candidate); | 453 ShadowRoot* shadowRoot = toShadowRoot(candidate); |
487 | 454 |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 nodeIds = TypeBuilder::Array<int>::create(); | 1084 nodeIds = TypeBuilder::Array<int>::create(); |
1118 for (int i = fromIndex; i < toIndex; ++i) | 1085 for (int i = fromIndex; i < toIndex; ++i) |
1119 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get())); | 1086 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get())); |
1120 } | 1087 } |
1121 | 1088 |
1122 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI d) | 1089 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI d) |
1123 { | 1090 { |
1124 m_searchResults.remove(searchId); | 1091 m_searchResults.remove(searchId); |
1125 } | 1092 } |
1126 | 1093 |
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 | 1094 |
1168 void InspectorDOMAgent::inspect(Node* inspectedNode) | 1095 void InspectorDOMAgent::inspect(Node* inspectedNode) |
1169 { | 1096 { |
1170 if (!inspectedNode) | 1097 if (!inspectedNode) |
1171 return; | 1098 return; |
1172 | 1099 |
1173 Node* node = inspectedNode; | 1100 Node* node = inspectedNode; |
1174 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i sDocumentFragment()) | 1101 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i sDocumentFragment()) |
1175 node = node->parentOrShadowHostNode(); | 1102 node = node->parentOrShadowHostNode(); |
1176 if (!node) | 1103 if (!node) |
1177 return; | 1104 return; |
1178 | 1105 |
1179 int backendNodeId = DOMNodeIds::idForNode(node); | 1106 int backendNodeId = DOMNodeIds::idForNode(node); |
1180 if (!frontend() || !enabled()) { | 1107 if (!frontend() || !enabled()) { |
1181 m_backendNodeIdToInspect = backendNodeId; | 1108 m_backendNodeIdToInspect = backendNodeId; |
1182 return; | 1109 return; |
1183 } | 1110 } |
1184 | 1111 |
1185 frontend()->inspectNodeRequested(backendNodeId); | 1112 frontend()->inspectNodeRequested(backendNodeId); |
1186 } | 1113 } |
1187 | 1114 |
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 | 1115 |
1223 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode searchMode, JSONObject* highlightInspectorObject) | 1116 void InspectorDOMAgent::setSearchingForNode(ErrorString* errorString, SearchMode searchMode, JSONObject* highlightInspectorObject) |
1224 { | 1117 { |
1225 // TODO(dgozman): move this to overlay. | 1118 // TODO(dgozman): move this to overlay. |
dgozman
2015/09/01 00:53:29
remove TODO
sergeyv
2015/09/01 03:41:20
Done.
| |
1226 m_searchingForNode = searchMode; | |
1227 if (m_client) | 1119 if (m_client) |
dgozman
2015/09/01 00:53:29
else errorString="...."
sergeyv
2015/09/01 03:41:20
I'll do this in follow-ups, because we should chec
| |
1228 m_client->setInspectModeEnabled(searchMode != NotSearching); | 1120 m_client->setSearchingForNode(searchMode, searchMode != NotSearching ? h ighlightConfigFromInspectorObject(errorString, highlightInspectorObject) : nullp tr); |
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 1004 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 |