Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: Source/core/editing/EditingStyle.cpp

Issue 1233363002: CSSValue Immediates: Replace CSSPrimitiveValue usage with const references (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_4_attempt_2
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties) 142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties)
143 { 143 {
144 if (!style) 144 if (!style)
145 return MutableStylePropertySet::create(); 145 return MutableStylePropertySet::create();
146 return copyEditingProperties(style.get(), type); 146 return copyEditingProperties(style.get(), type);
147 } 147 }
148 148
149 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); 149 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle);
150 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; 150 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch };
151 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue, bool, Legacy FontSizeMode); 151 static int legacyFontSizeFromCSSValue(Document*, const CSSPrimitiveValue&, bool, LegacyFontSizeMode);
152 static bool isTransparentColorValue(NullableCSSValue); 152 static bool isTransparentColorValue(const NullableCSSValue&);
153 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); 153 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
154 static bool hasTransparentBackgroundColor(StylePropertySet*); 154 static bool hasTransparentBackgroundColor(StylePropertySet*);
155 static NullableCSSValue backgroundColorInEffect(Node*); 155 static NullableCSSValue backgroundColorInEffect(Node*);
156 156
157 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollectedFinalized<HTMLE lementEquivalent> { 157 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollectedFinalized<HTMLE lementEquivalent> {
158 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HTMLElementEquivalent); 158 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HTMLElementEquivalent);
159 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent); 159 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
160 public: 160 public:
161 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName) 161 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
162 { 162 {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 EditingStyle::~EditingStyle() 385 EditingStyle::~EditingStyle()
386 { 386 {
387 } 387 }
388 388
389 static RGBA32 cssValueToRGBA(NullableCSSValue colorValue) 389 static RGBA32 cssValueToRGBA(NullableCSSValue colorValue)
390 { 390 {
391 if (!colorValue || !colorValue->isPrimitiveValue()) 391 if (!colorValue || !colorValue->isPrimitiveValue())
392 return Color::transparent; 392 return Color::transparent;
393 393
394 CSSPrimitiveValue primitiveColor = toCSSPrimitiveValue(*colorValue); 394 const CSSPrimitiveValue& primitiveColor = toCSSPrimitiveValue(*colorValue);
395 if (primitiveColor.isRGBColor()) 395 if (primitiveColor.isRGBColor())
396 return primitiveColor.getRGBA32Value(); 396 return primitiveColor.getRGBA32Value();
397 397
398 RGBA32 rgba = 0; 398 RGBA32 rgba = 0;
399 // FIXME: Why ignore the return value? 399 // FIXME: Why ignore the return value?
400 CSSParser::parseColor(rgba, colorValue->cssText()); 400 CSSParser::parseColor(rgba, colorValue->cssText());
401 return rgba; 401 return rgba;
402 } 402 }
403 403
404 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style) 404 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Explicit font size overrides any delta. 516 // Explicit font size overrides any delta.
517 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 517 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
518 return; 518 return;
519 } 519 }
520 520
521 // Get the adjustment amount out of the style. 521 // Get the adjustment amount out of the style.
522 NullableCSSValue value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta); 522 NullableCSSValue value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta);
523 if (!value || !value->isPrimitiveValue()) 523 if (!value || !value->isPrimitiveValue())
524 return; 524 return;
525 525
526 CSSPrimitiveValue primitiveValue = toCSSPrimitiveValue(*value); 526 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(*value);
527 527
528 // Only PX handled now. If we handle more types in the future, perhaps 528 // Only PX handled now. If we handle more types in the future, perhaps
529 // a switch statement here would be more appropriate. 529 // a switch statement here would be more appropriate.
530 if (!primitiveValue.isPx()) 530 if (!primitiveValue.isPx())
531 return; 531 return;
532 532
533 m_fontSizeDelta = primitiveValue.getFloatValue(); 533 m_fontSizeDelta = primitiveValue.getFloatValue();
534 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 534 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
535 } 535 }
536 536
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 if (NullableCSSValue fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) { 1548 if (NullableCSSValue fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) {
1549 if (!fontSize->isPrimitiveValue()) { 1549 if (!fontSize->isPrimitiveValue()) {
1550 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. 1550 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size.
1551 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(*fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValues Match)) { 1551 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(*fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValues Match)) {
1552 m_applyFontSize = String::number(legacyFontSize); 1552 m_applyFontSize = String::number(legacyFontSize);
1553 style->removeProperty(CSSPropertyFontSize); 1553 style->removeProperty(CSSPropertyFontSize);
1554 } 1554 }
1555 } 1555 }
1556 } 1556 }
1557 1557
1558 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, NullableCSSValue refTextDecoration) 1558 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, const NullableCSSValue& refTextDecoration)
1559 { 1559 {
1560 NullableCSSValue textDecoration = style->getPropertyCSSValue(propertyID); 1560 const NullableCSSValue& textDecoration = style->getPropertyCSSValue(property ID);
1561 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) 1561 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
1562 return; 1562 return;
1563 1563
1564 RefPtrWillBeRawPtr<CSSValueList> newTextDecoration = toCSSValueList(textDeco ration)->copy(); 1564 RefPtrWillBeRawPtr<CSSValueList> newTextDecoration = toCSSValueList(textDeco ration)->copy();
1565 CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecoration); 1565 CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecoration);
1566 1566
1567 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) 1567 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++)
1568 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i)); 1568 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i));
1569 1569
1570 setTextDecorationProperty(style, newTextDecoration.get(), propertyID); 1570 setTextDecorationProperty(style, newTextDecoration.get(), propertyID);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID) 1653 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID)
1654 { 1654 {
1655 if (!style) 1655 if (!style)
1656 return CSSValueInvalid; 1656 return CSSValueInvalid;
1657 NullableCSSValue value = style->getPropertyCSSValueInternal(propertyID); 1657 NullableCSSValue value = style->getPropertyCSSValueInternal(propertyID);
1658 if (!value || !value->isPrimitiveValue()) 1658 if (!value || !value->isPrimitiveValue())
1659 return CSSValueInvalid; 1659 return CSSValueInvalid;
1660 return toCSSPrimitiveValue(*value).getValueID(); 1660 return toCSSPrimitiveValue(*value).getValueID();
1661 } 1661 }
1662 1662
1663 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue value, bool isMonospaceFont, LegacyFontSizeMode mode) 1663 int legacyFontSizeFromCSSValue(Document* document, const CSSPrimitiveValue& valu e, bool isMonospaceFont, LegacyFontSizeMode mode)
1664 { 1664 {
1665 CSSPrimitiveValue::LengthUnitType lengthType; 1665 CSSPrimitiveValue::LengthUnitType lengthType;
1666 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value.primitiveType(), lengt hType) 1666 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value.primitiveType(), lengt hType)
1667 && lengthType == CSSPrimitiveValue::UnitTypePixels) { 1667 && lengthType == CSSPrimitiveValue::UnitTypePixels) {
1668 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value.primitiveType()); 1668 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value.primitiveType());
1669 int pixelFontSize = clampTo<int>(value.getDoubleValue() * conversion); 1669 int pixelFontSize = clampTo<int>(value.getDoubleValue() * conversion);
1670 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont); 1670 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont);
1671 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. 1671 // Use legacy font size only if pixel value matches exactly to that of l egacy font size.
1672 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize) 1672 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize)
1673 return legacyFontSize; 1673 return legacyFontSize;
1674 1674
1675 return 0; 1675 return 0;
1676 } 1676 }
1677 1677
1678 if (CSSValueXSmall <= value.getValueID() && value.getValueID() <= CSSValueWe bkitXxxLarge) 1678 if (CSSValueXSmall <= value.getValueID() && value.getValueID() <= CSSValueWe bkitXxxLarge)
1679 return value.getValueID() - CSSValueXSmall + 1; 1679 return value.getValueID() - CSSValueXSmall + 1;
1680 1680
1681 return 0; 1681 return 0;
1682 } 1682 }
1683 1683
1684 bool isTransparentColorValue(NullableCSSValue cssValue) 1684 bool isTransparentColorValue(const NullableCSSValue& cssValue)
1685 { 1685 {
1686 if (!cssValue) 1686 if (!cssValue)
1687 return true; 1687 return true;
1688 if (!cssValue->isPrimitiveValue()) 1688 if (!cssValue->isPrimitiveValue())
1689 return false; 1689 return false;
1690 CSSPrimitiveValue value = toCSSPrimitiveValue(*cssValue); 1690 const CSSPrimitiveValue& value = toCSSPrimitiveValue(*cssValue);
1691 if (value.isRGBColor()) 1691 if (value.isRGBColor())
1692 return !alphaChannel(value.getRGBA32Value()); 1692 return !alphaChannel(value.getRGBA32Value());
1693 return value.getValueID() == CSSValueTransparent; 1693 return value.getValueID() == CSSValueTransparent;
1694 } 1694 }
1695 1695
1696 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) 1696 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
1697 { 1697 {
1698 NullableCSSValue cssValue = style->getPropertyCSSValueInternal(CSSPropertyBa ckgroundColor); 1698 NullableCSSValue cssValue = style->getPropertyCSSValueInternal(CSSPropertyBa ckgroundColor);
1699 return isTransparentColorValue(cssValue); 1699 return isTransparentColorValue(cssValue);
1700 } 1700 }
1701 1701
1702 bool hasTransparentBackgroundColor(StylePropertySet* style) 1702 bool hasTransparentBackgroundColor(StylePropertySet* style)
1703 { 1703 {
1704 NullableCSSValue cssValue = style->getPropertyCSSValue(CSSPropertyBackground Color); 1704 NullableCSSValue cssValue = style->getPropertyCSSValue(CSSPropertyBackground Color);
1705 return isTransparentColorValue(cssValue); 1705 return isTransparentColorValue(cssValue);
1706 } 1706 }
1707 1707
1708 NullableCSSValue backgroundColorInEffect(Node* node) 1708 NullableCSSValue backgroundColorInEffect(Node* node)
1709 { 1709 {
1710 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1710 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1711 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor); 1711 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor);
1712 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1712 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1713 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1713 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1714 } 1714 }
1715 return nullptr; 1715 return nullptr;
1716 } 1716 }
1717 1717
1718 } 1718 }
OLDNEW
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.cpp ('k') | Source/core/layout/svg/ReferenceFilterBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698