Title: [191421] trunk/Source/WebInspectorUI
- Revision
- 191421
- Author
- commit-qu...@webkit.org
- Date
- 2015-10-21 17:50:25 -0700 (Wed, 21 Oct 2015)
Log Message
Web Inspector: srcset attributes should have hyperlinks to the resources
https://bugs.webkit.org/show_bug.cgi?id=150409
Patch by Joseph Pecoraro <pecor...@apple.com> on 2015-10-21
Reviewed by Timothy Hatcher.
The "srcset" attribute parsing is a simplification of:
https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset
The "srcset" attribute value is expected to be in comma
separated groups. Within each group we always expect a link,
and an optional descriptor. We want to linkify the link.
* UserInterface/Views/CodeMirrorAdditions.js:
(tokenizeSrcSetString):
(extendedXMLToken):
When parsing srcset attribute, parse links as link tokens
so that they are linkified in resource content views.
* UserInterface/Views/DOMTreeElement.js:
(WebInspector.DOMTreeElement.prototype._buildAttributeDOM):
When creating the DOMTree DOM for srcset attributes,
create link elements for the link values of attribute value.
Modified Paths
Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (191420 => 191421)
--- trunk/Source/WebInspectorUI/ChangeLog 2015-10-22 00:46:20 UTC (rev 191420)
+++ trunk/Source/WebInspectorUI/ChangeLog 2015-10-22 00:50:25 UTC (rev 191421)
@@ -1,3 +1,28 @@
+2015-10-21 Joseph Pecoraro <pecor...@apple.com>
+
+ Web Inspector: srcset attributes should have hyperlinks to the resources
+ https://bugs.webkit.org/show_bug.cgi?id=150409
+
+ Reviewed by Timothy Hatcher.
+
+ The "srcset" attribute parsing is a simplification of:
+ https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset
+
+ The "srcset" attribute value is expected to be in comma
+ separated groups. Within each group we always expect a link,
+ and an optional descriptor. We want to linkify the link.
+
+ * UserInterface/Views/CodeMirrorAdditions.js:
+ (tokenizeSrcSetString):
+ (extendedXMLToken):
+ When parsing srcset attribute, parse links as link tokens
+ so that they are linkified in resource content views.
+
+ * UserInterface/Views/DOMTreeElement.js:
+ (WebInspector.DOMTreeElement.prototype._buildAttributeDOM):
+ When creating the DOMTree DOM for srcset attributes,
+ create link elements for the link values of attribute value.
+
2015-10-21 Devin Rousso <dcrousso+web...@gmail.com>
Web Inspector: Autocompletion previews in the CSS sidebar do not apply
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js (191420 => 191421)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js 2015-10-22 00:46:20 UTC (rev 191420)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js 2015-10-22 00:50:25 UTC (rev 191421)
@@ -65,10 +65,50 @@
delete state._linkTokenize;
delete state._linkQuoteCharacter;
delete state._linkBaseStyle;
+ delete state._srcSetTokenizeState;
return style;
}
+ function tokenizeSrcSetString(stream, state)
+ {
+ console.assert(state._linkQuoteCharacter !== undefined);
+
+ if (state._srcSetTokenizeState === "link") {
+ // Eat the string until a space, comma, or ending quote.
+ // If this is unquoted, then eat until whitespace or common parse errors.
+ if (state._linkQuoteCharacter)
+ stream.eatWhile(new RegExp("[^\\s," + state._linkQuoteCharacter + "]"));
+ else
+ stream.eatWhile(/[^\s,\u00a0=<>\"\']/);
+ } else {
+ // Eat the string until a comma, or ending quote.
+ // If this is unquoted, then eat until whitespace or common parse errors.
+ stream.eatSpace();
+ if (state._linkQuoteCharacter)
+ stream.eatWhile(new RegExp("[^," + state._linkQuoteCharacter + "]"));
+ else
+ stream.eatWhile(/[^\s\u00a0=<>\"\',]/);
+ stream.eatWhile(/[\s,]/);
+ }
+
+ // If the stream isn't at the end of line and we found the end quote
+ // change _linkTokenize to parse the end of the link next. Otherwise
+ // _linkTokenize will stay as-is to parse more of the srcset.
+ if (!stream.eol() && (!state._linkQuoteCharacter || stream.peek() === state._linkQuoteCharacter))
+ state._linkTokenize = tokenizeEndOfLinkString;
+
+ // Link portion.
+ if (state._srcSetTokenizeState === "link") {
+ state._srcSetTokenizeState = "descriptor";
+ return "link";
+ }
+
+ // Descriptor portion.
+ state._srcSetTokenizeState = "link";
+ return state._linkBaseStyle;
+ }
+
function extendedXMLToken(stream, state)
{
if (state._linkTokenize) {
@@ -86,8 +126,12 @@
var text = stream.current().toLowerCase();
if (text === "href" || text === "src")
state._expectLink = true;
- else
+ else if (text === "srcset")
+ state._expectSrcSet = true;
+ else {
delete state._expectLink;
+ delete state._expectSrcSet;
+ }
} else if (state._expectLink && style === "string") {
var current = stream.current();
@@ -100,6 +144,32 @@
state._linkTokenize = tokenizeLinkString;
state._linkBaseStyle = style;
+ // The attribute should be quoted.
+ var quote = current[0];
+
+ state._linkQuoteCharacter = quote === "'" || quote === "\"" ? quote : null;
+
+ // Rewind the stream to the start of this token.
+ stream.pos = startPosition;
+
+ // Eat the open quote of the string so the string style
+ // will be used for the quote character.
+ if (state._linkQuoteCharacter)
+ stream.eat(state._linkQuoteCharacter);
+ }
+ } else if (state._expectSrcSet && style === "string") {
+ var current = stream.current();
+
+ // Unless current token is empty quotes, consume quote character
+ // and tokenize link next.
+ if (current !== "\"\"" && current !== "''") {
+ delete state._expectSrcSet;
+
+ // This is a link, so setup the state to process it next.
+ state._srcSetTokenizeState = "link";
+ state._linkTokenize = tokenizeSrcSetString;
+ state._linkBaseStyle = style;
+
// The attribute may or may not be quoted.
var quote = current[0];
@@ -118,6 +188,7 @@
// spaces and the equal character are not tokenized. So if we get
// another token before a string then we stop expecting a link.
delete state._expectLink;
+ delete state._expectSrcSet;
}
return style && (style + " m-" + this.name);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js (191420 => 191421)
--- trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js 2015-10-22 00:46:20 UTC (rev 191420)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js 2015-10-22 00:50:25 UTC (rev 191421)
@@ -1109,6 +1109,37 @@
attrValueElement.textContent = value;
attrSpanElement.appendChild(attrValueElement);
}
+ } else if (name === "srcset") {
+ let baseURL = node.ownerDocument ? node.ownerDocument.documentURL : null;
+ attrValueElement = attrSpanElement.createChild("span", "html-attribute-value");
+
+ let groups = value.split(/\s*,\s*/);
+ for (let i = 0; i < groups.length; ++i) {
+ let string = groups[i];
+ let spaceIndex = string.search(/\s/);
+
+ if (spaceIndex === -1) {
+ let linkText = string;
+ let rewrittenURL = absoluteURL(string, baseURL);
+ let linkElement = attrValueElement.appendChild(document.createElement("a"));
+ linkElement.href = ""
+ linkElement.textContent = linkText.insertWordBreakCharacters();
+ } else {
+ let linkText = string.substring(0, spaceIndex);
+ let descriptorText = string.substring(spaceIndex).insertWordBreakCharacters();
+ let rewrittenURL = absoluteURL(linkText, baseURL);
+ let linkElement = attrValueElement.appendChild(document.createElement("a"));
+ linkElement.href = ""
+ linkElement.textContent = linkText.insertWordBreakCharacters();
+ let descriptorElement = attrValueElement.appendChild(document.createElement("span"));
+ descriptorElement.textContent = string.substring(spaceIndex);
+ }
+
+ if (i < groups.length - 1) {
+ let commaElement = attrValueElement.appendChild(document.createElement("span"));
+ commaElement.textContent = ", ";
+ }
+ }
} else {
value = value.insertWordBreakCharacters();
attrValueElement = attrSpanElement.createChild("span", "html-attribute-value");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes