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