2008-04-16 Anatoli Papirovski <apapirovski@mac.com>
authorjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Apr 2008 19:47:55 +0000 (19:47 +0000)
committerjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Apr 2008 19:47:55 +0000 (19:47 +0000)
        Reviewed by David.

        Optimized the calculation of background-size.

        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::calculateBackgroundSize):

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

WebCore/ChangeLog
WebCore/rendering/RenderBox.cpp

index 3548b96..76c2ee5 100644 (file)
@@ -1,3 +1,12 @@
+2008-04-16  Anatoli Papirovski  <apapirovski@mac.com>
+
+        Reviewed by David.
+
+        Optimized the calculation of background-size.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::calculateBackgroundSize):
+
 2008-04-16  Adam Roben  <aroben@apple.com>
 
         Fix Bug 17228: console.{log,warn,info,error} should support format
 2008-04-16  Adam Roben  <aroben@apple.com>
 
         Fix Bug 17228: console.{log,warn,info,error} should support format
index e10b911..c1878f1 100644 (file)
@@ -436,37 +436,27 @@ IntSize RenderBox::calculateBackgroundSize(const BackgroundLayer* bgLayer, int s
         Length bgWidth = bgLayer->backgroundSize().width;
         Length bgHeight = bgLayer->backgroundSize().height;
 
         Length bgWidth = bgLayer->backgroundSize().width;
         Length bgHeight = bgLayer->backgroundSize().height;
 
-        if (bgWidth.isPercent())
-            w = bgWidth.calcValue(scaledWidth);
-        else if (bgWidth.isFixed())
+        if (bgWidth.isFixed())
             w = bgWidth.value();
             w = bgWidth.value();
-        else if (bgWidth.isAuto()) {
-            // If the width is auto and the height is not, we have to use the appropriate
-            // scale to maintain our aspect ratio.
-            if (bgHeight.isPercent()) {
-                int scaledH = bgHeight.calcValue(scaledHeight);
-                w = bg->imageSize(style()->effectiveZoom()).width() * scaledH / bg->imageSize(style()->effectiveZoom()).height();
-            } else if (bgHeight.isFixed())
-                w = bg->imageSize(style()->effectiveZoom()).width() * bgHeight.value() / bg->imageSize(style()->effectiveZoom()).height();
-        }
-
-        if (bgHeight.isPercent())
-            h = bgHeight.calcValue(scaledHeight);
-        else if (bgHeight.isFixed())
+        else if (bgWidth.isPercent())
+            w = bgWidth.calcValue(scaledWidth);
+        
+        if (bgHeight.isFixed())
             h = bgHeight.value();
             h = bgHeight.value();
-        else if (bgHeight.isAuto()) {
-            // If the height is auto and the width is not, we have to use the appropriate
-            // scale to maintain our aspect ratio.
-            if (bgWidth.isPercent())
-                h = bg->imageSize(style()->effectiveZoom()).height() * w / bg->imageSize(style()->effectiveZoom()).width();
-            else if (bgWidth.isFixed())
-                h = bg->imageSize(style()->effectiveZoom()).height() * bgWidth.value() / bg->imageSize(style()->effectiveZoom()).width();
-            else if (bgWidth.isAuto()) {
-                // If both width and height are auto, we just want to use the image's
-                // intrinsic size.
-                w = bg->imageSize(style()->effectiveZoom()).width();
-                h = bg->imageSize(style()->effectiveZoom()).height();
-            }
+        else if (bgHeight.isPercent())
+            h = bgHeight.calcValue(scaledHeight);
+        
+        // If one of the values is auto we have to use the appropriate
+        // scale to maintain our aspect ratio.
+        if (bgWidth.isAuto() && !bgHeight.isAuto())
+            w = bg->imageSize(style()->effectiveZoom()).width() * h / bg->imageSize(style()->effectiveZoom()).height();        
+        else if (!bgWidth.isAuto() && bgHeight.isAuto())
+            h = bg->imageSize(style()->effectiveZoom()).height() * w / bg->imageSize(style()->effectiveZoom()).width();
+        else if (bgWidth.isAuto() && bgHeight.isAuto()) {
+            // If both width and height are auto, we just want to use the image's
+            // intrinsic size.
+            w = bg->imageSize(style()->effectiveZoom()).width();
+            h = bg->imageSize(style()->effectiveZoom()).height();
         }
         
         return IntSize(max(1, w), max(1, h));
         }
         
         return IntSize(max(1, w), max(1, h));