Bug 1437625: Promote a few nsCSSRendering.cpp static functions into exposed static methods, since another .cpp file is already using them. r?mattwoodrow draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 12 Feb 2018 11:38:53 -0800
changeset 754057 d6c211ec71ca4c29a22d1f86ef8e990d87fd5355
parent 753815 3ee38289dac8838fe848f7234d75f3cef5d3dbc7
push id98743
push userdholbert@mozilla.com
push dateMon, 12 Feb 2018 19:39:04 +0000
reviewersmattwoodrow
bugs1437625
milestone60.0a1
Bug 1437625: Promote a few nsCSSRendering.cpp static functions into exposed static methods, since another .cpp file is already using them. r?mattwoodrow In partiuclar: nsCSSRenderingBorders.cpp is already using IsBoxDecorationSlice and BoxDecorationRectForBorder. This would be compile error, except that we happen to unify the two .cpp files together. This patch promotes these two functions (along with a closely-related function, for consistency). MozReview-Commit-ID: 4sWj5Rb9QSw
layout/painting/nsCSSRendering.cpp
layout/painting/nsCSSRendering.h
layout/painting/nsCSSRenderingBorders.cpp
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -559,48 +559,50 @@ JoinBoxesForSlice(nsIFrame* aFrame, cons
     return (aOrder == eForBorder
             ? gInlineBGData->GetBorderContinuousRect(aFrame, aBorderArea)
             : gInlineBGData->GetContinuousRect(aFrame)) +
       aBorderArea.TopLeft();
   }
   return JoinBoxesForBlockAxisSlice(aFrame, aBorderArea);
 }
 
-static bool
-IsBoxDecorationSlice(const nsStyleBorder& aStyleBorder)
+/* static */ bool
+nsCSSRendering::IsBoxDecorationSlice(const nsStyleBorder& aStyleBorder)
 {
   return aStyleBorder.mBoxDecorationBreak == StyleBoxDecorationBreak::Slice;
 }
 
-static nsRect
-BoxDecorationRectForBorder(nsIFrame* aFrame, const nsRect& aBorderArea,
-                           Sides aSkipSides,
-                           const nsStyleBorder* aStyleBorder = nullptr)
+/* static */ nsRect
+nsCSSRendering::BoxDecorationRectForBorder(nsIFrame* aFrame,
+                                           const nsRect& aBorderArea,
+                                           Sides aSkipSides,
+                                           const nsStyleBorder* aStyleBorder)
 {
   if (!aStyleBorder) {
     aStyleBorder = aFrame->StyleBorder();
   }
   // If aSkipSides.IsEmpty() then there are no continuations, or it's
   // a ::first-letter that wants all border sides on the first continuation.
-  return ::IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
+  return IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
            ? ::JoinBoxesForSlice(aFrame, aBorderArea, eForBorder)
            : aBorderArea;
 }
 
