Consolidate table-cell vertical align code. (Bug 585715) r=bzbarsky a2.0=blocking+
authorL. David Baron <dbaron@dbaron.org>
Tue, 31 Aug 2010 12:05:12 -0400
changeset 51775 253d994413d97700dbea2bd165146a81c2615812
parent 51774 9dc831f46e4c35269c14848982b5206e1197b8eb
child 51776 7bb992392d3ac38ff82766ea783f66eed0b091b1
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs585715
milestone2.0b6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Consolidate table-cell vertical align code. (Bug 585715) r=bzbarsky a2.0=blocking+
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableCellFrame.h
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -551,31 +551,17 @@ void nsTableCellFrame::VerticallyAlignCh
 {
   const nsStyleTextReset* textStyle = GetStyleTextReset();
   /* It's the 'border-collapse' on the table that matters */
   nsMargin borderPadding = GetUsedBorderAndPadding();
 
   nscoord topInset = borderPadding.top;
   nscoord bottomInset = borderPadding.bottom;
 
-  // As per bug 10207, we map 'sub', 'super', 'text-top', 'text-bottom',
-  // length and percentage values to 'baseline'
-  // XXX It seems that we don't get to see length and percentage values here
-  //     because the Style System has already fixed the error and mapped them
-  //     to whatever is inherited from the parent, i.e, 'middle' in most cases.
-  PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_BASELINE;
-  if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
-    verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
-    if (verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_TOP &&
-        verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_MIDDLE &&
-        verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_BOTTOM)
-    {
-      verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_BASELINE;
-    }
-  }
+  PRUint8 verticalAlignFlags = GetVerticalAlign();
 
   nscoord height = mRect.height;
   nsIFrame* firstKid = mFrames.FirstChild();
   NS_ASSERTION(firstKid, "Frame construction error, a table cell always has an inner cell frame");
   nsRect kidRect = firstKid->GetRect();
   nscoord childHeight = kidRect.height;
 
   // Vertically align the child
@@ -628,35 +614,31 @@ void nsTableCellFrame::VerticallyAlignCh
   }
   if (HasView()) {
     nsContainerFrame::SyncFrameViewAfterReflow(PresContext(), this,
                                                GetView(),
                                                &desiredSize.mOverflowArea, 0);
   }
 }
 
-// As per bug 10207, we map 'sub', 'super', 'text-top', 'text-bottom',
-// length and percentage values to 'baseline'
-// XXX It seems that we don't get to see length and percentage values here
-//     because the Style System has already fixed the error and mapped them
-//     to whatever is inherited from the parent, i.e, 'middle' in most cases.
-PRBool
-nsTableCellFrame::HasVerticalAlignBaseline()
+// Per CSS 2.1, we map 'sub', 'super', 'text-top', 'text-bottom',
+// length, percentage, and calc() values to 'baseline'.
+PRUint8
+nsTableCellFrame::GetVerticalAlign() const
 {
-  const nsStyleTextReset* textStyle = GetStyleTextReset();
-  if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
-    PRUint8 verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
-    if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_TOP ||
-        verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_MIDDLE ||
-        verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_BOTTOM)
-    {
-      return PR_FALSE;
+  const nsStyleCoord& verticalAlign = GetStyleTextReset()->mVerticalAlign;
+  if (verticalAlign.GetUnit() == eStyleUnit_Enumerated) {
+    PRUint8 value = verticalAlign.GetIntValue();
+    if (value == NS_STYLE_VERTICAL_ALIGN_TOP ||
+        value == NS_STYLE_VERTICAL_ALIGN_MIDDLE ||
+        value == NS_STYLE_VERTICAL_ALIGN_BOTTOM) {
+      return value;
     }
   }
-  return PR_TRUE;
+  return NS_STYLE_VERTICAL_ALIGN_BASELINE;
 }
 
 PRBool
 nsTableCellFrame::CellHasVisibleContent(nscoord       height,
                                         nsTableFrame* tableFrame,
                                         nsIFrame*     kidFrame)
 {
   // see  http://www.w3.org/TR/CSS21/tables.html#empty-cells
--- a/layout/tables/nsTableCellFrame.h
+++ b/layout/tables/nsTableCellFrame.h
@@ -152,17 +152,26 @@ public:
   virtual PRBool IsContainingBlock() const;
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
   void VerticallyAlignChild(nscoord aMaxAscent);
 
-  PRBool HasVerticalAlignBaseline();
+  /*
+   * Get the value of vertical-align adjusted for CSS 2's rules for a
+   * table cell, which means the result is always
+   * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
+   */
+  PRUint8 GetVerticalAlign() const;
+
+  PRBool HasVerticalAlignBaseline() const {
+    return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
+  }
 
   PRBool CellHasVisibleContent(nscoord       height,
                                nsTableFrame* tableFrame,
                                nsIFrame*     kidFrame);
 
   /**
    * Get the first-line baseline of the cell relative to its top border
    * edge, as if the cell were vertically aligned to the top of the row.