Changeset 99849 in webkit
- Timestamp:
- Nov 10, 2011 6:56:28 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r99841 r99849 1 2011-11-10 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Show media queries associated with specific CSS rules 4 https://bugs.webkit.org/show_bug.cgi?id=65626 5 6 Reviewed by Pavel Feldman. 7 8 * inspector/styles/media-queries-expected.txt: Added. 9 * inspector/styles/media-queries.html: Added. 10 * inspector/styles/resources/media-queries-1.css: Added. 11 (body): 12 (#main): 13 * inspector/styles/resources/media-queries.css: Added. 14 (#main): 15 * inspector/styles/styles-iframe-expected.txt: 16 * inspector/styles/styles-source-lines-expected.txt: 17 1 18 2011-11-10 Csaba Osztrogonác <ossy@webkit.org> 2 19 -
trunk/LayoutTests/inspector/styles/styles-iframe-expected.txt
r99713 r99849 9 9 ======== Matched CSS Rules ======== 10 10 [expanded] 11 media="screen" (styles-iframe.html) 11 12 #main { (styles-iframe.html:5) 12 13 background: blue; … … 23 24 ======== Matched CSS Rules ======== 24 25 [expanded] 26 media="screen" (styles-iframe-data.html) 25 27 body { (styles-iframe-data.html:4) 26 28 background: green; -
trunk/LayoutTests/inspector/styles/styles-source-lines-expected.txt
r99713 r99849 6 6 ======== Matched CSS Rules ======== 7 7 [expanded] 8 media="screen" (styles-source-lines.html) 8 9 #main, .at_line_50 { (styles-source-lines.html:50) 9 10 border: 1px solid … … 11 12 12 13 [expanded] 14 media="screen" (styles-source-lines.html) 13 15 #main, .at_line_43 { (styles-source-lines.html:43) 14 16 font-size: 10px; 15 17 16 18 [expanded] 19 media="screen" (styles-source-lines.html) 17 20 #main, .at_line_29 { (styles-source-lines.html:29) 18 21 font-family: /* Comment in … … 20 23 21 24 [expanded] 25 media="screen" (styles-source-lines.html) 22 26 #main, .at_line_15::before { (styles-source-lines.html:15) 23 27 color: red; -
trunk/Source/WebCore/ChangeLog
r99848 r99849 1 2011-11-10 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Show media queries associated with specific CSS rules 4 https://bugs.webkit.org/show_bug.cgi?id=65626 5 6 Reviewed by Pavel Feldman. 7 8 Test: inspector/styles/media-queries.html 9 10 * css/CSSGrammar.y: 11 * css/CSSParser.cpp: 12 (WebCore::CSSParser::updateLastMediaLine): 13 * css/CSSParser.h: 14 * css/MediaList.cpp: 15 (WebCore::MediaList::MediaList): 16 * css/MediaList.h: 17 (WebCore::MediaList::lastLine): 18 (WebCore::MediaList::setLastLine): 19 * inspector/Inspector.json: 20 * inspector/InspectorCSSAgent.cpp: 21 (WebCore::InspectorCSSAgent::bindStyleSheet): 22 (WebCore::InspectorCSSAgent::viaInspectorStyleSheet): 23 * inspector/InspectorDOMAgent.cpp: 24 (WebCore::InspectorDOMAgent::documentURLString): 25 * inspector/InspectorDOMAgent.h: 26 * inspector/InspectorStyleSheet.cpp: 27 (WebCore::buildMediaObject): 28 (WebCore::fillMediaListChain): 29 (WebCore::InspectorStyleSheet::buildObjectForRule): 30 * inspector/front-end/CSSStyleModel.js: 31 (WebInspector.CSSRule): 32 (WebInspector.CSSMedia): 33 (WebInspector.CSSMedia.parsePayload): 34 (WebInspector.CSSMedia.parseMediaArrayPayload): 35 * inspector/front-end/ResourceUtils.js: 36 (WebInspector.linkifyResourceAsNode): 37 * inspector/front-end/StylesSidebarPane.js: 38 (WebInspector.StylesSidebarPane.prototype._rebuildUpdate): 39 (WebInspector.StylesSidebarPane.prototype._rebuildStyleRules): 40 (WebInspector.StylePropertiesSection.prototype._handleEmptySpaceDoubleClick): 41 (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.successCallback): 42 (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted): 43 * inspector/front-end/elementsPanel.css: 44 (.styles-section .header .title .media, .styles-section .header .title .media .subtitle): 45 (.styles-section .header .subtitle): 46 1 47 2011-11-10 Alexander Pavlov <apavlov@chromium.org> 2 48 -
trunk/Source/WebCore/css/CSSGrammar.y
r99595 r99849 576 576 $$ = p->createMediaList(); 577 577 $$->appendMediaQuery(p->sinkFloatingMediaQuery($1)); 578 p->updateLastMediaLine($$); 578 579 } 579 580 | media_list ',' maybe_space media_query { 580 581 $$ = $1; 582 CSSParser* p = static_cast<CSSParser*>(parser); 581 583 if ($$) 582 $$->appendMediaQuery(static_cast<CSSParser*>(parser)->sinkFloatingMediaQuery($4)); 584 $$->appendMediaQuery(p->sinkFloatingMediaQuery($4)); 585 p->updateLastMediaLine($$); 583 586 } 584 587 | media_list error { -
trunk/Source/WebCore/css/CSSParser.cpp
r99695 r99849 7696 7696 } 7697 7697 7698 void CSSParser::updateLastMediaLine(MediaList* media) 7699 { 7700 media->setLastLine(m_lineNumber); 7701 } 7702 7698 7703 void CSSParser::markSelectorListStart() 7699 7704 { -
trunk/Source/WebCore/css/CSSParser.h
r99695 r99849 261 261 262 262 void updateLastSelectorLineAndPosition(); 263 void updateLastMediaLine(MediaList*); 263 264 264 265 void clearProperties(); -
trunk/Source/WebCore/css/MediaList.cpp
r97854 r99849 61 61 : m_fallback(fallbackToDescriptor) 62 62 , m_parentStyleSheet(parentStyleSheet) 63 , m_lastLine(0) 63 64 { 64 65 } … … 67 68 : m_fallback(fallbackToDescriptor) 68 69 , m_parentStyleSheet(parentStyleSheet) 70 , m_lastLine(0) 69 71 { 70 72 ExceptionCode ec = 0; … … 85 87 : m_fallback(false) 86 88 , m_parentStyleSheet(parentRule->parentStyleSheet()) 89 , m_lastLine(0) 87 90 { 88 91 ExceptionCode ec = 0; -
trunk/Source/WebCore/css/MediaList.h
r99184 r99849 86 86 } 87 87 88 int lastLine() const { return m_lastLine; } 89 void setLastLine(int lastLine) { m_lastLine = lastLine; } 90 88 91 private: 89 92 MediaList(CSSStyleSheet* parentSheet, bool fallbackToDescription); … … 97 100 CSSStyleSheet* m_parentStyleSheet; 98 101 Vector<MediaQuery*> m_queries; 102 int m_lastLine; 99 103 }; 100 104 -
trunk/Source/WebCore/inspector/Inspector.json
r98456 r99849 1439 1439 { "name": "origin", "type": "string", "enum": ["user", "user-agent", "inspector", ""], "description": "The parent stylesheet type: \"user\" for user stylesheets, \"user-agent\" for user-agent stylesheets, \"inspector\" for stylesheets created by the inspector (i.e. those holding new rules created with <code>addRule()</code>), \"\" for regular stylesheets."}, 1440 1440 { "name": "style", "$ref": "CSSStyle", "description": "Associated style declaration." }, 1441 { "name": "selectorRange", "$ref": "SourceRange", "optional": true, "description": "The rule selector range in the underlying resource (if available)." } 1441 { "name": "selectorRange", "$ref": "SourceRange", "optional": true, "description": "The rule selector range in the underlying resource (if available)." }, 1442 { "name": "media", "type": "array", "items": { "$ref": "CSSMedia" }, "optional": true, "description": "Media list array (for rules involving media queries). The array enumerates media queries starting with the innermost one, going outwards." } 1442 1443 ], 1443 1444 "description": "CSS rule representation." … … 1488 1489 ], 1489 1490 "description": "CSS style effective visual dimensions and source offsets." 1491 }, 1492 { 1493 "id": "CSSMedia", 1494 "type": "object", 1495 "properties": [ 1496 { "name": "text", "type": "string", "description": "Media query text." }, 1497 { "name": "source", "type": "string", "enum": ["mediaRule", "importRule", "stylesheet"], "optional": true, "description": "Source of the media query: \"mediaRule\" if specified by a @media rule, \"importRule\" if specified by an @import rule, \"stylesheet\" (implied if absent) if specified by a \"media\" attribute in a stylesheet's LINK or STYLE tag." }, 1498 { "name": "sourceURL", "type": "string", "optional": true, "description": "URL of the document containing the media query description." }, 1499 { "name": "sourceLine", "type": "string", "optional": true, "description": "Line in the document containing the media query (not defined for the \"stylesheet\" source)." } 1500 ], 1501 "description": "CSS media query descriptor." 1490 1502 } 1491 1503 ], -
trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
r99595 r99849 499 499 String id = String::number(m_lastStyleSheetId++); 500 500 Document* document = styleSheet->findDocument(); 501 inspectorStyleSheet = InspectorStyleSheet::create(id, styleSheet, detectOrigin(styleSheet, document), m_domAgent->documentURLString(document));501 inspectorStyleSheet = InspectorStyleSheet::create(id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document)); 502 502 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); 503 503 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet); … … 540 540 CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet); 541 541 String id = String::number(m_lastStyleSheetId++); 542 inspectorStyleSheet = InspectorStyleSheet::create(id, cssStyleSheet, "inspector", m_domAgent->documentURLString(document));542 inspectorStyleSheet = InspectorStyleSheet::create(id, cssStyleSheet, "inspector", InspectorDOMAgent::documentURLString(document)); 543 543 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); 544 544 m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet); -
trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp
r99683 r99849 1211 1211 } 1212 1212 1213 String InspectorDOMAgent::documentURLString(Document* document) const 1213 // static 1214 String InspectorDOMAgent::documentURLString(Document* document) 1214 1215 { 1215 1216 if (!document || document->url().isNull()) -
trunk/Source/WebCore/inspector/InspectorDOMAgent.h
r96106 r99849 162 162 void setDOMListener(DOMListener*); 163 163 164 String documentURLString(Document*) const;164 static String documentURLString(Document*); 165 165 166 166 PassRefPtr<InspectorObject> resolveNode(Node*, const String& objectGroup); -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r99595 r99849 103 103 namespace WebCore { 104 104 105 enum MediaListSource { 106 MediaListSourceLinkedSheet, 107 MediaListSourceInlineSheet, 108 MediaListSourceMediaRule, 109 MediaListSourceImportRule 110 }; 111 105 112 static PassRefPtr<InspectorObject> buildSourceRangeObject(const SourceRange& range) 106 113 { … … 111 118 } 112 119 120 static PassRefPtr<InspectorObject> buildMediaObject(const MediaList* media, MediaListSource mediaListSource, const String& sourceURL) 121 { 122 RefPtr<InspectorObject> mediaObject = InspectorObject::create(); 123 switch (mediaListSource) { 124 case MediaListSourceMediaRule: 125 mediaObject->setString("source", "mediaRule"); 126 break; 127 case MediaListSourceImportRule: 128 mediaObject->setString("source", "importRule"); 129 break; 130 case MediaListSourceLinkedSheet: 131 mediaObject->setString("source", "linkedSheet"); 132 break; 133 case MediaListSourceInlineSheet: 134 mediaObject->setString("source", "inlineSheet"); 135 break; 136 } 137 if (!sourceURL.isEmpty()) { 138 mediaObject->setString("sourceURL", sourceURL); 139 mediaObject->setNumber("sourceLine", media->lastLine()); 140 } 141 mediaObject->setString("text", media->mediaText()); 142 return mediaObject.release(); 143 } 144 113 145 static PassRefPtr<CSSRuleList> asCSSRuleList(CSSStyleSheet* styleSheet) 114 146 { … … 131 163 132 164 return 0; 165 } 166 167 static void fillMediaListChain(CSSRule* rule, InspectorArray* mediaArray) 168 { 169 MediaList* mediaList; 170 CSSRule* parentRule = rule; 171 String sourceURL; 172 while (parentRule) { 173 CSSStyleSheet* parentStyleSheet = 0; 174 bool isMediaRule = true; 175 if (parentRule->isMediaRule()) { 176 CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(parentRule); 177 mediaList = mediaRule->media(); 178 parentStyleSheet = mediaRule->parentStyleSheet(); 179 } else if (parentRule->isImportRule()) { 180 CSSImportRule* importRule = static_cast<CSSImportRule*>(parentRule); 181 mediaList = importRule->media(); 182 parentStyleSheet = importRule->parentStyleSheet(); 183 isMediaRule = false; 184 } else 185 mediaList = 0; 186 187 if (parentStyleSheet) { 188 sourceURL = parentStyleSheet->finalURL(); 189 if (sourceURL.isEmpty()) 190 sourceURL = InspectorDOMAgent::documentURLString(parentStyleSheet->findDocument()); 191 } else 192 sourceURL = ""; 193 194 if (mediaList && mediaList->length()) 195 mediaArray->pushObject(buildMediaObject(mediaList, isMediaRule ? MediaListSourceMediaRule : MediaListSourceImportRule, sourceURL)); 196 197 if (parentRule->parentRule()) 198 parentRule = parentRule->parentRule(); 199 else { 200 CSSStyleSheet* styleSheet = parentRule->parentStyleSheet(); 201 while (styleSheet) { 202 mediaList = styleSheet->media(); 203 if (mediaList && mediaList->length()) { 204 Document* doc = styleSheet->findDocument(); 205 if (doc) 206 sourceURL = doc->url(); 207 else if (!styleSheet->finalURL().isEmpty()) 208 sourceURL = styleSheet->finalURL(); 209 else 210 sourceURL = ""; 211 mediaArray->pushObject(buildMediaObject(mediaList, styleSheet->ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL)); 212 } 213 parentRule = styleSheet->parentRule(); 214 if (parentRule) 215 break; 216 styleSheet = styleSheet->parentStyleSheet(); 217 } 218 } 219 } 133 220 } 134 221 … … 717 804 } 718 805 806 RefPtr<InspectorArray> mediaArray = InspectorArray::create(); 807 808 fillMediaListChain(rule, mediaArray.get()); 809 if (mediaArray->length()) 810 result->setArray("media", mediaArray.release()); 811 719 812 return result.release(); 720 813 } -
trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js
r97606 r99849 491 491 this.style.parentRule = this; 492 492 this.selectorRange = payload.selectorRange; 493 if (payload.media) 494 this.media = WebInspector.CSSMedia.parseMediaArrayPayload(payload.media); 493 495 } 494 496 … … 652 654 CSSAgent.toggleProperty(this.ownerStyle.id, this.index, disabled, callback.bind(this)); 653 655 } 656 } 657 658 /** 659 * @constructor 660 * @param {*} payload 661 */ 662 WebInspector.CSSMedia = function(payload) 663 { 664 this.text = payload.text; 665 this.source = payload.source; 666 this.sourceURL = payload.sourceURL || ""; 667 this.sourceLine = typeof payload.sourceLine === "undefined" || this.source === "linkedSheet" ? -1 : payload.sourceLine; 668 } 669 670 WebInspector.CSSMedia.Source = { 671 LINKED_SHEET: "linkedSheet", 672 INLINE_SHEET: "inlineSheet", 673 MEDIA_RULE: "mediaRule", 674 IMPORT_RULE: "importRule" 675 }; 676 677 WebInspector.CSSMedia.parsePayload = function(payload) 678 { 679 return new WebInspector.CSSMedia(payload); 680 } 681 682 WebInspector.CSSMedia.parseMediaArrayPayload = function(payload) 683 { 684 var result = []; 685 for (var i = 0; i < payload.length; ++i) 686 result.push(WebInspector.CSSMedia.parsePayload(payload[i])); 687 return result; 654 688 } 655 689 -
trunk/Source/WebCore/inspector/front-end/ResourceUtils.js
r98840 r99849 216 216 var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, tooltipText); 217 217 anchor.setAttribute("preferred_panel", "resources"); 218 anchor.setAttribute("line_number", lineNumber); 218 if (typeof lineNumber !== "undefined") 219 anchor.setAttribute("line_number", lineNumber); 219 220 return anchor; 220 221 } -
trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js
r99713 r99849 340 340 for (var j = pseudoElementCSSRules.rules.length - 1; j >= 0; --j) { 341 341 var rule = pseudoElementCSSRules.rules[j]; 342 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });342 styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) }); 343 343 } 344 344 usedProperties = {}; … … 412 412 addStyleAttributes(); 413 413 } 414 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });414 styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) }); 415 415 } 416 416 … … 454 454 separatorInserted = true; 455 455 } 456 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule, isInherited: true, editable: !!(rule.style && rule.style.id) });456 styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, isInherited: true, editable: !!(rule.style && rule.style.id) }); 457 457 } 458 458 parentNode = parentNode.parentNode; … … 838 838 this.element.className = "styles-section monospace" + (isFirstSection ? " first-styles-section" : ""); 839 839 840 if (styleRule.media) { 841 for (var i = styleRule.media.length - 1; i >= 0; --i) { 842 var media = styleRule.media[i]; 843 var mediaDataElement = this.titleElement.createChild("div", "media"); 844 var mediaText; 845 switch (media.source) { 846 case WebInspector.CSSMedia.Source.LINKED_SHEET: 847 case WebInspector.CSSMedia.Source.INLINE_SHEET: 848 mediaText = "media=\"" + media.text + "\""; 849 break; 850 case WebInspector.CSSMedia.Source.MEDIA_RULE: 851 mediaText = "@media " + media.text; 852 break; 853 case WebInspector.CSSMedia.Source.IMPORT_RULE: 854 mediaText = "@import " + media.text; 855 break; 856 } 857 858 var mediaTextElement = mediaDataElement.createChild("span"); 859 mediaTextElement.textContent = mediaText; 860 mediaTextElement.title = media.text; 861 862 if (media.sourceURL) { 863 var refElement = mediaDataElement.createChild("div", "subtitle"); 864 var anchor = WebInspector.linkifyResourceAsNode(media.sourceURL, media.sourceLine < 0 ? undefined : media.sourceLine, "subtitle"); 865 anchor.style.float = "right"; 866 refElement.appendChild(anchor); 867 } 868 } 869 } 870 840 871 var selectorContainer = document.createElement("div"); 841 872 this._selectorElement = document.createElement("span"); … … 1123 1154 _handleEmptySpaceDoubleClick: function(event) 1124 1155 { 1125 if (event.target.hasStyleClass("header") || this.element.hasStyleClass("read-only") ) {1156 if (event.target.hasStyleClass("header") || this.element.hasStyleClass("read-only") || event.target.enclosingNodeOrSelfWithClass("media")) { 1126 1157 event.stopPropagation(); 1127 1158 return; … … 1211 1242 1212 1243 this.rule = newRule; 1213 this.styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, sourceURL: newRule.sourceURL, rule: newRule };1244 this.styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, media: newRule.media, sourceURL: newRule.sourceURL, rule: newRule }; 1214 1245 1215 1246 var oldIdentifier = this.identifier; -
trunk/Source/WebCore/inspector/front-end/elementsPanel.css
r98348 r99849 277 277 } 278 278 279 .styles-section .header .title .media, .styles-section .header .title .media .subtitle { 280 color: rgb(128, 128, 128); 281 overflow: hidden; 282 } 283 279 284 .styles-section .header .subtitle { 280 285 color: rgb(85, 85, 85); … … 284 289 text-overflow: ellipsis; 285 290 overflow: hidden; 291 white-space: nowrap; 286 292 } 287 293
Note: See TracChangeset
for help on using the changeset viewer.