Chromium Code Reviews| 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" |
| 11 #include "core/layout/LayoutPart.h" | 11 #include "core/layout/LayoutPart.h" |
| 12 #include "core/layout/svg/LayoutSVGRoot.h" | |
| 12 #include "core/paint/ObjectPaintProperties.h" | 13 #include "core/paint/ObjectPaintProperties.h" |
| 13 #include "core/paint/PaintLayer.h" | 14 #include "core/paint/PaintLayer.h" |
| 14 #include "platform/transforms/TransformationMatrix.h" | 15 #include "platform/transforms/TransformationMatrix.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 void PaintPropertyTreeBuilder::buildTreeRootNodes(FrameView& rootFrame, PaintPro pertyTreeBuilderContext& context) | 19 void PaintPropertyTreeBuilder::buildTreeRootNodes(FrameView& rootFrame, PaintPro pertyTreeBuilderContext& context) |
| 19 { | 20 { |
| 20 // Only create extra root clip and transform nodes when RLS is enabled, beca use the main frame | 21 // Only create extra root clip and transform nodes when RLS is enabled, beca use the main frame |
| 21 // unconditionally create frame translation / clip nodes otherwise. | 22 // unconditionally create frame translation / clip nodes otherwise. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 context.paintOffsetForAbsolutePosition = LayoutPoint(); | 58 context.paintOffsetForAbsolutePosition = LayoutPoint(); |
| 58 context.containerForAbsolutePosition = nullptr; | 59 context.containerForAbsolutePosition = nullptr; |
| 59 | 60 |
| 60 frameView.setPreTranslation(newTransformNodeForPreTranslation.release()); | 61 frameView.setPreTranslation(newTransformNodeForPreTranslation.release()); |
| 61 frameView.setScrollTranslation(newTransformNodeForScrollTranslation.release( )); | 62 frameView.setScrollTranslation(newTransformNodeForScrollTranslation.release( )); |
| 62 frameView.setContentClip(newClipNodeForContentClip.release()); | 63 frameView.setContentClip(newClipNodeForContentClip.release()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(const LayoutObject& object, PaintPropertyTreeBuilderContext& context) | 66 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(const LayoutObject& object, PaintPropertyTreeBuilderContext& context) |
| 66 { | 67 { |
| 67 bool shouldCreatePaintOffsetTranslationNode = false; | 68 if (object.isBoxModelObject()) { |
| 68 if (object.isSVGRoot()) { | |
| 69 // SVG doesn't use paint offset internally so emit a paint offset at the html->svg boundary. | |
| 70 shouldCreatePaintOffsetTranslationNode = true; | |
| 71 } else if (object.isBoxModelObject()) { | |
| 72 // TODO(trchen): Eliminate PaintLayer dependency. | 69 // TODO(trchen): Eliminate PaintLayer dependency. |
| 73 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); | 70 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); |
| 74 shouldCreatePaintOffsetTranslationNode = layer && layer->paintsWithTrans form(GlobalPaintNormalPhase); | 71 if (!layer || !layer->paintsWithTransform(GlobalPaintNormalPhase)) |
| 72 return; | |
| 75 } | 73 } |
| 76 | 74 |
| 77 if (context.paintOffset == LayoutPoint() || !shouldCreatePaintOffsetTranslat ionNode) | 75 if (context.paintOffset == LayoutPoint()) |
| 78 return; | 76 return; |
| 79 | 77 |
| 80 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create( | 78 RefPtr<TransformPaintPropertyNode> paintOffsetTranslation = TransformPaintPr opertyNode::create( |
| 81 TransformationMatrix().translate(context.paintOffset.x(), context.paintO ffset.y()), | 79 TransformationMatrix().translate(context.paintOffset.x(), context.paintO ffset.y()), |
| 82 FloatPoint3D(), context.currentTransform); | 80 FloatPoint3D(), context.currentTransform); |
| 83 context.currentTransform = paintOffsetTranslation.get(); | 81 context.currentTransform = paintOffsetTranslation.get(); |
| 84 context.paintOffset = LayoutPoint(); | 82 context.paintOffset = LayoutPoint(); |
| 85 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release()); | 83 object.getMutableForPainting().ensureObjectPaintProperties().setPaintOffsetT ranslation(paintOffsetTranslation.release()); |
| 86 } | 84 } |
| 87 | 85 |
| 88 static FloatPoint3D transformOrigin(const LayoutBox& box) | 86 static FloatPoint3D transformOrigin(const LayoutBox& box) |
| 89 { | 87 { |
| 90 const ComputedStyle& style = box.styleRef(); | 88 const ComputedStyle& style = box.styleRef(); |
| 91 FloatSize borderBoxSize(box.size()); | 89 FloatSize borderBoxSize(box.size()); |
| 92 return FloatPoint3D( | 90 return FloatPoint3D( |
| 93 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), | 91 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), |
| 94 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), | 92 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), |
| 95 style.transformOriginZ()); | 93 style.transformOriginZ()); |
| 96 } | 94 } |
| 97 | 95 |
| 98 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context) | 96 void PaintPropertyTreeBuilder::updateTransform(const LayoutObject& object, Paint PropertyTreeBuilderContext& context) |
| 99 { | 97 { |
| 98 if (object.isSVG() && !object.isSVGRoot()) { | |
| 99 // SVG does not use paint offset internally and the root should have alr eady accounted for | |
| 100 // any paint offset in the root's svgLocalToBorderBox transform. | |
| 101 // FIXME(pdr): SVG text nodes inherit from HTML and do change paint offs et. Figure out | |
|
jbroman
2016/06/09 22:16:49
TODO, not FIXME
pdr.
2016/06/09 23:39:04
Newest patch answers the "fixme" and removes this
| |
| 102 // whether this DCHECK should be removed or updated to handle text. | |
| 103 // DCHECK(context.paintOffset == LayoutPoint()); | |
|
jbroman
2016/06/09 22:16:49
Huh, removed? It's only a comment right now. Can y
pdr.
2016/06/09 23:39:04
Clarified with removal.
| |
| 104 | |
| 105 // FIXME(pdr): Check for the presence of a transform instead of the valu e. Checking for an | |
|
jbroman
2016/06/09 22:16:49
TODO, not FIXME
pdr.
2016/06/09 23:39:04
Done.
| |
| 106 // identity matrix will cause the property tree structure to change duri ng animations if | |
| 107 // the animation passes through the identity matrix. | |
| 108 const AffineTransform& transform = object.localSVGTransform(); | |
| 109 if (transform.isIdentity()) | |
| 110 return; | |
| 111 | |
| 112 // The origin is included in the local transform, so use an empty origin . | |
| 113 RefPtr<TransformPaintPropertyNode> svgTransform = TransformPaintProperty Node::create( | |
| 114 transform, FloatPoint3D(0, 0, 0), context.currentTransform); | |
| 115 context.currentTransform = svgTransform.get(); | |
| 116 object.getMutableForPainting().ensureObjectPaintProperties().setTransfor m(svgTransform.release()); | |
| 117 return; | |
| 118 } | |
| 119 | |
| 100 const ComputedStyle& style = object.styleRef(); | 120 const ComputedStyle& style = object.styleRef(); |
| 101 if (!object.isBox() || !style.hasTransform()) | 121 if (!object.isBox() || !style.hasTransform()) |
| 102 return; | 122 return; |
| 103 ASSERT(context.paintOffset == LayoutPoint()); | 123 ASSERT(context.paintOffset == LayoutPoint()); |
| 104 | 124 |
| 105 TransformationMatrix matrix; | 125 TransformationMatrix matrix; |
| 106 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin, | 126 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::Excl udeTransformOrigin, |
| 107 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties); | 127 ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTrans formProperties); |
| 108 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create( | 128 RefPtr<TransformPaintPropertyNode> transformNode = TransformPaintPropertyNod e::create( |
| 109 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform); | 129 matrix, transformOrigin(toLayoutBox(object)), context.currentTransform); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 return; | 245 return; |
| 226 | 246 |
| 227 RefPtr<TransformPaintPropertyNode> perspective = TransformPaintPropertyNode: :create( | 247 RefPtr<TransformPaintPropertyNode> perspective = TransformPaintPropertyNode: :create( |
| 228 TransformationMatrix().applyPerspective(style.perspective()), | 248 TransformationMatrix().applyPerspective(style.perspective()), |
| 229 perspectiveOrigin(toLayoutBox(object)) + toLayoutSize(context.paintOffse t), | 249 perspectiveOrigin(toLayoutBox(object)) + toLayoutSize(context.paintOffse t), |
| 230 context.currentTransform); | 250 context.currentTransform); |
| 231 context.currentTransform = perspective.get(); | 251 context.currentTransform = perspective.get(); |
| 232 object.getMutableForPainting().ensureObjectPaintProperties().setPerspective( perspective.release()); | 252 object.getMutableForPainting().ensureObjectPaintProperties().setPerspective( perspective.release()); |
| 233 } | 253 } |
| 234 | 254 |
| 235 void PaintPropertyTreeBuilder::updateSvgLocalTransform(const LayoutObject& objec t, PaintPropertyTreeBuilderContext& context) | 255 void PaintPropertyTreeBuilder::updateSvgLocalToBorderBoxTransform(const LayoutOb ject& object, PaintPropertyTreeBuilderContext& context) |
| 236 { | 256 { |
| 237 if (!object.isSVG()) | 257 if (!object.isSVGRoot()) |
| 238 return; | 258 return; |
| 239 | 259 |
| 240 const AffineTransform& transform = object.localToSVGParentTransform(); | 260 AffineTransform transform = AffineTransform::translation(context.paintOffset .x().toFloat(), context.paintOffset.y().toFloat()); |
| 261 transform *= toLayoutSVGRoot(object).localToBorderBoxTransform(); | |
| 241 if (transform.isIdentity()) | 262 if (transform.isIdentity()) |
| 242 return; | 263 return; |
| 243 | 264 |
| 244 // The origin is included in the local transform, so use an empty origin. | 265 RefPtr<TransformPaintPropertyNode> svgLocalToBorderBoxTransform = TransformP aintPropertyNode::create( |
| 245 RefPtr<TransformPaintPropertyNode> svgLocalTransform = TransformPaintPropert yNode::create( | |
| 246 transform, FloatPoint3D(0, 0, 0), context.currentTransform); | 266 transform, FloatPoint3D(0, 0, 0), context.currentTransform); |
| 247 context.currentTransform = svgLocalTransform.get(); | 267 context.currentTransform = svgLocalToBorderBoxTransform.get(); |
| 248 object.getMutableForPainting().ensureObjectPaintProperties().setSvgLocalTran sform(svgLocalTransform.release()); | 268 context.paintOffset = LayoutPoint(); |
| 269 object.getMutableForPainting().ensureObjectPaintProperties().setSvgLocalToBo rderBoxTransform(svgLocalToBorderBoxTransform.release()); | |
| 249 } | 270 } |
| 250 | 271 |
| 251 void PaintPropertyTreeBuilder::updateScrollTranslation(const LayoutObject& objec t, PaintPropertyTreeBuilderContext& context) | 272 void PaintPropertyTreeBuilder::updateScrollTranslation(const LayoutObject& objec t, PaintPropertyTreeBuilderContext& context) |
| 252 { | 273 { |
| 253 if (!object.isBoxModelObject() || !object.hasOverflowClip()) | 274 if (!object.isBoxModelObject() || !object.hasOverflowClip()) |
| 254 return; | 275 return; |
| 255 | 276 |
| 256 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); | 277 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); |
| 257 ASSERT(layer); | 278 ASSERT(layer); |
| 258 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset(); | 279 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 updatePaintOffsetTranslation(object, context); | 393 updatePaintOffsetTranslation(object, context); |
| 373 updateTransform(object, context); | 394 updateTransform(object, context); |
| 374 updateEffect(object, context); | 395 updateEffect(object, context); |
| 375 updateCssClip(object, context); | 396 updateCssClip(object, context); |
| 376 updateLocalBorderBoxContext(object, context); | 397 updateLocalBorderBoxContext(object, context); |
| 377 updateScrollbarPaintOffset(object, context); | 398 updateScrollbarPaintOffset(object, context); |
| 378 updateOverflowClip(object, context); | 399 updateOverflowClip(object, context); |
| 379 // TODO(trchen): Insert flattening transform here, as specified by | 400 // TODO(trchen): Insert flattening transform here, as specified by |
| 380 // http://www.w3.org/TR/css3-transforms/#transform-style-property | 401 // http://www.w3.org/TR/css3-transforms/#transform-style-property |
| 381 updatePerspective(object, context); | 402 updatePerspective(object, context); |
| 382 updateSvgLocalTransform(object, context); | 403 updateSvgLocalToBorderBoxTransform(object, context); |
| 383 updateScrollTranslation(object, context); | 404 updateScrollTranslation(object, context); |
| 384 updateOutOfFlowContext(object, context); | 405 updateOutOfFlowContext(object, context); |
| 385 } | 406 } |
| 386 | 407 |
| 387 } // namespace blink | 408 } // namespace blink |
| OLD | NEW |