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

Side by Side Diff: Source/core/rendering/RenderBox.cpp

Issue 16402019: Remove clips where we can show that they are unnecessary. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add TestExpectations for layout test changes due to crbug.com/249478 Created 7 years, 6 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 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 BackgroundImageGeometry geometry; 1451 BackgroundImageGeometry geometry;
1452 layerRenderer->calculateBackgroundImageGeometry(curLayer, rendererRe ct, geometry); 1452 layerRenderer->calculateBackgroundImageGeometry(curLayer, rendererRe ct, geometry);
1453 layerRenderer->repaintRectangle(geometry.destRect()); 1453 layerRenderer->repaintRectangle(geometry.destRect());
1454 if (geometry.destRect() == rendererRect) 1454 if (geometry.destRect() == rendererRect)
1455 return true; 1455 return true;
1456 } 1456 }
1457 } 1457 }
1458 return false; 1458 return false;
1459 } 1459 }
1460 1460
1461 bool RenderBox::pushContentsClip(PaintInfo& paintInfo, const LayoutPoint& accumu latedOffset) 1461 bool RenderBox::pushContentsClip(PaintInfo& paintInfo, const LayoutPoint& accumu latedOffset, const LayoutRect* visualOverflowRect)
1462 { 1462 {
1463 if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == Paint PhaseSelfOutline || paintInfo.phase == PaintPhaseMask) 1463 if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == Paint PhaseSelfOutline || paintInfo.phase == PaintPhaseMask)
1464 return false; 1464 return false;
1465 1465
1466 bool isControlClip = hasControlClip(); 1466 bool isControlClip = hasControlClip();
1467 bool isOverflowClip = hasOverflowClip() && !layer()->isSelfPaintingLayer(); 1467 bool isOverflowClip = hasOverflowClip() && !layer()->isSelfPaintingLayer();
1468 1468
1469 if (!isControlClip && !isOverflowClip) 1469 if (!isControlClip && !isOverflowClip)
1470 return false; 1470 return false;
1471 1471
1472 if (visualOverflowRect && visualOverflowRect->isEmpty())
1473 return false;
1474
1475 LayoutRect clipRect = isControlClip ? controlClipRect(accumulatedOffset) : o verflowClipRect(accumulatedOffset, paintInfo.renderRegion);
1476 RoundedRect clipRRect(0, 0, 0, 0);
1477 bool hasBorderRadius = style()->hasBorderRadius();
1478 if (hasBorderRadius)
1479 clipRRect = style()->getRoundedInnerBorderFor(LayoutRect(accumulatedOffs et, size()));
1480
1481 if (visualOverflowRect) {
1482 LayoutRect conservativeClipRect = clipRect;
1483 if (hasBorderRadius)
1484 conservativeClipRect.intersect(clipRRect.enclosedRect());
1485 conservativeClipRect.moveBy(-accumulatedOffset);
1486 if (hasLayer())
1487 conservativeClipRect.move(scrolledContentOffset());
1488 if (conservativeClipRect.contains(*visualOverflowRect))
1489 return false;
1490 }
1491
1472 if (paintInfo.phase == PaintPhaseOutline) 1492 if (paintInfo.phase == PaintPhaseOutline)
1473 paintInfo.phase = PaintPhaseChildOutlines; 1493 paintInfo.phase = PaintPhaseChildOutlines;
1474 else if (paintInfo.phase == PaintPhaseChildBlockBackground) { 1494 else if (paintInfo.phase == PaintPhaseChildBlockBackground) {
1475 paintInfo.phase = PaintPhaseBlockBackground; 1495 paintInfo.phase = PaintPhaseBlockBackground;
1476 paintObject(paintInfo, accumulatedOffset); 1496 paintObject(paintInfo, accumulatedOffset);
1477 paintInfo.phase = PaintPhaseChildBlockBackgrounds; 1497 paintInfo.phase = PaintPhaseChildBlockBackgrounds;
1478 } 1498 }
1479 IntRect clipRect = pixelSnappedIntRect(isControlClip ? controlClipRect(accum ulatedOffset) : overflowClipRect(accumulatedOffset, paintInfo.renderRegion));
1480 paintInfo.context->save(); 1499 paintInfo.context->save();
1481 if (style()->hasBorderRadius()) 1500 if (hasBorderRadius)
1482 paintInfo.context->clipRoundedRect(style()->getRoundedInnerBorderFor(Lay outRect(accumulatedOffset, size()))); 1501 paintInfo.context->clipRoundedRect(clipRRect);
1483 paintInfo.context->clip(clipRect); 1502 paintInfo.context->clip(pixelSnappedIntRect(clipRect));
1484 return true; 1503 return true;
1485 } 1504 }
1486 1505
1487 void RenderBox::popContentsClip(PaintInfo& paintInfo, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset) 1506 void RenderBox::popContentsClip(PaintInfo& paintInfo, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset)
1488 { 1507 {
1489 ASSERT(hasControlClip() || (hasOverflowClip() && !layer()->isSelfPaintingLay er())); 1508 ASSERT(hasControlClip() || (hasOverflowClip() && !layer()->isSelfPaintingLay er()));
1490 1509
1491 paintInfo.context->restore(); 1510 paintInfo.context->restore();
1492 if (originalPhase == PaintPhaseOutline) { 1511 if (originalPhase == PaintPhaseOutline) {
1493 paintInfo.phase = PaintPhaseSelfOutline; 1512 paintInfo.phase = PaintPhaseSelfOutline;
(...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 return isReplaced() || hasOverflowClip() || isHR() || isLegend() || isWritin gModeRoot() || isFlexItemIncludingDeprecated(); 4111 return isReplaced() || hasOverflowClip() || isHR() || isLegend() || isWritin gModeRoot() || isFlexItemIncludingDeprecated();
4093 } 4112 }
4094 4113
4095 void RenderBox::addVisualEffectOverflow() 4114 void RenderBox::addVisualEffectOverflow()
4096 { 4115 {
4097 if (!style()->boxShadow() && !style()->hasBorderImageOutsets()) 4116 if (!style()->boxShadow() && !style()->hasBorderImageOutsets())
4098 return; 4117 return;
4099 4118
4100 bool isFlipped = style()->isFlippedBlocksWritingMode(); 4119 bool isFlipped = style()->isFlippedBlocksWritingMode();
4101 bool isHorizontal = isHorizontalWritingMode(); 4120 bool isHorizontal = isHorizontalWritingMode();
4102 4121
4103 LayoutRect borderBox = borderBoxRect(); 4122 LayoutRect borderBox = borderBoxRect();
4104 LayoutUnit overflowMinX = borderBox.x(); 4123 LayoutUnit overflowMinX = borderBox.x();
4105 LayoutUnit overflowMaxX = borderBox.maxX(); 4124 LayoutUnit overflowMaxX = borderBox.maxX();
4106 LayoutUnit overflowMinY = borderBox.y(); 4125 LayoutUnit overflowMinY = borderBox.y();
4107 LayoutUnit overflowMaxY = borderBox.maxY(); 4126 LayoutUnit overflowMaxY = borderBox.maxY();
4108 4127
4109 // Compute box-shadow overflow first. 4128 // Compute box-shadow overflow first.
4110 if (style()->boxShadow()) { 4129 if (style()->boxShadow()) {
4111 LayoutUnit shadowLeft; 4130 LayoutUnit shadowLeft;
4112 LayoutUnit shadowRight; 4131 LayoutUnit shadowRight;
4113 LayoutUnit shadowTop; 4132 LayoutUnit shadowTop;
4114 LayoutUnit shadowBottom; 4133 LayoutUnit shadowBottom;
4115 style()->getBoxShadowExtent(shadowTop, shadowRight, shadowBottom, shadow Left); 4134 style()->getBoxShadowExtent(shadowTop, shadowRight, shadowBottom, shadow Left);
4116 4135
4117 // In flipped blocks writing modes such as vertical-rl, the physical rig ht shadow value is actually at the lower x-coordinate. 4136 // In flipped blocks writing modes such as vertical-rl, the physical rig ht shadow value is actually at the lower x-coordinate.
4118 overflowMinX = borderBox.x() + ((!isFlipped || isHorizontal) ? shadowLef t : -shadowRight); 4137 overflowMinX = borderBox.x() + ((!isFlipped || isHorizontal) ? shadowLef t : -shadowRight);
4119 overflowMaxX = borderBox.maxX() + ((!isFlipped || isHorizontal) ? shadow Right : -shadowLeft); 4138 overflowMaxX = borderBox.maxX() + ((!isFlipped || isHorizontal) ? shadow Right : -shadowLeft);
4120 overflowMinY = borderBox.y() + ((!isFlipped || !isHorizontal) ? shadowTo p : -shadowBottom); 4139 overflowMinY = borderBox.y() + ((!isFlipped || !isHorizontal) ? shadowTo p : -shadowBottom);
4121 overflowMaxY = borderBox.maxY() + ((!isFlipped || !isHorizontal) ? shado wBottom : -shadowTop); 4140 overflowMaxY = borderBox.maxY() + ((!isFlipped || !isHorizontal) ? shado wBottom : -shadowTop);
4122 } 4141 }
4123 4142
4124 // Now compute border-image-outset overflow. 4143 // Now compute border-image-outset overflow.
4125 if (style()->hasBorderImageOutsets()) { 4144 if (style()->hasBorderImageOutsets()) {
4126 LayoutBoxExtent borderOutsets = style()->borderImageOutsets(); 4145 LayoutBoxExtent borderOutsets = style()->borderImageOutsets();
4127 4146
4128 // In flipped blocks writing modes, the physical sides are inverted. For example in vertical-rl, the right 4147 // In flipped blocks writing modes, the physical sides are inverted. For example in vertical-rl, the right
4129 // border is at the lower x coordinate value. 4148 // border is at the lower x coordinate value.
4130 overflowMinX = min(overflowMinX, borderBox.x() - ((!isFlipped || isHoriz ontal) ? borderOutsets.left() : borderOutsets.right())); 4149 overflowMinX = min(overflowMinX, borderBox.x() - ((!isFlipped || isHoriz ontal) ? borderOutsets.left() : borderOutsets.right()));
4131 overflowMaxX = max(overflowMaxX, borderBox.maxX() + ((!isFlipped || isHo rizontal) ? borderOutsets.right() : borderOutsets.left())); 4150 overflowMaxX = max(overflowMaxX, borderBox.maxX() + ((!isFlipped || isHo rizontal) ? borderOutsets.right() : borderOutsets.left()));
4132 overflowMinY = min(overflowMinY, borderBox.y() - ((!isFlipped || !isHori zontal) ? borderOutsets.top() : borderOutsets.bottom())); 4151 overflowMinY = min(overflowMinY, borderBox.y() - ((!isFlipped || !isHori zontal) ? borderOutsets.top() : borderOutsets.bottom()));
4133 overflowMaxY = max(overflowMaxY, borderBox.maxY() + ((!isFlipped || !isH orizontal) ? borderOutsets.bottom() : borderOutsets.top())); 4152 overflowMaxY = max(overflowMaxY, borderBox.maxY() + ((!isFlipped || !isH orizontal) ? borderOutsets.bottom() : borderOutsets.top()));
4134 } 4153 }
4135 4154
4136 // Add in the final overflow with shadows and outsets combined. 4155 // Add in the final overflow with shadows and outsets combined.
4137 addVisualOverflow(LayoutRect(overflowMinX, overflowMinY, overflowMaxX - over flowMinX, overflowMaxY - overflowMinY)); 4156 LayoutRect visualOverflowRect(overflowMinX, overflowMinY, overflowMaxX - ove rflowMinX, overflowMaxY - overflowMinY);
4157 addVisualOverflow(visualOverflowRect, VisualOverflowNotClipped);
4138 } 4158 }
4139 4159
4140 void RenderBox::addOverflowFromChild(RenderBox* child, const LayoutSize& delta) 4160 void RenderBox::addOverflowFromChild(RenderBox* child, const LayoutSize& delta)
4141 { 4161 {
4142 // Never allow flow threads to propagate overflow up to a parent. 4162 // Never allow flow threads to propagate overflow up to a parent.
4143 if (child->isRenderFlowThread()) 4163 if (child->isRenderFlowThread())
4144 return; 4164 return;
4145 4165
4146 // Only propagate layout overflow from the child if the child isn't clipping its overflow. If it is, then 4166 // Only propagate layout overflow from the child if the child isn't clipping its overflow. If it is, then
4147 // its overflow is internal to it, and we don't care about it. layoutOverfl owRectForPropagation takes care of this 4167 // its overflow is internal to it, and we don't care about it. layoutOverfl owRectForPropagation takes care of this
4148 // and just propagates the border box rect instead. 4168 // and just propagates the border box rect instead.
4149 LayoutRect childLayoutOverflowRect = child->layoutOverflowRectForPropagation (style()); 4169 // Fixed positioned elements don't contribute to layout overflow, since they don't scroll with the content.
4150 childLayoutOverflowRect.move(delta); 4170 if (child->style()->position() != FixedPosition) {
4151 addLayoutOverflow(childLayoutOverflowRect); 4171 LayoutRect childLayoutOverflowRect = child->layoutOverflowRectForPropaga tion(style());
4152 4172 childLayoutOverflowRect.move(delta);
4173 addLayoutOverflow(childLayoutOverflowRect);
4174 }
4175
4153 // Add in visual overflow from the child. Even if the child clips its overf low, it may still 4176 // Add in visual overflow from the child. Even if the child clips its overf low, it may still
4154 // have visual overflow of its own set from box shadows or reflections. It is unnecessary to propagate this 4177 // have visual overflow of its own set from box shadows or reflections.
4155 // overflow if we are clipping our own overflow. 4178 if (child->hasSelfPaintingLayer())
4156 if (child->hasSelfPaintingLayer() || hasOverflowClip())
4157 return; 4179 return;
4158 LayoutRect childVisualOverflowRect = child->visualOverflowRectForPropagation (style()); 4180 LayoutRect childVisualOverflowRect = child->visualOverflowRectForPropagation (style());
4159 childVisualOverflowRect.move(delta); 4181 childVisualOverflowRect.move(delta);
4160 addVisualOverflow(childVisualOverflowRect); 4182 VisualOverflowClipBehavior clipBehavior = VisualOverflowClippedByContentsCli p;
4183 if (child->isOutOfFlowPositioned())
4184 clipBehavior = VisualOverflowNotClipped;
4185 addVisualOverflow(childVisualOverflowRect, clipBehavior);
4161 } 4186 }
4162 4187
4163 void RenderBox::addLayoutOverflow(const LayoutRect& rect) 4188 void RenderBox::addLayoutOverflow(const LayoutRect& rect)
4164 { 4189 {
4165 LayoutRect clientBox = clientBoxRect(); 4190 LayoutRect clientBox = clientBoxRect();
4166 if (clientBox.contains(rect) || rect.isEmpty()) 4191 if (clientBox.contains(rect) || rect.isEmpty())
4167 return; 4192 return;
4168 4193
4169 // For overflow clip objects, we don't want to propagate overflow into unrea chable areas. 4194 // For overflow clip objects, we don't want to propagate overflow into unrea chable areas.
4170 LayoutRect overflowRect(rect); 4195 LayoutRect overflowRect(rect);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4203 if (clientBox.contains(overflowRect) || overflowRect.isEmpty()) 4228 if (clientBox.contains(overflowRect) || overflowRect.isEmpty())
4204 return; 4229 return;
4205 } 4230 }
4206 4231
4207 if (!m_overflow) 4232 if (!m_overflow)
4208 m_overflow = adoptPtr(new RenderOverflow(clientBox, borderBoxRect())); 4233 m_overflow = adoptPtr(new RenderOverflow(clientBox, borderBoxRect()));
4209 4234
4210 m_overflow->addLayoutOverflow(overflowRect); 4235 m_overflow->addLayoutOverflow(overflowRect);
4211 } 4236 }
4212 4237
4213 void RenderBox::addVisualOverflow(const LayoutRect& rect) 4238 void RenderBox::addVisualOverflow(const LayoutRect& rect, VisualOverflowClipBeha vior clipBehavior)
4214 { 4239 {
4240 if (clipBehavior == VisualOverflowClippedByContentsClip && hasOverflowClip() )
4241 return;
4242
4215 LayoutRect borderBox = borderBoxRect(); 4243 LayoutRect borderBox = borderBoxRect();
4216 if (borderBox.contains(rect) || rect.isEmpty()) 4244 if (borderBox.contains(rect) || rect.isEmpty())
4217 return; 4245 return;
4218 4246
4219 if (!m_overflow) 4247 if (!m_overflow)
4220 m_overflow = adoptPtr(new RenderOverflow(clientBoxRect(), borderBox)); 4248 m_overflow = adoptPtr(new RenderOverflow(clientBoxRect(), borderBox));
4221 4249
4222 m_overflow->addVisualOverflow(rect); 4250 m_overflow->addVisualOverflow(rect);
4223 } 4251 }
4224 4252
4225 void RenderBox::clearLayoutOverflow() 4253 void RenderBox::clearLayoutOverflow()
4226 { 4254 {
4227 if (!m_overflow) 4255 if (!m_overflow)
4228 return; 4256 return;
4229 4257
4230 if (visualOverflowRect() == borderBoxRect()) { 4258 if (visualOverflowRect() == borderBoxRect()) {
4231 m_overflow.clear(); 4259 m_overflow.clear();
4232 return; 4260 return;
4233 } 4261 }
4234 4262
4235 m_overflow->setLayoutOverflow(borderBoxRect()); 4263 m_overflow->setLayoutOverflow(borderBoxRect());
4236 } 4264 }
4237 4265
4238 inline static bool percentageLogicalHeightIsResolvable(const RenderBox* box) 4266 inline static bool percentageLogicalHeightIsResolvable(const RenderBox* box)
4239 { 4267 {
4240 return RenderBox::percentageLogicalHeightIsResolvableFromBlock(box->containi ngBlock(), box->isOutOfFlowPositioned()); 4268 return RenderBox::percentageLogicalHeightIsResolvableFromBlock(box->containi ngBlock(), box->isOutOfFlowPositioned());
4241 } 4269 }
4242 4270
4243 bool RenderBox::percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool isOutOfFlowPositioned) 4271 bool RenderBox::percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool isOutOfFlowPositioned)
4244 { 4272 {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
4598 4626
4599 void RenderBox::reportStaticMembersMemoryUsage(MemoryInstrumentation* memoryInst rumentation) 4627 void RenderBox::reportStaticMembersMemoryUsage(MemoryInstrumentation* memoryInst rumentation)
4600 { 4628 {
4601 memoryInstrumentation->addRootObject(gOverrideHeightMap, WebCoreMemoryTypes: :RenderingStructures); 4629 memoryInstrumentation->addRootObject(gOverrideHeightMap, WebCoreMemoryTypes: :RenderingStructures);
4602 memoryInstrumentation->addRootObject(gOverrideWidthMap, WebCoreMemoryTypes:: RenderingStructures); 4630 memoryInstrumentation->addRootObject(gOverrideWidthMap, WebCoreMemoryTypes:: RenderingStructures);
4603 memoryInstrumentation->addRootObject(gOverrideContainingBlockLogicalHeightMa p, WebCoreMemoryTypes::RenderingStructures); 4631 memoryInstrumentation->addRootObject(gOverrideContainingBlockLogicalHeightMa p, WebCoreMemoryTypes::RenderingStructures);
4604 memoryInstrumentation->addRootObject(gOverrideContainingBlockLogicalWidthMap , WebCoreMemoryTypes::RenderingStructures); 4632 memoryInstrumentation->addRootObject(gOverrideContainingBlockLogicalWidthMap , WebCoreMemoryTypes::RenderingStructures);
4605 } 4633 }
4606 4634
4607 } // namespace WebCore 4635 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698