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/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/layout/LayoutInline.h" | |
| 9 #include "core/layout/LayoutPart.h" | 10 #include "core/layout/LayoutPart.h" |
| 10 #include "core/paint/ObjectPaintProperties.h" | 11 #include "core/paint/ObjectPaintProperties.h" |
| 11 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
| 12 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 13 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 13 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 14 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 14 #include "platform/transforms/TransformationMatrix.h" | 15 #include "platform/transforms/TransformationMatrix.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 // The context for layout tree walk. | 19 // The context for layout tree walk. |
| 19 // The walk will be done in the primary tree order (= DOM order), thus the conte xt will also be | 20 // The walk will be done in the primary tree order (= DOM order), thus the conte xt will also be |
| 20 // responsible for bookkeeping tree state in other order, for example, the most recent position | 21 // responsible for bookkeeping tree state in other order, for example, the most recent position |
| 21 // container seen. | 22 // container seen. |
| 22 struct PaintPropertyTreeBuilderContext { | 23 struct PaintPropertyTreeBuilderContext { |
| 23 PaintPropertyTreeBuilderContext() | 24 PaintPropertyTreeBuilderContext() |
| 24 : currentTransform(nullptr) | 25 : currentTransform(nullptr) |
| 25 , currentClip(nullptr) | 26 , currentClip(nullptr) |
| 26 , transformForAbsolutePosition(nullptr) | 27 , transformForAbsolutePosition(nullptr) |
| 28 , containerForAbsolutePosition(nullptr) | |
| 27 , clipForAbsolutePosition(nullptr) | 29 , clipForAbsolutePosition(nullptr) |
| 28 , transformForFixedPosition(nullptr) | 30 , transformForFixedPosition(nullptr) |
| 29 , clipForFixedPosition(nullptr) | 31 , clipForFixedPosition(nullptr) |
| 30 , currentEffect(nullptr) { } | 32 , currentEffect(nullptr) { } |
| 31 | 33 |
| 32 // The combination of a transform and paint offset describes a linear space. | 34 // The combination of a transform and paint offset describes a linear space. |
| 33 // When a layout object recur to its children, the main context is expected to refer | 35 // When a layout object recur to its children, the main context is expected to refer |
| 34 // the object's border box, then the callee will derive its own border box b y translating | 36 // the object's border box, then the callee will derive its own border box b y translating |
| 35 // the space with its own layout location. | 37 // the space with its own layout location. |
| 36 TransformPaintPropertyNode* currentTransform; | 38 TransformPaintPropertyNode* currentTransform; |
| 37 LayoutPoint paintOffset; | 39 LayoutPoint paintOffset; |
| 38 // The clip node describes the accumulated raster clip for the current subtr ee. | 40 // The clip node describes the accumulated raster clip for the current subtr ee. |
| 39 // Note that the computed raster region in canvas space for a clip node is i ndependent from | 41 // Note that the computed raster region in canvas space for a clip node is i ndependent from |
| 40 // the transform and paint offset above. Also the actual raster region may b e affected | 42 // the transform and paint offset above. Also the actual raster region may b e affected |
| 41 // by layerization and occlusion tracking. | 43 // by layerization and occlusion tracking. |
| 42 ClipPaintPropertyNode* currentClip; | 44 ClipPaintPropertyNode* currentClip; |
| 43 | 45 |
| 44 // Separate context for out-of-flow positioned and fixed positioned elements are needed | 46 // Separate context for out-of-flow positioned and fixed positioned elements are needed |
| 45 // because they don't use DOM parent as their containing block. | 47 // because they don't use DOM parent as their containing block. |
| 46 // These additional contexts normally pass through untouched, and are only c opied from | 48 // These additional contexts normally pass through untouched, and are only c opied from |
| 47 // the main context when the current element serves as the containing block of corresponding | 49 // the main context when the current element serves as the containing block of corresponding |
| 48 // positioned descendants. | 50 // positioned descendants. |
| 49 // Overflow clips are also inherited by containing block tree instead of DOM tree, thus they | 51 // Overflow clips are also inherited by containing block tree instead of DOM tree, thus they |
| 50 // are included in the additional context too. | 52 // are included in the additional context too. |
| 51 TransformPaintPropertyNode* transformForAbsolutePosition; | 53 TransformPaintPropertyNode* transformForAbsolutePosition; |
| 52 LayoutPoint paintOffsetForAbsolutePosition; | 54 LayoutPoint paintOffsetForAbsolutePosition; |
| 55 LayoutObject* containerForAbsolutePosition; | |
| 53 ClipPaintPropertyNode* clipForAbsolutePosition; | 56 ClipPaintPropertyNode* clipForAbsolutePosition; |
| 54 | 57 |
| 55 TransformPaintPropertyNode* transformForFixedPosition; | 58 TransformPaintPropertyNode* transformForFixedPosition; |
| 56 LayoutPoint paintOffsetForFixedPosition; | 59 LayoutPoint paintOffsetForFixedPosition; |
| 57 ClipPaintPropertyNode* clipForFixedPosition; | 60 ClipPaintPropertyNode* clipForFixedPosition; |
| 58 | 61 |
| 59 // The effect hierarchy is applied by the stacking context tree. It is guara nteed that every | 62 // The effect hierarchy is applied by the stacking context tree. It is guara nteed that every |
| 60 // DOM descendant is also a stacking context descendant. Therefore, we don't need extra | 63 // DOM descendant is also a stacking context descendant. Therefore, we don't need extra |
| 61 // bookkeeping for effect nodes and can generate the effect tree from a DOM- order traversal. | 64 // bookkeeping for effect nodes and can generate the effect tree from a DOM- order traversal. |
| 62 EffectPaintPropertyNode* currentEffect; | 65 EffectPaintPropertyNode* currentEffect; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 108 |
| 106 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e())); | 109 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e())); |
| 107 RefPtr<ClipPaintPropertyNode> newClipNodeForContentClip = ClipPaintPropertyN ode::create(newTransformNodeForPreTranslation.get(), contentClip, localContext.c urrentClip); | 110 RefPtr<ClipPaintPropertyNode> newClipNodeForContentClip = ClipPaintPropertyN ode::create(newTransformNodeForPreTranslation.get(), contentClip, localContext.c urrentClip); |
| 108 localContext.currentClip = localContext.clipForAbsolutePosition = localConte xt.clipForFixedPosition = newClipNodeForContentClip.get(); | 111 localContext.currentClip = localContext.clipForAbsolutePosition = localConte xt.clipForFixedPosition = newClipNodeForContentClip.get(); |
| 109 | 112 |
| 110 DoubleSize scrollOffset = frameView.scrollOffsetDouble(); | 113 DoubleSize scrollOffset = frameView.scrollOffsetDouble(); |
| 111 TransformationMatrix frameScroll; | 114 TransformationMatrix frameScroll; |
| 112 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height()); | 115 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height()); |
| 113 RefPtr<TransformPaintPropertyNode> newTransformNodeForScrollTranslation = Tr ansformPaintPropertyNode::create(frameScroll, FloatPoint3D(), newTransformNodeFo rPreTranslation); | 116 RefPtr<TransformPaintPropertyNode> newTransformNodeForScrollTranslation = Tr ansformPaintPropertyNode::create(frameScroll, FloatPoint3D(), newTransformNodeFo rPreTranslation); |
| 114 localContext.currentTransform = localContext.transformForAbsolutePosition = newTransformNodeForScrollTranslation.get(); | 117 localContext.currentTransform = localContext.transformForAbsolutePosition = newTransformNodeForScrollTranslation.get(); |
| 115 localContext.paintOffset = localContext.paintOffsetForAbsolutePosition = Lay outPoint(); | 118 localContext.paintOffset = LayoutPoint(); |
| 119 localContext.paintOffsetForAbsolutePosition = LayoutPoint(); | |
| 120 localContext.containerForAbsolutePosition = nullptr; | |
| 116 | 121 |
| 117 frameView.setPreTranslation(newTransformNodeForPreTranslation.release()); | 122 frameView.setPreTranslation(newTransformNodeForPreTranslation.release()); |
| 118 frameView.setScrollTranslation(newTransformNodeForScrollTranslation.release( )); | 123 frameView.setScrollTranslation(newTransformNodeForScrollTranslation.release( )); |
| 119 frameView.setContentClip(newClipNodeForContentClip.release()); | 124 frameView.setContentClip(newClipNodeForContentClip.release()); |
| 120 | 125 |
| 121 if (LayoutView* layoutView = frameView.layoutView()) | 126 if (LayoutView* layoutView = frameView.layoutView()) |
| 122 walk(*layoutView, localContext); | 127 walk(*layoutView, localContext); |
| 123 } | 128 } |
| 124 | 129 |
| 125 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(LayoutObject& object , PaintPropertyTreeBuilderContext& context) | 130 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(LayoutObject& object , PaintPropertyTreeBuilderContext& context) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 context.currentTransform = scrollTranslation.get(); | 331 context.currentTransform = scrollTranslation.get(); |
| 327 object.ensureObjectPaintProperties().setScrollTranslation(scrollTranslation. release()); | 332 object.ensureObjectPaintProperties().setScrollTranslation(scrollTranslation. release()); |
| 328 } | 333 } |
| 329 | 334 |
| 330 void PaintPropertyTreeBuilder::updateOutOfFlowContext(LayoutObject& object, Pain tPropertyTreeBuilderContext& context) | 335 void PaintPropertyTreeBuilder::updateOutOfFlowContext(LayoutObject& object, Pain tPropertyTreeBuilderContext& context) |
| 331 { | 336 { |
| 332 if (object.canContainAbsolutePositionObjects()) { | 337 if (object.canContainAbsolutePositionObjects()) { |
| 333 context.transformForAbsolutePosition = context.currentTransform; | 338 context.transformForAbsolutePosition = context.currentTransform; |
| 334 context.paintOffsetForAbsolutePosition = context.paintOffset; | 339 context.paintOffsetForAbsolutePosition = context.paintOffset; |
| 335 context.clipForAbsolutePosition = context.currentClip; | 340 context.clipForAbsolutePosition = context.currentClip; |
| 341 context.containerForAbsolutePosition = &object; | |
| 336 } | 342 } |
| 337 | 343 |
| 338 // TODO(pdr): Remove the !object.isLayoutView() condition when removing Fram eView | 344 // TODO(pdr): Remove the !object.isLayoutView() condition when removing Fram eView |
| 339 // paint properties for rootLayerScrolls. | 345 // paint properties for rootLayerScrolls. |
| 340 if (!object.isLayoutView() && object.canContainFixedPositionObjects()) { | 346 if (!object.isLayoutView() && object.canContainFixedPositionObjects()) { |
| 341 context.transformForFixedPosition = context.currentTransform; | 347 context.transformForFixedPosition = context.currentTransform; |
| 342 context.paintOffsetForFixedPosition = context.paintOffset; | 348 context.paintOffsetForFixedPosition = context.paintOffset; |
| 343 context.clipForFixedPosition = context.currentClip; | 349 context.clipForFixedPosition = context.currentClip; |
| 344 } else if (object.objectPaintProperties() && object.objectPaintProperties()- >cssClip()) { | 350 } else if (object.objectPaintProperties() && object.objectPaintProperties()- >cssClip()) { |
| 345 // CSS clip applies to all descendants, even if this object is not a con taining block | 351 // CSS clip applies to all descendants, even if this object is not a con taining block |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 372 | 378 |
| 373 const LayoutBoxModelObject& boxModelObject = toLayoutBoxModelObject(object); | 379 const LayoutBoxModelObject& boxModelObject = toLayoutBoxModelObject(object); |
| 374 | 380 |
| 375 switch (object.styleRef().position()) { | 381 switch (object.styleRef().position()) { |
| 376 case StaticPosition: | 382 case StaticPosition: |
| 377 break; | 383 break; |
| 378 case RelativePosition: | 384 case RelativePosition: |
| 379 context.paintOffset += boxModelObject.offsetForInFlowPosition(); | 385 context.paintOffset += boxModelObject.offsetForInFlowPosition(); |
| 380 break; | 386 break; |
| 381 case AbsolutePosition: | 387 case AbsolutePosition: |
| 382 context.currentTransform = context.transformForAbsolutePosition; | 388 { |
|
Xianzhu
2016/05/26 21:40:55
Nit: by putting '{' at the end of the previous lin
| |
| 383 context.paintOffset = context.paintOffsetForAbsolutePosition; | 389 context.currentTransform = context.transformForAbsolutePosition; |
| 384 context.currentClip = context.clipForAbsolutePosition; | 390 context.paintOffset = context.paintOffsetForAbsolutePosition; |
| 391 | |
| 392 // Absolutely positioned content in an inline should be positioned r elative to the inline. | |
| 393 LayoutObject* container = context.containerForAbsolutePosition; | |
| 394 if (container && container->isInFlowPositioned() && container->isLay outInline()) | |
| 395 context.paintOffset += toLayoutInline(container)->offsetForInFlo wPositionedInline(toLayoutBox(object)); | |
| 396 | |
| 397 context.currentClip = context.clipForAbsolutePosition; | |
| 398 } | |
| 385 break; | 399 break; |
| 386 case StickyPosition: | 400 case StickyPosition: |
| 387 context.paintOffset += boxModelObject.offsetForInFlowPosition(); | 401 context.paintOffset += boxModelObject.offsetForInFlowPosition(); |
| 388 break; | 402 break; |
| 389 case FixedPosition: | 403 case FixedPosition: |
| 390 context.currentTransform = context.transformForFixedPosition; | 404 context.currentTransform = context.transformForFixedPosition; |
| 391 context.paintOffset = context.paintOffsetForFixedPosition; | 405 context.paintOffset = context.paintOffsetForFixedPosition; |
| 392 context.currentClip = context.clipForFixedPosition; | 406 context.currentClip = context.clipForFixedPosition; |
| 393 break; | 407 break; |
| 394 default: | 408 default: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 | 449 |
| 436 if (object.isLayoutPart()) { | 450 if (object.isLayoutPart()) { |
| 437 Widget* widget = toLayoutPart(object).widget(); | 451 Widget* widget = toLayoutPart(object).widget(); |
| 438 if (widget && widget->isFrameView()) | 452 if (widget && widget->isFrameView()) |
| 439 walk(*toFrameView(widget), localContext); | 453 walk(*toFrameView(widget), localContext); |
| 440 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). | 454 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). |
| 441 } | 455 } |
| 442 } | 456 } |
| 443 | 457 |
| 444 } // namespace blink | 458 } // namespace blink |
| OLD | NEW |