| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 // This struct is stack allocated and allocated as part of vectors. | 49 // This struct is stack allocated and allocated as part of vectors. |
| 50 // When allocated on the stack its members are found by conservative | 50 // When allocated on the stack its members are found by conservative |
| 51 // stack scanning. When allocated as part of Vectors in heap-allocated | 51 // stack scanning. When allocated as part of Vectors in heap-allocated |
| 52 // objects its members are visited via the containing object's | 52 // objects its members are visited via the containing object's |
| 53 // (CSSGradientValue) traceAfterDispatch method. | 53 // (CSSGradientValue) traceAfterDispatch method. |
| 54 struct CSSGradientColorStop { | 54 struct CSSGradientColorStop { |
| 55 ALLOW_ONLY_INLINE_ALLOCATION(); | 55 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 56 public: | 56 public: |
| 57 CSSGradientColorStop() : m_colorIsDerivedFromElement(false) { } | 57 CSSGradientColorStop() : m_colorIsDerivedFromElement(false) { } |
| 58 RefPtrWillBeMember<CSSPrimitiveValue> m_position; // percentage or length | 58 RefPtr<CSSPrimitiveValue> m_position; // percentage or length |
| 59 RefPtrWillBeMember<CSSPrimitiveValue> m_color; | 59 RefPtr<CSSPrimitiveValue> m_color; |
| 60 bool m_colorIsDerivedFromElement; | 60 bool m_colorIsDerivedFromElement; |
| 61 bool operator==(const CSSGradientColorStop& other) const | 61 bool operator==(const CSSGradientColorStop& other) const |
| 62 { | 62 { |
| 63 return compareCSSValuePtr(m_color, other.m_color) | 63 return compareCSSValuePtr(m_color, other.m_color) |
| 64 && compareCSSValuePtr(m_position, other.m_position); | 64 && compareCSSValuePtr(m_position, other.m_position); |
| 65 } | 65 } |
| 66 bool isHint() const | 66 bool isHint() const |
| 67 { | 67 { |
| 68 ASSERT(m_color || m_position); | 68 ASSERT(m_color || m_position); |
| 69 return !m_color; | 69 return !m_color; |
| 70 } | 70 } |
| 71 | |
| 72 DECLARE_TRACE(); | |
| 73 }; | 71 }; |
| 74 | 72 |
| 75 } // namespace blink | 73 } // namespace blink |
| 76 | 74 |
| 77 | 75 |
| 78 // We have to declare the VectorTraits specialization before CSSGradientValue | 76 // We have to declare the VectorTraits specialization before CSSGradientValue |
| 79 // declares its inline capacity vector below. | 77 // declares its inline capacity vector below. |
| 80 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSGradientColorStop); | 78 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSGradientColorStop); |
| 81 | 79 |
| 82 namespace blink { | 80 namespace blink { |
| 83 | 81 |
| 84 class CSSGradientValue : public CSSImageGeneratorValue { | 82 class CSSGradientValue : public CSSImageGeneratorValue { |
| 85 public: | 83 public: |
| 86 PassRefPtr<Image> image(LayoutObject*, const IntSize&); | 84 PassRefPtr<Image> image(LayoutObject*, const IntSize&); |
| 87 | 85 |
| 88 void setFirstX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_firstX = v
al; } | 86 void setFirstX(PassRefPtr<CSSPrimitiveValue> val) { m_firstX = val; } |
| 89 void setFirstY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_firstY = v
al; } | 87 void setFirstY(PassRefPtr<CSSPrimitiveValue> val) { m_firstY = val; } |
| 90 void setSecondX(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_secondX =
val; } | 88 void setSecondX(PassRefPtr<CSSPrimitiveValue> val) { m_secondX = val; } |
| 91 void setSecondY(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_secondY =
val; } | 89 void setSecondY(PassRefPtr<CSSPrimitiveValue> val) { m_secondY = val; } |
| 92 | 90 |
| 93 void addStop(const CSSGradientColorStop& stop) { m_stops.append(stop); } | 91 void addStop(const CSSGradientColorStop& stop) { m_stops.append(stop); } |
| 94 | 92 |
| 95 unsigned stopCount() const { return m_stops.size(); } | 93 unsigned stopCount() const { return m_stops.size(); } |
| 96 | 94 |
| 97 void appendCSSTextForDeprecatedColorStops(StringBuilder&) const; | 95 void appendCSSTextForDeprecatedColorStops(StringBuilder&) const; |
| 98 | 96 |
| 99 bool isRepeating() const { return m_repeating; } | 97 bool isRepeating() const { return m_repeating; } |
| 100 | 98 |
| 101 CSSGradientType gradientType() const { return m_gradientType; } | 99 CSSGradientType gradientType() const { return m_gradientType; } |
| 102 | 100 |
| 103 bool isFixedSize() const { return false; } | 101 bool isFixedSize() const { return false; } |
| 104 IntSize fixedSize(const LayoutObject*) const { return IntSize(); } | 102 IntSize fixedSize(const LayoutObject*) const { return IntSize(); } |
| 105 | 103 |
| 106 bool isPending() const { return false; } | 104 bool isPending() const { return false; } |
| 107 bool knownToBeOpaque(const LayoutObject*) const; | 105 bool knownToBeOpaque(const LayoutObject*) const; |
| 108 | 106 |
| 109 void loadSubimages(Document*) { } | 107 void loadSubimages(Document*) { } |
| 110 | 108 |
| 111 DECLARE_TRACE_AFTER_DISPATCH(); | |
| 112 | |
| 113 protected: | 109 protected: |
| 114 CSSGradientValue(ClassType classType, CSSGradientRepeat repeat, CSSGradientT
ype gradientType) | 110 CSSGradientValue(ClassType classType, CSSGradientRepeat repeat, CSSGradientT
ype gradientType) |
| 115 : CSSImageGeneratorValue(classType) | 111 : CSSImageGeneratorValue(classType) |
| 116 , m_stopsSorted(false) | 112 , m_stopsSorted(false) |
| 117 , m_gradientType(gradientType) | 113 , m_gradientType(gradientType) |
| 118 , m_repeating(repeat == Repeating) | 114 , m_repeating(repeat == Repeating) |
| 119 { | 115 { |
| 120 } | 116 } |
| 121 | 117 |
| 122 CSSGradientValue(const CSSGradientValue& other, ClassType classType, CSSGrad
ientType gradientType) | 118 CSSGradientValue(const CSSGradientValue& other, ClassType classType, CSSGrad
ientType gradientType) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 | 130 |
| 135 void addStops(Gradient*, const CSSToLengthConversionData&, const LayoutObjec
t&); | 131 void addStops(Gradient*, const CSSToLengthConversionData&, const LayoutObjec
t&); |
| 136 void addDeprecatedStops(Gradient*, const LayoutObject&); | 132 void addDeprecatedStops(Gradient*, const LayoutObject&); |
| 137 | 133 |
| 138 // Resolve points/radii to front end values. | 134 // Resolve points/radii to front end values. |
| 139 FloatPoint computeEndPoint(CSSPrimitiveValue*, CSSPrimitiveValue*, const CSS
ToLengthConversionData&, const IntSize&); | 135 FloatPoint computeEndPoint(CSSPrimitiveValue*, CSSPrimitiveValue*, const CSS
ToLengthConversionData&, const IntSize&); |
| 140 | 136 |
| 141 bool isCacheable() const; | 137 bool isCacheable() const; |
| 142 | 138 |
| 143 // Points. Some of these may be null. | 139 // Points. Some of these may be null. |
| 144 RefPtrWillBeMember<CSSPrimitiveValue> m_firstX; | 140 RefPtr<CSSPrimitiveValue> m_firstX; |
| 145 RefPtrWillBeMember<CSSPrimitiveValue> m_firstY; | 141 RefPtr<CSSPrimitiveValue> m_firstY; |
| 146 | 142 |
| 147 RefPtrWillBeMember<CSSPrimitiveValue> m_secondX; | 143 RefPtr<CSSPrimitiveValue> m_secondX; |
| 148 RefPtrWillBeMember<CSSPrimitiveValue> m_secondY; | 144 RefPtr<CSSPrimitiveValue> m_secondY; |
| 149 | 145 |
| 150 // Stops | 146 // Stops |
| 151 WillBeHeapVector<CSSGradientColorStop, 2> m_stops; | 147 Vector<CSSGradientColorStop, 2> m_stops; |
| 152 bool m_stopsSorted; | 148 bool m_stopsSorted; |
| 153 CSSGradientType m_gradientType; | 149 CSSGradientType m_gradientType; |
| 154 bool m_repeating; | 150 bool m_repeating; |
| 155 }; | 151 }; |
| 156 | 152 |
| 157 DEFINE_CSS_VALUE_TYPE_CASTS(CSSGradientValue, isGradientValue()); | 153 DEFINE_CSS_VALUE_TYPE_CASTS(CSSGradientValue, isGradientValue()); |
| 158 | 154 |
| 159 class CSSLinearGradientValue final : public CSSGradientValue { | 155 class CSSLinearGradientValue final : public CSSGradientValue { |
| 160 public: | 156 public: |
| 161 | 157 |
| 162 static PassRefPtrWillBeRawPtr<CSSLinearGradientValue> create(CSSGradientRepe
at repeat, CSSGradientType gradientType = CSSLinearGradient) | 158 static PassRefPtr<CSSLinearGradientValue> create(CSSGradientRepeat repeat, C
SSGradientType gradientType = CSSLinearGradient) |
| 163 { | 159 { |
| 164 return adoptRefWillBeNoop(new CSSLinearGradientValue(repeat, gradientTyp
e)); | 160 return adoptRef(new CSSLinearGradientValue(repeat, gradientType)); |
| 165 } | 161 } |
| 166 | 162 |
| 167 void setAngle(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_angle = val
; } | 163 void setAngle(PassRefPtr<CSSPrimitiveValue> val) { m_angle = val; } |
| 168 | 164 |
| 169 String customCSSText() const; | 165 String customCSSText() const; |
| 170 | 166 |
| 171 // Create the gradient for a given size. | 167 // Create the gradient for a given size. |
| 172 PassRefPtr<Gradient> createGradient(const CSSToLengthConversionData&, const
IntSize&, const LayoutObject&); | 168 PassRefPtr<Gradient> createGradient(const CSSToLengthConversionData&, const
IntSize&, const LayoutObject&); |
| 173 | 169 |
| 174 PassRefPtrWillBeRawPtr<CSSLinearGradientValue> clone() const | 170 PassRefPtr<CSSLinearGradientValue> clone() const |
| 175 { | 171 { |
| 176 return adoptRefWillBeNoop(new CSSLinearGradientValue(*this)); | 172 return adoptRef(new CSSLinearGradientValue(*this)); |
| 177 } | 173 } |
| 178 | 174 |
| 179 bool equals(const CSSLinearGradientValue&) const; | 175 bool equals(const CSSLinearGradientValue&) const; |
| 180 | 176 |
| 181 DECLARE_TRACE_AFTER_DISPATCH(); | |
| 182 | |
| 183 private: | 177 private: |
| 184 CSSLinearGradientValue(CSSGradientRepeat repeat, CSSGradientType gradientTyp
e = CSSLinearGradient) | 178 CSSLinearGradientValue(CSSGradientRepeat repeat, CSSGradientType gradientTyp
e = CSSLinearGradient) |
| 185 : CSSGradientValue(LinearGradientClass, repeat, gradientType) | 179 : CSSGradientValue(LinearGradientClass, repeat, gradientType) |
| 186 { | 180 { |
| 187 } | 181 } |
| 188 | 182 |
| 189 explicit CSSLinearGradientValue(const CSSLinearGradientValue& other) | 183 explicit CSSLinearGradientValue(const CSSLinearGradientValue& other) |
| 190 : CSSGradientValue(other, LinearGradientClass, other.gradientType()) | 184 : CSSGradientValue(other, LinearGradientClass, other.gradientType()) |
| 191 , m_angle(other.m_angle) | 185 , m_angle(other.m_angle) |
| 192 { | 186 { |
| 193 } | 187 } |
| 194 | 188 |
| 195 RefPtrWillBeMember<CSSPrimitiveValue> m_angle; // may be null. | 189 RefPtr<CSSPrimitiveValue> m_angle; // may be null. |
| 196 }; | 190 }; |
| 197 | 191 |
| 198 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, isLinearGradientValue()); | 192 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, isLinearGradientValue()); |
| 199 | 193 |
| 200 class CSSRadialGradientValue final : public CSSGradientValue { | 194 class CSSRadialGradientValue final : public CSSGradientValue { |
| 201 public: | 195 public: |
| 202 static PassRefPtrWillBeRawPtr<CSSRadialGradientValue> create(CSSGradientRepe
at repeat, CSSGradientType gradientType = CSSRadialGradient) | 196 static PassRefPtr<CSSRadialGradientValue> create(CSSGradientRepeat repeat, C
SSGradientType gradientType = CSSRadialGradient) |
| 203 { | 197 { |
| 204 return adoptRefWillBeNoop(new CSSRadialGradientValue(repeat, gradientTyp
e)); | 198 return adoptRef(new CSSRadialGradientValue(repeat, gradientType)); |
| 205 } | 199 } |
| 206 | 200 |
| 207 PassRefPtrWillBeRawPtr<CSSRadialGradientValue> clone() const | 201 PassRefPtr<CSSRadialGradientValue> clone() const |
| 208 { | 202 { |
| 209 return adoptRefWillBeNoop(new CSSRadialGradientValue(*this)); | 203 return adoptRef(new CSSRadialGradientValue(*this)); |
| 210 } | 204 } |
| 211 | 205 |
| 212 String customCSSText() const; | 206 String customCSSText() const; |
| 213 | 207 |
| 214 void setFirstRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_first
Radius = val; } | 208 void setFirstRadius(PassRefPtr<CSSPrimitiveValue> val) { m_firstRadius = val
; } |
| 215 void setSecondRadius(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_seco
ndRadius = val; } | 209 void setSecondRadius(PassRefPtr<CSSPrimitiveValue> val) { m_secondRadius = v
al; } |
| 216 | 210 |
| 217 void setShape(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_shape = val
; } | 211 void setShape(PassRefPtr<CSSPrimitiveValue> val) { m_shape = val; } |
| 218 void setSizingBehavior(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_si
zingBehavior = val; } | 212 void setSizingBehavior(PassRefPtr<CSSPrimitiveValue> val) { m_sizingBehavior
= val; } |
| 219 | 213 |
| 220 void setEndHorizontalSize(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m
_endHorizontalSize = val; } | 214 void setEndHorizontalSize(PassRefPtr<CSSPrimitiveValue> val) { m_endHorizont
alSize = val; } |
| 221 void setEndVerticalSize(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_e
ndVerticalSize = val; } | 215 void setEndVerticalSize(PassRefPtr<CSSPrimitiveValue> val) { m_endVerticalSi
ze = val; } |
| 222 | 216 |
| 223 // Create the gradient for a given size. | 217 // Create the gradient for a given size. |
| 224 PassRefPtr<Gradient> createGradient(const CSSToLengthConversionData&, const
IntSize&, const LayoutObject&); | 218 PassRefPtr<Gradient> createGradient(const CSSToLengthConversionData&, const
IntSize&, const LayoutObject&); |
| 225 | 219 |
| 226 bool equals(const CSSRadialGradientValue&) const; | 220 bool equals(const CSSRadialGradientValue&) const; |
| 227 | 221 |
| 228 DECLARE_TRACE_AFTER_DISPATCH(); | |
| 229 | |
| 230 private: | 222 private: |
| 231 CSSRadialGradientValue(CSSGradientRepeat repeat, CSSGradientType gradientTyp
e = CSSRadialGradient) | 223 CSSRadialGradientValue(CSSGradientRepeat repeat, CSSGradientType gradientTyp
e = CSSRadialGradient) |
| 232 : CSSGradientValue(RadialGradientClass, repeat, gradientType) | 224 : CSSGradientValue(RadialGradientClass, repeat, gradientType) |
| 233 { | 225 { |
| 234 } | 226 } |
| 235 | 227 |
| 236 explicit CSSRadialGradientValue(const CSSRadialGradientValue& other) | 228 explicit CSSRadialGradientValue(const CSSRadialGradientValue& other) |
| 237 : CSSGradientValue(other, RadialGradientClass, other.gradientType()) | 229 : CSSGradientValue(other, RadialGradientClass, other.gradientType()) |
| 238 , m_firstRadius(other.m_firstRadius) | 230 , m_firstRadius(other.m_firstRadius) |
| 239 , m_secondRadius(other.m_secondRadius) | 231 , m_secondRadius(other.m_secondRadius) |
| 240 , m_shape(other.m_shape) | 232 , m_shape(other.m_shape) |
| 241 , m_sizingBehavior(other.m_sizingBehavior) | 233 , m_sizingBehavior(other.m_sizingBehavior) |
| 242 , m_endHorizontalSize(other.m_endHorizontalSize) | 234 , m_endHorizontalSize(other.m_endHorizontalSize) |
| 243 , m_endVerticalSize(other.m_endVerticalSize) | 235 , m_endVerticalSize(other.m_endVerticalSize) |
| 244 { | 236 { |
| 245 } | 237 } |
| 246 | 238 |
| 247 | 239 |
| 248 // Resolve points/radii to front end values. | 240 // Resolve points/radii to front end values. |
| 249 float resolveRadius(CSSPrimitiveValue*, const CSSToLengthConversionData&, fl
oat* widthOrHeight = 0); | 241 float resolveRadius(CSSPrimitiveValue*, const CSSToLengthConversionData&, fl
oat* widthOrHeight = 0); |
| 250 | 242 |
| 251 // These may be null for non-deprecated gradients. | 243 // These may be null for non-deprecated gradients. |
| 252 RefPtrWillBeMember<CSSPrimitiveValue> m_firstRadius; | 244 RefPtr<CSSPrimitiveValue> m_firstRadius; |
| 253 RefPtrWillBeMember<CSSPrimitiveValue> m_secondRadius; | 245 RefPtr<CSSPrimitiveValue> m_secondRadius; |
| 254 | 246 |
| 255 // The below are only used for non-deprecated gradients. Any of them may be
null. | 247 // The below are only used for non-deprecated gradients. Any of them may be
null. |
| 256 RefPtrWillBeMember<CSSPrimitiveValue> m_shape; | 248 RefPtr<CSSPrimitiveValue> m_shape; |
| 257 RefPtrWillBeMember<CSSPrimitiveValue> m_sizingBehavior; | 249 RefPtr<CSSPrimitiveValue> m_sizingBehavior; |
| 258 | 250 |
| 259 RefPtrWillBeMember<CSSPrimitiveValue> m_endHorizontalSize; | 251 RefPtr<CSSPrimitiveValue> m_endHorizontalSize; |
| 260 RefPtrWillBeMember<CSSPrimitiveValue> m_endVerticalSize; | 252 RefPtr<CSSPrimitiveValue> m_endVerticalSize; |
| 261 }; | 253 }; |
| 262 | 254 |
| 263 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, isRadialGradientValue()); | 255 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, isRadialGradientValue()); |
| 264 | 256 |
| 265 } // namespace blink | 257 } // namespace blink |
| 266 | 258 |
| 267 #endif // CSSGradientValue_h | 259 #endif // CSSGradientValue_h |
| OLD | NEW |