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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSCalculationValue.h

Issue 1481383002: [Experimental] CSSSerializer Proof-of-concept Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: snapshot: top_25 sites ser/dser now works Created 4 years, 11 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 CalcOther 65 CalcOther
66 }; 66 };
67 67
68 class CSSCalcExpressionNode : public RefCountedWillBeGarbageCollected<CSSCalcExp ressionNode> { 68 class CSSCalcExpressionNode : public RefCountedWillBeGarbageCollected<CSSCalcExp ressionNode> {
69 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CSSCalcExpressionNode); 69 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CSSCalcExpressionNode);
70 public: 70 public:
71 enum Type { 71 enum Type {
72 CssCalcPrimitiveValue = 1, 72 CssCalcPrimitiveValue = 1,
73 CssCalcBinaryOperation 73 CssCalcBinaryOperation
74 }; 74 };
75 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> deserialize(CSSDeserial izeStream*);
75 76
76 virtual bool isZero() const = 0; 77 virtual bool isZero() const = 0;
77 virtual double doubleValue() const = 0; 78 virtual double doubleValue() const = 0;
78 virtual double computeLengthPx(const CSSToLengthConversionData&) const = 0; 79 virtual double computeLengthPx(const CSSToLengthConversionData&) const = 0;
79 virtual void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, dou ble multiplier) const = 0; 80 virtual void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, dou ble multiplier) const = 0;
80 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData&, Pi xelsAndPercent&, float multiplier = 1) const = 0; 81 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData&, Pi xelsAndPercent&, float multiplier = 1) const = 0;
81 virtual String customCSSText() const = 0; 82 virtual String customCSSText() const = 0;
82 virtual bool equals(const CSSCalcExpressionNode& other) const { return m_cat egory == other.m_category && m_isInteger == other.m_isInteger; } 83 virtual bool equals(const CSSCalcExpressionNode& other) const { return m_cat egory == other.m_category && m_isInteger == other.m_isInteger; }
83 virtual Type type() const = 0; 84 virtual Type type() const = 0;
84 85
85 CalculationCategory category() const { return m_category; } 86 CalculationCategory category() const { return m_category; }
86 virtual CSSPrimitiveValue::UnitType typeWithCalcResolved() const = 0; 87 virtual CSSPrimitiveValue::UnitType typeWithCalcResolved() const = 0;
87 bool isInteger() const { return m_isInteger; } 88 bool isInteger() const { return m_isInteger; }
88 89
90 virtual void serialize(CSSSerializeStream*) const;
89 DEFINE_INLINE_VIRTUAL_TRACE() { } 91 DEFINE_INLINE_VIRTUAL_TRACE() { }
90 92
91 protected: 93 protected:
92 CSSCalcExpressionNode(CalculationCategory category, bool isInteger) 94 CSSCalcExpressionNode(CalculationCategory category, bool isInteger)
93 : m_category(category) 95 : m_category(category)
94 , m_isInteger(isInteger) 96 , m_isInteger(isInteger)
95 { 97 {
96 ASSERT(category != CalcOther); 98 ASSERT(category != CalcOther);
97 } 99 }
98 100
99 CalculationCategory m_category; 101 CalculationCategory m_category;
100 bool m_isInteger; 102 bool m_isInteger;
101 }; 103 };
102 104
103 class CORE_EXPORT CSSCalcValue : public RefCountedWillBeGarbageCollected<CSSCalc Value> { 105 class CORE_EXPORT CSSCalcValue : public RefCountedWillBeGarbageCollected<CSSCalc Value> {
104 public: 106 public:
105 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(const CSSParserTokenRange &, ValueRange); 107 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(const CSSParserTokenRange &, ValueRange);
106 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(PassRefPtrWillBeRawPtr<CS SCalcExpressionNode>, ValueRange = ValueRangeAll); 108 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(PassRefPtrWillBeRawPtr<CS SCalcExpressionNode>, ValueRange = ValueRangeAll);
109 static PassRefPtrWillBeRawPtr<CSSCalcValue> deserialize(CSSDeserializeStream *);
107 110
108 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa ssRefPtrWillBeRawPtr<CSSPrimitiveValue>, bool isInteger = false); 111 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa ssRefPtrWillBeRawPtr<CSSPrimitiveValue>, bool isInteger = false);
109 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa ssRefPtrWillBeRawPtr<CSSCalcExpressionNode>, PassRefPtrWillBeRawPtr<CSSCalcExpre ssionNode>, CalcOperator); 112 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa ssRefPtrWillBeRawPtr<CSSCalcExpressionNode>, PassRefPtrWillBeRawPtr<CSSCalcExpre ssionNode>, CalcOperator);
110 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(do uble pixels, double percent); 113 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(do uble pixels, double percent);
111 114
112 PassRefPtr<CalculationValue> toCalcValue(const CSSToLengthConversionData& co nversionData) const 115 PassRefPtr<CalculationValue> toCalcValue(const CSSToLengthConversionData& co nversionData) const
113 { 116 {
114 PixelsAndPercent value(0, 0); 117 PixelsAndPercent value(0, 0);
115 m_expression->accumulatePixelsAndPercent(conversionData, value); 118 m_expression->accumulatePixelsAndPercent(conversionData, value);
116 return CalculationValue::create(value, m_nonNegative ? ValueRangeNonNega tive : ValueRangeAll); 119 return CalculationValue::create(value, m_nonNegative ? ValueRangeNonNega tive : ValueRangeAll);
117 } 120 }
118 CalculationCategory category() const { return m_expression->category(); } 121 CalculationCategory category() const { return m_expression->category(); }
119 bool isInt() const { return m_expression->isInteger(); } 122 bool isInt() const { return m_expression->isInteger(); }
120 double doubleValue() const; 123 double doubleValue() const;
121 bool isNegative() const { return m_expression->doubleValue() < 0; } 124 bool isNegative() const { return m_expression->doubleValue() < 0; }
122 ValueRange permittedValueRange() { return m_nonNegative ? ValueRangeNonNegat ive : ValueRangeAll; } 125 ValueRange permittedValueRange() { return m_nonNegative ? ValueRangeNonNegat ive : ValueRangeAll; }
123 double computeLengthPx(const CSSToLengthConversionData&) const; 126 double computeLengthPx(const CSSToLengthConversionData&) const;
124 void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTypeArray& lengthTypeArray, double multiplier) const { m_expression->accumulateLengthArray( lengthArray, lengthTypeArray, multiplier); } 127 void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTypeArray& lengthTypeArray, double multiplier) const { m_expression->accumulateLengthArray( lengthArray, lengthTypeArray, multiplier); }
125 CSSCalcExpressionNode* expressionNode() const { return m_expression.get(); } 128 CSSCalcExpressionNode* expressionNode() const { return m_expression.get(); }
126 129
127 String customCSSText() const; 130 String customCSSText() const;
128 bool equals(const CSSCalcValue&) const; 131 bool equals(const CSSCalcValue&) const;
129 132
133 void serialize(CSSSerializeStream* stream) const;
134
130 DEFINE_INLINE_TRACE() 135 DEFINE_INLINE_TRACE()
131 { 136 {
132 visitor->trace(m_expression); 137 visitor->trace(m_expression);
133 } 138 }
134 139
135 private: 140 private:
136 CSSCalcValue(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, Value Range range) 141 CSSCalcValue(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, Value Range range)
137 : m_expression(expression) 142 : m_expression(expression)
138 , m_nonNegative(range == ValueRangeNonNegative) 143 , m_nonNegative(range == ValueRangeNonNegative)
139 { 144 {
140 } 145 }
141 146
142 double clampToPermittedRange(double) const; 147 double clampToPermittedRange(double) const;
143 148
144 const RefPtrWillBeMember<CSSCalcExpressionNode> m_expression; 149 const RefPtrWillBeMember<CSSCalcExpressionNode> m_expression;
145 const bool m_nonNegative; 150 const bool m_nonNegative;
146 }; 151 };
147 152
148 } // namespace blink 153 } // namespace blink
149 154
150 #endif // CSSCalculationValue_h 155 #endif // CSSCalculationValue_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/css/CSSCalculationValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698