OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "core/rendering/RenderLazyBlock.h" |
| 33 |
| 34 #include "core/dom/ClientRect.h" |
| 35 #include "core/rendering/LayoutRepainter.h" |
| 36 #include "core/rendering/RenderLayer.h" |
| 37 #include "core/rendering/RenderView.h" |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 RenderLazyBlock::RenderLazyBlock(Element* element) |
| 42 : RenderBlock(element) |
| 43 , m_next(0) |
| 44 , m_previous(0) |
| 45 , m_firstVisibleChildBox(0) |
| 46 , m_lastVisibleChildBox(0) |
| 47 , m_attached(false) |
| 48 , m_isNestedLayout(false) |
| 49 { |
| 50 setChildrenInline(false); // All of our children must be block-level. |
| 51 } |
| 52 |
| 53 RenderLazyBlock::~RenderLazyBlock() |
| 54 { |
| 55 ASSERT(!m_attached); |
| 56 } |
| 57 |
| 58 void RenderLazyBlock::willBeDestroyed() |
| 59 { |
| 60 detachLazyBlock(); |
| 61 RenderBlock::willBeDestroyed(); |
| 62 } |
| 63 |
| 64 void RenderLazyBlock::willBeRemovedFromTree() |
| 65 { |
| 66 RenderBlock::willBeRemovedFromTree(); |
| 67 detachLazyBlock(); |
| 68 } |
| 69 |
| 70 bool RenderLazyBlock::isNested() const |
| 71 { |
| 72 for (RenderObject* ancestor = parent(); ancestor; ancestor = ancestor->paren
t()) { |
| 73 if (ancestor->isRenderLazyBlock()) |
| 74 return true; |
| 75 } |
| 76 return false; |
| 77 } |
| 78 |
| 79 // FIXME: This method and detachLazyBlock are essentially identical to |
| 80 // RenderQuote::attachQuote and detachQuote. We should just have a |
| 81 // RenderTreeOrderedList that does this stuff internally. |
| 82 void RenderLazyBlock::attachLazyBlock() |
| 83 { |
| 84 ASSERT(view()); |
| 85 ASSERT(!m_attached); |
| 86 ASSERT(!m_next && !m_previous); |
| 87 ASSERT(isRooted()); |
| 88 |
| 89 if (!view()->firstLazyBlock()) { |
| 90 view()->setFirstLazyBlock(this); |
| 91 m_attached = true; |
| 92 return; |
| 93 } |
| 94 |
| 95 for (RenderObject* predecessor = previousInPreOrder(); predecessor; predeces
sor = predecessor->previousInPreOrder()) { |
| 96 if (!predecessor->isRenderLazyBlock() || !toRenderLazyBlock(predecessor)
->isAttached()) |
| 97 continue; |
| 98 m_previous = toRenderLazyBlock(predecessor); |
| 99 m_next = m_previous->m_next; |
| 100 m_previous->m_next = this; |
| 101 if (m_next) |
| 102 m_next->m_previous = this; |
| 103 break; |
| 104 } |
| 105 |
| 106 if (!m_previous) { |
| 107 m_next = view()->firstLazyBlock(); |
| 108 view()->setFirstLazyBlock(this); |
| 109 if (m_next) |
| 110 m_next->m_previous = this; |
| 111 } |
| 112 m_attached = true; |
| 113 |
| 114 ASSERT(!m_next || m_next->m_attached); |
| 115 ASSERT(!m_next || m_next->m_previous == this); |
| 116 ASSERT(!m_previous || m_previous->m_attached); |
| 117 ASSERT(!m_previous || m_previous->m_next == this); |
| 118 } |
| 119 |
| 120 void RenderLazyBlock::detachLazyBlock() |
| 121 { |
| 122 ASSERT(!m_next || m_next->m_attached); |
| 123 ASSERT(!m_previous || m_previous->m_attached); |
| 124 if (!m_attached) |
| 125 return; |
| 126 if (m_previous) |
| 127 m_previous->m_next = m_next; |
| 128 else if (view()) |
| 129 view()->setFirstLazyBlock(m_next); |
| 130 if (m_next) |
| 131 m_next->m_previous = m_previous; |
| 132 m_attached = false; |
| 133 m_next = 0; |
| 134 m_previous = 0; |
| 135 } |
| 136 |
| 137 void RenderLazyBlock::paintChildren(PaintInfo& paintInfo, const LayoutPoint& pai
ntOffset, PaintInfo& paintInfoForChild, bool usePrintRect) |
| 138 { |
| 139 for (RenderBox* child = m_firstVisibleChildBox; child && child != m_lastVisi
bleChildBox; child = child->nextSiblingBox()) { |
| 140 if (!paintChild(child, paintInfo, paintOffset, paintInfoForChild, usePri
ntRect)) |
| 141 return; |
| 142 } |
| 143 } |
| 144 |
| 145 void RenderLazyBlock::layoutChildren(bool relayoutChildren) |
| 146 { |
| 147 LayoutUnit afterEdge = borderAfter() + paddingAfter() + scrollbarLogicalHeig
ht(); |
| 148 LayoutUnit height = borderBefore() + paddingBefore(); |
| 149 LayoutRect intersectRect = m_intersectRect; |
| 150 |
| 151 // FIXME: If we already have m_firstVisibleChildBox we should start there |
| 152 // and stop when we have enough to fill the viewport. This catches the most |
| 153 // common cases of scrolling upward or downward. |
| 154 |
| 155 m_firstVisibleChildBox = 0; |
| 156 m_lastVisibleChildBox = 0; |
| 157 |
| 158 // FIXME: This should approximate the height so we don't actually need to wa
lk |
| 159 // every child and can optimistically layout children until we fill the |
| 160 // the expandedViewportRect. |
| 161 |
| 162 setLogicalHeight(height); |
| 163 int childCount = 0; |
| 164 LayoutUnit heightOfChildren = 0; |
| 165 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
| 166 ++childCount; |
| 167 updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); |
| 168 |
| 169 if (relayoutChildren) |
| 170 child->setNeedsLayout(true, MarkOnlyThis); |
| 171 |
| 172 if (child->style()->logicalHeight().isSpecified()) { |
| 173 LogicalExtentComputedValues computedValues; |
| 174 child->computeLogicalHeight(-1, height, computedValues); |
| 175 child->setLogicalHeight(computedValues.m_extent); |
| 176 heightOfChildren += computedValues.m_extent; |
| 177 } else { |
| 178 // FIXME: Enable guessing about height so we don't need to do layout |
| 179 // on every non fixed height child. |
| 180 setLogicalHeight(height); |
| 181 setLogicalTopForChild(child, height); |
| 182 if (heightOfChildren && child->needsLayout()) |
| 183 child->setLogicalHeight(heightOfChildren / childCount); |
| 184 else |
| 185 child->layoutIfNeeded(); |
| 186 heightOfChildren += child->logicalHeight(); |
| 187 } |
| 188 |
| 189 intersectRect.setHeight(child->logicalHeight()); |
| 190 |
| 191 if (m_expandedViewportRect.intersects(enclosingIntRect(intersectRect)))
{ |
| 192 if (!m_firstVisibleChildBox) |
| 193 m_firstVisibleChildBox = child; |
| 194 m_lastVisibleChildBox = child->nextSiblingBox(); |
| 195 setLogicalHeight(height); |
| 196 setLogicalTopForChild(child, height); |
| 197 child->layoutIfNeeded(); |
| 198 // FIXME: Track how far off our estimated height is from the actual
height, |
| 199 // and adjust the scrollbars accordingly. |
| 200 } |
| 201 |
| 202 intersectRect.setY(intersectRect.y() + child->logicalHeight()); |
| 203 height += child->logicalHeight(); |
| 204 } |
| 205 |
| 206 setLogicalHeight(height + afterEdge); |
| 207 |
| 208 updateLogicalHeight(); |
| 209 } |
| 210 |
| 211 void RenderLazyBlock::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalH
eight) |
| 212 { |
| 213 ASSERT(needsLayout()); |
| 214 |
| 215 if (!m_attached) |
| 216 attachLazyBlock(); |
| 217 |
| 218 // FIXME: We should adjust the style to disallow columns too. |
| 219 ASSERT(!hasColumns()); |
| 220 |
| 221 LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); |
| 222 LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransfo
rm() || hasReflection() || style()->isFlippedBlocksWritingMode()); |
| 223 |
| 224 // FIXME: The compositor can instead give us a list of rects it thinks |
| 225 // are important. |
| 226 IntRect expandedViewportRect = view()->frameView()->visibleContentRect(Scrol
lableArea::IncludeScrollbars); |
| 227 expandedViewportRect.move(-4000, -4000); |
| 228 expandedViewportRect.expand(8000, 8000); |
| 229 |
| 230 // FIXME: We probably want a RenderGeometryMap instead since we need to hand
le |
| 231 // rotation of the RenderLazyBlock and other transforms. |
| 232 Vector<FloatQuad> quads; |
| 233 enclosingBoxModelObject()->absoluteQuads(quads); |
| 234 LayoutRect intersectRect = quads[0].enclosingBoundingBox(); |
| 235 if (hasOverflowClip()) |
| 236 intersectRect.move(-scrolledContentOffset()); |
| 237 |
| 238 // Avoid doing work inside the nested layout if we know everything is correc
t already. |
| 239 if (!m_isNestedLayout || m_intersectRect != intersectRect || m_expandedViewp
ortRect != expandedViewportRect) { |
| 240 m_intersectRect = intersectRect; |
| 241 m_expandedViewportRect = expandedViewportRect; |
| 242 layoutChildren(relayoutChildren || updateLogicalWidthAndColumnWidth()); |
| 243 } |
| 244 |
| 245 statePusher.pop(); |
| 246 updateLayerTransform(); |
| 247 updateScrollInfoAfterLayout(); |
| 248 repainter.repaintAfterLayout(); |
| 249 |
| 250 m_isNestedLayout = false; |
| 251 setNeedsLayout(false); |
| 252 } |
| 253 |
| 254 } // namespace WebCore |
OLD | NEW |