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

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

Issue 1311783003: Devtools[LayoutEditor]: Rework layout-editor workflow (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@resize
Patch Set: Rebase on dgozman changes 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
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM") 309 : InspectorBaseAgent<InspectorDOMAgent, InspectorFrontend::DOM>("DOM")
310 , m_pageAgent(pageAgent) 310 , m_pageAgent(pageAgent)
311 , m_injectedScriptManager(injectedScriptManager) 311 , m_injectedScriptManager(injectedScriptManager)
312 , m_client(client) 312 , m_client(client)
313 , m_domListener(nullptr) 313 , m_domListener(nullptr)
314 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap())) 314 , m_documentNodeToIdMap(adoptPtrWillBeNoop(new NodeToIdMap()))
315 , m_lastNodeId(1) 315 , m_lastNodeId(1)
316 , m_searchingForNode(NotSearching) 316 , m_searchingForNode(NotSearching)
317 , m_suppressAttributeModifiedEvent(false) 317 , m_suppressAttributeModifiedEvent(false)
318 , m_backendNodeIdToInspect(0) 318 , m_backendNodeIdToInspect(0)
319 , m_layoutEditorEnabled(false)
319 { 320 {
320 } 321 }
321 322
322 InspectorDOMAgent::~InspectorDOMAgent() 323 InspectorDOMAgent::~InspectorDOMAgent()
323 { 324 {
324 #if !ENABLE(OILPAN) 325 #if !ENABLE(OILPAN)
325 setDocument(nullptr); 326 setDocument(nullptr);
326 ASSERT(m_searchingForNode == NotSearching); 327 ASSERT(m_searchingForNode == NotSearching);
327 #endif 328 #endif
328 } 329 }
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get())); 1120 nodeIds->addItem(pushNodePathToFrontend((it->value)[i].get()));
1120 } 1121 }
1121 1122
1122 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI d) 1123 void InspectorDOMAgent::discardSearchResults(ErrorString*, const String& searchI d)
1123 { 1124 {
1124 m_searchResults.remove(searchId); 1125 m_searchResults.remove(searchId);
1125 } 1126 }
1126 1127
1127 bool InspectorDOMAgent::handleMousePress() 1128 bool InspectorDOMAgent::handleMousePress()
1128 { 1129 {
1129 if (m_searchingForNode == NotSearching) 1130 if (!shouldHandleInputEvents())
1130 return false; 1131 return false;
1131 1132
1132 if (m_hoveredNodeForInspectMode) { 1133 if (m_hoveredNodeForInspectMode) {
1133 inspect(m_hoveredNodeForInspectMode.get()); 1134 inspect(m_hoveredNodeForInspectMode.get());
1134 m_hoveredNodeForInspectMode.clear(); 1135 m_hoveredNodeForInspectMode.clear();
1135 return true; 1136 return true;
1136 } 1137 }
1137 return false; 1138 return false;
1138 } 1139 }
1139 1140
1140 bool InspectorDOMAgent::handleGestureEvent(LocalFrame* frame, const PlatformGest ureEvent& event) 1141 bool InspectorDOMAgent::handleGestureEvent(LocalFrame* frame, const PlatformGest ureEvent& event)
1141 { 1142 {
1142 if (m_searchingForNode == NotSearching || event.type() != PlatformEvent::Ges tureTap) 1143 if (!shouldHandleInputEvents())
dgozman 2015/08/28 23:44:10 Bring back GestureTap!
sergeyv 2015/09/02 00:40:57 Done.
1143 return false; 1144 return false;
1144 Node* node = hoveredNodeForEvent(frame, event, false); 1145 Node* node = hoveredNodeForEvent(frame, event, false);
1145 if (node && m_inspectModeHighlightConfig) { 1146 if (node && m_inspectModeHighlightConfig) {
1146 if (m_client) 1147 if (m_client)
1147 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig hlightConfig, false); 1148 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig hlightConfig, false);
1148 inspect(node); 1149 inspect(node);
1149 return true; 1150 return true;
1150 } 1151 }
1151 return false; 1152 return false;
1152 } 1153 }
1153 1154
1154 bool InspectorDOMAgent::handleTouchEvent(LocalFrame* frame, const PlatformTouchE vent& event) 1155 bool InspectorDOMAgent::handleTouchEvent(LocalFrame* frame, const PlatformTouchE vent& event)
1155 { 1156 {
1156 if (m_searchingForNode == NotSearching) 1157 if (!shouldHandleInputEvents())
1157 return false; 1158 return false;
1158 Node* node = hoveredNodeForEvent(frame, event, false); 1159 Node* node = hoveredNodeForEvent(frame, event, false);
1159 if (node && m_inspectModeHighlightConfig) { 1160 if (node && m_inspectModeHighlightConfig) {
1160 if (m_client) 1161 if (m_client)
1161 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig hlightConfig, false); 1162 m_client->highlightNode(node, 0 /* eventTarget */, *m_inspectModeHig hlightConfig, false);
1162 inspect(node); 1163 inspect(node);
1163 return true; 1164 return true;
1164 } 1165 }
1165 return false; 1166 return false;
1166 } 1167 }
1167 1168
1168 void InspectorDOMAgent::inspect(Node* inspectedNode) 1169 void InspectorDOMAgent::inspect(Node* inspectedNode)
1169 { 1170 {
1170 if (!inspectedNode) 1171 if (!inspectedNode)
1171 return; 1172 return;
1172 1173
1173 Node* node = inspectedNode; 1174 Node* node = inspectedNode;
1174 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i sDocumentFragment()) 1175 while (node && !node->isElementNode() && !node->isDocumentNode() && !node->i sDocumentFragment())
1175 node = node->parentOrShadowHostNode(); 1176 node = node->parentOrShadowHostNode();
1176 if (!node) 1177 if (!node)
1177 return; 1178 return;
1178 1179
1179 int backendNodeId = DOMNodeIds::idForNode(node); 1180 int backendNodeId = DOMNodeIds::idForNode(node);
1180 if (!frontend() || !enabled()) { 1181 if (!frontend() || !enabled()) {
1181 m_backendNodeIdToInspect = backendNodeId; 1182 m_backendNodeIdToInspect = backendNodeId;
1182 return; 1183 return;
1183 } 1184 }
1184 1185
1185 frontend()->inspectNodeRequested(backendNodeId); 1186 frontend()->inspectNodeRequested(backendNodeId);
1187
1188 if (m_searchingForNode == SearchingInLayoutEditor) {
1189 m_layoutEditorEnabled = true;
1190 if (m_client) {
1191 m_client->setInspectModeEnabled(false);
1192 m_client->showLayoutEditorForNode(node, *m_inspectModeHighlightConfi g.get());
1193 }
1194 }
1186 } 1195 }
1187 1196
1188 bool InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv ent& event) 1197 bool InspectorDOMAgent::handleMouseMove(LocalFrame* frame, const PlatformMouseEv ent& event)
1189 { 1198 {
1190 if (m_searchingForNode == NotSearching) 1199 if (!shouldHandleInputEvents())
1191 return false; 1200 return false;
1192 1201
1193 if (!frame->view() || !frame->contentLayoutObject()) 1202 if (!frame->view() || !frame->contentLayoutObject())
1194 return true; 1203 return true;
1195 Node* node = hoveredNodeForEvent(frame, event, event.shiftKey()); 1204 Node* node = hoveredNodeForEvent(frame, event, event.shiftKey());
1196 1205
1197 // Do not highlight within user agent shadow root unless requested. 1206 // Do not highlight within user agent shadow root unless requested.
1198 if (m_searchingForNode != SearchingForUAShadow) { 1207 if (m_searchingForNode != SearchingForUAShadow) {
1199 ShadowRoot* shadowRoot = userAgentShadowRoot(node); 1208 ShadowRoot* shadowRoot = userAgentShadowRoot(node);
1200 if (shadowRoot) 1209 if (shadowRoot)
(...skipping 23 matching lines...) Expand all
1224 { 1233 {
1225 // TODO(dgozman): move this to overlay. 1234 // TODO(dgozman): move this to overlay.
1226 m_searchingForNode = searchMode; 1235 m_searchingForNode = searchMode;
1227 if (m_client) 1236 if (m_client)
1228 m_client->setInspectModeEnabled(searchMode != NotSearching); 1237 m_client->setInspectModeEnabled(searchMode != NotSearching);
1229 if (searchMode != NotSearching) { 1238 if (searchMode != NotSearching) {
1230 m_inspectModeHighlightConfig = highlightConfigFromInspectorObject(errorS tring, highlightInspectorObject); 1239 m_inspectModeHighlightConfig = highlightConfigFromInspectorObject(errorS tring, highlightInspectorObject);
1231 } else { 1240 } else {
1232 m_hoveredNodeForInspectMode.clear(); 1241 m_hoveredNodeForInspectMode.clear();
1233 hideHighlight(errorString); 1242 hideHighlight(errorString);
1243 if (m_client)
1244 m_client->showLayoutEditorForNode(nullptr, m_inspectModeHighlightCon fig ? *m_inspectModeHighlightConfig : InspectorHighlightConfig());
1234 } 1245 }
1235 } 1246 }
1236 1247
1237 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject) 1248 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject)
1238 { 1249 {
1239 if (!highlightInspectorObject) { 1250 if (!highlightInspectorObject) {
1240 *errorString = "Internal error: highlight configuration parameter is mis sing"; 1251 *errorString = "Internal error: highlight configuration parameter is mis sing";
1241 return nullptr; 1252 return nullptr;
1242 } 1253 }
1243 1254
1244 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig()); 1255 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig());
1245 bool showInfo = false; // Default: false (do not show a tooltip). 1256 bool showInfo = false; // Default: false (do not show a tooltip).
1246 highlightInspectorObject->getBoolean("showInfo", &showInfo); 1257 highlightInspectorObject->getBoolean("showInfo", &showInfo);
1247 highlightConfig->showInfo = showInfo; 1258 highlightConfig->showInfo = showInfo;
1248 bool showRulers = false; // Default: false (do not show rulers). 1259 bool showRulers = false; // Default: false (do not show rulers).
1249 highlightInspectorObject->getBoolean("showRulers", &showRulers); 1260 highlightInspectorObject->getBoolean("showRulers", &showRulers);
1250 highlightConfig->showRulers = showRulers; 1261 highlightConfig->showRulers = showRulers;
1251 bool showExtensionLines = false; // Default: false (do not show extension li nes). 1262 bool showExtensionLines = false; // Default: false (do not show extension li nes).
1252 highlightInspectorObject->getBoolean("showExtensionLines", &showExtensionLin es); 1263 highlightInspectorObject->getBoolean("showExtensionLines", &showExtensionLin es);
1253 highlightConfig->showExtensionLines = showExtensionLines; 1264 highlightConfig->showExtensionLines = showExtensionLines;
1254 bool showLayoutEditor = false;
1255 highlightInspectorObject->getBoolean("showLayoutEditor", &showLayoutEditor);
1256 highlightConfig->showLayoutEditor = showLayoutEditor;
1257 bool displayAsMaterial = false; 1265 bool displayAsMaterial = false;
1258 highlightInspectorObject->getBoolean("displayAsMaterial", &displayAsMaterial ); 1266 highlightInspectorObject->getBoolean("displayAsMaterial", &displayAsMaterial );
1259 highlightConfig->displayAsMaterial = displayAsMaterial; 1267 highlightConfig->displayAsMaterial = displayAsMaterial;
1260 highlightConfig->content = parseConfigColor("contentColor", highlightInspect orObject); 1268 highlightConfig->content = parseConfigColor("contentColor", highlightInspect orObject);
1261 highlightConfig->contentOutline = parseConfigColor("contentOutlineColor", hi ghlightInspectorObject); 1269 highlightConfig->contentOutline = parseConfigColor("contentOutlineColor", hi ghlightInspectorObject);
1262 highlightConfig->padding = parseConfigColor("paddingColor", highlightInspect orObject); 1270 highlightConfig->padding = parseConfigColor("paddingColor", highlightInspect orObject);
1263 highlightConfig->border = parseConfigColor("borderColor", highlightInspector Object); 1271 highlightConfig->border = parseConfigColor("borderColor", highlightInspector Object);
1264 highlightConfig->margin = parseConfigColor("marginColor", highlightInspector Object); 1272 highlightConfig->margin = parseConfigColor("marginColor", highlightInspector Object);
1265 highlightConfig->eventTarget = parseConfigColor("eventTargetColor", highligh tInspectorObject); 1273 highlightConfig->eventTarget = parseConfigColor("eventTargetColor", highligh tInspectorObject);
1266 highlightConfig->shape = parseConfigColor("shapeColor", highlightInspectorOb ject); 1274 highlightConfig->shape = parseConfigColor("shapeColor", highlightInspectorOb ject);
1267 highlightConfig->shapeMargin = parseConfigColor("shapeMarginColor", highligh tInspectorObject); 1275 highlightConfig->shapeMargin = parseConfigColor("shapeMarginColor", highligh tInspectorObject);
1268 1276
1269 return highlightConfig.release(); 1277 return highlightConfig.release();
1270 } 1278 }
1271 1279
1272 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena bled, const bool* inspectUAShadowDOM, const RefPtr<JSONObject>* highlightConfig) 1280 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena bled, const String* mode, const RefPtr<JSONObject>* highlightConfig)
1273 { 1281 {
1274 if (enabled && !pushDocumentUponHandlelessOperation(errorString)) 1282 if (enabled && !pushDocumentUponHandlelessOperation(errorString))
1275 return; 1283 return;
1276 SearchMode searchMode = enabled ? (asBool(inspectUAShadowDOM) ? SearchingFor UAShadow : SearchingForNormal) : NotSearching; 1284 SearchMode searchMode = SearchingForNormal;
1285 if (!enabled) {
1286 searchMode = NotSearching;
1287 } else if (!mode) {
1288 searchMode = SearchingForNormal;
1289 } else if (*mode == "showUAShadowDOM") {
dgozman 2015/08/28 23:44:10 There should be TypeBuilder constants for these.
sergeyv 2015/09/02 00:40:58 Done.
1290 searchMode = SearchingForUAShadow;
1291 } else if (*mode == "showLayoutEditor") {
1292 searchMode = SearchingInLayoutEditor;
1293 m_layoutEditorEnabled = false;
1294 }
1295
1277 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf ig->get() : nullptr); 1296 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf ig->get() : nullptr);
1278 } 1297 }
1279 1298
1280 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor ) 1299 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor )
1281 { 1300 {
1282 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh t))); 1301 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh t)));
1283 innerHighlightQuad(quad.release(), color, outlineColor); 1302 innerHighlightQuad(quad.release(), color, outlineColor);
1284 } 1303 }
1285 1304
1286 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o utlineColor) 1305 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o utlineColor)
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation(ErrorString* errorSt ring) 2242 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation(ErrorString* errorSt ring)
2224 { 2243 {
2225 if (!m_documentNodeToIdMap->contains(m_document)) { 2244 if (!m_documentNodeToIdMap->contains(m_document)) {
2226 RefPtr<TypeBuilder::DOM::Node> root; 2245 RefPtr<TypeBuilder::DOM::Node> root;
2227 getDocument(errorString, root); 2246 getDocument(errorString, root);
2228 return errorString->isEmpty(); 2247 return errorString->isEmpty();
2229 } 2248 }
2230 return true; 2249 return true;
2231 } 2250 }
2232 2251
2252 void InspectorDOMAgent::resumeSearchingForNode(Node* startNode)
2253 {
2254 if (m_searchingForNode != SearchingInLayoutEditor)
2255 return;
2256
2257 m_layoutEditorEnabled = false;
2258 if (m_client)
2259 m_client->setInspectModeEnabled(true);
2260 if (startNode && m_inspectModeHighlightConfig) {
2261 m_hoveredNodeForInspectMode = startNode;
2262 if (m_client)
2263 m_client->highlightNode(startNode, 0, *m_inspectModeHighlightConfig, false);
2264 }
2265
2266 }
2267
2268 bool InspectorDOMAgent::shouldHandleInputEvents()
dgozman 2015/08/28 23:44:10 shouldSearchForNode
sergeyv 2015/09/02 00:40:57 Done.
2269 {
2270 return m_searchingForNode != NotSearching && (m_searchingForNode != Searchin gInLayoutEditor || !m_layoutEditorEnabled);
dgozman 2015/08/28 23:44:10 return !(m_searchingForNode == NotSearching || (m_
sergeyv 2015/09/02 00:40:58 Done.
2271 }
2272
2233 DEFINE_TRACE(InspectorDOMAgent) 2273 DEFINE_TRACE(InspectorDOMAgent)
2234 { 2274 {
2235 visitor->trace(m_domListener); 2275 visitor->trace(m_domListener);
2236 visitor->trace(m_pageAgent); 2276 visitor->trace(m_pageAgent);
2237 visitor->trace(m_injectedScriptManager); 2277 visitor->trace(m_injectedScriptManager);
2238 #if ENABLE(OILPAN) 2278 #if ENABLE(OILPAN)
2239 visitor->trace(m_documentNodeToIdMap); 2279 visitor->trace(m_documentNodeToIdMap);
2240 visitor->trace(m_danglingNodeToIdMaps); 2280 visitor->trace(m_danglingNodeToIdMaps);
2241 visitor->trace(m_idToNode); 2281 visitor->trace(m_idToNode);
2242 visitor->trace(m_idToNodesMap); 2282 visitor->trace(m_idToNodesMap);
2243 visitor->trace(m_document); 2283 visitor->trace(m_document);
2244 visitor->trace(m_revalidateTask); 2284 visitor->trace(m_revalidateTask);
2245 visitor->trace(m_searchResults); 2285 visitor->trace(m_searchResults);
2246 #endif 2286 #endif
2247 visitor->trace(m_hoveredNodeForInspectMode); 2287 visitor->trace(m_hoveredNodeForInspectMode);
2248 visitor->trace(m_history); 2288 visitor->trace(m_history);
2249 visitor->trace(m_domEditor); 2289 visitor->trace(m_domEditor);
2250 InspectorBaseAgent::trace(visitor); 2290 InspectorBaseAgent::trace(visitor);
2251 } 2291 }
2252 2292
2253 } // namespace blink 2293 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698