Changeset 70772 in webkit
- Timestamp:
- Oct 28, 2010 6:27:08 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r70770 r70772 1 2010-10-28 Alexander Pavlov <apavlov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: Bring backend-frontend message format to follow the protocol specification 6 https://bugs.webkit.org/show_bug.cgi?id=48406 7 8 * http/tests/inspector/inspect-iframe-from-different-domain.html: 9 * inspector/styles-source-offsets.html: 10 1 11 2010-10-28 Mikhail Naganov <mnaganov@chromium.org> 2 12 -
trunk/LayoutTests/http/tests/inspector/inspect-iframe-from-different-domain.html
r66087 r70772 78 78 79 79 for (var i = styles.matchedCSSRules.length - 1; i >= 0; --i) { 80 var rule = WebInspector.CSS StyleDeclaration.parseRule(styles.matchedCSSRules[i]);80 var rule = WebInspector.CSSRule.parsePayload(styles.matchedCSSRules[i]); 81 81 if (rule.isUser || rule.isUserAgent) 82 82 continue; -
trunk/LayoutTests/inspector/styles-source-offsets.html
r70682 r70772 38 38 for (var i = 0; i < matchedCSSRules.length; ++i) { 39 39 var rule = matchedCSSRules[i]; 40 InspectorBackend.getStyleSourceData(rule.style. id, frontend_styleDataReceived.bind(null, testController, rule, false));40 InspectorBackend.getStyleSourceData(rule.style.styleId, frontend_styleDataReceived.bind(null, testController, rule, false)); 41 41 } 42 InspectorBackend.getStyleSourceData(styles.inlineStyle. id, frontend_styleDataReceived.bind(null, testController, styles.inlineStyle, true));42 InspectorBackend.getStyleSourceData(styles.inlineStyle.styleId, frontend_styleDataReceived.bind(null, testController, styles.inlineStyle, true)); 43 43 } 44 44 InspectorBackend.getStyles(WebInspector.domAgent.document.body.id, true, stylesCallback.bind(null, testController)); -
trunk/WebCore/ChangeLog
r70763 r70772 1 2010-10-28 Alexander Pavlov <apavlov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: Bring backend-frontend message format to follow the protocol specification 6 https://bugs.webkit.org/show_bug.cgi?id=48406 7 8 * inspector/InspectorDOMAgent.cpp: 9 (WebCore::InspectorDOMAgent::getStyles): 10 (WebCore::InspectorDOMAgent::applyStyleText): 11 (WebCore::InspectorDOMAgent::buildObjectForStyle): 12 (WebCore::InspectorDOMAgent::populateObjectWithStyleProperties): 13 (WebCore::InspectorDOMAgent::buildObjectForStyleSheet): 14 (WebCore::InspectorDOMAgent::buildObjectForRule): 15 * inspector/InspectorDOMAgent.h: 16 * inspector/front-end/AuditRules.js: 17 (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback): 18 (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun): 19 * inspector/front-end/CSSStyleModel.js: 20 (WebInspector.CSSStyleModel.parseRuleArrayPayload): 21 (WebInspector.CSSStyleModel.prototype.getStylesAsync): 22 (WebInspector.CSSStyleModel.prototype.getComputedStyleAsync): 23 (WebInspector.CSSStyleModel.prototype.getInlineStyleAsync): 24 (WebInspector.CSSStyleModel.prototype.setCSSText): 25 * inspector/front-end/DOMAgent.js: 26 (WebInspector.CSSStyleDeclaration): 27 (WebInspector.CSSStyleDeclaration.parsePayload): 28 (WebInspector.CSSStyleDeclaration.prototype.get allProperties): 29 (WebInspector.CSSStyleDeclaration.prototype.getLiveProperty): 30 (WebInspector.CSSStyleDeclaration.prototype.getPropertyValue): 31 (WebInspector.CSSStyleDeclaration.prototype.getPropertyPriority): 32 (WebInspector.CSSStyleDeclaration.prototype.getPropertyShorthand): 33 (WebInspector.CSSStyleDeclaration.prototype.isPropertyImplicit): 34 (WebInspector.CSSStyleDeclaration.prototype.getShorthandValue): 35 (WebInspector.CSSStyleDeclaration.prototype.getShorthandPriority): 36 (WebInspector.CSSStyleDeclaration.prototype.appendProperty): 37 (WebInspector.CSSStyleDeclaration.prototype.propertyAt): 38 (WebInspector.CSSRule): 39 (WebInspector.CSSRule.parsePayload): 40 (WebInspector.CSSRule.prototype.get isUserAgent): 41 (WebInspector.CSSRule.prototype.get isUser): 42 (WebInspector.CSSRule.prototype.get isViaInspector): 43 (WebInspector.CSSRule.prototype.get isRegular): 44 (WebInspector.CSSProperty): 45 (WebInspector.CSSProperty.parsePayload): 46 (WebInspector.CSSProperty.prototype.get propertyText): 47 (WebInspector.CSSProperty.prototype.get isLive): 48 (WebInspector.CSSProperty.prototype.get active): 49 (WebInspector.CSSProperty.prototype.get styleBased): 50 (WebInspector.CSSProperty.prototype.get inactive): 51 (WebInspector.CSSProperty.prototype.get disabled): 52 (WebInspector.CSSProperty.prototype.setText): 53 (WebInspector.CSSProperty.prototype.setValue): 54 (WebInspector.CSSProperty.prototype.setDisabled.callback): 55 (WebInspector.CSSProperty.prototype.setDisabled): 56 * inspector/front-end/MetricsSidebarPane.js: 57 (WebInspector.MetricsSidebarPane.prototype.update.callback): 58 (WebInspector.MetricsSidebarPane.prototype.update.inlineStyleCallback): 59 (WebInspector.MetricsSidebarPane.prototype.update): 60 (WebInspector.MetricsSidebarPane.prototype._update): 61 (WebInspector.MetricsSidebarPane.prototype.editingCommitted.callback): 62 (WebInspector.MetricsSidebarPane.prototype.editingCommitted.setEnabledValueCallback): 63 (WebInspector.MetricsSidebarPane.prototype.editingCommitted): 64 * inspector/front-end/StylesSidebarPane.js: 65 (WebInspector.StylesSidebarPane.prototype.update): 66 (WebInspector.StylesSidebarPane.prototype._rebuildUpdate): 67 (WebInspector.StylesSidebarPane.prototype._refreshStyleRules): 68 (WebInspector.StylesSidebarPane.prototype._rebuildStyleRules): 69 (WebInspector.StylesSidebarPane.prototype._markUsedProperties): 70 (WebInspector.StylesSidebarPane.prototype._containsInherited): 71 (WebInspector.StylePropertiesSection): 72 (WebInspector.StylePropertiesSection.prototype.isPropertyInherited): 73 (WebInspector.StylePropertiesSection.prototype.isPropertyOverloaded): 74 (WebInspector.StylePropertiesSection.prototype.onpopulate): 75 (WebInspector.StylePropertiesSection.prototype.addNewBlankProperty): 76 (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.successCallback): 77 (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted): 78 (WebInspector.ComputedStylePropertiesSection.prototype._isPropertyInherited): 79 (WebInspector.ComputedStylePropertiesSection.prototype.onpopulate): 80 (WebInspector.ComputedStylePropertiesSection.prototype.rebuildComputedTrace): 81 (WebInspector.StylePropertyTreeElement): 82 (WebInspector.StylePropertyTreeElement.prototype.get disabled): 83 (WebInspector.StylePropertyTreeElement.prototype.get name): 84 (WebInspector.StylePropertyTreeElement.prototype.get priority): 85 (WebInspector.StylePropertyTreeElement.prototype.get value): 86 (WebInspector.StylePropertyTreeElement.prototype.get parsedOk): 87 (WebInspector.StylePropertyTreeElement.prototype): 88 (WebInspector.StylePropertyTreeElement.prototype.): 89 1 90 2010-10-27 MORITA Hajime <morrita@google.com> 2 91 -
trunk/WebCore/inspector/InspectorDOMAgent.cpp
r70046 r70772 1220 1220 result->setArray("pseudoElements", buildArrayForPseudoElements(element, authorOnly)); 1221 1221 1222 RefPtr<Inspector Object> currentStyle = result;1222 RefPtr<InspectorArray> inheritedStyles = InspectorArray::create(); 1223 1223 Element* parentElement = element->parentElement(); 1224 1224 while (parentElement) { 1225 1225 RefPtr<InspectorObject> parentStyle = InspectorObject::create(); 1226 currentStyle->setObject("parent",parentStyle);1226 inheritedStyles->pushObject(parentStyle); 1227 1227 if (parentElement->style() && parentElement->style()->length()) 1228 1228 parentStyle->setObject("inlineStyle", buildObjectForStyle(parentElement->style(), true)); … … 1233 1233 1234 1234 parentElement = parentElement->parentElement(); 1235 currentStyle = parentStyle;1236 }1235 } 1236 result->setArray("inherited", inheritedStyles); 1237 1237 *styles = result.release(); 1238 1238 } … … 1397 1397 if (!styleTextLength) { 1398 1398 *success = true; 1399 *styleObject = buildObjectForStyle(style, true); 1399 1400 return; 1400 1401 } … … 1545 1546 RefPtr<InspectorObject> result = InspectorObject::create(); 1546 1547 if (bind) { 1547 long styleId = cssStore()->bindStyle(style); 1548 result->setNumber("id", styleId); 1549 CSSStyleSheet* parentStyleSheet = InspectorCSSStore::getParentStyleSheet(style); 1550 if (parentStyleSheet) 1551 result->setNumber("parentStyleSheetId", cssStore()->bindStyleSheet(parentStyleSheet)); 1552 1553 DisabledStyleDeclaration* disabledStyle = cssStore()->disabledStyleForId(styleId, false); 1554 if (disabledStyle) 1555 result->setArray("disabled", buildArrayForDisabledStyleProperties(disabledStyle)); 1556 } 1557 result->setString("width", style->getPropertyValue("width")); 1558 result->setString("height", style->getPropertyValue("height")); 1548 result->setNumber("styleId", cssStore()->bindStyle(style)); 1549 CSSStyleSheet* styleSheet = InspectorCSSStore::getParentStyleSheet(style); 1550 if (styleSheet) 1551 result->setNumber("styleSheetId", cssStore()->bindStyleSheet(styleSheet)); 1552 } 1553 RefPtr<InspectorObject> properties = InspectorObject::create(); 1554 properties->setString("width", style->getPropertyValue("width")); 1555 properties->setString("height", style->getPropertyValue("height")); 1556 result->setObject("properties", properties); 1559 1557 populateObjectWithStyleProperties(style, result.get()); 1560 1558 return result.release(); … … 1570 1568 RefPtr<InspectorObject> property = InspectorObject::create(); 1571 1569 String name = style->item(i); 1570 String value = style->getPropertyValue(name); 1571 String priority = style->getPropertyPriority(name); 1572 1572 property->setString("name", name); 1573 property->setString("priority", style->getPropertyPriority(name)); 1573 property->setString("value", value); 1574 property->setString("priority", priority); 1575 property->setString("text", name + ": " + value + (priority.length() ? " !" + priority : "") + ";"); 1574 1576 property->setBoolean("implicit", style->isPropertyImplicit(name)); 1577 property->setBoolean("parsedOk", true); 1578 property->setString("status", "style"); 1575 1579 String shorthand = style->getPropertyShorthand(name); 1576 property->setString("shorthand ", shorthand);1580 property->setString("shorthandName", shorthand); 1577 1581 if (!shorthand.isEmpty() && !foundShorthands.contains(shorthand)) { 1578 1582 foundShorthands.add(shorthand); 1579 1583 shorthandValues->setString(shorthand, shorthandValue(style, shorthand)); 1580 1584 } 1581 property->setString("value", style->getPropertyValue(name));1582 1585 properties->pushObject(property.release()); 1583 1586 } 1584 result->setArray("properties", properties); 1587 result->setArray("cssProperties", properties); 1588 result->setString("cssText", style->cssText()); 1585 1589 result->setObject("shorthandValues", shorthandValues); 1586 } 1587 1588 PassRefPtr<InspectorArray> InspectorDOMAgent::buildArrayForDisabledStyleProperties(DisabledStyleDeclaration* declaration)1589 { 1590 RefPtr<InspectorArray> properties = InspectorArray::create(); 1591 for (DisabledStyleDeclaration::iterator it = d eclaration->begin(); it != declaration->end(); ++it) {1590 1591 DisabledStyleDeclaration* disabledStyle = cssStore()->disabledStyleForId(cssStore()->bindStyle(style), false); 1592 if (!disabledStyle) 1593 return; 1594 1595 for (DisabledStyleDeclaration::iterator it = disabledStyle->begin(); it != disabledStyle->end(); ++it) { 1592 1596 RefPtr<InspectorObject> property = InspectorObject::create(); 1593 property->setString("name", it->first); 1594 property->setString("value", it->second.first); 1595 property->setString("priority", it->second.second); 1597 String name = it->first; 1598 String value = it->second.first; 1599 String priority = it->second.second; 1600 property->setString("name", name); 1601 property->setString("value", value); 1602 property->setString("priority", priority); 1603 property->setString("text", name + ": " + value + (priority.length() ? " !" + priority : "") + ";"); 1604 property->setBoolean("implicit", false); 1605 property->setBoolean("parsedOk", true); 1606 property->setString("status", "disabled"); 1596 1607 properties->pushObject(property.release()); 1597 1608 } 1598 return properties.release();1599 1609 } 1600 1610 … … 1603 1613 RefPtr<InspectorObject> result = InspectorObject::create(); 1604 1614 long id = cssStore()->bindStyleSheet(styleSheet); 1605 result->setNumber("id", id); 1615 result->setNumber("styleSheetId", id); 1616 result->setString("sourceURL", styleSheet->href()); 1617 result->setString("title", styleSheet->title()); 1606 1618 result->setBoolean("disabled", styleSheet->disabled()); 1607 result->setString("href", styleSheet->href());1608 result->setString("title", styleSheet->title());1609 result->setNumber("documentElementId", m_documentNodeToIdMap.get(styleSheet->document()));1610 1619 RefPtr<InspectorArray> cssRules = InspectorArray::create(); 1611 1620 PassRefPtr<CSSRuleList> cssRuleList = CSSRuleList::create(styleSheet, true); … … 1617 1626 } 1618 1627 } 1619 result->setArray(" cssRules", cssRules.release());1628 result->setArray("rules", cssRules.release()); 1620 1629 return result.release(); 1621 1630 } … … 1627 1636 RefPtr<InspectorObject> result = InspectorObject::create(); 1628 1637 result->setString("selectorText", rule->selectorText()); 1629 result->setString("cssText", rule->cssText());1630 1638 result->setNumber("sourceLine", rule->sourceLine()); 1631 result->setString("documentURL", documentURLString(ownerDocument)); 1632 if (parentStyleSheet) { 1633 RefPtr<InspectorObject> parentStyleSheetValue = InspectorObject::create(); 1634 parentStyleSheetValue->setString("href", parentStyleSheet->href()); 1635 parentStyleSheetValue->setNumber("id", cssStore()->bindStyleSheet(parentStyleSheet)); 1636 result->setObject("parentStyleSheet", parentStyleSheetValue.release()); 1637 } 1638 bool isUserAgent = parentStyleSheet && !parentStyleSheet->ownerNode() && parentStyleSheet->href().isEmpty(); 1639 bool isUser = parentStyleSheet && parentStyleSheet->ownerNode() && parentStyleSheet->ownerNode()->nodeName() == "#document"; 1640 result->setBoolean("isUserAgent", isUserAgent); 1641 result->setBoolean("isUser", isUser); 1642 result->setBoolean("isViaInspector", rule->parentStyleSheet() == cssStore()->inspectorStyleSheet(ownerDocument, false)); 1639 1640 String origin; 1641 bool canBind = true; 1642 if (parentStyleSheet && !parentStyleSheet->ownerNode() && parentStyleSheet->href().isEmpty()) { 1643 origin = "user-agent"; 1644 canBind = false; 1645 } else if (parentStyleSheet && parentStyleSheet->ownerNode() && parentStyleSheet->ownerNode()->nodeName() == "#document") { 1646 origin = "user"; 1647 canBind = false; 1648 } else if (rule->parentStyleSheet() == cssStore()->inspectorStyleSheet(ownerDocument, false)) 1649 origin = "inspector"; 1650 result->setString("origin", origin); 1651 1652 if (origin.isEmpty()) 1653 result->setString("sourceURL", parentStyleSheet && !parentStyleSheet->href().isEmpty() ? parentStyleSheet->href() : (ownerDocument ? ownerDocument->url().string() : "")); 1643 1654 1644 1655 // Bind editable scripts only. 1645 bool bind = !isUserAgent && !isUser; 1646 result->setObject("style", buildObjectForStyle(rule->style(), bind)); 1647 1648 if (bind) 1649 result->setNumber("id", cssStore()->bindRule(rule)); 1656 result->setObject("style", buildObjectForStyle(rule->style(), canBind)); 1657 1658 if (canBind) 1659 result->setNumber("ruleId", cssStore()->bindRule(rule)); 1650 1660 return result.release(); 1651 1661 } -
trunk/WebCore/inspector/InspectorDOMAgent.h
r70046 r70772 208 208 PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*, bool bind); 209 209 void populateObjectWithStyleProperties(CSSStyleDeclaration*, InspectorObject* result); 210 PassRefPtr<InspectorArray> buildArrayForDisabledStyleProperties(DisabledStyleDeclaration*);211 210 PassRefPtr<InspectorObject> buildObjectForRule(Document* ownerDocument, CSSStyleRule*); 212 211 PassRefPtr<InspectorObject> buildObjectForStyleSheet(Document* ownerDocument, CSSStyleSheet*); -
trunk/WebCore/inspector/front-end/AuditRules.js
r69947 r70772 287 287 for (var i = 0; i < styleSheets.length; ++i) { 288 288 var styleSheet = styleSheets[i]; 289 for (var curRule = 0; curRule < styleSheet. cssRules.length; ++curRule) {290 var rule = styleSheet. cssRules[curRule];289 for (var curRule = 0; curRule < styleSheet.rules.length; ++curRule) { 290 var rule = styleSheet.rules[curRule]; 291 291 if (rule.selectorText.match(pseudoSelectorRegexp)) 292 292 continue; … … 308 308 var unusedStylesheetSize = 0; 309 309 var unusedRules = []; 310 for (var curRule = 0; curRule < styleSheet.cssRules.length; ++curRule) { 311 var rule = styleSheet.cssRules[curRule]; 312 var textLength = rule.cssText ? rule.cssText.length : 0; 310 for (var curRule = 0; curRule < styleSheet.rules.length; ++curRule) { 311 var rule = styleSheet.rules[curRule]; 312 // FIXME: replace this by an exact computation once source ranges are available 313 var textLength = rule.style.cssText ? rule.style.cssText.length + rule.selectorText.length : 0; 313 314 stylesheetSize += textLength; 314 315 if (!testedSelectors[rule.selectorText] || foundSelectors[rule.selectorText]) … … 323 324 continue; 324 325 325 var url = styleSheet. href ? WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.href) : String.sprintf("Inline block #%d", ++inlineBlockOrdinal);326 var url = styleSheet.sourceURL ? WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.sourceURL) : String.sprintf("Inline block #%d", ++inlineBlockOrdinal); 326 327 var pctUnused = Math.round(100 * unusedStylesheetSize / stylesheetSize); 327 328 if (!summary) … … 658 659 src = completeSrc; 659 660 660 const computedStyle = new WebInspector.CSSStyleDeclaration(styles.computedStyle);661 const computedStyle = WebInspector.CSSStyleDeclaration.parsePayload(styles.computedStyle); 661 662 if (computedStyle.getPropertyValue("position") === "absolute") { 662 663 if (!context.imagesLeft) … … 669 670 670 671 for (var i = styles.matchedCSSRules.length - 1; i >= 0 && !(widthFound && heightFound); --i) { 671 var style = WebInspector.CSS StyleDeclaration.parseRule(styles.matchedCSSRules[i]).style;672 var style = WebInspector.CSSRule.parsePayload(styles.matchedCSSRules[i]).style; 672 673 if (style.getPropertyValue("width") !== "") 673 674 widthFound = true; -
trunk/WebCore/inspector/front-end/CSSStyleModel.js
r70046 r70772 33 33 } 34 34 35 WebInspector.CSSStyleModel.parseRuleArrayPayload = function(ruleArray) 36 { 37 var result = []; 38 for (var i = 0; i < ruleArray.length; ++i) 39 result.push(WebInspector.CSSRule.parsePayload(ruleArray[i])); 40 return result; 41 } 42 35 43 WebInspector.CSSStyleModel.prototype = { 36 getStylesAsync: function(nodeId, authOnly,userCallback)44 getStylesAsync: function(nodeId, userCallback) 37 45 { 38 InspectorBackend.getStyles(nodeId, authOnly, userCallback); 46 function callback(userCallback, payload) 47 { 48 if (!payload) { 49 if (userCallback) 50 userCallback(null); 51 return; 52 } 53 54 var result = {}; 55 if ("inlineStyle" in payload) 56 result.inlineStyle = WebInspector.CSSStyleDeclaration.parsePayload(payload.inlineStyle); 57 58 result.computedStyle = WebInspector.CSSStyleDeclaration.parsePayload(payload.computedStyle); 59 result.matchedCSSRules = WebInspector.CSSStyleModel.parseRuleArrayPayload(payload.matchedCSSRules); 60 61 result.styleAttributes = {}; 62 for (var name in payload.styleAttributes) 63 result.styleAttributes[name] = WebInspector.CSSStyleDeclaration.parsePayload(payload.styleAttributes[name]); 64 65 result.pseudoElements = []; 66 for (var i = 0; i < payload.pseudoElements.length; ++i) { 67 var entryPayload = payload.pseudoElements[i]; 68 result.pseudoElements.push({ pseudoId: entryPayload.pseudoId, rules: WebInspector.CSSStyleModel.parseRuleArrayPayload(entryPayload.rules) }); 69 } 70 71 result.inherited = []; 72 for (var i = 0; i < payload.inherited.length; ++i) { 73 var entryPayload = payload.inherited[i]; 74 var entry = {}; 75 if ("inlineStyle" in entryPayload) 76 entry.inlineStyle = WebInspector.CSSStyleDeclaration.parsePayload(entryPayload.inlineStyle); 77 if ("matchedCSSRules" in entryPayload) 78 entry.matchedCSSRules = WebInspector.CSSStyleModel.parseRuleArrayPayload(entryPayload.matchedCSSRules); 79 result.inherited.push(entry); 80 } 81 82 if (userCallback) 83 userCallback(result); 84 } 85 86 InspectorBackend.getStyles(nodeId, false, callback.bind(null, userCallback)); 39 87 }, 40 88 41 89 getComputedStyleAsync: function(nodeId, userCallback) 42 90 { 43 InspectorBackend.getComputedStyle(nodeId, userCallback); 91 function callback(userCallback, stylePayload) 92 { 93 if (!stylePayload) 94 userCallback(null); 95 else 96 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(stylePayload)); 97 } 98 99 InspectorBackend.getComputedStyle(nodeId, callback.bind(null, userCallback)); 100 }, 101 102 getInlineStyleAsync: function(nodeId, userCallback) 103 { 104 function callback(userCallback, stylePayload) 105 { 106 if (!stylePayload) 107 userCallback(null); 108 else 109 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(stylePayload)); 110 } 111 112 InspectorBackend.getInlineStyle(nodeId, callback.bind(null, userCallback)); 44 113 }, 45 114 … … 74 143 }, 75 144 76 toggleStyleEnabled: function(styleId, propertyName, disabled, userCallback)77 {78 function callback(newPayload)79 {80 if (!newPayload) {81 userCallback(null);82 return;83 }84 85 var newStyle = WebInspector.CSSStyleDeclaration.parseStyle(newPayload);86 userCallback(newStyle);87 }88 89 InspectorBackend.toggleStyleEnabled(styleId, propertyName, disabled, callback);90 },91 92 145 setCSSText: function(styleId, cssText) 93 146 { 94 147 InspectorBackend.setStyleText(styleId, cssText); 95 },96 97 applyStyleText: function(styleId, styleText, propertyName, successCallback, failureCallback)98 {99 function callback(success, newPayload)100 {101 if (!success)102 failureCallback();103 else {104 var newStyle = newPayload ? WebInspector.CSSStyleDeclaration.parseStyle(newPayload) : null;105 successCallback(newStyle);106 }107 }108 109 InspectorBackend.applyStyleText(styleId, styleText, propertyName, callback);110 148 } 111 149 } -
trunk/WebCore/inspector/front-end/DOMAgent.js
r69947 r70772 527 527 WebInspector.CSSStyleDeclaration = function(payload) 528 528 { 529 this.id = payload.id; 530 this.parentStyleSheetId = payload.parentStyleSheetId; 531 this.width = payload.width; 532 this.height = payload.height; 533 this.__disabledProperties = {}; 534 this.__disabledPropertyValues = {}; 535 this.__disabledPropertyPriorities = {}; 536 if (payload.disabled) { 537 for (var i = 0; i < payload.disabled.length; ++i) { 538 var property = payload.disabled[i]; 539 this.__disabledProperties[property.name] = true; 540 this.__disabledPropertyValues[property.name] = property.value; 541 this.__disabledPropertyPriorities[property.name] = property.priority; 542 } 543 } 544 529 this.id = payload.styleId; 530 this.properties = payload.properties; 545 531 this._shorthandValues = payload.shorthandValues; 546 this._propertyMap = {}; 547 this._longhandProperties = {}; 548 this.length = payload.properties.length; 549 550 for (var i = 0; i < this.length; ++i) { 551 var property = payload.properties[i]; 532 this._livePropertyMap = {}; // LIVE properties (source-based or style-based) : { name -> CSSProperty } 533 this._allProperties = []; // ALL properties: [ CSSProperty ] 534 this._longhandProperties = {}; // shorthandName -> [ CSSProperty ] 535 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProperty } 536 var payloadPropertyCount = payload.cssProperties.length; 537 538 var propertyIndex = 0; 539 for (var i = 0; i < payloadPropertyCount; ++i) { 540 var property = new WebInspector.CSSProperty.parsePayload(this, i, payload.cssProperties[i]); 541 this._allProperties.push(property); 542 if (property.disabled) 543 this.__disabledProperties[i] = property; 544 if (!property.active && !property.styleBased) 545 continue; 552 546 var name = property.name; 553 this[ i] = name;554 this._ propertyMap[name] = property;547 this[propertyIndex] = name; 548 this._livePropertyMap[name] = property; 555 549 556 550 // Index longhand properties. 557 if (property.shorthand) { 551 if (property.shorthand) { // only for parsed 558 552 var longhands = this._longhandProperties[property.shorthand]; 559 553 if (!longhands) { … … 561 555 this._longhandProperties[property.shorthand] = longhands; 562 556 } 563 longhands.push(name); 564 } 565 } 566 } 567 568 WebInspector.CSSStyleDeclaration.parseStyle = function(payload) 557 longhands.push(property); 558 } 559 ++propertyIndex; 560 } 561 this.length = propertyIndex; 562 } 563 564 WebInspector.CSSStyleDeclaration.parsePayload = function(payload) 569 565 { 570 566 return new WebInspector.CSSStyleDeclaration(payload); 571 567 } 572 568 573 WebInspector.CSSStyleDeclaration.parseRule = function(payload)574 {575 var rule = {};576 rule.id = payload.id;577 rule.selectorText = payload.selectorText;578 rule.style = new WebInspector.CSSStyleDeclaration(payload.style);579 rule.style.parentRule = rule;580 rule.isUserAgent = payload.isUserAgent;581 rule.isUser = payload.isUser;582 rule.isViaInspector = payload.isViaInspector;583 rule.sourceLine = payload.sourceLine;584 rule.documentURL = payload.documentURL;585 if (payload.parentStyleSheet)586 rule.parentStyleSheet = { href: payload.parentStyleSheet.href };587 588 return rule;589 }590 591 569 WebInspector.CSSStyleDeclaration.prototype = { 570 get allProperties() 571 { 572 return this._allProperties; 573 }, 574 575 getLiveProperty: function(name) 576 { 577 return this._livePropertyMap[name]; 578 }, 579 592 580 getPropertyValue: function(name) 593 581 { 594 var property = this._ propertyMap[name];582 var property = this._livePropertyMap[name]; 595 583 return property ? property.value : ""; 596 584 }, … … 598 586 getPropertyPriority: function(name) 599 587 { 600 var property = this._ propertyMap[name];588 var property = this._livePropertyMap[name]; 601 589 return property ? property.priority : ""; 602 590 }, … … 604 592 getPropertyShorthand: function(name) 605 593 { 606 var property = this._ propertyMap[name];594 var property = this._livePropertyMap[name]; 607 595 return property ? property.shorthand : ""; 608 596 }, … … 610 598 isPropertyImplicit: function(name) 611 599 { 612 var property = this._ propertyMap[name];600 var property = this._livePropertyMap[name]; 613 601 return property ? property.implicit : ""; 614 602 }, … … 652 640 getShorthandValue: function(shorthandProperty) 653 641 { 654 return this._shorthandValues[shorthandProperty]; 642 var property = this.getLiveProperty(shorthandProperty); 643 return property ? property.value : this._shorthandValues[shorthandProperty]; 655 644 }, 656 645 … … 663 652 var longhands = this._longhandProperties[shorthandProperty]; 664 653 return longhands ? this.getPropertyPriority(longhands[0]) : null; 654 }, 655 656 appendProperty: function(propertyName, propertyValue, userCallback) 657 { 658 function setPropertyCallback(userCallback, success, stylePayload) 659 { 660 if (!success) 661 userCallback(null); 662 else 663 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(stylePayload)); 664 } 665 666 // FIXME(apavlov): this should be migrated to the new InspectorCSSAgent API once it is enabled. 667 InspectorBackend.applyStyleText(this.id, propertyName + ": " + propertyValue + ";", propertyName, setPropertyCallback.bind(this, userCallback)); 668 }, 669 670 propertyAt: function(index) 671 { 672 return (index < this.allProperties.length) ? this.allProperties[index] : null; 673 } 674 } 675 676 WebInspector.CSSRule = function(payload) 677 { 678 this.id = payload.ruleId; 679 this.selectorText = payload.selectorText; 680 this.sourceLine = payload.sourceLine; 681 this.sourceURL = payload.sourceURL; 682 this.origin = payload.origin; 683 this.style = WebInspector.CSSStyleDeclaration.parsePayload(payload.style); 684 this.style.parentRule = this; 685 } 686 687 WebInspector.CSSRule.parsePayload = function(payload) 688 { 689 return new WebInspector.CSSRule(payload); 690 } 691 692 WebInspector.CSSRule.prototype = { 693 get isUserAgent() 694 { 695 return this.origin === "user-agent"; 696 }, 697 698 get isUser() 699 { 700 return this.origin === "user"; 701 }, 702 703 get isViaInspector() 704 { 705 return this.origin === "inspector"; 706 }, 707 708 get isRegular() 709 { 710 return this.origin === ""; 711 } 712 } 713 714 WebInspector.CSSProperty = function(ownerStyle, index, name, value, priority, status, parsedOk, implicit, shorthand, text) 715 { 716 this.ownerStyle = ownerStyle; 717 this.index = index; 718 this.name = name; 719 this.value = value; 720 this.priority = priority; 721 this.status = status; 722 this.parsedOk = parsedOk; 723 this.implicit = implicit; 724 this.shorthand = shorthand; 725 this.text = text; 726 } 727 728 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) 729 { 730 var result = new WebInspector.CSSProperty( 731 ownerStyle, index, payload.name, payload.value, payload.priority, payload.status, payload.parsedOk, payload.implicit, payload.shorthandName, payload.text); 732 return result; 733 } 734 735 WebInspector.CSSProperty.prototype = { 736 get propertyText() 737 { 738 if (this.text !== undefined) 739 return this.text; 740 741 return this.name + ": " + this.value + (this.priority ? " !" + this.priority : "") + ";"; 742 }, 743 744 get isLive() 745 { 746 return this.active || this.styleBased; 747 }, 748 749 get active() 750 { 751 return this.status === "active"; 752 }, 753 754 get styleBased() 755 { 756 return this.status === "style"; 757 }, 758 759 get inactive() 760 { 761 return this.status === "inactive"; 762 }, 763 764 get disabled() 765 { 766 return this.status === "disabled"; 767 }, 768 769 // Replaces "propertyName: propertyValue [!important];" in the stylesheet by an arbitrary propertyText. 770 setText: function(propertyText, userCallback) 771 { 772 function callback(userCallback, success, stylePayload) 773 { 774 if (!userCallback) 775 return; 776 if (!success) 777 userCallback(null); 778 else { 779 var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload); 780 userCallback(style); 781 } 782 } 783 784 if (!this.ownerStyle) 785 throw "No ownerStyle for property"; 786 InspectorBackend.applyStyleText(this.ownerStyle.id, propertyText, this.name, callback.bind(this, userCallback)); 787 }, 788 789 setValue: function(newValue, userCallback) 790 { 791 var text = this.name + ": " + newValue + (this.priority ? " !" + this.priority : "") + ";" 792 this.setText(text, userCallback); 793 }, 794 795 setDisabled: function(disabled, userCallback) 796 { 797 if (!this.ownerStyle && userCallback) 798 userCallback(null); 799 if (disabled === this.disabled && userCallback) 800 userCallback(this.ownerStyle); 801 802 function callback(userCallback, stylePayload) 803 { 804 if (!userCallback) 805 return; 806 if (!stylePayload) 807 userCallback(null); 808 else { 809 var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload); 810 userCallback(style); 811 } 812 } 813 InspectorBackend.toggleStyleEnabled(this.ownerStyle.id, this.name, disabled, callback.bind(this, userCallback)); 665 814 } 666 815 } -
trunk/WebCore/inspector/front-end/MetricsSidebarPane.js
r66087 r70772 47 47 48 48 var self = this; 49 var callback = function(style Payload) {50 if (!style Payload)49 var callback = function(style) { 50 if (!style) 51 51 return; 52 var style = WebInspector.CSSStyleDeclaration.parseStyle(stylePayload);53 52 self._update(style); 54 53 }; 55 InspectorBackend.getComputedStyle(node.id, callback);56 57 var inlineStyleCallback = function(style Payload) {58 if (!style Payload)54 WebInspector.cssModel.getComputedStyleAsync(node.id, callback); 55 56 var inlineStyleCallback = function(style) { 57 if (!style) 59 58 return; 60 self. _inlineStyleId = stylePayload.id;61 }; 62 InspectorBackend.getInlineStyle(node.id, inlineStyleCallback);59 self.inlineStyle = style; 60 }; 61 WebInspector.cssModel.getInlineStyleAsync(node.id, inlineStyleCallback); 63 62 }, 64 63 65 64 _update: function(style) 66 65 { 66 // Updating with computed style. 67 67 var metricsElement = document.createElement("div"); 68 68 metricsElement.className = "metrics"; … … 117 117 var name = boxes[i]; 118 118 119 if (name === "margin" && noMarginDisplayType[style. display])120 continue; 121 if (name === "padding" && noPaddingDisplayType[style. display])122 continue; 123 if (name === "position" && noPositionType[style. position])119 if (name === "margin" && noMarginDisplayType[style.getPropertyValue("display")]) 120 continue; 121 if (name === "padding" && noPaddingDisplayType[style.getPropertyValue("display")]) 122 continue; 123 if (name === "position" && noPositionType[style.getPropertyValue("position")]) 124 124 continue; 125 125 … … 128 128 129 129 if (name === "content") { 130 var width = style. width.replace(/px$/, "");130 var width = style.getPropertyValue("width").replace(/px$/, ""); 131 131 var widthElement = document.createElement("span"); 132 132 widthElement.textContent = width; 133 133 widthElement.addEventListener("dblclick", this.startEditing.bind(this, widthElement, "width", "width"), false); 134 134 135 var height = style. height.replace(/px$/, "");135 var height = style.getPropertyValue("height").replace(/px$/, ""); 136 136 var heightElement = document.createElement("span"); 137 137 heightElement.textContent = height; … … 186 186 editingCommitted: function(element, userInput, previousContent, context) 187 187 { 188 if (!this. _inlineStyleId) {188 if (!this.inlineStyle) { 189 189 // Element has no renderer. 190 190 return this.editingCancelled(element, context); // nothing changed, so cancel … … 204 204 205 205 var self = this; 206 var callback = function(s uccess) {207 if (!s uccess)206 var callback = function(style) { 207 if (!style) 208 208 return; 209 self.inlineStyle = style; 209 210 self.dispatchEventToListeners("metrics edited"); 210 211 self.update(); 211 212 }; 212 213 213 InspectorBackend.setStyleProperty(this._inlineStyleId, context.styleProperty, userInput, callback); 214 function setEnabledValueCallback(context, style) 215 { 216 var property = style.getLiveProperty(context.styleProperty); 217 if (!property) 218 style.appendProperty(context.styleProperty, userInput, callback); 219 else 220 property.setValue(userInput, callback); 221 } 222 223 var allProperties = this.inlineStyle.allProperties; 224 for (var i = 0; i < allProperties.length; ++i) { 225 var property = allProperties[i]; 226 if (property.name !== context.styleProperty || property.inactive) 227 continue; 228 if (property.disabled) 229 property.setDisabled(false, setEnabledValueCallback.bind(null, context)); 230 else 231 property.setValue(userInput, callback); 232 return; 233 } 234 235 this.inlineStyle.appendProperty(context.styleProperty, userInput, callback); 214 236 } 215 237 } -
trunk/WebCore/inspector/front-end/StylesSidebarPane.js
r70622 r70772 156 156 WebInspector.cssModel.getComputedStyleAsync(node.id, computedStyleCallback.bind(this)); 157 157 else 158 WebInspector.cssModel.getStylesAsync(node.id, !WebInspector.applicationSettings.showUserAgentStyles,stylesCallback.bind(this));158 WebInspector.cssModel.getStylesAsync(node.id, stylesCallback.bind(this)); 159 159 }, 160 160 … … 197 197 // Add rules in reverse order to match the cascade order. 198 198 for (var j = pseudoElementCSSRules.rules.length - 1; j >= 0; --j) { 199 var rule = WebInspector.CSSStyleDeclaration.parseRule(pseudoElementCSSRules.rules[j]);200 styleRules.push({ style: rule.style, selectorText: rule.selectorText, parentStyleSheet: rule.parentStyleSheet, rule: rule });199 var rule = pseudoElementCSSRules.rules[j]; 200 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule }); 201 201 } 202 202 usedProperties = {}; … … 209 209 _refreshStyleRules: function(sections, computedStyle) 210 210 { 211 var nodeComputedStyle = new WebInspector.CSSStyleDeclaration(computedStyle);211 var nodeComputedStyle = computedStyle; 212 212 var styleRules = []; 213 213 for (var i = 0; sections && i < sections.length; ++i) { … … 225 225 _rebuildStyleRules: function(node, styles) 226 226 { 227 var nodeComputedStyle = new WebInspector.CSSStyleDeclaration(styles.computedStyle);227 var nodeComputedStyle = styles.computedStyle; 228 228 this.sections = {}; 229 229 … … 234 234 var styleAttributes = {}; 235 235 for (var name in styles.styleAttributes) { 236 var attrStyle = { style: new WebInspector.CSSStyleDeclaration(styles.styleAttributes[name]), editable: false };236 var attrStyle = { style: styles.styleAttributes[name], editable: false }; 237 237 attrStyle.selectorText = WebInspector.panels.elements.treeOutline.nodeNameToCorrectCase(node.nodeName) + "[" + name; 238 238 if (node.getAttribute(name)) … … 244 244 // Show element's Style Attributes 245 245 if (styles.inlineStyle && node.nodeType === Node.ELEMENT_NODE) { 246 var inlineStyle = { selectorText: "element.style", style: new WebInspector.CSSStyleDeclaration(styles.inlineStyle), isAttribute: true };246 var inlineStyle = { selectorText: "element.style", style: styles.inlineStyle, isAttribute: true }; 247 247 styleRules.push(inlineStyle); 248 248 } … … 252 252 styleRules.push({ isStyleSeparator: true, text: WebInspector.UIString("Matched CSS Rules") }); 253 253 for (var i = styles.matchedCSSRules.length - 1; i >= 0; --i) { 254 var rule = WebInspector.CSSStyleDeclaration.parseRule(styles.matchedCSSRules[i]);255 styleRules.push({ style: rule.style, selectorText: rule.selectorText, parentStyleSheet: rule.parentStyleSheet, rule: rule });254 var rule = styles.matchedCSSRules[i]; 255 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule }); 256 256 } 257 257 258 258 // Walk the node structure and identify styles with inherited properties. 259 var parentStyles = styles.parent;260 259 var parentNode = node.parentNode; 261 260 function insertInheritedNodeSeparator(node) … … 267 266 } 268 267 269 while (parentStyles) { 268 for (var parentOrdinal = 0; parentOrdinal < styles.inherited.length; ++parentOrdinal) { 269 var parentStyles = styles.inherited[parentOrdinal]; 270 270 var separatorInserted = false; 271 271 if (parentStyles.inlineStyle) { 272 272 if (this._containsInherited(parentStyles.inlineStyle)) { 273 var inlineStyle = { selectorText: WebInspector.UIString("Style Attribute"), style: new WebInspector.CSSStyleDeclaration(parentStyles.inlineStyle), isAttribute: true, isInherited: true };273 var inlineStyle = { selectorText: WebInspector.UIString("Style Attribute"), style: parentStyles.inlineStyle, isAttribute: true, isInherited: true }; 274 274 if (!separatorInserted) { 275 275 insertInheritedNodeSeparator(parentNode); … … 284 284 if (!this._containsInherited(rulePayload.style)) 285 285 continue; 286 var rule = WebInspector.CSSStyleDeclaration.parseRule(rulePayload);286 var rule = rulePayload; 287 287 if (!separatorInserted) { 288 288 insertInheritedNodeSeparator(parentNode); 289 289 separatorInserted = true; 290 290 } 291 styleRules.push({ style: rule.style, selectorText: rule.selectorText, parentStyleSheet: rule.parentStyleSheet, rule: rule, isInherited: true }); 292 } 293 parentStyles = parentStyles.parent; 291 styleRules.push({ style: rule.style, selectorText: rule.selectorText, sourceURL: rule.sourceURL, rule: rule, isInherited: true }); 292 } 294 293 parentNode = parentNode.parentNode; 295 294 } … … 299 298 _markUsedProperties: function(styleRules, usedProperties, disabledComputedProperties) 300 299 { 301 function deleteDisabledProperty(style, name)302 {303 if (!style || !name)304 return;305 if (style.__disabledPropertyValues)306 delete style.__disabledPropertyValues[name];307 if (style.__disabledPropertyPriorities)308 delete style.__disabledPropertyPriorities[name];309 if (style.__disabledProperties)310 delete style.__disabledProperties[name];311 }312 313 300 var priorityUsed = false; 314 301 … … 324 311 325 312 var style = styleRule.style; 326 for (var j = 0; j < style.length; ++j) { 327 var name = style[j]; 328 329 if (!priorityUsed && style.getPropertyPriority(name).length) 313 var allProperties = style.allProperties; 314 for (var j = 0; j < allProperties.length; ++j) { 315 var property = allProperties[j]; 316 if (!property.isLive) 317 continue; 318 var name = property.name; 319 320 if (!priorityUsed && property.priority.length) 330 321 priorityUsed = true; 331 322 … … 346 337 styleRule.usedProperties["line-height"] = true; 347 338 } 348 349 // Delete any disabled properties, since the property does exist.350 // This prevents it from showing twice.351 deleteDisabledProperty(style, name);352 deleteDisabledProperty(style, style.getPropertyShorthand(name));353 339 } 354 340 … … 357 343 for (var name in styleRules[i].usedProperties) 358 344 usedProperties[name] = true; 359 360 // Remember all disabled properties so they show up in computed style.361 if (style.__disabledProperties)362 for (var name in style.__disabledProperties)363 disabledComputedProperties[name] = true;364 345 } 365 346 … … 374 355 375 356 var style = styleRules[i].style; 376 for (var j = 0; j < style.length; ++j) { 377 var name = style[j]; 378 if (style.getPropertyPriority(name).length) { 357 var allProperties = style.allProperties; 358 for (var j = 0; j < allProperties.length; ++j) { 359 var property = allProperties[j]; 360 if (!property.isLive) 361 continue; 362 var name = property.name; 363 if (property.priority.length) { 379 364 if (!(name in foundPriorityProperties)) 380 365 styleRules[i].usedProperties[name] = true; … … 460 445 }, 461 446 462 _containsInherited: function(payload) 463 { 464 if (this._arrayContainsInheritedProperty(payload.properties)) 465 return true; 466 if (payload.disabled && this._arrayContainsInheritedProperty(payload.disabled)) 467 return true; 468 return false; 469 }, 470 471 _arrayContainsInheritedProperty: function(properties) 472 { 447 _containsInherited: function(style) 448 { 449 var properties = style.allProperties; 473 450 for (var i = 0; i < properties.length; ++i) { 474 451 var property = properties[i]; 475 452 // Does this style contain non-overridden inherited property? 476 if (property. name in WebInspector.StylesSidebarPane.InheritedProperties)453 if (property.isLive && property.name in WebInspector.StylesSidebarPane.InheritedProperties) 477 454 return true; 478 455 } … … 652 629 653 630 var subtitle = ""; 654 if (this.styleRule. parentStyleSheet && this.styleRule.parentStyleSheet.href)655 this.subtitleElement.appendChild(linkifyUncopyable(this.styleRule. parentStyleSheet.href, this.rule.sourceLine));631 if (this.styleRule.sourceURL) 632 this.subtitleElement.appendChild(linkifyUncopyable(this.styleRule.sourceURL, this.rule.sourceLine)); 656 633 else if (isUserAgent) 657 634 subtitle = WebInspector.UIString("user agent stylesheet"); … … 660 637 else if (isViaInspector) 661 638 subtitle = WebInspector.UIString("via inspector"); 662 else if (this.rule && this.rule. documentURL)663 this.subtitleElement.appendChild(linkifyUncopyable(this.rule. documentURL, this.rule.sourceLine));639 else if (this.rule && this.rule.sourceURL) 640 this.subtitleElement.appendChild(linkifyUncopyable(this.rule.sourceURL, this.rule.sourceLine)); 664 641 665 642 if (isInherited) … … 682 659 }, 683 660 684 isPropertyInherited: function(property )661 isPropertyInherited: function(propertyName) 685 662 { 686 663 if (this.isInherited) { 687 664 // While rendering inherited stylesheet, reverse meaning of this property. 688 665 // Render truly inherited properties with black, i.e. return them as non-inherited. 689 return !(property in WebInspector.StylesSidebarPane.InheritedProperties);666 return !(propertyName in WebInspector.StylesSidebarPane.InheritedProperties); 690 667 } 691 668 return false; 692 669 }, 693 670 694 isPropertyOverloaded: function(property , shorthand)671 isPropertyOverloaded: function(propertyName, shorthand) 695 672 { 696 673 if (!this._usedProperties || this.noAffect) 697 674 return false; 698 675 699 if (this.isInherited && !(property in WebInspector.StylesSidebarPane.InheritedProperties)) {676 if (this.isInherited && !(propertyName in WebInspector.StylesSidebarPane.InheritedProperties)) { 700 677 // In the inherited sections, only show overrides for the potentially inherited properties. 701 678 return false; 702 679 } 703 680 704 var used = (property in this._usedProperties);681 var used = (propertyName in this._usedProperties); 705 682 if (used || !shorthand) 706 683 return !used; … … 708 685 // Find out if any of the individual longhand properties of the shorthand 709 686 // are used, if none are then the shorthand is overloaded too. 710 var longhandProperties = this.styleRule.style.getLonghandProperties(property );687 var longhandProperties = this.styleRule.style.getLonghandProperties(propertyName); 711 688 for (var j = 0; j < longhandProperties.length; ++j) { 712 689 var individualProperty = longhandProperties[j]; 713 if (individualProperty in this._usedProperties)690 if (individualProperty.name in this._usedProperties) 714 691 return false; 715 692 } 716 693 717 694 return true; 718 },719 720 isPropertyDisabled: function(property)721 {722 if (!this.styleRule.style.__disabledPropertyValues)723 return false;724 return property in this.styleRule.style.__disabledPropertyValues;725 695 }, 726 696 … … 750 720 onpopulate: function() 751 721 { 722 function sorter(a, b) 723 { 724 return a.name.localeCompare(b.name); 725 } 726 752 727 var style = this.styleRule.style; 753 728 754 var foundShorthands = {};755 var disabledProperties = style.__disabledPropertyValues ||{};729 var handledProperties = {}; 730 var shorthandNames = {}; 756 731 757 732 this.uniqueProperties = []; 758 for (var i = 0; i < style.length; ++i) 759 this.uniqueProperties.push(style[i]); 760 761 for (var name in disabledProperties) 762 this.uniqueProperties.push(name); 763 764 this.uniqueProperties.sort(); 765 733 var allProperties = style.allProperties; 734 for (var i = 0; i < allProperties.length; ++i) 735 this.uniqueProperties.push(allProperties[i]); 736 737 this.uniqueProperties.sort(sorter); 738 739 // Collect all shorthand names. 766 740 for (var i = 0; i < this.uniqueProperties.length; ++i) { 767 var name = this.uniqueProperties[i]; 768 var disabled = name in disabledProperties; 769 var shorthand = !disabled ? style.getPropertyShorthand(name) : null; 770 771 if (shorthand && shorthand in foundShorthands) 741 var property = this.uniqueProperties[i]; 742 if (property.disabled) 772 743 continue; 744 if (property.shorthand) 745 shorthandNames[property.shorthand] = true; 746 } 747 748 for (var i = 0; i < this.uniqueProperties.length; ++i) { 749 var property = this.uniqueProperties[i]; 750 var disabled = property.disabled; 751 if (!disabled && this.disabledComputedProperties && !(property.name in this.usedProperties) && property.name in this.disabledComputedProperties) 752 disabled = true; 753 754 var shorthand = !disabled ? property.shorthand : null; 755 756 if (shorthand && shorthand in handledProperties) 757 continue; 773 758 774 759 if (shorthand) { 775 foundShorthands[shorthand] = true; 776 name = shorthand; 777 } 778 779 var isShorthand = (shorthand ? true : false); 780 var inherited = this.isPropertyInherited(name); 781 var overloaded = this.isPropertyOverloaded(name, isShorthand); 782 783 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, style, name, isShorthand, inherited, overloaded, disabled); 760 property = style.getLiveProperty(shorthand); 761 if (!property) 762 property = new WebInspector.CSSProperty(style, style.allProperties.length, shorthand, style.getShorthandValue(shorthand), style.getShorthandPriority(shorthand), "style", true, true, ""); 763 } 764 765 var isShorthand = !!(property.isLive && (shorthand || shorthandNames[property.name])); 766 var inherited = this.isPropertyInherited(property.name); 767 var overloaded = this.isPropertyOverloaded(property.name, isShorthand); 768 769 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, style, property, isShorthand, inherited, overloaded); 784 770 this.propertiesTreeOutline.appendChild(item); 771 handledProperties[property.name] = property; 785 772 } 786 773 }, … … 799 786 addNewBlankProperty: function() 800 787 { 801 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, this.styleRule.style, "", false, false, false, false); 788 var style = this.styleRule.style; 789 var property = new WebInspector.CSSProperty(style, style.allProperties.length, "", "", "", "style", true, false, false, undefined); 790 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, style, "", false, false, false, false); 802 791 this.propertiesTreeOutline.appendChild(item); 803 792 item.listItemElement.textContent = ""; … … 885 874 886 875 self.rule = newRule; 887 self.styleRule = { section: self, style: newRule.style, selectorText: newRule.selectorText, parentStyleSheet: newRule.parentStyleSheet, rule: newRule };876 self.styleRule = { section: self, style: newRule.style, selectorText: newRule.selectorText, sourceURL: newRule.sourceURL, rule: newRule }; 888 877 889 878 var oldIdentifier = this.identifier; … … 928 917 }, 929 918 930 _isPropertyInherited: function(property )931 { 932 return !(property in this._usedProperties) && !(property in this._alwaysShowComputedProperties) && !(propertyin this._disabledComputedProperties);919 _isPropertyInherited: function(propertyName) 920 { 921 return !(propertyName in this._usedProperties) && !(propertyName in this._alwaysShowComputedProperties) && !(propertyName in this._disabledComputedProperties); 933 922 }, 934 923 … … 947 936 onpopulate: function() 948 937 { 938 function sorter(a, b) 939 { 940 return a.name.localeCompare(b.name); 941 } 942 949 943 var style = this.styleRule.style; 950 944 var uniqueProperties = []; 951 for (var i = 0; i < style.length; ++i) 952 uniqueProperties.push(style[i]); 953 uniqueProperties.sort(); 945 var allProperties = style.allProperties; 946 for (var i = 0; i < allProperties.length; ++i) 947 uniqueProperties.push(allProperties[i]); 948 uniqueProperties.sort(sorter); 954 949 955 950 this._propertyTreeElements = {}; 956 951 for (var i = 0; i < uniqueProperties.length; ++i) { 957 var name= uniqueProperties[i];958 var inherited = this._isPropertyInherited( name);959 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, style, name, false, inherited, false, false);952 var property = uniqueProperties[i]; 953 var inherited = this._isPropertyInherited(property.name); 954 var item = new WebInspector.StylePropertyTreeElement(this.styleRule, style, property, false, inherited, false, false); 960 955 this.propertiesTreeOutline.appendChild(item); 961 this._propertyTreeElements[ name] = item;956 this._propertyTreeElements[property.name] = item; 962 957 } 963 958 }, … … 971 966 972 967 for (var j = 0; j < section.uniqueProperties.length; ++j) { 973 var name= section.uniqueProperties[j];974 if ( section.isPropertyDisabled(name))968 var property = section.uniqueProperties[j]; 969 if (property.disabled) 975 970 continue; 976 if (section.isInherited && !( name in WebInspector.StylesSidebarPane.InheritedProperties))971 if (section.isInherited && !(property.name in WebInspector.StylesSidebarPane.InheritedProperties)) 977 972 continue; 978 973 979 var treeElement = this._propertyTreeElements[ name];974 var treeElement = this._propertyTreeElements[property.name]; 980 975 if (treeElement) { 981 976 var selectorText = section.styleRule.selectorText; 982 var value = section.styleRule.style.getPropertyValue(name);977 var value = property.value; 983 978 var title = "<span style='color: gray'>" + selectorText + "</span> - " + value; 984 979 var subtitle = " <span style='float:right'>" + section.subtitleElement.innerHTML + "</span>"; 985 980 var childElement = new TreeElement(title + subtitle, null, false); 986 981 treeElement.appendChild(childElement); 987 if (section.isPropertyOverloaded( name))982 if (section.isPropertyOverloaded(property.name)) 988 983 childElement.listItemElement.addStyleClass("overloaded"); 989 984 } … … 1051 1046 WebInspector.BlankStylePropertiesSection.prototype.__proto__ = WebInspector.StylePropertiesSection.prototype; 1052 1047 1053 WebInspector.StylePropertyTreeElement = function(styleRule, style, name, shorthand, inherited, overloaded, disabled)1048 WebInspector.StylePropertyTreeElement = function(styleRule, style, property, shorthand, inherited, overloaded) 1054 1049 { 1055 1050 this._styleRule = styleRule; 1056 1051 this.style = style; 1057 this. name = name;1052 this.property = property; 1058 1053 this.shorthand = shorthand; 1059 1054 this._inherited = inherited; 1060 1055 this._overloaded = overloaded; 1061 this._disabled = disabled;1062 1056 1063 1057 // Pass an empty title, the title gets made later in onattach. … … 1094 1088 get disabled() 1095 1089 { 1096 return this._disabled; 1097 }, 1098 1099 set disabled(x) 1100 { 1101 if (x === this._disabled) 1102 return; 1103 this._disabled = x; 1104 this.updateState(); 1090 return this.property.disabled; 1091 }, 1092 1093 get name() 1094 { 1095 return this.property.name; 1105 1096 }, 1106 1097 1107 1098 get priority() 1108 1099 { 1109 if (this.disabled && this.style.__disabledPropertyPriorities && this.name in this.style.__disabledPropertyPriorities)1110 return this. style.__disabledPropertyPriorities[this.name];1111 return (this.shorthand ? this.style.getShorthandPriority(this.name) : this. style.getPropertyPriority(this.name));1100 if (this.disabled) 1101 return this.property.priority; 1102 return (this.shorthand ? this.style.getShorthandPriority(this.name) : this.property.priority); 1112 1103 }, 1113 1104 1114 1105 get value() 1115 1106 { 1116 if (this.disabled && this.style.__disabledPropertyValues && this.name in this.style.__disabledPropertyValues) 1117 return this.style.__disabledPropertyValues[this.name]; 1118 return (this.shorthand ? this.style.getShorthandValue(this.name) : this.style.getPropertyValue(this.name)); 1107 if (this.disabled) 1108 return this.property.value; 1109 return (this.shorthand ? this.style.getShorthandValue(this.name) : this.property.value); 1110 }, 1111 1112 get parsedOk() 1113 { 1114 return this.property.parsedOk; 1119 1115 }, 1120 1116 … … 1136 1132 this.updateState(); 1137 1133 1138 var enabledCheckboxElement = document.createElement("input"); 1139 enabledCheckboxElement.className = "enabled-button"; 1140 enabledCheckboxElement.type = "checkbox"; 1141 enabledCheckboxElement.checked = !this.disabled; 1142 enabledCheckboxElement.addEventListener("change", this.toggleEnabled.bind(this), false); 1134 var enabledCheckboxElement; 1135 if (this.parsedOk) { 1136 enabledCheckboxElement = document.createElement("input"); 1137 enabledCheckboxElement.className = "enabled-button"; 1138 enabledCheckboxElement.type = "checkbox"; 1139 enabledCheckboxElement.checked = !this.disabled; 1140 enabledCheckboxElement.addEventListener("change", this.toggleEnabled.bind(this), false); 1141 } 1143 1142 1144 1143 var nameElement = document.createElement("span"); … … 1289 1288 1290 1289 // Append the checkbox for root elements of an editable section. 1291 if ( this.treeOutline.section && this.treeOutline.section.editable && this.parent.root)1290 if (enabledCheckboxElement && this.treeOutline.section && this.treeOutline.section.editable && this.parent.root) 1292 1291 this.listItemElement.appendChild(enabledCheckboxElement); 1293 1292 this.listItemElement.appendChild(nameElement); … … 1302 1301 this.listItemElement.appendChild(document.createTextNode(";")); 1303 1302 1304 this.tooltip = this. name + ": " + valueElement.textContent + (priority ? " " + priority : "");1303 this.tooltip = this.property.propertyText; 1305 1304 }, 1306 1305 … … 1314 1313 this.treeOutline.section.update(true); 1315 1314 else 1316 this.updateTitle(); // FIXME: this will not show new properties. But we don't hit his case yet.1315 this.updateTitle(); // FIXME: this will not show new properties. But we don't hit this case yet. 1317 1316 }, 1318 1317 … … 1321 1320 var disabled = !event.target.checked; 1322 1321 1323 var self = this;1324 1322 function callback(newStyle) 1325 1323 { … … 1327 1325 return; 1328 1326 1329 self.style = newStyle; 1330 self._styleRule.style = self.style; 1331 1332 // Set the disabled property here, since the code above replies on it not changing 1333 // until after the value and priority are retrieved. 1334 self.disabled = disabled; 1335 1336 if (self.treeOutline.section && self.treeOutline.section.pane) 1337 self.treeOutline.section.pane.dispatchEventToListeners("style property toggled"); 1338 1339 self.updateAll(true); 1340 } 1341 1342 WebInspector.cssModel.toggleStyleEnabled(this.style.id, this.name, disabled, callback); 1327 this.style = newStyle; 1328 this._styleRule.style = newStyle; 1329 1330 if (this.treeOutline.section && this.treeOutline.section.pane) 1331 this.treeOutline.section.pane.dispatchEventToListeners("style property toggled"); 1332 1333 this.updateAll(true); 1334 } 1335 1336 this.property.setDisabled(disabled, callback.bind(this)); 1343 1337 }, 1344 1338 … … 1377 1371 var longhandProperties = this.style.getLonghandProperties(this.name); 1378 1372 for (var i = 0; i < longhandProperties.length; ++i) { 1379 var name = longhandProperties[i]; 1373 var name = longhandProperties[i].name; 1374 1380 1375 1381 1376 if (this.treeOutline.section) { … … 1384 1379 } 1385 1380 1386 var item = new WebInspector.StylePropertyTreeElement(this._styleRule, this.style, name, false, inherited, overloaded); 1381 var liveProperty = this.style.getLiveProperty(name); 1382 var item = new WebInspector.StylePropertyTreeElement(this._styleRule, this.style, liveProperty, false, inherited, overloaded); 1387 1383 this.appendChild(item); 1388 1384 } … … 1672 1668 } 1673 1669 1674 var self = this; 1675 1676 function failureCallback() 1670 function callback(newStyle) 1677 1671 { 1678 // The user typed something, but it didn't parse. Just abort and restore 1679 // the original title for this property. If this was a new attribute and 1680 // we couldn't parse, then just remove it. 1681 if (self._newProperty) { 1682 self.parent.removeChild(self); 1672 if (!newStyle) { 1673 // The user typed something, but it didn't parse. Just abort and restore 1674 // the original title for this property. If this was a new attribute and 1675 // we couldn't parse, then just remove it. 1676 if (this._newProperty) { 1677 this.parent.removeChild(this); 1678 return; 1679 } 1680 if (updateInterface) 1681 this.updateTitle(); 1683 1682 return; 1684 1683 } 1685 if (updateInterface) 1686 self.updateTitle(); 1687 } 1688 1689 function successCallback(newStyle) 1690 { 1684 1691 1685 if (!styleTextLength) { 1692 1686 // Do remove ourselves from UI when the property removal is confirmed. 1693 self.parent.removeChild(self);1687 this.parent.removeChild(this); 1694 1688 } else { 1695 self.style = newStyle;1696 self._styleRule.style = self.style;1689 this.style = newStyle; 1690 this._styleRule.style = this.style; 1697 1691 } 1698 1692 … … 1701 1695 1702 1696 if (updateInterface) 1703 self.updateAll(true);1704 } 1705 1706 WebInspector.cssModel.applyStyleText(this.style.id, styleText, this.name, successCallback, failureCallback);1697 this.updateAll(true); 1698 } 1699 1700 this.property.setText(styleText, callback.bind(this)); 1707 1701 } 1708 1702 }
Note: See TracChangeset
for help on using the changeset viewer.