OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 this._elementStateButton.title = WebInspector.UIString("Toggle Element State
"); | 42 this._elementStateButton.title = WebInspector.UIString("Toggle Element State
"); |
43 this._elementStateButton.addEventListener("click", this._toggleElementStateP
ane.bind(this), false); | 43 this._elementStateButton.addEventListener("click", this._toggleElementStateP
ane.bind(this), false); |
44 this.titleElement.appendChild(this._elementStateButton); | 44 this.titleElement.appendChild(this._elementStateButton); |
45 | 45 |
46 var addButton = document.createElement("button"); | 46 var addButton = document.createElement("button"); |
47 addButton.className = "pane-title-button add"; | 47 addButton.className = "pane-title-button add"; |
48 addButton.id = "add-style-button-test-id"; | 48 addButton.id = "add-style-button-test-id"; |
49 addButton.title = WebInspector.UIString("New Style Rule"); | 49 addButton.title = WebInspector.UIString("New Style Rule"); |
50 addButton.addEventListener("click", this._createNewRuleInViaInspectorStyleSh
eet.bind(this), false); | 50 addButton.addEventListener("click", this._createNewRuleInViaInspectorStyleSh
eet.bind(this), false); |
51 this.titleElement.appendChild(addButton); | 51 this.titleElement.appendChild(addButton); |
| 52 addButton.createChild("div", "long-click-glyph fill"); |
| 53 |
| 54 this._addButtonLongClickController = new WebInspector.LongClickController(ad
dButton); |
| 55 this._addButtonLongClickController.addEventListener(WebInspector.LongClickCo
ntroller.Events.LongClick, this._onAddButtonLongClick.bind(this)); |
| 56 this._addButtonLongClickController.enable(); |
52 | 57 |
53 this._computedStylePane = computedStylePane; | 58 this._computedStylePane = computedStylePane; |
54 computedStylePane.setHostingPane(this); | 59 computedStylePane.setHostingPane(this); |
55 this._setPseudoClassCallback = setPseudoClassCallback; | 60 this._setPseudoClassCallback = setPseudoClassCallback; |
56 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin
d(this), true); | 61 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin
d(this), true); |
57 WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSetting
Changed.bind(this)); | 62 WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSetting
Changed.bind(this)); |
58 WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAg
entStylesSettingChanged.bind(this)); | 63 WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAg
entStylesSettingChanged.bind(this)); |
59 | 64 |
60 this._createElementStatePane(); | 65 this._createElementStatePane(); |
61 this.bodyElement.appendChild(this._elementStatePane); | 66 this.bodyElement.appendChild(this._elementStatePane); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (value.endsWith("\9")) | 162 if (value.endsWith("\9")) |
158 return true; | 163 return true; |
159 if (hasUnknownVendorPrefix(value)) | 164 if (hasUnknownVendorPrefix(value)) |
160 return true; | 165 return true; |
161 | 166 |
162 return false; | 167 return false; |
163 } | 168 } |
164 | 169 |
165 WebInspector.StylesSidebarPane.prototype = { | 170 WebInspector.StylesSidebarPane.prototype = { |
166 /** | 171 /** |
| 172 * @param {!WebInspector.Event} event |
| 173 */ |
| 174 _onAddButtonLongClick: function(event) |
| 175 { |
| 176 this._addButtonLongClickController.reset(); |
| 177 var cssModel = this._target.cssModel; |
| 178 var headers = cssModel.styleSheetHeaders().filter(styleSheetResourceHead
er); |
| 179 |
| 180 /** @type {!Array.<{text: string, handler: function()}>} */ |
| 181 var contextMenuDescriptors = []; |
| 182 for (var i = 0; i < headers.length; ++i) { |
| 183 var header = headers[i]; |
| 184 var handler = this._createNewRuleInStyleSheet.bind(this, header); |
| 185 contextMenuDescriptors.push({ |
| 186 text: WebInspector.displayNameForURL(header.resourceURL()), |
| 187 handler: handler |
| 188 }); |
| 189 } |
| 190 |
| 191 contextMenuDescriptors.sort(compareDescriptors); |
| 192 |
| 193 var contextMenu = new WebInspector.ContextMenu(/** @type {!Event} */(eve
nt.data)); |
| 194 for (var i = 0; i < contextMenuDescriptors.length; ++i) { |
| 195 var descriptor = contextMenuDescriptors[i]; |
| 196 contextMenu.appendItem(descriptor.text, descriptor.handler); |
| 197 } |
| 198 if (!contextMenu.isEmpty()) |
| 199 contextMenu.appendSeparator(); |
| 200 contextMenu.appendItem("inspector-stylesheet", this._createNewRuleInViaI
nspectorStyleSheet.bind(this)); |
| 201 contextMenu.show(); |
| 202 |
| 203 /** |
| 204 * @param {!{text: string, handler: function()}} descriptor1 |
| 205 * @param {!{text: string, handler: function()}} descriptor2 |
| 206 * @return {number} |
| 207 */ |
| 208 function compareDescriptors(descriptor1, descriptor2) |
| 209 { |
| 210 return String.naturalOrderComparator(descriptor1.text, descriptor2.t
ext); |
| 211 } |
| 212 |
| 213 /** |
| 214 * @param {!WebInspector.CSSStyleSheetHeader} header |
| 215 */ |
| 216 function styleSheetResourceHeader(header) |
| 217 { |
| 218 return !header.isViaInspector() && !header.isInline && header.resour
ceURL(); |
| 219 } |
| 220 }, |
| 221 |
| 222 /** |
167 * @param {!WebInspector.DOMNode} node | 223 * @param {!WebInspector.DOMNode} node |
168 */ | 224 */ |
169 updateEditingSelectorForNode: function(node) | 225 updateEditingSelectorForNode: function(node) |
170 { | 226 { |
171 var selectorText = WebInspector.DOMPresentationUtils.simpleSelector(node
); | 227 var selectorText = WebInspector.DOMPresentationUtils.simpleSelector(node
); |
172 if (!selectorText) | 228 if (!selectorText) |
173 return; | 229 return; |
174 this._editingSelectorSection.setSelectorText(selectorText); | 230 this._editingSelectorSection.setSelectorText(selectorText); |
175 }, | 231 }, |
176 | 232 |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 for (var i = 0; i < sections.length; ++i) | 879 for (var i = 0; i < sections.length; ++i) |
824 sections[i].update(true); | 880 sections[i].update(true); |
825 } | 881 } |
826 }, | 882 }, |
827 | 883 |
828 /** | 884 /** |
829 * @param {?Event} event | 885 * @param {?Event} event |
830 */ | 886 */ |
831 _createNewRuleInViaInspectorStyleSheet: function(event) | 887 _createNewRuleInViaInspectorStyleSheet: function(event) |
832 { | 888 { |
833 event.consume(); | |
834 var cssModel = this._target.cssModel; | 889 var cssModel = this._target.cssModel; |
835 cssModel.requestViaInspectorStylesheet(this._node, viaInspectorCallback.
bind(this)); | 890 cssModel.requestViaInspectorStylesheet(this._node, this._createNewRuleIn
StyleSheet.bind(this)); |
| 891 }, |
836 | 892 |
837 /** | 893 /** |
838 * @param {?WebInspector.CSSStyleSheetHeader} styleSheetHeader | 894 * @param {?WebInspector.CSSStyleSheetHeader} styleSheetHeader |
839 * @this {WebInspector.StylesSidebarPane} | 895 */ |
840 */ | 896 _createNewRuleInStyleSheet: function(styleSheetHeader) |
841 function viaInspectorCallback(styleSheetHeader) | 897 { |
842 { | 898 if (!styleSheetHeader) |
843 if (!styleSheetHeader) | 899 return; |
844 return; | 900 styleSheetHeader.requestContent(onStyleSheetContent.bind(this, styleShee
tHeader.id)); |
845 styleSheetHeader.requestContent(onViaInspectorContent.bind(this, sty
leSheetHeader.id)); | |
846 } | |
847 | 901 |
848 /** | 902 /** |
849 * @param {string} styleSheetId | 903 * @param {string} styleSheetId |
850 * @param {string} text | 904 * @param {string} text |
851 * @this {WebInspector.StylesSidebarPane} | 905 * @this {WebInspector.StylesSidebarPane} |
852 */ | 906 */ |
853 function onViaInspectorContent(styleSheetId, text) | 907 function onStyleSheetContent(styleSheetId, text) |
854 { | 908 { |
855 var lines = text.split("\n"); | 909 var lines = text.split("\n"); |
856 var range = WebInspector.TextRange.createFromLocation(lines.length -
1, lines[lines.length - 1].length); | 910 var range = WebInspector.TextRange.createFromLocation(lines.length -
1, lines[lines.length - 1].length); |
857 this._addBlankSection(this.sections[0][1], styleSheetId, range); | 911 this._addBlankSection(this.sections[0][1], styleSheetId, range); |
858 } | 912 } |
859 }, | 913 }, |
860 | 914 |
861 /** | 915 /** |
862 * @param {!WebInspector.StylePropertiesSection} insertAfterSection | 916 * @param {!WebInspector.StylePropertiesSection} insertAfterSection |
863 * @param {string} styleSheetId | 917 * @param {string} styleSheetId |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 { | 1288 { |
1235 if (!this.rule || !this.rule.styleSheetId) | 1289 if (!this.rule || !this.rule.styleSheetId) |
1236 return; | 1290 return; |
1237 if (this.rule !== editedRule) | 1291 if (this.rule !== editedRule) |
1238 this.rule.sourceStyleSheetEdited(editedRule.styleSheetId, oldRange,
newRange); | 1292 this.rule.sourceStyleSheetEdited(editedRule.styleSheetId, oldRange,
newRange); |
1239 this._updateMediaList(); | 1293 this._updateMediaList(); |
1240 this._updateRuleOrigin(); | 1294 this._updateRuleOrigin(); |
1241 }, | 1295 }, |
1242 | 1296 |
1243 /** | 1297 /** |
1244 * @param {!Object} styleRule | 1298 * @param {?Array.<!WebInspector.CSSMedia>} mediaRules |
1245 */ | 1299 */ |
1246 _createMediaList: function(styleRule) | 1300 _createMediaList: function(mediaRules) |
1247 { | 1301 { |
1248 if (!styleRule.media) | 1302 if (!mediaRules) |
1249 return; | 1303 return; |
1250 for (var i = styleRule.media.length - 1; i >= 0; --i) { | 1304 for (var i = mediaRules.length - 1; i >= 0; --i) { |
1251 var media = styleRule.media[i]; | 1305 var media = mediaRules[i]; |
1252 var mediaDataElement = this._mediaListElement.createChild("div", "me
dia"); | 1306 var mediaDataElement = this._mediaListElement.createChild("div", "me
dia"); |
1253 var mediaText; | 1307 var mediaText; |
1254 switch (media.source) { | 1308 switch (media.source) { |
1255 case WebInspector.CSSMedia.Source.LINKED_SHEET: | 1309 case WebInspector.CSSMedia.Source.LINKED_SHEET: |
1256 case WebInspector.CSSMedia.Source.INLINE_SHEET: | 1310 case WebInspector.CSSMedia.Source.INLINE_SHEET: |
1257 mediaText = "media=\"" + media.text + "\""; | 1311 mediaText = "media=\"" + media.text + "\""; |
1258 break; | 1312 break; |
1259 case WebInspector.CSSMedia.Source.MEDIA_RULE: | 1313 case WebInspector.CSSMedia.Source.MEDIA_RULE: |
1260 mediaText = "@media " + media.text; | 1314 mediaText = "@media " + media.text; |
1261 break; | 1315 break; |
(...skipping 11 matching lines...) Expand all Loading... |
1273 | 1327 |
1274 var mediaTextElement = mediaDataElement.createChild("span"); | 1328 var mediaTextElement = mediaDataElement.createChild("span"); |
1275 mediaTextElement.textContent = mediaText; | 1329 mediaTextElement.textContent = mediaText; |
1276 mediaTextElement.title = media.text; | 1330 mediaTextElement.title = media.text; |
1277 } | 1331 } |
1278 }, | 1332 }, |
1279 | 1333 |
1280 _updateMediaList: function() | 1334 _updateMediaList: function() |
1281 { | 1335 { |
1282 this._mediaListElement.removeChildren(); | 1336 this._mediaListElement.removeChildren(); |
1283 this._createMediaList(this.styleRule); | 1337 this._createMediaList(this.styleRule.media); |
1284 }, | 1338 }, |
1285 | 1339 |
1286 collapse: function() | 1340 collapse: function() |
1287 { | 1341 { |
1288 // Overriding with empty body. | 1342 // Overriding with empty body. |
1289 }, | 1343 }, |
1290 | 1344 |
1291 handleClick: function() | 1345 handleClick: function() |
1292 { | 1346 { |
1293 // Avoid consuming events. | 1347 // Avoid consuming events. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 return item; | 1620 return item; |
1567 }, | 1621 }, |
1568 | 1622 |
1569 /** | 1623 /** |
1570 * @param {?WebInspector.CSSRule} rule | 1624 * @param {?WebInspector.CSSRule} rule |
1571 * @param {!WebInspector.TextRange=} ruleLocation | 1625 * @param {!WebInspector.TextRange=} ruleLocation |
1572 * @return {!Node} | 1626 * @return {!Node} |
1573 */ | 1627 */ |
1574 _createRuleOriginNode: function(rule, ruleLocation) | 1628 _createRuleOriginNode: function(rule, ruleLocation) |
1575 { | 1629 { |
1576 /** | |
1577 * @param {string} url | |
1578 * @param {number} line | |
1579 */ | |
1580 function linkifyUncopyable(url, line) | |
1581 { | |
1582 var link = WebInspector.linkifyResourceAsNode(url, line, "", url + "
:" + (line + 1)); | |
1583 link.classList.add("webkit-html-resource-link"); | |
1584 link.setAttribute("data-uncopyable", link.textContent); | |
1585 link.textContent = ""; | |
1586 return link; | |
1587 } | |
1588 | |
1589 if (!rule) | 1630 if (!rule) |
1590 return document.createTextNode(""); | 1631 return document.createTextNode(""); |
1591 | 1632 |
1592 if (!ruleLocation) { | 1633 if (!ruleLocation) { |
1593 var firstMatchingIndex = rule.matchingSelectors && rule.matchingSele
ctors.length ? rule.matchingSelectors[0] : 0; | 1634 var firstMatchingIndex = rule.matchingSelectors && rule.matchingSele
ctors.length ? rule.matchingSelectors[0] : 0; |
1594 ruleLocation = rule.selectors[firstMatchingIndex].range; | 1635 ruleLocation = rule.selectors[firstMatchingIndex].range; |
1595 } | 1636 } |
1596 | 1637 |
1597 var sourceURL = rule.resourceURL(); | 1638 if (ruleLocation && rule.styleSheetId) |
1598 if (sourceURL && ruleLocation && rule.styleSheetId) { | 1639 return this._linkifyRuleLocation(rule.styleSheetId, ruleLocation); |
1599 var styleSheetHeader = this._parentPane._target.cssModel.styleSheetH
eaderForId(rule.styleSheetId); | |
1600 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.st
artLine); | |
1601 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocatio
n.startLine, ruleLocation.startColumn); | |
1602 var matchingSelectorLocation = new WebInspector.CSSLocation(this._pa
rentPane._target, rule.styleSheetId, sourceURL, lineNumber, columnNumber); | |
1603 return this._parentPane._linkifier.linkifyCSSLocation(matchingSelect
orLocation) || linkifyUncopyable(sourceURL, 0); | |
1604 } | |
1605 | 1640 |
1606 if (rule.isUserAgent) | 1641 if (rule.isUserAgent) |
1607 return document.createTextNode(WebInspector.UIString("user agent sty
lesheet")); | 1642 return document.createTextNode(WebInspector.UIString("user agent sty
lesheet")); |
1608 if (rule.isUser) | 1643 if (rule.isUser) |
1609 return document.createTextNode(WebInspector.UIString("user styleshee
t")); | 1644 return document.createTextNode(WebInspector.UIString("user styleshee
t")); |
1610 if (rule.isViaInspector) | 1645 if (rule.isViaInspector) |
1611 return this._createRuleViaInspectorOriginNode(); | 1646 return document.createTextNode(WebInspector.UIString("via inspector"
)); |
1612 return document.createTextNode(""); | 1647 return document.createTextNode(""); |
1613 }, | 1648 }, |
1614 | 1649 |
1615 /** | 1650 /** |
| 1651 * @param {string} styleSheetId |
| 1652 * @param {!WebInspector.TextRange} ruleLocation |
1616 * @return {!Node} | 1653 * @return {!Node} |
1617 */ | 1654 */ |
1618 _createRuleViaInspectorOriginNode: function() | 1655 _linkifyRuleLocation: function(styleSheetId, ruleLocation) |
1619 { | 1656 { |
1620 return document.createTextNode(WebInspector.UIString("via inspector")); | 1657 /** |
| 1658 * @param {string} url |
| 1659 * @param {number} line |
| 1660 */ |
| 1661 function linkifyUncopyable(url, line) |
| 1662 { |
| 1663 var link = WebInspector.linkifyResourceAsNode(url, line, "", url + "
:" + (line + 1)); |
| 1664 link.classList.add("webkit-html-resource-link"); |
| 1665 link.setAttribute("data-uncopyable", link.textContent); |
| 1666 link.textContent = ""; |
| 1667 return link; |
| 1668 } |
| 1669 |
| 1670 var styleSheetHeader = this._parentPane._target.cssModel.styleSheetHeade
rForId(styleSheetId); |
| 1671 var sourceURL = styleSheetHeader.resourceURL(); |
| 1672 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startL
ine); |
| 1673 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.st
artLine, ruleLocation.startColumn); |
| 1674 var matchingSelectorLocation = new WebInspector.CSSLocation(this._parent
Pane._target, styleSheetId, sourceURL, lineNumber, columnNumber); |
| 1675 return this._parentPane._linkifier.linkifyCSSLocation(matchingSelectorLo
cation) || linkifyUncopyable(sourceURL, 0); |
1621 }, | 1676 }, |
1622 | 1677 |
1623 _handleEmptySpaceMouseDown: function() | 1678 _handleEmptySpaceMouseDown: function() |
1624 { | 1679 { |
1625 this._willCauseCancelEditing = this._parentPane._isEditingStyle; | 1680 this._willCauseCancelEditing = this._parentPane._isEditingStyle; |
1626 }, | 1681 }, |
1627 | 1682 |
1628 _handleEmptySpaceClick: function(event) | 1683 _handleEmptySpaceClick: function(event) |
1629 { | 1684 { |
1630 if (!this.editable) | 1685 if (!this.editable) |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1972 * @param {!WebInspector.TextRange} ruleLocation | 2027 * @param {!WebInspector.TextRange} ruleLocation |
1973 * @param {!WebInspector.CSSRule=} insertAfterRule | 2028 * @param {!WebInspector.CSSRule=} insertAfterRule |
1974 */ | 2029 */ |
1975 WebInspector.BlankStylePropertiesSection = function(stylesPane, defaultSelectorT
ext, styleSheetId, ruleLocation, insertAfterRule) | 2030 WebInspector.BlankStylePropertiesSection = function(stylesPane, defaultSelectorT
ext, styleSheetId, ruleLocation, insertAfterRule) |
1976 { | 2031 { |
1977 var styleSheetHeader = WebInspector.cssModel.styleSheetHeaderForId(styleShee
tId); | 2032 var styleSheetHeader = WebInspector.cssModel.styleSheetHeaderForId(styleShee
tId); |
1978 WebInspector.StylePropertiesSection.call(this, stylesPane, { selectorText: d
efaultSelectorText }, true, false); | 2033 WebInspector.StylePropertiesSection.call(this, stylesPane, { selectorText: d
efaultSelectorText }, true, false); |
1979 this._ruleLocation = ruleLocation; | 2034 this._ruleLocation = ruleLocation; |
1980 this._styleSheetId = styleSheetId; | 2035 this._styleSheetId = styleSheetId; |
1981 this._selectorRefElement.removeChildren(); | 2036 this._selectorRefElement.removeChildren(); |
1982 if (insertAfterRule) { | 2037 this._selectorRefElement.appendChild(this._linkifyRuleLocation(styleSheetId,
this._actualRuleLocation())); |
1983 this._selectorRefElement.appendChild(this._createRuleOriginNode(insertAf
terRule, this._actualRuleLocation())); | 2038 if (insertAfterRule) |
1984 this._createMediaList(insertAfterRule); | 2039 this._createMediaList(insertAfterRule.media); |
1985 } else { | |
1986 this._selectorRefElement.appendChild(this._createRuleViaInspectorOriginN
ode()); | |
1987 } | |
1988 this.element.classList.add("blank-section"); | 2040 this.element.classList.add("blank-section"); |
1989 } | 2041 } |
1990 | 2042 |
1991 WebInspector.BlankStylePropertiesSection.prototype = { | 2043 WebInspector.BlankStylePropertiesSection.prototype = { |
1992 /** | 2044 /** |
1993 * @return {!WebInspector.TextRange} | 2045 * @return {!WebInspector.TextRange} |
1994 */ | 2046 */ |
1995 _actualRuleLocation: function() | 2047 _actualRuleLocation: function() |
1996 { | 2048 { |
1997 var prefix = this._rulePrefix(); | 2049 var prefix = this._rulePrefix(); |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3465 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase(
))) { | 3517 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase(
))) { |
3466 for (var i = 0; i < results.length; ++i) | 3518 for (var i = 0; i < results.length; ++i) |
3467 results[i] = results[i].toUpperCase(); | 3519 results[i] = results[i].toUpperCase(); |
3468 } | 3520 } |
3469 var selectedIndex = this._cssCompletions.mostUsedOf(results); | 3521 var selectedIndex = this._cssCompletions.mostUsedOf(results); |
3470 completionsReadyCallback(results, selectedIndex); | 3522 completionsReadyCallback(results, selectedIndex); |
3471 }, | 3523 }, |
3472 | 3524 |
3473 __proto__: WebInspector.TextPrompt.prototype | 3525 __proto__: WebInspector.TextPrompt.prototype |
3474 } | 3526 } |
OLD | NEW |