Changeset 150945 in webkit


Ignore:
Timestamp:
May 29, 2013 9:11:39 PM (11 years ago)
Author:
akling@apple.com
Message:

Take ComputedStyleExtractor for a spin.
<http://webkit.org/b/116968>

Reviewed by Antti Koivisto.

Convert some editing and SVG code to use ComputedStyleExtractor instead of creating full
blown CSSComputedStyleDeclaration objects.

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
(WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
(WebCore::highestEmbeddingAncestor):
(WebCore::ApplyStyleCommand::computedFontSize):

  • editing/EditingStyle.cpp:

(WebCore::EditingStyle::mergeStyleFromRulesForSerialization):
(WebCore::EditingStyle::textDirectionForSelection):
(WebCore::getIdentifierValue):
(WebCore::backgroundColorInEffect):

  • editing/EditingStyle.h:
  • svg/SVGAnimationElement.cpp:

(WebCore::SVGAnimationElement::computeCSSPropertyValue):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150944 r150945  
     12013-05-29  Andreas Kling  <akling@apple.com>
     2
     3        Take ComputedStyleExtractor for a spin.
     4        <http://webkit.org/b/116968>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Convert some editing and SVG code to use ComputedStyleExtractor instead of creating full
     9        blown CSSComputedStyleDeclaration objects.
     10
     11        * editing/ApplyStyleCommand.cpp:
     12        (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
     13        (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
     14        (WebCore::highestEmbeddingAncestor):
     15        (WebCore::ApplyStyleCommand::computedFontSize):
     16        * editing/EditingStyle.cpp:
     17        (WebCore::EditingStyle::mergeStyleFromRulesForSerialization):
     18        (WebCore::EditingStyle::textDirectionForSelection):
     19        (WebCore::getIdentifierValue):
     20        (WebCore::backgroundColorInEffect):
     21        * editing/EditingStyle.h:
     22        * svg/SVGAnimationElement.cpp:
     23        (WebCore::SVGAnimationElement::computeCSSPropertyValue):
     24
    1252013-05-29  Benjamin Poulain  <bpoulain@apple.com>
    226
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r150702 r150945  
    457457    int highestAncestorUnicodeBidi = 0;
    458458    for (Node* n = node->parentNode(); n != block; n = n->parentNode()) {
    459         int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create(n).get(), CSSPropertyUnicodeBidi);
     459        int unicodeBidi = getIdentifierValue(n, CSSPropertyUnicodeBidi);
    460460        if (unicodeBidi && unicodeBidi != CSSValueNormal) {
    461461            highestAncestorUnicodeBidi = unicodeBidi;
     
    509509
    510510        StyledElement* element = static_cast<StyledElement*>(n);
    511         int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create(element).get(), CSSPropertyUnicodeBidi);
     511        int unicodeBidi = getIdentifierValue(element, CSSPropertyUnicodeBidi);
    512512        if (!unicodeBidi || unicodeBidi == CSSValueNormal)
    513513            continue;
     
    535535{
    536536    for (Node* n = startNode; n && n != enclosingNode; n = n->parentNode()) {
    537         if (n->isHTMLElement() && getIdentifierValue(CSSComputedStyleDeclaration::create(n).get(), CSSPropertyUnicodeBidi) == CSSValueEmbed)
     537        if (n->isHTMLElement() && getIdentifierValue(n, CSSPropertyUnicodeBidi) == CSSValueEmbed)
    538538            return n;
    539539    }
     
    15081508        return 0;
    15091509
    1510     RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(node);
    1511     if (!style)
    1512         return 0;
    1513 
    1514     RefPtr<CSSPrimitiveValue> value = static_pointer_cast<CSSPrimitiveValue>(style->getPropertyCSSValue(CSSPropertyFontSize));
    1515     if (!value)
    1516         return 0;
    1517 
    1518     return value->getFloatValue(CSSPrimitiveValue::CSS_PX);
     1510    RefPtr<CSSValue> value = ComputedStyleExtractor(node).propertyValue(CSSPropertyFontSize);
     1511    ASSERT(value && value->isPrimitiveValue());
     1512    return static_cast<CSSPrimitiveValue*>(value.get())->getFloatValue(CSSPrimitiveValue::CSS_PX);
    15191513}
    15201514
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r150140 r150945  
    114114static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool shouldUseFixedFontDefaultSize, LegacyFontSizeMode);
    115115static bool isTransparentColorValue(CSSValue*);
    116 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
    117116static bool hasTransparentBackgroundColor(StylePropertySet*);
    118117static PassRefPtr<CSSValue> backgroundColorInEffect(Node*);
     
    11061105    // For example: style="height: 1%; overflow: visible;" in quirksmode
    11071106    // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot copy/paste fidelity problem
    1108     RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedStyleDeclaration::create(element);
    11091107    RefPtr<MutableStylePropertySet> fromComputedStyle = MutableStylePropertySet::create();
     1108    ComputedStyleExtractor computedStyle(element);
     1109
    11101110    {
    11111111        unsigned propertyCount = m_mutableStyle->propertyCount();
     
    11161116                continue;
    11171117            if (static_cast<CSSPrimitiveValue*>(value)->isPercentage()) {
    1118                 if (RefPtr<CSSValue> computedPropertyValue = computedStyleForElement->getPropertyCSSValue(property.id()))
    1119                     fromComputedStyle->addParsedProperty(CSSProperty(property.id(), computedPropertyValue));
     1118                if (RefPtr<CSSValue> computedPropertyValue = computedStyle.propertyValue(property.id()))
     1119                    fromComputedStyle->addParsedProperty(CSSProperty(property.id(), computedPropertyValue.release()));
    11201120            }
    11211121        }
     
    12481248                continue;
    12491249
    1250             RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(n);
    1251             RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
     1250            RefPtr<CSSValue> unicodeBidi = ComputedStyleExtractor(n).propertyValue(CSSPropertyUnicodeBidi);
    12521251            if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
    12531252                continue;
     
    12771276            continue;
    12781277
    1279         RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(node);
    1280         RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
     1278        ComputedStyleExtractor computedStyle(node);
     1279        RefPtr<CSSValue> unicodeBidi = computedStyle.propertyValue(CSSPropertyUnicodeBidi);
    12811280        if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
    12821281            continue;
     
    12901289
    12911290        ASSERT(unicodeBidiValue == CSSValueEmbed);
    1292         RefPtr<CSSValue> direction = style->getPropertyCSSValue(CSSPropertyDirection);
     1291        RefPtr<CSSValue> direction = computedStyle.propertyValue(CSSPropertyDirection);
    12931292        if (!direction || !direction->isPrimitiveValue())
    12941293            continue;
     
    15431542}
    15441543
     1544int getIdentifierValue(Node* node, CSSPropertyID propertyID)
     1545{
     1546    RefPtr<CSSValue> value = ComputedStyleExtractor(node).propertyValue(propertyID);
     1547    if (!value || !value->isPrimitiveValue())
     1548        return 0;
     1549    return static_cast<CSSPrimitiveValue*>(value.get())->getIdent();
     1550}
     1551
    15451552static bool isCSSValueLength(CSSPrimitiveValue* value)
    15461553{
     
    15791586}
    15801587
    1581 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
    1582 {
    1583     RefPtr<CSSValue> cssValue = style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor);
    1584     return isTransparentColorValue(cssValue.get());
    1585 }
    1586    
    15871588bool hasTransparentBackgroundColor(StylePropertySet* style)
    15881589{
     
    15941595{
    15951596    for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
    1596         RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDeclaration::create(ancestor);
    1597         if (!hasTransparentBackgroundColor(ancestorStyle.get()))
    1598             return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor);
     1597        if (RefPtr<CSSValue> value = ComputedStyleExtractor(ancestor).propertyValue(CSSPropertyBackgroundColor)) {
     1598            if (!isTransparentColorValue(value.get()))
     1599                return value.release();
     1600        }
    15991601    }
    16001602    return 0;
  • trunk/Source/WebCore/editing/EditingStyle.h

    r148402 r150945  
    4848class CSSPrimitiveValue;
    4949class CSSValue;
     50class ComputedStyleExtractor;
    5051class Document;
    5152class Element;
     
    236237int getIdentifierValue(CSSStyleDeclaration*, CSSPropertyID);
    237238int getIdentifierValue(StylePropertySet*, CSSPropertyID);
     239int getIdentifierValue(Node*, CSSPropertyID);
    238240
    239241} // namespace WebCore
  • trunk/Source/WebCore/svg/SVGAnimationElement.cpp

    r145433 r150945  
    633633}
    634634
    635 void SVGAnimationElement::computeCSSPropertyValue(SVGElement* element, CSSPropertyID id, String& value)
     635void SVGAnimationElement::computeCSSPropertyValue(SVGElement* element, CSSPropertyID id, String& valueString)
    636636{
    637637    ASSERT(element);
     
    640640    // Don't include any properties resulting from CSS Transitions/Animations or SMIL animations, as we want to retrieve the "base value".
    641641    element->setUseOverrideComputedStyle(true);
    642     value = CSSComputedStyleDeclaration::create(element)->getPropertyValue(id);
     642    RefPtr<CSSValue> value = ComputedStyleExtractor(element).propertyValue(id);
     643    valueString = value ? value->cssText() : String();
    643644    element->setUseOverrideComputedStyle(false);
    644645}
Note: See TracChangeset for help on using the changeset viewer.