| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ObjectPaintProperties_h | 5 #ifndef ObjectPaintProperties_h |
| 6 #define ObjectPaintProperties_h | 6 #define ObjectPaintProperties_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/geometry/LayoutPoint.h" | 9 #include "platform/geometry/LayoutPoint.h" |
| 10 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 10 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 11 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 11 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 12 #include "platform/graphics/paint/PaintChunkProperties.h" | 12 #include "platform/graphics/paint/PaintChunkProperties.h" |
| 13 #include "platform/graphics/paint/PropertyTreeState.h" | 13 #include "platform/graphics/paint/PropertyTreeState.h" |
| 14 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 14 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 15 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 15 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 16 #include "wtf/PassRefPtr.h" | 16 #include "wtf/PassRefPtr.h" |
| 17 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
| 18 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 19 #include <memory> | 19 #include <memory> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 enum PropertyWasCreated { |
| 24 DidNotCreateProperty = false, |
| 25 CreatedProperty = true |
| 26 }; |
| 27 |
| 28 enum ExistingPropertyWasCleared { |
| 29 DidNotClearExistingProperty = false, |
| 30 ClearedExistingProperty = true |
| 31 }; |
| 32 |
| 23 // This class stores property tree related information associated with a | 33 // This class stores property tree related information associated with a |
| 24 // LayoutObject. | 34 // LayoutObject. |
| 25 // Currently there are two groups of information: | 35 // Currently there are two groups of information: |
| 26 // 1. The set of property nodes created locally by this LayoutObject. | 36 // 1. The set of property nodes created locally by this LayoutObject. |
| 27 // 2. The set of property nodes (inherited, or created locally) and paint offset | 37 // 2. The set of property nodes (inherited, or created locally) and paint offset |
| 28 // that can be used to paint the border box of this LayoutObject (see: | 38 // that can be used to paint the border box of this LayoutObject (see: |
| 29 // localBorderBoxProperties). | 39 // localBorderBoxProperties). |
| 30 class CORE_EXPORT ObjectPaintProperties { | 40 class CORE_EXPORT ObjectPaintProperties { |
| 31 WTF_MAKE_NONCOPYABLE(ObjectPaintProperties); | 41 WTF_MAKE_NONCOPYABLE(ObjectPaintProperties); |
| 32 USING_FAST_MALLOC(ObjectPaintProperties); | 42 USING_FAST_MALLOC(ObjectPaintProperties); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // would be an effect node with opacity of 0.3 which was created by the div | 131 // would be an effect node with opacity of 0.3 which was created by the div |
| 122 // itself. Note that propertyTreeState.transform() would not be null but would | 132 // itself. Note that propertyTreeState.transform() would not be null but would |
| 123 // instead point to the transform space setup by div's ancestors. | 133 // instead point to the transform space setup by div's ancestors. |
| 124 const PropertyTreeStateWithOffset* localBorderBoxProperties() const { | 134 const PropertyTreeStateWithOffset* localBorderBoxProperties() const { |
| 125 return m_localBorderBoxProperties.get(); | 135 return m_localBorderBoxProperties.get(); |
| 126 } | 136 } |
| 127 void setLocalBorderBoxProperties( | 137 void setLocalBorderBoxProperties( |
| 128 std::unique_ptr<PropertyTreeStateWithOffset> properties) { | 138 std::unique_ptr<PropertyTreeStateWithOffset> properties) { |
| 129 m_localBorderBoxProperties = std::move(properties); | 139 m_localBorderBoxProperties = std::move(properties); |
| 130 } | 140 } |
| 141 void clearLocalBorderBoxProperties() { m_localBorderBoxProperties = nullptr; } |
| 131 | 142 |
| 132 // This is the complete set of property nodes and paint offset that can be | 143 // This is the complete set of property nodes and paint offset that can be |
| 133 // used to paint the contents of this object. It is similar to | 144 // used to paint the contents of this object. It is similar to |
| 134 // localBorderBoxProperties but includes properties (e.g., overflow clip, | 145 // localBorderBoxProperties but includes properties (e.g., overflow clip, |
| 135 // scroll translation) that apply to contents. This is suitable for paint | 146 // scroll translation) that apply to contents. This is suitable for paint |
| 136 // invalidation. | 147 // invalidation. |
| 137 ObjectPaintProperties::PropertyTreeStateWithOffset contentsProperties() const; | 148 ObjectPaintProperties::PropertyTreeStateWithOffset contentsProperties() const; |
| 138 | 149 |
| 139 void clearPaintOffsetTranslation() { m_paintOffsetTranslation = nullptr; } | 150 ExistingPropertyWasCleared clearPaintOffsetTranslation() { |
| 140 void clearTransform() { m_transform = nullptr; } | 151 return clear(m_paintOffsetTranslation); |
| 141 void clearEffect() { m_effect = nullptr; } | |
| 142 void clearCssClip() { m_cssClip = nullptr; } | |
| 143 void clearCssClipFixedPosition() { m_cssClipFixedPosition = nullptr; } | |
| 144 void clearInnerBorderRadiusClip() { m_innerBorderRadiusClip = nullptr; } | |
| 145 void clearOverflowClip() { m_overflowClip = nullptr; } | |
| 146 void clearLocalBorderBoxProperties() { m_localBorderBoxProperties = nullptr; } | |
| 147 void clearPerspective() { m_perspective = nullptr; } | |
| 148 void clearSvgLocalToBorderBoxTransform() { | |
| 149 m_svgLocalToBorderBoxTransform = nullptr; | |
| 150 } | 152 } |
| 151 void clearScrollTranslation() { m_scrollTranslation = nullptr; } | 153 ExistingPropertyWasCleared clearTransform() { return clear(m_transform); } |
| 152 void clearScrollbarPaintOffset() { m_scrollbarPaintOffset = nullptr; } | 154 ExistingPropertyWasCleared clearEffect() { return clear(m_effect); } |
| 153 void clearScroll() { m_scroll = nullptr; } | 155 ExistingPropertyWasCleared clearCssClip() { return clear(m_cssClip); } |
| 156 ExistingPropertyWasCleared clearCssClipFixedPosition() { |
| 157 return clear(m_cssClipFixedPosition); |
| 158 } |
| 159 ExistingPropertyWasCleared clearInnerBorderRadiusClip() { |
| 160 return clear(m_innerBorderRadiusClip); |
| 161 } |
| 162 ExistingPropertyWasCleared clearOverflowClip() { |
| 163 return clear(m_overflowClip); |
| 164 } |
| 165 ExistingPropertyWasCleared clearPerspective() { return clear(m_perspective); } |
| 166 ExistingPropertyWasCleared clearSvgLocalToBorderBoxTransform() { |
| 167 return clear(m_svgLocalToBorderBoxTransform); |
| 168 } |
| 169 ExistingPropertyWasCleared clearScrollTranslation() { |
| 170 return clear(m_scrollTranslation); |
| 171 } |
| 172 ExistingPropertyWasCleared clearScrollbarPaintOffset() { |
| 173 return clear(m_scrollbarPaintOffset); |
| 174 } |
| 175 ExistingPropertyWasCleared clearScroll() { return clear(m_scroll); } |
| 154 | 176 |
| 155 template <typename... Args> | 177 template <typename... Args> |
| 156 void updatePaintOffsetTranslation(Args&&... args) { | 178 PropertyWasCreated updatePaintOffsetTranslation(Args&&... args) { |
| 157 updateProperty(m_paintOffsetTranslation, std::forward<Args>(args)...); | 179 return update(m_paintOffsetTranslation, std::forward<Args>(args)...); |
| 158 } | 180 } |
| 159 template <typename... Args> | 181 template <typename... Args> |
| 160 void updateTransform(Args&&... args) { | 182 PropertyWasCreated updateTransform(Args&&... args) { |
| 161 updateProperty(m_transform, std::forward<Args>(args)...); | 183 return update(m_transform, std::forward<Args>(args)...); |
| 162 } | 184 } |
| 163 template <typename... Args> | 185 template <typename... Args> |
| 164 void updatePerspective(Args&&... args) { | 186 PropertyWasCreated updatePerspective(Args&&... args) { |
| 165 updateProperty(m_perspective, std::forward<Args>(args)...); | 187 return update(m_perspective, std::forward<Args>(args)...); |
| 166 } | 188 } |
| 167 template <typename... Args> | 189 template <typename... Args> |
| 168 void updateSvgLocalToBorderBoxTransform(Args&&... args) { | 190 PropertyWasCreated updateSvgLocalToBorderBoxTransform(Args&&... args) { |
| 169 DCHECK(!scrollTranslation()) << "SVG elements cannot scroll so there " | 191 DCHECK(!scrollTranslation()) << "SVG elements cannot scroll so there " |
| 170 "should never be both a scroll translation " | 192 "should never be both a scroll translation " |
| 171 "and an SVG local to border box transform."; | 193 "and an SVG local to border box transform."; |
| 172 updateProperty(m_svgLocalToBorderBoxTransform, std::forward<Args>(args)...); | 194 return update(m_svgLocalToBorderBoxTransform, std::forward<Args>(args)...); |
| 173 } | 195 } |
| 174 template <typename... Args> | 196 template <typename... Args> |
| 175 void updateScrollTranslation(Args&&... args) { | 197 PropertyWasCreated updateScrollTranslation(Args&&... args) { |
| 176 DCHECK(!svgLocalToBorderBoxTransform()) | 198 DCHECK(!svgLocalToBorderBoxTransform()) |
| 177 << "SVG elements cannot scroll so there should never be both a scroll " | 199 << "SVG elements cannot scroll so there should never be both a scroll " |
| 178 "translation and an SVG local to border box transform."; | 200 "translation and an SVG local to border box transform."; |
| 179 updateProperty(m_scrollTranslation, std::forward<Args>(args)...); | 201 return update(m_scrollTranslation, std::forward<Args>(args)...); |
| 180 } | 202 } |
| 181 template <typename... Args> | 203 template <typename... Args> |
| 182 void updateScrollbarPaintOffset(Args&&... args) { | 204 PropertyWasCreated updateScrollbarPaintOffset(Args&&... args) { |
| 183 updateProperty(m_scrollbarPaintOffset, std::forward<Args>(args)...); | 205 return update(m_scrollbarPaintOffset, std::forward<Args>(args)...); |
| 184 } | 206 } |
| 185 template <typename... Args> | 207 template <typename... Args> |
| 186 void updateScroll(Args&&... args) { | 208 PropertyWasCreated updateScroll(Args&&... args) { |
| 187 updateProperty(m_scroll, std::forward<Args>(args)...); | 209 return update(m_scroll, std::forward<Args>(args)...); |
| 188 } | 210 } |
| 189 template <typename... Args> | 211 template <typename... Args> |
| 190 void updateEffect(Args&&... args) { | 212 PropertyWasCreated updateEffect(Args&&... args) { |
| 191 updateProperty(m_effect, std::forward<Args>(args)...); | 213 return update(m_effect, std::forward<Args>(args)...); |
| 192 } | 214 } |
| 193 template <typename... Args> | 215 template <typename... Args> |
| 194 void updateCssClip(Args&&... args) { | 216 PropertyWasCreated updateCssClip(Args&&... args) { |
| 195 updateProperty(m_cssClip, std::forward<Args>(args)...); | 217 return update(m_cssClip, std::forward<Args>(args)...); |
| 196 } | 218 } |
| 197 template <typename... Args> | 219 template <typename... Args> |
| 198 void updateCssClipFixedPosition(Args&&... args) { | 220 PropertyWasCreated updateCssClipFixedPosition(Args&&... args) { |
| 199 updateProperty(m_cssClipFixedPosition, std::forward<Args>(args)...); | 221 return update(m_cssClipFixedPosition, std::forward<Args>(args)...); |
| 200 } | 222 } |
| 201 template <typename... Args> | 223 template <typename... Args> |
| 202 void updateInnerBorderRadiusClip(Args&&... args) { | 224 PropertyWasCreated updateInnerBorderRadiusClip(Args&&... args) { |
| 203 updateProperty(m_innerBorderRadiusClip, std::forward<Args>(args)...); | 225 return update(m_innerBorderRadiusClip, std::forward<Args>(args)...); |
| 204 } | 226 } |
| 205 template <typename... Args> | 227 template <typename... Args> |
| 206 void updateOverflowClip(Args&&... args) { | 228 PropertyWasCreated updateOverflowClip(Args&&... args) { |
| 207 updateProperty(m_overflowClip, std::forward<Args>(args)...); | 229 return update(m_overflowClip, std::forward<Args>(args)...); |
| 208 } | 230 } |
| 209 | 231 |
| 210 #if DCHECK_IS_ON() | 232 #if DCHECK_IS_ON() |
| 211 // Used by FindPropertiesNeedingUpdate.h for recording the current properties. | 233 // Used by FindPropertiesNeedingUpdate.h for recording the current properties. |
| 212 std::unique_ptr<ObjectPaintProperties> clone() const { | 234 std::unique_ptr<ObjectPaintProperties> clone() const { |
| 213 std::unique_ptr<ObjectPaintProperties> cloned = create(); | 235 std::unique_ptr<ObjectPaintProperties> cloned = create(); |
| 214 if (m_paintOffsetTranslation) | 236 if (m_paintOffsetTranslation) |
| 215 cloned->m_paintOffsetTranslation = m_paintOffsetTranslation->clone(); | 237 cloned->m_paintOffsetTranslation = m_paintOffsetTranslation->clone(); |
| 216 if (m_transform) | 238 if (m_transform) |
| 217 cloned->m_transform = m_transform->clone(); | 239 cloned->m_transform = m_transform->clone(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 246 state.scroll()))); | 268 state.scroll()))); |
| 247 } | 269 } |
| 248 return cloned; | 270 return cloned; |
| 249 } | 271 } |
| 250 #endif | 272 #endif |
| 251 | 273 |
| 252 private: | 274 private: |
| 253 ObjectPaintProperties() {} | 275 ObjectPaintProperties() {} |
| 254 | 276 |
| 255 template <typename PaintPropertyNode, typename... Args> | 277 template <typename PaintPropertyNode, typename... Args> |
| 256 void updateProperty(RefPtr<PaintPropertyNode>& field, Args&&... args) { | 278 PropertyWasCreated update(RefPtr<PaintPropertyNode>& field, Args&&... args) { |
| 257 if (field) | 279 if (field) { |
| 258 field->update(std::forward<Args>(args)...); | 280 field->update(std::forward<Args>(args)...); |
| 259 else | 281 return DidNotCreateProperty; |
| 260 field = PaintPropertyNode::create(std::forward<Args>(args)...); | 282 } |
| 283 field = PaintPropertyNode::create(std::forward<Args>(args)...); |
| 284 return CreatedProperty; |
| 285 } |
| 286 |
| 287 template <typename PaintPropertyNode> |
| 288 ExistingPropertyWasCleared clear(RefPtr<PaintPropertyNode>& field) { |
| 289 if (field) { |
| 290 field = nullptr; |
| 291 return ClearedExistingProperty; |
| 292 } |
| 293 return DidNotClearExistingProperty; |
| 261 } | 294 } |
| 262 | 295 |
| 263 RefPtr<TransformPaintPropertyNode> m_paintOffsetTranslation; | 296 RefPtr<TransformPaintPropertyNode> m_paintOffsetTranslation; |
| 264 RefPtr<TransformPaintPropertyNode> m_transform; | 297 RefPtr<TransformPaintPropertyNode> m_transform; |
| 265 RefPtr<EffectPaintPropertyNode> m_effect; | 298 RefPtr<EffectPaintPropertyNode> m_effect; |
| 266 RefPtr<ClipPaintPropertyNode> m_cssClip; | 299 RefPtr<ClipPaintPropertyNode> m_cssClip; |
| 267 RefPtr<ClipPaintPropertyNode> m_cssClipFixedPosition; | 300 RefPtr<ClipPaintPropertyNode> m_cssClipFixedPosition; |
| 268 RefPtr<ClipPaintPropertyNode> m_innerBorderRadiusClip; | 301 RefPtr<ClipPaintPropertyNode> m_innerBorderRadiusClip; |
| 269 RefPtr<ClipPaintPropertyNode> m_overflowClip; | 302 RefPtr<ClipPaintPropertyNode> m_overflowClip; |
| 270 RefPtr<TransformPaintPropertyNode> m_perspective; | 303 RefPtr<TransformPaintPropertyNode> m_perspective; |
| 271 // TODO(pdr): Only LayoutSVGRoot needs this and it should be moved there. | 304 // TODO(pdr): Only LayoutSVGRoot needs this and it should be moved there. |
| 272 RefPtr<TransformPaintPropertyNode> m_svgLocalToBorderBoxTransform; | 305 RefPtr<TransformPaintPropertyNode> m_svgLocalToBorderBoxTransform; |
| 273 RefPtr<TransformPaintPropertyNode> m_scrollTranslation; | 306 RefPtr<TransformPaintPropertyNode> m_scrollTranslation; |
| 274 RefPtr<TransformPaintPropertyNode> m_scrollbarPaintOffset; | 307 RefPtr<TransformPaintPropertyNode> m_scrollbarPaintOffset; |
| 275 RefPtr<ScrollPaintPropertyNode> m_scroll; | 308 RefPtr<ScrollPaintPropertyNode> m_scroll; |
| 276 | 309 |
| 277 std::unique_ptr<PropertyTreeStateWithOffset> m_localBorderBoxProperties; | 310 std::unique_ptr<PropertyTreeStateWithOffset> m_localBorderBoxProperties; |
| 278 }; | 311 }; |
| 279 | 312 |
| 280 } // namespace blink | 313 } // namespace blink |
| 281 | 314 |
| 282 #endif // ObjectPaintProperties_h | 315 #endif // ObjectPaintProperties_h |
| OLD | NEW |