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

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: Fixing tests 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->isURIValue())
96 if (primitiveValue->isURI()) 96 return SVGURIReference::fragmentIdentifierFromIRIString(toCSSURIValue(va lue)->value(), 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->isCustomIdentValue()) {
137 genericFamily = FontDescription::NoFamily; 136 genericFamily = FontDescription::NoFamily;
138 familyName = AtomicString(primitiveValue->getStringValue()); 137 familyName = AtomicString(toCSSCustomIdentValue(value)->value());
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 389 }
391 } 390 }
392 391
393 GridPosition StyleBuilderConverter::convertGridPosition(StyleResolverState&, CSS Value* value) 392 GridPosition StyleBuilderConverter::convertGridPosition(StyleResolverState&, CSS Value* value)
394 { 393 {
395 // We accept the specification's grammar: 394 // We accept the specification's grammar:
396 // 'auto' | [ <integer> || <custom-ident> ] | [ span && [ <integer> || <cust om-ident> ] ] | <custom-ident> 395 // 'auto' | [ <integer> || <custom-ident> ] | [ span && [ <integer> || <cust om-ident> ] ] | <custom-ident>
397 396
398 GridPosition position; 397 GridPosition position;
399 398
400 if (value->isPrimitiveValue()) { 399 if (value->isCustomIdentValue()) {
401 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
402 // We translate <custom-ident> to <string> during parsing as it 400 // We translate <custom-ident> to <string> during parsing as it
403 // makes handling it more simple. 401 // makes handling it more simple.
404 if (primitiveValue->isCustomIdent()) { 402 position.setNamedGridArea(toCSSCustomIdentValue(value)->value());
405 position.setNamedGridArea(primitiveValue->getStringValue());
406 return position;
407 }
408
409 ASSERT(primitiveValue->getValueID() == CSSValueAuto);
410 return position; 403 return position;
411 } 404 }
412 405
406 if (value->isPrimitiveValue()) {
407 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueAuto);
408 return position;
409 }
410
413 CSSValueList* values = toCSSValueList(value); 411 CSSValueList* values = toCSSValueList(value);
414 ASSERT(values->length()); 412 ASSERT(values->length());
415 413
416 bool isSpanPosition = false; 414 bool isSpanPosition = false;
417 // The specification makes the <integer> optional, in which case it default to '1'. 415 // The specification makes the <integer> optional, in which case it default to '1'.
418 int gridLineNumber = 1; 416 int gridLineNumber = 1;
419 String gridLineName; 417 String gridLineName;
420 418
421 auto it = values->begin(); 419 auto it = values->begin();
422 CSSPrimitiveValue* currentValue = toCSSPrimitiveValue(it->get()); 420 CSSValue* currentValue = it->get();
423 if (currentValue->getValueID() == CSSValueSpan) { 421 if (currentValue->isPrimitiveValue() && toCSSPrimitiveValue(currentValue)->g etValueID() == CSSValueSpan) {
424 isSpanPosition = true; 422 isSpanPosition = true;
425 ++it; 423 ++it;
426 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : nu llptr; 424 currentValue = it != values->end() ? it->get() : nullptr;
427 } 425 }
428 426
429 if (currentValue && currentValue->isNumber()) { 427 if (currentValue && currentValue->isPrimitiveValue() && toCSSPrimitiveValue( currentValue)->isNumber()) {
430 gridLineNumber = currentValue->getIntValue(); 428 gridLineNumber = toCSSPrimitiveValue(currentValue)->getIntValue();
431 ++it; 429 ++it;
432 currentValue = it != values->end() ? toCSSPrimitiveValue(it->get()) : nu llptr; 430 currentValue = it != values->end() ? it->get() : nullptr;
433 } 431 }
434 432
435 if (currentValue && currentValue->isCustomIdent()) { 433 if (currentValue && currentValue->isCustomIdentValue()) {
436 gridLineName = currentValue->getStringValue(); 434 gridLineName = toCSSCustomIdentValue(currentValue)->value();
437 ++it; 435 ++it;
438 } 436 }
439 437
440 ASSERT(it == values->end()); 438 ASSERT(it == values->end());
441 if (isSpanPosition) 439 if (isSpanPosition)
442 position.setSpanPosition(gridLineNumber, gridLineName); 440 position.setSpanPosition(gridLineNumber, gridLineName);
443 else 441 else
444 position.setExplicitPosition(gridLineNumber, gridLineName); 442 position.setExplicitPosition(gridLineNumber, gridLineName);
445 443
446 return position; 444 return position;
(...skipping 15 matching lines...) Expand all
462 { 460 {
463 if (value->isPrimitiveValue()) { 461 if (value->isPrimitiveValue()) {
464 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); 462 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone);
465 return; 463 return;
466 } 464 }
467 465
468 size_t currentNamedGridLine = 0; 466 size_t currentNamedGridLine = 0;
469 for (auto& currValue : *toCSSValueList(value)) { 467 for (auto& currValue : *toCSSValueList(value)) {
470 if (currValue->isGridLineNamesValue()) { 468 if (currValue->isGridLineNamesValue()) {
471 for (auto& namedGridLineValue : toCSSGridLineNamesValue(*currValue)) { 469 for (auto& namedGridLineValue : toCSSGridLineNamesValue(*currValue)) {
472 ASSERT(toCSSPrimitiveValue(namedGridLineValue.get())->isCustomId ent()); 470 String namedGridLine = toCSSCustomIdentValue(namedGridLineValue. get())->value();
473 String namedGridLine = toCSSPrimitiveValue(namedGridLineValue.ge t())->getStringValue();
474 NamedGridLinesMap::AddResult result = namedGridLines.add(namedGr idLine, Vector<size_t>()); 471 NamedGridLinesMap::AddResult result = namedGridLines.add(namedGr idLine, Vector<size_t>());
475 result.storedValue->value.append(currentNamedGridLine); 472 result.storedValue->value.append(currentNamedGridLine);
476 OrderedNamedGridLines::AddResult orderedInsertionResult = ordere dNamedGridLines.add(currentNamedGridLine, Vector<String>()); 473 OrderedNamedGridLines::AddResult orderedInsertionResult = ordere dNamedGridLines.add(currentNamedGridLine, Vector<String>());
477 orderedInsertionResult.storedValue->value.append(namedGridLine); 474 orderedInsertionResult.storedValue->value.append(namedGridLine);
478 } 475 }
479 continue; 476 continue;
480 } 477 }
481 478
482 ++currentNamedGridLine; 479 ++currentNamedGridLine;
483 trackSizes.append(convertGridTrackSize(state, currValue.get())); 480 trackSizes.append(convertGridTrackSize(state, currValue.get()));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 721 }
725 722
726 PassRefPtr<QuotesData> StyleBuilderConverter::convertQuotes(StyleResolverState&, CSSValue* value) 723 PassRefPtr<QuotesData> StyleBuilderConverter::convertQuotes(StyleResolverState&, CSSValue* value)
727 { 724 {
728 if (value->isValueList()) { 725 if (value->isValueList()) {
729 CSSValueList* list = toCSSValueList(value); 726 CSSValueList* list = toCSSValueList(value);
730 RefPtr<QuotesData> quotes = QuotesData::create(); 727 RefPtr<QuotesData> quotes = QuotesData::create();
731 for (size_t i = 0; i < list->length(); i += 2) { 728 for (size_t i = 0; i < list->length(); i += 2) {
732 CSSValue* first = list->item(i); 729 CSSValue* first = list->item(i);
733 CSSValue* second = list->item(i + 1); 730 CSSValue* second = list->item(i + 1);
734 ASSERT(toCSSPrimitiveValue(first)->isString()); 731 String startQuote = toCSSStringValue(first)->value();
735 ASSERT(toCSSPrimitiveValue(second)->isString()); 732 String endQuote = toCSSStringValue(second)->value();
736 String startQuote = toCSSPrimitiveValue(first)->getStringValue();
737 String endQuote = toCSSPrimitiveValue(second)->getStringValue();
738 quotes->addPair(std::make_pair(startQuote, endQuote)); 733 quotes->addPair(std::make_pair(startQuote, endQuote));
739 } 734 }
740 return quotes.release(); 735 return quotes.release();
741 } 736 }
742 ASSERT(value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); 737 ASSERT(value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNone);
743 return QuotesData::create(); 738 return QuotesData::create();
744 } 739 }
745 740
746 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, CSSVa lue* value) 741 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, CSSVa lue* value)
747 { 742 {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 return ScaleTransformOperation::create(sx, sy, sz, TransformOperation::Scale 3D); 943 return ScaleTransformOperation::create(sx, sy, sz, TransformOperation::Scale 3D);
949 } 944 }
950 945
951 RespectImageOrientationEnum StyleBuilderConverter::convertImageOrientation(Style ResolverState& state, CSSValue* value) 946 RespectImageOrientationEnum StyleBuilderConverter::convertImageOrientation(Style ResolverState& state, CSSValue* value)
952 { 947 {
953 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 948 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
954 return primitiveValue->getValueID() == CSSValueFromImage ? RespectImageOrien tation : DoNotRespectImageOrientation; 949 return primitiveValue->getValueID() == CSSValueFromImage ? RespectImageOrien tation : DoNotRespectImageOrientation;
955 } 950 }
956 951
957 } // namespace blink 952 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698