Title: [87801] trunk/Source/WebCore
Revision
87801
Author
[email protected]
Date
2011-06-01 07:10:15 -0700 (Wed, 01 Jun 2011)

Log Message

2011-06-01  Nikolas Zimmermann  <[email protected]>

        Reviewed by Rob Buis.

        Remove duplicated code in various computeReplacedLogical*() functions
        https://bugs.webkit.org/show_bug.cgi?id=61860

        Centralize this calculation in RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth:
        int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
        int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
        return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));

        Centralize this calculation in RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight:
        int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
        int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
        return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));

        Use the new helper methods where possible, deduplicating lots of code.

        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::computeReplacedLogicalWidth):
        (WebCore::RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth):
        (WebCore::RenderBox::computeReplacedLogicalHeight):
        (WebCore::RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight):
        * rendering/RenderBox.h:
        * rendering/RenderImage.cpp:
        (WebCore::RenderImage::computeReplacedLogicalWidth):
        (WebCore::RenderImage::computeReplacedLogicalHeight):
        * rendering/RenderPart.cpp:
        (WebCore::RenderPart::computeEmbeddedDocumentReplacedWidth):
        (WebCore::RenderPart::computeEmbeddedDocumentReplacedHeight):
        (WebCore::RenderPart::computeReplacedLogicalWidth):
        (WebCore::RenderPart::computeReplacedLogicalHeight):
        * rendering/RenderPart.h:
        * rendering/RenderReplaced.cpp:
        (WebCore::RenderReplaced::computeReplacedLogicalWidth):
        (WebCore::RenderReplaced::computeReplacedLogicalHeight):
        * rendering/svg/RenderSVGRoot.cpp:
        (WebCore::RenderSVGRoot::computeReplacedLogicalWidth):
        (WebCore::RenderSVGRoot::computeReplacedLogicalHeight):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (87800 => 87801)


--- trunk/Source/WebCore/ChangeLog	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/ChangeLog	2011-06-01 14:10:15 UTC (rev 87801)
@@ -1,3 +1,44 @@
+2011-06-01  Nikolas Zimmermann  <[email protected]>
+
+        Reviewed by Rob Buis.
+
+        Remove duplicated code in various computeReplacedLogical*() functions
+        https://bugs.webkit.org/show_bug.cgi?id=61860
+
+        Centralize this calculation in RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth:
+        int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
+        int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
+        return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
+
+        Centralize this calculation in RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight:
+        int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
+        int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
+        return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
+
+        Use the new helper methods where possible, deduplicating lots of code.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::computeReplacedLogicalWidth):
+        (WebCore::RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth):
+        (WebCore::RenderBox::computeReplacedLogicalHeight):
+        (WebCore::RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight):
+        * rendering/RenderBox.h:
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::computeReplacedLogicalWidth):
+        (WebCore::RenderImage::computeReplacedLogicalHeight):
+        * rendering/RenderPart.cpp:
+        (WebCore::RenderPart::computeEmbeddedDocumentReplacedWidth):
+        (WebCore::RenderPart::computeEmbeddedDocumentReplacedHeight):
+        (WebCore::RenderPart::computeReplacedLogicalWidth):
+        (WebCore::RenderPart::computeReplacedLogicalHeight):
+        * rendering/RenderPart.h:
+        * rendering/RenderReplaced.cpp:
+        (WebCore::RenderReplaced::computeReplacedLogicalWidth):
+        (WebCore::RenderReplaced::computeReplacedLogicalHeight):
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::computeReplacedLogicalWidth):
+        (WebCore::RenderSVGRoot::computeReplacedLogicalHeight):
+
 2011-06-01  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r87788.

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2011-06-01 14:10:15 UTC (rev 87801)
@@ -1945,10 +1945,13 @@
 
 int RenderBox::computeReplacedLogicalWidth(bool includeMaxWidth) const
 {
-    int logicalWidth = computeReplacedLogicalWidthUsing(style()->logicalWidth());
+    return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogicalWidthUsing(style()->logicalWidth()), includeMaxWidth);
+}
+
+int RenderBox::computeReplacedLogicalWidthRespectingMinMaxWidth(int logicalWidth, bool includeMaxWidth) const
+{
     int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
     int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
-
     return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
 }
 
@@ -1973,10 +1976,13 @@
 
 int RenderBox::computeReplacedLogicalHeight() const
 {
-    int logicalHeight = computeReplacedLogicalHeightUsing(style()->logicalHeight());
+    return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLogicalHeightUsing(style()->logicalHeight()));
+}
+
+int RenderBox::computeReplacedLogicalHeightRespectingMinMaxHeight(int logicalHeight) const
+{
     int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
     int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
-
     return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
 }
 

