| 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 #include "core/paint/PaintPropertyTreeBuilder.h" | 5 #include "core/paint/PaintPropertyTreeBuilder.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/layout/LayoutInline.h" | 10 #include "core/layout/LayoutInline.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 static FloatPoint3D transformOrigin(const LayoutBox& box) { | 264 static FloatPoint3D transformOrigin(const LayoutBox& box) { |
| 265 const ComputedStyle& style = box.styleRef(); | 265 const ComputedStyle& style = box.styleRef(); |
| 266 FloatSize borderBoxSize(box.size()); | 266 FloatSize borderBoxSize(box.size()); |
| 267 return FloatPoint3D( | 267 return FloatPoint3D( |
| 268 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), | 268 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), |
| 269 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), | 269 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), |
| 270 style.transformOriginZ()); | 270 style.transformOriginZ()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // SVG does not use the general transform update of |updateTransform|, instead |
| 274 // creating a transform node for SVG-specific transforms without 3D. |
| 275 void PaintPropertyTreeBuilder::updateTransformForNonRootSVG( |
| 276 const LayoutObject& object, |
| 277 PaintPropertyTreeBuilderContext& context) { |
| 278 DCHECK(object.isSVG() && !object.isSVGRoot()); |
| 279 // SVG (other than SVGForeignObject) does not use paint offset internally. |
| 280 DCHECK(object.isSVGForeignObject() || |
| 281 context.current.paintOffset == LayoutPoint()); |
| 282 |
| 283 // FIXME(pdr): Refactor this so all non-root SVG objects use the same |
| 284 // transform function. |
| 285 const AffineTransform& transform = object.isSVGForeignObject() |
| 286 ? object.localSVGTransform() |
| 287 : object.localToSVGParentTransform(); |
| 288 |
| 289 // FIXME(pdr): Check for the presence of a transform instead of the value. |
| 290 // Checking for an identity matrix will cause the property tree structure to |
| 291 // change during animations if the animation passes through the identity |
| 292 // matrix. |
| 293 if (!transform.isIdentity()) { |
| 294 // The origin is included in the local transform, so leave origin empty. |
| 295 context.current.transform = |
| 296 object.getMutableForPainting().ensurePaintProperties().updateTransform( |
| 297 context.current.transform, TransformationMatrix(transform), |
| 298 FloatPoint3D()); |
| 299 context.current.renderingContextID = 0; |
| 300 context.current.shouldFlattenInheritedTransform = false; |
| 301 } else { |
| 302 if (auto* properties = object.getMutableForPainting().paintProperties()) |
| 303 properties->clearTransform(); |
| 304 } |
| 305 } |
| 306 |
| 273 void PaintPropertyTreeBuilder::updateTransform( | 307 void PaintPropertyTreeBuilder::updateTransform( |
| 274 const LayoutObject& object, | 308 const LayoutObject& object, |
| 275 PaintPropertyTreeBuilderContext& context) { | 309 PaintPropertyTreeBuilderContext& context) { |
| 276 if (object.isSVG() && !object.isSVGRoot()) { | 310 if (object.isSVG() && !object.isSVGRoot()) { |
| 277 // SVG (other than SVGForeignObject) does not use paint offset internally. | 311 updateTransformForNonRootSVG(object, context); |
| 278 DCHECK(object.isSVGForeignObject() || | 312 return; |
| 279 context.current.paintOffset == LayoutPoint()); | |
| 280 | |
| 281 // FIXME(pdr): Check for the presence of a transform instead of the value. | |
| 282 // Checking for an identity matrix will cause the property tree structure to | |
| 283 // change during animations if the animation passes through the identity | |
| 284 // matrix. | |
| 285 // FIXME(pdr): Refactor this so all non-root SVG objects use the same | |
| 286 // transform function. | |
| 287 const AffineTransform& transform = object.isSVGForeignObject() | |
| 288 ? object.localSVGTransform() | |
| 289 : object.localToSVGParentTransform(); | |
| 290 if (!transform.isIdentity()) { | |
| 291 // The origin is included in the local transform, so leave origin empty. | |
| 292 context.current.transform = | |
| 293 object.getMutableForPainting() | |
| 294 .ensurePaintProperties() | |
| 295 .updateTransform(context.current.transform, | |
| 296 TransformationMatrix(transform), FloatPoint3D()); | |
| 297 context.current.renderingContextID = 0; | |
| 298 context.current.shouldFlattenInheritedTransform = false; | |
| 299 return; | |
| 300 } | |
| 301 } else { | |
| 302 const ComputedStyle& style = object.styleRef(); | |
| 303 if (object.isBox() && (style.hasTransform() || style.preserves3D())) { | |
| 304 TransformationMatrix matrix; | |
| 305 style.applyTransform( | |
| 306 matrix, toLayoutBox(object).size(), | |
| 307 ComputedStyle::ExcludeTransformOrigin, | |
| 308 ComputedStyle::IncludeMotionPath, | |
| 309 ComputedStyle::IncludeIndependentTransformProperties); | |
| 310 FloatPoint3D origin = transformOrigin(toLayoutBox(object)); | |
| 311 | |
| 312 unsigned renderingContextID = context.current.renderingContextID; | |
| 313 unsigned renderingContextIDForChildren = 0; | |
| 314 bool flattensInheritedTransform = | |
| 315 context.current.shouldFlattenInheritedTransform; | |
| 316 bool childrenFlattenInheritedTransform = true; | |
| 317 | |
| 318 // TODO(trchen): transform-style should only be respected if a PaintLayer | |
| 319 // is created. | |
| 320 if (style.preserves3D()) { | |
| 321 // If a node with transform-style: preserve-3d does not exist in an | |
| 322 // existing rendering context, it establishes a new one. | |
| 323 if (!renderingContextID) | |
| 324 renderingContextID = PtrHash<const LayoutObject>::hash(&object); | |
| 325 renderingContextIDForChildren = renderingContextID; | |
| 326 childrenFlattenInheritedTransform = false; | |
| 327 } | |
| 328 | |
| 329 context.current.transform = | |
| 330 object.getMutableForPainting() | |
| 331 .ensurePaintProperties() | |
| 332 .updateTransform(context.current.transform, matrix, origin, | |
| 333 flattensInheritedTransform, renderingContextID); | |
| 334 context.current.renderingContextID = renderingContextIDForChildren; | |
| 335 context.current.shouldFlattenInheritedTransform = | |
| 336 childrenFlattenInheritedTransform; | |
| 337 return; | |
| 338 } | |
| 339 } | 313 } |
| 340 | 314 |
| 341 if (auto* properties = object.getMutableForPainting().paintProperties()) | 315 const ComputedStyle& style = object.styleRef(); |
| 342 properties->clearTransform(); | 316 if (object.isBox() && (style.hasTransform() || style.preserves3D())) { |
| 317 TransformationMatrix matrix; |
| 318 style.applyTransform(matrix, toLayoutBox(object).size(), |
| 319 ComputedStyle::ExcludeTransformOrigin, |
| 320 ComputedStyle::IncludeMotionPath, |
| 321 ComputedStyle::IncludeIndependentTransformProperties); |
| 322 FloatPoint3D origin = transformOrigin(toLayoutBox(object)); |
| 323 |
| 324 unsigned renderingContextID = context.current.renderingContextID; |
| 325 unsigned renderingContextIDForChildren = 0; |
| 326 bool flattensInheritedTransform = |
| 327 context.current.shouldFlattenInheritedTransform; |
| 328 bool childrenFlattenInheritedTransform = true; |
| 329 |
| 330 // TODO(trchen): transform-style should only be respected if a PaintLayer |
| 331 // is created. |
| 332 if (style.preserves3D()) { |
| 333 // If a node with transform-style: preserve-3d does not exist in an |
| 334 // existing rendering context, it establishes a new one. |
| 335 if (!renderingContextID) |
| 336 renderingContextID = PtrHash<const LayoutObject>::hash(&object); |
| 337 renderingContextIDForChildren = renderingContextID; |
| 338 childrenFlattenInheritedTransform = false; |
| 339 } |
| 340 |
| 341 context.current.transform = |
| 342 object.getMutableForPainting().ensurePaintProperties().updateTransform( |
| 343 context.current.transform, matrix, origin, |
| 344 flattensInheritedTransform, renderingContextID); |
| 345 context.current.renderingContextID = renderingContextIDForChildren; |
| 346 context.current.shouldFlattenInheritedTransform = |
| 347 childrenFlattenInheritedTransform; |
| 348 } else { |
| 349 if (auto* properties = object.getMutableForPainting().paintProperties()) |
| 350 properties->clearTransform(); |
| 351 } |
| 343 } | 352 } |
| 344 | 353 |
| 345 void PaintPropertyTreeBuilder::updateEffect( | 354 void PaintPropertyTreeBuilder::updateEffect( |
| 346 const LayoutObject& object, | 355 const LayoutObject& object, |
| 347 PaintPropertyTreeBuilderContext& context) { | 356 PaintPropertyTreeBuilderContext& context) { |
| 348 if (!object.styleRef().hasOpacity()) { | 357 if (!object.styleRef().hasOpacity()) { |
| 349 if (auto* properties = object.getMutableForPainting().paintProperties()) | 358 if (auto* properties = object.getMutableForPainting().paintProperties()) |
| 350 properties->clearEffect(); | 359 properties->clearEffect(); |
| 351 return; | 360 return; |
| 352 } | 361 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 return; | 799 return; |
| 791 | 800 |
| 792 updateOverflowClip(object, context); | 801 updateOverflowClip(object, context); |
| 793 updatePerspective(object, context); | 802 updatePerspective(object, context); |
| 794 updateSvgLocalToBorderBoxTransform(object, context); | 803 updateSvgLocalToBorderBoxTransform(object, context); |
| 795 updateScrollAndScrollTranslation(object, context); | 804 updateScrollAndScrollTranslation(object, context); |
| 796 updateOutOfFlowContext(object, context); | 805 updateOutOfFlowContext(object, context); |
| 797 } | 806 } |
| 798 | 807 |
| 799 } // namespace blink | 808 } // namespace blink |
| OLD | NEW |