Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilder.cpp

Issue 2320463002: [SPV2] Implement the blink-side scroll property tree (Closed)
Patch Set: Prevent circular reference caught by lsan Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 22
23 void PaintPropertyTreeBuilder::buildTreeRootNodes(FrameView& rootFrame, PaintPro pertyTreeBuilderContext& context) 23 void PaintPropertyTreeBuilder::buildTreeRootNodes(FrameView& rootFrame, PaintPro pertyTreeBuilderContext& context)
24 { 24 {
25 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 25 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled())
26 return; 26 return;
27 27
28 if (!rootFrame.rootTransform() || rootFrame.rootTransform()->parent()) { 28 if (!rootFrame.rootTransform() || rootFrame.rootTransform()->parent()) {
29 rootFrame.setRootTransform(TransformPaintPropertyNode::create(nullptr, T ransformationMatrix(), FloatPoint3D())); 29 rootFrame.setRootTransform(TransformPaintPropertyNode::create(nullptr, T ransformationMatrix(), FloatPoint3D()));
30 rootFrame.setRootClip(ClipPaintPropertyNode::create(nullptr, rootFrame.r ootTransform(), FloatRoundedRect(LayoutRect::infiniteIntRect()))); 30 rootFrame.setRootClip(ClipPaintPropertyNode::create(nullptr, rootFrame.r ootTransform(), FloatRoundedRect(LayoutRect::infiniteIntRect())));
31 rootFrame.setRootEffect(EffectPaintPropertyNode::create(nullptr, 1.0)); 31 rootFrame.setRootEffect(EffectPaintPropertyNode::create(nullptr, 1.0));
32 rootFrame.setRootScroll(ScrollPaintPropertyNode::create(nullptr, rootFra me.rootTransform(), IntSize(), IntSize(), false, false));
32 } else { 33 } else {
33 DCHECK(rootFrame.rootClip() && !rootFrame.rootClip()->parent()); 34 DCHECK(rootFrame.rootClip() && !rootFrame.rootClip()->parent());
34 DCHECK(rootFrame.rootEffect() && !rootFrame.rootEffect()->parent()); 35 DCHECK(rootFrame.rootEffect() && !rootFrame.rootEffect()->parent());
35 } 36 }
36 37
37 context.current.transform = context.absolutePosition.transform = context.fix edPosition.transform = rootFrame.rootTransform(); 38 context.current.transform = context.absolutePosition.transform = context.fix edPosition.transform = rootFrame.rootTransform();
39 context.current.scroll = rootFrame.rootScroll();
38 context.current.clip = context.absolutePosition.clip = context.fixedPosition .clip = rootFrame.rootClip(); 40 context.current.clip = context.absolutePosition.clip = context.fixedPosition .clip = rootFrame.rootClip();
39 context.currentEffect = rootFrame.rootEffect(); 41 context.currentEffect = rootFrame.rootEffect();
40 } 42 }
41 43
44 void createOrUpdateFrameViewPreTranslation(FrameView& frameView,
45 PassRefPtr<const TransformPaintPropertyNode> parent,
46 const TransformationMatrix& matrix,
47 const FloatPoint3D& origin)
48 {
49 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
50 if (TransformPaintPropertyNode* existingPreTranslation = frameView.preTransl ation())
51 existingPreTranslation->update(parent, matrix, origin);
52 else
53 frameView.setPreTranslation(TransformPaintPropertyNode::create(parent, m atrix, origin));
54 }
55
56 void createOrUpdateFrameViewContentClip(FrameView& frameView,
57 PassRefPtr<const ClipPaintPropertyNode> parent,
58 PassRefPtr<const TransformPaintPropertyNode> localTransformSpace,
59 const FloatRoundedRect& clipRect)
60 {
61 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
62 if (ClipPaintPropertyNode* existingContentClip = frameView.contentClip())
63 existingContentClip->update(parent, localTransformSpace, clipRect);
64 else
65 frameView.setContentClip(ClipPaintPropertyNode::create(parent, localTran sformSpace, clipRect));
66 }
67
68 void createOrUpdateFrameViewScrollTranslation(FrameView& frameView,
69 PassRefPtr<const TransformPaintPropertyNode> parent,
70 const TransformationMatrix& matrix,
71 const FloatPoint3D& origin)
72 {
73 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
74 if (TransformPaintPropertyNode* existingScrollTranslation = frameView.scroll Translation())
75 existingScrollTranslation->update(parent, matrix, origin);
76 else
77 frameView.setScrollTranslation(TransformPaintPropertyNode::create(parent , matrix, origin));
78 }
79
80 void createOrUpdateFrameViewScroll(FrameView& frameView,
81 PassRefPtr<const ScrollPaintPropertyNode> parent,
82 PassRefPtr<const TransformPaintPropertyNode> scrollOffset,
83 const IntSize& clip, const IntSize& bounds,
84 bool userScrollableHorizontal,
85 bool userScrollableVertical)
86 {
87 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
88 if (ScrollPaintPropertyNode* existingScroll = frameView.scroll())
89 existingScroll->update(parent, scrollOffset, clip, bounds, userScrollabl eHorizontal, userScrollableVertical);
90 else
91 frameView.setScroll(ScrollPaintPropertyNode::create(parent, scrollOffset , clip, bounds, userScrollableHorizontal, userScrollableVertical));
92 }
93
42 void PaintPropertyTreeBuilder::buildTreeNodes(FrameView& frameView, PaintPropert yTreeBuilderContext& context) 94 void PaintPropertyTreeBuilder::buildTreeNodes(FrameView& frameView, PaintPropert yTreeBuilderContext& context)
43 { 95 {
44 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 96 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
45 LayoutView* layoutView = frameView.layoutView(); 97 LayoutView* layoutView = frameView.layoutView();
46 if (!layoutView) 98 if (!layoutView)
47 return; 99 return;
48 100
49 TransformationMatrix frameTranslate; 101 TransformationMatrix frameTranslate;
50 frameTranslate.translate( 102 frameTranslate.translate(
51 frameView.x() + layoutView->location().x() + context.current.paintOf fset.x(), 103 frameView.x() + layoutView->location().x() + context.current.paintOf fset.x(),
52 frameView.y() + layoutView->location().y() + context.current.paintOf fset.y()); 104 frameView.y() + layoutView->location().y() + context.current.paintOf fset.y());
53 context.current.transform = layoutView->getMutableForPainting().ensureOb jectPaintProperties().createOrUpdatePaintOffsetTranslation( 105 context.current.transform = layoutView->getMutableForPainting().ensureOb jectPaintProperties().createOrUpdatePaintOffsetTranslation(
54 context.current.transform, frameTranslate, FloatPoint3D()); 106 context.current.transform, frameTranslate, FloatPoint3D());
107 context.current.scroll = layoutView->getMutableForPainting().ensureObjec tPaintProperties().createOrUpdateScroll(
108 context.current.scroll, context.current.transform, IntSize(), IntSiz e(), false, false);
55 context.current.paintOffset = LayoutPoint(); 109 context.current.paintOffset = LayoutPoint();
56 context.current.renderingContextID = 0; 110 context.current.renderingContextID = 0;
57 context.current.shouldFlattenInheritedTransform = true; 111 context.current.shouldFlattenInheritedTransform = true;
58 context.absolutePosition = context.current; 112 context.absolutePosition = context.current;
59 context.containerForAbsolutePosition = nullptr; // This will get set in updateOutOfFlowContext(). 113 context.containerForAbsolutePosition = nullptr; // This will get set in updateOutOfFlowContext().
60 context.fixedPosition = context.current; 114 context.fixedPosition = context.current;
61 return; 115 return;
62 } 116 }
63 117
64 TransformationMatrix frameTranslate; 118 TransformationMatrix frameTranslate;
65 frameTranslate.translate(frameView.x() + context.current.paintOffset.x(), fr ameView.y() + context.current.paintOffset.y()); 119 frameTranslate.translate(frameView.x() + context.current.paintOffset.x(), fr ameView.y() + context.current.paintOffset.y());
66 if (TransformPaintPropertyNode* existingPreTranslation = frameView.preTransl ation()) 120 createOrUpdateFrameViewPreTranslation(frameView, context.current.transform, frameTranslate, FloatPoint3D());
67 existingPreTranslation->update(context.current.transform, frameTranslate , FloatPoint3D());
68 else
69 frameView.setPreTranslation(TransformPaintPropertyNode::create(context.c urrent.transform, frameTranslate, FloatPoint3D()));
70 121
71 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e())); 122 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e()));
72 if (ClipPaintPropertyNode* existingContentClip = frameView.contentClip()) 123 createOrUpdateFrameViewContentClip(frameView, context.current.clip, frameVie w.preTranslation(), contentClip);
73 existingContentClip->update(context.current.clip, frameView.preTranslati on(), contentClip);
74 else
75 frameView.setContentClip(ClipPaintPropertyNode::create(context.current.c lip, frameView.preTranslation(), contentClip));
76 124
77 DoubleSize scrollOffset = frameView.scrollOffsetDouble(); 125 DoubleSize scrollOffset = frameView.scrollOffsetDouble();
78 TransformationMatrix frameScroll; 126 TransformationMatrix frameScroll;
79 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height()); 127 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height());
80 if (TransformPaintPropertyNode* existingScrollTranslation = frameView.scroll Translation()) 128 // TODO(pdr): A scroll translation should not be needed when frameView.isScr ollable() is false.
81 existingScrollTranslation->update(frameView.preTranslation(), frameScrol l, FloatPoint3D()); 129 createOrUpdateFrameViewScrollTranslation(frameView, frameView.preTranslation (), frameScroll, FloatPoint3D());
82 else 130
83 frameView.setScrollTranslation(TransformPaintPropertyNode::create(frameV iew.preTranslation(), frameScroll, FloatPoint3D())); 131 if (frameView.isScrollable()) {
132 IntSize scrollClip = frameView.visibleContentSize();
133 IntSize scrollBounds = frameView.contentsSize();
134 bool userScrollableHorizontal = frameView.userInputScrollable(Horizontal Scrollbar);
135 bool userScrollableVertical = frameView.userInputScrollable(VerticalScro llbar);
136 createOrUpdateFrameViewScroll(frameView, context.current.scroll, frameVi ew.scrollTranslation(), scrollClip, scrollBounds, userScrollableHorizontal, user ScrollableVertical);
137 } else {
138 frameView.setScroll(nullptr);
139 }
84 140
85 // Initialize the context for current, absolute and fixed position cases. 141 // Initialize the context for current, absolute and fixed position cases.
86 // They are the same, except that scroll translation does not apply to 142 // They are the same, except that scroll translation does not apply to
87 // fixed position descendants. 143 // fixed position descendants.
144 const ScrollPaintPropertyNode* initialScroll = context.current.scroll;
88 context.current.transform = frameView.scrollTranslation(); 145 context.current.transform = frameView.scrollTranslation();
89 context.current.paintOffset = LayoutPoint(); 146 context.current.paintOffset = LayoutPoint();
90 context.current.clip = frameView.contentClip(); 147 context.current.clip = frameView.contentClip();
148 context.current.scroll = frameView.scroll() ? frameView.scroll() : initialSc roll;
91 context.current.renderingContextID = 0; 149 context.current.renderingContextID = 0;
92 context.current.shouldFlattenInheritedTransform = true; 150 context.current.shouldFlattenInheritedTransform = true;
93 context.absolutePosition = context.current; 151 context.absolutePosition = context.current;
94 context.containerForAbsolutePosition = nullptr; 152 context.containerForAbsolutePosition = nullptr;
95 context.fixedPosition = context.current; 153 context.fixedPosition = context.current;
96 context.fixedPosition.transform = frameView.preTranslation(); 154 context.fixedPosition.transform = frameView.preTranslation();
155 context.fixedPosition.scroll = initialScroll;
97 } 156 }
98 157
99 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(const LayoutObject& object, PaintPropertyTreeBuilderContext& context) 158 void PaintPropertyTreeBuilder::updatePaintOffsetTranslation(const LayoutObject& object, PaintPropertyTreeBuilderContext& context)
100 { 159 {
101 if (object.isBoxModelObject() && context.current.paintOffset != LayoutPoint( )) { 160 if (object.isBoxModelObject() && context.current.paintOffset != LayoutPoint( )) {
102 // TODO(trchen): Eliminate PaintLayer dependency. 161 // TODO(trchen): Eliminate PaintLayer dependency.
103 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); 162 PaintLayer* layer = toLayoutBoxModelObject(object).layer();
104 if (layer && layer->paintsWithTransform(GlobalPaintNormalPhase)) { 163 if (layer && layer->paintsWithTransform(GlobalPaintNormalPhase)) {
105 // We should use the same subpixel paint offset values for snapping regardless of whether a 164 // We should use the same subpixel paint offset values for snapping regardless of whether a
106 // transform is present. If there is a transform we round the paint offset but keep around 165 // transform is present. If there is a transform we round the paint offset but keep around
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 void PaintPropertyTreeBuilder::updateLocalBorderBoxContext(const LayoutObject& o bject, PaintPropertyTreeBuilderContext& context) 290 void PaintPropertyTreeBuilder::updateLocalBorderBoxContext(const LayoutObject& o bject, PaintPropertyTreeBuilderContext& context)
232 { 291 {
233 // Avoid adding an ObjectPaintProperties for non-boxes to save memory, since we don't need them at the moment. 292 // Avoid adding an ObjectPaintProperties for non-boxes to save memory, since we don't need them at the moment.
234 if (!object.isBox() && !object.hasLayer()) 293 if (!object.isBox() && !object.hasLayer())
235 return; 294 return;
236 295
237 std::unique_ptr<ObjectPaintProperties::LocalBorderBoxProperties> borderBoxCo ntext = 296 std::unique_ptr<ObjectPaintProperties::LocalBorderBoxProperties> borderBoxCo ntext =
238 wrapUnique(new ObjectPaintProperties::LocalBorderBoxProperties); 297 wrapUnique(new ObjectPaintProperties::LocalBorderBoxProperties);
239 borderBoxContext->paintOffset = context.current.paintOffset; 298 borderBoxContext->paintOffset = context.current.paintOffset;
240 borderBoxContext->propertyTreeState = PropertyTreeState(context.current.tran sform, context.current.clip, context.currentEffect); 299 borderBoxContext->propertyTreeState = PropertyTreeState(context.current.tran sform, context.current.clip, context.currentEffect);
300 borderBoxContext->scroll = context.current.scroll;
241 301
242 if (!context.current.clip) { 302 if (!context.current.clip) {
243 DCHECK(object.isLayoutView()); 303 DCHECK(object.isLayoutView());
244 DCHECK(toLayoutView(object).frameView()->frame().isMainFrame()); 304 DCHECK(toLayoutView(object).frameView()->frame().isMainFrame());
245 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled()); 305 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled());
246 borderBoxContext->propertyTreeState.clip = ClipPaintPropertyNode::create (nullptr, context.current.transform, FloatRoundedRect(LayoutRect::infiniteIntRec t())); 306 borderBoxContext->propertyTreeState.clip = ClipPaintPropertyNode::create (nullptr, context.current.transform, FloatRoundedRect(LayoutRect::infiniteIntRec t()));
247 context.current.clip = borderBoxContext->propertyTreeState.clip.get(); 307 context.current.clip = borderBoxContext->propertyTreeState.clip.get();
248 } 308 }
249 309
250 object.getMutableForPainting().ensureObjectPaintProperties().setLocalBorderB oxProperties(std::move(borderBoxContext)); 310 object.getMutableForPainting().ensureObjectPaintProperties().setLocalBorderB oxProperties(std::move(borderBoxContext));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 properties->clearSvgLocalToBorderBoxTransform(); 408 properties->clearSvgLocalToBorderBoxTransform();
349 return; 409 return;
350 } 410 }
351 411
352 context.current.transform = object.getMutableForPainting().ensureObjectPaint Properties().createOrUpdateSvgLocalToBorderBoxTransform( 412 context.current.transform = object.getMutableForPainting().ensureObjectPaint Properties().createOrUpdateSvgLocalToBorderBoxTransform(
353 context.current.transform, transformToBorderBox, FloatPoint3D()); 413 context.current.transform, transformToBorderBox, FloatPoint3D());
354 context.current.shouldFlattenInheritedTransform = false; 414 context.current.shouldFlattenInheritedTransform = false;
355 context.current.renderingContextID = 0; 415 context.current.renderingContextID = 0;
356 } 416 }
357 417
358 void PaintPropertyTreeBuilder::updateScrollTranslation(const LayoutObject& objec t, PaintPropertyTreeBuilderContext& context) 418 void PaintPropertyTreeBuilder::updateScrollAndScrollTranslation(const LayoutObje ct& object, PaintPropertyTreeBuilderContext& context)
359 { 419 {
360 if (object.isBoxModelObject() && object.hasOverflowClip()) { 420 if (object.isBoxModelObject() && object.hasOverflowClip()) {
361 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); 421 PaintLayer* layer = toLayoutBoxModelObject(object).layer();
362 DCHECK(layer); 422 DCHECK(layer);
363 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset(); 423 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset();
364 bool forceScrollingForLayoutView = object.isLayoutView() && RuntimeEnabl edFeatures::rootLayerScrollingEnabled(); 424 bool forceScrollingForLayoutView = object.isLayoutView() && RuntimeEnabl edFeatures::rootLayerScrollingEnabled();
365 if (forceScrollingForLayoutView || !scrollOffset.isZero() || layer->scro llsOverflow()) { 425 if (forceScrollingForLayoutView || !scrollOffset.isZero() || layer->scro llsOverflow()) {
366 TransformationMatrix matrix = TransformationMatrix().translate(-scro llOffset.width(), -scrollOffset.height()); 426 TransformationMatrix matrix = TransformationMatrix().translate(-scro llOffset.width(), -scrollOffset.height());
367 context.current.transform = object.getMutableForPainting().ensureObj ectPaintProperties().createOrUpdateScrollTranslation( 427 context.current.transform = object.getMutableForPainting().ensureObj ectPaintProperties().createOrUpdateScrollTranslation(
368 context.current.transform, matrix, FloatPoint3D(), context.curre nt.shouldFlattenInheritedTransform, context.current.renderingContextID); 428 context.current.transform, matrix, FloatPoint3D(), context.curre nt.shouldFlattenInheritedTransform, context.current.renderingContextID);
429
430 IntSize scrollClip = layer->getScrollableArea()->visibleContentRect( ).size();
431 IntSize scrollBounds = layer->getScrollableArea()->contentsSize();
432 bool userScrollableHorizontal = layer->getScrollableArea()->userInpu tScrollable(HorizontalScrollbar);
433 bool userScrollableVertical = layer->getScrollableArea()->userInputS crollable(VerticalScrollbar);
434 const ScrollPaintPropertyNode* parentScrollNode = forceScrollingForL ayoutView ? nullptr : context.current.scroll;
435 context.current.scroll = object.getMutableForPainting().ensureObject PaintProperties().createOrUpdateScroll(
436 parentScrollNode, context.current.transform, scrollClip, scrollB ounds, userScrollableHorizontal, userScrollableVertical);
437
369 context.current.shouldFlattenInheritedTransform = false; 438 context.current.shouldFlattenInheritedTransform = false;
370 return; 439 return;
371 } 440 }
372 } 441 }
373 442
374 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties()) 443 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties()) {
375 properties->clearScrollTranslation(); 444 properties->clearScrollTranslation();
445 properties->clearScroll();
446 }
376 } 447 }
377 448
378 void PaintPropertyTreeBuilder::updateOutOfFlowContext(const LayoutObject& object , PaintPropertyTreeBuilderContext& context) 449 void PaintPropertyTreeBuilder::updateOutOfFlowContext(const LayoutObject& object , PaintPropertyTreeBuilderContext& context)
379 { 450 {
380 if (object.canContainAbsolutePositionObjects()) { 451 if (object.canContainAbsolutePositionObjects()) {
381 context.absolutePosition = context.current; 452 context.absolutePosition = context.current;
382 context.containerForAbsolutePosition = &object; 453 context.containerForAbsolutePosition = &object;
383 } 454 }
384 455
385 if (object.isLayoutView()) { 456 if (object.isLayoutView()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 550 }
480 551
481 void PaintPropertyTreeBuilder::buildTreeNodesForChildren(const LayoutObject& obj ect, PaintPropertyTreeBuilderContext& context) 552 void PaintPropertyTreeBuilder::buildTreeNodesForChildren(const LayoutObject& obj ect, PaintPropertyTreeBuilderContext& context)
482 { 553 {
483 if (!object.isBoxModelObject() && !object.isSVG()) 554 if (!object.isBoxModelObject() && !object.isSVG())
484 return; 555 return;
485 556
486 updateOverflowClip(object, context); 557 updateOverflowClip(object, context);
487 updatePerspective(object, context); 558 updatePerspective(object, context);
488 updateSvgLocalToBorderBoxTransform(object, context); 559 updateSvgLocalToBorderBoxTransform(object, context);
489 updateScrollTranslation(object, context); 560 updateScrollAndScrollTranslation(object, context);
490 updateOutOfFlowContext(object, context); 561 updateOutOfFlowContext(object, context);
491 } 562 }
492 563
493 } // namespace blink 564 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698