Bug 1287492 - Part 1. Implement nsLayoutUtils::HasCSSBoxLayout. draft
authorcku <cku@mozilla.com>
Wed, 08 Feb 2017 20:15:28 +0800
changeset 481260 2858afc97f2f34a087343b50af9bda042ab1853c
parent 480952 f505911eb333d5ae8c2bf5c44f7b85add6450b53
child 481261 9407f887b938da7d2fd99c078e20568272f75400
push id44753
push userbmo:cku@mozilla.com
push dateThu, 09 Feb 2017 14:41:29 +0000
bugs1287492
milestone54.0a1
Bug 1287492 - Part 1. Implement nsLayoutUtils::HasCSSBoxLayout. There is no direct relation between this patch and the bug. Read through the code and think we may reuse some logic. MozReview-Commit-ID: HGEvDNGoIBS
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/painting/nsCSSRendering.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9343,15 +9343,22 @@ ComputeHTMLReferenceRect(nsIFrame* aFram
 
 /* static */ nsRect
 nsLayoutUtils::ComputeGeometryBox(nsIFrame* aFrame,
                                   StyleGeometryBox aGeometryBox)
 {
   // We use ComputeSVGReferenceRect for all SVG elements, except <svg>
   // element, which does have an associated CSS layout box. In this case we
   // should still use ComputeHTMLReferenceRect for region computing.
-  nsRect r = aFrame->IsFrameOfType(nsIFrame::eSVG) &&
-             (aFrame->GetType() != nsGkAtoms::svgOuterSVGFrame)
-             ? ComputeSVGReferenceRect(aFrame, aGeometryBox)
-             : ComputeHTMLReferenceRect(aFrame, aGeometryBox);
+  nsRect r = HasCSSBoxLayout(aFrame)
+             ? ComputeHTMLReferenceRect(aFrame, aGeometryBox)
+             : ComputeSVGReferenceRect(aFrame, aGeometryBox);
 
   return r;
 }
+
+/* static */ bool
+nsLayoutUtils::HasCSSBoxLayout(nsIFrame* aFrame)
+{
+  // Except SVG outer element, all SVG element does not have CSS box layout.
+  return !aFrame->IsFrameOfType(nsIFrame::eSVG) ||
+          aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame;
+}
\ No newline at end of file
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2893,16 +2893,21 @@ public:
    * @param   aNextLineFrame  assigned to first frame on the next line if such a
    *                          next line exists, null otherwise.
    */
   static bool IsInvisibleBreak(nsINode* aNode, nsIFrame** aNextLineFrame = nullptr);
 
   static nsRect ComputeGeometryBox(nsIFrame* aFrame,
                                    StyleGeometryBox aGeometryBox);
 
+  /*
+   * Check whether aFrame is associated with CSS layout box.
+   */
+  static bool HasCSSBoxLayout(nsIFrame* aFrame);
+
 private:
   static uint32_t sFontSizeInflationEmPerLine;
   static uint32_t sFontSizeInflationMinTwips;
   static uint32_t sFontSizeInflationLineThreshold;
   static int32_t  sFontSizeInflationMappingIntercept;
   static uint32_t sFontSizeInflationMaxRatio;
   static bool sFontSizeInflationForceEnabled;
   static bool sFontSizeInflationDisabledInMasterProcess;
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -1920,30 +1920,28 @@ IsHTMLStyleGeometryBox(StyleGeometryBox 
           aBox == StyleGeometryBox::Padding ||
           aBox == StyleGeometryBox::Border ||
           aBox == StyleGeometryBox::Margin);
 }
 
 static StyleGeometryBox
 ComputeBoxValue(nsIFrame* aForFrame, StyleGeometryBox aBox)
 {
-  // Except <svg>, all svg elements are not associate with CSS layout box.
-  if (aForFrame->IsFrameOfType(nsIFrame::eSVG) &&
-      (aForFrame->GetType() != nsGkAtoms::svgOuterSVGFrame)) {
+  if (nsLayoutUtils::HasCSSBoxLayout(aForFrame)) {
+    // For elements with associated CSS layout box, the values fill-box,
+    // stroke-box and view-box compute to the initial value of mask-clip.
+    if (IsSVGStyleGeometryBox(aBox)) {
+      return StyleGeometryBox::Border;
+    }
+  } else {
     // For SVG elements without associated CSS layout box, the values
     // content-box, padding-box, border-box and margin-box compute to fill-box.
     if (IsHTMLStyleGeometryBox(aBox)) {
       return StyleGeometryBox::Fill;
     }
-  } else {
-    // For elements with associated CSS layout box, the values fill-box,
-    // stroke-box and view-box compute to the initial value of mask-clip.
-    if (IsSVGStyleGeometryBox(aBox)) {
-      return StyleGeometryBox::Border;
-    }
   }
 
   return aBox;
 }
 
 /* static */ void
 nsCSSRendering::GetImageLayerClip(const nsStyleImageLayers::Layer& aLayer,
                                   nsIFrame* aForFrame, const nsStyleBorder& aBorder,