Changeset 56347 in webkit
- Timestamp:
- Mar 22, 2010 11:18:09 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r56345 r56347 1 2010-03-22 Alexander Pavlov <apavlov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: AuditRules still use getMatchedCSSRules as a part of the img-related audit. 6 https://bugs.webkit.org/show_bug.cgi?id=36424 7 8 * inspector/front-end/AuditRules.js: 9 (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun): 10 (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun.receivedImages): 11 (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun.pushImageNodes): 12 * inspector/front-end/InjectedScript.js: 13 (injectedScriptConstructor): 14 1 15 2010-03-22 Darin Adler <darin@apple.com> 2 16 -
trunk/WebCore/inspector/front-end/AuditRules.js
r56107 r56347 624 624 doRun: function(resources, result, callback) 625 625 { 626 function evalCallback(evalResult, isException) 627 { 628 if (isException || !evalResult || !evalResult.totalImages) 629 return callback(null); 630 631 var entry = result.addChild("A width and height should be specified for all images in order to speed up page display. The following image(s) are missing a width and/or height:", true); 632 var map = evalResult.map; 626 function doneCallback(context) 627 { 628 var map = context.urlToNoDimensionCount; 633 629 for (var url in map) { 630 var entry = entry || result.addChild("A width and height should be specified for all images in order to speed up page display. The following image(s) are missing a width and/or height:", true); 634 631 var value = WebInspector.linkifyURL(url); 635 632 if (map[url] > 1) 636 value += " (" + map[url] + " uses)";633 value += String.sprintf(" (%d uses)", map[url]); 637 634 entry.addChild(value); 638 635 result.violationCount++; 639 636 } 640 callback(result); 641 } 642 643 function routine() 644 { 645 var images = document.getElementsByTagName("img"); 646 const widthRegExp = /width[^:;]*:/gim; 647 const heightRegExp = /height[^:;]*:/gim; 648 649 function hasDimension(element, cssText, rules, regexp, attributeName) { 650 if (element.attributes.getNamedItem(attributeName) != null || (cssText && cssText.match(regexp))) 651 return true; 652 653 if (!rules) 654 return false; 655 for (var i = 0; i < rules.length; ++i) { 656 if (rules.item(i).style.cssText.match(regexp)) 657 return true; 637 callback(entry ? result : null); 638 } 639 640 function imageStylesReady(imageId, context, styles) 641 { 642 --context.imagesLeft; 643 644 const node = WebInspector.domAgent.nodeForId(imageId); 645 var src = node.getAttribute("src"); 646 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) { 647 if (frameOwnerCandidate.documentURL) { 648 var completeSrc = WebInspector.completeURL(frameOwnerCandidate.documentURL, src); 649 break; 658 650 } 659 return false; 660 } 661 662 function hasWidth(element, cssText, rules) { 663 return hasDimension(element, cssText, rules, widthRegExp, "width"); 664 } 665 666 function hasHeight(element, cssText, rules) { 667 return hasDimension(element, cssText, rules, heightRegExp, "height"); 668 } 669 670 var urlToNoDimensionCount = {}; 671 var found = false; 672 for (var i = 0; i < images.length; ++i) { 673 var image = images[i]; 674 if (!image.src) 651 } 652 if (completeSrc) 653 src = completeSrc; 654 655 const computedStyle = new WebInspector.CSSStyleDeclaration(styles.computedStyle); 656 if (computedStyle.getPropertyValue("position") === "absolute") { 657 if (!context.imagesLeft) 658 doneCallback(context); 659 return; 660 } 661 662 var widthFound = "width" in styles.styleAttributes; 663 var heightFound = "height" in styles.styleAttributes; 664 665 for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFound && heightFound); --i) { 666 var style = WebInspector.CSSStyleDeclaration.parseRule(styles.matchedCSSRules[i]).style; 667 if (style.getPropertyValue("width") !== "") 668 widthFound = true; 669 if (style.getPropertyValue("height") !== "") 670 heightFound = true; 671 } 672 673 if (!widthFound || !heightFound) { 674 if (src in context.urlToNoDimensionCount) 675 ++context.urlToNoDimensionCount[src]; 676 else 677 context.urlToNoDimensionCount[src] = 1; 678 } 679 680 if (!context.imagesLeft) 681 doneCallback(context); 682 } 683 684 function receivedImages(imageIds) 685 { 686 if (!imageIds || !imageIds.length) 687 return callback(null); 688 var context = {imagesLeft: imageIds.length, urlToNoDimensionCount: {}}; 689 for (var i = imageIds.length - 1; i >= 0; --i) 690 InspectorBackend.getStyles(WebInspector.Callback.wrap(imageStylesReady.bind(this, imageIds[i], context)), imageIds[i], true); 691 } 692 693 function pushImageNodes() 694 { 695 const nodeIds = []; 696 var nodes = document.getElementsByTagName("img"); 697 for (var i = 0; i < nodes.length; ++i) { 698 if (!nodes[i].src) 675 699 continue; 676 var position = document.defaultView.getComputedStyle(image).getPropertyValue("position"); 677 if (position === "absolute") 678 continue; 679 var cssText = (image.style && image.style.cssText) ? image.style.cssText : ""; 680 var rules = document.defaultView.getMatchedCSSRules(image, "", true); 681 if (!hasWidth(image, cssText, rules) || !hasHeight(image, cssText, rules)) { 682 found = true; 683 if (urlToNoDimensionCount.hasOwnProperty(image.src)) 684 ++urlToNoDimensionCount[image.src]; 685 else 686 urlToNoDimensionCount[image.src] = 1; 687 } 688 } 689 return found ? {totalImages: images.length, map: urlToNoDimensionCount} : null; 690 } 691 692 WebInspector.AuditRules.evaluateInTargetWindow(routine, null, evalCallback.bind(this)); 700 var nodeId = this.getNodeId(nodes[i]); 701 nodeIds.push(nodeId); 702 } 703 return nodeIds; 704 } 705 706 WebInspector.AuditRules.evaluateInTargetWindow(pushImageNodes, null, receivedImages); 693 707 } 694 708 } -
trunk/WebCore/inspector/front-end/InjectedScript.js
r56161 r56347 304 304 inspectedNodes.pop(); 305 305 return true; 306 } 307 308 InjectedScript.getNodeId = function(node) 309 { 310 return InjectedScriptHost.pushNodePathToFrontend(node, false, false); 306 311 } 307 312
Note: See TracChangeset
for help on using the changeset viewer.