1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef RenderBox_h 24 #define RenderBox_h 25 26 #include "core/rendering/RenderBoxModelObject.h" 27 #include "core/rendering/RenderOverflow.h" 28 #include "core/rendering/shapes/ShapeOutsideInfo.h" 29 #include "platform/scroll/ScrollTypes.h" 30 31 namespace blink { 32 33 struct PaintInfo; 34 35 enum SizeType { MainOrPreferredSize, MinSize, MaxSize }; 36 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding }; 37 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize }; 38 enum MarginDirection { BlockDirection, InlineDirection }; 39 40 enum ShouldComputePreferred { ComputeActual, ComputePreferred }; 41 42 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible }; 43 44 enum ScrollOffsetClamping { 45 ScrollOffsetUnclamped, 46 ScrollOffsetClamped 47 }; 48 49 struct RenderBoxRareData { 50 WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED; 51 public: 52 RenderBoxRareData() 53 : m_inlineBoxWrapper(0) 54 , m_overrideLogicalContentHeight(-1) 55 , m_overrideLogicalContentWidth(-1) 56 , m_previousBorderBoxSize(-1, -1) 57 { 58 } 59 60 // For inline replaced elements, the inline box that owns us. 61 InlineBox* m_inlineBoxWrapper; 62 63 LayoutUnit m_overrideLogicalContentHeight; 64 LayoutUnit m_overrideLogicalContentWidth; 65 66 // Set by RenderBox::updatePreviousBorderBoxSizeIfNeeded(). 67 LayoutSize m_previousBorderBoxSize; 68 }; 69 70 class RenderBox : public RenderBoxModelObject { 71 public: 72 explicit RenderBox(ContainerNode*); 73 74 // hasAutoZIndex only returns true if the element is positioned or a flex-item since 75 // position:static elements that are not flex-items get their z-index coerced to auto. 76 virtual LayerType layerTypeRequired() const OVERRIDE 77 { 78 if (isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations()) 79 return NormalLayer; 80 if (hasOverflowClip()) 81 return OverflowClipLayer; 82 83 return NoLayer; 84 } 85 86 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE; 87 88 // Use this with caution! No type checking is done! 89 RenderBox* firstChildBox() const; 90 RenderBox* lastChildBox() const; 91 92 LayoutUnit x() const { return m_frameRect.x(); } 93 LayoutUnit y() const { return m_frameRect.y(); } 94 LayoutUnit width() const { return m_frameRect.width(); } 95 LayoutUnit height() const { return m_frameRect.height(); } 96 97 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); } 98 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); } 99 100 // These represent your location relative to your container as a physical offset. 101 // In layout related methods you almost always want the logical location (e.g. x() and y()). 102 LayoutUnit top() const { return topLeftLocation().y(); } 103 LayoutUnit left() const { return topLeftLocation().x(); } 104 105 void setX(LayoutUnit x) { m_frameRect.setX(x); } 106 void setY(LayoutUnit y) { m_frameRect.setY(y); } 107 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); } 108 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); } 109 110 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); } 111 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); } 112 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); } 113 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); } 114 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); } 115 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); } 116 117 LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const; 118 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const; 119 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const; 120 121 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); } 122 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); } 123 124 void setLogicalLeft(LayoutUnit left) 125 { 126 if (style()->isHorizontalWritingMode()) 127 setX(left); 128 else 129 setY(left); 130 } 131 void setLogicalTop(LayoutUnit top) 132 { 133 if (style()->isHorizontalWritingMode()) 134 setY(top); 135 else 136 setX(top); 137 } 138 void setLogicalLocation(const LayoutPoint& location) 139 { 140 if (style()->isHorizontalWritingMode()) 141 setLocation(location); 142 else 143 setLocation(location.transposedPoint()); 144 } 145 void setLogicalWidth(LayoutUnit size) 146 { 147 if (style()->isHorizontalWritingMode()) 148 setWidth(size); 149 else 150 setHeight(size); 151 } 152 void setLogicalHeight(LayoutUnit size) 153 { 154 if (style()->isHorizontalWritingMode()) 155 setHeight(size); 156 else 157 setWidth(size); 158 } 159 void setLogicalSize(const LayoutSize& size) 160 { 161 if (style()->isHorizontalWritingMode()) 162 setSize(size); 163 else 164 setSize(size.transposedSize()); 165 } 166 167 LayoutPoint location() const { return m_frameRect.location(); } 168 LayoutSize locationOffset() const { return LayoutSize(x(), y()); } 169 LayoutSize size() const { return m_frameRect.size(); } 170 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); } 171 172 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); } 173 174 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); } 175 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); } 176 177 LayoutRect frameRect() const { return m_frameRect; } 178 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); } 179 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; } 180 181 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); } 182 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); } 183 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); } 184 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); } 185 186 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border). 187 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); } 188 // The content box in absolute coords. Ignores transforms. 189 IntRect absoluteContentBox() const; 190 // The content box converted to absolute coords (taking transforms into account). 191 FloatQuad absoluteContentQuad() const; 192 193 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect 194 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle). 195 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); } 196 197 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const OVERRIDE; 198 199 // Use this with caution! No type checking is done! 200 RenderBox* previousSiblingBox() const; 201 RenderBox* nextSiblingBox() const; 202 RenderBox* parentBox() const; 203 204 bool canResize() const; 205 206 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions. 207 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right 208 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr, 209 // but it is on the right in vertical-rl. 210 LayoutRect noOverflowRect() const; 211 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); } 212 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); } 213 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); } 214 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); } 215 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); } 216 217 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); } 218 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); } 219 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); } 220 221 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); } 222 223 void addLayoutOverflow(const LayoutRect&); 224 void addVisualOverflow(const LayoutRect&); 225 226 // Clipped by the contents clip, if one exists. 227 void addContentsVisualOverflow(const LayoutRect&); 228 229 void addVisualEffectOverflow(); 230 LayoutBoxExtent computeVisualEffectOverflowExtent() const; 231 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); } 232 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta); 233 void clearLayoutOverflow(); 234 void clearAllOverflows() { m_overflow.clear(); } 235 236 void updateLayerTransformAfterLayout(); 237 238 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); } 239 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); } 240 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); } 241 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); } 242 243 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow) 244 // to return the remaining width on a given line (and the height of a single line). 245 virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); } 246 virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); } 247 248 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL; 249 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL; 250 251 // More IE extensions. clientWidth and clientHeight represent the interior of an object 252 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth. 253 LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); } 254 LayoutUnit clientTop() const { return borderTop(); } 255 LayoutUnit clientWidth() const; 256 LayoutUnit clientHeight() const; 257 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); } 258 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); } 259 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); } 260 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); } 261 262 int pixelSnappedClientWidth() const; 263 int pixelSnappedClientHeight() const; 264 265 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the 266 // object has overflow:hidden/scroll/auto specified and also has overflow. 267 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like 268 // textareas can scroll shadow content (but pretend that they are the objects that are 269 // scrolling). 270 virtual LayoutUnit scrollLeft() const; 271 virtual LayoutUnit scrollTop() const; 272 virtual LayoutUnit scrollWidth() const; 273 virtual LayoutUnit scrollHeight() const; 274 int pixelSnappedScrollWidth() const; 275 int pixelSnappedScrollHeight() const; 276 virtual void setScrollLeft(LayoutUnit); 277 virtual void setScrollTop(LayoutUnit); 278 279 void scrollToOffset(const IntSize&); 280 void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped); 281 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY); 282 283 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); } 284 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); } 285 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); } 286 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); } 287 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); } 288 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); } 289 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); } 290 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); } 291 292 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); } 293 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); } 294 295 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); } 296 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); } 297 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL 298 { 299 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style(); 300 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction()); 301 } 302 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL 303 { 304 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style(); 305 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction()); 306 } 307 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); } 308 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); } 309 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0) 310 { 311 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style(); 312 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value); 313 } 314 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0) 315 { 316 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style(); 317 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value); 318 } 319 320 // The following functions are used to implement collapsing margins. 321 // All objects know their maximal positive and negative margins. The 322 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|. 323 // For a non-collapsing box, such as a leaf element, this formula will simply return 324 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter 325 // methods. 326 virtual bool isSelfCollapsingBlock() const { return false; } 327 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); } 328 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); } 329 330 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE; 331 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE; 332 333 int reflectionOffset() const; 334 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection. 335 LayoutRect reflectedRect(const LayoutRect&) const; 336 337 virtual void layout() OVERRIDE; 338 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE; 339 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE; 340 341 virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE; 342 virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE; 343 344 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store 345 // the border-box height/width like the regular height/width accessors on RenderBox. 346 // Right now, these are different than contentHeight/contentWidth because they still 347 // include the scrollbar height/width. 348 LayoutUnit overrideLogicalContentWidth() const; 349 LayoutUnit overrideLogicalContentHeight() const; 350 bool hasOverrideHeight() const; 351 bool hasOverrideWidth() const; 352 void setOverrideLogicalContentHeight(LayoutUnit); 353 void setOverrideLogicalContentWidth(LayoutUnit); 354 void clearOverrideSize(); 355 void clearOverrideLogicalContentHeight(); 356 void clearOverrideLogicalContentWidth(); 357 358 LayoutUnit overrideContainingBlockContentLogicalWidth() const; 359 LayoutUnit overrideContainingBlockContentLogicalHeight() const; 360 bool hasOverrideContainingBlockLogicalWidth() const; 361 bool hasOverrideContainingBlockLogicalHeight() const; 362 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit); 363 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit); 364 void clearContainingBlockOverrideSize(); 365 void clearOverrideContainingBlockContentLogicalHeight(); 366 367 virtual LayoutSize offsetFromContainer(const RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE; 368 369 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const; 370 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const; 371 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const; 372 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const; 373 374 struct ComputedMarginValues { 375 ComputedMarginValues() { } 376 377 LayoutUnit m_before; 378 LayoutUnit m_after; 379 LayoutUnit m_start; 380 LayoutUnit m_end; 381 }; 382 struct LogicalExtentComputedValues { 383 LogicalExtentComputedValues() { } 384 385 LayoutUnit m_extent; 386 LayoutUnit m_position; 387 ComputedMarginValues m_margins; 388 }; 389 // Resolve auto margins in the chosen direction of the containing block so that objects can be pushed to the start, middle or end 390 // of the containing block. 391 void computeMarginsForDirection(MarginDirection forDirection, const RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd, Length marginStartLength, Length marginStartEnd) const; 392 393 // Used to resolve margins in the containing block's block-flow direction. 394 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock); 395 396 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const; 397 398 void positionLineBox(InlineBox*); 399 void moveWithEdgeOfInlineContainerIfNecessary(bool isHorizontal); 400 401 virtual InlineBox* createInlineBox(); 402 void dirtyLineBoxes(bool fullLayout); 403 404 // For inline replaced elements, this function returns the inline box that owns us. Enables 405 // the replaced RenderObject to quickly determine what line it is contained on and to easily 406 // iterate over structures on the line. 407 InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; } 408 void setInlineBoxWrapper(InlineBox*); 409 void deleteLineBoxWrapper(); 410 411 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const OVERRIDE; 412 virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const OVERRIDE; 413 virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants); 414 415 virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE; 416 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const; 417 418 LayoutUnit containingBlockAvailableLineWidth() const; 419 LayoutUnit perpendicularContainingBlockLogicalHeight() const; 420 421 virtual void updateLogicalWidth(); 422 virtual void updateLogicalHeight(); 423 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const; 424 425 void computeLogicalWidth(LogicalExtentComputedValues&) const; 426 427 bool stretchesToViewport() const 428 { 429 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline(); 430 } 431 432 virtual LayoutSize intrinsicSize() const { return LayoutSize(); } 433 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); } 434 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); } 435 virtual LayoutUnit intrinsicContentLogicalHeight() const { return m_intrinsicContentLogicalHeight; } 436 437 // Whether or not the element shrinks to its intrinsic width (rather than filling the width 438 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this. 439 bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const; 440 441 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const; 442 443 LayoutUnit computeLogicalWidthUsing(SizeType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const; 444 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const; 445 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const; 446 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const; 447 LayoutUnit computeReplacedLogicalWidthUsing(const Length& width) const; 448 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const; 449 LayoutUnit computeReplacedLogicalHeightUsing(const Length& height) const; 450 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const; 451 452 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const; 453 virtual LayoutUnit computeReplacedLogicalHeight() const; 454 455 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned); 456 LayoutUnit computePercentageLogicalHeight(const Length& height) const; 457 458 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.) 459 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); } 460 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const; 461 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const; 462 463 // There are a few cases where we need to refer specifically to the available physical width and available physical height. 464 // Relative positioning is one of those cases, since left/top offsets are physical. 465 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); } 466 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); } 467 468 virtual int verticalScrollbarWidth() const; 469 int horizontalScrollbarHeight() const; 470 int instrinsicScrollbarLogicalWidth() const; 471 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); } 472 virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1); 473 bool canBeScrolledAndHasScrollableArea() const; 474 virtual bool canBeProgramaticallyScrolled() const; 475 virtual void autoscroll(const IntPoint&); 476 bool autoscrollInProgress() const; 477 bool canAutoscroll() const; 478 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const; 479 static RenderBox* findAutoscrollable(RenderObject*); 480 virtual void stopAutoscroll() { } 481 virtual void panScroll(const IntPoint&); 482 483 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); } 484 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); } 485 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); } 486 487 bool hasScrollableOverflowX() const { return scrollsOverflowX() && pixelSnappedScrollWidth() != pixelSnappedClientWidth(); } 488 bool hasScrollableOverflowY() const { return scrollsOverflowY() && pixelSnappedScrollHeight() != pixelSnappedClientHeight(); } 489 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); } 490 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); } 491 bool usesCompositedScrolling() const; 492 493 // Elements such as the <input> field override this to specify that they are scrollable 494 // outside the context of the CSS overflow style 495 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; } 496 497 bool hasUnsplittableScrollingOverflow() const; 498 bool isUnsplittableForPagination() const; 499 500 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE; 501 502 virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize); 503 LayoutRect clipRect(const LayoutPoint& location); 504 virtual bool hasControlClip() const { return false; } 505 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); } 506 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior); 507 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset); 508 509 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); } 510 virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&); 511 virtual void paintMask(PaintInfo&, const LayoutPoint&); 512 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&); 513 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE; 514 515 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted 516 // that just updates the object's position. If the size does change, the object remains dirty. 517 bool tryLayoutDoingPositionedMovementOnly() 518 { 519 LayoutUnit oldWidth = width(); 520 updateLogicalWidth(); 521 // If we shrink to fit our width may have changed, so we still need full layout. 522 if (oldWidth != width()) 523 return false; 524 updateLogicalHeight(); 525 return true; 526 } 527 528 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE; 529 530 void removeFloatingOrPositionedChildFromBlockLists(); 531 532 RenderLayer* enclosingFloatPaintingLayer() const; 533 534 virtual int firstLineBoxBaseline() const { return -1; } 535 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block. 536 537 bool shrinkToAvoidFloats() const; 538 virtual bool avoidsFloats() const; 539 540 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&); 541 542 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); } 543 544 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); } 545 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); } 546 547 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE; 548 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE; 549 550 virtual LayoutUnit offsetLeft() const OVERRIDE; 551 virtual LayoutUnit offsetTop() const OVERRIDE; 552 553 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const; 554 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes). 555 LayoutPoint flipForWritingMode(const LayoutPoint&) const; 556 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const; 557 LayoutSize flipForWritingMode(const LayoutSize&) const; 558 void flipForWritingMode(LayoutRect&) const; 559 FloatPoint flipForWritingMode(const FloatPoint&) const; 560 void flipForWritingMode(FloatRect&) const; 561 // These represent your location relative to your container as a physical offset. 562 // In layout related methods you almost always want the logical location (e.g. x() and y()). 563 LayoutPoint topLeftLocation() const; 564 LayoutSize topLeftLocationOffset() const; 565 566 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const; 567 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const; 568 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const; 569 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const; 570 571 bool hasRenderOverflow() const { return m_overflow; } 572 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); } 573 574 virtual bool needsPreferredWidthsRecalculation() const; 575 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { } 576 577 IntSize scrolledContentOffset() const; 578 void applyCachedClipAndScrollOffsetForPaintInvalidation(LayoutRect& paintRect) const; 579 580 virtual bool hasRelativeLogicalHeight() const; 581 582 bool hasHorizontalLayoutOverflow() const 583 { 584 if (!m_overflow) 585 return false; 586 587 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect(); 588 LayoutRect noOverflowRect = this->noOverflowRect(); 589 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX(); 590 } 591 592 bool hasVerticalLayoutOverflow() const 593 { 594 if (!m_overflow) 595 return false; 596 597 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect(); 598 LayoutRect noOverflowRect = this->noOverflowRect(); 599 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY(); 600 } 601 602 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const 603 { 604 ASSERT_NOT_REACHED(); 605 return 0; 606 } 607 608 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); } 609 610 ShapeOutsideInfo* shapeOutsideInfo() const 611 { 612 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0; 613 } 614 615 void markShapeOutsideDependentsForLayout() 616 { 617 if (isFloating()) 618 removeFloatingOrPositionedChildFromBlockLists(); 619 } 620 621 bool backgroundHasOpaqueTopLayer() const; 622 623 void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; } 624 protected: 625 virtual void willBeDestroyed() OVERRIDE; 626 627 628 virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) OVERRIDE; 629 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE; 630 virtual void updateFromStyle() OVERRIDE; 631 632 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect. 633 // FIXME: make this a const method once the RenderBox reference in BoxPainter is const. 634 bool getBackgroundPaintedExtent(LayoutRect&); 635 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const; 636 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE; 637 638 void computePositionedLogicalWidth(LogicalExtentComputedValues&) const; 639 640 LayoutUnit computeIntrinsicLogicalWidthUsing(const Length& logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const; 641 LayoutUnit computeIntrinsicLogicalContentHeightUsing(const Length& logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const; 642 643 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); } 644 645 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const OVERRIDE; 646 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE; 647 648 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild); 649 650 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE; 651 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE; 652 653 virtual InvalidationReason getPaintInvalidationReason(const RenderLayerModelObject& paintInvalidationContainer, 654 const LayoutRect& oldBounds, const LayoutPoint& oldPositionFromPaintInvalidationContainer, 655 const LayoutRect& newBounds, const LayoutPoint& newPositionFromPaintInvalidationContainer) OVERRIDE; 656 virtual void incrementallyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect& oldBounds, const LayoutRect& newBounds, const LayoutPoint& positionFromPaintInvalidationContainer) OVERRIDE; 657 658 virtual void clearPaintInvalidationState(const PaintInvalidationState&) OVERRIDE; 659 #if ENABLE(ASSERT) 660 virtual bool paintInvalidationStateIsDirty() const OVERRIDE; 661 #endif 662 663 private: 664 void invalidatePaintRectClippedByOldAndNewBounds(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect&, const LayoutRect& oldBounds, const LayoutRect& newBounds); 665 666 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle); 667 void updateGridPositionAfterStyleChange(const RenderStyle*); 668 669 bool autoWidthShouldFitContent() const; 670 void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const; 671 672 // Returns true if we queued up a paint invalidation. 673 bool paintInvalidationLayerRectsForImage(WrappedImagePtr, const FillLayer&, bool drawingBackground); 674 675 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const; 676 677 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const; 678 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const; 679 680 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const; 681 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection, 682 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding, 683 const Length& logicalLeft, const Length& logicalRight, const Length& marginLogicalLeft, 684 const Length& marginLogicalRight, LogicalExtentComputedValues&) const; 685 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock, 686 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight, 687 const Length& logicalTop, const Length& logicalBottom, const Length& marginLogicalTop, 688 const Length& marginLogicalBottom, LogicalExtentComputedValues&) const; 689 690 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const; 691 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const; 692 693 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const; 694 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const; 695 696 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const; 697 698 // This function calculates the minimum and maximum preferred widths for an object. 699 // These values are used in shrink-to-fit layout systems. 700 // These include tables, positioned objects, floats and flexible boxes. 701 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); } 702 703 RenderBoxRareData& ensureRareData() 704 { 705 if (!m_rareData) 706 m_rareData = adoptPtr(new RenderBoxRareData()); 707 return *m_rareData.get(); 708 } 709 710 void savePreviousBorderBoxSizeIfNeeded(); 711 LayoutSize computePreviousBorderBoxSize(const LayoutSize& previousBoundsSize) const; 712 713 bool logicalHeightComputesAsNone(SizeType) const; 714 715 virtual InvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& newPaintInvalidationContainer) OVERRIDE FINAL; 716 717 bool isBox() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check. 718 719 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent). 720 LayoutRect m_frameRect; 721 722 // Our intrinsic height, used for min-height: min-content etc. Maintained by 723 // updateLogicalHeight. This is logicalHeight() before it is clamped to 724 // min/max. 725 mutable LayoutUnit m_intrinsicContentLogicalHeight; 726 727 void inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect&) const; 728 729 protected: 730 LayoutBoxExtent m_marginBox; 731 732 // The preferred logical width of the element if it were to break its lines at every possible opportunity. 733 LayoutUnit m_minPreferredLogicalWidth; 734 735 // The preferred logical width of the element if it never breaks any lines at all. 736 LayoutUnit m_maxPreferredLogicalWidth; 737 738 // Our overflow information. 739 OwnPtr<RenderOverflow> m_overflow; 740 741 private: 742 OwnPtr<RenderBoxRareData> m_rareData; 743 }; 744 745 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox()); 746 747 inline RenderBox* RenderBox::previousSiblingBox() const 748 { 749 return toRenderBox(previousSibling()); 750 } 751 752 inline RenderBox* RenderBox::nextSiblingBox() const 753 { 754 return toRenderBox(nextSibling()); 755 } 756 757 inline RenderBox* RenderBox::parentBox() const 758 { 759 return toRenderBox(parent()); 760 } 761 762 inline RenderBox* RenderBox::firstChildBox() const 763 { 764 return toRenderBox(slowFirstChild()); 765 } 766 767 inline RenderBox* RenderBox::lastChildBox() const 768 { 769 return toRenderBox(slowLastChild()); 770 } 771 772 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper) 773 { 774 if (boxWrapper) { 775 ASSERT(!inlineBoxWrapper()); 776 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues. 777 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and 778 // only one will be notified when the renderer is getting destroyed. The second line box wrapper 779 // will keep a stale reference. 780 if (UNLIKELY(inlineBoxWrapper() != 0)) 781 deleteLineBoxWrapper(); 782 } 783 784 ensureRareData().m_inlineBoxWrapper = boxWrapper; 785 } 786 787 } // namespace blink 788 789 #endif // RenderBox_h 790