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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/DOMPresentationUtils.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> 4 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
5 * Copyright (C) 2009 Joseph Pecoraro 5 * Copyright (C) 2009 Joseph Pecoraro
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 10 matching lines...) Expand all
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 WebInspector.DOMPresentationUtils = {}; 31 Components.DOMPresentationUtils = {};
32 32
33 /** 33 /**
34 * @param {!WebInspector.DOMNode} node 34 * @param {!SDK.DOMNode} node
35 * @param {!Element} parentElement 35 * @param {!Element} parentElement
36 */ 36 */
37 WebInspector.DOMPresentationUtils.decorateNodeLabel = function(node, parentEleme nt) { 37 Components.DOMPresentationUtils.decorateNodeLabel = function(node, parentElement ) {
38 var originalNode = node; 38 var originalNode = node;
39 var isPseudo = node.nodeType() === Node.ELEMENT_NODE && node.pseudoType(); 39 var isPseudo = node.nodeType() === Node.ELEMENT_NODE && node.pseudoType();
40 if (isPseudo && node.parentNode) 40 if (isPseudo && node.parentNode)
41 node = node.parentNode; 41 node = node.parentNode;
42 42
43 var title = node.nodeNameInCorrectCase(); 43 var title = node.nodeNameInCorrectCase();
44 44
45 var nameElement = parentElement.createChild('span', 'node-label-name'); 45 var nameElement = parentElement.createChild('span', 'node-label-name');
46 nameElement.textContent = title; 46 nameElement.textContent = title;
47 47
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 pseudoElement.createTextChild(pseudoText); 81 pseudoElement.createTextChild(pseudoText);
82 title += pseudoText; 82 title += pseudoText;
83 } 83 }
84 parentElement.title = title; 84 parentElement.title = title;
85 }; 85 };
86 86
87 /** 87 /**
88 * @param {!Element} container 88 * @param {!Element} container
89 * @param {string} nodeTitle 89 * @param {string} nodeTitle
90 */ 90 */
91 WebInspector.DOMPresentationUtils.createSpansForNodeTitle = function(container, nodeTitle) { 91 Components.DOMPresentationUtils.createSpansForNodeTitle = function(container, no deTitle) {
92 var match = nodeTitle.match(/([^#.]+)(#[^.]+)?(\..*)?/); 92 var match = nodeTitle.match(/([^#.]+)(#[^.]+)?(\..*)?/);
93 container.createChild('span', 'webkit-html-tag-name').textContent = match[1]; 93 container.createChild('span', 'webkit-html-tag-name').textContent = match[1];
94 if (match[2]) 94 if (match[2])
95 container.createChild('span', 'webkit-html-attribute-value').textContent = m atch[2]; 95 container.createChild('span', 'webkit-html-attribute-value').textContent = m atch[2];
96 if (match[3]) 96 if (match[3])
97 container.createChild('span', 'webkit-html-attribute-name').textContent = ma tch[3]; 97 container.createChild('span', 'webkit-html-attribute-name').textContent = ma tch[3];
98 }; 98 };
99 99
100 /** 100 /**
101 * @param {?WebInspector.DOMNode} node 101 * @param {?SDK.DOMNode} node
102 * @param {string=} idref 102 * @param {string=} idref
103 * @return {!Node} 103 * @return {!Node}
104 */ 104 */
105 WebInspector.DOMPresentationUtils.linkifyNodeReference = function(node, idref) { 105 Components.DOMPresentationUtils.linkifyNodeReference = function(node, idref) {
106 if (!node) 106 if (!node)
107 return createTextNode(WebInspector.UIString('<node>')); 107 return createTextNode(Common.UIString('<node>'));
108 108
109 var root = createElementWithClass('span', 'monospace'); 109 var root = createElementWithClass('span', 'monospace');
110 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(root, 'components /domUtils.css'); 110 var shadowRoot = UI.createShadowRootWithCoreStyles(root, 'components/domUtils. css');
111 var link = shadowRoot.createChild('div', 'node-link'); 111 var link = shadowRoot.createChild('div', 'node-link');
112 112
113 if (idref) 113 if (idref)
114 link.createChild('span', 'node-label-id').createTextChild('#' + idref); 114 link.createChild('span', 'node-label-id').createTextChild('#' + idref);
115 else 115 else
116 WebInspector.DOMPresentationUtils.decorateNodeLabel(node, link); 116 Components.DOMPresentationUtils.decorateNodeLabel(node, link);
117 117
118 link.addEventListener('click', WebInspector.Revealer.reveal.bind(WebInspector. Revealer, node, undefined), false); 118 link.addEventListener('click', Common.Revealer.reveal.bind(Common.Revealer, no de, undefined), false);
119 link.addEventListener('mouseover', node.highlight.bind(node, undefined, undefi ned), false); 119 link.addEventListener('mouseover', node.highlight.bind(node, undefined, undefi ned), false);
120 link.addEventListener('mouseleave', WebInspector.DOMModel.hideDOMNodeHighlight .bind(WebInspector.DOMModel), false); 120 link.addEventListener('mouseleave', SDK.DOMModel.hideDOMNodeHighlight.bind(SDK .DOMModel), false);
121 121
122 return root; 122 return root;
123 }; 123 };
124 124
125 /** 125 /**
126 * @param {!WebInspector.DeferredDOMNode} deferredNode 126 * @param {!SDK.DeferredDOMNode} deferredNode
127 * @return {!Node} 127 * @return {!Node}
128 */ 128 */
129 WebInspector.DOMPresentationUtils.linkifyDeferredNodeReference = function(deferr edNode) { 129 Components.DOMPresentationUtils.linkifyDeferredNodeReference = function(deferred Node) {
130 var root = createElement('div'); 130 var root = createElement('div');
131 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(root, 'components /domUtils.css'); 131 var shadowRoot = UI.createShadowRootWithCoreStyles(root, 'components/domUtils. css');
132 var link = shadowRoot.createChild('div', 'node-link'); 132 var link = shadowRoot.createChild('div', 'node-link');
133 link.createChild('content'); 133 link.createChild('content');
134 link.addEventListener('click', deferredNode.resolve.bind(deferredNode, onDefer redNodeResolved), false); 134 link.addEventListener('click', deferredNode.resolve.bind(deferredNode, onDefer redNodeResolved), false);
135 link.addEventListener('mousedown', (e) => e.consume(), false); 135 link.addEventListener('mousedown', (e) => e.consume(), false);
136 136
137 /** 137 /**
138 * @param {?WebInspector.DOMNode} node 138 * @param {?SDK.DOMNode} node
139 */ 139 */
140 function onDeferredNodeResolved(node) { 140 function onDeferredNodeResolved(node) {
141 WebInspector.Revealer.reveal(node); 141 Common.Revealer.reveal(node);
142 } 142 }
143 143
144 return root; 144 return root;
145 }; 145 };
146 146
147 /** 147 /**
148 * @param {!WebInspector.Target} target 148 * @param {!SDK.Target} target
149 * @param {string} originalImageURL 149 * @param {string} originalImageURL
150 * @param {boolean} showDimensions 150 * @param {boolean} showDimensions
151 * @param {function(!Element=)} userCallback 151 * @param {function(!Element=)} userCallback
152 * @param {!Object=} precomputedFeatures 152 * @param {!Object=} precomputedFeatures
153 */ 153 */
154 WebInspector.DOMPresentationUtils.buildImagePreviewContents = function( 154 Components.DOMPresentationUtils.buildImagePreviewContents = function(
155 target, originalImageURL, showDimensions, userCallback, precomputedFeatures) { 155 target, originalImageURL, showDimensions, userCallback, precomputedFeatures) {
156 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target); 156 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
157 if (!resourceTreeModel) { 157 if (!resourceTreeModel) {
158 userCallback(); 158 userCallback();
159 return; 159 return;
160 } 160 }
161 var resource = resourceTreeModel.resourceForURL(originalImageURL); 161 var resource = resourceTreeModel.resourceForURL(originalImageURL);
162 var imageURL = originalImageURL; 162 var imageURL = originalImageURL;
163 if (!isImageResource(resource) && precomputedFeatures && precomputedFeatures.c urrentSrc) { 163 if (!isImageResource(resource) && precomputedFeatures && precomputedFeatures.c urrentSrc) {
164 imageURL = precomputedFeatures.currentSrc; 164 imageURL = precomputedFeatures.currentSrc;
165 resource = resourceTreeModel.resourceForURL(imageURL); 165 resource = resourceTreeModel.resourceForURL(imageURL);
166 } 166 }
167 if (!isImageResource(resource)) { 167 if (!isImageResource(resource)) {
168 userCallback(); 168 userCallback();
169 return; 169 return;
170 } 170 }
171 171
172 var imageElement = createElement('img'); 172 var imageElement = createElement('img');
173 imageElement.addEventListener('load', buildContent, false); 173 imageElement.addEventListener('load', buildContent, false);
174 imageElement.addEventListener('error', errorCallback, false); 174 imageElement.addEventListener('error', errorCallback, false);
175 resource.populateImageSource(imageElement); 175 resource.populateImageSource(imageElement);
176 176
177 function errorCallback() { 177 function errorCallback() {
178 // Drop the event parameter when invoking userCallback. 178 // Drop the event parameter when invoking userCallback.
179 userCallback(); 179 userCallback();
180 } 180 }
181 181
182 /** 182 /**
183 * @param {?WebInspector.Resource} resource 183 * @param {?SDK.Resource} resource
184 * @return {boolean} 184 * @return {boolean}
185 */ 185 */
186 function isImageResource(resource) { 186 function isImageResource(resource) {
187 return !!resource && resource.resourceType() === WebInspector.resourceTypes. Image; 187 return !!resource && resource.resourceType() === Common.resourceTypes.Image;
188 } 188 }
189 189
190 function buildContent() { 190 function buildContent() {
191 var container = createElement('table'); 191 var container = createElement('table');
192 container.className = 'image-preview-container'; 192 container.className = 'image-preview-container';
193 var naturalWidth = precomputedFeatures ? precomputedFeatures.naturalWidth : imageElement.naturalWidth; 193 var naturalWidth = precomputedFeatures ? precomputedFeatures.naturalWidth : imageElement.naturalWidth;
194 var naturalHeight = precomputedFeatures ? precomputedFeatures.naturalHeight : imageElement.naturalHeight; 194 var naturalHeight = precomputedFeatures ? precomputedFeatures.naturalHeight : imageElement.naturalHeight;
195 var offsetWidth = precomputedFeatures ? precomputedFeatures.offsetWidth : na turalWidth; 195 var offsetWidth = precomputedFeatures ? precomputedFeatures.offsetWidth : na turalWidth;
196 var offsetHeight = precomputedFeatures ? precomputedFeatures.offsetHeight : naturalHeight; 196 var offsetHeight = precomputedFeatures ? precomputedFeatures.offsetHeight : naturalHeight;
197 var description; 197 var description;
198 if (showDimensions) { 198 if (showDimensions) {
199 if (offsetHeight === naturalHeight && offsetWidth === naturalWidth) 199 if (offsetHeight === naturalHeight && offsetWidth === naturalWidth)
200 description = WebInspector.UIString('%d \xd7 %d pixels', offsetWidth, of fsetHeight); 200 description = Common.UIString('%d \xd7 %d pixels', offsetWidth, offsetHe ight);
201 else 201 else
202 description = WebInspector.UIString( 202 description = Common.UIString(
203 '%d \xd7 %d pixels (Natural: %d \xd7 %d pixels)', offsetWidth, offse tHeight, naturalWidth, naturalHeight); 203 '%d \xd7 %d pixels (Natural: %d \xd7 %d pixels)', offsetWidth, offse tHeight, naturalWidth, naturalHeight);
204 } 204 }
205 205
206 container.createChild('tr').createChild('td', 'image-container').appendChild (imageElement); 206 container.createChild('tr').createChild('td', 'image-container').appendChild (imageElement);
207 if (description) 207 if (description)
208 container.createChild('tr').createChild('td').createChild('span', 'descrip tion').textContent = description; 208 container.createChild('tr').createChild('td').createChild('span', 'descrip tion').textContent = description;
209 if (imageURL !== originalImageURL) 209 if (imageURL !== originalImageURL)
210 container.createChild('tr').createChild('td').createChild('span', 'descrip tion').textContent = 210 container.createChild('tr').createChild('td').createChild('span', 'descrip tion').textContent =
211 String.sprintf('currentSrc: %s', imageURL.trimMiddle(100)); 211 String.sprintf('currentSrc: %s', imageURL.trimMiddle(100));
212 userCallback(container); 212 userCallback(container);
213 } 213 }
214 }; 214 };
215 215
216 /** 216 /**
217 * @param {!WebInspector.Target} target 217 * @param {!SDK.Target} target
218 * @param {!WebInspector.Linkifier} linkifier 218 * @param {!Components.Linkifier} linkifier
219 * @param {!Protocol.Runtime.StackTrace=} stackTrace 219 * @param {!Protocol.Runtime.StackTrace=} stackTrace
220 * @return {!Element} 220 * @return {!Element}
221 */ 221 */
222 WebInspector.DOMPresentationUtils.buildStackTracePreviewContents = function(targ et, linkifier, stackTrace) { 222 Components.DOMPresentationUtils.buildStackTracePreviewContents = function(target , linkifier, stackTrace) {
223 var element = createElement('span'); 223 var element = createElement('span');
224 element.style.display = 'inline-block'; 224 element.style.display = 'inline-block';
225 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(element, 'compone nts/domUtils.css'); 225 var shadowRoot = UI.createShadowRootWithCoreStyles(element, 'components/domUti ls.css');
226 var contentElement = shadowRoot.createChild('table', 'stack-preview-container' ); 226 var contentElement = shadowRoot.createChild('table', 'stack-preview-container' );
227 227
228 /** 228 /**
229 * @param {!Protocol.Runtime.StackTrace} stackTrace 229 * @param {!Protocol.Runtime.StackTrace} stackTrace
230 */ 230 */
231 function appendStackTrace(stackTrace) { 231 function appendStackTrace(stackTrace) {
232 for (var stackFrame of stackTrace.callFrames) { 232 for (var stackFrame of stackTrace.callFrames) {
233 var row = createElement('tr'); 233 var row = createElement('tr');
234 row.createChild('td').textContent = '\n'; 234 row.createChild('td').textContent = '\n';
235 row.createChild('td', 'function-name').textContent = WebInspector.beautify FunctionName(stackFrame.functionName); 235 row.createChild('td', 'function-name').textContent = UI.beautifyFunctionNa me(stackFrame.functionName);
236 var link = linkifier.maybeLinkifyConsoleCallFrame(target, stackFrame); 236 var link = linkifier.maybeLinkifyConsoleCallFrame(target, stackFrame);
237 if (link) { 237 if (link) {
238 row.createChild('td').textContent = ' @ '; 238 row.createChild('td').textContent = ' @ ';
239 row.createChild('td').appendChild(link); 239 row.createChild('td').appendChild(link);
240 } 240 }
241 contentElement.appendChild(row); 241 contentElement.appendChild(row);
242 } 242 }
243 } 243 }
244 244
245 if (!stackTrace) 245 if (!stackTrace)
246 return element; 246 return element;
247 247
248 appendStackTrace(stackTrace); 248 appendStackTrace(stackTrace);
249 249
250 var asyncStackTrace = stackTrace.parent; 250 var asyncStackTrace = stackTrace.parent;
251 while (asyncStackTrace) { 251 while (asyncStackTrace) {
252 if (!asyncStackTrace.callFrames.length) { 252 if (!asyncStackTrace.callFrames.length) {
253 asyncStackTrace = asyncStackTrace.parent; 253 asyncStackTrace = asyncStackTrace.parent;
254 continue; 254 continue;
255 } 255 }
256 var row = contentElement.createChild('tr'); 256 var row = contentElement.createChild('tr');
257 row.createChild('td').textContent = '\n'; 257 row.createChild('td').textContent = '\n';
258 row.createChild('td', 'stack-preview-async-description').textContent = 258 row.createChild('td', 'stack-preview-async-description').textContent =
259 WebInspector.asyncStackTraceLabel(asyncStackTrace.description); 259 UI.asyncStackTraceLabel(asyncStackTrace.description);
260 row.createChild('td'); 260 row.createChild('td');
261 row.createChild('td'); 261 row.createChild('td');
262 appendStackTrace(asyncStackTrace); 262 appendStackTrace(asyncStackTrace);
263 asyncStackTrace = asyncStackTrace.parent; 263 asyncStackTrace = asyncStackTrace.parent;
264 } 264 }
265 265
266 return element; 266 return element;
267 }; 267 };
268 268
269 /** 269 /**
270 * @param {!WebInspector.DOMNode} node 270 * @param {!SDK.DOMNode} node
271 * @param {boolean=} justSelector 271 * @param {boolean=} justSelector
272 * @return {string} 272 * @return {string}
273 */ 273 */
274 WebInspector.DOMPresentationUtils.fullQualifiedSelector = function(node, justSel ector) { 274 Components.DOMPresentationUtils.fullQualifiedSelector = function(node, justSelec tor) {
275 if (node.nodeType() !== Node.ELEMENT_NODE) 275 if (node.nodeType() !== Node.ELEMENT_NODE)
276 return node.localName() || node.nodeName().toLowerCase(); 276 return node.localName() || node.nodeName().toLowerCase();
277 return WebInspector.DOMPresentationUtils.cssPath(node, justSelector); 277 return Components.DOMPresentationUtils.cssPath(node, justSelector);
278 }; 278 };
279 279
280 /** 280 /**
281 * @param {!WebInspector.DOMNode} node 281 * @param {!SDK.DOMNode} node
282 * @return {string} 282 * @return {string}
283 */ 283 */
284 WebInspector.DOMPresentationUtils.simpleSelector = function(node) { 284 Components.DOMPresentationUtils.simpleSelector = function(node) {
285 var lowerCaseName = node.localName() || node.nodeName().toLowerCase(); 285 var lowerCaseName = node.localName() || node.nodeName().toLowerCase();
286 if (node.nodeType() !== Node.ELEMENT_NODE) 286 if (node.nodeType() !== Node.ELEMENT_NODE)
287 return lowerCaseName; 287 return lowerCaseName;
288 if (lowerCaseName === 'input' && node.getAttribute('type') && !node.getAttribu te('id') && !node.getAttribute('class')) 288 if (lowerCaseName === 'input' && node.getAttribute('type') && !node.getAttribu te('id') && !node.getAttribute('class'))
289 return lowerCaseName + '[type="' + node.getAttribute('type') + '"]'; 289 return lowerCaseName + '[type="' + node.getAttribute('type') + '"]';
290 if (node.getAttribute('id')) 290 if (node.getAttribute('id'))
291 return lowerCaseName + '#' + node.getAttribute('id'); 291 return lowerCaseName + '#' + node.getAttribute('id');
292 if (node.getAttribute('class')) 292 if (node.getAttribute('class'))
293 return (lowerCaseName === 'div' ? '' : lowerCaseName) + '.' + 293 return (lowerCaseName === 'div' ? '' : lowerCaseName) + '.' +
294 node.getAttribute('class').trim().replace(/\s+/g, '.'); 294 node.getAttribute('class').trim().replace(/\s+/g, '.');
295 return lowerCaseName; 295 return lowerCaseName;
296 }; 296 };
297 297
298 /** 298 /**
299 * @param {!WebInspector.DOMNode} node 299 * @param {!SDK.DOMNode} node
300 * @param {boolean=} optimized 300 * @param {boolean=} optimized
301 * @return {string} 301 * @return {string}
302 */ 302 */
303 WebInspector.DOMPresentationUtils.cssPath = function(node, optimized) { 303 Components.DOMPresentationUtils.cssPath = function(node, optimized) {
304 if (node.nodeType() !== Node.ELEMENT_NODE) 304 if (node.nodeType() !== Node.ELEMENT_NODE)
305 return ''; 305 return '';
306 306
307 var steps = []; 307 var steps = [];
308 var contextNode = node; 308 var contextNode = node;
309 while (contextNode) { 309 while (contextNode) {
310 var step = WebInspector.DOMPresentationUtils._cssPathStep(contextNode, !!opt imized, contextNode === node); 310 var step = Components.DOMPresentationUtils._cssPathStep(contextNode, !!optim ized, contextNode === node);
311 if (!step) 311 if (!step)
312 break; // Error - bail out early. 312 break; // Error - bail out early.
313 steps.push(step); 313 steps.push(step);
314 if (step.optimized) 314 if (step.optimized)
315 break; 315 break;
316 contextNode = contextNode.parentNode; 316 contextNode = contextNode.parentNode;
317 } 317 }
318 318
319 steps.reverse(); 319 steps.reverse();
320 return steps.join(' > '); 320 return steps.join(' > ');
321 }; 321 };
322 322
323 /** 323 /**
324 * @param {!WebInspector.DOMNode} node 324 * @param {!SDK.DOMNode} node
325 * @param {boolean} optimized 325 * @param {boolean} optimized
326 * @param {boolean} isTargetNode 326 * @param {boolean} isTargetNode
327 * @return {?WebInspector.DOMNodePathStep} 327 * @return {?Components.DOMNodePathStep}
328 */ 328 */
329 WebInspector.DOMPresentationUtils._cssPathStep = function(node, optimized, isTar getNode) { 329 Components.DOMPresentationUtils._cssPathStep = function(node, optimized, isTarge tNode) {
330 if (node.nodeType() !== Node.ELEMENT_NODE) 330 if (node.nodeType() !== Node.ELEMENT_NODE)
331 return null; 331 return null;
332 332
333 var id = node.getAttribute('id'); 333 var id = node.getAttribute('id');
334 if (optimized) { 334 if (optimized) {
335 if (id) 335 if (id)
336 return new WebInspector.DOMNodePathStep(idSelector(id), true); 336 return new Components.DOMNodePathStep(idSelector(id), true);
337 var nodeNameLower = node.nodeName().toLowerCase(); 337 var nodeNameLower = node.nodeName().toLowerCase();
338 if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower == = 'html') 338 if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower == = 'html')
339 return new WebInspector.DOMNodePathStep(node.nodeNameInCorrectCase(), true ); 339 return new Components.DOMNodePathStep(node.nodeNameInCorrectCase(), true);
340 } 340 }
341 var nodeName = node.nodeNameInCorrectCase(); 341 var nodeName = node.nodeNameInCorrectCase();
342 342
343 if (id) 343 if (id)
344 return new WebInspector.DOMNodePathStep(nodeName + idSelector(id), true); 344 return new Components.DOMNodePathStep(nodeName + idSelector(id), true);
345 var parent = node.parentNode; 345 var parent = node.parentNode;
346 if (!parent || parent.nodeType() === Node.DOCUMENT_NODE) 346 if (!parent || parent.nodeType() === Node.DOCUMENT_NODE)
347 return new WebInspector.DOMNodePathStep(nodeName, true); 347 return new Components.DOMNodePathStep(nodeName, true);
348 348
349 /** 349 /**
350 * @param {!WebInspector.DOMNode} node 350 * @param {!SDK.DOMNode} node
351 * @return {!Array.<string>} 351 * @return {!Array.<string>}
352 */ 352 */
353 function prefixedElementClassNames(node) { 353 function prefixedElementClassNames(node) {
354 var classAttribute = node.getAttribute('class'); 354 var classAttribute = node.getAttribute('class');
355 if (!classAttribute) 355 if (!classAttribute)
356 return []; 356 return [];
357 357
358 return classAttribute.split(/\s+/g).filter(Boolean).map(function(name) { 358 return classAttribute.split(/\s+/g).filter(Boolean).map(function(name) {
359 // The prefix is required to store "__proto__" in a object-based map. 359 // The prefix is required to store "__proto__" in a object-based map.
360 return '$' + name; 360 return '$' + name;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (isTargetNode && nodeName.toLowerCase() === 'input' && node.getAttribute('t ype') && !node.getAttribute('id') && 463 if (isTargetNode && nodeName.toLowerCase() === 'input' && node.getAttribute('t ype') && !node.getAttribute('id') &&
464 !node.getAttribute('class')) 464 !node.getAttribute('class'))
465 result += '[type="' + node.getAttribute('type') + '"]'; 465 result += '[type="' + node.getAttribute('type') + '"]';
466 if (needsNthChild) { 466 if (needsNthChild) {
467 result += ':nth-child(' + (ownIndex + 1) + ')'; 467 result += ':nth-child(' + (ownIndex + 1) + ')';
468 } else if (needsClassNames) { 468 } else if (needsClassNames) {
469 for (var prefixedName of prefixedOwnClassNamesArray) 469 for (var prefixedName of prefixedOwnClassNamesArray)
470 result += '.' + escapeIdentifierIfNeeded(prefixedName.substr(1)); 470 result += '.' + escapeIdentifierIfNeeded(prefixedName.substr(1));
471 } 471 }
472 472
473 return new WebInspector.DOMNodePathStep(result, false); 473 return new Components.DOMNodePathStep(result, false);
474 }; 474 };
475 475
476 /** 476 /**
477 * @param {!WebInspector.DOMNode} node 477 * @param {!SDK.DOMNode} node
478 * @param {boolean=} optimized 478 * @param {boolean=} optimized
479 * @return {string} 479 * @return {string}
480 */ 480 */
481 WebInspector.DOMPresentationUtils.xPath = function(node, optimized) { 481 Components.DOMPresentationUtils.xPath = function(node, optimized) {
482 if (node.nodeType() === Node.DOCUMENT_NODE) 482 if (node.nodeType() === Node.DOCUMENT_NODE)
483 return '/'; 483 return '/';
484 484
485 var steps = []; 485 var steps = [];
486 var contextNode = node; 486 var contextNode = node;
487 while (contextNode) { 487 while (contextNode) {
488 var step = WebInspector.DOMPresentationUtils._xPathValue(contextNode, optimi zed); 488 var step = Components.DOMPresentationUtils._xPathValue(contextNode, optimize d);
489 if (!step) 489 if (!step)
490 break; // Error - bail out early. 490 break; // Error - bail out early.
491 steps.push(step); 491 steps.push(step);
492 if (step.optimized) 492 if (step.optimized)
493 break; 493 break;
494 contextNode = contextNode.parentNode; 494 contextNode = contextNode.parentNode;
495 } 495 }
496 496
497 steps.reverse(); 497 steps.reverse();
498 return (steps.length && steps[0].optimized ? '' : '/') + steps.join('/'); 498 return (steps.length && steps[0].optimized ? '' : '/') + steps.join('/');
499 }; 499 };
500 500
501 /** 501 /**
502 * @param {!WebInspector.DOMNode} node 502 * @param {!SDK.DOMNode} node
503 * @param {boolean=} optimized 503 * @param {boolean=} optimized
504 * @return {?WebInspector.DOMNodePathStep} 504 * @return {?Components.DOMNodePathStep}
505 */ 505 */
506 WebInspector.DOMPresentationUtils._xPathValue = function(node, optimized) { 506 Components.DOMPresentationUtils._xPathValue = function(node, optimized) {
507 var ownValue; 507 var ownValue;
508 var ownIndex = WebInspector.DOMPresentationUtils._xPathIndex(node); 508 var ownIndex = Components.DOMPresentationUtils._xPathIndex(node);
509 if (ownIndex === -1) 509 if (ownIndex === -1)
510 return null; // Error. 510 return null; // Error.
511 511
512 switch (node.nodeType()) { 512 switch (node.nodeType()) {
513 case Node.ELEMENT_NODE: 513 case Node.ELEMENT_NODE:
514 if (optimized && node.getAttribute('id')) 514 if (optimized && node.getAttribute('id'))
515 return new WebInspector.DOMNodePathStep('//*[@id="' + node.getAttribute( 'id') + '"]', true); 515 return new Components.DOMNodePathStep('//*[@id="' + node.getAttribute('i d') + '"]', true);
516 ownValue = node.localName(); 516 ownValue = node.localName();
517 break; 517 break;
518 case Node.ATTRIBUTE_NODE: 518 case Node.ATTRIBUTE_NODE:
519 ownValue = '@' + node.nodeName(); 519 ownValue = '@' + node.nodeName();
520 break; 520 break;
521 case Node.TEXT_NODE: 521 case Node.TEXT_NODE:
522 case Node.CDATA_SECTION_NODE: 522 case Node.CDATA_SECTION_NODE:
523 ownValue = 'text()'; 523 ownValue = 'text()';
524 break; 524 break;
525 case Node.PROCESSING_INSTRUCTION_NODE: 525 case Node.PROCESSING_INSTRUCTION_NODE:
526 ownValue = 'processing-instruction()'; 526 ownValue = 'processing-instruction()';
527 break; 527 break;
528 case Node.COMMENT_NODE: 528 case Node.COMMENT_NODE:
529 ownValue = 'comment()'; 529 ownValue = 'comment()';
530 break; 530 break;
531 case Node.DOCUMENT_NODE: 531 case Node.DOCUMENT_NODE:
532 ownValue = ''; 532 ownValue = '';
533 break; 533 break;
534 default: 534 default:
535 ownValue = ''; 535 ownValue = '';
536 break; 536 break;
537 } 537 }
538 538
539 if (ownIndex > 0) 539 if (ownIndex > 0)
540 ownValue += '[' + ownIndex + ']'; 540 ownValue += '[' + ownIndex + ']';
541 541
542 return new WebInspector.DOMNodePathStep(ownValue, node.nodeType() === Node.DOC UMENT_NODE); 542 return new Components.DOMNodePathStep(ownValue, node.nodeType() === Node.DOCUM ENT_NODE);
543 }; 543 };
544 544
545 /** 545 /**
546 * @param {!WebInspector.DOMNode} node 546 * @param {!SDK.DOMNode} node
547 * @return {number} 547 * @return {number}
548 */ 548 */
549 WebInspector.DOMPresentationUtils._xPathIndex = function(node) { 549 Components.DOMPresentationUtils._xPathIndex = function(node) {
550 // Returns -1 in case of error, 0 if no siblings matching the same expression, <XPath index among the same expression-matching sibling nodes> otherwise. 550 // Returns -1 in case of error, 0 if no siblings matching the same expression, <XPath index among the same expression-matching sibling nodes> otherwise.
551 function areNodesSimilar(left, right) { 551 function areNodesSimilar(left, right) {
552 if (left === right) 552 if (left === right)
553 return true; 553 return true;
554 554
555 if (left.nodeType() === Node.ELEMENT_NODE && right.nodeType() === Node.ELEME NT_NODE) 555 if (left.nodeType() === Node.ELEMENT_NODE && right.nodeType() === Node.ELEME NT_NODE)
556 return left.localName() === right.localName(); 556 return left.localName() === right.localName();
557 557
558 if (left.nodeType() === right.nodeType()) 558 if (left.nodeType() === right.nodeType())
559 return true; 559 return true;
(...skipping 23 matching lines...) Expand all
583 return ownIndex; 583 return ownIndex;
584 ++ownIndex; 584 ++ownIndex;
585 } 585 }
586 } 586 }
587 return -1; // An error occurred: |node| not found in parent's children. 587 return -1; // An error occurred: |node| not found in parent's children.
588 }; 588 };
589 589
590 /** 590 /**
591 * @unrestricted 591 * @unrestricted
592 */ 592 */
593 WebInspector.DOMNodePathStep = class { 593 Components.DOMNodePathStep = class {
594 /** 594 /**
595 * @param {string} value 595 * @param {string} value
596 * @param {boolean} optimized 596 * @param {boolean} optimized
597 */ 597 */
598 constructor(value, optimized) { 598 constructor(value, optimized) {
599 this.value = value; 599 this.value = value;
600 this.optimized = optimized || false; 600 this.optimized = optimized || false;
601 } 601 }
602 602
603 /** 603 /**
604 * @override 604 * @override
605 * @return {string} 605 * @return {string}
606 */ 606 */
607 toString() { 607 toString() {
608 return this.value; 608 return this.value;
609 } 609 }
610 }; 610 };
611 611
612 /** 612 /**
613 * @interface 613 * @interface
614 */ 614 */
615 WebInspector.DOMPresentationUtils.MarkerDecorator = function() {}; 615 Components.DOMPresentationUtils.MarkerDecorator = function() {};
616 616
617 WebInspector.DOMPresentationUtils.MarkerDecorator.prototype = { 617 Components.DOMPresentationUtils.MarkerDecorator.prototype = {
618 /** 618 /**
619 * @param {!WebInspector.DOMNode} node 619 * @param {!SDK.DOMNode} node
620 * @return {?{title: string, color: string}} 620 * @return {?{title: string, color: string}}
621 */ 621 */
622 decorate: function(node) {} 622 decorate: function(node) {}
623 }; 623 };
624 624
625 /** 625 /**
626 * @implements {WebInspector.DOMPresentationUtils.MarkerDecorator} 626 * @implements {Components.DOMPresentationUtils.MarkerDecorator}
627 * @unrestricted 627 * @unrestricted
628 */ 628 */
629 WebInspector.DOMPresentationUtils.GenericDecorator = class { 629 Components.DOMPresentationUtils.GenericDecorator = class {
630 /** 630 /**
631 * @param {!Runtime.Extension} extension 631 * @param {!Runtime.Extension} extension
632 */ 632 */
633 constructor(extension) { 633 constructor(extension) {
634 this._title = WebInspector.UIString(extension.title()); 634 this._title = Common.UIString(extension.title());
635 this._color = extension.descriptor()['color']; 635 this._color = extension.descriptor()['color'];
636 } 636 }
637 637
638 /** 638 /**
639 * @override 639 * @override
640 * @param {!WebInspector.DOMNode} node 640 * @param {!SDK.DOMNode} node
641 * @return {?{title: string, color: string}} 641 * @return {?{title: string, color: string}}
642 */ 642 */
643 decorate(node) { 643 decorate(node) {
644 return {title: this._title, color: this._color}; 644 return {title: this._title, color: this._color};
645 } 645 }
646 }; 646 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698