int RenderTableCell::borderHalfBottom(bool outer) const { CollapsedBorderValue border = collapsedBottomBorder(); if (border.exists()) return (border.width() + (outer ? 1 : 0)) / 2; return 0; }
int RenderTableCell::borderHalfStart(bool outer) const { CollapsedBorderValue border = collapsedStartBorder(); if (border.exists()) return (border.width() + ((table()->style()->isLeftToRightDirection() ^ outer) ? 1 : 0)) / 2; // Give the extra pixel to top and left. return 0; }
int RenderTableCell::borderHalfRight(bool outer) const { CollapsedBorderValue border = collapsedRightBorder(table()->style()->direction() == RTL); if (border.exists()) return (border.width() + (outer ? 1 : 0)) / 2; return 0; }
int RenderTableCell::borderHalfTop(bool outer) const { CollapsedBorderValue border = collapsedTopBorder(); if (border.exists()) return (border.width() + (outer ? 0 : 1)) / 2; // Give the extra pixel to top and left. return 0; }
int RenderTableCell::borderHalfLeft(bool outer) const { CollapsedBorderValue border = collapsedLeftBorder(table()->style()->direction() == RTL); if (border.exists()) return (border.width() + (outer ? 0 : 1)) / 2; // Give the extra pixel to top and left. return 0; }
int RenderTableCell::borderHalfEnd(bool outer) const { CollapsedBorderValue border = collapsedEndBorder(); if (border.exists()) return (border.width() + ((table()->style()->isLeftToRightDirection() ^ outer) ? 0 : 1)) / 2; return 0; }
int RenderTableCell::borderHalfBefore(bool outer) const { CollapsedBorderValue border = collapsedBeforeBorder(); if (border.exists()) return (border.width() + ((table()->style()->isFlippedBlocksWritingMode() ^ outer) ? 0 : 1)) / 2; // Give the extra pixel to top and left. return 0; }
int RenderTableCell::borderHalfAfter(bool outer) const { CollapsedBorderValue border = collapsedAfterBorder(); if (border.exists()) return (border.width() + ((table()->style()->isFlippedBlocksWritingMode() ^ outer) ? 1 : 0)) / 2; return 0; }
static void addBorderStyle(RenderTableCell::CollapsedBorderStyles& borderStyles, CollapsedBorderValue borderValue) { if (!borderValue.exists()) return; size_t count = borderStyles.size(); for (size_t i = 0; i < count; ++i) if (borderStyles[i] == borderValue) return; borderStyles.append(borderValue); }
void addBorder(const CollapsedBorderValue& borderValue, BoxSide borderSide, bool shouldPaint, int x1, int y1, int x2, int y2, EBorderStyle borderStyle) { if (borderValue.exists() && shouldPaint) { m_borders[m_count].borderValue = borderValue; m_borders[m_count].side = borderSide; m_borders[m_count].shouldPaint = shouldPaint; m_borders[m_count].x1 = x1; m_borders[m_count].x2 = x2; m_borders[m_count].y1 = y1; m_borders[m_count].y2 = y2; m_borders[m_count].style = borderStyle; m_count++; } }
void RenderTableCell::readyWRATHWidgetCollapsedBorder(PaintedWidgetsOfWRATHHandle& handle, ContextOfWRATH *wrath_context, int tx, int ty, int w, int h) { RenderTableCell_ReadyWRATHWidgetCollapsedBorder *d(RenderTableCell_ReadyWRATHWidgetCollapsedBorder::object(this, handle)); ContextOfWRATH::AutoPushNode autoPushRoot(wrath_context, d->m_root_node); ContextOfWRATH::AutoPushNode autoPushSkip(wrath_context, d->m_skip_node); if (!table()->currentBorderStyle()) { d->m_skip_node.widget()->visible(false); return; } d->m_skip_node.widget()->visible(true); CollapsedBorderValue leftVal = collapsedLeftBorder(); CollapsedBorderValue rightVal = collapsedRightBorder(); CollapsedBorderValue topVal = collapsedTopBorder(); CollapsedBorderValue bottomVal = collapsedBottomBorder(); // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. int topWidth = topVal.width(); int bottomWidth = bottomVal.width(); int leftWidth = leftVal.width(); int rightWidth = rightVal.width(); tx -= leftWidth / 2; ty -= topWidth / 2; w += leftWidth / 2 + (rightWidth + 1) / 2; h += topWidth / 2 + (bottomWidth + 1) / 2; EBorderStyle topStyle = collapsedBorderStyle(topVal.style()); EBorderStyle bottomStyle = collapsedBorderStyle(bottomVal.style()); EBorderStyle leftStyle = collapsedBorderStyle(leftVal.style()); EBorderStyle rightStyle = collapsedBorderStyle(rightVal.style()); bool renderTop = topStyle > BHIDDEN && !topVal.isTransparent(); bool renderBottom = bottomStyle > BHIDDEN && !bottomVal.isTransparent(); bool renderLeft = leftStyle > BHIDDEN && !leftVal.isTransparent(); bool renderRight = rightStyle > BHIDDEN && !rightVal.isTransparent(); // We never paint diagonals at the joins. We simply let the border with the highest // precedence paint on top of borders with lower precedence. CollapsedBorders borders; borders.addBorder(topVal, BSTop, renderTop, tx, ty, tx + w, ty + topWidth, topStyle); borders.addBorder(bottomVal, BSBottom, renderBottom, tx, ty + h - bottomWidth, tx + w, ty + h, bottomStyle); borders.addBorder(leftVal, BSLeft, renderLeft, tx, ty, tx + leftWidth, ty + h, leftStyle); borders.addBorder(rightVal, BSRight, renderRight, tx + w - rightWidth, ty, tx + w, ty + h, rightStyle); /* [WRATH-DANGER]: These are not used at the moment const AffineTransform& currentCTM = graphicsContext->getCTM(); bool antialias = !currentCTM.isIdentityOrTranslationOrFlipped(); */ d->m_top.visible(false); d->m_bottom.visible(false); d->m_left.visible(false); d->m_right.visible(false); for (CollapsedBorder* border = borders.nextBorder(); border; border = borders.nextBorder()) { if (border->borderValue == *table()->currentBorderStyle()) { PaintedWidgetsOfWRATHHandle* bh = NULL; if (border->borderValue == topVal) bh = &d->m_top; else if (border->borderValue == bottomVal) bh = &d->m_bottom; else if (border->borderValue == leftVal) bh = &d->m_left; else if (border->borderValue == rightVal) bh = &d->m_right; else ASSERT_NOT_REACHED(); bh->visible(true); readyWRATHWidgetDrawLineForBoxSide(*bh, wrath_context, border->x1, border->y1, border->x2, border->y2, border->side, border->borderValue.color(), border->style, 0, 0, false /*antialias*/); } } }
CollapsedBorderValue RenderTableCell::collapsedBottomBorder() const { // For border top, we need to check, in order of precedence: // (1) Our bottom border. CollapsedBorderValue result = CollapsedBorderValue(&style()->borderBottom(), BCELL); RenderTableCell* nextCell = table()->cellBelow(this); if (nextCell) { // (2) A following cell's top border. result = compareBorders(result, CollapsedBorderValue(&nextCell->style()->borderTop(), BCELL)); if (!result.exists()) return result; } // (3) Our row's bottom border. (FIXME: Deal with rowspan!) result = compareBorders(result, CollapsedBorderValue(&parent()->style()->borderBottom(), BROW)); if (!result.exists()) return result; // (4) The next row's top border. if (nextCell) { result = compareBorders(result, CollapsedBorderValue(&nextCell->parent()->style()->borderTop(), BROW)); if (!result.exists()) return result; } // Now check row groups. RenderTableSection* currSection = section(); if (row() + rowSpan() >= currSection->numRows()) { // (5) Our row group's bottom border. result = compareBorders(result, CollapsedBorderValue(&currSection->style()->borderBottom(), BROWGROUP)); if (!result.exists()) return result; // (6) Following row group's top border. currSection = table()->sectionBelow(currSection); if (currSection) { result = compareBorders(result, CollapsedBorderValue(&currSection->style()->borderTop(), BROWGROUP)); if (!result.exists()) return result; } } if (!currSection) { // (8) Our column and column group's bottom borders. RenderTableCol* colElt = table()->colElement(col()); if (colElt) { result = compareBorders(result, CollapsedBorderValue(&colElt->style()->borderBottom(), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol()) { result = compareBorders(result, CollapsedBorderValue(&colElt->parent()->style()->borderBottom(), BCOLGROUP)); if (!result.exists()) return result; } } // (9) The table's bottom border. result = compareBorders(result, CollapsedBorderValue(&table()->style()->borderBottom(), BTABLE)); if (!result.exists()) return result; } return result; }
CollapsedBorderValue RenderTableCell::collapsedTopBorder() const { // For border top, we need to check, in order of precedence: // (1) Our top border. CollapsedBorderValue result = CollapsedBorderValue(&style()->borderTop(), BCELL); RenderTableCell* prevCell = table()->cellAbove(this); if (prevCell) { // (2) A previous cell's bottom border. result = compareBorders(CollapsedBorderValue(&prevCell->style()->borderBottom(), BCELL), result); if (!result.exists()) return result; } // (3) Our row's top border. result = compareBorders(result, CollapsedBorderValue(&parent()->style()->borderTop(), BROW)); if (!result.exists()) return result; // (4) The previous row's bottom border. if (prevCell) { RenderObject* prevRow = 0; if (prevCell->section() == section()) prevRow = parent()->previousSibling(); else prevRow = prevCell->section()->lastChild(); if (prevRow) { result = compareBorders(CollapsedBorderValue(&prevRow->style()->borderBottom(), BROW), result); if (!result.exists()) return result; } } // Now check row groups. RenderTableSection* currSection = section(); if (!row()) { // (5) Our row group's top border. result = compareBorders(result, CollapsedBorderValue(&currSection->style()->borderTop(), BROWGROUP)); if (!result.exists()) return result; // (6) Previous row group's bottom border. currSection = table()->sectionAbove(currSection); if (currSection) { result = compareBorders(CollapsedBorderValue(&currSection->style()->borderBottom(), BROWGROUP), result); if (!result.exists()) return result; } } if (!currSection) { // (8) Our column and column group's top borders. RenderTableCol* colElt = table()->colElement(col()); if (colElt) { result = compareBorders(result, CollapsedBorderValue(&colElt->style()->borderTop(), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol()) { result = compareBorders(result, CollapsedBorderValue(&colElt->parent()->style()->borderTop(), BCOLGROUP)); if (!result.exists()) return result; } } // (9) The table's top border. result = compareBorders(result, CollapsedBorderValue(&table()->style()->borderTop(), BTABLE)); if (!result.exists()) return result; } return result; }
CollapsedBorderValue RenderTableCell::collapsedAfterBorder() const { RenderTable* table = this->table(); // For after border, we need to check, in order of precedence: // (1) Our after border. int before = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderBeforeColor, table->style()->direction(), table->style()->writingMode()); int after = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderAfterColor, table->style()->direction(), table->style()->writingMode()); CollapsedBorderValue result = CollapsedBorderValue(&style()->borderAfter(), style()->visitedDependentColor(after), BCELL); RenderTableCell* nextCell = table->cellBelow(this); if (nextCell) { // (2) An after cell's before border. result = chooseBorder(result, CollapsedBorderValue(&nextCell->style()->borderBefore(), nextCell->style()->visitedDependentColor(before), BCELL)); if (!result.exists()) return result; } // (3) Our row's after border. (FIXME: Deal with rowspan!) result = chooseBorder(result, CollapsedBorderValue(&parent()->style()->borderAfter(), parent()->style()->visitedDependentColor(after), BROW)); if (!result.exists()) return result; // (4) The next row's before border. if (nextCell) { result = chooseBorder(result, CollapsedBorderValue(&nextCell->parent()->style()->borderBefore(), nextCell->parent()->style()->visitedDependentColor(before), BROW)); if (!result.exists()) return result; } // Now check row groups. RenderTableSection* currSection = section(); if (row() + rowSpan() >= currSection->numRows()) { // (5) Our row group's after border. result = chooseBorder(result, CollapsedBorderValue(&currSection->style()->borderAfter(), currSection->style()->visitedDependentColor(after), BROWGROUP)); if (!result.exists()) return result; // (6) Following row group's before border. currSection = table->sectionBelow(currSection); if (currSection) { result = chooseBorder(result, CollapsedBorderValue(&currSection->style()->borderBefore(), currSection->style()->visitedDependentColor(before), BROWGROUP)); if (!result.exists()) return result; } } if (!currSection) { // (8) Our column and column group's after borders. RenderTableCol* colElt = table->colElement(col()); if (colElt) { result = chooseBorder(result, CollapsedBorderValue(&colElt->style()->borderAfter(), colElt->style()->visitedDependentColor(after), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol()) { result = chooseBorder(result, CollapsedBorderValue(&colElt->parent()->style()->borderAfter(), colElt->parent()->style()->visitedDependentColor(after), BCOLGROUP)); if (!result.exists()) return result; } } // (9) The table's after border. result = chooseBorder(result, CollapsedBorderValue(&table->style()->borderAfter(), table->style()->visitedDependentColor(after), BTABLE)); if (!result.exists()) return result; } return result; }
void RenderTableCell::paintCollapsedBorder(GraphicsContext* graphicsContext, int tx, int ty, int w, int h) { if (!table()->currentBorderStyle()) return; bool rtl = table()->style()->direction() == RTL; CollapsedBorderValue leftVal = collapsedLeftBorder(rtl); CollapsedBorderValue rightVal = collapsedRightBorder(rtl); CollapsedBorderValue topVal = collapsedTopBorder(); CollapsedBorderValue bottomVal = collapsedBottomBorder(); // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. int topWidth = topVal.width(); int bottomWidth = bottomVal.width(); int leftWidth = leftVal.width(); int rightWidth = rightVal.width(); tx -= leftWidth / 2; ty -= topWidth / 2; w += leftWidth / 2 + (rightWidth + 1) / 2; h += topWidth / 2 + (bottomWidth + 1) / 2; EBorderStyle topStyle = collapsedBorderStyle(topVal.style()); EBorderStyle bottomStyle = collapsedBorderStyle(bottomVal.style()); EBorderStyle leftStyle = collapsedBorderStyle(leftVal.style()); EBorderStyle rightStyle = collapsedBorderStyle(rightVal.style()); bool renderTop = topStyle > BHIDDEN && !topVal.isTransparent(); bool renderBottom = bottomStyle > BHIDDEN && !bottomVal.isTransparent(); bool renderLeft = leftStyle > BHIDDEN && !leftVal.isTransparent(); bool renderRight = rightStyle > BHIDDEN && !rightVal.isTransparent(); // We never paint diagonals at the joins. We simply let the border with the highest // precedence paint on top of borders with lower precedence. CollapsedBorders borders; borders.addBorder(topVal, BSTop, renderTop, tx, ty, tx + w, ty + topWidth, topStyle); borders.addBorder(bottomVal, BSBottom, renderBottom, tx, ty + h - bottomWidth, tx + w, ty + h, bottomStyle); borders.addBorder(leftVal, BSLeft, renderLeft, tx, ty, tx + leftWidth, ty + h, leftStyle); borders.addBorder(rightVal, BSRight, renderRight, tx + w - rightWidth, ty, tx + w, ty + h, rightStyle); for (CollapsedBorder* border = borders.nextBorder(); border; border = borders.nextBorder()) { if (border->borderValue == *table()->currentBorderStyle()) drawLineForBoxSide(graphicsContext, border->x1, border->y1, border->x2, border->y2, border->side, border->borderValue.color(), style()->color(), border->style, 0, 0); } }
CollapsedBorderValue RenderTableCell::collapsedBeforeBorder() const { RenderTable* table = this->table(); // For before border, we need to check, in order of precedence: // (1) Our before border. int before = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderBeforeColor, table->style()->direction(), table->style()->writingMode()); int after = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderAfterColor, table->style()->direction(), table->style()->writingMode()); CollapsedBorderValue result = CollapsedBorderValue(&style()->borderBefore(), style()->visitedDependentColor(before), BCELL); RenderTableCell* prevCell = table->cellAbove(this); if (prevCell) { // (2) A before cell's after border. result = chooseBorder(CollapsedBorderValue(&prevCell->style()->borderAfter(), prevCell->style()->visitedDependentColor(after), BCELL), result); if (!result.exists()) return result; } // (3) Our row's before border. result = chooseBorder(result, CollapsedBorderValue(&parent()->style()->borderBefore(), parent()->style()->visitedDependentColor(before), BROW)); if (!result.exists()) return result; // (4) The previous row's after border. if (prevCell) { RenderObject* prevRow = 0; if (prevCell->section() == section()) prevRow = parent()->previousSibling(); else prevRow = prevCell->section()->lastChild(); if (prevRow) { result = chooseBorder(CollapsedBorderValue(&prevRow->style()->borderAfter(), prevRow->style()->visitedDependentColor(after), BROW), result); if (!result.exists()) return result; } } // Now check row groups. RenderTableSection* currSection = section(); if (!row()) { // (5) Our row group's before border. result = chooseBorder(result, CollapsedBorderValue(&currSection->style()->borderBefore(), currSection->style()->visitedDependentColor(before), BROWGROUP)); if (!result.exists()) return result; // (6) Previous row group's after border. currSection = table->sectionAbove(currSection); if (currSection) { result = chooseBorder(CollapsedBorderValue(&currSection->style()->borderAfter(), currSection->style()->visitedDependentColor(after), BROWGROUP), result); if (!result.exists()) return result; } } if (!currSection) { // (8) Our column and column group's before borders. RenderTableCol* colElt = table->colElement(col()); if (colElt) { result = chooseBorder(result, CollapsedBorderValue(&colElt->style()->borderBefore(), colElt->style()->visitedDependentColor(before), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol()) { result = chooseBorder(result, CollapsedBorderValue(&colElt->parent()->style()->borderBefore(), colElt->parent()->style()->visitedDependentColor(before), BCOLGROUP)); if (!result.exists()) return result; } } // (9) The table's before border. result = chooseBorder(result, CollapsedBorderValue(&table->style()->borderBefore(), table->style()->visitedDependentColor(before), BTABLE)); if (!result.exists()) return result; } return result; }
CollapsedBorderValue RenderTableCell::collapsedEndBorder() const { RenderTable* table = this->table(); bool isEndColumn = table->colToEffCol(col() + colSpan() - 1) == table->numEffCols() - 1; // For end border, we need to check, in order of precedence: // (1) Our end border. int start = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderStartColor, table->style()->direction(), table->style()->writingMode()); int end = CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderEndColor, table->style()->direction(), table->style()->writingMode()); CollapsedBorderValue result = CollapsedBorderValue(&style()->borderEnd(), style()->visitedDependentColor(end), BCELL); // (2) The start border of the following cell. if (!isEndColumn) { RenderTableCell* nextCell = table->cellAfter(this); if (nextCell && nextCell->style()) { CollapsedBorderValue startBorder = CollapsedBorderValue(&nextCell->style()->borderStart(), nextCell->style()->visitedDependentColor(start), BCELL); result = chooseBorder(result, startBorder); if (!result.exists()) return result; } } else { // (3) Our row's end border. result = chooseBorder(result, CollapsedBorderValue(&parent()->style()->borderEnd(), parent()->style()->visitedDependentColor(end), BROW)); if (!result.exists()) return result; // (4) Our row group's end border. result = chooseBorder(result, CollapsedBorderValue(§ion()->style()->borderEnd(), section()->style()->visitedDependentColor(end), BROWGROUP)); if (!result.exists()) return result; } // (5) Our column and column group's end borders. bool startColEdge; bool endColEdge; RenderTableCol* colElt = table->colElement(col() + colSpan() - 1, &startColEdge, &endColEdge); if (colElt && endColEdge) { result = chooseBorder(result, CollapsedBorderValue(&colElt->style()->borderEnd(), colElt->style()->visitedDependentColor(end), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol() && !colElt->nextSibling()) { result = chooseBorder(result, CollapsedBorderValue(&colElt->parent()->style()->borderEnd(), colElt->parent()->style()->visitedDependentColor(end), BCOLGROUP)); if (!result.exists()) return result; } } // (6) The start border of the next column. if (!isEndColumn) { colElt = table->colElement(col() + colSpan(), &startColEdge, &endColEdge); if (colElt && startColEdge) { CollapsedBorderValue startBorder = CollapsedBorderValue(&colElt->style()->borderStart(), colElt->style()->visitedDependentColor(start), BCOL); result = chooseBorder(result, startBorder); if (!result.exists()) return result; } } else { // (7) The table's end border. result = chooseBorder(result, CollapsedBorderValue(&table->style()->borderEnd(), table->style()->visitedDependentColor(end), BTABLE)); if (!result.exists()) return result; } return result; }
// The following rules apply for resolving conflicts and figuring out which border // to use. // (1) Borders with the 'border-style' of 'hidden' take precedence over all other conflicting // borders. Any border with this value suppresses all borders at this location. // (2) Borders with a style of 'none' have the lowest priority. Only if the border properties of all // the elements meeting at this edge are 'none' will the border be omitted (but note that 'none' is // the default value for the border style.) // (3) If none of the styles are 'hidden' and at least one of them is not 'none', then narrow borders // are discarded in favor of wider ones. If several have the same 'border-width' then styles are preferred // in this order: 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and the lowest: 'inset'. // (4) If border styles differ only in color, then a style set on a cell wins over one on a row, // which wins over a row group, column, column group and, lastly, table. It is undefined which color // is used when two elements of the same type disagree. static int compareBorders(const CollapsedBorderValue& border1, const CollapsedBorderValue& border2) { // Sanity check the values passed in. The null border have lowest priority. if (!border2.exists()) { if (!border1.exists()) return 0; return 1; } if (!border1.exists()) return -1; // Rule #1 above. if (border2.style() == BHIDDEN) { if (border1.style() == BHIDDEN) return 0; return -1; } if (border1.style() == BHIDDEN) return 1; // Rule #2 above. A style of 'none' has lowest priority and always loses to any other border. if (border2.style() == BNONE) { if (border1.style() == BNONE) return 0; return 1; } if (border1.style() == BNONE) return -1; // The first part of rule #3 above. Wider borders win. if (border1.width() != border2.width()) return border1.width() < border2.width() ? -1 : 1; // The borders have equal width. Sort by border style. if (border1.style() != border2.style()) return border1.style() < border2.style() ? -1 : 1; // The border have the same width and style. Rely on precedence (cell over row over row group, etc.) if (border1.precedence() == border2.precedence()) return 0; return border1.precedence() < border2.precedence() ? -1 : 1; }
CollapsedBorderValue RenderTableCell::collapsedRightBorder(bool rtl) const { RenderTable* tableElt = table(); bool rightmostColumn; if (rtl) rightmostColumn = col() == 0; else { int effCol = tableElt->colToEffCol(col() + colSpan() - 1); rightmostColumn = effCol == tableElt->numEffCols() - 1; } // For border right, we need to check, in order of precedence: // (1) Our right border. CollapsedBorderValue result = CollapsedBorderValue(&style()->borderRight(), BCELL); // (2) The left border of the cell to the right. if (!rightmostColumn) { RenderTableCell* nextCell = rtl ? tableElt->cellBefore(this) : tableElt->cellAfter(this); if (nextCell && nextCell->style()) { result = rtl ? compareBorders(CollapsedBorderValue(&nextCell->style()->borderLeft(), BCELL), result) : compareBorders(result, CollapsedBorderValue(&nextCell->style()->borderLeft(), BCELL)); if (!result.exists()) return result; } } else { // (3) Our row's right border. result = compareBorders(result, CollapsedBorderValue(&parent()->style()->borderRight(), BROW)); if (!result.exists()) return result; // (4) Our row group's right border. result = compareBorders(result, CollapsedBorderValue(§ion()->style()->borderRight(), BROWGROUP)); if (!result.exists()) return result; } // (5) Our column and column group's right borders. bool startColEdge; bool endColEdge; RenderTableCol* colElt = tableElt->colElement(col() + (rtl ? 0 : colSpan() - 1), &startColEdge, &endColEdge); if (colElt && (!rtl ? endColEdge : startColEdge)) { result = compareBorders(result, CollapsedBorderValue(&colElt->style()->borderRight(), BCOL)); if (!result.exists()) return result; if (colElt->parent()->isTableCol() && (!rtl ? !colElt->nextSibling() : !colElt->previousSibling())) { result = compareBorders(result, CollapsedBorderValue(&colElt->parent()->style()->borderRight(), BCOLGROUP)); if (!result.exists()) return result; } } // (6) The left border of the column to the right. if (!rightmostColumn) { colElt = tableElt->colElement(col() + (rtl ? -1 : colSpan()), &startColEdge, &endColEdge); if (colElt && (!rtl ? startColEdge : endColEdge)) { result = rtl ? compareBorders(CollapsedBorderValue(&colElt->style()->borderLeft(), BCOL), result) : compareBorders(result, CollapsedBorderValue(&colElt->style()->borderLeft(), BCOL)); if (!result.exists()) return result; } } else { // (7) The table's right border. result = compareBorders(result, CollapsedBorderValue(&tableElt->style()->borderRight(), BTABLE)); if (!result.exists()) return result; } return result; }
void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { ASSERT(paintInfo.phase == PaintPhaseCollapsedTableBorders); if (!paintInfo.shouldPaintWithinRoot(&m_renderTableCell) || m_renderTableCell.style()->visibility() != VISIBLE) return; LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); if (paintRect.y() - m_renderTableCell.table()->outerBorderTop() >= paintInfo.rect.maxY()) return; if (paintRect.maxY() + m_renderTableCell.table()->outerBorderBottom() <= paintInfo.rect.y()) return; if (!m_renderTableCell.table()->currentBorderValue()) return; RenderDrawingRecorder recorder(paintInfo.context, m_renderTableCell, paintInfo.phase, paintRect); if (recorder.canUseCachedDrawing()) return; const RenderStyle* styleForCellFlow = m_renderTableCell.styleForCellFlow(); CollapsedBorderValue leftVal = cachedCollapsedLeftBorder(styleForCellFlow); CollapsedBorderValue rightVal = cachedCollapsedRightBorder(styleForCellFlow); CollapsedBorderValue topVal = cachedCollapsedTopBorder(styleForCellFlow); CollapsedBorderValue bottomVal = cachedCollapsedBottomBorder(styleForCellFlow); // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. int topWidth = topVal.width(); int bottomWidth = bottomVal.width(); int leftWidth = leftVal.width(); int rightWidth = rightVal.width(); IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); EBorderStyle topStyle = collapsedBorderStyle(topVal.style()); EBorderStyle bottomStyle = collapsedBorderStyle(bottomVal.style()); EBorderStyle leftStyle = collapsedBorderStyle(leftVal.style()); EBorderStyle rightStyle = collapsedBorderStyle(rightVal.style()); bool renderTop = topStyle > BHIDDEN && !topVal.isTransparent(); bool renderBottom = bottomStyle > BHIDDEN && !bottomVal.isTransparent(); bool renderLeft = leftStyle > BHIDDEN && !leftVal.isTransparent(); bool renderRight = rightStyle > BHIDDEN && !rightVal.isTransparent(); // We never paint diagonals at the joins. We simply let the border with the highest // precedence paint on top of borders with lower precedence. CollapsedBorders borders; borders.addBorder(topVal, BSTop, renderTop, borderRect.x(), borderRect.y(), borderRect.maxX(), borderRect.y() + topWidth, topStyle); borders.addBorder(bottomVal, BSBottom, renderBottom, borderRect.x(), borderRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), bottomStyle); borders.addBorder(leftVal, BSLeft, renderLeft, borderRect.x(), borderRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), leftStyle); borders.addBorder(rightVal, BSRight, renderRight, borderRect.maxX() - rightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), rightStyle); GraphicsContext* graphicsContext = paintInfo.context; bool antialias = BoxPainter::shouldAntialiasLines(graphicsContext); for (CollapsedBorder* border = borders.nextBorder(); border; border = borders.nextBorder()) { if (border->borderValue.isSameIgnoringColor(*m_renderTableCell.table()->currentBorderValue())) { ObjectPainter::drawLineForBoxSide(graphicsContext, border->x1, border->y1, border->x2, border->y2, border->side, border->borderValue.color().resolve(m_renderTableCell.resolveColor(CSSPropertyColor)), border->style, 0, 0, antialias); } } }
void RenderTableCell::paintCollapsedBorder(GraphicsContext* graphicsContext, const IntRect& paintRect) { if (!table()->currentBorderStyle() || graphicsContext->paintingDisabled()) return; CollapsedBorderValue leftVal = collapsedLeftBorder(); CollapsedBorderValue rightVal = collapsedRightBorder(); CollapsedBorderValue topVal = collapsedTopBorder(); CollapsedBorderValue bottomVal = collapsedBottomBorder(); // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. int topWidth = topVal.width(); int bottomWidth = bottomVal.width(); int leftWidth = leftVal.width(); int rightWidth = rightVal.width(); int x = paintRect.x() - leftWidth / 2; int y = paintRect.y() - topWidth / 2; int w = paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2; int h = paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2; EBorderStyle topStyle = collapsedBorderStyle(topVal.style()); EBorderStyle bottomStyle = collapsedBorderStyle(bottomVal.style()); EBorderStyle leftStyle = collapsedBorderStyle(leftVal.style()); EBorderStyle rightStyle = collapsedBorderStyle(rightVal.style()); bool renderTop = topStyle > BHIDDEN && !topVal.isTransparent(); bool renderBottom = bottomStyle > BHIDDEN && !bottomVal.isTransparent(); bool renderLeft = leftStyle > BHIDDEN && !leftVal.isTransparent(); bool renderRight = rightStyle > BHIDDEN && !rightVal.isTransparent(); // We never paint diagonals at the joins. We simply let the border with the highest // precedence paint on top of borders with lower precedence. CollapsedBorders borders; borders.addBorder(topVal, BSTop, renderTop, x, y, x + w, y + topWidth, topStyle); borders.addBorder(bottomVal, BSBottom, renderBottom, x, y + h - bottomWidth, x + w, y + h, bottomStyle); borders.addBorder(leftVal, BSLeft, renderLeft, x, y, x + leftWidth, y + h, leftStyle); borders.addBorder(rightVal, BSRight, renderRight, x + w - rightWidth, y, x + w, y + h, rightStyle); const AffineTransform& currentCTM = graphicsContext->getCTM(); bool antialias = !currentCTM.isIdentityOrTranslationOrFlipped(); for (CollapsedBorder* border = borders.nextBorder(); border; border = borders.nextBorder()) { if (border->borderValue == *table()->currentBorderStyle()) drawLineForBoxSide(graphicsContext, border->x1, border->y1, border->x2, border->y2, border->side, border->borderValue.color(), border->style, 0, 0, antialias); } }
// The following rules apply for resolving conflicts and figuring out which border // to use. // (1) Borders with the 'border-style' of 'hidden' take precedence over all other conflicting // borders. Any border with this value suppresses all borders at this location. // (2) Borders with a style of 'none' have the lowest priority. Only if the border properties of all // the elements meeting at this edge are 'none' will the border be omitted (but note that 'none' is // the default value for the border style.) // (3) If none of the styles are 'hidden' and at least one of them is not 'none', then narrow borders // are discarded in favor of wider ones. If several have the same 'border-width' then styles are preferred // in this order: 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and the lowest: 'inset'. // (4) If border styles differ only in color, then a style set on a cell wins over one on a row, // which wins over a row group, column, column group and, lastly, table. It is undefined which color // is used when two elements of the same type disagree. static CollapsedBorderValue compareBorders(const CollapsedBorderValue& border1, const CollapsedBorderValue& border2) { // Sanity check the values passed in. If either is null, return the other. if (!border2.exists()) return border1; if (!border1.exists()) return border2; // Rule #1 above. if (border1.style() == BHIDDEN || border2.style() == BHIDDEN) return CollapsedBorderValue(); // No border should exist at this location. // Rule #2 above. A style of 'none' has lowest priority and always loses to any other border. if (border2.style() == BNONE) return border1; if (border1.style() == BNONE) return border2; // The first part of rule #3 above. Wider borders win. if (border1.width() != border2.width()) return border1.width() > border2.width() ? border1 : border2; // The borders have equal width. Sort by border style. if (border1.style() != border2.style()) return border1.style() > border2.style() ? border1 : border2; // The border have the same width and style. Rely on precedence (cell over row over row group, etc.) return border1.precedence >= border2.precedence ? border1 : border2; }