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

Unified Diff: third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Rebase please work Created 4 years, 3 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
Index: third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp b/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp
index cdb4359d89b9676489ab52204bc743e595519453..d9caa3354bec6167ef1b8d950707d897c9a9dc67 100644
--- a/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp
@@ -168,7 +168,7 @@ void StyleBuilderFunctions::applyInheritCSSPropertyColor(StyleResolverState& sta
void StyleBuilderFunctions::applyValueCSSPropertyColor(StyleResolverState& state, const CSSValue& value)
{
// As per the spec, 'color: currentColor' is treated as 'color: inherit'
- if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == CSSValueCurrentcolor) {
+ if (value.isIdentifierValue() && toCSSIdentifierValue(value).getValueID() == CSSValueCurrentcolor) {
applyInheritCSSPropertyColor(state);
return;
}
@@ -231,17 +231,17 @@ void StyleBuilderFunctions::applyValueCSSPropertyCursor(StyleResolverState& stat
state.style()->addCursor(state.styleImage(CSSPropertyCursor, image), hotSpotSpecified, hotSpot);
} else {
- state.style()->setCursor(toCSSPrimitiveValue(item).convertTo<ECursor>());
+ state.style()->setCursor(toCSSIdentifierValue(item).convertTo<ECursor>());
}
}
} else {
- state.style()->setCursor(toCSSPrimitiveValue(value).convertTo<ECursor>());
+ state.style()->setCursor(toCSSIdentifierValue(value).convertTo<ECursor>());
}
}
void StyleBuilderFunctions::applyValueCSSPropertyDirection(StyleResolverState& state, const CSSValue& value)
{
- state.style()->setDirection(toCSSPrimitiveValue(value).convertTo<TextDirection>());
+ state.style()->setDirection(toCSSIdentifierValue(value).convertTo<TextDirection>());
}
void StyleBuilderFunctions::applyInitialCSSPropertyGridTemplateAreas(StyleResolverState& state)
@@ -260,9 +260,9 @@ void StyleBuilderFunctions::applyInheritCSSPropertyGridTemplateAreas(StyleResolv
void StyleBuilderFunctions::applyValueCSSPropertyGridTemplateAreas(StyleResolverState& state, const CSSValue& value)
{
- if (value.isPrimitiveValue()) {
+ if (value.isIdentifierValue()) {
// FIXME: Shouldn't we clear the grid-area values
- DCHECK_EQ(toCSSPrimitiveValue(value).getValueID(), CSSValueNone);
+ DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueNone);
return;
}
@@ -302,28 +302,28 @@ void StyleBuilderFunctions::applyInheritCSSPropertyOutlineStyle(StyleResolverSta
void StyleBuilderFunctions::applyValueCSSPropertyOutlineStyle(StyleResolverState& state, const CSSValue& value)
{
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
- state.style()->setOutlineStyleIsAuto(primitiveValue.convertTo<OutlineIsAuto>());
- state.style()->setOutlineStyle(primitiveValue.convertTo<EBorderStyle>());
+ const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value);
+ state.style()->setOutlineStyleIsAuto(identifierValue.convertTo<OutlineIsAuto>());
+ state.style()->setOutlineStyle(identifierValue.convertTo<EBorderStyle>());
}
void StyleBuilderFunctions::applyValueCSSPropertyResize(StyleResolverState& state, const CSSValue& value)
{
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
+ const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value);
EResize r = RESIZE_NONE;
- if (primitiveValue.getValueID() == CSSValueAuto) {
+ if (identifierValue.getValueID() == CSSValueAuto) {
if (Settings* settings = state.document().settings())
r = settings->textAreasAreResizable() ? RESIZE_BOTH : RESIZE_NONE;
} else {
- r = primitiveValue.convertTo<EResize>();
+ r = identifierValue.convertTo<EResize>();
}
state.style()->setResize(r);
}
static float mmToPx(float mm) { return mm * cssPixelsPerMillimeter; }
static float inchToPx(float inch) { return inch * cssPixelsPerInch; }
-static FloatSize getPageSizeFromName(const CSSPrimitiveValue& pageSizeName)
+static FloatSize getPageSizeFromName(const CSSIdentifierValue& pageSizeName)
{
switch (pageSizeName.getValueID()) {
case CSSValueA5:
@@ -358,32 +358,33 @@ void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state,
const CSSValueList& list = toCSSValueList(value);
if (list.length() == 2) {
// <length>{2} | <page-size> <orientation>
- const CSSPrimitiveValue& first = toCSSPrimitiveValue(list.item(0));
- const CSSPrimitiveValue& second = toCSSPrimitiveValue(list.item(1));
- if (first.isLength()) {
+ const CSSValue& first = list.item(0);
+ const CSSValue& second = list.item(1);
+ if (first.isPrimitiveValue() && toCSSPrimitiveValue(first).isLength()) {
// <length>{2}
- size = FloatSize(first.computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)),
- second.computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)));
+ size = FloatSize(toCSSPrimitiveValue(first).computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)),
+ toCSSPrimitiveValue(second).computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)));
} else {
// <page-size> <orientation>
- size = getPageSizeFromName(first);
+ size = getPageSizeFromName(toCSSIdentifierValue(first));
- DCHECK(second.getValueID() == CSSValueLandscape || second.getValueID() == CSSValuePortrait);
- if (second.getValueID() == CSSValueLandscape)
+ DCHECK(toCSSIdentifierValue(second).getValueID() == CSSValueLandscape || toCSSIdentifierValue(second).getValueID() == CSSValuePortrait);
+ if (toCSSIdentifierValue(second).getValueID() == CSSValueLandscape)
size = size.transposedSize();
}
pageSizeType = PAGE_SIZE_RESOLVED;
} else {
DCHECK_EQ(list.length(), 1U);
// <length> | auto | <page-size> | [ portrait | landscape]
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(list.item(0));
- if (primitiveValue.isLength()) {
+ const CSSValue& first = list.item(0);
+ if (first.isPrimitiveValue() && toCSSPrimitiveValue(first).isLength()) {
// <length>
pageSizeType = PAGE_SIZE_RESOLVED;
- float width = primitiveValue.computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
+ float width = toCSSPrimitiveValue(first).computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
size = FloatSize(width, width);
} else {
- switch (primitiveValue.getValueID()) {
+ const CSSIdentifierValue& ident = toCSSIdentifierValue(first);
+ switch (ident.getValueID()) {
case CSSValueAuto:
pageSizeType = PAGE_SIZE_AUTO;
break;
@@ -396,7 +397,7 @@ void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state,
default:
// <page-size>
pageSizeType = PAGE_SIZE_RESOLVED;
- size = getPageSizeFromName(primitiveValue);
+ size = getPageSizeFromName(ident);
}
}
}
@@ -440,14 +441,14 @@ void StyleBuilderFunctions::applyValueCSSPropertySnapHeight(StyleResolverState&
void StyleBuilderFunctions::applyValueCSSPropertyTextAlign(StyleResolverState& state, const CSSValue& value)
{
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
- if (primitiveValue.isValueID() && primitiveValue.getValueID() != CSSValueWebkitMatchParent) {
+ if (value.isIdentifierValue() && toCSSIdentifierValue(value).getValueID() != CSSValueWebkitMatchParent) {
// Special case for th elements - UA stylesheet text-align does not apply if parent's computed value for text-align is not its initial value
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
- if (primitiveValue.getValueID() == CSSValueInternalCenter && state.parentStyle()->textAlign() != ComputedStyle::initialTextAlign())
+ const CSSIdentifierValue& identValue = toCSSIdentifierValue(value);
+ if (identValue.getValueID() == CSSValueInternalCenter && state.parentStyle()->textAlign() != ComputedStyle::initialTextAlign())
state.style()->setTextAlign(state.parentStyle()->textAlign());
else
- state.style()->setTextAlign(primitiveValue.convertTo<ETextAlign>());
+ state.style()->setTextAlign(identValue.convertTo<ETextAlign>());
}
else if (state.parentStyle()->textAlign() == TASTART)
state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? LEFT : RIGHT);
@@ -478,15 +479,15 @@ void StyleBuilderFunctions::applyValueCSSPropertyTextIndent(StyleResolverState&
TextIndentType textIndentTypeValue = ComputedStyle::initialTextIndentType();
for (auto& listValue : toCSSValueList(value)) {
- const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(listValue.get());
- if (!primitiveValue->getValueID())
- lengthOrPercentageValue = primitiveValue->convertToLength(state.cssToLengthConversionData());
- else if (primitiveValue->getValueID() == CSSValueEachLine)
+ if (listValue->isPrimitiveValue()) {
+ lengthOrPercentageValue = toCSSPrimitiveValue(*listValue).convertToLength(state.cssToLengthConversionData());
+ } else if (toCSSIdentifierValue(*listValue).getValueID() == CSSValueEachLine) {
textIndentLineValue = TextIndentEachLine;
- else if (primitiveValue->getValueID() == CSSValueHanging)
+ } else if (toCSSIdentifierValue(*listValue).getValueID() == CSSValueHanging) {
textIndentTypeValue = TextIndentHanging;
- else
+ } else {
NOTREACHED();
+ }
}
state.style()->setTextIndent(lengthOrPercentageValue);
@@ -512,12 +513,10 @@ void StyleBuilderFunctions::applyInheritCSSPropertyVerticalAlign(StyleResolverSt
void StyleBuilderFunctions::applyValueCSSPropertyVerticalAlign(StyleResolverState& state, const CSSValue& value)
{
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
-
- if (primitiveValue.getValueID())
- state.style()->setVerticalAlign(primitiveValue.convertTo<EVerticalAlign>());
+ if (value.isIdentifierValue())
+ state.style()->setVerticalAlign(toCSSIdentifierValue(value).convertTo<EVerticalAlign>());
else
- state.style()->setVerticalAlignLength(primitiveValue.convertToLength(state.cssToLengthConversionData()));
+ state.style()->setVerticalAlignLength(toCSSPrimitiveValue(value).convertToLength(state.cssToLengthConversionData()));
}
static void resetEffectiveZoom(StyleResolverState& state)
@@ -540,27 +539,32 @@ void StyleBuilderFunctions::applyInheritCSSPropertyZoom(StyleResolverState& stat
void StyleBuilderFunctions::applyValueCSSPropertyZoom(StyleResolverState& state, const CSSValue& value)
{
- SECURITY_DCHECK(value.isPrimitiveValue());
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
-
- if (primitiveValue.getValueID() == CSSValueNormal) {
- resetEffectiveZoom(state);
- state.setZoom(ComputedStyle::initialZoom());
- } else if (primitiveValue.getValueID() == CSSValueReset) {
- state.setEffectiveZoom(ComputedStyle::initialZoom());
- state.setZoom(ComputedStyle::initialZoom());
- } else if (primitiveValue.getValueID() == CSSValueDocument) {
- float docZoom = state.rootElementStyle() ? state.rootElementStyle()->zoom() : ComputedStyle::initialZoom();
- state.setEffectiveZoom(docZoom);
- state.setZoom(docZoom);
- } else if (primitiveValue.isPercentage()) {
- resetEffectiveZoom(state);
- if (float percent = primitiveValue.getFloatValue())
- state.setZoom(percent / 100.0f);
- } else if (primitiveValue.isNumber()) {
- resetEffectiveZoom(state);
- if (float number = primitiveValue.getFloatValue())
- state.setZoom(number);
+ SECURITY_DCHECK(value.isPrimitiveValue() || value.isIdentifierValue());
+
+ if (value.isIdentifierValue()) {
+ const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value);
+ if (identifierValue.getValueID() == CSSValueNormal) {
+ resetEffectiveZoom(state);
+ state.setZoom(ComputedStyle::initialZoom());
+ } else if (identifierValue.getValueID() == CSSValueReset) {
+ state.setEffectiveZoom(ComputedStyle::initialZoom());
+ state.setZoom(ComputedStyle::initialZoom());
+ } else if (identifierValue.getValueID() == CSSValueDocument) {
+ float docZoom = state.rootElementStyle() ? state.rootElementStyle()->zoom() : ComputedStyle::initialZoom();
+ state.setEffectiveZoom(docZoom);
+ state.setZoom(docZoom);
+ }
+ } else if (value.isPrimitiveValue()) {
+ const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
+ if (primitiveValue.isPercentage()) {
+ resetEffectiveZoom(state);
+ if (float percent = primitiveValue.getFloatValue())
+ state.setZoom(percent / 100.0f);
+ } else if (primitiveValue.isNumber()) {
+ resetEffectiveZoom(state);
+ if (float number = primitiveValue.getFloatValue())
+ state.setZoom(number);
+ }
}
}
@@ -591,7 +595,7 @@ void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextEmphasisStyle(StyleRe
const CSSValueList& list = toCSSValueList(value);
DCHECK_EQ(list.length(), 2U);
for (unsigned i = 0; i < 2; ++i) {
- const CSSPrimitiveValue& value = toCSSPrimitiveValue(list.item(i));
+ const CSSIdentifierValue& value = toCSSIdentifierValue(list.item(i));
if (value.getValueID() == CSSValueFilled || value.getValueID() == CSSValueOpen)
state.style()->setTextEmphasisFill(value.convertTo<TextEmphasisFill>());
else
@@ -608,16 +612,16 @@ void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextEmphasisStyle(StyleRe
return;
}
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
+ const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value);
state.style()->setTextEmphasisCustomMark(nullAtom);
- if (primitiveValue.getValueID() == CSSValueFilled || primitiveValue.getValueID() == CSSValueOpen) {
- state.style()->setTextEmphasisFill(primitiveValue.convertTo<TextEmphasisFill>());
+ if (identifierValue.getValueID() == CSSValueFilled || identifierValue.getValueID() == CSSValueOpen) {
+ state.style()->setTextEmphasisFill(identifierValue.convertTo<TextEmphasisFill>());
state.style()->setTextEmphasisMark(TextEmphasisMarkAuto);
} else {
state.style()->setTextEmphasisFill(TextEmphasisFillFilled);
- state.style()->setTextEmphasisMark(primitiveValue.convertTo<TextEmphasisMark>());
+ state.style()->setTextEmphasisMark(identifierValue.convertTo<TextEmphasisMark>());
}
}
@@ -643,16 +647,16 @@ void StyleBuilderFunctions::applyValueCSSPropertyWillChange(StyleResolverState&
bool willChangeScrollPosition = false;
Vector<CSSPropertyID> willChangeProperties;
- if (value.isPrimitiveValue()) {
- DCHECK_EQ(toCSSPrimitiveValue(value).getValueID(), CSSValueAuto);
+ if (value.isIdentifierValue()) {
+ DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueAuto);
} else {
DCHECK(value.isValueList());
for (auto& willChangeValue : toCSSValueList(value)) {
if (willChangeValue->isCustomIdentValue())
willChangeProperties.append(toCSSCustomIdentValue(*willChangeValue).valueAsPropertyID());
- else if (toCSSPrimitiveValue(*willChangeValue).getValueID() == CSSValueContents)
+ else if (toCSSIdentifierValue(*willChangeValue).getValueID() == CSSValueContents)
willChangeContents = true;
- else if (toCSSPrimitiveValue(*willChangeValue).getValueID() == CSSValueScrollPosition)
+ else if (toCSSIdentifierValue(*willChangeValue).getValueID() == CSSValueScrollPosition)
willChangeScrollPosition = true;
else
NOTREACHED();
@@ -677,8 +681,8 @@ void StyleBuilderFunctions::applyInheritCSSPropertyContent(StyleResolverState&)
void StyleBuilderFunctions::applyValueCSSPropertyContent(StyleResolverState& state, const CSSValue& value)
{
- if (value.isPrimitiveValue()) {
- DCHECK(toCSSPrimitiveValue(value).getValueID() == CSSValueNormal || toCSSPrimitiveValue(value).getValueID() == CSSValueNone);
+ if (value.isIdentifierValue()) {
+ DCHECK(toCSSIdentifierValue(value).getValueID() == CSSValueNormal || toCSSIdentifierValue(value).getValueID() == CSSValueNone);
state.style()->setContent(nullptr);
return;
}
@@ -697,9 +701,9 @@ void StyleBuilderFunctions::applyValueCSSPropertyContent(StyleResolverState& sta
listStyleType = static_cast<EListStyleType>(listStyleIdent - CSSValueDisc);
std::unique_ptr<CounterContent> counter = wrapUnique(new CounterContent(AtomicString(counterValue->identifier()), listStyleType, AtomicString(counterValue->separator())));
nextContent = ContentData::create(std::move(counter));
- } else if (item->isPrimitiveValue()) {
+ } else if (item->isIdentifierValue()) {
QuoteType quoteType;
- switch (toCSSPrimitiveValue(*item).getValueID()) {
+ switch (toCSSIdentifierValue(*item).getValueID()) {
default:
NOTREACHED();
case CSSValueOpenQuote:
@@ -753,8 +757,8 @@ void StyleBuilderFunctions::applyValueCSSPropertyContent(StyleResolverState& sta
void StyleBuilderFunctions::applyValueCSSPropertyWebkitLocale(StyleResolverState& state, const CSSValue& value)
{
- if (value.isPrimitiveValue()) {
- DCHECK_EQ(toCSSPrimitiveValue(value).getValueID(), CSSValueAuto);
+ if (value.isIdentifierValue()) {
+ DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueAuto);
state.fontBuilder().setLocale(nullptr);
} else {
state.fontBuilder().setLocale(LayoutLocale::get(AtomicString(toCSSStringValue(value).value())));
@@ -771,29 +775,29 @@ void StyleBuilderFunctions::applyInheritCSSPropertyWebkitAppRegion(StyleResolver
void StyleBuilderFunctions::applyValueCSSPropertyWebkitAppRegion(StyleResolverState& state, const CSSValue& value)
{
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
- state.style()->setDraggableRegionMode(primitiveValue.getValueID() == CSSValueDrag ? DraggableRegionDrag : DraggableRegionNoDrag);
+ const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value);
+ state.style()->setDraggableRegionMode(identifierValue.getValueID() == CSSValueDrag ? DraggableRegionDrag : DraggableRegionNoDrag);
state.document().setHasAnnotatedRegions(true);
}
void StyleBuilderFunctions::applyValueCSSPropertyWritingMode(StyleResolverState& state, const CSSValue& value)
{
- state.setWritingMode(toCSSPrimitiveValue(value).convertTo<WritingMode>());
+ state.setWritingMode(toCSSIdentifierValue(value).convertTo<WritingMode>());
}
void StyleBuilderFunctions::applyValueCSSPropertyWebkitWritingMode(StyleResolverState& state, const CSSValue& value)
{
- state.setWritingMode(toCSSPrimitiveValue(value).convertTo<WritingMode>());
+ state.setWritingMode(toCSSIdentifierValue(value).convertTo<WritingMode>());
}
void StyleBuilderFunctions::applyValueCSSPropertyTextOrientation(StyleResolverState& state, const CSSValue& value)
{
- state.setTextOrientation(toCSSPrimitiveValue(value).convertTo<TextOrientation>());
+ state.setTextOrientation(toCSSIdentifierValue(value).convertTo<TextOrientation>());
}
void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextOrientation(StyleResolverState& state, const CSSValue& value)
{
- state.setTextOrientation(toCSSPrimitiveValue(value).convertTo<TextOrientation>());
+ state.setTextOrientation(toCSSIdentifierValue(value).convertTo<TextOrientation>());
}
void StyleBuilderFunctions::applyValueCSSPropertyVariable(StyleResolverState& state, const CSSValue& value)
@@ -887,13 +891,12 @@ void StyleBuilderFunctions::applyInheritCSSPropertyBaselineShift(StyleResolverSt
void StyleBuilderFunctions::applyValueCSSPropertyBaselineShift(StyleResolverState& state, const CSSValue& value)
{
SVGComputedStyle& svgStyle = state.style()->accessSVGStyle();
- const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
- if (!primitiveValue.isValueID()) {
+ if (!value.isIdentifierValue()) {
svgStyle.setBaselineShift(BS_LENGTH);
- svgStyle.setBaselineShiftValue(StyleBuilderConverter::convertLength(state, primitiveValue));
+ svgStyle.setBaselineShiftValue(StyleBuilderConverter::convertLength(state, toCSSPrimitiveValue(value)));
return;
}
- switch (primitiveValue.getValueID()) {
+ switch (toCSSIdentifierValue(value).getValueID()) {
case CSSValueBaseline:
svgStyle.setBaselineShift(BS_LENGTH);
svgStyle.setBaselineShiftValue(Length(Fixed));

Powered by Google App Engine
This is Rietveld 408576698