         {
             if (measuredSizeIncludesScrollBars)
             {
+                var contentSize:Point = getLayoutContentSize(viewport);
+    
                 var viewportPreferredW:Number =  viewport.getPreferredBoundsWidth();
-                measuredW += Math.max(viewportPreferredW, (showHSB) ? hsb.getMinBoundsWidth() : 0);
+                var viewportContentW:Number = contentSize.x;
+                var viewportW:Number = viewport.getLayoutBoundsWidth();  // "current" size
+                var currentSizeNoHSB:Boolean = !isNaN(viewportW) && ((viewportW + SDT) > viewportContentW);
+                if (hAuto && !showHSB && ((viewportPreferredW + SDT) <= viewportContentW) && currentSizeNoHSB)
+                    measuredW += viewportW;
+                else
+                    measuredW += Math.max(viewportPreferredW, (showHSB) ? hsb.getMinBoundsWidth() : 0);
     
                 var viewportPreferredH:Number = viewport.getPreferredBoundsHeight();
-                measuredH += Math.max(viewportPreferredH, (showVSB) ? vsb.getMinBoundsHeight() : 0);
+                var viewportContentH:Number = contentSize.y;
+                var viewportH:Number = viewport.getLayoutBoundsHeight();  // "current" size
+                var currentSizeNoVSB:Boolean = !isNaN(viewportH) && ((viewportH + SDT) > viewportContentH);
+                if (vAuto && !showVSB && ((viewportPreferredH + SDT) <= viewportContentH) && currentSizeNoVSB)
+                    measuredH += viewportH;
+                else
+                    measuredH += Math.max(viewportPreferredH, (showVSB) ? vsb.getMinBoundsHeight() : 0);
             }
             else
             {

{
import flash.geom.Point;

import mx.core.FlexVersion;
import mx.core.IContainerInvalidating;
import mx.core.ILayoutElement;
import mx.core.IUIComponent;
import mx.core.InteractionMode;
import mx.core.ScrollPolicy;
import mx.core.UIComponentGlobals;
import mx.core.mx_internal;
import mx.managers.ILayoutManagerClient;
import mx.managers.ILayoutManagerContainerClient;
import mx.utils.MatrixUtil;

import spark.components.Scroller;

			
			vsb.setLayoutBoundsPosition(w - vsbW, 0);
        }

        // If we've added an auto scrollbar, then the measured size is likely to have been wrong.
        // There's a risk of looping here, so we count.  
        if ((invalidationCount < 2) && (((vsbVisible != oldShowVSB) && vAuto) || ((hsbVisible != oldShowHSB) && hAuto)))
        {
            target.invalidateSize();
            
            // If the viewport's layout is virtual, it's possible that its
            // measured size changed as a consequence of laying it out,
            // so we invalidate its size as well.
            var viewportGroup:GroupBase = viewport as GroupBase;
            if (viewportGroup && viewportGroup.layout && viewportGroup.layout.useVirtualLayout)
                viewportGroup.invalidateSize();
            
            invalidationCount += 1; 
        }
        else
            invalidationCount = 0;
             
        target.setContentSize(w, h);
    }

