Implement horizontal and vertical border-spacing

David Hyatt hyatt at apple.com
Sat Oct 18 01:00:50 CEST 2003


Index: khtml/css/cssparser.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/css/cssparser.cpp,v
retrieving revision 1.42
diff -u -p -r1.42 khtml/css/cssparser.cpp
--- khtml/css/cssparser.cpp	2003/10/01 23:27:11	1.42
+++ khtml/css/cssparser.cpp	2003/10/12 01:02:53
@@ -688,11 +688,27 @@ bool CSSParser::parseValue( int propId, 
 	valid_primitive = validUnit( value, FPercent|FLength, strict&(!nonCSSHint) );
 	break;
 
-    case CSS_PROP_BORDER_SPACING:
-	// ### should be able to have two values
-	valid_primitive = ( validUnit( value, FLength|FNonNeg, strict&(!nonCSSHint) ) );
-	break;
-
+    case CSS_PROP_BORDER_SPACING: {
+        const int properties[2] = { CSS_PROP__KHTML_HORIZONTAL_BORDER_SPACING,
+                                    CSS_PROP__KHTML_VERTICAL_BORDER_SPACING };
+        int num = valueList->numValues;
+        if (num == 1) {
+            if (!parseValue(properties[0], important)) return false;
+            CSSValueImpl* value = parsedProperties[numParsedProperties-1]->value();
+            addProperty(properties[1], value, important);
+            return true;
+        }
+        else if (num == 2) {
+            if (!parseValue(properties[0], important)) return false;
+            if (!parseValue(properties[1], important)) return false;
+            return true;
+        }
+        return false;
+    }
+    case CSS_PROP__KHTML_HORIZONTAL_BORDER_SPACING:
+    case CSS_PROP__KHTML_VERTICAL_BORDER_SPACING:
+        valid_primitive = validUnit(value, FLength|FNonNeg, strict&(!nonCSSHint));
+        break;
     case CSS_PROP_SCROLLBAR_FACE_COLOR:         // IE5.5
     case CSS_PROP_SCROLLBAR_SHADOW_COLOR:       // IE5.5
     case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:    // IE5.5
 
Index: khtml/css/cssproperties.in
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/css/cssproperties.in,v
retrieving revision 1.6
diff -u -p -r1.6 khtml/css/cssproperties.in
--- khtml/css/cssproperties.in	2003/07/24 22:07:45	1.6
+++ khtml/css/cssproperties.in	2003/10/12 01:02:54
@@ -24,6 +24,8 @@ background-position-y
 
 border-collapse
 border-spacing
+-khtml-horizontal-border-spacing
+-khtml-vertical-border-spacing
 border-top-color
 border-right-color
 border-bottom-color
Index: khtml/css/cssstyleselector.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/css/cssstyleselector.cpp,v
retrieving revision 1.96
diff -u -p -r1.96 khtml/css/cssstyleselector.cpp
--- khtml/css/cssstyleselector.cpp	2003/09/19 22:54:38	1.96
+++ khtml/css/cssstyleselector.cpp	2003/10/12 01:02:58
@@ -2143,15 +2143,24 @@ void CSSStyleSelector::applyRule( int id
       style->setBackgroundYPosition(l);
       break;
       }
-    case CSS_PROP_BORDER_SPACING:
-        {
-        if(!primitiveValue) break;
-        short spacing = 0;
-        spacing =  primitiveValue->computeLength(style, paintDeviceMetrics);
-        style->setBorderSpacing(spacing);
+    case CSS_PROP_BORDER_SPACING: {
+        if(value->cssValueType() != CSSValue::CSS_INHERIT || !parentNode) return;
+        style->setHorizontalBorderSpacing(parentStyle->horizontalBorderSpacing());
+        style->setVerticalBorderSpacing(parentStyle->verticalBorderSpacing());
         break;
-        }
-        // CSS2BorderSpacing
+    }
+    case CSS_PROP__KHTML_HORIZONTAL_BORDER_SPACING: {
+        if (!primitiveValue) break;
+        short spacing =  primitiveValue->computeLength(style, paintDeviceMetrics);
+        style->setHorizontalBorderSpacing(spacing);
+        break;
+    }
+    case CSS_PROP__KHTML_VERTICAL_BORDER_SPACING: {
+        if (!primitiveValue) break;
+        short spacing =  primitiveValue->computeLength(style, paintDeviceMetrics);
+        style->setVerticalBorderSpacing(spacing);
+        break;
+    }
     case CSS_PROP_CURSOR:
         // CSS2Cursor
         if(value->cssValueType() == CSSValue::CSS_INHERIT) {
Index: khtml/rendering/render_style.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/rendering/render_style.cpp,v
retrieving revision 1.28
diff -u -p -r1.28 khtml/rendering/render_style.cpp
--- khtml/rendering/render_style.cpp	2003/09/26 00:57:15	1.28
+++ khtml/rendering/render_style.cpp	2003/10/12 01:02:59
@@ -207,7 +207,8 @@ bool StyleCSS3InheritedData::shadowDataE
 
 StyleInheritedData::StyleInheritedData()
     : indent( Fixed ), line_height( -100, Percent ), style_image( 0 ),
-      cursor_image( 0 ), font(), color( Qt::black ), border_spacing( 0 )
+      cursor_image( 0 ), font(), color( Qt::black ), 
+      horizontal_border_spacing( 0 ), vertical_border_spacing( 0 )
 {
 }
 
@@ -220,7 +221,8 @@ StyleInheritedData::StyleInheritedData(c
       indent( o.indent ), line_height( o.line_height ), style_image( o.style_image ),
       cursor_image( o.cursor_image ), font( o.font ),
       color( o.color ),
-      border_spacing( o.border_spacing )
+      horizontal_border_spacing( o.horizontal_border_spacing ),
+      vertical_border_spacing( o.vertical_border_spacing )
 {
 }
 
@@ -229,11 +231,12 @@ bool StyleInheritedData::operator==(cons
     return
 	indent == o.indent &&
 	line_height == o.line_height &&
-	border_spacing == o.border_spacing &&
 	style_image == o.style_image &&
 	cursor_image == o.cursor_image &&
 	font == o.font &&
-	color == o.color;
+	color == o.color &&
+        horizontal_border_spacing == o.horizontal_border_spacing &&
+        vertical_border_spacing == o.vertical_border_spacing;
 
     // doesn't work because structs are not packed
     //return memcmp(this, &o, sizeof(*this))==0;
@@ -428,7 +431,8 @@ RenderStyle::Diff RenderStyle::diff( con
         !(inherited->style_image == other->inherited->style_image) ||
         !(inherited->cursor_image == other->inherited->cursor_image) ||
         !(inherited->font == other->inherited->font) ||
-        !(inherited->border_spacing == other->inherited->border_spacing) ||
+        !(inherited->horizontal_border_spacing == other->inherited->horizontal_border_spacing) ||
+        !(inherited->vertical_border_spacing == other->inherited->vertical_border_spacing) ||
         !(inherited_flags._box_direction == other->inherited_flags._box_direction) ||
         !(inherited_flags._visuallyOrdered == other->inherited_flags._visuallyOrdered) ||
         !(inherited_flags._htmlHacks == other->inherited_flags._htmlHacks) ||
Index: khtml/rendering/render_style.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/rendering/render_style.h,v
retrieving revision 1.31
diff -u -p -r1.31 khtml/rendering/render_style.h
--- khtml/rendering/render_style.h	2003/10/10 23:22:10	1.31
+++ khtml/rendering/render_style.h	2003/10/12 01:03:01
@@ -515,7 +515,8 @@ public:
     khtml::Font font;
     QColor color;
     
-    short border_spacing;
+    short horizontal_border_spacing;
+    short vertical_border_spacing;
 };
 
 
@@ -875,7 +876,8 @@ public:
 
     // returns true for collapsing borders, false for separate borders
     bool borderCollapse() const { return inherited_flags._border_collapse; }
-    short borderSpacing() const { return inherited->border_spacing; }
+    short horizontalBorderSpacing() const { return inherited->horizontal_border_spacing; }
+    short verticalBorderSpacing() const { return inherited->vertical_border_spacing; }
     EEmptyCell emptyCells() const { return inherited_flags._empty_cells; }
     ECaptionSide captionSide() const { return inherited_flags._caption_side; }
 
@@ -1017,7 +1019,8 @@ public:
     void setBackgroundYPosition(Length v) {  SET_VAR(background,y_position,v) }
 
     void setBorderCollapse(bool collapse) { inherited_flags._border_collapse = collapse; }
-    void setBorderSpacing(short v) { SET_VAR(inherited,border_spacing,v) }
+    void setHorizontalBorderSpacing(short v) { SET_VAR(inherited,horizontal_border_spacing,v) }
+    void setVerticalBorderSpacing(short v) { SET_VAR(inherited,vertical_border_spacing,v) }
     void setEmptyCells(EEmptyCell v) { inherited_flags._empty_cells = v; }
     void setCaptionSide(ECaptionSide v) { inherited_flags._caption_side = v; }
 
Index: khtml/rendering/render_table.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/rendering/render_table.cpp,v
retrieving revision 1.78
diff -u -p -r1.78 khtml/rendering/render_table.cpp
--- khtml/rendering/render_table.cpp	2003/10/10 23:22:10	1.78
+++ khtml/rendering/render_table.cpp	2003/10/12 01:03:03
@@ -59,7 +59,8 @@ RenderTable::RenderTable(DOM::NodeImpl* 
     rules = None;
     frame = Void;
     has_col_elems = false;
-    spacing = 0;
+    hspacing = 0;
+    vspacing = 0;
     padding = 0;
     needSectionRecalc = false;
     padding = 0;
@@ -89,8 +90,9 @@ void RenderTable::setStyle(RenderStyle *
     setReplaced(style()->display()==INLINE_TABLE);
 
     // In the collapsed border model, there is no cell spacing.
-    spacing = collapseBorders() ? 0 : style()->borderSpacing();
-    columnPos[0] = spacing;
+    hspacing = collapseBorders() ? 0 : style()->horizontalBorderSpacing();
+    vspacing = collapseBorders() ? 0 : style()->verticalBorderSpacing();
+    columnPos[0] = hspacing;
 
     if ( !tableLayout || style()->tableLayout() != oldTableLayout ) {
 	delete tableLayout;

@@ -940,7 +984,7 @@ void RenderTableSection::setCellWidths()
 		cspan -= table()->columns[endCol].span;
 		endCol++;
 	    }
-	    int w = columnPos[endCol] - columnPos[j] - table()->cellSpacing();
+	    int w = columnPos[endCol] - columnPos[j] - table()->hBorderSpacing();
 #ifdef DEBUG_LAYOUT
 	    kdDebug( 6040 ) << "setting width of cell " << cell << " " << cell->row() << "/" << cell->col() << " to " << w << " colspan=" << cell->colSpan() << " start=" << j << " end=" << endCol << endl;
 #endif
@@ -960,7 +1004,7 @@ void RenderTableSection::calcRowHeight()
     RenderTableCell *cell;
 
     int totalRows = grid.size();
-    int spacing = table()->cellSpacing();
+    int spacing = table()->vBorderSpacing();
 
     rowPos.resize( totalRows + 1 );
     rowPos[0] = spacing;
@@ -972,7 +1016,7 @@ void RenderTableSection::calcRowHeight()
 	int bdesc = 0;
 // 	qDebug("height of row %d is %d/%d", r, grid[r].height.value, grid[r].height.type );
 	int ch = grid[r].height.minWidth( 0 );
-	int pos = rowPos[ r+1 ] + ch + table()->cellSpacing();
+	int pos = rowPos[ r+1 ] + ch + spacing;
 
 	if ( pos > rowPos[r+1] )
 	    rowPos[r+1] = pos;
@@ -995,7 +1039,7 @@ void RenderTableSection::calcRowHeight()
 	    if (cell->height() > ch)
 		ch = cell->height();
 
-	    pos = rowPos[ indx ] + ch + table()->cellSpacing();
+            pos = rowPos[ indx ] + ch + spacing;
 
 	    if ( pos > rowPos[r+1] )
 		rowPos[r+1] = pos;
@@ -1019,7 +1063,7 @@ void RenderTableSection::calcRowHeight()
 	//do we have baseline aligned elements?
 	if (baseline) {
 	    // increase rowheight if baseline requires
-	    int bRowPos = baseline + bdesc  + table()->cellSpacing() ; // + 2*padding
+	    int bRowPos = baseline + bdesc  + spacing ; // + 2*padding
 	    if (rowPos[r+1]<bRowPos)
 		rowPos[r+1]=bRowPos;
 
@@ -1037,8 +1081,9 @@ int RenderTableSection::layoutRows( int 
     int rHeight;
     int rindx;
     int totalRows = grid.size();
-    int spacing = table()->cellSpacing();
-
+    int hspacing = table()->hBorderSpacing();
+    int vspacing = table()->vBorderSpacing();
+    
     if (toAdd && totalRows && (rowPos[totalRows] || !nextSibling())) {
 
 	int totalHeight = rowPos[totalRows] + toAdd;
@@ -1103,7 +1148,7 @@ int RenderTableSection::layoutRows( int 
         }
     }
 
-    int leftOffset = spacing;
+    int leftOffset = hspacing;
 
     int nEffCols = table()->numEffCols();
     for ( int r = 0; r < totalRows; r++ )
@@ -1121,7 +1166,7 @@ int RenderTableSection::layoutRows( int 
             if ( ( rindx = r-cell->rowSpan()+1 ) < 0 )
                 rindx = 0;
 
-            rHeight = rowPos[r+1] - rowPos[rindx] - spacing;
+            rHeight = rowPos[r+1] - rowPos[rindx] - vspacing;
             
             // Force percent height children to lay themselves out again.
             // This will cause, e.g., textareas to grow to

Index: khtml/rendering/render_table.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/rendering/render_table.h,v
retrieving revision 1.28
diff -u -p -r1.28 khtml/rendering/render_table.h
--- khtml/rendering/render_table.h	2003/10/10 23:22:10	1.28
+++ khtml/rendering/render_table.h	2003/10/12 01:03:03
@@ -84,10 +84,15 @@ public:
     int getColumnPos(int col) const
         { return columnPos[col]; }
 
-    int cellSpacing() const { return spacing; }
+    int hBorderSpacing() const { return hspacing; }
+    int vBorderSpacing() const { return vspacing; }
     
@@ -152,7 +157,7 @@ public:
 
     int bordersPaddingAndSpacing() const {
 	return borderLeft() + borderRight() + 
-               (collapseBorders() ? 0 : (paddingLeft() + paddingRight() + (numEffCols()+1) * cellSpacing()));
+               (collapseBorders() ? 0 : (paddingLeft() + paddingRight() + (numEffCols()+1) * hBorderSpacing()));
     }
 
     RenderTableCol *colElement( int col );
@@ -182,9 +187,11 @@ protected:
     Rules rules                 : 4;
 
     bool has_col_elems		: 1;
-    uint spacing                : 11;
-    uint padding		: 11;
+    uint padding		: 22;
     uint needSectionRecalc	: 1;
+    
+    short hspacing;
+    short vspacing;
 };
 
 // -------------------------------------------------------------------------
 
Index: khtml/rendering/table_layout.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/rendering/table_layout.cpp,v
retrieving revision 1.16
diff -u -p -r1.16 khtml/rendering/table_layout.cpp
--- khtml/rendering/table_layout.cpp	2003/10/10 22:03:14	1.16
+++ khtml/rendering/table_layout.cpp	2003/10/12 01:03:05
@@ -345,13 +345,13 @@ void FixedTableLayout::layout()
     }
     
     int pos = 0;
-    int spacing = table->cellSpacing();
+    int hspacing = table->hBorderSpacing();
     for ( int i = 0; i < nEffCols; i++ ) {
 #ifdef DEBUG_LAYOUT
 	qDebug("col %d: %d (width %d)", i, pos, calcWidth[i] );
 #endif
 	table->columnPos[i] = pos;
-	pos += calcWidth[i] + spacing;
+	pos += calcWidth[i] + hspacing;
     }
     table->columnPos[table->columnPos.size()-1] = pos;
 }
@@ -631,7 +631,7 @@ int AutoTableLayout::calcEffectiveWidth(
     int tMaxWidth = 0;
 
     unsigned int nEffCols = layoutStruct.size();
-    int spacing = table->cellSpacing();
+    int hspacing = table->hBorderSpacing();
 #ifdef DEBUG_LAYOUT
     qDebug("AutoTableLayout::calcEffectiveWidth for %d cols", nEffCols );
 #endif
@@ -653,8 +653,8 @@ int AutoTableLayout::calcEffectiveWidth(
 
 	int col = table->colToEffCol( cell->col() );
 	unsigned int lastCol = col;
-	int cMinWidth = cell->minWidth() + spacing;
-	int cMaxWidth = cell->maxWidth() + spacing;
+	int cMinWidth = cell->minWidth() + hspacing;
+	int cMaxWidth = cell->maxWidth() + hspacing;
 	int totalPercent = 0;
 	int minWidth = 0;
 	int maxWidth = 0;
@@ -703,8 +703,8 @@ int AutoTableLayout::calcEffectiveWidth(
 	    minWidth += layoutStruct[lastCol].effMinWidth;
 	    maxWidth += layoutStruct[lastCol].effMaxWidth;
 	    lastCol++;
-	    cMinWidth -= spacing;
-	    cMaxWidth -= spacing;
+	    cMinWidth -= hspacing;
+	    cMaxWidth -= hspacing;
 	}
 #ifdef DEBUG_LAYOUT
 	qDebug("    colspan cell %p at effCol %d, span %d, type %d, value %d cmin=%d min=%d fixedwidth=%d", cell, col, cSpan, w.type, w.value, cMinWidth, minWidth, fixedWidth );
@@ -1158,7 +1158,7 @@ void AutoTableLayout::layout()
 	qDebug("col %d: %d (width %d)", i, pos, layoutStruct[i].calcWidth );
 #endif
 	table->columnPos[i] = pos;
-	pos += layoutStruct[i].calcWidth + table->cellSpacing();
+	pos += layoutStruct[i].calcWidth + table->hBorderSpacing();
     }
     table->columnPos[table->columnPos.size()-1] = pos;
 
-------------- next part --------------


dave


More information about the Khtml-devel mailing list