Changeset 56237 in webkit


Ignore:
Timestamp:
Mar 19, 2010 6:35:09 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-03-19 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: editing shorthands does not always work.

https://bugs.webkit.org/show_bug.cgi?id=36362

  • inspector/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::applyStyleText): (WebCore::InspectorDOMAgent::populateObjectWithStyleProperties): (WebCore::InspectorDOMAgent::shorthandValue):
  • inspector/InspectorDOMAgent.h:
  • inspector/front-end/StylesSidebarPane.js: (WebInspector.StylePropertyTreeElement.prototype):
  • inspector/front-end/inspector.css: (.section .properties li.disabled .enabled-button):
  • inspector/front-end/inspector.js: (WebInspector.startEditing.editingCommitted):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56236 r56237  
     12010-03-19  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: editing shorthands does not always work.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=36362
     8
     9        * inspector/InspectorDOMAgent.cpp:
     10        (WebCore::InspectorDOMAgent::applyStyleText):
     11        (WebCore::InspectorDOMAgent::populateObjectWithStyleProperties):
     12        (WebCore::InspectorDOMAgent::shorthandValue):
     13        * inspector/InspectorDOMAgent.h:
     14        * inspector/front-end/StylesSidebarPane.js:
     15        (WebInspector.StylePropertyTreeElement.prototype):
     16        * inspector/front-end/inspector.css:
     17        (.section .properties li.disabled .enabled-button):
     18        * inspector/front-end/inspector.js:
     19        (WebInspector.startEditing.editingCommitted):
     20
    1212010-03-19  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    222
  • trunk/WebCore/inspector/InspectorDOMAgent.cpp

    r56161 r56237  
    795795    int styleTextLength = styleText.length();
    796796
    797     // Create a new element to parse the user input CSS.
    798     ExceptionCode ec = 0;
    799     RefPtr<Element> parseElement = mainFrameDocument()->createElement("span", ec);
    800     if (!ec)
    801         parseElement->setAttribute("style", styleText, ec);
    802     if (ec) {
    803         m_frontend->didApplyStyleText(callId, false, ScriptValue::undefined(), m_frontend->newScriptArray());
    804         return;
    805     }
    806 
    807     CSSStyleDeclaration* tempStyle = parseElement->style();
    808     if ((tempStyle && tempStyle->length()) || !styleTextLength) {
     797    RefPtr<CSSMutableStyleDeclaration> tempMutableStyle = CSSMutableStyleDeclaration::create();
     798    tempMutableStyle->parseDeclaration(styleText);
     799    CSSStyleDeclaration* tempStyle = static_cast<CSSStyleDeclaration*>(tempMutableStyle.get());
     800
     801    if (tempStyle->length() || !styleTextLength) {
    809802        ExceptionCode ec = 0;
    810803        // The input was parsable or the user deleted everything, so remove the
     
    813806        if (style->getPropertyShorthand(propertyName).isEmpty()) {
    814807            Vector<String> longhandProps = longhandProperties(style, propertyName);
    815             for (unsigned i = 0; i < longhandProps.size(); ++i)
     808            for (unsigned i = 0; !ec && i < longhandProps.size(); ++i)
    816809                style->removeProperty(longhandProps[i], ec);
    817810        } else
     
    841834    Vector<String> changedProperties;
    842835
    843     Vector<String> uniqueProperties = uniqueStyleProperties(tempStyle);
    844     for (unsigned i = 0; i < uniqueProperties.size(); ++i) {
    845         String name = uniqueProperties[i];
     836    for (unsigned i = 0; i < tempStyle->length(); ++i) {
     837        String name = tempStyle->item(i);
    846838        String shorthand = tempStyle->getPropertyShorthand(name);
    847839
     
    852844        String priority;
    853845        if (!shorthand.isEmpty()) {
    854             value = tempStyle->getPropertyValue(shorthand);
     846            value = shorthandValue(tempStyle, shorthand);
    855847            priority = shorthandPriority(tempStyle, shorthand);
    856848            foundShorthands.add(shorthand);
     
    10631055        if (!shorthand.isEmpty() && !foundShorthands.contains(shorthand)) {
    10641056            foundShorthands.add(shorthand);
    1065             shorthandValues.set(shorthand, style->getPropertyValue(shorthand));
     1057            shorthandValues.set(shorthand, shorthandValue(style, shorthand));
    10661058        }
    10671059        property.set("value", style->getPropertyValue(name));
     
    11181110}
    11191111
    1120 Vector<String> InspectorDOMAgent::uniqueStyleProperties(CSSStyleDeclaration* style)
    1121 {
    1122     Vector<String> properties;
    1123     HashSet<String> foundProperties;
    1124 
    1125     for (unsigned i = 0; i < style->length(); ++i) {
    1126         String property = style->item(i);
    1127         if (foundProperties.contains(property))
    1128             continue;
    1129         foundProperties.add(property);
    1130         properties.append(property);
    1131     }
    1132     return properties;
    1133 }
    1134 
    11351112Vector<String> InspectorDOMAgent::longhandProperties(CSSStyleDeclaration* style, const String& shorthandProperty)
    11361113{
     
    11471124
    11481125    return properties;
     1126}
     1127
     1128String InspectorDOMAgent::shorthandValue(CSSStyleDeclaration* style, const String& shorthandProperty)
     1129{
     1130    String value = style->getPropertyValue(shorthandProperty);
     1131    if (value.isEmpty()) {
     1132        // Some shorthands (like border) return a null value, so compute a shorthand value.
     1133        // FIXME: remove this when http://bugs.webkit.org/show_bug.cgi?id=15823 is fixed.
     1134        for (unsigned i = 0; i < style->length(); ++i) {
     1135            String individualProperty = style->item(i);
     1136            if (style->getPropertyShorthand(individualProperty) != shorthandProperty)
     1137                continue;
     1138            if (style->isPropertyImplicit(individualProperty))
     1139                continue;
     1140            String individualValue = style->getPropertyValue(individualProperty);
     1141            if (individualValue == "initial")
     1142                continue;
     1143            if (value.length())
     1144                value.append(" ");
     1145            value.append(individualValue);
     1146        }
     1147    }
     1148    return value;
    11491149}
    11501150
  • trunk/WebCore/inspector/InspectorDOMAgent.h

    r56107 r56237  
    162162        ScriptObject buildObjectForRule(CSSStyleRule*);
    163163        ScriptObject buildObjectForStyleSheet(CSSStyleSheet*);
    164         Vector<String> uniqueStyleProperties(CSSStyleDeclaration*);
    165164        Vector<String> longhandProperties(CSSStyleDeclaration*, const String& shorthandProperty);
     165        String shorthandValue(CSSStyleDeclaration*, const String& shorthandProperty);
    166166        String shorthandPriority(CSSStyleDeclaration*, const String& shorthandProperty);
    167167        bool ruleAffectsNode(CSSStyleRule*, Node*);
  • trunk/WebCore/inspector/front-end/StylesSidebarPane.js

    r56161 r56237  
    13811381        var section = this.treeOutline.section;
    13821382        var elementsPanel = WebInspector.panels.elements;
    1383         var styleTextLength = styleText.trim().length;
     1383        styleText = styleText.replace(/\s/g, " ").trim(); // replace &nbsp; with whitespace.
     1384        var styleTextLength = styleText.length;
    13841385        if (!styleTextLength && updateInterface) {
    13851386            if (this._newProperty) {
     
    14271428                self.updateAll(true);
    14281429        }
    1429         InspectorBackend.applyStyleText(WebInspector.Callback.wrap(callback), this.style.id, styleText.trim(), this.name);
     1430        InspectorBackend.applyStyleText(WebInspector.Callback.wrap(callback), this.style.id, styleText, this.name);
    14301431    }
    14311432}
  • trunk/WebCore/inspector/front-end/inspector.css

    r56161 r56237  
    15731573}
    15741574
     1575.section .properties li.disabled .enabled-button {
     1576    display: block;
     1577}
     1578
    15751579.section .properties .name, .event-properties .name {
    15761580    color: rgb(136, 19, 145);
Note: See TracChangeset for help on using the changeset viewer.