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

Side by Side Diff: Source/core/css/resolver/StyleBuilderConverter.cpp

Issue 1306823004: Split out String, URI and CustomIdent from CSSPrimitiveValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@split_out_attr_values
Patch Set: Rebase Created 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * * Redistributions of source code must retain the above copyright 4 * * Redistributions of source code must retain the above copyright
5 * notice, this list of conditions and the following disclaimer. 5 * notice, this list of conditions and the following disclaimer.
6 * * Redistributions in binary form must reproduce the above 6 * * Redistributions in binary form must reproduce the above
7 * copyright notice, this list of conditions and the following disclaimer 7 * copyright notice, this list of conditions and the following disclaimer
8 * in the documentation and/or other materials provided with the 8 * in the documentation and/or other materials provided with the
9 * distribution. 9 * distribution.
10 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 86
87 Color StyleBuilderConverter::convertColor(StyleResolverState& state, CSSValue* v alue, bool forVisitedLink) 87 Color StyleBuilderConverter::convertColor(StyleResolverState& state, CSSValue* v alue, bool forVisitedLink)
88 { 88 {
89 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 89 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
90 return state.document().textLinkColors().colorFromPrimitiveValue(primitiveVa lue, state.style()->color(), forVisitedLink); 90 return state.document().textLinkColors().colorFromPrimitiveValue(primitiveVa lue, state.style()->color(), forVisitedLink);
91 } 91 }
92 92
93 AtomicString StyleBuilderConverter::convertFragmentIdentifier(StyleResolverState & state, CSSValue* value) 93 AtomicString StyleBuilderConverter::convertFragmentIdentifier(StyleResolverState & state, CSSValue* value)
94 { 94 {
95 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 95 if (value->isStringValue() && toCSSStringValue(value)->serializationType() = = CSSStringValue::SerializeAsURI)
96 if (primitiveValue->isURI()) 96 return SVGURIReference::fragmentIdentifierFromIRIString(toCSSStringValue (value)->getStringValue(), state.element()->treeScope());
97 return SVGURIReference::fragmentIdentifierFromIRIString(primitiveValue-> getStringValue(), state.element()->treeScope());
98 return nullAtom; 97 return nullAtom;
99 } 98 }
100 99
101 LengthBox StyleBuilderConverter::convertClip(StyleResolverState& state, CSSValue * value) 100 LengthBox StyleBuilderConverter::convertClip(StyleResolverState& state, CSSValue * value)
102 { 101 {
103 RefPtrWillBeRawPtr<CSSQuadValue> rect = toCSSQuadValue(value); 102 RefPtrWillBeRawPtr<CSSQuadValue> rect = toCSSQuadValue(value);
104 103
105 return LengthBox(convertLengthOrAuto(state, rect->top()), 104 return LengthBox(convertLengthOrAuto(state, rect->top()),
106 convertLengthOrAuto(state, rect->right()), 105 convertLengthOrAuto(state, rect->right()),
107 convertLengthOrAuto(state, rect->bottom()), 106 convertLengthOrAuto(state, rect->bottom()),
(...skipping 15 matching lines...) Expand all
123 return FontDescription::FantasyFamily; 122 return FontDescription::FantasyFamily;
124 case CSSValueMonospace: 123 case CSSValueMonospace:
125 return FontDescription::MonospaceFamily; 124 return FontDescription::MonospaceFamily;
126 case CSSValueWebkitPictograph: 125 case CSSValueWebkitPictograph:
127 return FontDescription::PictographFamily; 126 return FontDescription::PictographFamily;
128 default: 127 default:
129 return FontDescription::NoFamily; 128 return FontDescription::NoFamily;
130 } 129 }
131 } 130 }
132 131
133 static bool convertFontFamilyName(StyleResolverState& state, CSSPrimitiveValue* primitiveValue, 132 static bool convertFontFamilyName(StyleResolverState& state, CSSValue* value,
134 FontDescription::GenericFamilyType& genericFamily, AtomicString& familyName) 133 FontDescription::GenericFamilyType& genericFamily, AtomicString& familyName)
135 { 134 {
136 if (primitiveValue->isCustomIdent()) { 135 if (value->isStringValue() && toCSSStringValue(value)->serializationType() = = CSSStringValue::SerializeAsCustomIdentifier) {
137 genericFamily = FontDescription::NoFamily; 136 genericFamily = FontDescription::NoFamily;
138 familyName = AtomicString(primitiveValue->getStringValue()); 137 familyName = AtomicString(toCSSStringValue(value)->getStringValue());
139 } else if (state.document().settings()) { 138 } else if (state.document().settings()) {
140 genericFamily = convertGenericFamily(primitiveValue->getValueID()); 139 genericFamily = convertGenericFamily(toCSSPrimitiveValue(value)->getValu eID());
141 familyName = state.fontBuilder().genericFontFamilyName(genericFamily); 140 familyName = state.fontBuilder().genericFontFamilyName(genericFamily);
142 } 141 }
143 142
144 return !familyName.isEmpty(); 143 return !familyName.isEmpty();
145 } 144 }
146 145
147 FontDescription::FamilyDescription StyleBuilderConverter::convertFontFamily(Styl eResolverState& state, CSSValue* value) 146 FontDescription::FamilyDescription StyleBuilderConverter::convertFontFamily(Styl eResolverState& state, CSSValue* value)
148 { 147 {
149 ASSERT(value->isValueList()); 148 ASSERT(value->isValueList());
150 149
151 FontDescription::FamilyDescription desc(FontDescription::NoFamily); 150 FontDescription::FamilyDescription desc(FontDescription::NoFamily);
152 FontFamily* currFamily = nullptr; 151 FontFamily* currFamily = nullptr;
153 152
154 for (auto& family : toCSSValueList(*value)) { 153 for (auto& family : toCSSValueList(*value)) {
155 FontDescription::GenericFamilyType genericFamily = FontDescription::NoFa mily; 154 FontDescription::GenericFamilyType genericFamily = FontDescription::NoFa mily;
156 AtomicString familyName; 155 AtomicString familyName;
157 156
158 if (!convertFontFamilyName(state, toCSSPrimitiveValue(family.get()), gen ericFamily, familyName)) 157 if (!convertFontFamilyName(state, family.get(), genericFamily, familyNam e))
159 continue; 158 continue;
160 159
161 if (!currFamily) { 160 if (!currFamily) {
162 currFamily = &desc.family; 161 currFamily = &desc.family;
163 } else { 162 } else {
164 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create(); 163 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
165 currFamily->appendFamily(newFamily); 164 currFamily->appendFamily(newFamily);
166 currFamily = newFamily.get(); 165 currFamily = newFamily.get();
167 } 166 }
168 167
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 390 }
392 } 391 }
393 392
394 GridPosition StyleBuilderConverter::convertGridPosition(StyleResolverState&, CSS Value* value) 393 GridPosition StyleBuilderConverter::convertGridPosition(StyleResolverState&, CSS Value* value)
395 { 394 {
396 // We accept the specification's grammar: 395 // We accept the specification's grammar:
397 // 'auto' | [ <integer> || <custom-ident> ] | [ span && [ <integer> || <cust om-ident> ] ] | <custom-ident> 396 // 'auto' | [ <integer> || <custom-ident> ] | [ span && [ <integer> || <cust om-ident> ] ] | <custom-ident>
398 397
399 GridPosition position; 398 GridPosition position;
400 399
401 if (value->isPrimitiveValue()) { 400 if (value->isStringValue()) {
402 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 401 CSSStringValue* stringValue = toCSSStringValue(value);
403 // We translate <custom-ident> to <string> during parsing as it 402 // We translate <custom-ident> to <string> during parsing as it
404 // makes handling it more simple. 403 // makes handling it more simple.
405 if (primitiveValue->isCustomIdent()) { 404 ASSERT(stringValue->serializationType() == CSSStringValue::SerializeAsCu stomIdentifier);
406 position.setNamedGridArea(primitiveValue->getStringValue()); 405 position.setNamedGridArea(stringValue->getStringValue());
407 return position;
408 }
409
410 ASSERT(primitiveValue->getValueID() == CSSValueAuto);
411 return position; 406 return position;
412 } 407 }
413 408
409 if (value->isPrimitiveValue()) {
410 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueAuto);
411 return position;
412 }
413
414 CSSValueList* values = toCSSValueList(value); 414 CSSValueList* values = toCSSValueList(value);
415 ASSERT(values->length()); 415 ASSERT(values->length());
416 416
417 bool isSpanPosition = false; 417 bool isSpanPosition = false;
418 // The specification makes the <integer> optional, in which case it default to '1'. 418 // The specification makes the <integer> optional, in which case it default to '1'.
419 int gridLineNumber = 1; 419 int gridLineNumber = 1;
420 String gridLineName; 420 String gridLineName;
421 421
422 auto it = values->begin(); 422 auto it = values->begin();
423 CSSPrimitiveValue* currentValue = toCSSPrimitiveValue(it->get()); 423 CSSValue* currentValue = it->get();
424 if (currentValue->getValueID() == CSSValueSpan) { 424 if (currentValue->isPrimitiveValue() && toCSSPrimitiveValue(currentValue)->g etValueID() == CSSValueSpan) {
425 isSpanPosition = true; 425 isSpanPosition = true;
426 ++it; 426 ++it;
427 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : 0; 427 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : 0;
428 } 428 }
429 429
430 if (currentValue && currentValue->isNumber()) { 430 if (currentValue && currentValue->isPrimitiveValue() && toCSSPrimitiveValue( currentValue)->isNumber()) {
431 gridLineNumber = currentValue->getIntValue(); 431 gridLineNumber = toCSSPrimitiveValue(currentValue)->getIntValue();
432 ++it; 432 ++it;
433 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : 0; 433 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : 0;
434 } 434 }
435 435
436 if (currentValue && currentValue->isCustomIdent()) { 436 if (currentValue && currentValue->isStringValue() && toCSSStringValue(curren tValue)->serializationType() == CSSStringValue::SerializeAsCustomIdentifier) {
437 gridLineName = currentValue->getStringValue(); 437 gridLineName = toCSSStringValue(currentValue)->getStringValue();
438 ++it; 438 ++it;
439 } 439 }
440 440
441 ASSERT(it == values->end()); 441 ASSERT(it == values->end());
442 if (isSpanPosition) 442 if (isSpanPosition)
443 position.setSpanPosition(gridLineNumber, gridLineName); 443 position.setSpanPosition(gridLineNumber, gridLineName);
444 else 444 else
445 position.setExplicitPosition(gridLineNumber, gridLineName); 445 position.setExplicitPosition(gridLineNumber, gridLineName);
446 446
447 return position; 447 return position;
(...skipping 15 matching lines...) Expand all
463 { 463 {
464 if (value->isPrimitiveValue()) { 464 if (value->isPrimitiveValue()) {
465 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); 465 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone);
466 return; 466 return;
467 } 467 }
468 468
469 size_t currentNamedGridLine = 0; 469 size_t currentNamedGridLine = 0;
470 for (auto& currValue : *toCSSValueList(value)) { 470 for (auto& currValue : *toCSSValueList(value)) {
471 if (currValue->isGridLineNamesValue()) { 471 if (currValue->isGridLineNamesValue()) {
472 for (auto& namedGridLineValue : toCSSGridLineNamesValue(*currValue)) { 472 for (auto& namedGridLineValue : toCSSGridLineNamesValue(*currValue)) {
473 ASSERT(toCSSPrimitiveValue(namedGridLineValue.get())->isCustomId ent()); 473 ASSERT(toCSSStringValue(namedGridLineValue.get())->serialization Type() == CSSStringValue::SerializeAsCustomIdentifier);
474 String namedGridLine = toCSSPrimitiveValue(namedGridLineValue.ge t())->getStringValue(); 474 String namedGridLine = toCSSStringValue(namedGridLineValue.get() )->getStringValue();
475 NamedGridLinesMap::AddResult result = namedGridLines.add(namedGr idLine, Vector<size_t>()); 475 NamedGridLinesMap::AddResult result = namedGridLines.add(namedGr idLine, Vector<size_t>());
476 result.storedValue->value.append(currentNamedGridLine); 476 result.storedValue->value.append(currentNamedGridLine);
477 OrderedNamedGridLines::AddResult orderedInsertionResult = ordere dNamedGridLines.add(currentNamedGridLine, Vector<String>()); 477 OrderedNamedGridLines::AddResult orderedInsertionResult = ordere dNamedGridLines.add(currentNamedGridLine, Vector<String>());
478 orderedInsertionResult.storedValue->value.append(namedGridLine); 478 orderedInsertionResult.storedValue->value.append(namedGridLine);
479 } 479 }
480 continue; 480 continue;
481 } 481 }
482 482
483 ++currentNamedGridLine; 483 ++currentNamedGridLine;
484 trackSizes.append(convertGridTrackSize(state, currValue.get())); 484 trackSizes.append(convertGridTrackSize(state, currValue.get()));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 } 736 }
737 737
738 PassRefPtr<QuotesData> StyleBuilderConverter::convertQuotes(StyleResolverState&, CSSValue* value) 738 PassRefPtr<QuotesData> StyleBuilderConverter::convertQuotes(StyleResolverState&, CSSValue* value)
739 { 739 {
740 if (value->isValueList()) { 740 if (value->isValueList()) {
741 CSSValueList* list = toCSSValueList(value); 741 CSSValueList* list = toCSSValueList(value);
742 RefPtr<QuotesData> quotes = QuotesData::create(); 742 RefPtr<QuotesData> quotes = QuotesData::create();
743 for (size_t i = 0; i < list->length(); i += 2) { 743 for (size_t i = 0; i < list->length(); i += 2) {
744 CSSValue* first = list->item(i); 744 CSSValue* first = list->item(i);
745 CSSValue* second = list->item(i + 1); 745 CSSValue* second = list->item(i + 1);
746 ASSERT(toCSSPrimitiveValue(first)->isString()); 746 ASSERT(toCSSStringValue(first)->serializationType() == CSSStringValu e::SerializeAsString);
747 ASSERT(toCSSPrimitiveValue(second)->isString()); 747 ASSERT(toCSSStringValue(second)->serializationType() == CSSStringVal ue::SerializeAsString);
748 String startQuote = toCSSPrimitiveValue(first)->getStringValue(); 748 String startQuote = toCSSStringValue(first)->getStringValue();
749 String endQuote = toCSSPrimitiveValue(second)->getStringValue(); 749 String endQuote = toCSSStringValue(second)->getStringValue();
750 quotes->addPair(std::make_pair(startQuote, endQuote)); 750 quotes->addPair(std::make_pair(startQuote, endQuote));
751 } 751 }
752 return quotes.release(); 752 return quotes.release();
753 } 753 }
754 ASSERT(value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); 754 ASSERT(value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNone);
755 return QuotesData::create(); 755 return QuotesData::create();
756 } 756 }
757 757
758 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, CSSVa lue* value) 758 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, CSSVa lue* value)
759 { 759 {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 return ScaleTransformOperation::create(sx, sy, sz, TransformOperation::Scale 3D); 961 return ScaleTransformOperation::create(sx, sy, sz, TransformOperation::Scale 3D);
962 } 962 }
963 963
964 RespectImageOrientationEnum StyleBuilderConverter::convertImageOrientation(Style ResolverState& state, CSSValue* value) 964 RespectImageOrientationEnum StyleBuilderConverter::convertImageOrientation(Style ResolverState& state, CSSValue* value)
965 { 965 {
966 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 966 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
967 return primitiveValue->getValueID() == CSSValueFromImage ? RespectImageOrien tation : DoNotRespectImageOrientation; 967 return primitiveValue->getValueID() == CSSValueFromImage ? RespectImageOrien tation : DoNotRespectImageOrientation;
968 } 968 }
969 969
970 } // namespace blink 970 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698