Make computeBlockDirectionMargins const
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Sep 2012 01:00:10 +0000 (01:00 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Sep 2012 01:00:10 +0000 (01:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95595

Reviewed by Ojan Vafai.

This is a step in making computeLogicalHeight const.
Refactor RenderBox::computeBlockDirectionMargins and make it const.
Add a helper method computeAndSetBlockDirectionMargins for the callers outside of
computeLogicalHeight that are calling this.

No new tests, this is already covered by tests in fast/writing-mode and fast/multicol.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::marginBeforeEstimateForChild): Switch to computeAndSetBlockDirectionMargins
(WebCore::RenderBlock::layoutBlockChild): Switch to computeAndSetBlockDirectionMargins
(WebCore::RenderBlock::insertFloatingObject): Switch to computeAndSetBlockDirectionMargins
* rendering/RenderBox.cpp:
(WebCore::RenderBox::computeLogicalHeight): Use const version and fill in a MarginValues struct (to be merged in the next patch).
(WebCore::RenderBox::computeBlockDirectionMargins): Pass in out params.
(WebCore):
(WebCore::RenderBox::computeAndSetBlockDirectionMargins): Does the same as the old computeBlockDirectionMargins.
* rendering/RenderBox.h:
(RenderBox):
* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::RenderDeprecatedFlexibleBox::layoutHorizontalBox): Switch to computeAndSetBlockDirectionMargins
(WebCore::RenderDeprecatedFlexibleBox::layoutVerticalBox): Switch to computeAndSetBlockDirectionMargins
* rendering/RenderTableRow.cpp:
(WebCore::RenderTableRow::layout): Switch to computeAndSetBlockDirectionMargins

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@127346 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
Source/WebCore/rendering/RenderTableRow.cpp

index 784cf6d..a646941 100644 (file)
@@ -1,3 +1,34 @@
+2012-08-31  Tony Chang  <tony@chromium.org>
+
+        Make computeBlockDirectionMargins const
+        https://bugs.webkit.org/show_bug.cgi?id=95595
+
+        Reviewed by Ojan Vafai.
+
+        This is a step in making computeLogicalHeight const.
+        Refactor RenderBox::computeBlockDirectionMargins and make it const.
+        Add a helper method computeAndSetBlockDirectionMargins for the callers outside of
+        computeLogicalHeight that are calling this.
+
+        No new tests, this is already covered by tests in fast/writing-mode and fast/multicol.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::marginBeforeEstimateForChild): Switch to computeAndSetBlockDirectionMargins
+        (WebCore::RenderBlock::layoutBlockChild): Switch to computeAndSetBlockDirectionMargins
+        (WebCore::RenderBlock::insertFloatingObject): Switch to computeAndSetBlockDirectionMargins
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::computeLogicalHeight): Use const version and fill in a MarginValues struct (to be merged in the next patch).
+        (WebCore::RenderBox::computeBlockDirectionMargins): Pass in out params.
+        (WebCore):
+        (WebCore::RenderBox::computeAndSetBlockDirectionMargins): Does the same as the old computeBlockDirectionMargins.
+        * rendering/RenderBox.h:
+        (RenderBox):
+        * rendering/RenderDeprecatedFlexibleBox.cpp:
+        (WebCore::RenderDeprecatedFlexibleBox::layoutHorizontalBox): Switch to computeAndSetBlockDirectionMargins
+        (WebCore::RenderDeprecatedFlexibleBox::layoutVerticalBox): Switch to computeAndSetBlockDirectionMargins
+        * rendering/RenderTableRow.cpp:
+        (WebCore::RenderTableRow::layout): Switch to computeAndSetBlockDirectionMargins
+
 2012-08-30  Dirk Schulze  <krit@webkit.org>
 
         Introduce new CSS property for clip-path
