⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stylessidebarpane.js

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 JS
📖 第 1 页 / 共 3 页
字号:
                var inspectedWindow = InspectorController.inspectedWindow();                this.style.__disabledProperties = new inspectedWindow.Object;                this.style.__disabledPropertyValues = new inspectedWindow.Object;                this.style.__disabledPropertyPriorities = new inspectedWindow.Object;            }            this.style.__disabledPropertyValues[this.name] = this.value;            this.style.__disabledPropertyPriorities[this.name] = this.priority;            if (this.shorthand) {                var longhandProperties = getLonghandProperties(this.style, this.name);                for (var i = 0; i < longhandProperties.length; ++i) {                    this.style.__disabledProperties[longhandProperties[i]] = true;                    this.style.removeProperty(longhandProperties[i]);                }            } else {                this.style.__disabledProperties[this.name] = true;                this.style.removeProperty(this.name);            }        } else {            this.style.setProperty(this.name, this.value, this.priority);            delete this.style.__disabledProperties[this.name];            delete this.style.__disabledPropertyValues[this.name];            delete this.style.__disabledPropertyPriorities[this.name];        }        // Set the disabled property here, since the code above replies on it not changing        // until after the value and priority are retrieved.        this.disabled = disabled;        if (this.treeOutline.section && this.treeOutline.section.pane)            this.treeOutline.section.pane.dispatchEventToListeners("style property toggled");        this.updateAll(true);    },    updateState: function()    {        if (!this.listItemElement)            return;        if (this.style.isPropertyImplicit(this.name) || this.value === "initial")            this.listItemElement.addStyleClass("implicit");        else            this.listItemElement.removeStyleClass("implicit");        if (this.inherited)            this.listItemElement.addStyleClass("inherited");        else            this.listItemElement.removeStyleClass("inherited");        if (this.overloaded)            this.listItemElement.addStyleClass("overloaded");        else            this.listItemElement.removeStyleClass("overloaded");        if (this.disabled)            this.listItemElement.addStyleClass("disabled");        else            this.listItemElement.removeStyleClass("disabled");    },    onpopulate: function()    {        // Only populate once and if this property is a shorthand.        if (this.children.length || !this.shorthand)            return;        var longhandProperties = getLonghandProperties(this.style, this.name);        for (var i = 0; i < longhandProperties.length; ++i) {            var name = longhandProperties[i];            if (this.treeOutline.section) {                var inherited = this.treeOutline.section.isPropertyInherited(name);                var overloaded = this.treeOutline.section.isPropertyOverloaded(name);            }            var item = new WebInspector.StylePropertyTreeElement(this.style, name, false, inherited, overloaded);            this.appendChild(item);        }    },    ondblclick: function(element, event)    {        this.startEditing(event.target);    },    startEditing: function(selectElement)    {        // FIXME: we don't allow editing of longhand properties under a shorthand right now.        if (this.parent.shorthand)            return;        if (WebInspector.isBeingEdited(this.listItemElement) || (this.treeOutline.section && !this.treeOutline.section.editable))            return;        var context = { expanded: this.expanded, hasChildren: this.hasChildren };        // Lie about our children to prevent expanding on double click and to collapse shorthands.        this.hasChildren = false;        if (!selectElement)            selectElement = this.listItemElement;        this.listItemElement.handleKeyEvent = this.editingKeyDown.bind(this);        WebInspector.startEditing(this.listItemElement, this.editingCommitted.bind(this), this.editingCancelled.bind(this), context);        window.getSelection().setBaseAndExtent(selectElement, 0, selectElement, 1);    },    editingKeyDown: function(event)    {        var arrowKeyPressed = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down");        var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifier === "PageDown");        if (!arrowKeyPressed && !pageKeyPressed)            return;        var selection = window.getSelection();        if (!selection.rangeCount)            return;        var selectionRange = selection.getRangeAt(0);        if (selectionRange.commonAncestorContainer !== this.listItemElement && !selectionRange.commonAncestorContainer.isDescendant(this.listItemElement))            return;        const styleValueDelimeters = " \t\n\"':;,/()";        var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, styleValueDelimeters, this.listItemElement);        var wordString = wordRange.toString();        var replacementString = wordString;        var matches = /(.*?)(-?\d+(?:\.\d+)?)(.*)/.exec(wordString);        if (matches && matches.length) {            var prefix = matches[1];            var number = parseFloat(matches[2]);            var suffix = matches[3];            // If the number is near zero or the number is one and the direction will take it near zero.            var numberNearZero = (number < 1 && number > -1);            if (number === 1 && event.keyIdentifier === "Down")                numberNearZero = true;            else if (number === -1 && event.keyIdentifier === "Up")                numberNearZero = true;            if (numberNearZero && event.altKey && arrowKeyPressed) {                if (event.keyIdentifier === "Down")                    number = Math.ceil(number - 1);                else                    number = Math.floor(number + 1);            } else {                // Jump by 10 when shift is down or jump by 0.1 when near zero or Alt/Option is down.                // Also jump by 10 for page up and down, or by 100 if shift is held with a page key.                var changeAmount = 1;                if (event.shiftKey && pageKeyPressed)                    changeAmount = 100;                else if (event.shiftKey || pageKeyPressed)                    changeAmount = 10;                else if (event.altKey || numberNearZero)                    changeAmount = 0.1;                if (event.keyIdentifier === "Down" || event.keyIdentifier === "PageDown")                    changeAmount *= -1;                // Make the new number and constrain it to a precision of 6, this matches numbers the engine returns.                // Use the Number constructor to forget the fixed precision, so 1.100000 will print as 1.1.                number = Number((number + changeAmount).toFixed(6));            }            replacementString = prefix + number + suffix;        } else {            // FIXME: this should cycle through known keywords for the current property name.            return;        }        var replacementTextNode = document.createTextNode(replacementString);        wordRange.deleteContents();        wordRange.insertNode(replacementTextNode);        var finalSelectionRange = document.createRange();        finalSelectionRange.setStart(replacementTextNode, 0);        finalSelectionRange.setEnd(replacementTextNode, replacementString.length);        selection.removeAllRanges();        selection.addRange(finalSelectionRange);        event.preventDefault();        event.handled = true;        if (!this.originalCSSText) {            // Remember the rule's original CSS text, so it can be restored            // if the editing is canceled and before each apply.            this.originalCSSText = getStyleTextWithShorthands(this.style);        } else {            // Restore the original CSS text before applying user changes. This is needed to prevent            // new properties from sticking around if the user adds one, then removes it.            this.style.cssText = this.originalCSSText;        }        this.applyStyleText(this.listItemElement.textContent);    },    editingEnded: function(context)    {        this.hasChildren = context.hasChildren;        if (context.expanded)            this.expand();        delete this.listItemElement.handleKeyEvent;        delete this.originalCSSText;    },    editingCancelled: function(element, context)    {        if (this.originalCSSText) {            this.style.cssText = this.originalCSSText;            if (this.treeOutline.section && this.treeOutline.section.pane)                this.treeOutline.section.pane.dispatchEventToListeners("style edited");            this.updateAll();        } else            this.updateTitle();        this.editingEnded(context);    },    editingCommitted: function(element, userInput, previousContent, context)    {        this.editingEnded(context);        if (userInput === previousContent)            return; // nothing changed, so do nothing else        this.applyStyleText(userInput, true);    },    applyStyleText: function(styleText, updateInterface)    {        var styleTextLength = styleText.trimWhitespace().length;        // Create a new element to parse the user input CSS.        var parseElement = document.createElement("span");        parseElement.setAttribute("style", styleText);        var tempStyle = parseElement.style;        if (tempStyle.length || !styleTextLength) {            // The input was parsable or the user deleted everything, so remove the            // original property from the real style declaration. If this represents            // a shorthand remove all the longhand properties.            if (this.shorthand) {                var longhandProperties = getLonghandProperties(this.style, this.name);                for (var i = 0; i < longhandProperties.length; ++i)                    this.style.removeProperty(longhandProperties[i]);            } else                this.style.removeProperty(this.name);        }        if (!styleTextLength) {            if (updateInterface) {                // The user deleted the everything, so remove the tree element and update.                if (this.treeOutline.section && this.treeOutline.section.pane)                    this.treeOutline.section.pane.update();                this.parent.removeChild(this);            }            return;        }        if (!tempStyle.length) {            // The user typed something, but it didn't parse. Just abort and restore            // the original title for this property.            if (updateInterface)                this.updateTitle();            return;        }        // Iterate of the properties on the test element's style declaration and        // add them to the real style declaration. We take care to move shorthands.        var foundShorthands = {};        var uniqueProperties = getUniqueStyleProperties(tempStyle);        for (var i = 0; i < uniqueProperties.length; ++i) {            var name = uniqueProperties[i];            var shorthand = tempStyle.getPropertyShorthand(name);            if (shorthand && shorthand in foundShorthands)                continue;            if (shorthand) {                var value = getShorthandValue(tempStyle, shorthand);                var priority = getShorthandPriority(tempStyle, shorthand);                foundShorthands[shorthand] = true;            } else {                var value = tempStyle.getPropertyValue(name);                var priority = tempStyle.getPropertyPriority(name);            }            // Set the property on the real style declaration.            this.style.setProperty((shorthand || name), value, priority);        }        if (this.treeOutline.section && this.treeOutline.section.pane)            this.treeOutline.section.pane.dispatchEventToListeners("style edited");        if (updateInterface)            this.updateAll(true);    }}WebInspector.StylePropertyTreeElement.prototype.__proto__ = TreeElement.prototype;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -