Changeset 176668 in webkit
- Timestamp:
- Dec 2, 2014 9:59:18 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r176664 r176668 1 2014-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 1 27 2014-12-02 Bartlomiej Gajda <b.gajda@samsung.com> 2 28 -
trunk/Source/WebCore/editing/EditingStyle.cpp
r175067 r176668 129 129 } 130 130 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);131 static PassRefPtr<CSSValue> extractPropertyValue(const StyleProperties& style, CSSPropertyID propertyID) 132 { 133 return style.getPropertyCSSValue(propertyID); 134 } 135 136 static PassRefPtr<CSSValue> extractPropertyValue(ComputedStyleExtractor& computedStyle, CSSPropertyID propertyID) 137 { 138 return computedStyle.propertyValue(propertyID); 139 139 } 140 140 141 141 template<typename T> 142 int identifierForStyleProperty(T *style, CSSPropertyID propertyID)142 int identifierForStyleProperty(T& style, CSSPropertyID propertyID) 143 143 { 144 144 RefPtr<CSSValue> value = extractPropertyValue(style, propertyID); … … 148 148 } 149 149 150 template<typename T> PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties * styleWithRedundantProperties, T*baseStyle);150 template<typename T> PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle); 151 151 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelValuesMatch }; 152 152 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool shouldUseFixedFontDefaultSize, LegacyFontSizeMode); … … 370 370 371 371 template<typename T> 372 static inline RGBA32 textColorFromStyle(T *style)372 static inline RGBA32 textColorFromStyle(T& style) 373 373 { 374 374 return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get()); … … 376 376 377 377 template<typename T> 378 static inline RGBA32 backgroundColorFromStyle(T *style)378 static inline RGBA32 backgroundColorFromStyle(T& style) 379 379 { 380 380 return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get()); … … 409 409 410 410 template<typename T> 411 static int textAlignResolvingStartAndEnd(T *style)411 static int textAlignResolvingStartAndEnd(T& style) 412 412 { 413 413 return textAlignResolvingStartAndEnd(identifierForStyleProperty(style, CSSPropertyTextAlign), identifierForStyleProperty(style, CSSPropertyDirection)); … … 643 643 if (!style || !style->m_mutableStyle) 644 644 return FalseTriState; 645 return triStateOfStyle( style->m_mutableStyle.get(), DoNotIgnoreTextOnlyProperties);645 return triStateOfStyle(*style->m_mutableStyle, DoNotIgnoreTextOnlyProperties); 646 646 } 647 647 648 648 template<typename T> 649 TriState EditingStyle::triStateOfStyle(T* styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const 650 { 651 RefPtr<MutableStyleProperties> difference = getPropertiesNotIn(m_mutableStyle.get(), styleToCompare); 649 TriState EditingStyle::triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const 650 { 651 if (!m_mutableStyle) 652 return TrueTriState; 653 654 RefPtr<MutableStyleProperties> difference = getPropertiesNotIn(*m_mutableStyle, styleToCompare); 652 655 653 656 if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties) … … 675 678 if (node->renderer() && node->hasEditableStyle()) { 676 679 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); 678 681 if (nodeIsStart) { 679 682 state = nodeState; … … 850 853 return true; 851 854 ComputedStyleExtractor computedStyle(node); 852 return getPropertiesNotIn( m_mutableStyle.get(), &computedStyle)->isEmpty();855 return getPropertiesNotIn(*m_mutableStyle, computedStyle)->isEmpty(); 853 856 } 854 857 … … 921 924 removeEquivalentProperties(*styleAtPosition); 922 925 923 if (textAlignResolvingStartAndEnd( m_mutableStyle.get()) == textAlignResolvingStartAndEnd(styleAtPosition))926 if (textAlignResolvingStartAndEnd(*m_mutableStyle) == textAlignResolvingStartAndEnd(*styleAtPosition)) 924 927 m_mutableStyle->removeProperty(CSSPropertyTextAlign); 925 928 926 if (textColorFromStyle( m_mutableStyle.get()) == textColorFromStyle(styleAtPosition))929 if (textColorFromStyle(*m_mutableStyle) == textColorFromStyle(*styleAtPosition)) 927 930 m_mutableStyle->removeProperty(CSSPropertyColor); 928 931 … … 1162 1165 RefPtr<MutableStyleProperties> styleFromMatchedRules = styleFromMatchedRulesForElement(element, StyleResolver::AllButEmptyCSSRules); 1163 1166 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) 1164 m_mutableStyle = getPropertiesNotIn( m_mutableStyle.get(), styleFromMatchedRules.get());1167 m_mutableStyle = getPropertiesNotIn(*m_mutableStyle, *styleFromMatchedRules); 1165 1168 1166 1169 // 2. Remove style present in context and not overriden by matched rules. … … 1171 1174 1172 1175 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); 1174 1177 } 1175 1178 … … 1177 1180 // These rules are added by serialization code to wrap text nodes. 1178 1181 if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) { 1179 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && identifierForStyleProperty( m_mutableStyle.get(), CSSPropertyDisplay) == CSSValueInline)1182 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && identifierForStyleProperty(*m_mutableStyle, CSSPropertyDisplay) == CSSValueInline) 1180 1183 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) 1182 1185 m_mutableStyle->removeProperty(CSSPropertyFloat); 1183 1186 } … … 1406 1409 1407 1410 // FIXME: take care of background-color in effect 1408 RefPtr<MutableStyleProperties> mutableStyle = getPropertiesNotIn( style->style(), &computedStyle);1411 RefPtr<MutableStyleProperties> mutableStyle = getPropertiesNotIn(*style->style(), computedStyle); 1409 1412 1410 1413 reconcileTextDecorationProperties(mutableStyle.get()); 1411 1414 if (!document->frame()->editor().shouldStyleWithCSS()) 1412 extractTextStyles(document, mutableStyle.get(), computedStyle.useFixedFontDefaultSize());1415 extractTextStyles(document, *mutableStyle, computedStyle.useFixedFontDefaultSize()); 1413 1416 1414 1417 // Changing the whitespace style in a tab span would collapse the tab into a space. … … 1425 1428 } 1426 1429 1427 static void setTextDecorationProperty(MutableStyleProperties *style, const CSSValueList* newTextDecoration, CSSPropertyID propertyID)1430 static void setTextDecorationProperty(MutableStyleProperties& style, const CSSValueList* newTextDecoration, CSSPropertyID propertyID) 1428 1431 { 1429 1432 if (newTextDecoration->length()) 1430 style ->setProperty(propertyID, newTextDecoration->cssText(), style->propertyIsImportant(propertyID));1433 style.setProperty(propertyID, newTextDecoration->cssText(), style.propertyIsImportant(propertyID)); 1431 1434 else { 1432 1435 // 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 1440 void StyleChange::extractTextStyles(Document* document, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize) 1441 { 1441 1442 if (identifierForStyleProperty(style, CSSPropertyFontWeight) == CSSValueBold) { 1442 style ->removeProperty(CSSPropertyFontWeight);1443 style.removeProperty(CSSPropertyFontWeight); 1443 1444 m_applyBold = true; 1444 1445 } … … 1446 1447 int fontStyle = identifierForStyleProperty(style, CSSPropertyFontStyle); 1447 1448 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1448 style ->removeProperty(CSSPropertyFontStyle);1449 style.removeProperty(CSSPropertyFontStyle); 1449 1450 m_applyItalic = true; 1450 1451 } … … 1452 1453 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1453 1454 // 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); 1455 1456 if (is<CSSValueList>(textDecoration.get())) { 1456 1457 RefPtr<CSSPrimitiveValue> underline = cssValuePool().createIdentifierValue(CSSValueUnderline); … … 1470 1471 switch (verticalAlign) { 1471 1472 case CSSValueSub: 1472 style ->removeProperty(CSSPropertyVerticalAlign);1473 style.removeProperty(CSSPropertyVerticalAlign); 1473 1474 m_applySubscript = true; 1474 1475 break; 1475 1476 case CSSValueSuper: 1476 style ->removeProperty(CSSPropertyVerticalAlign);1477 style.removeProperty(CSSPropertyVerticalAlign); 1477 1478 m_applySuperscript = true; 1478 1479 break; 1479 1480 } 1480 1481 1481 if (style ->getPropertyCSSValue(CSSPropertyColor)) {1482 if (style.getPropertyCSSValue(CSSPropertyColor)) { 1482 1483 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); 1487 1488 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.webkit.org/show_bug.cgi?id=79448 1488 1489 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)) { 1492 1493 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. 1494 1495 else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, downcast<CSSPrimitiveValue>(fontSize.get()), 1495 1496 shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValuesMatch)) { 1496 1497 m_applyFontSize = String::number(legacyFontSize); 1497 style ->removeProperty(CSSPropertyFontSize);1498 style.removeProperty(CSSPropertyFontSize); 1498 1499 } 1499 1500 } 1500 1501 } 1501 1502 1502 static void diffTextDecorations(MutableStyleProperties *style, CSSPropertyID propertID, CSSValue* refTextDecoration)1503 { 1504 RefPtr<CSSValue> textDecoration = style ->getPropertyCSSValue(propertID);1503 static void diffTextDecorations(MutableStyleProperties& style, CSSPropertyID propertID, CSSValue* refTextDecoration) 1504 { 1505 RefPtr<CSSValue> textDecoration = style.getPropertyCSSValue(propertID); 1505 1506 if (!is<CSSValueList>(textDecoration.get()) || !is<CSSValueList>(refTextDecoration)) 1506 1507 return; … … 1515 1516 } 1516 1517 1517 static bool fontWeightIsBold(CSSValue *fontWeight)1518 static bool fontWeightIsBold(CSSValue& fontWeight) 1518 1519 { 1519 1520 if (!is<CSSPrimitiveValue>(fontWeight)) … … 1522 1523 // Because b tag can only bold text, there are only two states in plain html: bold and not bold. 1523 1524 // 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()) { 1525 1526 case CSSValue100: 1526 1527 case CSSValue200: … … 1545 1546 1546 1547 template<typename T> 1547 static bool fontWeightIsBold(T* style) 1548 { 1549 return fontWeightIsBold(extractPropertyValue(style, CSSPropertyFontWeight).get()); 1548 static bool fontWeightIsBold(T& style) 1549 { 1550 RefPtr<CSSValue> fontWeight = extractPropertyValue(style, CSSPropertyFontWeight); 1551 return fontWeight && fontWeightIsBold(*fontWeight); 1550 1552 } 1551 1553 1552 1554 template<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); 1555 static PassRefPtr<MutableStyleProperties> extractPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle) 1556 { 1557 RefPtr<EditingStyle> result = EditingStyle::create(&styleWithRedundantProperties); 1558 result->removeEquivalentProperties(baseStyle); 1558 1559 RefPtr<MutableStyleProperties> mutableStyle = result->style(); 1559 1560 1560 1561 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)) 1565 1566 mutableStyle->removeProperty(CSSPropertyFontWeight); 1566 1567 1567 if (extractPropertyValue(baseStyle, CSSPropertyColor) && textColorFromStyle( mutableStyle.get()) == textColorFromStyle(baseStyle))1568 if (extractPropertyValue(baseStyle, CSSPropertyColor) && textColorFromStyle(*mutableStyle) == textColorFromStyle(baseStyle)) 1568 1569 mutableStyle->removeProperty(CSSPropertyColor); 1569 1570 1570 1571 if (extractPropertyValue(baseStyle, CSSPropertyTextAlign) 1571 && textAlignResolvingStartAndEnd( mutableStyle.get()) == textAlignResolvingStartAndEnd(baseStyle))1572 && textAlignResolvingStartAndEnd(*mutableStyle) == textAlignResolvingStartAndEnd(baseStyle)) 1572 1573 mutableStyle->removeProperty(CSSPropertyTextAlign); 1573 1574 1574 if (extractPropertyValue(baseStyle, CSSPropertyBackgroundColor) && backgroundColorFromStyle( mutableStyle.get()) == backgroundColorFromStyle(baseStyle))1575 if (extractPropertyValue(baseStyle, CSSPropertyBackgroundColor) && backgroundColorFromStyle(*mutableStyle) == backgroundColorFromStyle(baseStyle)) 1575 1576 mutableStyle->removeProperty(CSSPropertyBackgroundColor); 1576 1577 … … 1579 1580 1580 1581 template<typename T> 1581 PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties * styleWithRedundantProperties, T*baseStyle)1582 PassRefPtr<MutableStyleProperties> getPropertiesNotIn(StyleProperties& styleWithRedundantProperties, T& baseStyle) 1582 1583 { 1583 1584 return extractPropertiesNotIn(styleWithRedundantProperties, baseStyle); -
trunk/Source/WebCore/editing/EditingStyle.h
r172814 r176668 158 158 void setProperty(CSSPropertyID, const String& value, bool important = false); 159 159 void extractFontSizeDelta(); 160 template<typename T> TriState triStateOfStyle(T *styleToCompare, ShouldIgnoreTextOnlyProperties) const;160 template<typename T> TriState triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties) const; 161 161 bool conflictsWithInlineStyleOfElement(StyledElement*, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const; 162 162 void mergeInlineAndImplicitStyleOfElement(StyledElement*, CSSPropertyOverrideMode, PropertiesToInclude); … … 217 217 } 218 218 private: 219 void extractTextStyles(Document*, MutableStyleProperties *, bool shouldUseFixedFontDefaultSize);219 void extractTextStyles(Document*, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize); 220 220 221 221 String m_cssStyle;
Note: See TracChangeset
for help on using the changeset viewer.