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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp

Issue 1421533006: Make SVGLength wrap a CSSPrimitiveValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewable version Created 5 years, 1 month 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 { 53 {
54 StringToUnitTable table; 54 StringToUnitTable table;
55 table.set(String("em"), CSSPrimitiveValue::UnitType::Ems); 55 table.set(String("em"), CSSPrimitiveValue::UnitType::Ems);
56 table.set(String("ex"), CSSPrimitiveValue::UnitType::Exs); 56 table.set(String("ex"), CSSPrimitiveValue::UnitType::Exs);
57 table.set(String("px"), CSSPrimitiveValue::UnitType::Pixels); 57 table.set(String("px"), CSSPrimitiveValue::UnitType::Pixels);
58 table.set(String("cm"), CSSPrimitiveValue::UnitType::Centimeters); 58 table.set(String("cm"), CSSPrimitiveValue::UnitType::Centimeters);
59 table.set(String("mm"), CSSPrimitiveValue::UnitType::Millimeters); 59 table.set(String("mm"), CSSPrimitiveValue::UnitType::Millimeters);
60 table.set(String("in"), CSSPrimitiveValue::UnitType::Inches); 60 table.set(String("in"), CSSPrimitiveValue::UnitType::Inches);
61 table.set(String("pt"), CSSPrimitiveValue::UnitType::Points); 61 table.set(String("pt"), CSSPrimitiveValue::UnitType::Points);
62 table.set(String("pc"), CSSPrimitiveValue::UnitType::Picas); 62 table.set(String("pc"), CSSPrimitiveValue::UnitType::Picas);
63 table.set(String(""), CSSPrimitiveValue::UnitType::UserCoordinates);
63 table.set(String("deg"), CSSPrimitiveValue::UnitType::Degrees); 64 table.set(String("deg"), CSSPrimitiveValue::UnitType::Degrees);
64 table.set(String("rad"), CSSPrimitiveValue::UnitType::Radians); 65 table.set(String("rad"), CSSPrimitiveValue::UnitType::Radians);
65 table.set(String("grad"), CSSPrimitiveValue::UnitType::Gradians); 66 table.set(String("grad"), CSSPrimitiveValue::UnitType::Gradians);
66 table.set(String("ms"), CSSPrimitiveValue::UnitType::Milliseconds); 67 table.set(String("ms"), CSSPrimitiveValue::UnitType::Milliseconds);
67 table.set(String("s"), CSSPrimitiveValue::UnitType::Seconds); 68 table.set(String("s"), CSSPrimitiveValue::UnitType::Seconds);
68 table.set(String("hz"), CSSPrimitiveValue::UnitType::Hertz); 69 table.set(String("hz"), CSSPrimitiveValue::UnitType::Hertz);
69 table.set(String("khz"), CSSPrimitiveValue::UnitType::Kilohertz); 70 table.set(String("khz"), CSSPrimitiveValue::UnitType::Kilohertz);
70 table.set(String("dpi"), CSSPrimitiveValue::UnitType::DotsPerInch); 71 table.set(String("dpi"), CSSPrimitiveValue::UnitType::DotsPerInch);
71 table.set(String("dpcm"), CSSPrimitiveValue::UnitType::DotsPerCentimeter); 72 table.set(String("dpcm"), CSSPrimitiveValue::UnitType::DotsPerCentimeter);
72 table.set(String("dppx"), CSSPrimitiveValue::UnitType::DotsPerPixel); 73 table.set(String("dppx"), CSSPrimitiveValue::UnitType::DotsPerPixel);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 case UnitType::Number: 114 case UnitType::Number:
114 return CSSPrimitiveValue::UNumber; 115 return CSSPrimitiveValue::UNumber;
115 case UnitType::Percentage: 116 case UnitType::Percentage:
116 return CSSPrimitiveValue::UPercent; 117 return CSSPrimitiveValue::UPercent;
117 case UnitType::Pixels: 118 case UnitType::Pixels:
118 case UnitType::Centimeters: 119 case UnitType::Centimeters:
119 case UnitType::Millimeters: 120 case UnitType::Millimeters:
120 case UnitType::Inches: 121 case UnitType::Inches:
121 case UnitType::Points: 122 case UnitType::Points:
122 case UnitType::Picas: 123 case UnitType::Picas:
124 case UnitType::UserCoordinates:
123 return CSSPrimitiveValue::ULength; 125 return CSSPrimitiveValue::ULength;
124 case UnitType::Milliseconds: 126 case UnitType::Milliseconds:
125 case UnitType::Seconds: 127 case UnitType::Seconds:
126 return CSSPrimitiveValue::UTime; 128 return CSSPrimitiveValue::UTime;
127 case UnitType::Degrees: 129 case UnitType::Degrees:
128 case UnitType::Radians: 130 case UnitType::Radians:
129 case UnitType::Gradians: 131 case UnitType::Gradians:
130 case UnitType::Turns: 132 case UnitType::Turns:
131 return CSSPrimitiveValue::UAngle; 133 return CSSPrimitiveValue::UAngle;
132 case UnitType::Hertz: 134 case UnitType::Hertz:
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 case UnitType::QuirkyEms: 323 case UnitType::QuirkyEms:
322 case UnitType::Exs: 324 case UnitType::Exs:
323 case UnitType::Rems: 325 case UnitType::Rems:
324 case UnitType::Chs: 326 case UnitType::Chs:
325 case UnitType::Pixels: 327 case UnitType::Pixels:
326 case UnitType::Centimeters: 328 case UnitType::Centimeters:
327 case UnitType::Millimeters: 329 case UnitType::Millimeters:
328 case UnitType::Inches: 330 case UnitType::Inches:
329 case UnitType::Points: 331 case UnitType::Points:
330 case UnitType::Picas: 332 case UnitType::Picas:
333 case UnitType::UserCoordinates:
331 case UnitType::Degrees: 334 case UnitType::Degrees:
332 case UnitType::Radians: 335 case UnitType::Radians:
333 case UnitType::Gradians: 336 case UnitType::Gradians:
334 case UnitType::Milliseconds: 337 case UnitType::Milliseconds:
335 case UnitType::Seconds: 338 case UnitType::Seconds:
336 case UnitType::Hertz: 339 case UnitType::Hertz:
337 case UnitType::Kilohertz: 340 case UnitType::Kilohertz:
338 case UnitType::Turns: 341 case UnitType::Turns:
339 case UnitType::ViewportWidth: 342 case UnitType::ViewportWidth:
340 case UnitType::ViewportHeight: 343 case UnitType::ViewportHeight:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return CSSPrimitiveValue::accumulateLengthArray(lengthArray, lengthTypeArray , multiplier); 455 return CSSPrimitiveValue::accumulateLengthArray(lengthArray, lengthTypeArray , multiplier);
453 } 456 }
454 457
455 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(UnitType unitTyp e) 458 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(UnitType unitTyp e)
456 { 459 {
457 double factor = 1.0; 460 double factor = 1.0;
458 // FIXME: the switch can be replaced by an array of scale factors. 461 // FIXME: the switch can be replaced by an array of scale factors.
459 switch (unitType) { 462 switch (unitType) {
460 // These are "canonical" units in their respective categories. 463 // These are "canonical" units in their respective categories.
461 case UnitType::Pixels: 464 case UnitType::Pixels:
465 case UnitType::UserCoordinates:
462 case UnitType::Degrees: 466 case UnitType::Degrees:
463 case UnitType::Milliseconds: 467 case UnitType::Milliseconds:
464 case UnitType::Hertz: 468 case UnitType::Hertz:
465 break; 469 break;
466 case UnitType::Centimeters: 470 case UnitType::Centimeters:
467 factor = cssPixelsPerCentimeter; 471 factor = cssPixelsPerCentimeter;
468 break; 472 break;
469 case UnitType::DotsPerCentimeter: 473 case UnitType::DotsPerCentimeter:
470 factor = 1 / cssPixelsPerCentimeter; 474 factor = 1 / cssPixelsPerCentimeter;
471 break; 475 break;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 507
504 return factor; 508 return factor;
505 } 509 }
506 510
507 Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conve rsionData) const 511 Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conve rsionData) const
508 { 512 {
509 if (isLength()) 513 if (isLength())
510 return computeLength<Length>(conversionData); 514 return computeLength<Length>(conversionData);
511 if (isPercentage()) 515 if (isPercentage())
512 return Length(getDoubleValue(), Percent); 516 return Length(getDoubleValue(), Percent);
513 ASSERT(isCalculated());
fs 2015/10/28 20:14:34 I guess this should be restored (I think this impl
Stephen Chennney 2015/10/30 18:00:55 I removed it because the exact same assertion is t
514 return Length(cssCalcValue()->toCalcValue(conversionData)); 517 return Length(cssCalcValue()->toCalcValue(conversionData));
515 } 518 }
516 519
517 double CSSPrimitiveValue::getDoubleValue() const 520 double CSSPrimitiveValue::getDoubleValue() const
518 { 521 {
519 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue(); 522 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue();
520 } 523 }
521 524
522 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(Unit Category category) 525 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(Unit Category category)
523 { 526 {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 static String formatNumber(double number, const char* characters) 642 static String formatNumber(double number, const char* characters)
640 { 643 {
641 return formatNumber(number, characters, strlen(characters)); 644 return formatNumber(number, characters, strlen(characters));
642 } 645 }
643 646
644 const char* CSSPrimitiveValue::unitTypeToString(UnitType type) 647 const char* CSSPrimitiveValue::unitTypeToString(UnitType type)
645 { 648 {
646 switch (type) { 649 switch (type) {
647 case UnitType::Number: 650 case UnitType::Number:
648 case UnitType::Integer: 651 case UnitType::Integer:
652 case UnitType::UserCoordinates:
649 return ""; 653 return "";
650 case UnitType::Percentage: 654 case UnitType::Percentage:
651 return "%"; 655 return "%";
652 case UnitType::Ems: 656 case UnitType::Ems:
653 case UnitType::QuirkyEms: 657 case UnitType::QuirkyEms:
654 return "em"; 658 return "em";
655 case UnitType::Exs: 659 case UnitType::Exs:
656 return "ex"; 660 return "ex";
657 case UnitType::Rems: 661 case UnitType::Rems:
658 return "rem"; 662 return "rem";
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 case UnitType::Chs: 741 case UnitType::Chs:
738 case UnitType::Pixels: 742 case UnitType::Pixels:
739 case UnitType::Centimeters: 743 case UnitType::Centimeters:
740 case UnitType::DotsPerPixel: 744 case UnitType::DotsPerPixel:
741 case UnitType::DotsPerInch: 745 case UnitType::DotsPerInch:
742 case UnitType::DotsPerCentimeter: 746 case UnitType::DotsPerCentimeter:
743 case UnitType::Millimeters: 747 case UnitType::Millimeters:
744 case UnitType::Inches: 748 case UnitType::Inches:
745 case UnitType::Points: 749 case UnitType::Points:
746 case UnitType::Picas: 750 case UnitType::Picas:
751 case UnitType::UserCoordinates:
747 case UnitType::Degrees: 752 case UnitType::Degrees:
748 case UnitType::Radians: 753 case UnitType::Radians:
749 case UnitType::Gradians: 754 case UnitType::Gradians:
750 case UnitType::Milliseconds: 755 case UnitType::Milliseconds:
751 case UnitType::Seconds: 756 case UnitType::Seconds:
752 case UnitType::Hertz: 757 case UnitType::Hertz:
753 case UnitType::Kilohertz: 758 case UnitType::Kilohertz:
754 case UnitType::Turns: 759 case UnitType::Turns:
755 case UnitType::Fraction: 760 case UnitType::Fraction:
756 case UnitType::ViewportWidth: 761 case UnitType::ViewportWidth:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 case UnitType::Rems: 797 case UnitType::Rems:
793 case UnitType::Pixels: 798 case UnitType::Pixels:
794 case UnitType::Centimeters: 799 case UnitType::Centimeters:
795 case UnitType::DotsPerPixel: 800 case UnitType::DotsPerPixel:
796 case UnitType::DotsPerInch: 801 case UnitType::DotsPerInch:
797 case UnitType::DotsPerCentimeter: 802 case UnitType::DotsPerCentimeter:
798 case UnitType::Millimeters: 803 case UnitType::Millimeters:
799 case UnitType::Inches: 804 case UnitType::Inches:
800 case UnitType::Points: 805 case UnitType::Points:
801 case UnitType::Picas: 806 case UnitType::Picas:
807 case UnitType::UserCoordinates:
802 case UnitType::Degrees: 808 case UnitType::Degrees:
803 case UnitType::Radians: 809 case UnitType::Radians:
804 case UnitType::Gradians: 810 case UnitType::Gradians:
805 case UnitType::Milliseconds: 811 case UnitType::Milliseconds:
806 case UnitType::Seconds: 812 case UnitType::Seconds:
807 case UnitType::Hertz: 813 case UnitType::Hertz:
808 case UnitType::Kilohertz: 814 case UnitType::Kilohertz:
809 case UnitType::Turns: 815 case UnitType::Turns:
810 case UnitType::ViewportWidth: 816 case UnitType::ViewportWidth:
811 case UnitType::ViewportHeight: 817 case UnitType::ViewportHeight:
(...skipping 23 matching lines...) Expand all
835 visitor->trace(m_value.calc); 841 visitor->trace(m_value.calc);
836 break; 842 break;
837 default: 843 default:
838 break; 844 break;
839 } 845 }
840 #endif 846 #endif
841 CSSValue::traceAfterDispatch(visitor); 847 CSSValue::traceAfterDispatch(visitor);
842 } 848 }
843 849
844 } // namespace blink 850 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698