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

Side by Side Diff: sky/engine/core/rendering/RenderLayer.cpp

Issue 961053002: Assorted cleanup of RenderLayer. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « sky/engine/core/rendering/RenderLayer.h ('k') | sky/engine/core/rendering/RenderObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu> 7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu> 8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de> 9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 , m_has3DTransformedDescendant(false) 85 , m_has3DTransformedDescendant(false)
86 , m_hasFilterInfo(false) 86 , m_hasFilterInfo(false)
87 , m_renderer(renderer) 87 , m_renderer(renderer)
88 , m_parent(0) 88 , m_parent(0)
89 , m_previous(0) 89 , m_previous(0)
90 , m_next(0) 90 , m_next(0)
91 , m_first(0) 91 , m_first(0)
92 , m_last(0) 92 , m_last(0)
93 , m_clipper(*renderer) 93 , m_clipper(*renderer)
94 { 94 {
95 updateStackingNode(); 95 m_stackingNode = adoptPtr(new RenderLayerStackingNode(this));
96
97 m_isSelfPaintingLayer = shouldBeSelfPaintingLayer(); 96 m_isSelfPaintingLayer = shouldBeSelfPaintingLayer();
98 } 97 }
99 98
100 RenderLayer::~RenderLayer() 99 RenderLayer::~RenderLayer()
101 { 100 {
102 removeFilterInfoIfNeeded(); 101 removeFilterInfoIfNeeded();
103 } 102 }
104 103
105 String RenderLayer::debugName() const
106 {
107 return renderer()->debugName();
108 }
109
110 LayoutSize RenderLayer::subpixelAccumulation() const
111 {
112 return m_subpixelAccumulation;
113 }
114
115 void RenderLayer::setSubpixelAccumulation(const LayoutSize& size)
116 {
117 m_subpixelAccumulation = size;
118 }
119
120 void RenderLayer::updateLayerPositionsAfterLayout() 104 void RenderLayer::updateLayerPositionsAfterLayout()
121 { 105 {
122 TRACE_EVENT0("blink", "RenderLayer::updateLayerPositionsAfterLayout");
123
124 m_clipper.clearClipRectsIncludingDescendants(); 106 m_clipper.clearClipRectsIncludingDescendants();
125 } 107 }
126 108
127 void RenderLayer::updateTransformationMatrix() 109 void RenderLayer::updateTransformationMatrix()
128 { 110 {
129 if (m_transform) { 111 if (m_transform) {
130 RenderBox* box = renderBox(); 112 RenderBox* box = renderer();
131 ASSERT(box);
132 m_transform->makeIdentity(); 113 m_transform->makeIdentity();
133 box->style()->applyTransform(*m_transform, box->pixelSnappedBorderBoxRec t().size(), RenderStyle::IncludeTransformOrigin); 114 box->style()->applyTransform(*m_transform, box->pixelSnappedBorderBoxRec t().size(), RenderStyle::IncludeTransformOrigin);
134 // FIXME(sky): We shouldn't need to do this once Skia has 4x4 matrix sup port. 115 // FIXME(sky): We shouldn't need to do this once Skia has 4x4 matrix sup port.
135 // Until then, 3d transforms don't work right. 116 // Until then, 3d transforms don't work right.
136 m_transform->makeAffine(); 117 m_transform->makeAffine();
137 } 118 }
138 } 119 }
139 120
140 void RenderLayer::updateTransform(const RenderStyle* oldStyle, RenderStyle* newS tyle) 121 void RenderLayer::updateTransform(const RenderStyle* oldStyle, RenderStyle* newS tyle)
141 { 122 {
(...skipping 17 matching lines...) Expand all
159 } else if (hasTransform) { 140 } else if (hasTransform) {
160 m_clipper.clearClipRectsIncludingDescendants(AbsoluteClipRects); 141 m_clipper.clearClipRectsIncludingDescendants(AbsoluteClipRects);
161 } 142 }
162 143
163 updateTransformationMatrix(); 144 updateTransformationMatrix();
164 145
165 if (had3DTransform != has3DTransform()) 146 if (had3DTransform != has3DTransform())
166 dirty3DTransformedDescendantStatus(); 147 dirty3DTransformedDescendantStatus();
167 } 148 }
168 149
169 static RenderLayer* enclosingLayerForContainingBlock(RenderLayer* layer)
170 {
171 if (RenderObject* containingBlock = layer->renderer()->containingBlock())
172 return containingBlock->enclosingLayer();
173 return 0;
174 }
175
176 RenderLayer* RenderLayer::renderingContextRoot()
177 {
178 RenderLayer* renderingContext = 0;
179
180 if (shouldPreserve3D())
181 renderingContext = this;
182
183 for (RenderLayer* current = enclosingLayerForContainingBlock(this); current && current->shouldPreserve3D(); current = enclosingLayerForContainingBlock(curre nt))
184 renderingContext = current;
185
186 return renderingContext;
187 }
188
189 RenderLayer* RenderLayer::enclosingOverflowClipLayer(IncludeSelfOrNot includeSel f) const
190 {
191 const RenderLayer* layer = (includeSelf == IncludeSelf) ? this : parent();
192 while (layer) {
193 if (layer->renderer()->hasOverflowClip())
194 return const_cast<RenderLayer*>(layer);
195
196 layer = layer->parent();
197 }
198 return 0;
199 }
200
201 void RenderLayer::dirty3DTransformedDescendantStatus() 150 void RenderLayer::dirty3DTransformedDescendantStatus()
202 { 151 {
203 RenderLayerStackingNode* stackingNode = m_stackingNode->ancestorStackingCont extNode(); 152 RenderLayerStackingNode* stackingNode = m_stackingNode->ancestorStackingCont extNode();
204 if (!stackingNode) 153 if (!stackingNode)
205 return; 154 return;
206 155
207 stackingNode->layer()->m_3DTransformedDescendantStatusDirty = true; 156 stackingNode->layer()->m_3DTransformedDescendantStatusDirty = true;
208 157
209 // This propagates up through preserve-3d hierarchies to the enclosing flatt ening layer. 158 // This propagates up through preserve-3d hierarchies to the enclosing flatt ening layer.
210 // Note that preserves3D() creates stacking context, so we can just run up t he stacking containers. 159 // Note that preserves3D() creates stacking context, so we can just run up t he stacking containers.
(...skipping 23 matching lines...) Expand all
234 // If we live in a 3d hierarchy, then the layer at the root of that hierarch y needs 183 // If we live in a 3d hierarchy, then the layer at the root of that hierarch y needs
235 // the m_has3DTransformedDescendant set. 184 // the m_has3DTransformedDescendant set.
236 if (preserves3D()) 185 if (preserves3D())
237 return has3DTransform() || m_has3DTransformedDescendant; 186 return has3DTransform() || m_has3DTransformedDescendant;
238 187
239 return has3DTransform(); 188 return has3DTransform();
240 } 189 }
241 190
242 IntSize RenderLayer::size() const 191 IntSize RenderLayer::size() const
243 { 192 {
244 if (renderer()->isInline() && renderer()->isRenderInline())
245 return toRenderInline(renderer())->linesBoundingBox().size();
246
247 // FIXME: Is snapping the size really needed here? 193 // FIXME: Is snapping the size really needed here?
248 if (RenderBox* box = renderBox()) 194 RenderBox* box = renderer();
249 return pixelSnappedIntSize(box->size(), box->location()); 195 return pixelSnappedIntSize(box->size(), box->location());
250
251 return IntSize();
252 } 196 }
253 197
254 LayoutPoint RenderLayer::location() const 198 LayoutPoint RenderLayer::location() const
255 { 199 {
256 LayoutPoint localPoint; 200 LayoutPoint localPoint;
257 LayoutSize inlineBoundingBoxOffset; // We don't put this into the RenderLaye r x/y for inlines, so we need to subtract it out when done. 201 LayoutSize inlineBoundingBoxOffset; // We don't put this into the RenderLaye r x/y for inlines, so we need to subtract it out when done.
258 202
259 if (renderer()->isInline() && renderer()->isRenderInline()) { 203 if (renderer()->isInline() && renderer()->isRenderInline()) {
260 RenderInline* inlineFlow = toRenderInline(renderer()); 204 RenderInline* inlineFlow = toRenderInline(renderer());
261 IntRect lineBox = inlineFlow->linesBoundingBox(); 205 IntRect lineBox = inlineFlow->linesBoundingBox();
262 inlineBoundingBoxOffset = toSize(lineBox.location()); 206 inlineBoundingBoxOffset = toSize(lineBox.location());
263 localPoint += inlineBoundingBoxOffset; 207 localPoint += inlineBoundingBoxOffset;
264 } else if (RenderBox* box = renderBox()) { 208 } else {
265 localPoint += box->locationOffset(); 209 localPoint += renderer()->locationOffset();
266 } 210 }
267 211
268 if (!renderer()->isOutOfFlowPositioned() && renderer()->parent()) { 212 if (!renderer()->isOutOfFlowPositioned() && renderer()->parent()) {
269 // We must adjust our position by walking up the render tree looking for the 213 // We must adjust our position by walking up the render tree looking for the
270 // nearest enclosing object with a layer. 214 // nearest enclosing object with a layer.
271 RenderObject* curr = renderer()->parent(); 215 RenderObject* curr = renderer()->parent();
272 while (curr && !curr->hasLayer()) { 216 while (curr && !curr->hasLayer()) {
273 if (curr->isBox()) { 217 if (curr->isBox()) {
274 // Rows and cells share the same coordinate space (that of the s ection). 218 // Rows and cells share the same coordinate space (that of the s ection).
275 // Omit them when computing our xpos/ypos. 219 // Omit them when computing our xpos/ypos.
276 localPoint += toRenderBox(curr)->locationOffset(); 220 localPoint += toRenderBox(curr)->locationOffset();
277 } 221 }
278 curr = curr->parent(); 222 curr = curr->parent();
279 } 223 }
280 } 224 }
281 225
282 // FIXME: We'd really like to just get rid of the concept of a layer rectang le and rely on the renderers. 226 // FIXME: We'd really like to just get rid of the concept of a layer rectang le and rely on the renderers.
283 localPoint -= inlineBoundingBoxOffset; 227 localPoint -= inlineBoundingBoxOffset;
284 228
285 return localPoint; 229 return localPoint;
286 } 230 }
287 231
288 TransformationMatrix RenderLayer::perspectiveTransform() const
289 {
290 if (!renderer()->hasTransform())
291 return TransformationMatrix();
292
293 RenderStyle* style = renderer()->style();
294 if (!style->hasPerspective())
295 return TransformationMatrix();
296
297 // Maybe fetch the perspective from the backing?
298 const IntRect borderBox = renderer()->pixelSnappedBorderBoxRect();
299 const float boxWidth = borderBox.width();
300 const float boxHeight = borderBox.height();
301
302 float perspectiveOriginX = floatValueForLength(style->perspectiveOriginX(), boxWidth);
303 float perspectiveOriginY = floatValueForLength(style->perspectiveOriginY(), boxHeight);
304
305 // A perspective origin of 0,0 makes the vanishing point in the center of th e element.
306 // We want it to be in the top-left, so subtract half the height and width.
307 perspectiveOriginX -= boxWidth / 2.0f;
308 perspectiveOriginY -= boxHeight / 2.0f;
309
310 TransformationMatrix t;
311 t.translate(perspectiveOriginX, perspectiveOriginY);
312 t.applyPerspective(style->perspective());
313 t.translate(-perspectiveOriginX, -perspectiveOriginY);
314
315 return t;
316 }
317
318 FloatPoint RenderLayer::perspectiveOrigin() const
319 {
320 if (!renderer()->hasTransform())
321 return FloatPoint();
322
323 const LayoutRect borderBox = renderer()->borderBoxRect();
324 RenderStyle* style = renderer()->style();
325
326 return FloatPoint(floatValueForLength(style->perspectiveOriginX(), borderBox .width().toFloat()), floatValueForLength(style->perspectiveOriginY(), borderBox. height().toFloat()));
327 }
328
329 RenderLayer* RenderLayer::enclosingPositionedAncestor() const 232 RenderLayer* RenderLayer::enclosingPositionedAncestor() const
330 { 233 {
331 RenderLayer* curr = parent(); 234 RenderLayer* curr = parent();
332 while (curr && !curr->isPositionedContainer()) 235 while (curr && !curr->isPositionedContainer())
333 curr = curr->parent(); 236 curr = curr->parent();
334 237
335 return curr; 238 return curr;
336 } 239 }
337 240
338 const RenderLayer* RenderLayer::compositingContainer() const 241 const RenderLayer* RenderLayer::compositingContainer() const
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 currLayer = accumulateOffsetTowardsAncestor(currLayer, ancestorLayer, lo cation); 423 currLayer = accumulateOffsetTowardsAncestor(currLayer, ancestorLayer, lo cation);
521 } 424 }
522 425
523 void RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutR ect& rect) const 426 void RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutR ect& rect) const
524 { 427 {
525 LayoutPoint delta; 428 LayoutPoint delta;
526 convertToLayerCoords(ancestorLayer, delta); 429 convertToLayerCoords(ancestorLayer, delta);
527 rect.move(-delta.x(), -delta.y()); 430 rect.move(-delta.x(), -delta.y());
528 } 431 }
529 432
530 void RenderLayer::updateStackingNode()
531 {
532 if (requiresStackingNode())
533 m_stackingNode = adoptPtr(new RenderLayerStackingNode(this));
534 else
535 m_stackingNode = nullptr;
536 }
537
538 static bool inContainingBlockChain(RenderLayer* startLayer, RenderLayer* endLaye r) 433 static bool inContainingBlockChain(RenderLayer* startLayer, RenderLayer* endLaye r)
539 { 434 {
540 if (startLayer == endLayer) 435 if (startLayer == endLayer)
541 return true; 436 return true;
542 437
543 RenderView* view = startLayer->renderer()->view(); 438 RenderView* view = startLayer->renderer()->view();
544 for (RenderBlock* currentBlock = startLayer->renderer()->containingBlock(); currentBlock && currentBlock != view; currentBlock = currentBlock->containingBlo ck()) { 439 for (RenderBlock* currentBlock = startLayer->renderer()->containingBlock(); currentBlock && currentBlock != view; currentBlock = currentBlock->containingBlo ck()) {
545 if (currentBlock->layer() == endLayer) 440 if (currentBlock->layer() == endLayer)
546 return true; 441 return true;
547 } 442 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // line boxes of all three lines (including overflow on those lines). 505 // line boxes of all three lines (including overflow on those lines).
611 // (2) Left/Top Overflow. The width/height of layers already includes right /bottom overflow. However, in the case of left/top 506 // (2) Left/Top Overflow. The width/height of layers already includes right /bottom overflow. However, in the case of left/top
612 // overflow, we have to create a bounding box that will extend to include th is overflow. 507 // overflow, we have to create a bounding box that will extend to include th is overflow.
613 // (3) Floats. When a layer has overhanging floats that it paints, we need to make sure to include these overhanging floats 508 // (3) Floats. When a layer has overhanging floats that it paints, we need to make sure to include these overhanging floats
614 // as part of our bounding box. We do this because we are the responsible l ayer for both hit testing and painting those 509 // as part of our bounding box. We do this because we are the responsible l ayer for both hit testing and painting those
615 // floats. 510 // floats.
616 LayoutRect result; 511 LayoutRect result;
617 if (renderer()->isInline() && renderer()->isRenderInline()) { 512 if (renderer()->isInline() && renderer()->isRenderInline()) {
618 result = toRenderInline(renderer())->linesVisualOverflowBoundingBox(); 513 result = toRenderInline(renderer())->linesVisualOverflowBoundingBox();
619 } else { 514 } else {
620 RenderBox* box = renderBox(); 515 RenderBox* box = renderer();
621 ASSERT(box);
622 result = box->borderBoxRect(); 516 result = box->borderBoxRect();
623 result.unite(box->visualOverflowRect()); 517 result.unite(box->visualOverflowRect());
624 } 518 }
625 519
626 ASSERT(renderer()->view()); 520 ASSERT(renderer()->view());
627 return result; 521 return result;
628 } 522 }
629 523
630 LayoutRect RenderLayer::physicalBoundingBox(const RenderLayer* ancestorLayer, co nst LayoutPoint* offsetFromRoot) const 524 LayoutRect RenderLayer::physicalBoundingBox(const RenderLayer* ancestorLayer, co nst LayoutPoint* offsetFromRoot) const
631 { 525 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 convertToLayerCoords(ancestorLayer, delta); 603 convertToLayerCoords(ancestorLayer, delta);
710 result.moveBy(delta); 604 result.moveBy(delta);
711 return result; 605 return result;
712 } 606 }
713 607
714 bool RenderLayer::shouldBeSelfPaintingLayer() const 608 bool RenderLayer::shouldBeSelfPaintingLayer() const
715 { 609 {
716 return m_layerType == NormalLayer; 610 return m_layerType == NormalLayer;
717 } 611 }
718 612
719 bool RenderLayer::hasBoxDecorationsOrBackground() const
720 {
721 return renderer()->style()->hasBoxDecorations() || renderer()->style()->hasB ackground();
722 }
723
724 bool RenderLayer::hasVisibleBoxDecorations() const
725 {
726 return hasBoxDecorationsOrBackground();
727 }
728
729 void RenderLayer::updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle) 613 void RenderLayer::updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle)
730 { 614 {
731 if (!newStyle->hasFilter() && (!oldStyle || !oldStyle->hasFilter())) 615 if (!newStyle->hasFilter() && (!oldStyle || !oldStyle->hasFilter()))
732 return; 616 return;
733 617
734 if (!hasFilter()) { 618 if (!renderer()->hasFilter()) {
735 removeFilterInfoIfNeeded(); 619 removeFilterInfoIfNeeded();
736 return; 620 return;
737 } 621 }
738 622
739 if (renderer()->style()->filter().hasReferenceFilter()) 623 if (renderer()->style()->filter().hasReferenceFilter())
740 ensureFilterInfo()->updateReferenceFilterClients(renderer()->style()->fi lter()); 624 ensureFilterInfo()->updateReferenceFilterClients(renderer()->style()->fi lter());
741 else if (hasFilterInfo()) 625 else if (hasFilterInfo())
742 filterInfo()->removeReferenceFilterClients(); 626 filterInfo()->removeReferenceFilterClients();
743 627
744 // FilterEffectRenderer is only used to render the filters in software mode, 628 // FilterEffectRenderer is only used to render the filters in software mode,
(...skipping 30 matching lines...) Expand all
775 659
776 // Overlay scrollbars can make this layer self-painting so we need 660 // Overlay scrollbars can make this layer self-painting so we need
777 // to recompute the bit once scrollbars have been updated. 661 // to recompute the bit once scrollbars have been updated.
778 m_isSelfPaintingLayer = shouldBeSelfPaintingLayer(); 662 m_isSelfPaintingLayer = shouldBeSelfPaintingLayer();
779 663
780 updateTransform(oldStyle, renderer()->style()); 664 updateTransform(oldStyle, renderer()->style());
781 updateFilters(oldStyle, renderer()->style()); 665 updateFilters(oldStyle, renderer()->style());
782 } 666 }
783 667
784 } // namespace blink 668 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderLayer.h ('k') | sky/engine/core/rendering/RenderObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698