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

Unified Diff: Source/core/editing/EditingStyle.cpp

Issue 1249553002: CSSValue Immediates: Add move operators to CSSPrimitiveValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_3_tagged_ptrs_with_copy_ops_mv_operators_ref_primvalue
Patch Set: Rebase Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/EditingStyle.cpp
diff --git a/Source/core/editing/EditingStyle.cpp b/Source/core/editing/EditingStyle.cpp
index 17bb1b7b8ff0c8c6fff05462c3548e7693610ff0..43d50ded8d2dd3a65a72fee777bf99e59ed97e0e 100644
--- a/Source/core/editing/EditingStyle.cpp
+++ b/Source/core/editing/EditingStyle.cpp
@@ -148,13 +148,13 @@ static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS
static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StylePropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle);
enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelValuesMatch };
-static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool, LegacyFontSizeMode);
+static int legacyFontSizeFromCSSValue(Document*, const CSSPrimitiveValue&, bool, LegacyFontSizeMode);
static bool isTransparentColorValue(const NullableCSSValue&);
static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
static bool hasTransparentBackgroundColor(StylePropertySet*);
static NullableCSSValue backgroundColorInEffect(Node*);
-class HTMLElementEquivalent : public NoBaseWillBeGarbageCollected<HTMLElementEquivalent> {
+class HTMLElementEquivalent : public NoBaseWillBeGarbageCollectedFinalized<HTMLElementEquivalent> {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HTMLElementEquivalent);
DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
public:
@@ -165,7 +165,7 @@ public:
virtual bool matches(const Element* element) const { return !m_tagName || element->hasTagName(*m_tagName); }
virtual bool hasAttribute() const { return false; }
- virtual bool propertyExistsInStyle(const StylePropertySet* style) const { return style->getPropertyCSSValue(m_propertyID); }
+ virtual bool propertyExistsInStyle(const StylePropertySet* style) const { return (bool)style->getPropertyCSSValue(m_propertyID); }
virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const;
virtual void addToStyle(Element*, EditingStyle*) const;
@@ -176,7 +176,7 @@ protected:
HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName);
HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName);
const CSSPropertyID m_propertyID;
- const RefPtrWillBeMember<CSSPrimitiveValue> m_primitiveValue;
+ const NullableCSSValue m_primitiveValue;
const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML tag names are const global.
};
@@ -204,8 +204,8 @@ HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit
bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePropertySet* style) const
{
- NullableCSSValue value = style->getPropertyCSSValue(m_propertyID);
- return matches(element) && value && value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == m_primitiveValue->getValueID();
+ const NullableCSSValue &value = style->getPropertyCSSValue(m_propertyID);
+ return matches(element) && value && value->isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == toCSSPrimitiveValue(m_primitiveValue).getValueID();
}
void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
@@ -263,7 +263,7 @@ public:
bool hasAttribute() const override { return true; }
bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const override;
void addToStyle(Element*, EditingStyle*) const override;
- virtual NullableCSSValue attributeValueAsCSSValue(Element*) const;
+ virtual const NullableCSSValue attributeValueAsCSSValue(Element*) const;
inline const QualifiedName& attributeName() const { return m_attrName; }
DEFINE_INLINE_VIRTUAL_TRACE() { HTMLElementEquivalent::trace(visitor); }
@@ -288,8 +288,8 @@ HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const Qualifi
bool HTMLAttributeEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePropertySet* style) const
{
- NullableCSSValue value = attributeValueAsCSSValue(element);
- NullableCSSValue styleValue = style->getPropertyCSSValue(m_propertyID);
+ const NullableCSSValue& value = attributeValueAsCSSValue(element);
+ const NullableCSSValue& styleValue = style->getPropertyCSSValue(m_propertyID);
return value == styleValue;
}
@@ -300,7 +300,7 @@ void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style)
style->setProperty(m_propertyID, value->cssText());
}
-NullableCSSValue HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) const
+const NullableCSSValue HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) const
{
ASSERT(element);
const AtomicString& value = element->getAttribute(m_attrName);
@@ -319,7 +319,7 @@ public:
{
return adoptPtrWillBeNoop(new HTMLFontSizeEquivalent());
}
- NullableCSSValue attributeValueAsCSSValue(Element*) const override;
+ const NullableCSSValue attributeValueAsCSSValue(Element*) const override;
DEFINE_INLINE_VIRTUAL_TRACE() { HTMLAttributeEquivalent::trace(visitor); }
@@ -332,7 +332,7 @@ HTMLFontSizeEquivalent::HTMLFontSizeEquivalent()
{
}
-NullableCSSValue HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) const
+const NullableCSSValue HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) const
{
ASSERT(element);
const AtomicString& value = element->getAttribute(m_attrName);
@@ -391,9 +391,9 @@ static RGBA32 cssValueToRGBA(NullableCSSValue colorValue)
if (!colorValue || !colorValue->isPrimitiveValue())
return Color::transparent;
- CSSPrimitiveValue* primitiveColor = toCSSPrimitiveValue(colorValue);
- if (primitiveColor->isRGBColor())
- return primitiveColor->getRGBA32Value();
+ const CSSPrimitiveValue& primitiveColor = toCSSPrimitiveValue(colorValue);
+ if (primitiveColor.isRGBColor())
+ return primitiveColor.getRGBA32Value();
RGBA32 rgba = 0;
// FIXME: Why ignore the return value?
@@ -519,18 +519,18 @@ void EditingStyle::extractFontSizeDelta()
}
// Get the adjustment amount out of the style.
- NullableCSSValue value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitFontSizeDelta);
+ const NullableCSSValue& value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitFontSizeDelta);
if (!value || !value->isPrimitiveValue())
return;
- CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
+ const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
// Only PX handled now. If we handle more types in the future, perhaps
// a switch statement here would be more appropriate.
- if (!primitiveValue->isPx())
+ if (!primitiveValue.isPx())
return;
- m_fontSizeDelta = primitiveValue->getFloatValue();
+ m_fontSizeDelta = primitiveValue.getFloatValue();
m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
}
@@ -544,17 +544,17 @@ bool EditingStyle::textDirection(WritingDirection& writingDirection) const
if (!m_mutableStyle)
return false;
- NullableCSSValue unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
+ const NullableCSSValue& unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
return false;
- CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID();
+ CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi).getValueID();
if (unicodeBidiValue == CSSValueEmbed) {
- NullableCSSValue direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
+ const NullableCSSValue& direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
if (!direction || !direction->isPrimitiveValue())
return false;
- writingDirection = toCSSPrimitiveValue(direction)->getValueID() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
+ writingDirection = toCSSPrimitiveValue(direction).getValueID() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
return true;
}
@@ -688,7 +688,7 @@ void EditingStyle::collapseTextDecorationProperties()
if (!m_mutableStyle)
return;
- NullableCSSValue textDecorationsInEffect = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
+ const NullableCSSValue& textDecorationsInEffect = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
if (!textDecorationsInEffect)
return;
@@ -1005,9 +1005,9 @@ void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit
m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
if (unicodeBidi && unicodeBidi->isPrimitiveValue()) {
- m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue(unicodeBidi)->getValueID());
+ m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue(unicodeBidi).getValueID());
if (direction && direction->isPrimitiveValue())
- m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValue(direction)->getValueID());
+ m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValue(direction).getValueID());
}
}
@@ -1124,14 +1124,14 @@ PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::wrappingStyleForSerialization
static void mergeTextDecorationValues(CSSValueList& mergedValue, const CSSValueList& valueToMerge)
{
- DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSPrimitiveValue::createIdentifier(CSSValueUnderline)));
- DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough)));
+ CSSPrimitiveValue underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
+ CSSPrimitiveValue lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
- if (valueToMerge.hasValue(CSSValue(*underline)) && !mergedValue.hasValue(CSSValue(*underline)))
- mergedValue.append(CSSValue(*underline));
+ if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline))
+ mergedValue.append(underline);
- if (valueToMerge.hasValue(CSSValue(*lineThrough)) && !mergedValue.hasValue(CSSValue(*lineThrough)))
- mergedValue.append(CSSValue(*lineThrough));
+ if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough))
+ mergedValue.append(lineThrough);
}
void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverrideMode mode)
@@ -1298,7 +1298,7 @@ void EditingStyle::forceInline()
int EditingStyle::legacyFontSize(Document* document) const
{
- NullableCSSValue cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize);
+ const NullableCSSValue& cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize);
if (!cssValue || !cssValue->isPrimitiveValue())
return 0;
return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue),
@@ -1367,7 +1367,7 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
continue;
- CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID();
+ CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi).getValueID();
if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValueBidiOverride)
return NaturalWritingDirection;
}
@@ -1397,7 +1397,7 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
continue;
- CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID();
+ CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi).getValueID();
if (unicodeBidiValue == CSSValueNormal)
continue;
@@ -1409,7 +1409,7 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
if (!direction || !direction->isPrimitiveValue())
continue;
- int directionValue = toCSSPrimitiveValue(direction)->getValueID();
+ int directionValue = toCSSPrimitiveValue(direction).getValueID();
if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
continue;
@@ -1433,7 +1433,7 @@ DEFINE_TRACE(EditingStyle)
static void reconcileTextDecorationProperties(MutableStylePropertySet* style)
{
- NullableCSSValue textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
+ const NullableCSSValue& textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
NullableCSSValue textDecoration = style->getPropertyCSSValue(textDecorationPropertyForEditing());
// We shouldn't have both text-decoration and -webkit-text-decorations-in-effect because that wouldn't make sense.
ASSERT(!textDecorationsInEffect || !textDecoration);
@@ -1509,14 +1509,14 @@ void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet*
// Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
// Furthermore, text-decoration: none has been trimmed so that text-decoration property is always a CSSValueList.
- NullableCSSValue textDecoration = style->getPropertyCSSValue(textDecorationPropertyForEditing());
+ const NullableCSSValue& textDecoration = style->getPropertyCSSValue(textDecorationPropertyForEditing());
if (textDecoration && textDecoration->isValueList()) {
- DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSPrimitiveValue::createIdentifier(CSSValueUnderline)));
- DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough)));
+ CSSPrimitiveValue underline = CSSPrimitiveValue::createIdentifier(CSSValueUnderline);
+ CSSPrimitiveValue lineThrough = CSSPrimitiveValue::createIdentifier(CSSValueLineThrough);
RefPtrWillBeRawPtr<CSSValueList> newTextDecoration = toCSSValueList(textDecoration)->copy();
- if (newTextDecoration->removeAll(CSSValue(*underline)))
+ if (newTextDecoration->removeAll(underline))
m_applyUnderline = true;
- if (newTextDecoration->removeAll(CSSValue(*lineThrough)))
+ if (newTextDecoration->removeAll(lineThrough))
m_applyLineThrough = true;
// If trimTextDecorations, delete underline and line-through
@@ -1545,7 +1545,7 @@ void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet*
m_applyFontFace.replaceWithLiteral('\'', "");
style->removeProperty(CSSPropertyFontFamily);
- if (NullableCSSValue fontSize = style->getPropertyCSSValue(CSSPropertyFontSize)) {
+ if (const NullableCSSValue& fontSize = style->getPropertyCSSValue(CSSPropertyFontSize)) {
if (!fontSize->isPrimitiveValue()) {
style->removeProperty(CSSPropertyFontSize); // Can't make sense of the number. Put no font size.
} else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesMatch)) {
@@ -1557,7 +1557,7 @@ void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet*
static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID propertyID, NullableCSSValue refTextDecoration)
{
- NullableCSSValue textDecoration = style->getPropertyCSSValue(propertyID);
+ const NullableCSSValue& textDecoration = style->getPropertyCSSValue(propertyID);
if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
return;
@@ -1621,7 +1621,7 @@ PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleProperty
diffTextDecorations(result.get(), CSSPropertyWebkitTextDecorationsInEffect, baseTextDecorationsInEffect);
if (NullableCSSValue baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPropertyFontWeight)) {
- if (NullableCSSValue fontWeight = result->getPropertyCSSValue(CSSPropertyFontWeight)) {
+ if (const NullableCSSValue& fontWeight = result->getPropertyCSSValue(CSSPropertyFontWeight)) {
if (!fontWeightNeedsResolving(*fontWeight) && (fontWeightIsBold(*fontWeight) == fontWeightIsBold(*baseFontWeight)))
result->removeProperty(CSSPropertyFontWeight);
}
@@ -1644,10 +1644,10 @@ CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID)
{
if (!style)
return CSSValueInvalid;
- NullableCSSValue value = style->getPropertyCSSValue(propertyID);
+ const NullableCSSValue& value = style->getPropertyCSSValue(propertyID);
if (!value || !value->isPrimitiveValue())
return CSSValueInvalid;
- return toCSSPrimitiveValue(value)->getValueID();
+ return toCSSPrimitiveValue(value).getValueID();
}
CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID propertyID)
@@ -1657,16 +1657,16 @@ CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property
NullableCSSValue value = style->getPropertyCSSValueInternal(propertyID);
if (!value || !value->isPrimitiveValue())
return CSSValueInvalid;
- return toCSSPrimitiveValue(value)->getValueID();
+ return toCSSPrimitiveValue(value).getValueID();
}
-int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, bool isMonospaceFont, LegacyFontSizeMode mode)
+int legacyFontSizeFromCSSValue(Document* document, const CSSPrimitiveValue& value, bool isMonospaceFont, LegacyFontSizeMode mode)
{
CSSPrimitiveValue::LengthUnitType lengthType;
- if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->primitiveType(), lengthType)
+ if (CSSPrimitiveValue::unitTypeToLengthUnitType(value.primitiveType(), lengthType)
&& lengthType == CSSPrimitiveValue::UnitTypePixels) {
- double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(value->primitiveType());
- int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion);
+ double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(value.primitiveType());
+ int pixelFontSize = clampTo<int>(value.getDoubleValue() * conversion);
int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, isMonospaceFont);
// Use legacy font size only if pixel value matches exactly to that of legacy font size.
if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(document, legacyFontSize, isMonospaceFont) == pixelFontSize)
@@ -1675,8 +1675,8 @@ int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, boo
return 0;
}
- if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValueWebkitXxxLarge)
- return value->getValueID() - CSSValueXSmall + 1;
+ if (CSSValueXSmall <= value.getValueID() && value.getValueID() <= CSSValueWebkitXxxLarge)
+ return value.getValueID() - CSSValueXSmall + 1;
return 0;
}
@@ -1687,10 +1687,10 @@ bool isTransparentColorValue(const NullableCSSValue& cssValue)
return true;
if (!cssValue->isPrimitiveValue())
return false;
- CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue);
- if (value->isRGBColor())
- return !alphaChannel(value->getRGBA32Value());
- return value->getValueID() == CSSValueTransparent;
+ const CSSPrimitiveValue& value = toCSSPrimitiveValue(cssValue);
+ if (value.isRGBColor())
+ return !alphaChannel(value.getRGBA32Value());
+ return value.getValueID() == CSSValueTransparent;
}
bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
@@ -1701,7 +1701,7 @@ bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
bool hasTransparentBackgroundColor(StylePropertySet* style)
{
- NullableCSSValue cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundColor);
+ const NullableCSSValue& cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundColor);
return isTransparentColorValue(cssValue);
}
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698