index 6d51fbf..90900d0 100755 (executable)
@@ -2164,7 +2164,7 @@ void RenderBlock::marginBeforeEstimateForChild(RenderBox* child, LayoutUnit& pos
 
     // Make sure to update the block margins now for the grandchild box so that we're looking at current values.
     if (grandchildBox->needsLayout()) {
-        grandchildBox->computeBlockDirectionMargins(this); 
+        grandchildBox->computeAndSetBlockDirectionMargins(this);
         grandchildBox->setMarginBeforeQuirk(grandchildBox->style()->marginBefore().quirk());
         grandchildBox->setMarginAfterQuirk(grandchildBox->style()->marginAfter().quirk());
     }
@@ -2411,7 +2411,7 @@ void RenderBlock::layoutBlockChild(RenderBox* child, MarginInfo& marginInfo, Lay
     LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore();
 
     // The child is a normal flow object.  Compute the margins we will use for collapsing now.
-    child->computeBlockDirectionMargins(this);
+    child->computeAndSetBlockDirectionMargins(this);
 
     // Do not allow a collapse if the margin-before-collapse style is set to SEPARATE.
     RenderStyle* childStyle = child->style();
@@ -3761,7 +3761,7 @@ RenderBlock::FloatingObject* RenderBlock::insertFloatingObject(RenderBox* o)
         o->layoutIfNeeded();
     else {
         o->computeLogicalWidth();
-        o->computeBlockDirectionMargins(this);
+        o->computeAndSetBlockDirectionMargins(this);
     }
     setLogicalWidthForFloat(newObj, logicalWidthForChild(o) + marginStartForChild(o) + marginEndForChild(o));
 
index da7d479..38dcf2f 100644 (file)
@@ -1984,8 +1984,15 @@ void RenderBox::computeLogicalHeight()
         RenderBlock* cb = containingBlock();
         bool hasPerpendicularContainingBlock = cb->isHorizontalWritingMode() != isHorizontalWritingMode();
     
-        if (!hasPerpendicularContainingBlock)
-            computeBlockDirectionMargins(cb);
+        if (!hasPerpendicularContainingBlock) {
+            ComputedMarginValues marginValues;
+            bool shouldFlipBeforeAfter = cb->style()->writingMode() != style()->writingMode();
+            computeBlockDirectionMargins(cb,
+                shouldFlipBeforeAfter ? marginValues.m_after : marginValues.m_before,
+                shouldFlipBeforeAfter ? marginValues.m_before : marginValues.m_after);
+            setMarginBefore(marginValues.m_before);
+            setMarginAfter(marginValues.m_after);
+        }
 
         // For tables, calculate margins only.
         if (isTable()) {
@@ -2361,13 +2368,13 @@ LayoutUnit RenderBox::availableLogicalHeightUsing(const Length& h) const
     return containingBlock()->availableLogicalHeight();
 }
 
-void RenderBox::computeBlockDirectionMargins(const RenderBlock* containingBlock)
+void RenderBox::computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const
 {
     if (isTableCell()) {
         // FIXME: Not right if we allow cells to have different directionality than the table.  If we do allow this, though,
         // we may just do it with an extra anonymous block inside the cell.
-        setMarginBefore(0);
-        setMarginAfter(0);
+        marginBefore = 0;
+        marginAfter = 0;
         return;
     }
 
@@ -2376,8 +2383,17 @@ void RenderBox::computeBlockDirectionMargins(const RenderBlock* containingBlock)
     LayoutUnit cw = containingBlockLogicalWidthForContent();
     RenderView* renderView = view();
     RenderStyle* containingBlockStyle = containingBlock->style();
-    containingBlock->setMarginBeforeForChild(this, minimumValueForLength(style()->marginBeforeUsing(containingBlockStyle), cw, renderView));
-    containingBlock->setMarginAfterForChild(this, minimumValueForLength(style()->marginAfterUsing(containingBlockStyle), cw, renderView));
+    marginBefore = minimumValueForLength(style()->marginBeforeUsing(containingBlockStyle), cw, renderView);
+    marginAfter = minimumValueForLength(style()->marginAfterUsing(containingBlockStyle), cw, renderView);
+}
+
+void RenderBox::computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock)
+{
+    LayoutUnit marginBefore;
+    LayoutUnit marginAfter;
+    computeBlockDirectionMargins(containingBlock, marginBefore, marginAfter);
+    containingBlock->setMarginBeforeForChild(this, marginBefore);
+    containingBlock->setMarginAfterForChild(this, marginAfter);
 }
 
 LayoutUnit RenderBox::containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* region,
index c61035f..2a163c2 100644 (file)
@@ -335,7 +335,8 @@ public:
     void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
 
     // Used to resolve margins in the containing block's block-flow direction.
-    void computeBlockDirectionMargins(const RenderBlock* containingBlock);
+    void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
+    void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
 
     enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
     LayoutRect borderBoxRectInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage = 0, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
index 8fa73ae..e2fe1cf 100644 (file)
@@ -379,7 +379,7 @@ void RenderDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren)
                 continue;
 
             // Compute the child's vertical margins.
-            child->computeBlockDirectionMargins(this);
+            child->computeAndSetBlockDirectionMargins(this);
 
             if (!child->needsLayout())
                 child->markForPaginationRelayoutIfNeeded();
@@ -684,7 +684,7 @@ void RenderDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren)
             }
 
             // Compute the child's vertical margins.
-            child->computeBlockDirectionMargins(this);
+            child->computeAndSetBlockDirectionMargins(this);
 
             // Add in the child's marginTop to our height.
             setHeight(height() + child->marginTop());
index f575a88..2b83faa 100644 (file)
@@ -151,7 +151,7 @@ void RenderTableRow::layout()
                 cell->setChildNeedsLayout(true, MarkOnlyThis);
 
             if (child->needsLayout()) {
-                cell->computeBlockDirectionMargins(table());
+                cell->computeAndSetBlockDirectionMargins(table());
                 cell->layout();
             }
         }