Changeset 110126 in webkit
- Timestamp:
- Mar 7, 2012 6:12:26 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r110124 r110126 1 2012-03-07 Mike Lawther <mikelawther@chromium.org> 2 3 CSS3 calc: mixed absolute/percentages work for width, height, margin and padding 4 https://bugs.webkit.org/show_bug.cgi?id=79621 5 6 Reviewed by Andreas Kling. 7 8 * css3/calc/margin-expected.txt: 9 * css3/calc/padding-expected.txt: 10 * css3/calc/simple-calcs-expected.txt: 11 1 12 2012-03-07 Stephen White <senorblanco@chromium.org> 2 13 -
trunk/LayoutTests/css3/calc/margin-expected.txt
r109874 r110126 19 19 PASS computedMarginRight("simple-bottom") is "0px" 20 20 PASS computedMarginBottom("simple-bottom") is "25px" 21 FAIL computedMarginLeft("percent-all") should be 25px. Was 0px. 22 FAIL computedMarginTop("percent-all") should be 25px. Was 0px. 23 FAIL computedMarginRight("percent-all") should be 25px. Was 0px. 24 FAIL computedMarginBottom("percent-all") should be 25px. Was 0px. 25 FAIL computedMarginLeft("percent-left") should be 25px. Was 0px. 21 PASS computedMarginLeft("percent-all") is "25px" 22 PASS computedMarginTop("percent-all") is "25px" 23 PASS computedMarginRight("percent-all") is "25px" 24 PASS computedMarginBottom("percent-all") is "25px" 25 PASS computedMarginLeft("percent-left") is "25px" 26 26 PASS computedMarginTop("percent-left") is "0px" 27 27 PASS computedMarginRight("percent-left") is "0px" … … 29 29 PASS computedMarginLeft("percent-right") is "0px" 30 30 PASS computedMarginTop("percent-right") is "0px" 31 FAIL computedMarginRight("percent-right") should be 25px. Was 0px. 31 PASS computedMarginRight("percent-right") is "25px" 32 32 PASS computedMarginBottom("percent-right") is "0px" 33 33 PASS computedMarginLeft("percent-top") is "0px" 34 FAIL computedMarginTop("percent-top") should be 25px. Was 0px. 34 PASS computedMarginTop("percent-top") is "25px" 35 35 PASS computedMarginRight("percent-top") is "0px" 36 36 PASS computedMarginBottom("percent-top") is "0px" … … 38 38 PASS computedMarginTop("percent-bottom") is "0px" 39 39 PASS computedMarginRight("percent-bottom") is "0px" 40 FAIL computedMarginBottom("percent-bottom") should be 25px. Was 0px. 40 PASS computedMarginBottom("percent-bottom") is "25px" 41 41 PASS successfullyParsed is true 42 42 -
trunk/LayoutTests/css3/calc/padding-expected.txt
r107688 r110126 9 9 This element should have a bottom padding of 25 pixels. => PASS 10 10 11 This element should have an overall padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong width, wrong height11 This element should have an overall padding of 25 pixels (10% of parent width of 300px minus 5px). => PASS 12 12 13 This element should have a left padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong width13 This element should have a left padding of 25 pixels (10% of parent width of 300px minus 5px). => PASS 14 14 15 This element should have a right padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong width15 This element should have a right padding of 25 pixels (10% of parent width of 300px minus 5px). => PASS 16 16 17 This element should have a top padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong height17 This element should have a top padding of 25 pixels (10% of parent width of 300px minus 5px). => PASS 18 18 19 This element should have a bottom padding of 25 pixels (10% of parent width of 300px minus 5px). => FAIL: wrong height19 This element should have a bottom padding of 25 pixels (10% of parent width of 300px minus 5px). => PASS -
trunk/LayoutTests/css3/calc/simple-calcs-expected.txt
r107688 r110126 21 21 50px + 10px * 5 (operation order) => PASS 22 22 100%/2 (where 100% is 200px) => PASS 23 100% + -100px (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 25624 80% - 60px (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 25625 300px - 100% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 25626 -100px + 100% (where 100% is 200px) => FAIL: @zoom=1 expected width of 100, but was 256; @zoom=1.2 expected width of 100, but was 256; @zoom=2 expected width of 100, but was 25623 100% + -100px (where 100% is 200px) => PASS 24 80% - 60px (where 100% is 200px) => PASS 25 300px - 100% (where 100% is 200px) => PASS 26 -100px + 100% (where 100% is 200px) => PASS 27 27 20% + 30% (where 100% is 200px) => PASS 28 28 80% - 30% (where 100% is 200px) => PASS -
trunk/Source/WebCore/ChangeLog
r110120 r110126 1 2012-03-07 Mike Lawther <mikelawther@chromium.org> 2 3 CSS3 calc: mixed absolute/percentages work for width, height, margin and padding 4 https://bugs.webkit.org/show_bug.cgi?id=79621 5 6 Reviewed by Andreas Kling. 7 8 ApplyPropertyLength in CSSStyleApplyPropery now handles mixed absolute/percentage 9 length expressions. All property handlers using this template now work with 10 mixed expressions. 11 12 This patch adds a new expression evaluator in CalculationValue.cpp. This is because 13 Length.[cpp|h] (in platform) cannot refer to CSSCalculationValue.[cpp|h] (in css) 14 due to layering restrictions. 15 16 Lengths can be copied, and so the expressions are stored in a hashmap, and only their 17 ids are copied along with Length. The expressions are RefCounted, and will get 18 cleaned up when the last referring Length is destructed. 19 20 * WebCore.exp.in: 21 * css/CSSCalculationValue.cpp: 22 (WebCore::CSSCalcPrimitiveValue::toCalcValue): 23 (CSSCalcPrimitiveValue): 24 (WebCore::CSSCalcBinaryOperation::toCalcValue): 25 (CSSCalcBinaryOperation): 26 * css/CSSCalculationValue.h: 27 (WebCore): 28 (CSSCalcExpressionNode): 29 (CSSCalcValue): 30 (WebCore::CSSCalcValue::toCalcValue): 31 * css/CSSPrimitiveValue.cpp: 32 (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): 33 * css/CSSStyleApplyProperty.cpp: 34 (WebCore::ApplyPropertyLength::applyValue): 35 * css/CSSStyleSelector.cpp: 36 (WebCore::CSSStyleSelector::collectMatchingRulesForList): 37 * css/CSSStyleSelector.h: 38 (CSSStyleSelector): 39 * platform/CalculationValue.cpp: 40 (WebCore::CalcExpressionBinaryOperation::evaluate): 41 (WebCore): 42 (WebCore::CalculationValue::create): 43 (WebCore::CalculationValue::evaluate): 44 * platform/CalculationValue.h: 45 (CalcExpressionNode): 46 (WebCore::CalcExpressionNode::~CalcExpressionNode): 47 (WebCore): 48 (CalculationValue): 49 (WebCore::CalculationValue::CalculationValue): 50 (CalcExpressionNumber): 51 (WebCore::CalcExpressionNumber::CalcExpressionNumber): 52 (WebCore::CalcExpressionNumber::evaluate): 53 (CalcExpressionLength): 54 (WebCore::CalcExpressionLength::CalcExpressionLength): 55 (WebCore::CalcExpressionLength::evaluate): 56 (CalcExpressionBinaryOperation): 57 (WebCore::CalcExpressionBinaryOperation::CalcExpressionBinaryOperation): 58 * platform/Length.cpp: 59 (WebCore): 60 (WebCore::Length::~Length): 61 (CalculationValueHandleMap): 62 (WebCore::CalculationValueHandleMap::CalculationValueHandleMap): 63 (WebCore::CalculationValueHandleMap::insert): 64 (WebCore::CalculationValueHandleMap::remove): 65 (WebCore::CalculationValueHandleMap::get): 66 (WebCore::calcHandles): 67 (WebCore::Length::Length): 68 (WebCore::Length::calculationValue): 69 (WebCore::Length::calculatedValue): 70 (WebCore::Length::calculatedMinValue): 71 (WebCore::Length::calculatedFloatValue): 72 (WebCore::Length::incrementCalculatedRef): 73 (WebCore::Length::decrementCalculatedRef): 74 (WebCore::Length::nonNanCalculatedValue): 75 * platform/Length.h: 76 (Length): 77 (WebCore::Length::Length): 78 (WebCore::Length::operator=): 79 (WebCore::Length::operator*=): 80 (WebCore::Length::value): 81 (WebCore::Length::setValue): 82 (WebCore::Length::calcValue): 83 (WebCore::Length::calcMinValue): 84 (WebCore::Length::calcFloatValue): 85 (WebCore::Length::isZero): 86 (WebCore::Length::isPositive): 87 (WebCore::Length::isNegative): 88 (WebCore::Length::isPercent): 89 (WebCore::Length::isSpecified): 90 (WebCore::Length::isCalculated): 91 (WebCore::Length::initFromLength): 92 (WebCore::Length::calculationHandle): 93 1 94 2012-03-07 Emil A Eklund <eae@chromium.org> 2 95 -
trunk/Source/WebCore/WebCore.exp.in
r110014 r110126 1423 1423 __ZNK7WebCore6Editor9canDeleteEv 1424 1424 __ZNK7WebCore6JSNode21pushEventHandlerScopeEPN3JSC9ExecStateEPNS1_14ScopeChainNodeE 1425 __ZNK7WebCore6Length22decrementCalculatedRefEv 1425 1426 __ZNK7WebCore6Region5rectsEv 1426 1427 __ZNK7WebCore6Widget14platformWidgetEv -
trunk/Source/WebCore/css/CSSCalculationValue.cpp
r108750 r110126 115 115 } 116 116 117 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom) const 118 { 119 switch (m_category) { 120 case CalcNumber: 121 return adoptPtr(new CalcExpressionNumber(m_value->getFloatValue())); 122 case CalcLength: 123 return adoptPtr(new CalcExpressionNumber(m_value->computeLength<float>(style, rootStyle, zoom))); 124 case CalcPercent: 125 case CalcPercentLength: 126 return adoptPtr(new CalcExpressionLength(CSSStyleSelector::convertToFloatLength(m_value.get(), style, rootStyle, zoom))); 127 // Only types that could be part of a Length expression can be converted 128 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length. 129 case CalcPercentNumber: 130 case CalcOther: 131 ASSERT_NOT_REACHED(); 132 } 133 return nullptr; 134 } 135 117 136 virtual double doubleValue() const 118 137 { … … 209 228 } 210 229 230 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom) const 231 { 232 OwnPtr<CalcExpressionNode> left(m_leftSide->toCalcValue(style, rootStyle, zoom)); 233 if (!left) 234 return nullptr; 235 OwnPtr<CalcExpressionNode> right(m_rightSide->toCalcValue(style, rootStyle, zoom)); 236 if (!right) 237 return nullptr; 238 return adoptPtr(new CalcExpressionBinaryOperation(left.release(), right.release(), m_operator)); 239 } 240 211 241 virtual double doubleValue() const 212 242 { -
trunk/Source/WebCore/css/CSSCalculationValue.h
r108750 r110126 44 44 class CSSValueList; 45 45 class RenderStyle; 46 class Calc Value;46 class CalculationValue; 47 47 class CalcExpressionNode; 48 48 … … 59 59 public: 60 60 61 virtual ~CSSCalcExpressionNode() = 0; 61 virtual ~CSSCalcExpressionNode() = 0; 62 62 virtual bool isZero() const = 0; 63 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle*, RenderStyle* rootStyle, double zoom = 1.0) const = 0; 63 64 virtual double doubleValue() const = 0; 64 65 virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0; … … 81 82 public: 82 83 static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange); 84 static PassRefPtr<CSSCalcValue> create(CalculationValue*); 83 85 86 PassRefPtr<CalculationValue> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom = 1.0) const 87 { 88 return CalculationValue::create(m_expression->toCalcValue(style, rootStyle, zoom), m_nonNegative ? CalculationRangeNonNegative : CalculationRangeAll); 89 } 84 90 CalculationCategory category() const { return m_expression->category(); } 85 91 bool isInt() const { return m_expression->isInteger(); } -
trunk/Source/WebCore/css/CSSPrimitiveValue.cpp
r109785 r110126 267 267 m_value.num = length.percent(); 268 268 break; 269 case Calculated: 269 270 case Relative: 270 271 case Undefined: -
trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp
r109806 r110126 27 27 28 28 #include "CSSAspectRatioValue.h" 29 #include "CSSCalculationValue.h" 29 30 #include "CSSCursorImageValue.h" 30 31 #include "CSSFlexValue.h" … … 390 391 } else if (primitiveValue->isPercentage()) 391 392 setValue(selector->style(), Length(primitiveValue->getDoubleValue(), Percent)); 393 else if (primitiveValue->isCalculatedPercentageWithLength()) 394 setValue(selector->style(), Length(primitiveValue->cssCalcValue()->toCalcValue(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()))); 392 395 } 393 396 } -
trunk/Source/WebCore/css/CSSStyleSelector.cpp
r109964 r110126 31 31 #include "Attribute.h" 32 32 #include "CachedImage.h" 33 #include "CalculationValue.h" 33 34 #include "ContentData.h" 34 35 #include "Counter.h" 35 36 #include "CounterContent.h" 36 37 #include "CSSBorderImage.h" 38 #include "CSSCalculationValue.h" 37 39 #include "CSSCursorImageValue.h" 38 40 #include "CSSFontFaceRule.h" … … 2548 2550 } 2549 2551 2550 static Length convertToIntLength(CSSPrimitiveValue* primitiveValue, RenderStyle* style, RenderStyle* rootStyle, double multiplier = 1)2552 Length CSSStyleSelector::convertToIntLength(CSSPrimitiveValue* primitiveValue, RenderStyle* style, RenderStyle* rootStyle, double multiplier) 2551 2553 { 2552 2554 return convertToLength(primitiveValue, style, rootStyle, false, multiplier); 2553 2555 } 2554 2556 2555 static Length convertToFloatLength(CSSPrimitiveValue* primitiveValue, RenderStyle* style, RenderStyle* rootStyle, double multiplier = 1)2557 Length CSSStyleSelector::convertToFloatLength(CSSPrimitiveValue* primitiveValue, RenderStyle* style, RenderStyle* rootStyle, double multiplier) 2556 2558 { 2557 2559 return convertToLength(primitiveValue, style, rootStyle, true, multiplier); -
trunk/Source/WebCore/css/CSSStyleSelector.h
r109563 r110126 363 363 bool applyPropertyToVisitedLinkStyle() const { return m_applyPropertyToVisitedLinkStyle; } 364 364 365 static Length convertToIntLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1); 366 static Length convertToFloatLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1); 367 365 368 private: 366 369 static RenderStyle* s_styleNotYetAvailable; -
trunk/Source/WebCore/platform/CalculationValue.cpp
r106166 r110126 32 32 #include "CalculationValue.h" 33 33 34 #include <limits> 35 34 36 namespace WebCore { 35 37 38 float CalcExpressionBinaryOperation::evaluate(float maxValue) const 39 { 40 float left = m_leftSide->evaluate(maxValue); 41 float right = m_rightSide->evaluate(maxValue); 42 switch (m_operator) { 43 case CalcAdd: 44 return left + right; 45 case CalcSubtract: 46 return left - right; 47 case CalcMultiply: 48 return left * right; 49 case CalcDivide: 50 if (!right) 51 return std::numeric_limits<float>::quiet_NaN(); 52 return left / right; 53 } 54 ASSERT_NOT_REACHED(); 55 return std::numeric_limits<float>::quiet_NaN(); 56 } 57 58 PassRefPtr<CalculationValue> CalculationValue::create(PassOwnPtr<CalcExpressionNode> value, CalculationPermittedValueRange range) 59 { 60 return adoptRef(new CalculationValue(value, range)); 61 } 62 63 float CalculationValue::evaluate(float maxValue) const 64 { 65 float result = m_value->evaluate(maxValue); 66 // FIXME calc https://webkit.org/b/80411 : result is NaN when there is a division 67 // by zero which isn't found at parse time. 68 if (isnan(result)) 69 return 0; 70 return m_isNonNegative && result < 0 ? 0 : result; 71 } 72 36 73 } // namespace WebCore -
trunk/Source/WebCore/platform/CalculationValue.h
r108750 r110126 51 51 CalculationRangeNonNegative 52 52 }; 53 54 class CalcExpressionNode { 55 public: 56 virtual ~CalcExpressionNode() 57 { 58 } 59 60 virtual float evaluate(float maxValue) const = 0; 61 }; 62 63 class CalculationValue : public RefCounted<CalculationValue> { 64 public: 65 static PassRefPtr<CalculationValue> create(PassOwnPtr<CalcExpressionNode> value, CalculationPermittedValueRange); 66 float evaluate(float maxValue) const; 67 68 private: 69 CalculationValue(PassOwnPtr<CalcExpressionNode> value, CalculationPermittedValueRange range) 70 : m_value(value) 71 , m_isNonNegative(range == CalculationRangeNonNegative) 72 { 73 } 74 75 OwnPtr<CalcExpressionNode> m_value; 76 bool m_isNonNegative; 77 }; 78 79 class CalcExpressionNumber : public CalcExpressionNode { 80 public: 81 explicit CalcExpressionNumber(float value) 82 : m_value(value) 83 { 84 } 85 86 virtual float evaluate(float) const 87 { 88 return m_value; 89 } 90 91 private: 92 float m_value; 93 }; 94 95 class CalcExpressionLength : public CalcExpressionNode { 96 public: 97 explicit CalcExpressionLength(Length length) 98 : m_length(length) 99 { 100 } 101 102 virtual float evaluate(float maxValue) const 103 { 104 return m_length.calcFloatValue(maxValue); 105 } 106 107 private: 108 Length m_length; 109 }; 110 111 class CalcExpressionBinaryOperation : public CalcExpressionNode { 112 public: 113 CalcExpressionBinaryOperation(PassOwnPtr<CalcExpressionNode> leftSide, PassOwnPtr<CalcExpressionNode> rightSide, CalcOperator op) 114 : m_leftSide(leftSide) 115 , m_rightSide(rightSide) 116 , m_operator(op) 117 { 118 } 119 120 virtual float evaluate(float) const; 121 122 private: 123 OwnPtr<CalcExpressionNode> m_leftSide; 124 OwnPtr<CalcExpressionNode> m_rightSide; 125 CalcOperator m_operator; 126 }; 53 127 54 128 } // namespace WebCore -
trunk/Source/WebCore/platform/Length.cpp
r107487 r110126 26 26 #include "Length.h" 27 27 28 #include "CalculationValue.h" 28 29 #include "PlatformString.h" 29 30 #include <wtf/ASCIICType.h> … … 149 150 return r.release(); 150 151 } 152 153 class CalculationValueHandleMap { 154 public: 155 CalculationValueHandleMap() 156 : m_index(1) 157 { 158 } 159 160 int insert(PassRefPtr<CalculationValue> calcValue) 161 { 162 ASSERT(m_index); 163 // FIXME calc(): https://bugs.webkit.org/show_bug.cgi?id=80489 164 // This monotonically increasing handle generation scheme is potentially wasteful 165 // of the handle space. Consider reusing empty handles. 166 while (m_map.contains(m_index)) 167 m_index++; 168 169 m_map.set(m_index, calcValue); 170 171 return m_index; 172 } 173 174 void remove(int index) 175 { 176 ASSERT(m_map.contains(index)); 177 m_map.remove(index); 178 } 179 180 PassRefPtr<CalculationValue> get(int index) 181 { 182 ASSERT(m_map.contains(index)); 183 return m_map.get(index); 184 } 185 186 private: 187 int m_index; 188 HashMap<int, RefPtr<CalculationValue> > m_map; 189 }; 190 191 static CalculationValueHandleMap& calcHandles() 192 { 193 DEFINE_STATIC_LOCAL(CalculationValueHandleMap, handleMap, ()); 194 return handleMap; 195 } 196 197 Length::Length(PassRefPtr<CalculationValue> calc) 198 : m_quirk(false) 199 , m_type(Calculated) 200 , m_isFloat(false) 201 { 202 m_intValue = calcHandles().insert(calc); 203 } 204 205 PassRefPtr<CalculationValue> Length::calculationValue() const 206 { 207 ASSERT(isCalculated()); 208 return calcHandles().get(calculationHandle()); 209 } 210 211 void Length::incrementCalculatedRef() const 212 { 213 ASSERT(isCalculated()); 214 calculationValue()->ref(); 215 } 216 217 void Length::decrementCalculatedRef() const 218 { 219 ASSERT(isCalculated()); 220 RefPtr<CalculationValue> calcLength = calculationValue(); 221 if (calcLength->hasOneRef()) 222 calcHandles().remove(calculationHandle()); 223 calcLength->deref(); 224 } 225 226 float Length::nonNanCalculatedValue(int maxValue) const 227 { 228 ASSERT(isCalculated()); 229 float result = calculationValue()->evaluate(maxValue); 230 if (isnan(result)) 231 return 0; 232 return result; 233 } 151 234 152 235 class SameSizeAsLength { -
trunk/Source/WebCore/platform/Length.h
r109785 r110126 27 27 #include <wtf/FastAllocBase.h> 28 28 #include <wtf/Forward.h> 29 #include <wtf/HashMap.h> 29 30 #include <wtf/MathExtras.h> 30 31 #include <wtf/PassOwnArrayPtr.h> … … 35 36 const int intMinForLength = (-0x7ffffff - 1); // min value for a 28-bit int 36 37 37 enum LengthType { Auto, Relative, Percent, Fixed, Intrinsic, MinIntrinsic, Undefined }; 38 38 enum LengthType { Auto, Relative, Percent, Fixed, Intrinsic, MinIntrinsic, Calculated, Undefined }; 39 40 class CalculationValue; 41 39 42 struct Length { 40 43 WTF_MAKE_FAST_ALLOCATED; … … 66 69 } 67 70 71 explicit Length(PassRefPtr<CalculationValue>); 72 73 Length(const Length& length) 74 { 75 initFromLength(length); 76 } 77 78 Length& operator=(const Length& length) 79 { 80 initFromLength(length); 81 return *this; 82 } 83 84 ~Length() 85 { 86 if (isCalculated()) 87 decrementCalculatedRef(); 88 } 89 68 90 bool operator==(const Length& o) const { return (m_type == o.m_type) && (m_quirk == o.m_quirk) && (isUndefined() || (getFloatValue() == o.getFloatValue())); } 69 91 bool operator!=(const Length& o) const { return !(*this == o); } 70 92 71 93 const Length& operator*=(float v) 72 { 94 { 95 if (isCalculated()) { 96 ASSERT_NOT_REACHED(); 97 return *this; 98 } 99 73 100 if (m_isFloat) 74 101 m_floatValue = static_cast<float>(m_floatValue * v); … … 81 108 int value() const 82 109 { 110 if (isCalculated()) { 111 ASSERT_NOT_REACHED(); 112 return 0; 113 } 83 114 return getIntValue(); 84 115 } … … 89 120 return getFloatValue(); 90 121 } 122 123 PassRefPtr<CalculationValue> calculationValue() const; 91 124 92 125 LengthType type() const { return static_cast<LengthType>(m_type); } … … 107 140 void setValue(int value) 108 141 { 142 if (isCalculated()) { 143 ASSERT_NOT_REACHED(); 144 return; 145 } 109 146 setValue(Fixed, value); 110 147 } … … 122 159 } 123 160 124 // Note: May only be called for Fixed, Percent and Auto lengths.125 // Other types will ASSERT in order to catch invalid length calculations.126 161 int calcValue(int maxValue, bool roundPercentages = false) const 127 162 { … … 129 164 case Fixed: 130 165 case Percent: 166 case Calculated: 131 167 return calcMinValue(maxValue, roundPercentages); 132 168 case Auto: … … 153 189 // Don't remove the extra cast to float. It is needed for rounding on 32-bit Intel machines that use the FPU stack. 154 190 return static_cast<int>(static_cast<float>(maxValue * percent() / 100.0f)); 191 case Calculated: 192 return nonNanCalculatedValue(maxValue); 155 193 case Auto: 156 194 return 0; … … 175 213 case Auto: 176 214 return static_cast<float>(maxValue); 215 case Calculated: 216 return nonNanCalculatedValue(maxValue); 177 217 case Relative: 178 218 case Intrinsic: … … 187 227 188 228 bool isUndefined() const { return type() == Undefined; } 229 230 // FIXME calc: https://bugs.webkit.org/show_bug.cgi?id=80357. A calculated Length 231 // always contains a percentage, and without a maxValue passed to these functions 232 // it's impossible to determine the sign or zero-ness. We assume all calc values 233 // are positive and non-zero for now. 189 234 bool isZero() const 190 235 { 191 236 ASSERT(!isUndefined()); 237 if (isCalculated()) 238 return false; 239 192 240 return m_isFloat ? !m_floatValue : !m_intValue; 193 241 } 194 195 bool isPositive() const { return isUndefined() ? false : getFloatValue() > 0; } 196 bool isNegative() const { return isUndefined() ? false : getFloatValue() < 0; } 197 242 bool isPositive() const 243 { 244 if (isUndefined()) 245 return false; 246 if (isCalculated()) 247 return true; 248 249 return getFloatValue() > 0; 250 } 251 bool isNegative() const 252 { 253 if (isUndefined() || isCalculated()) 254 return false; 255 256 return getFloatValue() < 0; 257 } 258 198 259 bool isAuto() const { return type() == Auto; } 199 260 bool isRelative() const { return type() == Relative; } 200 bool isPercent() const { return type() == Percent ; }261 bool isPercent() const { return type() == Percent || type() == Calculated; } 201 262 bool isFixed() const { return type() == Fixed; } 202 263 bool isIntrinsicOrAuto() const { return type() == Auto || type() == MinIntrinsic || type() == Intrinsic; } 203 bool isSpecified() const { return type() == Fixed || type() == Percent; } 264 bool isSpecified() const { return type() == Fixed || type() == Percent || type() == Calculated; } 265 bool isCalculated() const { return type() == Calculated; } 204 266 205 267 Length blend(const Length& from, double progress) const … … 240 302 } 241 303 304 void initFromLength(const Length &length) 305 { 306 m_quirk = length.m_quirk; 307 m_type = length.m_type; 308 m_isFloat = length.m_isFloat; 309 310 if (m_isFloat) 311 m_floatValue = length.m_floatValue; 312 else 313 m_intValue = length.m_intValue; 314 315 if (isCalculated()) 316 incrementCalculatedRef(); 317 } 318 319 float nonNanCalculatedValue(int maxValue) const; 320 int calculationHandle() const 321 { 322 ASSERT(isCalculated()); 323 return getIntValue(); 324 } 325 void incrementCalculatedRef() const; 326 void decrementCalculatedRef() const; 327 242 328 union { 243 329 int m_intValue;
Note: See TracChangeset
for help on using the changeset viewer.