1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
|
/*
* Copyright (C) 1997 Martin Jones (mjones@kde.org)
* (C) 1997 Torben Weis (weis@kde.org)
* (C) 1998 Waldo Bastian (bastian@kde.org)
* (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "core/rendering/RenderTableCell.h"
#include "core/HTMLNames.h"
#include "core/css/StylePropertySet.h"
#include "core/html/HTMLTableCellElement.h"
#include "core/paint/TableCellPainter.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderTableCol.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/SubtreeLayoutScope.h"
#include "core/rendering/style/CollapsedBorderValue.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/TransformState.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
namespace blink {
using namespace HTMLNames;
struct SameSizeAsRenderTableCell : public RenderBlockFlow {
unsigned bitfields;
int paddings[2];
};
static_assert(sizeof(RenderTableCell) == sizeof(SameSizeAsRenderTableCell), "RenderTableCell should stay small");
static_assert(sizeof(CollapsedBorderValue) == 8, "CollapsedBorderValue should stay small");
RenderTableCell::RenderTableCell(Element* element)
: RenderBlockFlow(element)
, m_column(unsetColumnIndex)
, m_cellWidthChanged(false)
, m_intrinsicPaddingBefore(0)
, m_intrinsicPaddingAfter(0)
{
// We only update the flags when notified of DOM changes in colSpanOrRowSpanChanged()
// so we need to set their initial values here in case something asks for colSpan()/rowSpan() before then.
updateColAndRowSpanFlags();
}
void RenderTableCell::willBeRemovedFromTree()
{
RenderBlockFlow::willBeRemovedFromTree();
section()->setNeedsCellRecalc();
section()->removeCachedCollapsedBorders(this);
}
unsigned RenderTableCell::parseColSpanFromDOM() const
{
ASSERT(node());
if (isHTMLTableCellElement(*node()))
return std::min<unsigned>(toHTMLTableCellElement(*node()).colSpan(), maxColumnIndex);
return 1;
}
unsigned RenderTableCell::parseRowSpanFromDOM() const
{
ASSERT(node());
if (isHTMLTableCellElement(*node()))
return std::min<unsigned>(toHTMLTableCellElement(*node()).rowSpan(), maxRowIndex);
return 1;
}
void RenderTableCell::updateColAndRowSpanFlags()
{
// The vast majority of table cells do not have a colspan or rowspan,
// so we keep a bool to know if we need to bother reading from the DOM.
m_hasColSpan = node() && parseColSpanFromDOM() != 1;
m_hasRowSpan = node() && parseRowSpanFromDOM() != 1;
}
void RenderTableCell::colSpanOrRowSpanChanged()
{
ASSERT(node());
ASSERT(isHTMLTableCellElement(*node()));
updateColAndRowSpanFlags();
setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
if (parent() && section())
section()->setNeedsCellRecalc();
}
Length RenderTableCell::logicalWidthFromColumns(RenderTableCol* firstColForThisCell, Length widthFromStyle) const
{
ASSERT(firstColForThisCell && firstColForThisCell == table()->colElement(col()));
RenderTableCol* tableCol = firstColForThisCell;
unsigned colSpanCount = colSpan();
int colWidthSum = 0;
for (unsigned i = 1; i <= colSpanCount; i++) {
Length colWidth = tableCol->style()->logicalWidth();
// Percentage value should be returned only for colSpan == 1.
// Otherwise we return original width for the cell.
if (!colWidth.isFixed()) {
if (colSpanCount > 1)
return widthFromStyle;
return colWidth;
}
colWidthSum += colWidth.value();
tableCol = tableCol->nextColumn();
// If no next <col> tag found for the span we just return what we have for now.
if (!tableCol)
break;
}
// Column widths specified on <col> apply to the border box of the cell, see bug 8126.
// FIXME: Why is border/padding ignored in the negative width case?
if (colWidthSum > 0)
return Length(std::max(0, colWidthSum - borderAndPaddingLogicalWidth().ceil()), Fixed);
return Length(colWidthSum, Fixed);
}
void RenderTableCell::computePreferredLogicalWidths()
{
// The child cells rely on the grids up in the sections to do their computePreferredLogicalWidths work. Normally the sections are set up early, as table
// cells are added, but relayout can cause the cells to be freed, leaving stale pointers in the sections'
// grids. We must refresh those grids before the child cells try to use them.
table()->recalcSectionsIfNeeded();
RenderBlockFlow::computePreferredLogicalWidths();
if (node() && style()->autoWrap()) {
// See if nowrap was set.
Length w = styleOrColLogicalWidth();
const AtomicString& nowrap = toElement(node())->getAttribute(nowrapAttr);
if (!nowrap.isNull() && w.isFixed()) {
// Nowrap is set, but we didn't actually use it because of the
// fixed width set on the cell. Even so, it is a WinIE/Moz trait
// to make the minwidth of the cell into the fixed width. They do this
// even in strict mode, so do not make this a quirk. Affected the top
// of hiptop.com.
m_minPreferredLogicalWidth = std::max<LayoutUnit>(w.value(), m_minPreferredLogicalWidth);
}
}
}
void RenderTableCell::addLayerHitTestRects(LayerHitTestRects& layerRects, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
{
LayoutPoint adjustedLayerOffset = layerOffset;
// RenderTableCell's location includes the offset of it's containing RenderTableRow, so
// we need to subtract that again here (as for RenderTableCell::offsetFromContainer.
if (parent())
adjustedLayerOffset -= parentBox()->locationOffset();
RenderBox::addLayerHitTestRects(layerRects, currentLayer, adjustedLayerOffset, containerRect);
}
void RenderTableCell::computeIntrinsicPadding(int rowHeight, SubtreeLayoutScope& layouter)
{
int oldIntrinsicPaddingBefore = intrinsicPaddingBefore();
int oldIntrinsicPaddingAfter = intrinsicPaddingAfter();
int logicalHeightWithoutIntrinsicPadding = pixelSnappedLogicalHeight() - oldIntrinsicPaddingBefore - oldIntrinsicPaddingAfter;
int intrinsicPaddingBefore = 0;
switch (style()->verticalAlign()) {
case SUB:
case SUPER:
case TEXT_TOP:
case TEXT_BOTTOM:
case LENGTH:
case BASELINE: {
LayoutUnit baseline = cellBaselinePosition();
if (baseline > borderBefore() + paddingBefore())
intrinsicPaddingBefore = section()->rowBaseline(rowIndex()) - (baseline - oldIntrinsicPaddingBefore);
break;
}
case TOP:
break;
case MIDDLE:
intrinsicPaddingBefore = (rowHeight - logicalHeightWithoutIntrinsicPadding) / 2;
break;
case BOTTOM:
intrinsicPaddingBefore = rowHeight - logicalHeightWithoutIntrinsicPadding;
break;
case BASELINE_MIDDLE:
break;
}
int intrinsicPaddingAfter = rowHeight - logicalHeightWithoutIntrinsicPadding - intrinsicPaddingBefore;
setIntrinsicPaddingBefore(intrinsicPaddingBefore);
setIntrinsicPaddingAfter(intrinsicPaddingAfter);
// FIXME: Changing an intrinsic padding shouldn't trigger a relayout as it only shifts the cell inside the row but
// doesn't change the logical height.
if (intrinsicPaddingBefore != oldIntrinsicPaddingBefore || intrinsicPaddingAfter != oldIntrinsicPaddingAfter)
layouter.setNeedsLayout(this);
}
void RenderTableCell::updateLogicalWidth()
{
}
void RenderTableCell::setCellLogicalWidth(int tableLayoutLogicalWidth, SubtreeLayoutScope& layouter)
{
if (tableLayoutLogicalWidth == logicalWidth())
return;
layouter.setNeedsLayout(this);
setLogicalWidth(tableLayoutLogicalWidth);
setCellWidthChanged(true);
}
void RenderTableCell::layout()
{
ASSERT(needsLayout());
int oldCellBaseline = cellBaselinePosition();
layoutBlock(cellWidthChanged());
// If we have replaced content, the intrinsic height of our content may have changed since the last time we laid out. If that's the case the intrinsic padding we used
// for layout (the padding required to push the contents of the cell down to the row's baseline) is included in our new height and baseline and makes both
// of them wrong. So if our content's intrinsic height has changed push the new content up into the intrinsic padding and relayout so that the rest of
// table and row layout can use the correct baseline and height for this cell.
if (isBaselineAligned() && section()->rowBaseline(rowIndex()) && cellBaselinePosition() > section()->rowBaseline(rowIndex())) {
int newIntrinsicPaddingBefore = std::max<LayoutUnit>(0, intrinsicPaddingBefore() - std::max<LayoutUnit>(0, cellBaselinePosition() - oldCellBaseline));
setIntrinsicPaddingBefore(newIntrinsicPaddingBefore);
SubtreeLayoutScope layouter(*this);
layouter.setNeedsLayout(this);
layoutBlock(cellWidthChanged());
}
// FIXME: This value isn't the intrinsic content logical height, but we need
// to update the value as its used by flexbox layout. crbug.com/367324
setIntrinsicContentLogicalHeight(contentLogicalHeight());
setCellWidthChanged(false);
}
LayoutUnit RenderTableCell::paddingTop() const
{
int result = computedCSSPaddingTop();
if (!isHorizontalWritingMode())
return result;
return result + (style()->writingMode() == TopToBottomWritingMode ? intrinsicPaddingBefore() : intrinsicPaddingAfter());
}
LayoutUnit RenderTableCell::paddingBottom() const
{
int result = computedCSSPaddingBottom();
if (!isHorizontalWritingMode())
return result;
return result + (style()->writingMode() == TopToBottomWritingMode ? intrinsicPaddingAfter() : intrinsicPaddingBefore());
}
LayoutUnit RenderTableCell::paddingLeft() const
{
int result = computedCSSPaddingLeft();
if (isHorizontalWritingMode())
return result;
return result + (style()->writingMode() == LeftToRightWritingMode ? intrinsicPaddingBefore() : intrinsicPaddingAfter());
}
LayoutUnit RenderTableCell::paddingRight() const
{
int result = computedCSSPaddingRight();
if (isHorizontalWritingMode())
return result;
return result + (style()->writingMode() == LeftToRightWritingMode ? intrinsicPaddingAfter() : intrinsicPaddingBefore());
}
LayoutUnit RenderTableCell::paddingBefore() const
{
return static_cast<int>(computedCSSPaddingBefore()) + intrinsicPaddingBefore();
}
LayoutUnit RenderTableCell::paddingAfter() const
{
return static_cast<int>(computedCSSPaddingAfter()) + intrinsicPaddingAfter();
}
void RenderTableCell::setOverrideLogicalContentHeightFromRowHeight(LayoutUnit rowHeight)
{
clearIntrinsicPadding();
setOverrideLogicalContentHeight(std::max<LayoutUnit>(0, rowHeight - borderAndPaddingLogicalHeight()));
}
LayoutSize RenderTableCell::offsetFromContainer(const RenderObject* o, const LayoutPoint& point, bool* offsetDependsOnPoint) const
{
ASSERT(o == container());
LayoutSize offset = RenderBlockFlow::offsetFromContainer(o, point, offsetDependsOnPoint);
if (parent())
offset -= parentBox()->locationOffset();
return offset;
}
LayoutRect RenderTableCell::clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paintInvalidationState) const
{
// If the table grid is dirty, we cannot get reliable information about adjoining cells,
// so we ignore outside borders. This should not be a problem because it means that
// the table is going to recalculate the grid, relayout and issue a paint invalidation of its current rect, which
// includes any outside borders of this cell.
if (!table()->collapseBorders() || table()->needsSectionRecalc())
return RenderBlockFlow::clippedOverflowRectForPaintInvalidation(paintInvalidationContainer, paintInvalidationState);
bool rtl = !styleForCellFlow()->isLeftToRightDirection();
int outlineSize = style()->outlineSize();
int left = std::max(borderHalfLeft(true), outlineSize);
int right = std::max(borderHalfRight(true), outlineSize);
int top = std::max(borderHalfTop(true), outlineSize);
int bottom = std::max(borderHalfBottom(true), outlineSize);
if ((left && !rtl) || (right && rtl)) {
if (RenderTableCell* before = table()->cellBefore(this)) {
top = std::max(top, before->borderHalfTop(true));
bottom = std::max(bottom, before->borderHalfBottom(true));
}
}
if ((left && rtl) || (right && !rtl)) {
if (RenderTableCell* after = table()->cellAfter(this)) {
top = std::max(top, after->borderHalfTop(true));
bottom = std::max(bottom, after->borderHalfBottom(true));
}
}
if (top) {
if (RenderTableCell* above = table()->cellAbove(this)) {
left = std::max(left, above->borderHalfLeft(true));
right = std::max(right, above->borderHalfRight(true));
}
}
if (bottom) {
if (RenderTableCell* below = table()->cellBelow(this)) {
left = std::max(left, below->borderHalfLeft(true));
right = std::max(right, below->borderHalfRight(true));
}
}
LayoutPoint location(std::max<LayoutUnit>(left, -visualOverflowRect().x()), std::max<LayoutUnit>(top, -visualOverflowRect().y()));
LayoutRect r(-location.x(), -location.y(), location.x() + std::max(size().width() + right, visualOverflowRect().maxX()), location.y() + std::max(size().height() + bottom, visualOverflowRect().maxY()));
mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvalidationState);
return r;
}
void RenderTableCell::mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect& r, const PaintInvalidationState* paintInvalidationState) const
{
if (paintInvalidationContainer == this)
return;
r.setY(r.y());
if ((!paintInvalidationState || !paintInvalidationState->canMapToContainer(paintInvalidationContainer)) && parent())
r.moveBy(-parentBox()->location()); // Rows are in the same coordinate space, so don't add their offset in.
RenderBlockFlow::mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvalidationState);
}
LayoutUnit RenderTableCell::cellBaselinePosition() const
{
// <http://www.w3.org/TR/2007/CR-CSS21-20070719/tables.html#height-layout>: The baseline of a cell is the baseline of
// the first in-flow line box in the cell, or the first in-flow table-row in the cell, whichever comes first. If there
// is no such line box or table-row, the baseline is the bottom of content edge of the cell box.
LayoutUnit firstLineBaseline = firstLineBoxBaseline();
if (firstLineBaseline != -1)
return firstLineBaseline;
return paddingBefore() + borderBefore() + contentLogicalHeight();
}
void RenderTableCell::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
ASSERT(style()->display() == TABLE_CELL);
RenderBlockFlow::styleDidChange(diff, oldStyle);
setHasBoxDecorationBackground(true);
if (parent() && section() && oldStyle && style()->height() != oldStyle->height())
section()->rowLogicalHeightChanged(row());
// Our intrinsic padding pushes us down to align with the baseline of other cells on the row. If our vertical-align
// has changed then so will the padding needed to align with other cells - clear it so we can recalculate it from scratch.
if (oldStyle && style()->verticalAlign() != oldStyle->verticalAlign())
clearIntrinsicPadding();
// If border was changed, notify table.
if (parent()) {
RenderTable* table = this->table();
if (table && !table->selfNeedsLayout() && !table->normalChildNeedsLayout()&& oldStyle && oldStyle->border() != style()->border())
table->invalidateCollapsedBorders();
}
}
// 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;
}
static CollapsedBorderValue chooseBorder(const CollapsedBorderValue& border1, const CollapsedBorderValue& border2)
{
const CollapsedBorderValue& border = compareBorders(border1, border2) < 0 ? border2 : border1;
return border.style() == BHIDDEN ? CollapsedBorderValue() : border;
}
bool RenderTableCell::hasStartBorderAdjoiningTable() const
{
bool isStartColumn = !col();
bool isEndColumn = table()->colToEffCol(col() + colSpan() - 1) == table()->numEffCols() - 1;
bool hasSameDirectionAsTable = hasSameDirectionAs(table());
// The table direction determines the row direction. In mixed directionality, we cannot guarantee that
// we have a common border with the table (think a ltr table with rtl start cell).
return (isStartColumn && hasSameDirectionAsTable) || (isEndColumn && !hasSameDirectionAsTable);
}
bool RenderTableCell::hasEndBorderAdjoiningTable() const
{
bool isStartColumn = !col();
bool isEndColumn = table()->colToEffCol(col() + colSpan() - 1) == table()->numEffCols() - 1;
bool hasSameDirectionAsTable = hasSameDirectionAs(table());
// The table direction determines the row direction. In mixed directionality, we cannot guarantee that
// we have a common border with the table (think a ltr table with ltr end cell).
return (isStartColumn && !hasSameDirectionAsTable) || (isEndColumn && hasSameDirectionAsTable);
}
CollapsedBorderValue RenderTableCell::collapsedStartBorder(IncludeBorderColorOrNot includeColor) const
{
CollapsedBorderValue result = computeCollapsedStartBorder(includeColor);
if (includeColor)
section()->setCachedCollapsedBorder(this, CBSStart, result);
return result;
}
CollapsedBorderValue RenderTableCell::computeCollapsedStartBorder(IncludeBorderColorOrNot includeColor) const
{
RenderTable* table = this->table();
// For the start border, we need to check, in order of precedence:
// (1) Our start border.
int startColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderStartColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
int endColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderEndColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
CollapsedBorderValue result(style()->borderStart(), includeColor ? resolveColor(startColorProperty) : Color(), BCELL);
// (2) The end border of the preceding cell.
RenderTableCell* cellBefore = table->cellBefore(this);
if (cellBefore) {
CollapsedBorderValue cellBeforeAdjoiningBorder = CollapsedBorderValue(cellBefore->borderAdjoiningCellAfter(this), includeColor ? cellBefore->resolveColor(endColorProperty) : Color(), BCELL);
// |result| should be the 2nd argument as |cellBefore| should win in case of equality per CSS 2.1 (Border conflict resolution, point 4).
result = chooseBorder(cellBeforeAdjoiningBorder, result);
if (!result.exists())
return result;
}
bool startBorderAdjoinsTable = hasStartBorderAdjoiningTable();
if (startBorderAdjoinsTable) {
// (3) Our row's start border.
result = chooseBorder(result, CollapsedBorderValue(row()->borderAdjoiningStartCell(this), includeColor ? parent()->resolveColor(startColorProperty) : Color(), BROW));
if (!result.exists())
return result;
// (4) Our row group's start border.
result = chooseBorder(result, CollapsedBorderValue(section()->borderAdjoiningStartCell(this), includeColor ? section()->resolveColor(startColorProperty) : Color(), BROWGROUP));
if (!result.exists())
return result;
}
// (5) Our column and column group's start borders.
bool startColEdge;
bool endColEdge;
if (RenderTableCol* colElt = table->colElement(col(), &startColEdge, &endColEdge)) {
if (colElt->isTableColumnGroup() && startColEdge) {
// The |colElt| is a column group and is also the first colgroup (in case of spanned colgroups).
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellStartBorder(this), includeColor ? colElt->resolveColor(startColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
} else if (!colElt->isTableColumnGroup()) {
// We first consider the |colElt| and irrespective of whether it is a spanned col or not, we apply
// its start border. This is as per HTML5 which states that: "For the purposes of the CSS table model,
// the col element is expected to be treated as if it was present as many times as its span attribute specifies".
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellStartBorder(this), includeColor ? colElt->resolveColor(startColorProperty) : Color(), BCOL));
if (!result.exists())
return result;
// Next, apply the start border of the enclosing colgroup but only if it is adjacent to the cell's edge.
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroupIfAdjacentBefore()) {
result = chooseBorder(result, CollapsedBorderValue(enclosingColumnGroup->borderAdjoiningCellStartBorder(this), includeColor ? enclosingColumnGroup->resolveColor(startColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
}
}
}
// (6) The end border of the preceding column.
if (cellBefore) {
if (RenderTableCol* colElt = table->colElement(col() - 1, &startColEdge, &endColEdge)) {
if (colElt->isTableColumnGroup() && endColEdge) {
// The element is a colgroup and is also the last colgroup (in case of spanned colgroups).
result = chooseBorder(CollapsedBorderValue(colElt->borderAdjoiningCellAfter(this), includeColor ? colElt->resolveColor(endColorProperty) : Color(), BCOLGROUP), result);
if (!result.exists())
return result;
} else if (colElt->isTableColumn()) {
// Resolve the collapsing border against the col's border ignoring any 'span' as per HTML5.
result = chooseBorder(CollapsedBorderValue(colElt->borderAdjoiningCellAfter(this), includeColor ? colElt->resolveColor(endColorProperty) : Color(), BCOL), result);
if (!result.exists())
return result;
// Next, if the previous col has a parent colgroup then its end border should be applied
// but only if it is adjacent to the cell's edge.
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroupIfAdjacentAfter()) {
result = chooseBorder(CollapsedBorderValue(enclosingColumnGroup->borderAdjoiningCellEndBorder(this), includeColor ? enclosingColumnGroup->resolveColor(endColorProperty) : Color(), BCOLGROUP), result);
if (!result.exists())
return result;
}
}
}
}
if (startBorderAdjoinsTable) {
// (7) The table's start border.
result = chooseBorder(result, CollapsedBorderValue(table->tableStartBorderAdjoiningCell(this), includeColor ? table->resolveColor(startColorProperty) : Color(), BTABLE));
if (!result.exists())
return result;
}
return result;
}
CollapsedBorderValue RenderTableCell::collapsedEndBorder(IncludeBorderColorOrNot includeColor) const
{
CollapsedBorderValue result = computeCollapsedEndBorder(includeColor);
if (includeColor)
section()->setCachedCollapsedBorder(this, CBSEnd, result);
return result;
}
CollapsedBorderValue RenderTableCell::computeCollapsedEndBorder(IncludeBorderColorOrNot includeColor) const
{
RenderTable* table = this->table();
// Note: We have to use the effective column information instead of whether we have a cell after as a table doesn't
// have to be regular (any row can have less cells than the total cell count).
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 startColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderStartColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
int endColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderEndColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
CollapsedBorderValue result = CollapsedBorderValue(style()->borderEnd(), includeColor ? resolveColor(endColorProperty) : Color(), BCELL);
// (2) The start border of the following cell.
if (!isEndColumn) {
if (RenderTableCell* cellAfter = table->cellAfter(this)) {
CollapsedBorderValue cellAfterAdjoiningBorder = CollapsedBorderValue(cellAfter->borderAdjoiningCellBefore(this), includeColor ? cellAfter->resolveColor(startColorProperty) : Color(), BCELL);
result = chooseBorder(result, cellAfterAdjoiningBorder);
if (!result.exists())
return result;
}
}
bool endBorderAdjoinsTable = hasEndBorderAdjoiningTable();
if (endBorderAdjoinsTable) {
// (3) Our row's end border.
result = chooseBorder(result, CollapsedBorderValue(row()->borderAdjoiningEndCell(this), includeColor ? parent()->resolveColor(endColorProperty) : Color(), BROW));
if (!result.exists())
return result;
// (4) Our row group's end border.
result = chooseBorder(result, CollapsedBorderValue(section()->borderAdjoiningEndCell(this), includeColor ? section()->resolveColor(endColorProperty) : Color(), BROWGROUP));
if (!result.exists())
return result;
}
// (5) Our column and column group's end borders.
bool startColEdge;
bool endColEdge;
if (RenderTableCol* colElt = table->colElement(col() + colSpan() - 1, &startColEdge, &endColEdge)) {
if (colElt->isTableColumnGroup() && endColEdge) {
// The element is a colgroup and is also the last colgroup (in case of spanned colgroups).
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellEndBorder(this), includeColor ? colElt->resolveColor(endColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
} else if (!colElt->isTableColumnGroup()) {
// First apply the end border of the column irrespective of whether it is spanned or not. This is as per
// HTML5 which states that: "For the purposes of the CSS table model, the col element is expected to be
// treated as if it was present as many times as its span attribute specifies".
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellEndBorder(this), includeColor ? colElt->resolveColor(endColorProperty) : Color(), BCOL));
if (!result.exists())
return result;
// Next, if it has a parent colgroup then we apply its end border but only if it is adjacent to the cell.
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroupIfAdjacentAfter()) {
result = chooseBorder(result, CollapsedBorderValue(enclosingColumnGroup->borderAdjoiningCellEndBorder(this), includeColor ? enclosingColumnGroup->resolveColor(endColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
}
}
}
// (6) The start border of the next column.
if (!isEndColumn) {
if (RenderTableCol* colElt = table->colElement(col() + colSpan(), &startColEdge, &endColEdge)) {
if (colElt->isTableColumnGroup() && startColEdge) {
// This case is a colgroup without any col, we only compute it if it is adjacent to the cell's edge.
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellBefore(this), includeColor ? colElt->resolveColor(startColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
} else if (colElt->isTableColumn()) {
// Resolve the collapsing border against the col's border ignoring any 'span' as per HTML5.
result = chooseBorder(result, CollapsedBorderValue(colElt->borderAdjoiningCellBefore(this), includeColor ? colElt->resolveColor(startColorProperty) : Color(), BCOL));
if (!result.exists())
return result;
// If we have a parent colgroup, resolve the border only if it is adjacent to the cell.
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroupIfAdjacentBefore()) {
result = chooseBorder(result, CollapsedBorderValue(enclosingColumnGroup->borderAdjoiningCellStartBorder(this), includeColor ? enclosingColumnGroup->resolveColor(startColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
}
}
}
}
if (endBorderAdjoinsTable) {
// (7) The table's end border.
result = chooseBorder(result, CollapsedBorderValue(table->tableEndBorderAdjoiningCell(this), includeColor ? table->resolveColor(endColorProperty) : Color(), BTABLE));
if (!result.exists())
return result;
}
return result;
}
CollapsedBorderValue RenderTableCell::collapsedBeforeBorder(IncludeBorderColorOrNot includeColor) const
{
CollapsedBorderValue result = computeCollapsedBeforeBorder(includeColor);
if (includeColor)
section()->setCachedCollapsedBorder(this, CBSBefore, result);
return result;
}
CollapsedBorderValue RenderTableCell::computeCollapsedBeforeBorder(IncludeBorderColorOrNot includeColor) const
{
RenderTable* table = this->table();
// For before border, we need to check, in order of precedence:
// (1) Our before border.
int beforeColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderBeforeColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
int afterColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderAfterColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
CollapsedBorderValue result = CollapsedBorderValue(style()->borderBefore(), includeColor ? resolveColor(beforeColorProperty) : Color(), BCELL);
RenderTableCell* prevCell = table->cellAbove(this);
if (prevCell) {
// (2) A before cell's after border.
result = chooseBorder(CollapsedBorderValue(prevCell->style()->borderAfter(), includeColor ? prevCell->resolveColor(afterColorProperty) : Color(), BCELL), result);
if (!result.exists())
return result;
}
// (3) Our row's before border.
result = chooseBorder(result, CollapsedBorderValue(parent()->style()->borderBefore(), includeColor ? parent()->resolveColor(beforeColorProperty) : Color(), 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()->lastRow();
if (prevRow) {
result = chooseBorder(CollapsedBorderValue(prevRow->style()->borderAfter(), includeColor ? prevRow->resolveColor(afterColorProperty) : Color(), BROW), result);
if (!result.exists())
return result;
}
}
// Now check row groups.
RenderTableSection* currSection = section();
if (!rowIndex()) {
// (5) Our row group's before border.
result = chooseBorder(result, CollapsedBorderValue(currSection->style()->borderBefore(), includeColor ? currSection->resolveColor(beforeColorProperty) : Color(), BROWGROUP));
if (!result.exists())
return result;
// (6) Previous row group's after border.
currSection = table->sectionAbove(currSection, SkipEmptySections);
if (currSection) {
result = chooseBorder(CollapsedBorderValue(currSection->style()->borderAfter(), includeColor ? currSection->resolveColor(afterColorProperty) : Color(), 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(), includeColor ? colElt->resolveColor(beforeColorProperty) : Color(), BCOL));
if (!result.exists())
return result;
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroup()) {
result = chooseBorder(result, CollapsedBorderValue(enclosingColumnGroup->style()->borderBefore(), includeColor ? enclosingColumnGroup->resolveColor(beforeColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
}
}
// (9) The table's before border.
result = chooseBorder(result, CollapsedBorderValue(table->style()->borderBefore(), includeColor ? table->resolveColor(beforeColorProperty) : Color(), BTABLE));
if (!result.exists())
return result;
}
return result;
}
CollapsedBorderValue RenderTableCell::collapsedAfterBorder(IncludeBorderColorOrNot includeColor) const
{
CollapsedBorderValue result = computeCollapsedAfterBorder(includeColor);
if (includeColor)
section()->setCachedCollapsedBorder(this, CBSAfter, result);
return result;
}
CollapsedBorderValue RenderTableCell::computeCollapsedAfterBorder(IncludeBorderColorOrNot includeColor) const
{
RenderTable* table = this->table();
// For after border, we need to check, in order of precedence:
// (1) Our after border.
int beforeColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderBeforeColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
int afterColorProperty = includeColor ? CSSProperty::resolveDirectionAwareProperty(CSSPropertyWebkitBorderAfterColor, styleForCellFlow()->direction(), styleForCellFlow()->writingMode()) : 0;
CollapsedBorderValue result = CollapsedBorderValue(style()->borderAfter(), includeColor ? resolveColor(afterColorProperty) : Color(), BCELL);
RenderTableCell* nextCell = table->cellBelow(this);
if (nextCell) {
// (2) An after cell's before border.
result = chooseBorder(result, CollapsedBorderValue(nextCell->style()->borderBefore(), includeColor ? nextCell->resolveColor(beforeColorProperty) : Color(), BCELL));
if (!result.exists())
return result;
}
// (3) Our row's after border. (FIXME: Deal with rowspan!)
result = chooseBorder(result, CollapsedBorderValue(parent()->style()->borderAfter(), includeColor ? parent()->resolveColor(afterColorProperty) : Color(), BROW));
if (!result.exists())
return result;
// (4) The next row's before border.
if (nextCell) {
result = chooseBorder(result, CollapsedBorderValue(nextCell->parent()->style()->borderBefore(), includeColor ? nextCell->parent()->resolveColor(beforeColorProperty) : Color(), BROW));
if (!result.exists())
return result;
}
// Now check row groups.
RenderTableSection* currSection = section();
if (rowIndex() + rowSpan() >= currSection->numRows()) {
// (5) Our row group's after border.
result = chooseBorder(result, CollapsedBorderValue(currSection->style()->borderAfter(), includeColor ? currSection->resolveColor(afterColorProperty) : Color(), BROWGROUP));
if (!result.exists())
return result;
// (6) Following row group's before border.
currSection = table->sectionBelow(currSection, SkipEmptySections);
if (currSection) {
result = chooseBorder(result, CollapsedBorderValue(currSection->style()->borderBefore(), includeColor ? currSection->resolveColor(beforeColorProperty) : Color(), 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(), includeColor ? colElt->resolveColor(afterColorProperty) : Color(), BCOL));
if (!result.exists()) return result;
if (RenderTableCol* enclosingColumnGroup = colElt->enclosingColumnGroup()) {
result = chooseBorder(result, CollapsedBorderValue(enclosingColumnGroup->style()->borderAfter(), includeColor ? enclosingColumnGroup->resolveColor(afterColorProperty) : Color(), BCOLGROUP));
if (!result.exists())
return result;
}
}
// (9) The table's after border.
result = chooseBorder(result, CollapsedBorderValue(table->style()->borderAfter(), includeColor ? table->resolveColor(afterColorProperty) : Color(), BTABLE));
if (!result.exists())
return result;
}
return result;
}
int RenderTableCell::borderLeft() const
{
return table()->collapseBorders() ? borderHalfLeft(false) : RenderBlockFlow::borderLeft();
}
int RenderTableCell::borderRight() const
{
return table()->collapseBorders() ? borderHalfRight(false) : RenderBlockFlow::borderRight();
}
int RenderTableCell::borderTop() const
{
return table()->collapseBorders() ? borderHalfTop(false) : RenderBlockFlow::borderTop();
}
int RenderTableCell::borderBottom() const
{
return table()->collapseBorders() ? borderHalfBottom(false) : RenderBlockFlow::borderBottom();
}
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=46191, make the collapsed border drawing
// work with different block flow values instead of being hard-coded to top-to-bottom.
int RenderTableCell::borderStart() const
{
return table()->collapseBorders() ? borderHalfStart(false) : RenderBlockFlow::borderStart();
}
int RenderTableCell::borderEnd() const
{
return table()->collapseBorders() ? borderHalfEnd(false) : RenderBlockFlow::borderEnd();
}
int RenderTableCell::borderBefore() const
{
return table()->collapseBorders() ? borderHalfBefore(false) : RenderBlockFlow::borderBefore();
}
int RenderTableCell::borderAfter() const
{
return table()->collapseBorders() ? borderHalfAfter(false) : RenderBlockFlow::borderAfter();
}
int RenderTableCell::borderHalfLeft(bool outer) const
{
const RenderStyle* styleForCellFlow = this->styleForCellFlow();
if (styleForCellFlow->isHorizontalWritingMode())
return styleForCellFlow->isLeftToRightDirection() ? borderHalfStart(outer) : borderHalfEnd(outer);
return styleForCellFlow->isFlippedBlocksWritingMode() ? borderHalfAfter(outer) : borderHalfBefore(outer);
}
int RenderTableCell::borderHalfRight(bool outer) const
{
const RenderStyle* styleForCellFlow = this->styleForCellFlow();
if (styleForCellFlow->isHorizontalWritingMode())
return styleForCellFlow->isLeftToRightDirection() ? borderHalfEnd(outer) : borderHalfStart(outer);
return styleForCellFlow->isFlippedBlocksWritingMode() ? borderHalfBefore(outer) : borderHalfAfter(outer);
}
int RenderTableCell::borderHalfTop(bool outer) const
{
const RenderStyle* styleForCellFlow = this->styleForCellFlow();
if (styleForCellFlow->isHorizontalWritingMode())
return styleForCellFlow->isFlippedBlocksWritingMode() ? borderHalfAfter(outer) : borderHalfBefore(outer);
return styleForCellFlow->isLeftToRightDirection() ? borderHalfStart(outer) : borderHalfEnd(outer);
}
int RenderTableCell::borderHalfBottom(bool outer) const
{
const RenderStyle* styleForCellFlow = this->styleForCellFlow();
if (styleForCellFlow->isHorizontalWritingMode())
return styleForCellFlow->isFlippedBlocksWritingMode() ? borderHalfBefore(outer) : borderHalfAfter(outer);
return styleForCellFlow->isLeftToRightDirection() ? borderHalfEnd(outer) : borderHalfStart(outer);
}
int RenderTableCell::borderHalfStart(bool outer) const
{
CollapsedBorderValue border = collapsedStartBorder(DoNotIncludeBorderColor);
if (border.exists())
return (border.width() + ((styleForCellFlow()->isLeftToRightDirection() ^ outer) ? 1 : 0)) / 2; // Give the extra pixel to top and left.
return 0;
}
int RenderTableCell::borderHalfEnd(bool outer) const
{
CollapsedBorderValue border = collapsedEndBorder(DoNotIncludeBorderColor);
if (border.exists())
return (border.width() + ((styleForCellFlow()->isLeftToRightDirection() ^ outer) ? 0 : 1)) / 2;
return 0;
}
int RenderTableCell::borderHalfBefore(bool outer) const
{
CollapsedBorderValue border = collapsedBeforeBorder(DoNotIncludeBorderColor);
if (border.exists())
return (border.width() + ((styleForCellFlow()->isFlippedBlocksWritingMode() ^ outer) ? 0 : 1)) / 2; // Give the extra pixel to top and left.
return 0;
}
int RenderTableCell::borderHalfAfter(bool outer) const
{
CollapsedBorderValue border = collapsedAfterBorder(DoNotIncludeBorderColor);
if (border.exists())
return (border.width() + ((styleForCellFlow()->isFlippedBlocksWritingMode() ^ outer) ? 1 : 0)) / 2;
return 0;
}
void RenderTableCell::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
TableCellPainter(*this).paint(paintInfo, paintOffset);
}
static void addBorderStyle(RenderTable::CollapsedBorderValues& borderValues,
CollapsedBorderValue borderValue)
{
if (!borderValue.exists())
return;
size_t count = borderValues.size();
for (size_t i = 0; i < count; ++i)
if (borderValues[i].isSameIgnoringColor(borderValue))
return;
borderValues.append(borderValue);
}
void RenderTableCell::collectBorderValues(RenderTable::CollapsedBorderValues& borderValues) const
{
addBorderStyle(borderValues, collapsedStartBorder());
addBorderStyle(borderValues, collapsedEndBorder());
addBorderStyle(borderValues, collapsedBeforeBorder());
addBorderStyle(borderValues, collapsedAfterBorder());
}
static int compareBorderValuesForQSort(const void* pa, const void* pb)
{
const CollapsedBorderValue* a = static_cast<const CollapsedBorderValue*>(pa);
const CollapsedBorderValue* b = static_cast<const CollapsedBorderValue*>(pb);
if (a->isSameIgnoringColor(*b))
return 0;
return compareBorders(*a, *b);
}
void RenderTableCell::sortBorderValues(RenderTable::CollapsedBorderValues& borderValues)
{
qsort(borderValues.data(), borderValues.size(), sizeof(CollapsedBorderValue),
compareBorderValuesForQSort);
}
void RenderTableCell::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
TableCellPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset);
}
void RenderTableCell::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
TableCellPainter(*this).paintMask(paintInfo, paintOffset);
}
bool RenderTableCell::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const
{
return false;
}
void RenderTableCell::scrollbarsChanged(bool horizontalScrollbarChanged, bool verticalScrollbarChanged)
{
LayoutUnit scrollbarHeight = scrollbarLogicalHeight();
if (!scrollbarHeight)
return; // Not sure if we should be doing something when a scrollbar goes away or not.
// We only care if the scrollbar that affects our intrinsic padding has been added.
if ((isHorizontalWritingMode() && !horizontalScrollbarChanged) ||
(!isHorizontalWritingMode() && !verticalScrollbarChanged))
return;
// Shrink our intrinsic padding as much as possible to accommodate the scrollbar.
if (style()->verticalAlign() == MIDDLE) {
LayoutUnit totalHeight = logicalHeight();
LayoutUnit heightWithoutIntrinsicPadding = totalHeight - intrinsicPaddingBefore() - intrinsicPaddingAfter();
totalHeight -= scrollbarHeight;
LayoutUnit newBeforePadding = (totalHeight - heightWithoutIntrinsicPadding) / 2;
LayoutUnit newAfterPadding = totalHeight - heightWithoutIntrinsicPadding - newBeforePadding;
setIntrinsicPaddingBefore(newBeforePadding);
setIntrinsicPaddingAfter(newAfterPadding);
} else
setIntrinsicPaddingAfter(intrinsicPaddingAfter() - scrollbarHeight);
}
RenderTableCell* RenderTableCell::createAnonymous(Document* document)
{
RenderTableCell* renderer = new RenderTableCell(0);
renderer->setDocumentForAnonymous(document);
return renderer;
}
RenderTableCell* RenderTableCell::createAnonymousWithParentRenderer(const RenderObject* parent)
{
RenderTableCell* newCell = RenderTableCell::createAnonymous(&parent->document());
RefPtr<RenderStyle> newStyle = RenderStyle::createAnonymousStyleWithDisplay(parent->style(), TABLE_CELL);
newCell->setStyle(newStyle.release());
return newCell;
}
} // namespace blink
|