-static nsRect
-BoxDecorationRectForBackground(nsIFrame* aFrame, const nsRect& aBorderArea,
-                               Sides aSkipSides,
-                               const nsStyleBorder* aStyleBorder = nullptr)
+/* static */ nsRect
+nsCSSRendering::BoxDecorationRectForBackground(nsIFrame* aFrame,
+                                               const nsRect& aBorderArea,
+                                               Sides aSkipSides,
+                                               const nsStyleBorder* aStyleBorder)
 {
   if (!aStyleBorder) {
     aStyleBorder = aFrame->StyleBorder();
   }
   // If aSkipSides.IsEmpty() then there are no continuations, or it's
   // a ::first-letter that wants all border sides on the first continuation.
-  return ::IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
+  return IsBoxDecorationSlice(*aStyleBorder) && !aSkipSides.IsEmpty()
            ? ::JoinBoxesForSlice(aFrame, aBorderArea, eForBackground)
            : aBorderArea;
 }
 
 //----------------------------------------------------------------------
 // Thebes Border Rendering Code Start
 
 /*
@@ -807,25 +809,26 @@ ConstructBorderRenderer(nsPresContext* a
   nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame(aForFrame, quirks);
   nsStyleContext* bgContext = bgFrame->StyleContext();
   nscolor bgColor = bgContext->
     GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aBorderArea & aBGClipRect.
   nsRect joinedBorderArea =
-    ::BoxDecorationRectForBorder(aForFrame, aBorderArea, aSkipSides, &aStyleBorder);
+    nsCSSRendering::BoxDecorationRectForBorder(aForFrame, aBorderArea,
+                                               aSkipSides, &aStyleBorder);
   RectCornerRadii bgRadii;
   ::GetRadii(aForFrame, aStyleBorder, aBorderArea, joinedBorderArea, &bgRadii);
 
   PrintAsFormatString(" joinedBorderArea: %d %d %d %d\n", joinedBorderArea.x, joinedBorderArea.y,
      joinedBorderArea.width, joinedBorderArea.height);
 
   // start drawing
-  if (::IsBoxDecorationSlice(aStyleBorder)) {
+  if (nsCSSRendering::IsBoxDecorationSlice(aStyleBorder)) {
     if (joinedBorderArea.IsEqualEdges(aBorderArea)) {
       // No need for a clip, just skip the sides we don't want.
       border.ApplySkipSides(aSkipSides);
     } else {
       // We're drawing borders around the joined continuation boxes so we need
       // to clip that to the slice that we want for this frame.
       *aNeedsClip = true;
     }
@@ -1532,17 +1535,17 @@ nsRect
 nsCSSRendering::GetShadowRect(const nsRect aFrameArea,
                               bool aNativeTheme,
                               nsIFrame* aForFrame)
 {
   nsRect frameRect = aNativeTheme ?
     aForFrame->GetVisualOverflowRectRelativeToSelf() + aFrameArea.TopLeft() :
     aFrameArea;
   Sides skipSides = aForFrame->GetSkipSides();
-  frameRect = ::BoxDecorationRectForBorder(aForFrame, frameRect, skipSides);
+  frameRect = BoxDecorationRectForBorder(aForFrame, frameRect, skipSides);
 
   // Explicitly do not need to account for the spread radius here
   // Webrender does it for us or PaintBoxShadow will for non-WR
   return frameRect;
 }
 
 bool
 nsCSSRendering::GetBorderRadii(const nsRect& aFrameRect,
@@ -1780,17 +1783,17 @@ nsCSSRendering::PaintBoxShadowOuter(nsPr
 }
 
 nsRect
 nsCSSRendering::GetBoxShadowInnerPaddingRect(nsIFrame* aFrame,
                                              const nsRect& aFrameArea)
 {
   Sides skipSides = aFrame->GetSkipSides();
   nsRect frameRect =
-    ::BoxDecorationRectForBorder(aFrame, aFrameArea, skipSides);
+    BoxDecorationRectForBorder(aFrame, aFrameArea, skipSides);
 
   nsRect paddingRect = frameRect;
   nsMargin border = aFrame->GetUsedBorder();
   paddingRect.Deflate(border);
   return paddingRect;
 }
 
 bool
@@ -1816,17 +1819,17 @@ bool
 nsCSSRendering::GetShadowInnerRadii(nsIFrame* aFrame,
                                     const nsRect& aFrameArea,
                                     RectCornerRadii& aOutInnerRadii)
 {
   // Get any border radius, since box-shadow must also have rounded corners
   // if the frame does.
   nscoord twipsRadii[8];
   nsRect frameRect =
-    ::BoxDecorationRectForBorder(aFrame, aFrameArea, aFrame->GetSkipSides());
+    BoxDecorationRectForBorder(aFrame, aFrameArea, aFrame->GetSkipSides());
   nsSize sz = frameRect.Size();
   nsMargin border = aFrame->GetUsedBorder();
   bool hasBorderRadius = aFrame->GetBorderRadii(sz, sz, Sides(), twipsRadii);
   const nscoord oneDevPixel = aFrame->PresContext()->DevPixelsToAppUnits(1);
 
   RectCornerRadii borderRadii;
 
   hasBorderRadius = GetBorderRadii(frameRect, aFrameArea, aFrame, borderRadii);
@@ -2298,17 +2301,17 @@ nsCSSRendering::GetImageLayerClip(const 
 
   MOZ_ASSERT(!aForFrame->IsFrameOfType(nsIFrame::eSVG) ||
              aForFrame->IsSVGOuterSVGFrame());
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aBorderArea.
   Sides skipSides = aForFrame->GetSkipSides();
   nsRect clipBorderArea =
-    ::BoxDecorationRectForBorder(aForFrame, aBorderArea, skipSides, &aBorder);
+    BoxDecorationRectForBorder(aForFrame, aBorderArea, skipSides, &aBorder);
 
   bool haveRoundedCorners = false;
   LayoutFrameType fType = aForFrame->Type();
   if (fType != LayoutFrameType::TableColGroup &&
       fType != LayoutFrameType::TableCol &&
       fType != LayoutFrameType::TableRow &&
       fType != LayoutFrameType::TableRowGroup) {
     haveRoundedCorners = GetRadii(aForFrame, aBorder, aBorderArea,
@@ -2745,20 +2748,20 @@ nsCSSRendering::PaintStyleImageLayerWith
   if (drawBackgroundColor && !isCanvasFrame) {
     DrawBackgroundColor(clipState, &aRenderingCtx, appUnitsPerPixel);
   }
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aParams.borderArea & aParams.bgClipRect.
   Sides skipSides = aParams.frame->GetSkipSides();
   nsRect paintBorderArea =
-    ::BoxDecorationRectForBackground(aParams.frame, aParams.borderArea,
+    BoxDecorationRectForBackground(aParams.frame, aParams.borderArea,
                                      skipSides, &aBorder);
   nsRect clipBorderArea =
-    ::BoxDecorationRectForBorder(aParams.frame, aParams.borderArea,
+    BoxDecorationRectForBorder(aParams.frame, aParams.borderArea,
                                  skipSides, &aBorder);
 
   ImgDrawResult result = ImgDrawResult::SUCCESS;
   StyleGeometryBox currentBackgroundClip = StyleGeometryBox::BorderBox;
   uint32_t count = drawAllLayers
     ? layers.mImageCount                  // iterate all image layers.
     : layers.mImageCount - aParams.layer; // iterate from the bottom layer to
                                           // the 'aParams.layer-th' layer.
@@ -2864,17 +2867,17 @@ nsCSSRendering::BuildWebRenderDisplayIte
   SetupDirtyRects(clipState.mBGClipArea, aParams.dirtyRect, appUnitsPerPixel,
                   &clipState.mDirtyRectInAppUnits,
                   &clipState.mDirtyRectInDevPx);
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aParams.borderArea & aParams.bgClipRect.
   Sides skipSides = aParams.frame->GetSkipSides();
   nsRect paintBorderArea =
-    ::BoxDecorationRectForBackground(aParams.frame, aParams.borderArea,
+    BoxDecorationRectForBackground(aParams.frame, aParams.borderArea,
                                      skipSides, &aBorder);
 
   const nsStyleImageLayers& layers = aBackgroundSC->StyleBackground()->mImage;
   const nsStyleImageLayers::Layer& layer = layers.mLayers[aParams.layer];
 
   // Skip the following layer painting code if we found the dirty region is
   // empty or the current layer is not selected for drawing.
   if (clipState.mDirtyRectInDevPx.IsEmpty()) {
@@ -3384,17 +3387,17 @@ nsCSSRendering::GetBackgroundLayerRect(n
                                        nsIFrame* aForFrame,
                                        const nsRect& aBorderArea,
                                        const nsRect& aClipRect,
                                        const nsStyleImageLayers::Layer& aLayer,
                                        uint32_t aFlags)
 {
   Sides skipSides = aForFrame->GetSkipSides();
   nsRect borderArea =
-    ::BoxDecorationRectForBackground(aForFrame, aBorderArea, skipSides);
+    BoxDecorationRectForBackground(aForFrame, aBorderArea, skipSides);
   nsBackgroundLayerState state =
       PrepareImageLayer(aPresContext, aForFrame, aFlags, borderArea,
                              aClipRect, aLayer);
   return state.mFillArea;
 }
 
 // Begin table border-collapsing section
 // These functions were written to not disrupt the normal ones and yet satisfy some additional requirements
--- a/layout/painting/nsCSSRendering.h
+++ b/layout/painting/nsCSSRendering.h
@@ -115,16 +115,28 @@ struct nsCSSRendering {
    */
   static void Init();
 
   /**
    * Clean up any static variables used by nsCSSRendering.
    */
   static void Shutdown();
 
