Bug 670334 - Set a minimum size for mfence's fences and separators. r=karlt
authorJames Kitchener <jkitch.bug@internode.on.net>
Fri, 17 Oct 2014 18:01:00 +0200
changeset 211186 27bc3dbcaff532c3f91eb7eea4e4ff38152e7edd
parent 211185 f564fff0642cfbd82f7192d7e2d8b00610e16091
child 211187 6250e897cd5dc474167a52d80310800576bdd79c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskarlt
bugs670334
milestone36.0a1
Bug 670334 - Set a minimum size for mfence's fences and separators. r=karlt
layout/mathml/nsMathMLmfencedFrame.cpp
layout/reftests/mathml/mfenced-11-ref.html
layout/reftests/mathml/mfenced-11.html
layout/reftests/mathml/reftest.list
--- a/layout/mathml/nsMathMLmfencedFrame.cpp
+++ b/layout/mathml/nsMathMLmfencedFrame.cpp
@@ -179,16 +179,39 @@ nsMathMLmfencedFrame::BuildDisplayList(n
     mCloseChar->Display(aBuilder, this, aLists, count++);
   }
   
   for (int32_t i = 0; i < mSeparatorsCount; i++) {
     mSeparatorsChar[i].Display(aBuilder, this, aLists, count++);
   }
 }
 
+/* @param aMetrics is an IN/OUT.  Provide the current metrics for the mFenced
+          frame and it will be enlarged as necessary.
+For simplicity the width of the container is always incremented by the width
+of the nsMathMLChar.  As we only stretch fences and separators in the vertical
+direction, this has no impact on overall appearance.
+*/
+static void
+ApplyUnstretchedMetrics(nsPresContext*      aPresContext,
+                        nsRenderingContext& aRenderingContext,
+                        nsMathMLChar*       aMathMLChar,
+                        nsBoundingMetrics&  aMetrics,
+                        bool                aIsRTL)
+{
+  if (aMathMLChar && 0 < aMathMLChar->Length()) {
+    nsBoundingMetrics charSize;
+    aMathMLChar->Stretch(aPresContext, aRenderingContext,
+                         NS_STRETCH_DIRECTION_DEFAULT,
+                         aMetrics, // size is unimportant as we aren't stretching
+                         charSize, NS_STRETCH_NONE, aIsRTL);
+    aMetrics += charSize;
+  }
+}
+
 void
 nsMathMLmfencedFrame::Reflow(nsPresContext*          aPresContext,
                              nsHTMLReflowMetrics&     aDesiredSize,
                              const nsHTMLReflowState& aReflowState,
                              nsReflowStatus&          aStatus)
 {
   aDesiredSize.ClearSize();
   aDesiredSize.SetBlockStartAscent(0);
@@ -287,28 +310,39 @@ nsMathMLmfencedFrame::Reflow(nsPresConte
     childFrame = childFrame->GetNextSibling();
   }
 
   // bug 121748: for surrounding fences & separators, use a size that covers everything
   GetPreferredStretchSize(*aReflowState.rendContext,
                           STRETCH_CONSIDER_EMBELLISHMENTS,
                           stretchDir, containerSize);
 
+  bool isRTL = StyleVisibility()->mDirection;
+
+  // To achieve a minimum size of "1", the container should be enlarged by the
+  // unstretched metrics of the fences and separators.
+  ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext, mOpenChar,
+                          containerSize, isRTL);
+  for (i = 0; i < mSeparatorsCount; i++) {
+    ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext,
+                            &mSeparatorsChar[i], containerSize, isRTL);
+  }
+  ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext, mCloseChar,
+                          containerSize, isRTL);
+
   //////////////////////////////////////////
   // Prepare the opening fence, separators, and closing fence, and
   // adjust the origin of children.
 
   // we need to center around the axis
   nscoord delta = std::max(containerSize.ascent - axisHeight, 
                          containerSize.descent + axisHeight);
   containerSize.ascent = delta + axisHeight;
   containerSize.descent = delta - axisHeight;
 
-  bool isRTL = StyleVisibility()->mDirection;
-
   /////////////////
   // opening fence ...
   ReflowChar(aPresContext, *aReflowState.rendContext, mOpenChar,
              NS_MATHML_OPERATOR_FORM_PREFIX, font->mScriptLevel, 
              axisHeight, leading, em, containerSize, ascent, descent, isRTL);
   /////////////////
   // separators ...
   for (i = 0; i < mSeparatorsCount; i++) {
new file mode 100644
--- /dev/null
+++ b/layout/reftests/mathml/mfenced-11-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<html>
+  <body>
+
+    <!-- Size of fences when empty -->
+
+    <math>
+      <mrow>
+        <mo>(</mo>
+        <mn>.</mn>
+        <mo>)</mo>
+      </mrow>
+    </math>
+
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/mathml/mfenced-11.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+  <body>
+
+    <!-- Size of fences when empty -->
+
+    <math>
+      <mfenced>
+      <mn>.</mn>
+      </mfenced>
+    </math>
+
+  </body>
+</html>
--- a/layout/reftests/mathml/reftest.list
+++ b/layout/reftests/mathml/reftest.list
@@ -32,16 +32,17 @@ skip-if(B2G&&browserIsRemote) random-if(
 == mfenced-5b.xhtml mfenced-5-ref.xhtml
 == mfenced-5c.xhtml mfenced-5-ref.xhtml
 == mfenced-5d.xhtml mfenced-5-ref.xhtml
 == mfenced-6.html mfenced-6-ref.html
 == mfenced-7.html mfenced-7-ref.html
 != mfenced-8.html mfenced-8-ref.html
 == mfenced-9.html mfenced-9-ref.html
 fails-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == mfenced-10.html mfenced-10-ref.html # Windows versions without Cambria Math, see bug 670592
+fails-if(winWidget&&d2d) == mfenced-11.html mfenced-11-ref.html
 == mi-mathvariant-1.xhtml mi-mathvariant-1-ref.xhtml
 == mi-mathvariant-2.xhtml mi-mathvariant-2-ref.xhtml
 != mi-mathvariant-3.html mi-mathvariant-3-ref.html
 != non-spacing-accent-1.xhtml non-spacing-accent-1-ref.xhtml
 == overbar-width-1.xhtml overbar-width-1-ref.xhtml
 skip-if(B2G) == quotes-1.xhtml quotes-1-ref.xhtml
 != stretchy-underbar-1.xhtml stretchy-underbar-1-ref.xhtml
 != stretchy-munderover-1a.html stretchy-munderover-1-ref.html