diff --git a/mozilla/layout/generic/nsHTMLReflowState.h b/mozilla/layout/generic/nsHTMLReflowState.h
index 8ff992b2b56..f69a71074a6 100644
--- a/mozilla/layout/generic/nsHTMLReflowState.h
+++ b/mozilla/layout/generic/nsHTMLReflowState.h
@@ -59,12 +59,17 @@ struct nsStylePadding;
struct nsStyleText;
struct nsHypotheticalBox;
-#define NS_CSS_MINMAX(_value,_min,_max) \
- ((_value) < (_min) \
- ? (_min) \
- : ((_value) > (_max) \
- ? (_max) \
- : (_value)))
+template
+NumericType
+NS_CSS_MINMAX(NumericType aValue, NumericType aMinValue, NumericType aMaxValue)
+{
+ NumericType result = aValue;
+ if (aMaxValue < result)
+ result = aMaxValue;
+ if (aMinValue > result)
+ result = aMinValue;
+ return result;
+}
/**
* Constant used to indicate an unconstrained size.
diff --git a/mozilla/layout/reftests/bugs/413361-1-ref.html b/mozilla/layout/reftests/bugs/413361-1-ref.html
new file mode 100644
index 00000000000..463d45f2a8a
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/413361-1-ref.html
@@ -0,0 +1,13 @@
+
+
+testcase
+
+
+
+
+
+
diff --git a/mozilla/layout/reftests/bugs/413361-1.html b/mozilla/layout/reftests/bugs/413361-1.html
new file mode 100644
index 00000000000..a38daa53da8
--- /dev/null
+++ b/mozilla/layout/reftests/bugs/413361-1.html
@@ -0,0 +1,15 @@
+
+
+testcase
+
+
+
+
+
+
diff --git a/mozilla/layout/reftests/bugs/reftest.list b/mozilla/layout/reftests/bugs/reftest.list
index dcadc1c5d30..160c4c4a769 100644
--- a/mozilla/layout/reftests/bugs/reftest.list
+++ b/mozilla/layout/reftests/bugs/reftest.list
@@ -662,3 +662,4 @@ random == 403134-1.html 403134-1-ref.html # bug 405377
!= 409659-1c.html 409659-1-ref.html
== 409659-1d.html 409659-1-ref.html
== 411334-1.xml 411334-1-ref.xml
+== 413361-1.html 413361-1-ref.html