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

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

Issue 227043007: CSS Length calculation with MediaValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser3
Patch Set: Fix debug compile issue Created 6 years, 8 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
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/CSSToLengthConversionData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 case CSS_GRAD: 551 case CSS_GRAD:
552 return grad2deg(getDoubleValue()); 552 return grad2deg(getDoubleValue());
553 case CSS_TURN: 553 case CSS_TURN:
554 return turn2deg(getDoubleValue()); 554 return turn2deg(getDoubleValue());
555 default: 555 default:
556 ASSERT_NOT_REACHED(); 556 ASSERT_NOT_REACHED();
557 return 0; 557 return 0;
558 } 558 }
559 } 559 }
560 560
561 template<> int CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData) 561 template<> int CSSPrimitiveValue::computeLength(const CSSLengthData& lengthData)
562 { 562 {
563 return roundForImpreciseConversion<int>(computeLengthDouble(conversionData)) ; 563 return roundForImpreciseConversion<int>(computeLengthDouble(&lengthData));
564 } 564 }
565 565
566 template<> unsigned CSSPrimitiveValue::computeLength(const CSSToLengthConversion Data& conversionData) 566 template<> unsigned CSSPrimitiveValue::computeLength(const CSSLengthData& length Data)
567 { 567 {
568 return roundForImpreciseConversion<unsigned>(computeLengthDouble(conversionD ata)); 568 return roundForImpreciseConversion<unsigned>(computeLengthDouble(&lengthData ));
569 } 569 }
570 570
571 template<> Length CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa ta& conversionData) 571 template<> Length CSSPrimitiveValue::computeLength(const CSSLengthData& lengthDa ta)
572 { 572 {
573 return Length(clampTo<float>(computeLengthDouble(conversionData), minValueFo rCssLength, maxValueForCssLength), Fixed); 573 return Length(clampTo<float>(computeLengthDouble(&lengthData), minValueForCs sLength, maxValueForCssLength), Fixed);
574 } 574 }
575 575
576 template<> short CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat a& conversionData) 576 template<> short CSSPrimitiveValue::computeLength(const CSSLengthData& lengthDat a)
577 { 577 {
578 return roundForImpreciseConversion<short>(computeLengthDouble(conversionData )); 578 return roundForImpreciseConversion<short>(computeLengthDouble(&lengthData));
579 } 579 }
580 580
581 template<> unsigned short CSSPrimitiveValue::computeLength(const CSSToLengthConv ersionData& conversionData) 581 template<> unsigned short CSSPrimitiveValue::computeLength(const CSSLengthData& lengthData)
582 { 582 {
583 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(conve rsionData)); 583 return roundForImpreciseConversion<unsigned short>(computeLengthDouble(&leng thData));
584 } 584 }
585 585
586 template<> float CSSPrimitiveValue::computeLength(const CSSToLengthConversionDat a& conversionData) 586 template<> float CSSPrimitiveValue::computeLength(const CSSLengthData& lengthDat a)
587 { 587 {
588 return static_cast<float>(computeLengthDouble(conversionData)); 588 return static_cast<float>(computeLengthDouble(&lengthData));
589 } 589 }
590 590
591 template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa ta& conversionData) 591 template<> double CSSPrimitiveValue::computeLength(const CSSLengthData& lengthDa ta)
592 { 592 {
593 return computeLengthDouble(conversionData); 593 return computeLengthDouble(&lengthData);
594 } 594 }
595 595
596 double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c onversionData) 596 double CSSPrimitiveValue::computeLengthDouble(const CSSLengthData* lengthData)
597 { 597 {
598 ASSERT(lengthData);
598 if (m_primitiveUnitType == CSS_CALC) 599 if (m_primitiveUnitType == CSS_CALC)
599 return m_value.calc->computeLengthPx(conversionData); 600 return m_value.calc->computeLengthPx(lengthData);
600 601
601 const RenderStyle& style = conversionData.style(); 602 bool computingFontSize = lengthData->computingFontSize();
602 const RenderStyle* rootStyle = conversionData.rootStyle();
603 bool computingFontSize = conversionData.computingFontSize();
604 603
605 double factor; 604 double factor;
606 605
607 switch (primitiveType()) { 606 switch (primitiveType()) {
608 case CSS_EMS: 607 case CSS_EMS:
609 factor = computingFontSize ? style.fontDescription().specifiedSize() : style.fontDescription().computedSize(); 608 factor = computingFontSize ? lengthData->fontSpecifiedSize() : lengt hData->fontComputedSize();
610 break; 609 break;
611 case CSS_EXS: 610 case CSS_EXS:
612 // FIXME: We have a bug right now where the zoom will be applied twi ce to EX units. 611 // FIXME: We have a bug right now where the zoom will be applied twi ce to EX units.
613 // We really need to compute EX using fontMetrics for the original s pecifiedSize and not use 612 // We really need to compute EX using fontMetrics for the original s pecifiedSize and not use
614 // our actual constructed rendering font. 613 // our actual constructed rendering font.
615 if (style.fontMetrics().hasXHeight()) 614 if (lengthData->hasXHeight())
616 factor = style.fontMetrics().xHeight(); 615 factor = lengthData->xHeight();
617 else 616 else
618 factor = (computingFontSize ? style.fontDescription().specifiedS ize() : style.fontDescription().computedSize()) / 2.0; 617 factor = (computingFontSize ? lengthData->fontSpecifiedSize() : lengthData->fontComputedSize()) / 2.0;
619 break; 618 break;
620 case CSS_REMS: 619 case CSS_REMS:
621 if (rootStyle) 620 if (lengthData->hasRoot())
622 factor = computingFontSize ? rootStyle->fontDescription().specif iedSize() : rootStyle->fontDescription().computedSize(); 621 factor = computingFontSize ? lengthData->rootFontSpecifiedSize() : lengthData->rootFontComputedSize();
623 else 622 else
624 factor = 1.0; 623 factor = 1.0;
625 break; 624 break;
626 case CSS_CHS: 625 case CSS_CHS:
627 factor = style.fontMetrics().zeroWidth(); 626 factor = lengthData->zeroWidth();
628 break; 627 break;
629 case CSS_PX: 628 case CSS_PX:
630 factor = 1.0; 629 factor = 1.0;
631 break; 630 break;
632 case CSS_CM: 631 case CSS_CM:
633 factor = cssPixelsPerCentimeter; 632 factor = cssPixelsPerCentimeter;
634 break; 633 break;
635 case CSS_MM: 634 case CSS_MM:
636 factor = cssPixelsPerMillimeter; 635 factor = cssPixelsPerMillimeter;
637 break; 636 break;
638 case CSS_IN: 637 case CSS_IN:
639 factor = cssPixelsPerInch; 638 factor = cssPixelsPerInch;
640 break; 639 break;
641 case CSS_PT: 640 case CSS_PT:
642 factor = cssPixelsPerPoint; 641 factor = cssPixelsPerPoint;
643 break; 642 break;
644 case CSS_PC: 643 case CSS_PC:
645 factor = cssPixelsPerPica; 644 factor = cssPixelsPerPica;
646 break; 645 break;
647 case CSS_VW: 646 case CSS_VW:
648 factor = conversionData.viewportWidthPercent(); 647 factor = lengthData->viewportWidthPercent();
649 break; 648 break;
650 case CSS_VH: 649 case CSS_VH:
651 factor = conversionData.viewportHeightPercent(); 650 factor = lengthData->viewportHeightPercent();
652 break; 651 break;
653 case CSS_VMIN: 652 case CSS_VMIN:
654 factor = conversionData.viewportMinPercent(); 653 factor = lengthData->viewportMinPercent();
655 break; 654 break;
656 case CSS_VMAX: 655 case CSS_VMAX:
657 factor = conversionData.viewportMaxPercent(); 656 factor = lengthData->viewportMaxPercent();
658 break; 657 break;
659 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 658 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
660 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 659 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
661 ASSERT_NOT_REACHED(); 660 ASSERT_NOT_REACHED();
662 return -1.0; 661 return -1.0;
663 default: 662 default:
664 ASSERT_NOT_REACHED(); 663 ASSERT_NOT_REACHED();
665 return -1.0; 664 return -1.0;
666 } 665 }
667 666
668 // We do not apply the zoom factor when we are computing the value of the fo nt-size property. The zooming 667 // We do not apply the zoom factor when we are computing the value of the fo nt-size property. The zooming
669 // for font sizes is much more complicated, since we have to worry about enf orcing the minimum font size preference 668 // for font sizes is much more complicated, since we have to worry about enf orcing the minimum font size preference
670 // as well as enforcing the implicit "smart minimum." 669 // as well as enforcing the implicit "smart minimum."
671 double result = getDoubleValue() * factor; 670 double result = getDoubleValue() * factor;
672 if (computingFontSize || isFontRelativeLength()) 671 if (computingFontSize || isFontRelativeLength())
673 return result; 672 return result;
674 673
675 return result * conversionData.zoom(); 674 return result * lengthData->zoom();
676 } 675 }
677 676
678 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex ceptionState) 677 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex ceptionState)
679 { 678 {
680 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects. 679 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects.
681 // No other engine supports mutating style through this API. Computed style is always read-only anyway. 680 // No other engine supports mutating style through this API. Computed style is always read-only anyway.
682 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation. 681 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation.
683 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only."); 682 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only.");
684 } 683 }
685 684
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 case CSS_SHAPE: 1316 case CSS_SHAPE:
1318 visitor->trace(m_value.shape); 1317 visitor->trace(m_value.shape);
1319 break; 1318 break;
1320 default: 1319 default:
1321 break; 1320 break;
1322 } 1321 }
1323 CSSValue::traceAfterDispatch(visitor); 1322 CSSValue::traceAfterDispatch(visitor);
1324 } 1323 }
1325 1324
1326 } // namespace WebCore 1325 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/CSSToLengthConversionData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698