OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/paint/PaintPropertyTreeBuilder.h" |
| 7 |
| 8 #include "core/frame/FrameView.h" |
| 9 #include "core/layout/LayoutView.h" |
| 10 #include "core/paint/ObjectPaintProperties.h" |
| 11 #include "core/paint/PaintLayer.h" |
| 12 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 13 #include "platform/transforms/TransformationMatrix.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 struct PaintPropertyTreeBuilder::Context { |
| 18 Context() : transformForOutOfFlowPositioned(nullptr), transformForFixedPosit
ioned(nullptr) { } |
| 19 |
| 20 TransformPaintPropertyNode* currentTransform; |
| 21 LayoutPoint paintOffset; |
| 22 |
| 23 TransformPaintPropertyNode* transformForOutOfFlowPositioned; |
| 24 LayoutPoint paintOffsetForOutOfFlowPositioned; |
| 25 |
| 26 TransformPaintPropertyNode* transformForFixedPositioned; |
| 27 LayoutPoint paintOffsetForFixedPositioned; |
| 28 }; |
| 29 |
| 30 void PaintPropertyTreeBuilder::buildPropertyTrees(FrameView& rootFrame) |
| 31 { |
| 32 walk(rootFrame, Context()); |
| 33 } |
| 34 |
| 35 void PaintPropertyTreeBuilder::walk(FrameView& frameView, const Context& context
) |
| 36 { |
| 37 Context localContext(context); |
| 38 ObjectPaintProperties& properties = frameView.ensureObjectPaintProperties(); |
| 39 |
| 40 TransformationMatrix frameTranslate; |
| 41 frameTranslate.translate(frameView.x(), frameView.y()); |
| 42 // The frame owner applies paint offset already. |
| 43 // This assumption may change in the future. |
| 44 ASSERT(context.paintOffset == LayoutPoint()); |
| 45 TransformPaintPropertyNode* transformNodeForSelf = new TransformPaintPropert
yNode(frameTranslate, FloatPoint3D(), context.currentTransform); |
| 46 properties.setTransformNodeForSelf(adoptRef(transformNodeForSelf)); |
| 47 localContext.transformForFixedPositioned = transformNodeForSelf; |
| 48 localContext.paintOffsetForFixedPositioned = LayoutPoint(); |
| 49 |
| 50 TransformationMatrix frameScroll; |
| 51 frameScroll.translate(-frameView.scrollX(), -frameView.scrollY()); |
| 52 TransformPaintPropertyNode* transformNodeForDescendants = new TransformPaint
PropertyNode(frameScroll, FloatPoint3D(), transformNodeForSelf); |
| 53 properties.setTransformNodeForDescendants(adoptRef(transformNodeForDescendan
ts)); |
| 54 localContext.currentTransform = localContext.transformForOutOfFlowPositioned
= transformNodeForDescendants; |
| 55 localContext.paintOffset = localContext.paintOffsetForOutOfFlowPositioned =
LayoutPoint(); |
| 56 |
| 57 if (LayoutView* layoutView = frameView.layoutView()) |
| 58 walk(*layoutView, localContext); |
| 59 } |
| 60 |
| 61 static bool shouldCreateTransformNodeForSelf(LayoutBoxModelObject& object) |
| 62 { |
| 63 // TODO(trchen): Eliminate PaintLayer dependency. |
| 64 PaintLayer* layer = object.layer(); |
| 65 if (!layer) |
| 66 return false; |
| 67 |
| 68 return layer->paintsWithTransform(GlobalPaintNormalPhase); |
| 69 } |
| 70 |
| 71 static FloatPoint perspectiveOrigin(const LayoutBox& box) |
| 72 { |
| 73 const ComputedStyle& style = box.styleRef(); |
| 74 |
| 75 FloatSize borderBoxSize(box.size()); |
| 76 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), borderBoxS
ize.width()), floatValueForLength(style.perspectiveOriginY(), borderBoxSize.heig
ht())); |
| 77 } |
| 78 |
| 79 void PaintPropertyTreeBuilder::walk(LayoutBoxModelObject& object, const Context&
context) |
| 80 { |
| 81 ASSERT(object.isBox() != object.isLayoutInline()); // Either or. |
| 82 |
| 83 Context localContext(context); |
| 84 RefPtr<TransformPaintPropertyNode> newTransformNodeForSelf; |
| 85 RefPtr<TransformPaintPropertyNode> newTransformNodeForDescendants; |
| 86 |
| 87 const ComputedStyle& style = object.styleRef(); |
| 88 // TODO(trchen): There is some insanity going on with tables. Double check r
esults. |
| 89 switch (style.position()) { |
| 90 case StaticPosition: |
| 91 break; |
| 92 case RelativePosition: |
| 93 localContext.paintOffset += object.offsetForInFlowPosition(); |
| 94 break; |
| 95 case AbsolutePosition: |
| 96 localContext.currentTransform = context.transformForOutOfFlowPositioned; |
| 97 localContext.paintOffset = context.paintOffsetForOutOfFlowPositioned; |
| 98 break; |
| 99 case StickyPosition: |
| 100 localContext.paintOffset += object.offsetForInFlowPosition(); |
| 101 break; |
| 102 case FixedPosition: |
| 103 localContext.currentTransform = context.transformForFixedPositioned; |
| 104 localContext.paintOffset = context.paintOffsetForFixedPositioned; |
| 105 break; |
| 106 default: |
| 107 ASSERT_NOT_REACHED(); |
| 108 } |
| 109 if (object.isBox()) |
| 110 localContext.paintOffset += toLayoutBox(object).locationOffset(); |
| 111 |
| 112 bool hasTransform = object.isBox() && style.hasTransform(); |
| 113 if (shouldCreateTransformNodeForSelf(object)) { |
| 114 TransformationMatrix matrix; |
| 115 if (hasTransform) |
| 116 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedSty
le::IncludeTransformOrigin, ComputedStyle::IncludeMotionPath, ComputedStyle::Inc
ludeIndependentTransformProperties); |
| 117 matrix.translateRight(localContext.paintOffset.x(), localContext.paintOf
fset.y()); |
| 118 // TODO(jbroman): Put the real transform origin here, instead of using a |
| 119 // matrix with the origin baked in. |
| 120 newTransformNodeForSelf = adoptRef(new TransformPaintPropertyNode(matrix
, FloatPoint3D(), localContext.currentTransform)); |
| 121 localContext.currentTransform = newTransformNodeForSelf.get(); |
| 122 localContext.paintOffset = LayoutPoint(); |
| 123 } else { |
| 124 ASSERT(!hasTransform); |
| 125 } |
| 126 |
| 127 if (object.isBox() && style.hasPerspective()) { |
| 128 TransformationMatrix matrix; |
| 129 matrix.applyPerspective(style.perspective()); |
| 130 // Perspective forces an element to paint with transform today. |
| 131 // The assumption may change in the future. |
| 132 ASSERT(localContext.paintOffset == LayoutPoint()); |
| 133 newTransformNodeForDescendants = adoptRef(new TransformPaintPropertyNode
(matrix, perspectiveOrigin(toLayoutBox(object)), localContext.currentTransform))
; |
| 134 localContext.currentTransform = newTransformNodeForDescendants.get(); |
| 135 } |
| 136 |
| 137 if (style.position() != StaticPosition || hasTransform) { |
| 138 localContext.transformForOutOfFlowPositioned = localContext.currentTrans
form; |
| 139 localContext.paintOffsetForOutOfFlowPositioned = localContext.paintOffse
t; |
| 140 } |
| 141 |
| 142 if (hasTransform) { |
| 143 localContext.transformForFixedPositioned = localContext.currentTransform
; |
| 144 localContext.paintOffsetForFixedPositioned = localContext.paintOffset; |
| 145 } |
| 146 |
| 147 if (object.hasOverflowClip()) { |
| 148 PaintLayer* layer = object.layer(); |
| 149 ASSERT(layer); |
| 150 DoubleSize scrollOffset = layer->scrollableArea()->scrollOffset(); |
| 151 if (!scrollOffset.isZero() || layer->scrollsOverflow()) { |
| 152 TransformationMatrix matrix; |
| 153 matrix.translate(-scrollOffset.width(), -scrollOffset.height()); |
| 154 newTransformNodeForDescendants = adoptRef(new TransformPaintProperty
Node(matrix, FloatPoint3D(), localContext.currentTransform)); |
| 155 localContext.currentTransform = newTransformNodeForDescendants.get()
; |
| 156 } |
| 157 } |
| 158 |
| 159 if (newTransformNodeForSelf || newTransformNodeForDescendants) { |
| 160 ObjectPaintProperties& properties = object.ensureObjectPaintProperties()
; |
| 161 properties.setTransformNodeForSelf(newTransformNodeForSelf.release()); |
| 162 properties.setTransformNodeForDescendants(newTransformNodeForDescendants
.release()); |
| 163 } else { |
| 164 object.clearObjectPaintProperties(); |
| 165 } |
| 166 |
| 167 if (object.isSVGRoot()) { |
| 168 // TODO(trchen): Implement SVG walk. |
| 169 return; |
| 170 } |
| 171 |
| 172 for (LayoutObject* child = object.slowFirstChild(); child; child = child->ne
xtSibling()) { |
| 173 if (child->isText()) |
| 174 continue; |
| 175 walk(toLayoutBoxModelObject(*child), localContext); |
| 176 } |
| 177 } |
| 178 |
| 179 } // namespace blink |
OLD | NEW |