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

Side by Side Diff: sky/engine/core/css/CSSPrimitiveValue.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « sky/engine/core/css/CSSMatrix.cpp ('k') | sky/engine/core/css/CSSPrimitiveValue.idl » ('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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "sky/engine/config.h" 21 #include "sky/engine/config.h"
22 #include "sky/engine/core/css/CSSPrimitiveValue.h" 22 #include "sky/engine/core/css/CSSPrimitiveValue.h"
23 23
24 #include "sky/engine/bindings/core/v8/ExceptionState.h" 24 #include "sky/engine/bindings2/exception_state.h"
25 #include "sky/engine/core/css/CSSBasicShapes.h" 25 #include "sky/engine/core/css/CSSBasicShapes.h"
26 #include "sky/engine/core/css/CSSCalculationValue.h" 26 #include "sky/engine/core/css/CSSCalculationValue.h"
27 #include "sky/engine/core/css/CSSHelper.h" 27 #include "sky/engine/core/css/CSSHelper.h"
28 #include "sky/engine/core/css/CSSMarkup.h" 28 #include "sky/engine/core/css/CSSMarkup.h"
29 #include "sky/engine/core/css/CSSToLengthConversionData.h" 29 #include "sky/engine/core/css/CSSToLengthConversionData.h"
30 #include "sky/engine/core/css/Pair.h" 30 #include "sky/engine/core/css/Pair.h"
31 #include "sky/engine/core/css/RGBColor.h" 31 #include "sky/engine/core/css/RGBColor.h"
32 #include "sky/engine/core/css/Rect.h" 32 #include "sky/engine/core/css/Rect.h"
33 #include "sky/engine/core/css/StyleSheetContents.h" 33 #include "sky/engine/core/css/StyleSheetContents.h"
34 #include "sky/engine/core/dom/ExceptionCode.h" 34 #include "sky/engine/core/dom/ExceptionCode.h"
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 LengthUnitType lengthType; 653 LengthUnitType lengthType;
654 if (unitTypeToLengthUnitType(static_cast<UnitType>(m_primitiveUnitType), len gthType)) 654 if (unitTypeToLengthUnitType(static_cast<UnitType>(m_primitiveUnitType), len gthType))
655 lengthArray.at(lengthType) += m_value.num * conversionToCanonicalUnitsSc aleFactor(static_cast<UnitType>(m_primitiveUnitType)) * multiplier; 655 lengthArray.at(lengthType) += m_value.num * conversionToCanonicalUnitsSc aleFactor(static_cast<UnitType>(m_primitiveUnitType)) * multiplier;
656 } 656 }
657 657
658 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex ceptionState) 658 void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& ex ceptionState)
659 { 659 {
660 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects. 660 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects.
661 // No other engine supports mutating style through this API. Computed style is always read-only anyway. 661 // No other engine supports mutating style through this API. Computed style is always read-only anyway.
662 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation. 662 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation.
663 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only."); 663 exceptionState.ThrowDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only.");
664 } 664 }
665 665
666 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(UnitType unitTyp e) 666 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(UnitType unitTyp e)
667 { 667 {
668 double factor = 1.0; 668 double factor = 1.0;
669 // FIXME: the switch can be replaced by an array of scale factors. 669 // FIXME: the switch can be replaced by an array of scale factors.
670 switch (unitType) { 670 switch (unitType) {
671 // These are "canonical" units in their respective categories. 671 // These are "canonical" units in their respective categories.
672 case CSS_PX: 672 case CSS_PX:
673 case CSS_DEG: 673 case CSS_DEG:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 713 }
714 714
715 return factor; 715 return factor;
716 } 716 }
717 717
718 double CSSPrimitiveValue::getDoubleValue(UnitType unitType, ExceptionState& exce ptionState) const 718 double CSSPrimitiveValue::getDoubleValue(UnitType unitType, ExceptionState& exce ptionState) const
719 { 719 {
720 double result = 0; 720 double result = 0;
721 bool success = getDoubleValueInternal(unitType, &result); 721 bool success = getDoubleValueInternal(unitType, &result);
722 if (!success) { 722 if (!success) {
723 exceptionState.throwDOMException(InvalidAccessError, "Failed to obtain a double value."); 723 exceptionState.ThrowDOMException(InvalidAccessError, "Failed to obtain a double value.");
724 return 0.0; 724 return 0.0;
725 } 725 }
726 726
727 return result; 727 return result;
728 } 728 }
729 729
730 double CSSPrimitiveValue::getDoubleValue(UnitType unitType) const 730 double CSSPrimitiveValue::getDoubleValue(UnitType unitType) const
731 { 731 {
732 double result = 0; 732 double result = 0;
733 getDoubleValueInternal(unitType, &result); 733 getDoubleValueInternal(unitType, &result);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 } 879 }
880 ASSERT_NOT_REACHED(); 880 ASSERT_NOT_REACHED();
881 return CSSPrimitiveValue::CSS_UNKNOWN; 881 return CSSPrimitiveValue::CSS_UNKNOWN;
882 } 882 }
883 883
884 void CSSPrimitiveValue::setStringValue(unsigned short, const String&, ExceptionS tate& exceptionState) 884 void CSSPrimitiveValue::setStringValue(unsigned short, const String&, ExceptionS tate& exceptionState)
885 { 885 {
886 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects. 886 // Keeping values immutable makes optimizations easier and allows sharing of the primitive value objects.
887 // No other engine supports mutating style through this API. Computed style is always read-only anyway. 887 // No other engine supports mutating style through this API. Computed style is always read-only anyway.
888 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation. 888 // Supporting setter would require making primitive value copy-on-write and taking care of style invalidation.
889 exceptionState.throwDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only."); 889 exceptionState.ThrowDOMException(NoModificationAllowedError, "CSSPrimitiveVa lue objects are read-only.");
890 } 890 }
891 891
892 String CSSPrimitiveValue::getStringValue(ExceptionState& exceptionState) const 892 String CSSPrimitiveValue::getStringValue(ExceptionState& exceptionState) const
893 { 893 {
894 switch (m_primitiveUnitType) { 894 switch (m_primitiveUnitType) {
895 case CSS_STRING: 895 case CSS_STRING:
896 case CSS_ATTR: 896 case CSS_ATTR:
897 case CSS_URI: 897 case CSS_URI:
898 return m_value.string; 898 return m_value.string;
899 case CSS_VALUE_ID: 899 case CSS_VALUE_ID:
900 return valueName(m_value.valueID); 900 return valueName(m_value.valueID);
901 case CSS_PROPERTY_ID: 901 case CSS_PROPERTY_ID:
902 return propertyName(m_value.propertyID); 902 return propertyName(m_value.propertyID);
903 default: 903 default:
904 exceptionState.throwDOMException(InvalidAccessError, "This object's value cannot be represented as a string."); 904 exceptionState.ThrowDOMException(InvalidAccessError, "This object's value cannot be represented as a string.");
905 break; 905 break;
906 } 906 }
907 907
908 return String(); 908 return String();
909 } 909 }
910 910
911 String CSSPrimitiveValue::getStringValue() const 911 String CSSPrimitiveValue::getStringValue() const
912 { 912 {
913 switch (m_primitiveUnitType) { 913 switch (m_primitiveUnitType) {
914 case CSS_STRING: 914 case CSS_STRING:
915 case CSS_ATTR: 915 case CSS_ATTR:
916 case CSS_URI: 916 case CSS_URI:
917 return m_value.string; 917 return m_value.string;
918 case CSS_VALUE_ID: 918 case CSS_VALUE_ID:
919 return valueName(m_value.valueID); 919 return valueName(m_value.valueID);
920 case CSS_PROPERTY_ID: 920 case CSS_PROPERTY_ID:
921 return propertyName(m_value.propertyID); 921 return propertyName(m_value.propertyID);
922 default: 922 default:
923 break; 923 break;
924 } 924 }
925 925
926 return String(); 926 return String();
927 } 927 }
928 928
929 Rect* CSSPrimitiveValue::getRectValue(ExceptionState& exceptionState) const 929 Rect* CSSPrimitiveValue::getRectValue(ExceptionState& exceptionState) const
930 { 930 {
931 if (m_primitiveUnitType != CSS_RECT) { 931 if (m_primitiveUnitType != CSS_RECT) {
932 exceptionState.throwDOMException(InvalidAccessError, "This object is not a rect value."); 932 exceptionState.ThrowDOMException(InvalidAccessError, "This object is not a rect value.");
933 return 0; 933 return 0;
934 } 934 }
935 935
936 return m_value.rect; 936 return m_value.rect;
937 } 937 }
938 938
939 Quad* CSSPrimitiveValue::getQuadValue(ExceptionState& exceptionState) const 939 Quad* CSSPrimitiveValue::getQuadValue(ExceptionState& exceptionState) const
940 { 940 {
941 if (m_primitiveUnitType != CSS_QUAD) { 941 if (m_primitiveUnitType != CSS_QUAD) {
942 exceptionState.throwDOMException(InvalidAccessError, "This object is not a quad value."); 942 exceptionState.ThrowDOMException(InvalidAccessError, "This object is not a quad value.");
943 return 0; 943 return 0;
944 } 944 }
945 945
946 return m_value.quad; 946 return m_value.quad;
947 } 947 }
948 948
949 PassRefPtr<RGBColor> CSSPrimitiveValue::getRGBColorValue(ExceptionState& excepti onState) const 949 PassRefPtr<RGBColor> CSSPrimitiveValue::getRGBColorValue(ExceptionState& excepti onState) const
950 { 950 {
951 if (m_primitiveUnitType != CSS_RGBCOLOR) { 951 if (m_primitiveUnitType != CSS_RGBCOLOR) {
952 exceptionState.throwDOMException(InvalidAccessError, "This object is not an RGB color value."); 952 exceptionState.ThrowDOMException(InvalidAccessError, "This object is not an RGB color value.");
953 return nullptr; 953 return nullptr;
954 } 954 }
955 955
956 // FIMXE: This should not return a new object for each invocation. 956 // FIMXE: This should not return a new object for each invocation.
957 return RGBColor::create(m_value.rgbcolor); 957 return RGBColor::create(m_value.rgbcolor);
958 } 958 }
959 959
960 Pair* CSSPrimitiveValue::getPairValue(ExceptionState& exceptionState) const 960 Pair* CSSPrimitiveValue::getPairValue(ExceptionState& exceptionState) const
961 { 961 {
962 if (m_primitiveUnitType != CSS_PAIR) { 962 if (m_primitiveUnitType != CSS_PAIR) {
963 exceptionState.throwDOMException(InvalidAccessError, "This object is not a pair value."); 963 exceptionState.ThrowDOMException(InvalidAccessError, "This object is not a pair value.");
964 return 0; 964 return 0;
965 } 965 }
966 966
967 return m_value.pair; 967 return m_value.pair;
968 } 968 }
969 969
970 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth) 970 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth)
971 { 971 {
972 Decimal decimal = Decimal::fromDouble(number); 972 Decimal decimal = Decimal::fromDouble(number);
973 String result = decimal.toString(); 973 String result = decimal.toString();
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other .m_value.pair); 1301 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other .m_value.pair);
1302 case CSS_CALC: 1302 case CSS_CALC:
1303 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 1303 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc);
1304 case CSS_SHAPE: 1304 case CSS_SHAPE:
1305 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape); 1305 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape);
1306 } 1306 }
1307 return false; 1307 return false;
1308 } 1308 }
1309 1309
1310 } // namespace blink 1310 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/CSSMatrix.cpp ('k') | sky/engine/core/css/CSSPrimitiveValue.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698