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

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

Issue 87453003: Less magic numbers in converting CSS lengths of cm/mm/pc/pt types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Created 7 years 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 else 581 else
582 factor = 1.0; 582 factor = 1.0;
583 break; 583 break;
584 case CSS_CHS: 584 case CSS_CHS:
585 factor = style->fontMetrics().zeroWidth(); 585 factor = style->fontMetrics().zeroWidth();
586 break; 586 break;
587 case CSS_PX: 587 case CSS_PX:
588 factor = 1.0; 588 factor = 1.0;
589 break; 589 break;
590 case CSS_CM: 590 case CSS_CM:
591 factor = cssPixelsPerInch / 2.54; // (2.54 cm/in) 591 factor = cssPixelsPerCentimeter;
592 break; 592 break;
593 case CSS_MM: 593 case CSS_MM:
594 factor = cssPixelsPerInch / 25.4; 594 factor = cssPixelsPerMillimeter;
595 break; 595 break;
596 case CSS_IN: 596 case CSS_IN:
597 factor = cssPixelsPerInch; 597 factor = cssPixelsPerInch;
598 break; 598 break;
599 case CSS_PT: 599 case CSS_PT:
600 factor = cssPixelsPerInch / 72.0; 600 factor = cssPixelsPerPoint;
601 break; 601 break;
602 case CSS_PC: 602 case CSS_PC:
603 // 1 pc == 12 pt 603 factor = cssPixelsPerPica;
604 factor = cssPixelsPerInch * 12.0 / 72.0;
605 break; 604 break;
606 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 605 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
607 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 606 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
608 ASSERT_NOT_REACHED(); 607 ASSERT_NOT_REACHED();
609 return -1.0; 608 return -1.0;
610 default: 609 default:
611 ASSERT_NOT_REACHED(); 610 ASSERT_NOT_REACHED();
612 return -1.0; 611 return -1.0;
613 } 612 }
614 613
(...skipping 20 matching lines...) Expand all
635 double factor = 1.0; 634 double factor = 1.0;
636 // FIXME: the switch can be replaced by an array of scale factors. 635 // FIXME: the switch can be replaced by an array of scale factors.
637 switch (unitType) { 636 switch (unitType) {
638 // These are "canonical" units in their respective categories. 637 // These are "canonical" units in their respective categories.
639 case CSS_PX: 638 case CSS_PX:
640 case CSS_DEG: 639 case CSS_DEG:
641 case CSS_MS: 640 case CSS_MS:
642 case CSS_HZ: 641 case CSS_HZ:
643 break; 642 break;
644 case CSS_CM: 643 case CSS_CM:
645 factor = cssPixelsPerInch / 2.54; // (2.54 cm/in) 644 factor = cssPixelsPerCentimeter;
646 break; 645 break;
647 case CSS_DPCM: 646 case CSS_DPCM:
648 factor = 2.54 / cssPixelsPerInch; // (2.54 cm/in) 647 factor = 1 / cssPixelsPerCentimeter;
649 break; 648 break;
650 case CSS_MM: 649 case CSS_MM:
651 factor = cssPixelsPerInch / 25.4; 650 factor = cssPixelsPerMillimeter;
652 break; 651 break;
653 case CSS_IN: 652 case CSS_IN:
654 factor = cssPixelsPerInch; 653 factor = cssPixelsPerInch;
655 break; 654 break;
656 case CSS_DPI: 655 case CSS_DPI:
657 factor = 1 / cssPixelsPerInch; 656 factor = 1 / cssPixelsPerInch;
658 break; 657 break;
659 case CSS_PT: 658 case CSS_PT:
660 factor = cssPixelsPerInch / 72.0; 659 factor = cssPixelsPerPoint;
661 break; 660 break;
662 case CSS_PC: 661 case CSS_PC:
663 factor = cssPixelsPerInch * 12.0 / 72.0; // 1 pc == 12 pt 662 factor = cssPixelsPerPica;
664 break; 663 break;
665 case CSS_RAD: 664 case CSS_RAD:
666 factor = 180 / piDouble; 665 factor = 180 / piDouble;
667 break; 666 break;
668 case CSS_GRAD: 667 case CSS_GRAD:
669 factor = 0.9; 668 factor = 0.9;
670 break; 669 break;
671 case CSS_TURN: 670 case CSS_TURN:
672 factor = 360; 671 factor = 360;
673 break; 672 break;
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 return m_value.parserOperator == other.m_value.parserOperator; 1330 return m_value.parserOperator == other.m_value.parserOperator;
1332 case CSS_CALC: 1331 case CSS_CALC:
1333 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 1332 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc);
1334 case CSS_SHAPE: 1333 case CSS_SHAPE:
1335 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape); 1334 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape);
1336 } 1335 }
1337 return false; 1336 return false;
1338 } 1337 }
1339 1338
1340 } // namespace WebCore 1339 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698