📄 rendertablecell.cpp
字号:
{ return table()->collapseBorders() ? borderHalfLeft(false) : RenderBlock::borderLeft();}int RenderTableCell::borderRight() const{ return table()->collapseBorders() ? borderHalfRight(false) : RenderBlock::borderRight();}int RenderTableCell::borderTop() const{ return table()->collapseBorders() ? borderHalfTop(false) : RenderBlock::borderTop();}int RenderTableCell::borderBottom() const{ return table()->collapseBorders() ? borderHalfBottom(false) : RenderBlock::borderBottom();}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::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::borderHalfBottom(bool outer) const{ CollapsedBorderValue border = collapsedBottomBorder(); if (border.exists()) return (border.width() + (outer ? 1 : 0)) / 2; return 0;}void RenderTableCell::paint(PaintInfo& paintInfo, int tx, int ty){ if (paintInfo.phase == PaintPhaseCollapsedTableBorders && style()->visibility() == VISIBLE) { tx += x(); ty += y(); int os = 2 * maximalOutlineSize(paintInfo.phase); if (ty - table()->outerBorderTop() < paintInfo.rect.bottom() + os && ty + height() + table()->outerBorderBottom() > paintInfo.rect.y() - os) paintCollapsedBorder(paintInfo.context, tx, ty, width(), height()); return; } RenderBlock::paint(paintInfo, tx, ty);}static EBorderStyle collapsedBorderStyle(EBorderStyle style){ if (style == OUTSET) return GROOVE; if (style == INSET) return RIDGE; return style;}struct CollapsedBorder { CollapsedBorderValue borderValue; BoxSide side; bool shouldPaint; int x1; int y1; int x2; int y2; EBorderStyle style;};class CollapsedBorders {public: CollapsedBorders() : m_count(0) { } 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++; } } CollapsedBorder* nextBorder() { for (int i = 0; i < m_count; i++) { if (m_borders[i].borderValue.exists() && m_borders[i].shouldPaint) { m_borders[i].shouldPaint = false; return &m_borders[i]; } } return 0; } CollapsedBorder m_borders[4]; int m_count;};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 RenderTableCell::collectBorderStyles(CollapsedBorderStyles& borderStyles) const{ bool rtl = table()->style()->direction() == RTL; addBorderStyle(borderStyles, collapsedLeftBorder(rtl)); addBorderStyle(borderStyles, collapsedRightBorder(rtl)); addBorderStyle(borderStyles, collapsedTopBorder()); addBorderStyle(borderStyles, collapsedBottomBorder());}static int compareBorderStylesForQSort(const void* pa, const void* pb){ const CollapsedBorderValue* a = static_cast<const CollapsedBorderValue*>(pa); const CollapsedBorderValue* b = static_cast<const CollapsedBorderValue*>(pb); if (*a == *b) return 0; CollapsedBorderValue borderWithHigherPrecedence = compareBorders(*a, *b); if (*a == borderWithHigherPrecedence) return 1; return -1;}void RenderTableCell::sortBorderStyles(CollapsedBorderStyles& borderStyles){ qsort(borderStyles.data(), borderStyles.size(), sizeof(CollapsedBorderValue), compareBorderStylesForQSort);}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); }}void RenderTableCell::paintBackgroundsBehindCell(PaintInfo& paintInfo, int tx, int ty, RenderObject* backgroundObject){ if (!backgroundObject) return; if (style()->visibility() != VISIBLE) return; RenderTable* tableElt = table(); if (!tableElt->collapseBorders() && style()->emptyCells() == HIDE && !firstChild()) return; if (backgroundObject != this) { tx += x(); ty += y(); } int w = width(); int h = height(); int my = max(ty, paintInfo.rect.y()); int end = min(paintInfo.rect.bottom(), ty + h); int mh = end - my; Color c = backgroundObject->style()->backgroundColor(); const FillLayer* bgLayer = backgroundObject->style()->backgroundLayers(); if (bgLayer->hasImage() || c.isValid()) { // We have to clip here because the background would paint // on top of the borders otherwise. This only matters for cells and rows. bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == this || backgroundObject == parent()) && tableElt->collapseBorders(); if (shouldClip) { IntRect clipRect(tx + borderLeft(), ty + borderTop(), w - borderLeft() - borderRight(), h - borderTop() - borderBottom()); paintInfo.context->save(); paintInfo.context->clip(clipRect); } paintFillLayers(paintInfo, c, bgLayer, my, mh, tx, ty, w, h); if (shouldClip) paintInfo.context->restore(); }}void RenderTableCell::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty){ RenderTable* tableElt = table(); if (!tableElt->collapseBorders() && style()->emptyCells() == HIDE && !firstChild()) return; int w = width(); int h = height(); if (style()->boxShadow()) paintBoxShadow(paintInfo.context, tx, ty, w, h, style()); // Paint our cell background. paintBackgroundsBehindCell(paintInfo, tx, ty, this); if (!style()->hasBorder() || tableElt->collapseBorders()) return; paintBorder(paintInfo.context, tx, ty, w, h, style());}void RenderTableCell::paintMask(PaintInfo& paintInfo, int tx, int ty){ if (style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask) return; RenderTable* tableElt = table(); if (!tableElt->collapseBorders() && style()->emptyCells() == HIDE && !firstChild()) return; int w = width(); int h = height(); int my = max(ty, paintInfo.rect.y()); int end = min(paintInfo.rect.bottom(), ty + h); int mh = end - my; paintMaskImages(paintInfo, my, mh, tx, ty, w, h);}} // namespace WebCore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -