Changeset 191421 in webkit
- Timestamp:
- Oct 21, 2015, 5:50:25 PM (10 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r191419 r191421 1 2015-10-21 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: srcset attributes should have hyperlinks to the resources 4 https://bugs.webkit.org/show_bug.cgi?id=150409 5 6 Reviewed by Timothy Hatcher. 7 8 The "srcset" attribute parsing is a simplification of: 9 https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset 10 11 The "srcset" attribute value is expected to be in comma 12 separated groups. Within each group we always expect a link, 13 and an optional descriptor. We want to linkify the link. 14 15 * UserInterface/Views/CodeMirrorAdditions.js: 16 (tokenizeSrcSetString): 17 (extendedXMLToken): 18 When parsing srcset attribute, parse links as link tokens 19 so that they are linkified in resource content views. 20 21 * UserInterface/Views/DOMTreeElement.js: 22 (WebInspector.DOMTreeElement.prototype._buildAttributeDOM): 23 When creating the DOMTree DOM for srcset attributes, 24 create link elements for the link values of attribute value. 25 1 26 2015-10-21 Devin Rousso <dcrousso+webkit@gmail.com> 2 27 -
trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js
r189190 r191421 66 66 delete state._linkQuoteCharacter; 67 67 delete state._linkBaseStyle; 68 delete state._srcSetTokenizeState; 68 69 69 70 return style; 71 } 72 73 function tokenizeSrcSetString(stream, state) 74 { 75 console.assert(state._linkQuoteCharacter !== undefined); 76 77 if (state._srcSetTokenizeState === "link") { 78 // Eat the string until a space, comma, or ending quote. 79 // If this is unquoted, then eat until whitespace or common parse errors. 80 if (state._linkQuoteCharacter) 81 stream.eatWhile(new RegExp("[^\\s," + state._linkQuoteCharacter + "]")); 82 else 83 stream.eatWhile(/[^\s,\u00a0=<>\"\']/); 84 } else { 85 // Eat the string until a comma, or ending quote. 86 // If this is unquoted, then eat until whitespace or common parse errors. 87 stream.eatSpace(); 88 if (state._linkQuoteCharacter) 89 stream.eatWhile(new RegExp("[^," + state._linkQuoteCharacter + "]")); 90 else 91 stream.eatWhile(/[^\s\u00a0=<>\"\',]/); 92 stream.eatWhile(/[\s,]/); 93 } 94 95 // If the stream isn't at the end of line and we found the end quote 96 // change _linkTokenize to parse the end of the link next. Otherwise 97 // _linkTokenize will stay as-is to parse more of the srcset. 98 if (!stream.eol() && (!state._linkQuoteCharacter || stream.peek() === state._linkQuoteCharacter)) 99 state._linkTokenize = tokenizeEndOfLinkString; 100 101 // Link portion. 102 if (state._srcSetTokenizeState === "link") { 103 state._srcSetTokenizeState = "descriptor"; 104 return "link"; 105 } 106 107 // Descriptor portion. 108 state._srcSetTokenizeState = "link"; 109 return state._linkBaseStyle; 70 110 } 71 111 … … 87 127 if (text === "href" || text === "src") 88 128 state._expectLink = true; 89 else 129 else if (text === "srcset") 130 state._expectSrcSet = true; 131 else { 90 132 delete state._expectLink; 133 delete state._expectSrcSet; 134 } 91 135 } else if (state._expectLink && style === "string") { 92 136 var current = stream.current(); … … 99 143 // This is a link, so setup the state to process it next. 100 144 state._linkTokenize = tokenizeLinkString; 145 state._linkBaseStyle = style; 146 147 // The attribute should be quoted. 148 var quote = current[0]; 149 150 state._linkQuoteCharacter = quote === "'" || quote === "\"" ? quote : null; 151 152 // Rewind the stream to the start of this token. 153 stream.pos = startPosition; 154 155 // Eat the open quote of the string so the string style 156 // will be used for the quote character. 157 if (state._linkQuoteCharacter) 158 stream.eat(state._linkQuoteCharacter); 159 } 160 } else if (state._expectSrcSet && style === "string") { 161 var current = stream.current(); 162 163 // Unless current token is empty quotes, consume quote character 164 // and tokenize link next. 165 if (current !== "\"\"" && current !== "''") { 166 delete state._expectSrcSet; 167 168 // This is a link, so setup the state to process it next. 169 state._srcSetTokenizeState = "link"; 170 state._linkTokenize = tokenizeSrcSetString; 101 171 state._linkBaseStyle = style; 102 172 … … 119 189 // another token before a string then we stop expecting a link. 120 190 delete state._expectLink; 191 delete state._expectSrcSet; 121 192 } 122 193 -
trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js
r190286 r191421 1110 1110 attrSpanElement.appendChild(attrValueElement); 1111 1111 } 1112 } else if (name === "srcset") { 1113 let baseURL = node.ownerDocument ? node.ownerDocument.documentURL : null; 1114 attrValueElement = attrSpanElement.createChild("span", "html-attribute-value"); 1115 1116 let groups = value.split(/\s*,\s*/); 1117 for (let i = 0; i < groups.length; ++i) { 1118 let string = groups[i]; 1119 let spaceIndex = string.search(/\s/); 1120 1121 if (spaceIndex === -1) { 1122 let linkText = string; 1123 let rewrittenURL = absoluteURL(string, baseURL); 1124 let linkElement = attrValueElement.appendChild(document.createElement("a")); 1125 linkElement.href = rewrittenURL; 1126 linkElement.textContent = linkText.insertWordBreakCharacters(); 1127 } else { 1128 let linkText = string.substring(0, spaceIndex); 1129 let descriptorText = string.substring(spaceIndex).insertWordBreakCharacters(); 1130 let rewrittenURL = absoluteURL(linkText, baseURL); 1131 let linkElement = attrValueElement.appendChild(document.createElement("a")); 1132 linkElement.href = rewrittenURL; 1133 linkElement.textContent = linkText.insertWordBreakCharacters(); 1134 let descriptorElement = attrValueElement.appendChild(document.createElement("span")); 1135 descriptorElement.textContent = string.substring(spaceIndex); 1136 } 1137 1138 if (i < groups.length - 1) { 1139 let commaElement = attrValueElement.appendChild(document.createElement("span")); 1140 commaElement.textContent = ", "; 1141 } 1142 } 1112 1143 } else { 1113 1144 value = value.insertWordBreakCharacters();
Note:
See TracChangeset
for help on using the changeset viewer.