Modified: trunk/Source/WebCore/rendering/RenderBox.h (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderBox.h	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2011-06-01 14:10:15 UTC (rev 87801)
@@ -308,7 +308,9 @@
     int computeLogicalWidthUsing(LogicalWidthType, int availableLogicalWidth);
     int computeLogicalHeightUsing(const Length& height);
     int computeReplacedLogicalWidthUsing(Length width) const;
+    int computeReplacedLogicalWidthRespectingMinMaxWidth(int logicalWidth, bool includeMaxWidth = true) const;
     int computeReplacedLogicalHeightUsing(Length height) const;
+    int computeReplacedLogicalHeightRespectingMinMaxHeight(int logicalHeight) const;
 
     virtual int computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
     virtual int computeReplacedLogicalHeight() const;

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2011-06-01 14:10:15 UTC (rev 87801)
@@ -477,10 +477,7 @@
     else
         logicalWidth = calcAspectRatioLogicalWidth();
 
-    int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
-    int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
-
-    return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
+    return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, includeMaxWidth);
 }
 
 int RenderImage::computeReplacedLogicalHeight() const
@@ -496,10 +493,7 @@
     else
         logicalHeight = calcAspectRatioLogicalHeight();
 
-    int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
-    int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
-
-    return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
+    return computeReplacedLogicalHeightRespectingMinMaxHeight(logicalHeight);
 }
 
 int RenderImage::calcAspectRatioLogicalWidth() const

Modified: trunk/Source/WebCore/rendering/RenderPart.cpp (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderPart.cpp	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderPart.cpp	2011-06-01 14:10:15 UTC (rev 87801)
@@ -112,22 +112,18 @@
     return toRenderSVGRoot(svgRootRenderer);
 }
 
-int RenderPart::computeEmbeddedDocumentReplacedWidth(bool includeMaxWidth, RenderStyle* contentRenderStyle) const
+int RenderPart::computeEmbeddedDocumentReplacedWidth(RenderSVGRoot* contentRenderer, bool includeMaxWidth) const
 {
-    int logicalWidth = computeReplacedLogicalWidthUsing(contentRenderStyle->logicalWidth());
-    int minLogicalWidth = computeReplacedLogicalWidthUsing(contentRenderStyle->logicalMinWidth());
-    int maxLogicalWidth = !includeMaxWidth || contentRenderStyle->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(contentRenderStyle->logicalMaxWidth());
-    int width = max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
-    return width;
+    ASSERT(contentRenderer);
+    ASSERT(contentRenderer->style());
+    return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogicalWidthUsing(contentRenderer->style()->logicalWidth()), includeMaxWidth);
 }
 
-int RenderPart::computeEmbeddedDocumentReplacedHeight(RenderStyle* contentRenderStyle) const
+int RenderPart::computeEmbeddedDocumentReplacedHeight(RenderSVGRoot* contentRenderer) const
 {
-    int logicalHeight = computeReplacedLogicalHeightUsing(contentRenderStyle->logicalHeight());
-    int minLogicalHeight = computeReplacedLogicalHeightUsing(contentRenderStyle->logicalMinHeight());
-    int maxLogicalHeight = contentRenderStyle->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(contentRenderStyle->logicalMaxHeight());
-    int height = max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
-    return height;
+    ASSERT(contentRenderer);
+    ASSERT(contentRenderer->style());
+    return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLogicalHeightUsing(contentRenderer->style()->logicalHeight()));
 }
 
 int RenderPart::computeReplacedLogicalWidth(bool includeMaxWidth) const
@@ -149,7 +145,7 @@
 
         // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.
         if (heightIsAuto && hasIntrinsicWidth)
-            return computeEmbeddedDocumentReplacedWidth(includeMaxWidth, contentRenderStyle);
+            return computeEmbeddedDocumentReplacedWidth(contentRenderer, includeMaxWidth);
     
         bool hasIntrinsicHeight = contentRenderStyle->height().isFixed();
         if (!intrinsicRatio.isEmpty()) {
@@ -175,7 +171,7 @@
 
         // Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'.
         if (hasIntrinsicWidth)
-            return computeEmbeddedDocumentReplacedWidth(includeMaxWidth, contentRenderStyle);
+            return computeEmbeddedDocumentReplacedWidth(contentRenderer, includeMaxWidth);
     }
 
     // Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px. If 300px is too
@@ -202,7 +198,7 @@
 
         // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
         if (widthIsAuto && hasIntrinsicHeight)
-            return computeEmbeddedDocumentReplacedHeight(contentRenderStyle);
+            return computeEmbeddedDocumentReplacedHeight(contentRenderer);
     
         // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic ratio then the used value of 'height' is:
         // (used width) / (intrinsic ratio)
@@ -213,7 +209,7 @@
 
         // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic height, then that intrinsic height is the used value of 'height'.
         if (hasIntrinsicHeight)
