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

Side by Side Diff: Source/core/inspector/InspectorDOMAgent.cpp

Issue 1322053002: Devtools: Move inspectMode logic from InspectorDomAgent to InspectorOverlayImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix win compilation Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/web/InspectorOverlayImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
327 #endif 293 #endif
328 } 294 }
329 295
330 void InspectorDOMAgent::restore() 296 void InspectorDOMAgent::restore()
331 { 297 {
332 if (!enabled()) 298 if (!enabled())
333 return; 299 return;
334 innerEnable(); 300 innerEnable();
335 } 301 }
336 302
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (!node) 433 if (!node)
468 return nullptr; 434 return nullptr;
469 435
470 if (!node->isElementNode()) { 436 if (!node->isElementNode()) {
471 *errorString = "Node is not an Element"; 437 *errorString = "Node is not an Element";
472 return nullptr; 438 return nullptr;
473 } 439 }
474 return toElement(node); 440 return toElement(node);
475 } 441 }
476 442
477 static ShadowRoot* userAgentShadowRoot(Node* node) 443 // static
444 ShadowRoot* InspectorDOMAgent::userAgentShadowRoot(Node* node)
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
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.
1226 m_searchingForNode = searchMode;
1227 if (m_client) 1118 if (m_client)
1228 m_client->setInspectModeEnabled(searchMode != NotSearching); 1119 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 } 1120 }
1236 1121
1237 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject) 1122 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject)
1238 { 1123 {
1239 if (!highlightInspectorObject) { 1124 if (!highlightInspectorObject) {
1240 *errorString = "Internal error: highlight configuration parameter is mis sing"; 1125 *errorString = "Internal error: highlight configuration parameter is mis sing";
1241 return nullptr; 1126 return nullptr;
1242 } 1127 }
1243 1128
1244 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig()); 1129 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 *errorString = "Either nodeId or objectId must be specified"; 1241 *errorString = "Either nodeId or objectId must be specified";
1357 1242
1358 if (!node) 1243 if (!node)
1359 return; 1244 return;
1360 1245
1361 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get()); 1246 OwnPtr<InspectorHighlightConfig> highlightConfig = highlightConfigFromInspec torObject(errorString, highlightInspectorObject.get());
1362 if (!highlightConfig) 1247 if (!highlightConfig)
1363 return; 1248 return;
1364 1249
1365 if (m_client) 1250 if (m_client)
1366 m_client->highlightNode(node, 0 /* eventTarget */, *highlightConfig, fal se); 1251 m_client->highlightNode(node, *highlightConfig, false);
1367 } 1252 }
1368 1253
1369 void InspectorDOMAgent::highlightFrame( 1254 void InspectorDOMAgent::highlightFrame(
1370 ErrorString*, 1255 ErrorString*,
1371 const String& frameId, 1256 const String& frameId,
1372 const RefPtr<JSONObject>* color, 1257 const RefPtr<JSONObject>* color,
1373 const RefPtr<JSONObject>* outlineColor) 1258 const RefPtr<JSONObject>* outlineColor)
1374 { 1259 {
1375 LocalFrame* frame = IdentifiersFactory::frameById(m_pageAgent->inspectedFram e(), frameId); 1260 LocalFrame* frame = IdentifiersFactory::frameById(m_pageAgent->inspectedFram e(), frameId);
1376 // FIXME: Inspector doesn't currently work cross process. 1261 // FIXME: Inspector doesn't currently work cross process.
1377 if (frame && frame->deprecatedLocalOwner()) { 1262 if (frame && frame->deprecatedLocalOwner()) {
1378 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto rHighlightConfig()); 1263 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto rHighlightConfig());
1379 highlightConfig->showInfo = true; // Always show tooltips for frames. 1264 highlightConfig->showInfo = true; // Always show tooltips for frames.
1380 highlightConfig->content = parseColor(color); 1265 highlightConfig->content = parseColor(color);
1381 highlightConfig->contentOutline = parseColor(outlineColor); 1266 highlightConfig->contentOutline = parseColor(outlineColor);
1382 if (m_client) 1267 if (m_client)
1383 m_client->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTar get */, *highlightConfig, false); 1268 m_client->highlightNode(frame->deprecatedLocalOwner(), *highlightCon fig, false);
1384 } 1269 }
1385 } 1270 }
1386 1271
1387 void InspectorDOMAgent::hideHighlight(ErrorString*) 1272 void InspectorDOMAgent::hideHighlight(ErrorString*)
1388 { 1273 {
1389 if (m_client) 1274 if (m_client)
1390 m_client->hideHighlight(); 1275 m_client->hideHighlight();
1391 } 1276 }
1392 1277
1393 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) 1278 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
2249 visitor->trace(m_injectedScriptManager); 2134 visitor->trace(m_injectedScriptManager);
2250 #if ENABLE(OILPAN) 2135 #if ENABLE(OILPAN)
2251 visitor->trace(m_documentNodeToIdMap); 2136 visitor->trace(m_documentNodeToIdMap);
2252 visitor->trace(m_danglingNodeToIdMaps); 2137 visitor->trace(m_danglingNodeToIdMaps);
2253 visitor->trace(m_idToNode); 2138 visitor->trace(m_idToNode);
2254 visitor->trace(m_idToNodesMap); 2139 visitor->trace(m_idToNodesMap);
2255 visitor->trace(m_document); 2140 visitor->trace(m_document);
2256 visitor->trace(m_revalidateTask); 2141 visitor->trace(m_revalidateTask);
2257 visitor->trace(m_searchResults); 2142 visitor->trace(m_searchResults);
2258 #endif 2143 #endif
2259 visitor->trace(m_hoveredNodeForInspectMode);
2260 visitor->trace(m_history); 2144 visitor->trace(m_history);
2261 visitor->trace(m_domEditor); 2145 visitor->trace(m_domEditor);
2262 InspectorBaseAgent::trace(visitor); 2146 InspectorBaseAgent::trace(visitor);
2263 } 2147 }
2264 2148
2265 } // namespace blink 2149 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorDOMAgent.h ('k') | Source/web/InspectorOverlayImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698