Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: Source/devtools/front_end/elements/StylesSidebarPane.js

Issue 662793002: [DevTools] Replace usages of document with custom functions. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 /** 30 /**
31 * @constructor 31 * @constructor
32 * @extends {WebInspector.SidebarPane} 32 * @extends {WebInspector.SidebarPane}
33 * @param {!WebInspector.ComputedStyleSidebarPane} computedStylePane 33 * @param {!WebInspector.ComputedStyleSidebarPane} computedStylePane
34 * @param {function(!WebInspector.DOMNode, string, boolean)=} setPseudoClassCall back 34 * @param {function(!WebInspector.DOMNode, string, boolean)=} setPseudoClassCall back
35 */ 35 */
36 WebInspector.StylesSidebarPane = function(computedStylePane, setPseudoClassCallb ack) 36 WebInspector.StylesSidebarPane = function(computedStylePane, setPseudoClassCallb ack)
37 { 37 {
38 WebInspector.SidebarPane.call(this, WebInspector.UIString("Styles")); 38 WebInspector.SidebarPane.call(this, WebInspector.UIString("Styles"));
39 39
40 this._elementStateButton = document.createElement("button"); 40 this._elementStateButton = createElement("button");
41 this._elementStateButton.className = "pane-title-button element-state"; 41 this._elementStateButton.className = "pane-title-button element-state";
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 = 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"); 52 addButton.createChild("div", "long-click-glyph fill");
53 53
54 this._addButtonLongClickController = new WebInspector.LongClickController(ad dButton); 54 this._addButtonLongClickController = new WebInspector.LongClickController(ad dButton);
55 this._addButtonLongClickController.addEventListener(WebInspector.LongClickCo ntroller.Events.LongClick, this._onAddButtonLongClick.bind(this)); 55 this._addButtonLongClickController.addEventListener(WebInspector.LongClickCo ntroller.Events.LongClick, this._onAddButtonLongClick.bind(this));
56 this._addButtonLongClickController.enable(); 56 this._addButtonLongClickController.enable();
57 57
58 this._computedStylePane = computedStylePane; 58 this._computedStylePane = computedStylePane;
59 computedStylePane.setHostingPane(this); 59 computedStylePane.setHostingPane(this);
60 this._setPseudoClassCallback = setPseudoClassCallback; 60 this._setPseudoClassCallback = setPseudoClassCallback;
61 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin d(this), true); 61 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin d(this), true);
62 WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSetting Changed.bind(this)); 62 WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSetting Changed.bind(this));
63 WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAg entStylesSettingChanged.bind(this)); 63 WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAg entStylesSettingChanged.bind(this));
64 64
65 this._createElementStatePane(); 65 this._createElementStatePane();
66 this.bodyElement.appendChild(this._elementStatePane); 66 this.bodyElement.appendChild(this._elementStatePane);
67 this._sectionsContainer = document.createElement("div"); 67 this._sectionsContainer = createElement("div");
68 this.bodyElement.appendChild(this._sectionsContainer); 68 this.bodyElement.appendChild(this._sectionsContainer);
69 69
70 this._spectrumHelper = new WebInspector.SpectrumPopupHelper(); 70 this._spectrumHelper = new WebInspector.SpectrumPopupHelper();
71 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter()); 71 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter());
72 72
73 this.element.classList.add("styles-pane"); 73 this.element.classList.add("styles-pane");
74 this.element.classList.toggle("show-user-styles", WebInspector.settings.show UserAgentStyles.get()); 74 this.element.classList.toggle("show-user-styles", WebInspector.settings.show UserAgentStyles.get());
75 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false); 75 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false);
76 document.body.addEventListener("keydown", this._keyDown.bind(this), false); 76 document.body.addEventListener("keydown", this._keyDown.bind(this), false);
77 document.body.addEventListener("keyup", this._keyUp.bind(this), false); 77 document.body.addEventListener("keyup", this._keyUp.bind(this), false);
(...skipping 18 matching lines...) Expand all
96 SelectorEditingStarted: "SelectorEditingStarted", 96 SelectorEditingStarted: "SelectorEditingStarted",
97 SelectorEditingEnded: "SelectorEditingEnded" 97 SelectorEditingEnded: "SelectorEditingEnded"
98 }; 98 };
99 99
100 /** 100 /**
101 * @param {!WebInspector.CSSProperty} property 101 * @param {!WebInspector.CSSProperty} property
102 * @return {!Element} 102 * @return {!Element}
103 */ 103 */
104 WebInspector.StylesSidebarPane.createExclamationMark = function(property) 104 WebInspector.StylesSidebarPane.createExclamationMark = function(property)
105 { 105 {
106 var exclamationElement = document.createElement("div"); 106 var exclamationElement = createElement("div");
107 exclamationElement.className = "exclamation-mark" + (WebInspector.StylesSide barPane._ignoreErrorsForProperty(property) ? "" : " warning-icon-small"); 107 exclamationElement.className = "exclamation-mark" + (WebInspector.StylesSide barPane._ignoreErrorsForProperty(property) ? "" : " warning-icon-small");
108 exclamationElement.title = WebInspector.CSSMetadata.cssPropertiesMetainfo.ke ySet()[property.name.toLowerCase()] ? WebInspector.UIString("Invalid property va lue.") : WebInspector.UIString("Unknown property name."); 108 exclamationElement.title = WebInspector.CSSMetadata.cssPropertiesMetainfo.ke ySet()[property.name.toLowerCase()] ? WebInspector.UIString("Invalid property va lue.") : WebInspector.UIString("Unknown property name.");
109 return exclamationElement; 109 return exclamationElement;
110 } 110 }
111 111
112 /** 112 /**
113 * @param {!WebInspector.Color} color 113 * @param {!WebInspector.Color} color
114 */ 114 */
115 WebInspector.StylesSidebarPane._colorFormat = function(color) 115 WebInspector.StylesSidebarPane._colorFormat = function(color)
116 { 116 {
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 * @param {!Object.<string, boolean>} usedProperties 806 * @param {!Object.<string, boolean>} usedProperties
807 * @param {?Element} anchorElement 807 * @param {?Element} anchorElement
808 */ 808 */
809 _rebuildSectionsForStyleRules: function(styleRules, usedProperties, anchorEl ement) 809 _rebuildSectionsForStyleRules: function(styleRules, usedProperties, anchorEl ement)
810 { 810 {
811 // Make a property section for each style rule. 811 // Make a property section for each style rule.
812 var sections = []; 812 var sections = [];
813 for (var i = 0; i < styleRules.length; ++i) { 813 for (var i = 0; i < styleRules.length; ++i) {
814 var styleRule = styleRules[i]; 814 var styleRule = styleRules[i];
815 if (styleRule.isStyleSeparator) { 815 if (styleRule.isStyleSeparator) {
816 var separatorElement = document.createElement("div"); 816 var separatorElement = createElement("div");
817 if (styleRule.isPlaceholder) { 817 if (styleRule.isPlaceholder) {
818 separatorElement.className = "styles-sidebar-placeholder"; 818 separatorElement.className = "styles-sidebar-placeholder";
819 this._sectionsContainer.insertBefore(separatorElement, ancho rElement); 819 this._sectionsContainer.insertBefore(separatorElement, ancho rElement);
820 continue; 820 continue;
821 } 821 }
822 separatorElement.className = "sidebar-separator"; 822 separatorElement.className = "sidebar-separator";
823 if (styleRule.node) { 823 if (styleRule.node) {
824 var link = WebInspector.DOMPresentationUtils.linkifyNodeRefe rence(styleRule.node); 824 var link = WebInspector.DOMPresentationUtils.linkifyNodeRefe rence(styleRule.node);
825 separatorElement.createTextChild(WebInspector.UIString("Inhe rited from") + " "); 825 separatorElement.createTextChild(WebInspector.UIString("Inhe rited from") + " ");
826 separatorElement.appendChild(link); 826 separatorElement.appendChild(link);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 948
949 var buttonToggled = !this._elementStateButton.classList.contains("toggle d"); 949 var buttonToggled = !this._elementStateButton.classList.contains("toggle d");
950 if (buttonToggled) 950 if (buttonToggled)
951 this.expand(); 951 this.expand();
952 this._elementStateButton.classList.toggle("toggled", buttonToggled); 952 this._elementStateButton.classList.toggle("toggled", buttonToggled);
953 this._elementStatePane.classList.toggle("expanded", buttonToggled); 953 this._elementStatePane.classList.toggle("expanded", buttonToggled);
954 }, 954 },
955 955
956 _createElementStatePane: function() 956 _createElementStatePane: function()
957 { 957 {
958 this._elementStatePane = document.createElement("div"); 958 this._elementStatePane = createElement("div");
959 this._elementStatePane.className = "styles-element-state-pane source-cod e"; 959 this._elementStatePane.className = "styles-element-state-pane source-cod e";
960 var table = document.createElement("table"); 960 var table = createElement("table");
961 961
962 var inputs = []; 962 var inputs = [];
963 this._elementStatePane.inputs = inputs; 963 this._elementStatePane.inputs = inputs;
964 964
965 /** 965 /**
966 * @param {!Event} event 966 * @param {!Event} event
967 * @this {WebInspector.StylesSidebarPane} 967 * @this {WebInspector.StylesSidebarPane}
968 */ 968 */
969 function clickListener(event) 969 function clickListener(event)
970 { 970 {
971 var node = this._validateNode(); 971 var node = this._validateNode();
972 if (!node) 972 if (!node)
973 return; 973 return;
974 this._setPseudoClassCallback(node, event.target.state, event.target. checked); 974 this._setPseudoClassCallback(node, event.target.state, event.target. checked);
975 } 975 }
976 976
977 /** 977 /**
978 * @param {string} state 978 * @param {string} state
979 * @return {!Element} 979 * @return {!Element}
980 * @this {WebInspector.StylesSidebarPane} 980 * @this {WebInspector.StylesSidebarPane}
981 */ 981 */
982 function createCheckbox(state) 982 function createCheckbox(state)
983 { 983 {
984 var td = document.createElement("td"); 984 var td = createElement("td");
985 var label = document.createElement("label"); 985 var label = createElement("label");
986 var input = document.createElement("input"); 986 var input = createElement("input");
987 input.type = "checkbox"; 987 input.type = "checkbox";
988 input.state = state; 988 input.state = state;
989 input.addEventListener("click", clickListener.bind(this), false); 989 input.addEventListener("click", clickListener.bind(this), false);
990 inputs.push(input); 990 inputs.push(input);
991 label.appendChild(input); 991 label.appendChild(input);
992 label.createTextChild(":" + state); 992 label.createTextChild(":" + state);
993 td.appendChild(label); 993 td.appendChild(label);
994 return td; 994 return td;
995 } 995 }
996 996
(...skipping 16 matching lines...) Expand all
1013 return this._filterRegex; 1013 return this._filterRegex;
1014 }, 1014 },
1015 1015
1016 /** 1016 /**
1017 * @param {boolean} isComputedStyleFilter 1017 * @param {boolean} isComputedStyleFilter
1018 * @return {!Element} 1018 * @return {!Element}
1019 * @param {function(?RegExp)} filterCallback 1019 * @param {function(?RegExp)} filterCallback
1020 */ 1020 */
1021 _createPropertyFilterElement: function(isComputedStyleFilter, filterCallback ) 1021 _createPropertyFilterElement: function(isComputedStyleFilter, filterCallback )
1022 { 1022 {
1023 var input = document.createElement("input"); 1023 var input = createElement("input");
1024 input.type = "text"; 1024 input.type = "text";
1025 input.placeholder = isComputedStyleFilter ? WebInspector.UIString("Filte r") : WebInspector.UIString("Find in Styles"); 1025 input.placeholder = isComputedStyleFilter ? WebInspector.UIString("Filte r") : WebInspector.UIString("Find in Styles");
1026 var boundSearchHandler = searchHandler.bind(this); 1026 var boundSearchHandler = searchHandler.bind(this);
1027 1027
1028 /** 1028 /**
1029 * @this {WebInspector.StylesSidebarPane} 1029 * @this {WebInspector.StylesSidebarPane}
1030 */ 1030 */
1031 function searchHandler() 1031 function searchHandler()
1032 { 1032 {
1033 var regex = input.value ? new RegExp(input.value.escapeForRegExp(), "i") : null; 1033 var regex = input.value ? new RegExp(input.value.escapeForRegExp(), "i") : null;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 this.styleRule = styleRule; 1204 this.styleRule = styleRule;
1205 this.rule = this.styleRule.rule; 1205 this.rule = this.styleRule.rule;
1206 this.editable = editable; 1206 this.editable = editable;
1207 this.isInherited = isInherited; 1207 this.isInherited = isInherited;
1208 1208
1209 var extraClasses = (this.rule && (this.rule.isUser || this.rule.isUserAgent) ? " user-rule" : ""); 1209 var extraClasses = (this.rule && (this.rule.isUser || this.rule.isUserAgent) ? " user-rule" : "");
1210 this.element.className = "styles-section matched-styles monospace" + extraCl asses; 1210 this.element.className = "styles-section matched-styles monospace" + extraCl asses;
1211 // We don't really use properties' disclosure. 1211 // We don't really use properties' disclosure.
1212 this.propertiesElement.classList.remove("properties-tree"); 1212 this.propertiesElement.classList.remove("properties-tree");
1213 1213
1214 var selectorContainer = document.createElement("div"); 1214 var selectorContainer = createElement("div");
1215 this._selectorElement = document.createElement("span"); 1215 this._selectorElement = createElement("span");
1216 this._selectorElement.textContent = styleRule.selectorText; 1216 this._selectorElement.textContent = styleRule.selectorText;
1217 selectorContainer.appendChild(this._selectorElement); 1217 selectorContainer.appendChild(this._selectorElement);
1218 1218
1219 var openBrace = document.createElement("span"); 1219 var openBrace = createElement("span");
1220 openBrace.textContent = " {"; 1220 openBrace.textContent = " {";
1221 selectorContainer.appendChild(openBrace); 1221 selectorContainer.appendChild(openBrace);
1222 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false); 1222 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false);
1223 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false); 1223 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false);
1224 1224
1225 var closeBrace = document.createElement("div"); 1225 var closeBrace = createElement("div");
1226 closeBrace.textContent = "}"; 1226 closeBrace.textContent = "}";
1227 this.element.appendChild(closeBrace); 1227 this.element.appendChild(closeBrace);
1228 1228
1229 if (this.editable && this.rule) { 1229 if (this.editable && this.rule) {
1230 var newRuleButton = closeBrace.createChild("div", "sidebar-pane-button-n ew-rule"); 1230 var newRuleButton = closeBrace.createChild("div", "sidebar-pane-button-n ew-rule");
1231 newRuleButton.title = WebInspector.UIString("Insert Style Rule"); 1231 newRuleButton.title = WebInspector.UIString("Insert Style Rule");
1232 newRuleButton.addEventListener("click", this._onNewRuleClick.bind(this), false); 1232 newRuleButton.addEventListener("click", this._onNewRuleClick.bind(this), false);
1233 } 1233 }
1234 1234
1235 this._selectorElement.addEventListener("click", this._handleSelectorClick.bi nd(this), false); 1235 this._selectorElement.addEventListener("click", this._handleSelectorClick.bi nd(this), false);
1236 this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.b ind(this), false); 1236 this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.b ind(this), false);
1237 this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this ), false); 1237 this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this ), false);
1238 1238
1239 if (this.rule) { 1239 if (this.rule) {
1240 // Prevent editing the user agent and user rules. 1240 // Prevent editing the user agent and user rules.
1241 if (this.rule.isUserAgent || this.rule.isUser) 1241 if (this.rule.isUserAgent || this.rule.isUser)
1242 this.editable = false; 1242 this.editable = false;
1243 else { 1243 else {
1244 // Check this is a real CSSRule, not a bogus object coming from WebI nspector.BlankStylePropertiesSection. 1244 // Check this is a real CSSRule, not a bogus object coming from WebI nspector.BlankStylePropertiesSection.
1245 if (this.rule.styleSheetId) 1245 if (this.rule.styleSheetId)
1246 this.navigable = !!this.rule.resourceURL(); 1246 this.navigable = !!this.rule.resourceURL();
1247 } 1247 }
1248 this.titleElement.classList.add("styles-selector"); 1248 this.titleElement.classList.add("styles-selector");
1249 } 1249 }
1250 1250
1251 this._usedProperties = styleRule.usedProperties; 1251 this._usedProperties = styleRule.usedProperties;
1252 1252
1253 this._selectorRefElement = document.createElement("div"); 1253 this._selectorRefElement = createElement("div");
1254 this._selectorRefElement.className = "subtitle"; 1254 this._selectorRefElement.className = "subtitle";
1255 this._mediaListElement = this.titleElement.createChild("div", "media-list"); 1255 this._mediaListElement = this.titleElement.createChild("div", "media-list");
1256 this._updateMediaList(); 1256 this._updateMediaList();
1257 this._updateRuleOrigin(); 1257 this._updateRuleOrigin();
1258 selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.f irstChild); 1258 selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.f irstChild);
1259 this.titleElement.appendChild(selectorContainer); 1259 this.titleElement.appendChild(selectorContainer);
1260 this._selectorContainer = selectorContainer; 1260 this._selectorContainer = selectorContainer;
1261 1261
1262 if (isInherited) 1262 if (isInherited)
1263 this.element.classList.add("styles-show-inherited"); // This one is rela ted to inherited rules, not computed style. 1263 this.element.classList.add("styles-show-inherited"); // This one is rela ted to inherited rules, not computed style.
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 return; 1554 return;
1555 1555
1556 var matchingSelectors = rule.matchingSelectors; 1556 var matchingSelectors = rule.matchingSelectors;
1557 // .selector is rendered as non-affecting selector by default. 1557 // .selector is rendered as non-affecting selector by default.
1558 if (this.noAffect || matchingSelectors) 1558 if (this.noAffect || matchingSelectors)
1559 this._selectorElement.className = "selector"; 1559 this._selectorElement.className = "selector";
1560 if (!matchingSelectors) 1560 if (!matchingSelectors)
1561 return; 1561 return;
1562 1562
1563 var selectors = rule.selectors; 1563 var selectors = rule.selectors;
1564 var fragment = document.createDocumentFragment(); 1564 var fragment = createDocumentFragment();
1565 var currentMatch = 0; 1565 var currentMatch = 0;
1566 for (var i = 0; i < selectors.length ; ++i) { 1566 for (var i = 0; i < selectors.length ; ++i) {
1567 if (i) 1567 if (i)
1568 fragment.createTextChild(", "); 1568 fragment.createTextChild(", ");
1569 var isSelectorMatching = matchingSelectors[currentMatch] === i; 1569 var isSelectorMatching = matchingSelectors[currentMatch] === i;
1570 if (isSelectorMatching) 1570 if (isSelectorMatching)
1571 ++currentMatch; 1571 ++currentMatch;
1572 var matchingSelectorClass = isSelectorMatching ? " selector-matches" : ""; 1572 var matchingSelectorClass = isSelectorMatching ? " selector-matches" : "";
1573 var selectorElement = document.createElement("span"); 1573 var selectorElement = createElement("span");
1574 selectorElement.className = "simple-selector" + matchingSelectorClas s; 1574 selectorElement.className = "simple-selector" + matchingSelectorClas s;
1575 if (rule.styleSheetId) 1575 if (rule.styleSheetId)
1576 selectorElement._selectorIndex = i; 1576 selectorElement._selectorIndex = i;
1577 selectorElement.textContent = selectors[i].value; 1577 selectorElement.textContent = selectors[i].value;
1578 1578
1579 fragment.appendChild(selectorElement); 1579 fragment.appendChild(selectorElement);
1580 } 1580 }
1581 1581
1582 this._selectorElement.removeChildren(); 1582 this._selectorElement.removeChildren();
1583 this._selectorElement.appendChild(fragment); 1583 this._selectorElement.appendChild(fragment);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 }, 1629 },
1630 1630
1631 /** 1631 /**
1632 * @param {?WebInspector.CSSRule} rule 1632 * @param {?WebInspector.CSSRule} rule
1633 * @param {!WebInspector.TextRange=} ruleLocation 1633 * @param {!WebInspector.TextRange=} ruleLocation
1634 * @return {!Node} 1634 * @return {!Node}
1635 */ 1635 */
1636 _createRuleOriginNode: function(rule, ruleLocation) 1636 _createRuleOriginNode: function(rule, ruleLocation)
1637 { 1637 {
1638 if (!rule) 1638 if (!rule)
1639 return document.createTextNode(""); 1639 return createTextNode("");
1640 1640
1641 if (!ruleLocation) { 1641 if (!ruleLocation) {
1642 var firstMatchingIndex = rule.matchingSelectors && rule.matchingSele ctors.length ? rule.matchingSelectors[0] : 0; 1642 var firstMatchingIndex = rule.matchingSelectors && rule.matchingSele ctors.length ? rule.matchingSelectors[0] : 0;
1643 ruleLocation = rule.selectors[firstMatchingIndex].range; 1643 ruleLocation = rule.selectors[firstMatchingIndex].range;
1644 } 1644 }
1645 1645
1646 if (ruleLocation && rule.styleSheetId) 1646 if (ruleLocation && rule.styleSheetId)
1647 return this._linkifyRuleLocation(rule.styleSheetId, ruleLocation); 1647 return this._linkifyRuleLocation(rule.styleSheetId, ruleLocation);
1648 1648
1649 if (rule.isUserAgent) 1649 if (rule.isUserAgent)
1650 return document.createTextNode(WebInspector.UIString("user agent sty lesheet")); 1650 return createTextNode(WebInspector.UIString("user agent stylesheet") );
1651 if (rule.isUser) 1651 if (rule.isUser)
1652 return document.createTextNode(WebInspector.UIString("user styleshee t")); 1652 return createTextNode(WebInspector.UIString("user stylesheet"));
1653 if (rule.isViaInspector) 1653 if (rule.isViaInspector)
1654 return document.createTextNode(WebInspector.UIString("via inspector" )); 1654 return createTextNode(WebInspector.UIString("via inspector"));
1655 return document.createTextNode(""); 1655 return createTextNode("");
1656 }, 1656 },
1657 1657
1658 /** 1658 /**
1659 * @param {string} styleSheetId 1659 * @param {string} styleSheetId
1660 * @param {!WebInspector.TextRange} ruleLocation 1660 * @param {!WebInspector.TextRange} ruleLocation
1661 * @return {!Node} 1661 * @return {!Node}
1662 */ 1662 */
1663 _linkifyRuleLocation: function(styleSheetId, ruleLocation) 1663 _linkifyRuleLocation: function(styleSheetId, ruleLocation)
1664 { 1664 {
1665 /** 1665 /**
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 1992
1993 for (var j = 0; j < section.uniqueProperties.length; ++j) { 1993 for (var j = 0; j < section.uniqueProperties.length; ++j) {
1994 var property = section.uniqueProperties[j]; 1994 var property = section.uniqueProperties[j];
1995 if (property.disabled) 1995 if (property.disabled)
1996 continue; 1996 continue;
1997 if (section.isInherited && !WebInspector.CSSMetadata.isPropertyI nherited(property.name)) 1997 if (section.isInherited && !WebInspector.CSSMetadata.isPropertyI nherited(property.name))
1998 continue; 1998 continue;
1999 1999
2000 var treeElement = this._propertyTreeElements[property.name.toLow erCase()]; 2000 var treeElement = this._propertyTreeElements[property.name.toLow erCase()];
2001 if (treeElement) { 2001 if (treeElement) {
2002 var fragment = document.createDocumentFragment(); 2002 var fragment = createDocumentFragment();
2003 var selector = fragment.createChild("span"); 2003 var selector = fragment.createChild("span");
2004 selector.style.color = "gray"; 2004 selector.style.color = "gray";
2005 selector.textContent = section.styleRule.selectorText; 2005 selector.textContent = section.styleRule.selectorText;
2006 fragment.createTextChild(" - " + property.value + " "); 2006 fragment.createTextChild(" - " + property.value + " ");
2007 var subtitle = fragment.createChild("span"); 2007 var subtitle = fragment.createChild("span");
2008 subtitle.style.float = "right"; 2008 subtitle.style.float = "right";
2009 subtitle.appendChild(section._createRuleOriginNode(section.r ule)); 2009 subtitle.appendChild(section._createRuleOriginNode(section.r ule));
2010 var childElement = new TreeElement(fragment, null, false); 2010 var childElement = new TreeElement(fragment, null, false);
2011 treeElement.appendChild(childElement); 2011 treeElement.appendChild(childElement);
2012 if (property.inactive || section.isPropertyOverloaded(proper ty.name)) 2012 if (property.inactive || section.isPropertyOverloaded(proper ty.name))
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 { 2297 {
2298 this.updateTitle(); 2298 this.updateTitle();
2299 }, 2299 },
2300 2300
2301 updateTitle: function() 2301 updateTitle: function()
2302 { 2302 {
2303 var value = this.value; 2303 var value = this.value;
2304 2304
2305 this.updateState(); 2305 this.updateState();
2306 2306
2307 var nameElement = document.createElement("span"); 2307 var nameElement = createElement("span");
2308 nameElement.className = "webkit-css-property"; 2308 nameElement.className = "webkit-css-property";
2309 nameElement.textContent = this.name; 2309 nameElement.textContent = this.name;
2310 nameElement.title = this.property.propertyText; 2310 nameElement.title = this.property.propertyText;
2311 this.nameElement = nameElement; 2311 this.nameElement = nameElement;
2312 2312
2313 this._expandElement = document.createElement("span"); 2313 this._expandElement = createElement("span");
2314 this._expandElement.className = "expand-element"; 2314 this._expandElement.className = "expand-element";
2315 2315
2316 var valueElement = document.createElement("span"); 2316 var valueElement = createElement("span");
2317 valueElement.className = "value"; 2317 valueElement.className = "value";
2318 this.valueElement = valueElement; 2318 this.valueElement = valueElement;
2319 2319
2320 /** 2320 /**
2321 * @param {!RegExp} regex 2321 * @param {!RegExp} regex
2322 * @param {function(string):!Node} processor 2322 * @param {function(string):!Node} processor
2323 * @param {?function(string):!Node} nextProcessor 2323 * @param {?function(string):!Node} nextProcessor
2324 * @param {string} valueText 2324 * @param {string} valueText
2325 * @return {!DocumentFragment} 2325 * @return {!DocumentFragment}
2326 */ 2326 */
2327 function processValue(regex, processor, nextProcessor, valueText) 2327 function processValue(regex, processor, nextProcessor, valueText)
2328 { 2328 {
2329 var container = document.createDocumentFragment(); 2329 var container = createDocumentFragment();
2330 2330
2331 var items = valueText.replace(regex, "\0$1\0").split("\0"); 2331 var items = valueText.replace(regex, "\0$1\0").split("\0");
2332 for (var i = 0; i < items.length; ++i) { 2332 for (var i = 0; i < items.length; ++i) {
2333 if ((i % 2) === 0) { 2333 if ((i % 2) === 0) {
2334 if (nextProcessor) 2334 if (nextProcessor)
2335 container.appendChild(nextProcessor(items[i])); 2335 container.appendChild(nextProcessor(items[i]));
2336 else 2336 else
2337 container.createTextChild(items[i]); 2337 container.createTextChild(items[i]);
2338 } else { 2338 } else {
2339 var processedNode = processor(items[i]); 2339 var processedNode = processor(items[i]);
2340 if (processedNode) 2340 if (processedNode)
2341 container.appendChild(processedNode); 2341 container.appendChild(processedNode);
2342 } 2342 }
2343 } 2343 }
2344 2344
2345 return container; 2345 return container;
2346 } 2346 }
2347 2347
2348 /** 2348 /**
2349 * @param {string} url 2349 * @param {string} url
2350 * @return {!Node} 2350 * @return {!Node}
2351 * @this {WebInspector.StylePropertyTreeElementBase} 2351 * @this {WebInspector.StylePropertyTreeElementBase}
2352 */ 2352 */
2353 function linkifyURL(url) 2353 function linkifyURL(url)
2354 { 2354 {
2355 var hrefUrl = url; 2355 var hrefUrl = url;
2356 var match = hrefUrl.match(/['"]?([^'"]+)/); 2356 var match = hrefUrl.match(/['"]?([^'"]+)/);
2357 if (match) 2357 if (match)
2358 hrefUrl = match[1]; 2358 hrefUrl = match[1];
2359 var container = document.createDocumentFragment(); 2359 var container = createDocumentFragment();
2360 container.createTextChild("url("); 2360 container.createTextChild("url(");
2361 if (this._styleRule.rule && this._styleRule.rule.resourceURL()) 2361 if (this._styleRule.rule && this._styleRule.rule.resourceURL())
2362 hrefUrl = WebInspector.ParsedURL.completeURL(this._styleRule.rul e.resourceURL(), hrefUrl); 2362 hrefUrl = WebInspector.ParsedURL.completeURL(this._styleRule.rul e.resourceURL(), hrefUrl);
2363 else if (this.node()) 2363 else if (this.node())
2364 hrefUrl = this.node().resolveURL(hrefUrl); 2364 hrefUrl = this.node().resolveURL(hrefUrl);
2365 var hasResource = hrefUrl && !!WebInspector.resourceForURL(hrefUrl); 2365 var hasResource = hrefUrl && !!WebInspector.resourceForURL(hrefUrl);
2366 // FIXME: WebInspector.linkifyURLAsNode() should really use baseURI. 2366 // FIXME: WebInspector.linkifyURLAsNode() should really use baseURI.
2367 container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl || url, url, undefined, !hasResource)); 2367 container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl || url, url, undefined, !hasResource));
2368 container.createTextChild(")"); 2368 container.createTextChild(")");
2369 return container; 2369 return container;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 * @param {!Element} valueElement 2415 * @param {!Element} valueElement
2416 * @param {string} text 2416 * @param {string} text
2417 * @return {!Node} 2417 * @return {!Node}
2418 */ 2418 */
2419 _processColor: function(nameElement, valueElement, text) 2419 _processColor: function(nameElement, valueElement, text)
2420 { 2420 {
2421 var color = WebInspector.Color.parse(text); 2421 var color = WebInspector.Color.parse(text);
2422 2422
2423 // We can be called with valid non-color values of |text| (like 'none' f rom border style) 2423 // We can be called with valid non-color values of |text| (like 'none' f rom border style)
2424 if (!color) 2424 if (!color)
2425 return document.createTextNode(text); 2425 return createTextNode(text);
2426 2426
2427 var format = WebInspector.StylesSidebarPane._colorFormat(color); 2427 var format = WebInspector.StylesSidebarPane._colorFormat(color);
2428 var spectrumHelper = this.editablePane() && this.editablePane()._spectru mHelper; 2428 var spectrumHelper = this.editablePane() && this.editablePane()._spectru mHelper;
2429 var spectrum = spectrumHelper ? spectrumHelper.spectrum() : null; 2429 var spectrum = spectrumHelper ? spectrumHelper.spectrum() : null;
2430 2430
2431 var isEditable = !!(this._styleRule && this._styleRule.editable !== fals e); // |editable| is true by default. 2431 var isEditable = !!(this._styleRule && this._styleRule.editable !== fals e); // |editable| is true by default.
2432 var colorSwatch = new WebInspector.ColorSwatch(!isEditable); 2432 var colorSwatch = new WebInspector.ColorSwatch(!isEditable);
2433 colorSwatch.setColorString(text); 2433 colorSwatch.setColorString(text);
2434 colorSwatch.element.addEventListener("click", swatchClick.bind(this), fa lse); 2434 colorSwatch.element.addEventListener("click", swatchClick.bind(this), fa lse);
2435 2435
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2500 spectrumHelper.addEventListener(WebInspector.SpectrumPopupHelper .Events.Hidden, boundSpectrumHidden); 2500 spectrumHelper.addEventListener(WebInspector.SpectrumPopupHelper .Events.Hidden, boundSpectrumHidden);
2501 2501
2502 scrollerElement = colorSwatch.element.enclosingNodeOrSelfWithCla ss("style-panes-wrapper"); 2502 scrollerElement = colorSwatch.element.enclosingNodeOrSelfWithCla ss("style-panes-wrapper");
2503 if (scrollerElement) 2503 if (scrollerElement)
2504 scrollerElement.addEventListener("scroll", repositionSpectru m, false); 2504 scrollerElement.addEventListener("scroll", repositionSpectru m, false);
2505 else 2505 else
2506 console.error("Unable to handle color picker scrolling"); 2506 console.error("Unable to handle color picker scrolling");
2507 } 2507 }
2508 } 2508 }
2509 2509
2510 var colorValueElement = document.createElement("span"); 2510 var colorValueElement = createElement("span");
2511 if (format === WebInspector.Color.Format.Original) 2511 if (format === WebInspector.Color.Format.Original)
2512 colorValueElement.textContent = text; 2512 colorValueElement.textContent = text;
2513 else 2513 else
2514 colorValueElement.textContent = color.toString(format); 2514 colorValueElement.textContent = color.toString(format);
2515 2515
2516 /** 2516 /**
2517 * @param {string} curFormat 2517 * @param {string} curFormat
2518 */ 2518 */
2519 function nextFormat(curFormat) 2519 function nextFormat(curFormat)
2520 { 2520 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 2564
2565 function changeColorDisplay() 2565 function changeColorDisplay()
2566 { 2566 {
2567 do { 2567 do {
2568 format = nextFormat(format); 2568 format = nextFormat(format);
2569 var currentValue = color.toString(format); 2569 var currentValue = color.toString(format);
2570 } while (currentValue === colorValueElement.textContent); 2570 } while (currentValue === colorValueElement.textContent);
2571 colorValueElement.textContent = currentValue; 2571 colorValueElement.textContent = currentValue;
2572 } 2572 }
2573 2573
2574 var container = document.createElement("nobr"); 2574 var container = createElement("nobr");
2575 container.appendChild(colorSwatch.element); 2575 container.appendChild(colorSwatch.element);
2576 container.appendChild(colorValueElement); 2576 container.appendChild(colorValueElement);
2577 return container; 2577 return container;
2578 }, 2578 },
2579 2579
2580 updateState: function() 2580 updateState: function()
2581 { 2581 {
2582 if (!this.listItemElement) 2582 if (!this.listItemElement)
2583 return; 2583 return;
2584 2584
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 delete this._parentPane._mouseDownTreeElementIsName; 2829 delete this._parentPane._mouseDownTreeElementIsName;
2830 delete this._parentPane._mouseDownTreeElementIsValue; 2830 delete this._parentPane._mouseDownTreeElementIsValue;
2831 } 2831 }
2832 }, 2832 },
2833 2833
2834 updateTitle: function() 2834 updateTitle: function()
2835 { 2835 {
2836 WebInspector.StylePropertyTreeElementBase.prototype.updateTitle.call(thi s); 2836 WebInspector.StylePropertyTreeElementBase.prototype.updateTitle.call(thi s);
2837 2837
2838 if (this.parsedOk && this.section() && this.parent.root) { 2838 if (this.parsedOk && this.section() && this.parent.root) {
2839 var enabledCheckboxElement = document.createElement("input"); 2839 var enabledCheckboxElement = createElement("input");
2840 enabledCheckboxElement.className = "enabled-button"; 2840 enabledCheckboxElement.className = "enabled-button";
2841 enabledCheckboxElement.type = "checkbox"; 2841 enabledCheckboxElement.type = "checkbox";
2842 enabledCheckboxElement.checked = !this.disabled; 2842 enabledCheckboxElement.checked = !this.disabled;
2843 enabledCheckboxElement.addEventListener("click", this.toggleEnabled. bind(this), false); 2843 enabledCheckboxElement.addEventListener("click", this.toggleEnabled. bind(this), false);
2844 this.listItemElement.insertBefore(enabledCheckboxElement, this.listI temElement.firstChild); 2844 this.listItemElement.insertBefore(enabledCheckboxElement, this.listI temElement.firstChild);
2845 } 2845 }
2846 }, 2846 },
2847 2847
2848 _mouseClick: function(event) 2848 _mouseClick: function(event)
2849 { 2849 {
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase( ))) { 3582 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase( ))) {
3583 for (var i = 0; i < results.length; ++i) 3583 for (var i = 0; i < results.length; ++i)
3584 results[i] = results[i].toUpperCase(); 3584 results[i] = results[i].toUpperCase();
3585 } 3585 }
3586 var selectedIndex = this._cssCompletions.mostUsedOf(results); 3586 var selectedIndex = this._cssCompletions.mostUsedOf(results);
3587 completionsReadyCallback(results, selectedIndex); 3587 completionsReadyCallback(results, selectedIndex);
3588 }, 3588 },
3589 3589
3590 __proto__: WebInspector.TextPrompt.prototype 3590 __proto__: WebInspector.TextPrompt.prototype
3591 } 3591 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/elements/Spectrum.js ('k') | Source/devtools/front_end/extensions/ExtensionAuditCategory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698