-            return computeEmbeddedDocumentReplacedHeight(contentRenderStyle);
+            return computeEmbeddedDocumentReplacedHeight(contentRenderer);
     }
 
     // Otherwise, if 'height' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'height' must be set to the height

Modified: trunk/Source/WebCore/rendering/RenderPart.h (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderPart.h	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderPart.h	2011-06-01 14:10:15 UTC (rev 87801)
@@ -49,8 +49,8 @@
 
 #if ENABLE(SVG)
     RenderSVGRoot* embeddedSVGContentRenderer() const;
-    int computeEmbeddedDocumentReplacedWidth(bool includeMaxWidth, RenderStyle* contentRenderStyle) const;
-    int computeEmbeddedDocumentReplacedHeight(RenderStyle* contentRenderStyle) const;
+    int computeEmbeddedDocumentReplacedWidth(RenderSVGRoot* contentRenderer, bool includeMaxWidth) const;
+    int computeEmbeddedDocumentReplacedHeight(RenderSVGRoot* contentRenderer) const;
     virtual int computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
     virtual int computeReplacedLogicalHeight() const;
     virtual void layout();

Modified: trunk/Source/WebCore/rendering/RenderReplaced.cpp (87800 => 87801)


--- trunk/Source/WebCore/rendering/RenderReplaced.cpp	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/RenderReplaced.cpp	2011-06-01 14:10:15 UTC (rev 87801)
@@ -202,10 +202,7 @@
     else
         logicalWidth = intrinsicLogicalWidth();
 
-    int minLogicalWidth = computeReplacedLogicalWidthUsing(style()->logicalMinWidth());
-    int maxLogicalWidth = !includeMaxWidth || style()->logicalMaxWidth().isUndefined() ? logicalWidth : computeReplacedLogicalWidthUsing(style()->logicalMaxWidth());
-
-    return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
+    return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, includeMaxWidth);
 }
 
 int RenderReplaced::computeReplacedLogicalHeight() const
@@ -218,10 +215,7 @@
     else
         logicalHeight = intrinsicLogicalHeight();
 
-    int minLogicalHeight = computeReplacedLogicalHeightUsing(style()->logicalMinHeight());
-    int maxLogicalHeight = style()->logicalMaxHeight().isUndefined() ? logicalHeight : computeReplacedLogicalHeightUsing(style()->logicalMaxHeight());
-
-    return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
+    return computeReplacedLogicalHeightRespectingMinMaxHeight(logicalHeight);
 }
 
 int RenderReplaced::calcAspectRatioLogicalWidth() const

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp (87800 => 87801)


--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2011-06-01 13:48:43 UTC (rev 87800)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2011-06-01 14:10:15 UTC (rev 87801)
@@ -190,10 +190,7 @@
     //   the width of the viewport.
     //
     // Under these conditions, the positioning properties establish the viewport's width.
-    int logicalWidth = ownerRenderer->computeReplacedLogicalWidthUsing(ownerWidth);
-    int minLogicalWidth = ownerRenderer->computeReplacedLogicalWidthUsing(ownerRendererStyle->logicalMinWidth());
-    int maxLogicalWidth = !includeMaxWidth || ownerRendererStyle->logicalMaxWidth().isUndefined() ? logicalWidth : ownerRenderer->computeReplacedLogicalWidthUsing(ownerRendererStyle->logicalMaxWidth());
-    return max(minLogicalWidth, min(logicalWidth, maxLogicalWidth));
+    return ownerRenderer->computeReplacedLogicalWidthRespectingMinMaxWidth(ownerRenderer->computeReplacedLogicalWidthUsing(ownerWidth), includeMaxWidth);
 }
 
 int RenderSVGRoot::computeReplacedLogicalHeight() const
@@ -222,10 +219,7 @@
     // Similarly, if there are positioning properties specified on the referencing element or on the outermost svg element that
     // are sufficient to establish the height of the viewport, then these positioning properties establish the viewport's height;
     // otherwise, the ‘height’ attribute on the outermost svg element establishes the viewport's height.
-    int logicalHeight = ownerRenderer->computeReplacedLogicalHeightUsing(ownerHeight);
-    int minLogicalHeight = ownerRenderer->computeReplacedLogicalHeightUsing(ownerRendererStyle->logicalMinHeight());
-    int maxLogicalHeight = ownerRendererStyle->logicalMaxHeight().isUndefined() ? logicalHeight : ownerRenderer->computeReplacedLogicalHeightUsing(ownerRendererStyle->logicalMaxHeight());
-    return max(minLogicalHeight, min(logicalHeight, maxLogicalHeight));
+    return ownerRenderer->computeReplacedLogicalHeightRespectingMinMaxHeight(ownerRenderer->computeReplacedLogicalHeightUsing(ownerHeight));
 }
 
 void RenderSVGRoot::layout()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to