Changeset 176668 in webkit


Ignore:
Timestamp:
Dec 2, 2014 9:59:18 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Use references instead of pointers in EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=137918

Patch by Tibor Meszaros <tmeszaros.u-szeged@partner.samsung.com> on 2014-12-02
Reviewed by Darin Adler.

  • editing/EditingStyle.cpp:

(WebCore::extractPropertyValue):
(WebCore::identifierForStyleProperty):
(WebCore::textColorFromStyle):
(WebCore::backgroundColorFromStyle):
(WebCore::textAlignResolvingStartAndEnd):
(WebCore::EditingStyle::triStateOfStyle):
(WebCore::EditingStyle::styleIsPresentInComputedStyleOfNode):
(WebCore::EditingStyle::prepareToApplyAt):
(WebCore::EditingStyle::removeStyleFromRulesAndContext):
(WebCore::StyleChange::StyleChange):
(WebCore::setTextDecorationProperty):
(WebCore::StyleChange::extractTextStyles):
(WebCore::diffTextDecorations):
(WebCore::fontWeightIsBold):
(WebCore::extractPropertiesNotIn):
(WebCore::getPropertiesNotIn):

  • editing/EditingStyle.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176664 r176668  
     12014-12-02  Tibor Meszaros  <tmeszaros.u-szeged@partner.samsung.com>
     2
     3        Use references instead of pointers in EditingStyle
     4        https://bugs.webkit.org/show_bug.cgi?id=137918
     5
     6        Reviewed by Darin Adler.
     7
     8        * editing/EditingStyle.cpp:
     9        (WebCore::extractPropertyValue):
     10        (WebCore::identifierForStyleProperty):
     11        (WebCore::textColorFromStyle):
     12        (WebCore::backgroundColorFromStyle):
     13        (WebCore::textAlignResolvingStartAndEnd):
     14        (WebCore::EditingStyle::triStateOfStyle):
     15        (WebCore::EditingStyle::styleIsPresentInComputedStyleOfNode):
     16        (WebCore::EditingStyle::prepareToApplyAt):
     17        (WebCore::EditingStyle::removeStyleFromRulesAndContext):
     18        (WebCore::StyleChange::StyleChange):
     19        (WebCore::setTextDecorationProperty):
     20        (WebCore::StyleChange::extractTextStyles):
     21        (WebCore::diffTextDecorations):
     22        (WebCore::fontWeightIsBold):
     23        (WebCore::extractPropertiesNotIn):
     24        (WebCore::getPropertiesNotIn):
     25        * editing/EditingStyle.h:
     26
    1272014-12-02  Bartlomiej Gajda  <b.gajda@samsung.com>
    228
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r175067 r176668  
    129129}
    130130
    131 static PassRefPtr<CSSValue> extractPropertyValue(const StyleProperties* style, CSSPropertyID propertyID)
    132 {
    133     return style ? style->getPropertyCSSValue(propertyID) : PassRefPtr<CSSValue>();
    134 }
    135 
    136 static PassRefPtr<CSSValue> extractPropertyValue(ComputedStyleExtractor* computedStyle, CSSPropertyID propertyID)
    137 {
    138     return computedStyle->propertyValue(propertyID);
     131static PassRefPtr<CSSValue> extractPropertyValue(const StyleProperties& style, CSSPropertyID propertyID)
     132{
     133    return style.getPropertyCSSValue(propertyID);
     134}
     135
     136static PassRefPtr<CSSValue> extractPropertyValue(ComputedStyleExtractor& computedStyle, CSSPropertyID propertyID)
     137{
     138    return computedStyle.propertyValue(propertyID);
    139139}
    140140
    141141template<typename T>
    142 int identifierForStyleProperty(T* style, CSSPropertyID propertyID)
     142int identifierForStyleProperty(T& style, CSSPropertyID propertyID)
    143143{
    144144    RefPtr<CSSValue> value = extractPropertyValue(style, propertyID);
     
    148148}
    149149
    150 template<typename T> PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties* styleWithRedundantProperties, T* baseStyle);
     150template<typename T> PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle);
    151151enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelValuesMatch };
    152152static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool shouldUseFixedFontDefaultSize, LegacyFontSizeMode);
     
    370370
    371371template<typename T>
    372 static inline RGBA32 textColorFromStyle(T* style)
     372static inline RGBA32 textColorFromStyle(T& style)
    373373{
    374374    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get());
     
    376376
    377377template<typename T>
    378 static inline RGBA32 backgroundColorFromStyle(T* style)
     378static inline RGBA32 backgroundColorFromStyle(T& style)
    379379{
    380380    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
     
    409409
    410410template<typename T>
    411 static int textAlignResolvingStartAndEnd(T* style)
     411static int textAlignResolvingStartAndEnd(T& style)
    412412{
    413413    return textAlignResolvingStartAndEnd(identifierForStyleProperty(style, CSSPropertyTextAlign), identifierForStyleProperty(style, CSSPropertyDirection));
     
    643643    if (!style || !style->m_mutableStyle)
    644644        return FalseTriState;
    645     return triStateOfStyle(style->m_mutableStyle.get(), DoNotIgnoreTextOnlyProperties);
     645    return triStateOfStyle(*style->m_mutableStyle, DoNotIgnoreTextOnlyProperties);
    646646}
    647647
    648648template<typename T>
    649 TriState EditingStyle::triStateOfStyle(T* styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const
    650 {
    651     RefPtr<MutableStyleProperties> difference = getPropertiesNotIn(m_mutableStyle.get(), styleToCompare);
     649TriState EditingStyle::triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const
     650{
     651    if (!m_mutableStyle)
     652        return TrueTriState;
     653
     654    RefPtr<MutableStyleProperties> difference = getPropertiesNotIn(*m_mutableStyle, styleToCompare);
    652655
    653656    if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties)
     
    675678        if (node->renderer() && node->hasEditableStyle()) {
    676679            ComputedStyleExtractor computedStyle(node);
    677             TriState nodeState = triStateOfStyle(&computedStyle, node->isTextNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTextOnlyProperties);
     680            TriState nodeState = triStateOfStyle(computedStyle, node->isTextNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTextOnlyProperties);
    678681            if (nodeIsStart) {
    679682                state = nodeState;
     
    850853        return true;
    851854    ComputedStyleExtractor computedStyle(node);
    852     return getPropertiesNotIn(m_mutableStyle.get(), &computedStyle)->isEmpty();
     855    return getPropertiesNotIn(*m_mutableStyle, computedStyle)->isEmpty();
    853856}
    854857
     
    921924    removeEquivalentProperties(*styleAtPosition);
    922925
    923     if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvingStartAndEnd(styleAtPosition))
     926    if (textAlignResolvingStartAndEnd(*m_mutableStyle) == textAlignResolvingStartAndEnd(*styleAtPosition))
    924927        m_mutableStyle->removeProperty(CSSPropertyTextAlign);
    925928
    926     if (textColorFromStyle(m_mutableStyle.get()) == textColorFromStyle(styleAtPosition))
     929    if (textColorFromStyle(*m_mutableStyle) == textColorFromStyle(*styleAtPosition))
    927930        m_mutableStyle->removeProperty(CSSPropertyColor);
    928931
     
    11621165    RefPtr<MutableStyleProperties> styleFromMatchedRules = styleFromMatchedRulesForElement(element, StyleResolver::AllButEmptyCSSRules);
    11631166    if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty())
    1164         m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatchedRules.get());
     1167        m_mutableStyle = getPropertiesNotIn(*m_mutableStyle, *styleFromMatchedRules);
    11651168
    11661169    // 2. Remove style present in context and not overriden by matched rules.
     
    11711174
    11721175        removePropertiesInStyle(computedStyle->m_mutableStyle.get(), styleFromMatchedRules.get());
    1173         m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), computedStyle->m_mutableStyle.get());
     1176        m_mutableStyle = getPropertiesNotIn(*m_mutableStyle, *computedStyle->m_mutableStyle);
    11741177    }
    11751178
     
    11771180    // These rules are added by serialization code to wrap text nodes.
    11781181    if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) {
    1179         if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && identifierForStyleProperty(m_mutableStyle.get(), CSSPropertyDisplay) == CSSValueInline)
     1182        if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && identifierForStyleProperty(*m_mutableStyle, CSSPropertyDisplay) == CSSValueInline)
    11801183            m_mutableStyle->removeProperty(CSSPropertyDisplay);
    1181         if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyFloat) && identifierForStyleProperty(m_mutableStyle.get(), CSSPropertyFloat) == CSSValueNone)
     1184        if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyFloat) && identifierForStyleProperty(*m_mutableStyle, CSSPropertyFloat) == CSSValueNone)
    11821185            m_mutableStyle->removeProperty(CSSPropertyFloat);
    11831186    }
     
    14061409
    14071410    // FIXME: take care of background-color in effect
    1408     RefPtr<MutableStyleProperties> mutableStyle = getPropertiesNotIn(style->style(), &computedStyle);
     1411    RefPtr<MutableStyleProperties> mutableStyle = getPropertiesNotIn(*style->style(), computedStyle);
    14091412
    14101413    reconcileTextDecorationProperties(mutableStyle.get());
    14111414    if (!document->frame()->editor().shouldStyleWithCSS())
    1412         extractTextStyles(document, mutableStyle.get(), computedStyle.useFixedFontDefaultSize());
     1415        extractTextStyles(document, *mutableStyle, computedStyle.useFixedFontDefaultSize());
    14131416
    14141417    // Changing the whitespace style in a tab span would collapse the tab into a space.
     
    14251428}
    14261429
    1427 static void setTextDecorationProperty(MutableStyleProperties* style, const CSSValueList* newTextDecoration, CSSPropertyID propertyID)
     1430static void setTextDecorationProperty(MutableStyleProperties& style, const CSSValueList* newTextDecoration, CSSPropertyID propertyID)
    14281431{
    14291432    if (newTextDecoration->length())
    1430         style->setProperty(propertyID, newTextDecoration->cssText(), style->propertyIsImportant(propertyID));
     1433        style.setProperty(propertyID, newTextDecoration->cssText(), style.propertyIsImportant(propertyID));
    14311434    else {
    14321435        // text-decoration: none is redundant since it does not remove any text decorations.
    1433         style->removeProperty(propertyID);
    1434     }
    1435 }
    1436 
    1437 void StyleChange::extractTextStyles(Document* document, MutableStyleProperties* style, bool shouldUseFixedFontDefaultSize)
    1438 {
    1439     ASSERT(style);
    1440 
     1436        style.removeProperty(propertyID);
     1437    }
     1438}
     1439
     1440void StyleChange::extractTextStyles(Document* document, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize)
     1441{
    14411442    if (identifierForStyleProperty(style, CSSPropertyFontWeight) == CSSValueBold) {
    1442         style->removeProperty(CSSPropertyFontWeight);
     1443        style.removeProperty(CSSPropertyFontWeight);
    14431444        m_applyBold = true;
    14441445    }
     
    14461447    int fontStyle = identifierForStyleProperty(style, CSSPropertyFontStyle);
    14471448    if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
    1448         style->removeProperty(CSSPropertyFontStyle);
     1449        style.removeProperty(CSSPropertyFontStyle);
    14491450        m_applyItalic = true;
    14501451    }
     
    14521453    // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
    14531454    // Furthermore, text-decoration: none has been trimmed so that text-decoration property is always a CSSValueList.
    1454     RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(CSSPropertyTextDecoration);
     1455    RefPtr<CSSValue> textDecoration = style.getPropertyCSSValue(CSSPropertyTextDecoration);
    14551456    if (is<CSSValueList>(textDecoration.get())) {
    14561457        RefPtr<CSSPrimitiveValue> underline = cssValuePool().createIdentifierValue(CSSValueUnderline);
     
    14701471    switch (verticalAlign) {
    14711472    case CSSValueSub:
    1472         style->removeProperty(CSSPropertyVerticalAlign);
     1473        style.removeProperty(CSSPropertyVerticalAlign);
    14731474        m_applySubscript = true;
    14741475        break;
    14751476    case CSSValueSuper:
    1476         style->removeProperty(CSSPropertyVerticalAlign);
     1477        style.removeProperty(CSSPropertyVerticalAlign);
    14771478        m_applySuperscript = true;
    14781479        break;
    14791480    }
    14801481
    1481     if (style->getPropertyCSSValue(CSSPropertyColor)) {
     1482    if (style.getPropertyCSSValue(CSSPropertyColor)) {
    14821483        m_applyFontColor = Color(textColorFromStyle(style)).serialized();
    1483         style->removeProperty(CSSPropertyColor);
    1484     }
    1485 
    1486     m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily);
     1484        style.removeProperty(CSSPropertyColor);
     1485    }
     1486
     1487    m_applyFontFace = style.getPropertyValue(CSSPropertyFontFamily);
    14871488    // Remove single quotes for Outlook 2007 compatibility. See https://bugs.webkit.org/show_bug.cgi?id=79448
    14881489    m_applyFontFace.replaceWithLiteral('\'', "");
    1489     style->removeProperty(CSSPropertyFontFamily);
    1490 
    1491     if (RefPtr<CSSValue> fontSize = style->getPropertyCSSValue(CSSPropertyFontSize)) {
     1490    style.removeProperty(CSSPropertyFontFamily);
     1491
     1492    if (RefPtr<CSSValue> fontSize = style.getPropertyCSSValue(CSSPropertyFontSize)) {
    14921493        if (!is<CSSPrimitiveValue>(*fontSize))
    1493             style->removeProperty(CSSPropertyFontSize); // Can't make sense of the number. Put no font size.
     1494            style.removeProperty(CSSPropertyFontSize); // Can't make sense of the number. Put no font size.
    14941495        else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, downcast<CSSPrimitiveValue>(fontSize.get()),
    14951496                shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValuesMatch)) {
    14961497            m_applyFontSize = String::number(legacyFontSize);
    1497             style->removeProperty(CSSPropertyFontSize);
     1498            style.removeProperty(CSSPropertyFontSize);
    14981499        }
    14991500    }
    15001501}
    15011502
    1502 static void diffTextDecorations(MutableStyleProperties* style, CSSPropertyID propertID, CSSValue* refTextDecoration)
    1503 {
    1504     RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(propertID);
     1503static void diffTextDecorations(MutableStyleProperties& style, CSSPropertyID propertID, CSSValue* refTextDecoration)
     1504{
     1505    RefPtr<CSSValue> textDecoration = style.getPropertyCSSValue(propertID);
    15051506    if (!is<CSSValueList>(textDecoration.get()) || !is<CSSValueList>(refTextDecoration))
    15061507        return;
     
    15151516}
    15161517
    1517 static bool fontWeightIsBold(CSSValue* fontWeight)
     1518static bool fontWeightIsBold(CSSValue& fontWeight)
    15181519{
    15191520    if (!is<CSSPrimitiveValue>(fontWeight))
     
    15221523    // Because b tag can only bold text, there are only two states in plain html: bold and not bold.
    15231524    // Collapse all other values to either one of these two states for editing purposes.
    1524     switch (downcast<CSSPrimitiveValue>(*fontWeight).getValueID()) {
     1525    switch (downcast<CSSPrimitiveValue>(fontWeight).getValueID()) {
    15251526        case CSSValue100:
    15261527        case CSSValue200:
     
    15451546
    15461547template<typename T>
    1547 static bool fontWeightIsBold(T* style)
    1548 {
    1549     return fontWeightIsBold(extractPropertyValue(style, CSSPropertyFontWeight).get());
     1548static bool fontWeightIsBold(T& style)
     1549{
     1550    RefPtr<CSSValue> fontWeight = extractPropertyValue(style, CSSPropertyFontWeight);
     1551    return fontWeight && fontWeightIsBold(*fontWeight);
    15501552}
    15511553
    15521554template<typename T>
    1553 static PassRefPtr<MutableStyleProperties> extractPropertiesNotIn(StyleProperties* styleWithRedundantProperties, T* baseStyle)
    1554 {
    1555     ASSERT(styleWithRedundantProperties);
    1556     RefPtr<EditingStyle> result = EditingStyle::create(styleWithRedundantProperties);
    1557     result->removeEquivalentProperties(*baseStyle);
     1555static PassRefPtr<MutableStyleProperties> extractPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle)
     1556{
     1557    RefPtr<EditingStyle> result = EditingStyle::create(&styleWithRedundantProperties);
     1558    result->removeEquivalentProperties(baseStyle);
    15581559    RefPtr<MutableStyleProperties> mutableStyle = result->style();
    15591560
    15601561    RefPtr<CSSValue> baseTextDecorationsInEffect = extractPropertyValue(baseStyle, CSSPropertyWebkitTextDecorationsInEffect);
    1561     diffTextDecorations(mutableStyle.get(), CSSPropertyTextDecoration, baseTextDecorationsInEffect.get());
    1562     diffTextDecorations(mutableStyle.get(), CSSPropertyWebkitTextDecorationsInEffect, baseTextDecorationsInEffect.get());
    1563 
    1564     if (extractPropertyValue(baseStyle, CSSPropertyFontWeight) && fontWeightIsBold(mutableStyle.get()) == fontWeightIsBold(baseStyle))
     1562    diffTextDecorations(*mutableStyle, CSSPropertyTextDecoration, baseTextDecorationsInEffect.get());
     1563    diffTextDecorations(*mutableStyle, CSSPropertyWebkitTextDecorationsInEffect, baseTextDecorationsInEffect.get());
     1564
     1565    if (extractPropertyValue(baseStyle, CSSPropertyFontWeight) && fontWeightIsBold(*mutableStyle) == fontWeightIsBold(baseStyle))
    15651566        mutableStyle->removeProperty(CSSPropertyFontWeight);
    15661567
    1567     if (extractPropertyValue(baseStyle, CSSPropertyColor) && textColorFromStyle(mutableStyle.get()) == textColorFromStyle(baseStyle))
     1568    if (extractPropertyValue(baseStyle, CSSPropertyColor) && textColorFromStyle(*mutableStyle) == textColorFromStyle(baseStyle))
    15681569        mutableStyle->removeProperty(CSSPropertyColor);
    15691570
    15701571    if (extractPropertyValue(baseStyle, CSSPropertyTextAlign)
    1571         && textAlignResolvingStartAndEnd(mutableStyle.get()) == textAlignResolvingStartAndEnd(baseStyle))
     1572        && textAlignResolvingStartAndEnd(*mutableStyle) == textAlignResolvingStartAndEnd(baseStyle))
    15721573        mutableStyle->removeProperty(CSSPropertyTextAlign);
    15731574
    1574     if (extractPropertyValue(baseStyle, CSSPropertyBackgroundColor) && backgroundColorFromStyle(mutableStyle.get()) == backgroundColorFromStyle(baseStyle))
     1575    if (extractPropertyValue(baseStyle, CSSPropertyBackgroundColor) && backgroundColorFromStyle(*mutableStyle) == backgroundColorFromStyle(baseStyle))
    15751576        mutableStyle->removeProperty(CSSPropertyBackgroundColor);
    15761577
     
    15791580
    15801581template<typename T>
    1581 PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties* styleWithRedundantProperties, T* baseStyle)
     1582PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle)
    15821583{
    15831584    return extractPropertiesNotIn(styleWithRedundantProperties, baseStyle);
  • trunk/Source/WebCore/editing/EditingStyle.h

    r172814 r176668  
    158158    void setProperty(CSSPropertyID, const String& value, bool important = false);
    159159    void extractFontSizeDelta();
    160     template<typename T> TriState triStateOfStyle(T* styleToCompare, ShouldIgnoreTextOnlyProperties) const;
     160    template<typename T> TriState triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties) const;
    161161    bool conflictsWithInlineStyleOfElement(StyledElement*, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const;
    162162    void mergeInlineAndImplicitStyleOfElement(StyledElement*, CSSPropertyOverrideMode, PropertiesToInclude);
     
    217217    }
    218218private:
    219     void extractTextStyles(Document*, MutableStyleProperties*, bool shouldUseFixedFontDefaultSize);
     219    void extractTextStyles(Document*, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize);
    220220
    221221    String m_cssStyle;
Note: See TracChangeset for help on using the changeset viewer.