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

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

Issue 1204453002: Devtools: Create layout editor experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 5 years, 6 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 | Annotate | Revision Log
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 using namespace HTMLNames; 92 using namespace HTMLNames;
93 93
94 namespace DOMAgentState { 94 namespace DOMAgentState {
95 static const char domAgentEnabled[] = "domAgentEnabled"; 95 static const char domAgentEnabled[] = "domAgentEnabled";
96 }; 96 };
97 97
98 static const size_t maxTextSize = 10000; 98 static const size_t maxTextSize = 10000;
99 static const UChar ellipsisUChar[] = { 0x2026, 0 }; 99 static const UChar ellipsisUChar[] = { 0x2026, 0 };
100 100
101 static Color parseColor(const RefPtr<JSONObject>* colorObject)
102 {
103 if (!colorObject || !(*colorObject))
104 return Color::transparent;
105
106 int r;
107 int g;
108 int b;
109 bool success = (*colorObject)->getNumber("r", &r);
110 success |= (*colorObject)->getNumber("g", &g);
111 success |= (*colorObject)->getNumber("b", &b);
112 if (!success)
113 return Color::transparent;
114
115 double a;
116 success = (*colorObject)->getNumber("a", &a);
117 if (!success)
118 return Color(r, g, b);
119
120 // Clamp alpha to the [0..1] range.
121 if (a < 0)
122 a = 0;
123 else if (a > 1)
124 a = 1;
125
126 return Color(r, g, b, static_cast<int>(a * 255));
127 }
128
129 static Color parseConfigColor(const String& fieldName, JSONObject* configObject)
130 {
131 const RefPtr<JSONObject> colorObject = configObject->getObject(fieldName);
132 return parseColor(&colorObject);
133 }
134
135 static bool parseQuad(const RefPtr<JSONArray>& quadArray, FloatQuad* quad) 101 static bool parseQuad(const RefPtr<JSONArray>& quadArray, FloatQuad* quad)
136 { 102 {
137 if (!quadArray) 103 if (!quadArray)
138 return false; 104 return false;
139 const size_t coordinatesInQuad = 8; 105 const size_t coordinatesInQuad = 8;
140 double coordinates[coordinatesInQuad]; 106 double coordinates[coordinatesInQuad];
141 if (quadArray->length() != coordinatesInQuad) 107 if (quadArray->length() != coordinatesInQuad)
142 return false; 108 return false;
143 for (size_t i = 0; i < coordinatesInQuad; ++i) { 109 for (size_t i = 0; i < coordinatesInQuad; ++i) {
144 if (!quadArray->get(i)->asNumber(coordinates + i)) 110 if (!quadArray->get(i)->asNumber(coordinates + i))
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 hideHighlight(errorString); 1189 hideHighlight(errorString);
1224 } 1190 }
1225 } 1191 }
1226 1192
1227 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject) 1193 PassOwnPtr<InspectorHighlightConfig> InspectorDOMAgent::highlightConfigFromInspe ctorObject(ErrorString* errorString, JSONObject* highlightInspectorObject)
1228 { 1194 {
1229 if (!highlightInspectorObject) { 1195 if (!highlightInspectorObject) {
1230 *errorString = "Internal error: highlight configuration parameter is mis sing"; 1196 *errorString = "Internal error: highlight configuration parameter is mis sing";
1231 return nullptr; 1197 return nullptr;
1232 } 1198 }
1233 1199 return InspectorHighlight::highlightConfigFromInspectorObject(highlightInspe ctorObject);
1234 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig());
1235 bool showInfo = false; // Default: false (do not show a tooltip).
1236 highlightInspectorObject->getBoolean("showInfo", &showInfo);
1237 highlightConfig->showInfo = showInfo;
1238 bool showRulers = false; // Default: false (do not show rulers).
1239 highlightInspectorObject->getBoolean("showRulers", &showRulers);
1240 highlightConfig->showRulers = showRulers;
1241 bool showExtensionLines = false; // Default: false (do not show extension li nes).
1242 highlightInspectorObject->getBoolean("showExtensionLines", &showExtensionLin es);
1243 highlightConfig->showExtensionLines = showExtensionLines;
1244 highlightConfig->content = parseConfigColor("contentColor", highlightInspect orObject);
1245 highlightConfig->contentOutline = parseConfigColor("contentOutlineColor", hi ghlightInspectorObject);
1246 highlightConfig->padding = parseConfigColor("paddingColor", highlightInspect orObject);
1247 highlightConfig->border = parseConfigColor("borderColor", highlightInspector Object);
1248 highlightConfig->margin = parseConfigColor("marginColor", highlightInspector Object);
1249 highlightConfig->eventTarget = parseConfigColor("eventTargetColor", highligh tInspectorObject);
1250 highlightConfig->shape = parseConfigColor("shapeColor", highlightInspectorOb ject);
1251 highlightConfig->shapeMargin = parseConfigColor("shapeMarginColor", highligh tInspectorObject);
1252
1253 return highlightConfig.release();
1254 } 1200 }
1255 1201
1256 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena bled, const bool* inspectUAShadowDOM, const RefPtr<JSONObject>* highlightConfig) 1202 void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena bled, const bool* inspectUAShadowDOM, const RefPtr<JSONObject>* highlightConfig)
1257 { 1203 {
1258 if (enabled && !pushDocumentUponHandlelessOperation(errorString)) 1204 if (enabled && !pushDocumentUponHandlelessOperation(errorString))
1259 return; 1205 return;
1260 SearchMode searchMode = enabled ? (asBool(inspectUAShadowDOM) ? SearchingFor UAShadow : SearchingForNormal) : NotSearching; 1206 SearchMode searchMode = enabled ? (asBool(inspectUAShadowDOM) ? SearchingFor UAShadow : SearchingForNormal) : NotSearching;
1261 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf ig->get() : nullptr); 1207 setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConf ig->get() : nullptr);
1262 } 1208 }
1263 1209
1264 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor ) 1210 void InspectorDOMAgent::highlightRect(ErrorString*, int x, int y, int width, int height, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor )
1265 { 1211 {
1266 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh t))); 1212 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad(FloatRect(x, y, width, heigh t)));
1267 innerHighlightQuad(quad.release(), color, outlineColor); 1213 innerHighlightQuad(quad.release(), color, outlineColor);
1268 } 1214 }
1269 1215
1270 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o utlineColor) 1216 void InspectorDOMAgent::highlightQuad(ErrorString* errorString, const RefPtr<JSO NArray>& quadArray, const RefPtr<JSONObject>* color, const RefPtr<JSONObject>* o utlineColor)
1271 { 1217 {
1272 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad()); 1218 OwnPtr<FloatQuad> quad = adoptPtr(new FloatQuad());
1273 if (!parseQuad(quadArray, quad.get())) { 1219 if (!parseQuad(quadArray, quad.get())) {
1274 *errorString = "Invalid Quad format"; 1220 *errorString = "Invalid Quad format";
1275 return; 1221 return;
1276 } 1222 }
1277 innerHighlightQuad(quad.release(), color, outlineColor); 1223 innerHighlightQuad(quad.release(), color, outlineColor);
1278 } 1224 }
1279 1225
1280 void InspectorDOMAgent::innerHighlightQuad(PassOwnPtr<FloatQuad> quad, const Ref Ptr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor) 1226 void InspectorDOMAgent::innerHighlightQuad(PassOwnPtr<FloatQuad> quad, const Ref Ptr<JSONObject>* color, const RefPtr<JSONObject>* outlineColor)
1281 { 1227 {
1282 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new InspectorHig hlightConfig()); 1228 OwnPtr<InspectorHighlightConfig> highlightConfig = InspectorHighlight::highl ightConfigWithColors(color, outlineColor);
1283 highlightConfig->content = parseColor(color);
1284 highlightConfig->contentOutline = parseColor(outlineColor);
1285 m_overlay->highlightQuad(quad, *highlightConfig); 1229 m_overlay->highlightQuad(quad, *highlightConfig);
1286 } 1230 }
1287 1231
1288 void InspectorDOMAgent::highlightNode(ErrorString* errorString, const RefPtr<JSO NObject>& highlightInspectorObject, const int* nodeId, const int* backendNodeId, const String* objectId) 1232 void InspectorDOMAgent::highlightNode(ErrorString* errorString, const RefPtr<JSO NObject>& highlightInspectorObject, const int* nodeId, const int* backendNodeId, const String* objectId)
1289 { 1233 {
1290 Node* node = nullptr; 1234 Node* node = nullptr;
1291 if (nodeId) { 1235 if (nodeId) {
1292 node = assertNode(errorString, *nodeId); 1236 node = assertNode(errorString, *nodeId);
1293 } else if (backendNodeId) { 1237 } else if (backendNodeId) {
1294 node = DOMNodeIds::nodeForId(*backendNodeId); 1238 node = DOMNodeIds::nodeForId(*backendNodeId);
(...skipping 17 matching lines...) Expand all
1312 1256
1313 void InspectorDOMAgent::highlightFrame( 1257 void InspectorDOMAgent::highlightFrame(
1314 ErrorString*, 1258 ErrorString*,
1315 const String& frameId, 1259 const String& frameId,
1316 const RefPtr<JSONObject>* color, 1260 const RefPtr<JSONObject>* color,
1317 const RefPtr<JSONObject>* outlineColor) 1261 const RefPtr<JSONObject>* outlineColor)
1318 { 1262 {
1319 LocalFrame* frame = m_pageAgent->frameForId(frameId); 1263 LocalFrame* frame = m_pageAgent->frameForId(frameId);
1320 // FIXME: Inspector doesn't currently work cross process. 1264 // FIXME: Inspector doesn't currently work cross process.
1321 if (frame && frame->deprecatedLocalOwner()) { 1265 if (frame && frame->deprecatedLocalOwner()) {
1322 OwnPtr<InspectorHighlightConfig> highlightConfig = adoptPtr(new Inspecto rHighlightConfig()); 1266 OwnPtr<InspectorHighlightConfig> highlightConfig = InspectorHighlight::h ighlightConfigWithColors(color, outlineColor);
1323 highlightConfig->showInfo = true; // Always show tooltips for frames. 1267 highlightConfig->showInfo = true; // Always show tooltips for frames.
1324 highlightConfig->content = parseColor(color);
1325 highlightConfig->contentOutline = parseColor(outlineColor);
1326 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false); 1268 m_overlay->highlightNode(frame->deprecatedLocalOwner(), 0 /* eventTarget */, *highlightConfig, false);
1327 } 1269 }
1328 } 1270 }
1329 1271
1330 void InspectorDOMAgent::hideHighlight(ErrorString*) 1272 void InspectorDOMAgent::hideHighlight(ErrorString*)
1331 { 1273 {
1332 m_overlay->hideHighlight(); 1274 m_overlay->hideHighlight();
1333 } 1275 }
1334 1276
1335 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId) 1277 void InspectorDOMAgent::copyTo(ErrorString* errorString, int nodeId, int targetE lementId, const int* const anchorNodeId, int* newNodeId)
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 visitor->trace(m_searchResults); 2132 visitor->trace(m_searchResults);
2191 #endif 2133 #endif
2192 visitor->trace(m_hoveredNodeForInspectMode); 2134 visitor->trace(m_hoveredNodeForInspectMode);
2193 visitor->trace(m_history); 2135 visitor->trace(m_history);
2194 visitor->trace(m_domEditor); 2136 visitor->trace(m_domEditor);
2195 visitor->trace(m_listener); 2137 visitor->trace(m_listener);
2196 InspectorBaseAgent::trace(visitor); 2138 InspectorBaseAgent::trace(visitor);
2197 } 2139 }
2198 2140
2199 } // namespace blink 2141 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698