+  static bool IsBoxDecorationSlice(const nsStyleBorder& aStyleBorder);
+  static nsRect BoxDecorationRectForBorder(
+                  nsIFrame* aFrame,
+                  const nsRect& aBorderArea,
+                  Sides aSkipSides,
+                  const nsStyleBorder* aStyleBorder = nullptr);
+  static nsRect BoxDecorationRectForBackground(
+                  nsIFrame* aFrame,
+                  const nsRect& aBorderArea,
+                  Sides aSkipSides,
+                  const nsStyleBorder* aStyleBorder = nullptr);
+
   static bool GetShadowInnerRadii(nsIFrame* aFrame,
                                   const nsRect& aFrameArea,
                                   RectCornerRadii& aOutInnerRadii);
   static nsRect GetBoxShadowInnerPaddingRect(nsIFrame* aFrame,
                                              const nsRect& aFrameArea);
   static bool ShouldPaintBoxShadowInner(nsIFrame* aFrame);
   static void PaintBoxShadowInner(nsPresContext* aPresContext,
                                   gfxContext& aRenderingContext,
--- a/layout/painting/nsCSSRenderingBorders.cpp
+++ b/layout/painting/nsCSSRenderingBorders.cpp
@@ -13,16 +13,17 @@
 #include "mozilla/gfx/PathHelpers.h"
 #include "BorderConsts.h"
 #include "DashedCornerFinder.h"
 #include "DottedCornerFinder.h"
 #include "nsLayoutUtils.h"
 #include "nsStyleConsts.h"
 #include "nsContentUtils.h"
 #include "nsCSSColorUtils.h"
+#include "nsCSSRendering.h"
 #include "nsCSSRenderingGradients.h"
 #include "GeckoProfiler.h"
 #include "nsExpirationTracker.h"
 #include "RoundedRect.h"
 #include "nsIScriptError.h"
 #include "nsClassHashtable.h"
 #include "nsPresContext.h"
 #include "nsStyleStruct.h"
@@ -3831,19 +3832,21 @@ nsCSSBorderImageRenderer::nsCSSBorderIma
   : mImageRenderer(aImageRenderer)
 {
   // Determine the border image area, which by default corresponds to the
   // border box but can be modified by 'border-image-outset'.
   // Note that 'border-radius' do not apply to 'border-image' borders per
   // <http://dev.w3.org/csswg/css-backgrounds/#corner-clipping>.
   nsMargin borderWidths(aStyleBorder.GetComputedBorder());
   mImageOutset = aStyleBorder.GetImageOutset();
-  if (::IsBoxDecorationSlice(aStyleBorder) && !aSkipSides.IsEmpty()) {
-    mArea = ::BoxDecorationRectForBorder(aForFrame, aBorderArea,
-                                         aSkipSides, &aStyleBorder);
+  if (nsCSSRendering::IsBoxDecorationSlice(aStyleBorder) &&
+      !aSkipSides.IsEmpty()) {
+    mArea = nsCSSRendering::BoxDecorationRectForBorder(aForFrame, aBorderArea,
+                                                       aSkipSides,
+                                                       &aStyleBorder);
     if (mArea.IsEqualEdges(aBorderArea)) {
       // No need for a clip, just skip the sides we don't want.
       borderWidths.ApplySkipSides(aSkipSides);
       mImageOutset.ApplySkipSides(aSkipSides);
       mArea.Inflate(mImageOutset);
     } else {
       // We're drawing borders around the joined continuation boxes so we need
       // to clip that to the slice that we want for this frame.