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 |
| 39 TransformationMatrix frameTranslate; |
| 40 frameTranslate.translate(frameView.x(), frameView.y()); |
| 41 // The frame owner applies paint offset already. |
| 42 // This assumption may change in the future. |
| 43 ASSERT(context.paintOffset == LayoutPoint()); |
| 44 TransformPaintPropertyNode* transformNodeForPreTranslation = new TransformPa
intPropertyNode(frameTranslate, FloatPoint3D(), context.currentTransform); |
| 45 frameView.setPreTranslation(adoptRef(transformNodeForPreTranslation)); |
| 46 localContext.transformForFixedPositioned = transformNodeForPreTranslation; |
| 47 localContext.paintOffsetForFixedPositioned = LayoutPoint(); |
| 48 |
| 49 // This is going away in favor of Settings::rootLayerScrolls. |
| 50 TransformationMatrix frameScroll; |
| 51 frameScroll.translate(-frameView.scrollX(), -frameView.scrollY()); |
| 52 TransformPaintPropertyNode* transformNodeForScrollTranslation = new Transfor
mPaintPropertyNode(frameScroll, FloatPoint3D(), transformNodeForPreTranslation); |
| 53 frameView.setScrollTranslation(adoptRef(transformNodeForScrollTranslation)); |
| 54 localContext.currentTransform = localContext.transformForOutOfFlowPositioned
= transformNodeForScrollTranslation; |
| 55 localContext.paintOffset = localContext.paintOffsetForOutOfFlowPositioned =
LayoutPoint(); |
| 56 |
| 57 if (LayoutView* layoutView = frameView.layoutView()) |
| 58 walk(*layoutView, localContext); |
| 59 } |
| 60 |
| 61 static bool shouldCreatePreTranslationNode(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 FloatPoint3D transformOrigin(const LayoutBox& box) |
| 72 { |
| 73 const ComputedStyle& style = box.styleRef(); |
| 74 |
| 75 FloatSize borderBoxSize(box.size()); |
| 76 return FloatPoint3D(floatValueForLength(style.transformOriginX(), borderBoxS
ize.width()), floatValueForLength(style.transformOriginY(), borderBoxSize.height
()), style.transformOriginZ()); |
| 77 } |
| 78 |
| 79 static FloatPoint perspectiveOrigin(const LayoutBox& box) |
| 80 { |
| 81 const ComputedStyle& style = box.styleRef(); |
| 82 |
| 83 FloatSize borderBoxSize(box.size()); |
| 84 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), borderBoxS
ize.width()), floatValueForLength(style.perspectiveOriginY(), borderBoxSize.heig
ht())); |
| 85 } |
| 86 |
| 87 void PaintPropertyTreeBuilder::walk(LayoutBoxModelObject& object, const Context&
context) |
| 88 { |
| 89 ASSERT(object.isBox() != object.isLayoutInline()); // Either or. |
| 90 |
| 91 Context localContext(context); |
| 92 RefPtr<TransformPaintPropertyNode> newTransformNodeForPreTranslation; |
| 93 RefPtr<TransformPaintPropertyNode> newTransformNodeForTransform; |
| 94 RefPtr<TransformPaintPropertyNode> newTransformNodeForPerspective; |
| 95 RefPtr<TransformPaintPropertyNode> newTransformNodeForScrollTranslation; |
| 96 |
| 97 // Step 1: Figure out the layout space of the current object. |
| 98 const ComputedStyle& style = object.styleRef(); |
| 99 // TODO(trchen): There is some insanity going on with tables. Double check r
esults. |
| 100 switch (style.position()) { |
| 101 case StaticPosition: |
| 102 break; |
| 103 case RelativePosition: |
| 104 localContext.paintOffset += object.offsetForInFlowPosition(); |
| 105 break; |
| 106 case AbsolutePosition: |
| 107 localContext.currentTransform = context.transformForOutOfFlowPositioned; |
| 108 localContext.paintOffset = context.paintOffsetForOutOfFlowPositioned; |
| 109 break; |
| 110 case StickyPosition: |
| 111 localContext.paintOffset += object.offsetForInFlowPosition(); |
| 112 break; |
| 113 case FixedPosition: |
| 114 localContext.currentTransform = context.transformForFixedPositioned; |
| 115 localContext.paintOffset = context.paintOffsetForFixedPositioned; |
| 116 break; |
| 117 default: |
| 118 ASSERT_NOT_REACHED(); |
| 119 } |
| 120 if (object.isBox()) |
| 121 localContext.paintOffset += toLayoutBox(object).locationOffset(); |
| 122 |
| 123 // Step 2: Create a transform node to consolidate paint offset (if needed). |
| 124 if (shouldCreatePreTranslationNode(object) && localContext.paintOffset != La
youtPoint()) { |
| 125 TransformationMatrix matrix; |
| 126 matrix.translate(localContext.paintOffset.x(), localContext.paintOffset.
y()); |
| 127 newTransformNodeForPreTranslation = adoptRef(new TransformPaintPropertyN
ode(matrix, FloatPoint3D(), localContext.currentTransform)); |
| 128 localContext.currentTransform = newTransformNodeForPreTranslation.get(); |
| 129 localContext.paintOffset = LayoutPoint(); |
| 130 } |
| 131 |
| 132 // Step 3: Create a transform node for CSS transform (if presents). |
| 133 bool hasTransform = object.isBox() && style.hasTransform(); |
| 134 if (hasTransform) { |
| 135 TransformationMatrix matrix; |
| 136 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle::
ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath, ComputedStyle::Include
IndependentTransformProperties); |
| 137 newTransformNodeForTransform = adoptRef(new TransformPaintPropertyNode(m
atrix, transformOrigin(toLayoutBox(object)), localContext.currentTransform)); |
| 138 localContext.currentTransform = newTransformNodeForTransform.get(); |
| 139 ASSERT(localContext.paintOffset == LayoutPoint()); |
| 140 } |
| 141 // At this point, the current space is the space we paint the element itself
. |
| 142 |
| 143 // Step 3: Create a transform node for CSS perspective (if presents). |
| 144 if (object.isBox() && style.hasPerspective()) { |
| 145 TransformationMatrix matrix; |
| 146 matrix.applyPerspective(style.perspective()); |
| 147 newTransformNodeForPerspective = adoptRef(new TransformPaintPropertyNode
(matrix, perspectiveOrigin(toLayoutBox(object)), localContext.currentTransform))
; |
| 148 localContext.currentTransform = newTransformNodeForPerspective.get(); |
| 149 ASSERT(localContext.paintOffset == LayoutPoint()); |
| 150 } |
| 151 |
| 152 // Step 4: Update the context for out-of-flow descendants (if position conta
iner is established). |
| 153 if (style.position() != StaticPosition || hasTransform) { |
| 154 localContext.transformForOutOfFlowPositioned = localContext.currentTrans
form; |
| 155 localContext.paintOffsetForOutOfFlowPositioned = localContext.paintOffse
t; |
| 156 } |
| 157 if (hasTransform) { |
| 158 localContext.transformForFixedPositioned = localContext.currentTransform
; |
| 159 localContext.paintOffsetForFixedPositioned = localContext.paintOffset; |
| 160 } |
| 161 |
| 162 // Step 5: Create a transform node for overflow clip (if presents). |
| 163 if (object.hasOverflowClip()) { |
| 164 PaintLayer* layer = object.layer(); |
| 165 ASSERT(layer); |
| 166 DoubleSize scrollOffset = layer->scrollableArea()->scrollOffset(); |
| 167 if (!scrollOffset.isZero() || layer->scrollsOverflow()) { |
| 168 TransformationMatrix matrix; |
| 169 matrix.translate(-scrollOffset.width(), -scrollOffset.height()); |
| 170 newTransformNodeForScrollTranslation = adoptRef(new TransformPaintPr
opertyNode(matrix, FloatPoint3D(), localContext.currentTransform)); |
| 171 localContext.currentTransform = newTransformNodeForScrollTranslation
.get(); |
| 172 } |
| 173 } |
| 174 // At this point, the current space is the space we paint in-flow children. |
| 175 |
| 176 // Step 6: Memorize the nodes we created for future reference during paint. |
| 177 if (newTransformNodeForPreTranslation || newTransformNodeForTransform || new
TransformNodeForPerspective || newTransformNodeForScrollTranslation) { |
| 178 ObjectPaintProperties& properties = object.ensureObjectPaintProperties()
; |
| 179 properties.setPreTranslation(newTransformNodeForPreTranslation.release()
); |
| 180 properties.setTransform(newTransformNodeForTransform.release()); |
| 181 properties.setPerspective(newTransformNodeForPerspective.release()); |
| 182 properties.setScrollTranslation(newTransformNodeForScrollTranslation.rel
ease()); |
| 183 } else { |
| 184 object.clearObjectPaintProperties(); |
| 185 } |
| 186 |
| 187 // Step 7: Recur. |
| 188 if (object.isSVGRoot()) { |
| 189 // TODO(trchen): Implement SVG walk. |
| 190 return; |
| 191 } |
| 192 |
| 193 for (LayoutObject* child = object.slowFirstChild(); child; child = child->ne
xtSibling()) { |
| 194 if (child->isText()) |
| 195 continue; |
| 196 walk(toLayoutBoxModelObject(*child), localContext); |
| 197 } |
| 198 } |
| 199 |
| 200 } // namespace blink |
OLD | NEW |