📄 stylessidebarpane.js
字号:
/* * Copyright (C) 2007 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */WebInspector.StylesSidebarPane = function(){ WebInspector.SidebarPane.call(this, WebInspector.UIString("Styles"));}WebInspector.StylesSidebarPane.prototype = { update: function(node, editedSection, forceUpdate) { var refresh = false; if (forceUpdate) delete this.node; if (!forceUpdate && (!node || node === this.node)) refresh = true; if (node && node.nodeType === Node.TEXT_NODE && node.parentNode) node = node.parentNode; if (node && node.nodeType !== Node.ELEMENT_NODE) node = null; if (node) this.node = node; else node = this.node; var body = this.bodyElement; if (!refresh || !node) { body.removeChildren(); this.sections = []; } if (!node) return; var styleRules = []; if (refresh) { for (var i = 0; i < this.sections.length; ++i) { var section = this.sections[i]; if (section.computedStyle) section.styleRule.style = node.ownerDocument.defaultView.getComputedStyle(node); var styleRule = { section: section, style: section.styleRule.style, computedStyle: section.computedStyle }; styleRules.push(styleRule); } } else { var computedStyle = node.ownerDocument.defaultView.getComputedStyle(node); styleRules.push({ computedStyle: true, selectorText: WebInspector.UIString("Computed Style"), style: computedStyle, editable: false }); var nodeName = node.nodeName.toLowerCase(); for (var i = 0; i < node.attributes.length; ++i) { var attr = node.attributes[i]; if (attr.style) { var attrStyle = { style: attr.style, editable: false }; attrStyle.subtitle = WebInspector.UIString("element’s “%s” attribute", attr.name); attrStyle.selectorText = nodeName + "[" + attr.name; if (attr.value.length) attrStyle.selectorText += "=" + attr.value; attrStyle.selectorText += "]"; styleRules.push(attrStyle); } } if (node.style && (node.style.length || Object.hasProperties(node.style.__disabledProperties))) { var inlineStyle = { selectorText: WebInspector.UIString("Inline Style Attribute"), style: node.style }; inlineStyle.subtitle = WebInspector.UIString("element’s “%s” attribute", "style"); styleRules.push(inlineStyle); } var matchedStyleRules = node.ownerDocument.defaultView.getMatchedCSSRules(node, "", !Preferences.showUserAgentStyles); if (matchedStyleRules) { // Add rules in reverse order to match the cascade order. for (var i = (matchedStyleRules.length - 1); i >= 0; --i) { var rule = matchedStyleRules[i]; styleRules.push({ style: rule.style, selectorText: rule.selectorText, parentStyleSheet: rule.parentStyleSheet }); } } } function deleteDisabledProperty(style, name) { if (!style || !name) return; if (style.__disabledPropertyValues) delete style.__disabledPropertyValues[name]; if (style.__disabledPropertyPriorities) delete style.__disabledPropertyPriorities[name]; if (style.__disabledProperties) delete style.__disabledProperties[name]; } var usedProperties = {}; var disabledComputedProperties = {}; var priorityUsed = false; // Walk the style rules and make a list of all used and overloaded properties. for (var i = 0; i < styleRules.length; ++i) { var styleRule = styleRules[i]; if (styleRule.computedStyle) continue; styleRule.usedProperties = {}; var style = styleRule.style; for (var j = 0; j < style.length; ++j) { var name = style[j]; if (!priorityUsed && style.getPropertyPriority(name).length) priorityUsed = true; // If the property name is already used by another rule then this rule's // property is overloaded, so don't add it to the rule's usedProperties. if (!(name in usedProperties)) styleRule.usedProperties[name] = true; if (name === "font") { // The font property is not reported as a shorthand. Report finding the individual // properties so they are visible in computed style. // FIXME: remove this when http://bugs.webkit.org/show_bug.cgi?id=15598 is fixed. styleRule.usedProperties["font-family"] = true; styleRule.usedProperties["font-size"] = true; styleRule.usedProperties["font-style"] = true; styleRule.usedProperties["font-variant"] = true; styleRule.usedProperties["font-weight"] = true; styleRule.usedProperties["line-height"] = true; } // Delete any disabled properties, since the property does exist. // This prevents it from showing twice. deleteDisabledProperty(style, name); deleteDisabledProperty(style, style.getPropertyShorthand(name)); } // Add all the properties found in this style to the used properties list. // Do this here so only future rules are affect by properties used in this rule. for (var name in styleRules[i].usedProperties) usedProperties[name] = true; // Remember all disabled properties so they show up in computed style. if (style.__disabledProperties) for (var name in style.__disabledProperties) disabledComputedProperties[name] = true; } if (priorityUsed) { // Walk the properties again and account for !important. var foundPriorityProperties = []; // Walk in reverse to match the order !important overrides. for (var i = (styleRules.length - 1); i >= 0; --i) { if (styleRules[i].computedStyle) continue; var style = styleRules[i].style; var uniqueProperties = getUniqueStyleProperties(style); for (var j = 0; j < uniqueProperties.length; ++j) { var name = uniqueProperties[j]; if (style.getPropertyPriority(name).length) { if (!(name in foundPriorityProperties)) styleRules[i].usedProperties[name] = true; else delete styleRules[i].usedProperties[name]; foundPriorityProperties[name] = true; } else if (name in foundPriorityProperties) delete styleRules[i].usedProperties[name]; } } } if (refresh) { // Walk the style rules and update the sections with new overloaded and used properties. for (var i = 0; i < styleRules.length; ++i) { var styleRule = styleRules[i]; var section = styleRule.section; if (styleRule.computedStyle) section.disabledComputedProperties = disabledComputedProperties; section._usedProperties = (styleRule.usedProperties || usedProperties); section.update((section === editedSection) || styleRule.computedStyle); } } else { // Make a property section for each style rule. for (var i = 0; i < styleRules.length; ++i) { var styleRule = styleRules[i]; var subtitle = styleRule.subtitle; delete styleRule.subtitle; var computedStyle = styleRule.computedStyle; delete styleRule.computedStyle; var ruleUsedProperties = styleRule.usedProperties; delete styleRule.usedProperties; var editable = styleRule.editable; delete styleRule.editable; // Default editable to true if it was omitted. if (typeof editable === "undefined") editable = true; var section = new WebInspector.StylePropertiesSection(styleRule, subtitle, computedStyle, (ruleUsedProperties || usedProperties), editable); if (computedStyle) section.disabledComputedProperties = disabledComputedProperties; section.pane = this; if (Preferences.styleRulesExpandedState && section.identifier in Preferences.styleRulesExpandedState) section.expanded = Preferences.styleRulesExpandedState[section.identifier]; else if (computedStyle) section.collapse(true); else section.expand(true); body.appendChild(section.element); this.sections.push(section); } } }}WebInspector.StylesSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;WebInspector.StylePropertiesSection = function(styleRule, subtitle, computedStyle, usedProperties, editable){ WebInspector.PropertiesSection.call(this, styleRule.selectorText); this.styleRule = styleRule; this.computedStyle = computedStyle; this.editable = (editable && !computedStyle); // Prevent editing the user agent and user rules. var isUserAgent = this.styleRule.parentStyleSheet && !this.styleRule.parentStyleSheet.ownerNode && !this.styleRule.parentStyleSheet.href; var isUser = this.styleRule.parentStyleSheet && this.styleRule.parentStyleSheet.ownerNode && this.styleRule.parentStyleSheet.ownerNode.nodeName == '#document'; if (isUserAgent || isUser) this.editable = false; this._usedProperties = usedProperties; if (computedStyle) { this.element.addStyleClass("computed-style"); if (Preferences.showInheritedComputedStyleProperties) this.element.addStyleClass("show-inherited"); var showInheritedLabel = document.createElement("label"); var showInheritedInput = document.createElement("input"); showInheritedInput.type = "checkbox"; showInheritedInput.checked = Preferences.showInheritedComputedStyleProperties; var computedStyleSection = this; var showInheritedToggleFunction = function(event) { Preferences.showInheritedComputedStyleProperties = showInheritedInput.checked; if (Preferences.showInheritedComputedStyleProperties) computedStyleSection.element.addStyleClass("show-inherited"); else computedStyleSection.element.removeStyleClass("show-inherited"); event.stopPropagation(); }; showInheritedLabel.addEventListener("click", showInheritedToggleFunction, false); showInheritedLabel.appendChild(showInheritedInput); showInheritedLabel.appendChild(document.createTextNode(WebInspector.UIString("Show inherited"))); this.subtitleElement.appendChild(showInheritedLabel); } else { if (!subtitle) { if (this.styleRule.parentStyleSheet && this.styleRule.parentStyleSheet.href) { var url = this.styleRule.parentStyleSheet.href; subtitle = WebInspector.linkifyURL(url, WebInspector.displayNameForURL(url)); this.subtitleElement.addStyleClass("file"); } else if (isUserAgent) subtitle = WebInspector.UIString("user agent stylesheet"); else if (isUser) subtitle = WebInspector.UIString("user stylesheet"); else subtitle = WebInspector.UIString("inline stylesheet"); } this.subtitle = subtitle; } this.identifier = styleRule.selectorText; if (this.subtitle)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -