Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTableCell.cpp

Issue 2551963003: Reland of Paint collapsed borders of a table as one display item (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org) 3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org) 4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org) 5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 m_absoluteColumnIndex(unsetColumnIndex), 60 m_absoluteColumnIndex(unsetColumnIndex),
61 m_cellWidthChanged(false), 61 m_cellWidthChanged(false),
62 m_intrinsicPaddingBefore(0), 62 m_intrinsicPaddingBefore(0),
63 m_intrinsicPaddingAfter(0) { 63 m_intrinsicPaddingAfter(0) {
64 // We only update the flags when notified of DOM changes in 64 // We only update the flags when notified of DOM changes in
65 // colSpanOrRowSpanChanged() so we need to set their initial values here in 65 // colSpanOrRowSpanChanged() so we need to set their initial values here in
66 // case something asks for colSpan()/rowSpan() before then. 66 // case something asks for colSpan()/rowSpan() before then.
67 updateColAndRowSpanFlags(); 67 updateColAndRowSpanFlags();
68 } 68 }
69 69
70 LayoutTableCell::CollapsedBorderValues::CollapsedBorderValues(
71 const LayoutTable& layoutTable,
72 const CollapsedBorderValue& startBorder,
73 const CollapsedBorderValue& endBorder,
74 const CollapsedBorderValue& beforeBorder,
75 const CollapsedBorderValue& afterBorder)
76 : m_layoutTable(layoutTable),
77 m_startBorder(startBorder),
78 m_endBorder(endBorder),
79 m_beforeBorder(beforeBorder),
80 m_afterBorder(afterBorder) {}
81
82 void LayoutTableCell::CollapsedBorderValues::setCollapsedBorderValues(
83 const CollapsedBorderValues& other) {
84 m_startBorder = other.startBorder();
85 m_endBorder = other.endBorder();
86 m_beforeBorder = other.beforeBorder();
87 m_afterBorder = other.afterBorder();
88 }
89
90 String LayoutTableCell::CollapsedBorderValues::debugName() const {
91 return "CollapsedBorderValues";
92 }
93
94 LayoutRect LayoutTableCell::CollapsedBorderValues::visualRect() const {
95 return m_layoutTable.visualRect();
96 }
97
98 void LayoutTableCell::willBeRemovedFromTree() { 70 void LayoutTableCell::willBeRemovedFromTree() {
99 LayoutBlockFlow::willBeRemovedFromTree(); 71 LayoutBlockFlow::willBeRemovedFromTree();
100 72
101 section()->setNeedsCellRecalc(); 73 section()->setNeedsCellRecalc();
102 74
103 // When borders collapse, removing a cell can affect the the width of 75 // When borders collapse, removing a cell can affect the the width of
104 // neighboring cells. 76 // neighboring cells.
105 LayoutTable* enclosingTable = table(); 77 LayoutTable* enclosingTable = table();
106 DCHECK(enclosingTable); 78 DCHECK(enclosingTable);
107 if (!enclosingTable->collapseBorders()) 79 if (!enclosingTable->collapseBorders())
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 clearIntrinsicPadding(); 465 clearIntrinsicPadding();
494 466
495 // If border was changed, notify table. 467 // If border was changed, notify table.
496 if (!parent()) 468 if (!parent())
497 return; 469 return;
498 LayoutTable* table = this->table(); 470 LayoutTable* table = this->table();
499 if (!table) 471 if (!table)
500 return; 472 return;
501 if (!table->selfNeedsLayout() && !table->normalChildNeedsLayout() && 473 if (!table->selfNeedsLayout() && !table->normalChildNeedsLayout() &&
502 oldStyle && oldStyle->border() != style()->border()) 474 oldStyle && oldStyle->border() != style()->border())
503 table->invalidateCollapsedBorders(); 475 table->invalidateCollapsedBorders(PaintInvalidationStyleChange);
504 476
505 if (LayoutTableBoxComponent::doCellsHaveDirtyWidth(*this, *table, diff, 477 if (LayoutTableBoxComponent::doCellsHaveDirtyWidth(*this, *table, diff,
506 *oldStyle)) { 478 *oldStyle)) {
507 if (previousCell()) { 479 if (previousCell()) {
508 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is 480 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is
509 // needed instead of setNeedsLayout. 481 // needed instead of setNeedsLayout.
510 previousCell()->setChildNeedsLayout(); 482 previousCell()->setChildNeedsLayout();
511 previousCell()->setPreferredLogicalWidthsDirty(MarkOnlyThis); 483 previousCell()->setPreferredLogicalWidthsDirty(MarkOnlyThis);
512 } 484 }
513 if (nextCell()) { 485 if (nextCell()) {
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 : 0)) / 1268 : 0)) /
1297 2; 1269 2;
1298 return 0; 1270 return 0;
1299 } 1271 }
1300 1272
1301 void LayoutTableCell::paint(const PaintInfo& paintInfo, 1273 void LayoutTableCell::paint(const PaintInfo& paintInfo,
1302 const LayoutPoint& paintOffset) const { 1274 const LayoutPoint& paintOffset) const {
1303 TableCellPainter(*this).paint(paintInfo, paintOffset); 1275 TableCellPainter(*this).paint(paintInfo, paintOffset);
1304 } 1276 }
1305 1277
1306 static void addBorderStyle(LayoutTable::CollapsedBorderValues& borderValues, 1278 static void addBorderStyle(Vector<CollapsedBorderValue>& borderValues,
1307 CollapsedBorderValue borderValue) { 1279 CollapsedBorderValue borderValue) {
1308 if (!borderValue.isVisible()) 1280 if (!borderValue.isVisible())
1309 return; 1281 return;
1310 size_t count = borderValues.size(); 1282 size_t count = borderValues.size();
1311 for (size_t i = 0; i < count; ++i) { 1283 for (size_t i = 0; i < count; ++i) {
1312 if (borderValues[i].isSameIgnoringColor(borderValue)) 1284 if (borderValues[i].isSameIgnoringColor(borderValue))
1313 return; 1285 return;
1314 } 1286 }
1315 borderValues.append(borderValue); 1287 borderValues.append(borderValue);
1316 } 1288 }
1317 1289
1318 void LayoutTableCell::collectBorderValues( 1290 bool LayoutTableCell::collectBorderValues(
1319 LayoutTable::CollapsedBorderValues& borderValues) { 1291 Vector<CollapsedBorderValue>& borderValues) {
1320 CollapsedBorderValues newValues( 1292 CollapsedBorderValues newValues = {
1321 *table(), computeCollapsedStartBorder(), computeCollapsedEndBorder(), 1293 computeCollapsedStartBorder(), computeCollapsedEndBorder(),
1322 computeCollapsedBeforeBorder(), computeCollapsedAfterBorder()); 1294 computeCollapsedBeforeBorder(), computeCollapsedAfterBorder()};
1323 1295
1324 bool changed = false; 1296 bool changed = false;
1325 if (!newValues.startBorder().isVisible() && 1297 if (newValues.allBordersAreInvisible()) {
1326 !newValues.endBorder().isVisible() &&
1327 !newValues.beforeBorder().isVisible() &&
1328 !newValues.afterBorder().isVisible()) {
1329 changed = !!m_collapsedBorderValues; 1298 changed = !!m_collapsedBorderValues;
1330 m_collapsedBorderValues = nullptr; 1299 m_collapsedBorderValues = nullptr;
1331 } else if (!m_collapsedBorderValues) { 1300 } else if (!m_collapsedBorderValues) {
1332 changed = true; 1301 changed = true;
1333 m_collapsedBorderValues = wrapUnique(new CollapsedBorderValues( 1302 m_collapsedBorderValues = wrapUnique(new CollapsedBorderValues(newValues));
1334 *table(), newValues.startBorder(), newValues.endBorder(),
1335 newValues.beforeBorder(), newValues.afterBorder()));
1336 } else { 1303 } else {
1337 // We check visuallyEquals so that the table cell is invalidated only if a 1304 changed = !m_collapsedBorderValues->bordersVisuallyEqual(newValues);
1338 // changed collapsed border is visible in the first place.
1339 changed = !m_collapsedBorderValues->startBorder().visuallyEquals(
1340 newValues.startBorder()) ||
1341 !m_collapsedBorderValues->endBorder().visuallyEquals(
1342 newValues.endBorder()) ||
1343 !m_collapsedBorderValues->beforeBorder().visuallyEquals(
1344 newValues.beforeBorder()) ||
1345 !m_collapsedBorderValues->afterBorder().visuallyEquals(
1346 newValues.afterBorder());
1347 if (changed) 1305 if (changed)
1348 m_collapsedBorderValues->setCollapsedBorderValues(newValues); 1306 *m_collapsedBorderValues = newValues;
1349 } 1307 }
1350 1308
1351 // If collapsed borders changed, invalidate the cell's display item client on 1309 addBorderStyle(borderValues, newValues.startBorder);
1352 // the table's backing. 1310 addBorderStyle(borderValues, newValues.endBorder);
1353 // TODO(crbug.com/451090#c5): Need a way to invalidate/repaint the borders 1311 addBorderStyle(borderValues, newValues.beforeBorder);
1354 // only. 1312 addBorderStyle(borderValues, newValues.afterBorder);
1355 if (changed) 1313 return changed;
1356 ObjectPaintInvalidator(*table())
1357 .slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient(
1358 *this, PaintInvalidationStyleChange);
1359
1360 addBorderStyle(borderValues, newValues.startBorder());
1361 addBorderStyle(borderValues, newValues.endBorder());
1362 addBorderStyle(borderValues, newValues.beforeBorder());
1363 addBorderStyle(borderValues, newValues.afterBorder());
1364 } 1314 }
1365 1315
1366 void LayoutTableCell::sortBorderValues( 1316 void LayoutTableCell::sortBorderValues(
1367 LayoutTable::CollapsedBorderValues& borderValues) { 1317 Vector<CollapsedBorderValue>& borderValues) {
1368 std::sort(borderValues.begin(), borderValues.end(), compareBorders); 1318 std::sort(borderValues.begin(), borderValues.end(), compareBorders);
1369 } 1319 }
1370 1320
1371 void LayoutTableCell::paintBoxDecorationBackground( 1321 void LayoutTableCell::paintBoxDecorationBackground(
1372 const PaintInfo& paintInfo, 1322 const PaintInfo& paintInfo,
1373 const LayoutPoint& paintOffset) const { 1323 const LayoutPoint& paintOffset) const {
1374 TableCellPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset); 1324 TableCellPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset);
1375 } 1325 }
1376 1326
1377 void LayoutTableCell::paintMask(const PaintInfo& paintInfo, 1327 void LayoutTableCell::paintMask(const PaintInfo& paintInfo,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 } 1402 }
1453 1403
1454 void LayoutTableCell::invalidateDisplayItemClients( 1404 void LayoutTableCell::invalidateDisplayItemClients(
1455 PaintInvalidationReason reason) const { 1405 PaintInvalidationReason reason) const {
1456 LayoutBlockFlow::invalidateDisplayItemClients(reason); 1406 LayoutBlockFlow::invalidateDisplayItemClients(reason);
1457 1407
1458 if (!usesCompositedCellDisplayItemClients()) 1408 if (!usesCompositedCellDisplayItemClients())
1459 return; 1409 return;
1460 1410
1461 ObjectPaintInvalidator invalidator(*this); 1411 ObjectPaintInvalidator invalidator(*this);
1462 if (m_collapsedBorderValues)
1463 invalidator.invalidateDisplayItemClient(*m_collapsedBorderValues, reason);
1464 if (m_rowBackgroundDisplayItemClient) { 1412 if (m_rowBackgroundDisplayItemClient) {
1465 invalidator.invalidateDisplayItemClient(*m_rowBackgroundDisplayItemClient, 1413 invalidator.invalidateDisplayItemClient(*m_rowBackgroundDisplayItemClient,
1466 reason); 1414 reason);
1467 } 1415 }
1468 } 1416 }
1469 1417
1470 // TODO(lunalu): Deliberately dump the "inner" box of table cells, since that 1418 // TODO(lunalu): Deliberately dump the "inner" box of table cells, since that
1471 // is what current results reflect. We'd like to clean up the results to dump 1419 // is what current results reflect. We'd like to clean up the results to dump
1472 // both the outer box and the intrinsic padding so that both bits of information 1420 // both the outer box and the intrinsic padding so that both bits of information
1473 // are captured by the results. 1421 // are captured by the results.
1474 LayoutRect LayoutTableCell::debugRect() const { 1422 LayoutRect LayoutTableCell::debugRect() const {
1475 LayoutRect rect = LayoutRect( 1423 LayoutRect rect = LayoutRect(
1476 location().x(), location().y() + intrinsicPaddingBefore(), size().width(), 1424 location().x(), location().y() + intrinsicPaddingBefore(), size().width(),
1477 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter()); 1425 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter());
1478 1426
1479 LayoutBlock* cb = containingBlock(); 1427 LayoutBlock* cb = containingBlock();
1480 if (cb) 1428 if (cb)
1481 cb->adjustChildDebugRect(rect); 1429 cb->adjustChildDebugRect(rect);
1482 1430
1483 return rect; 1431 return rect;
1484 } 1432 }
1485 1433
1486 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const { 1434 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const {
1487 r.move(0, -intrinsicPaddingBefore()); 1435 r.move(0, -intrinsicPaddingBefore());
1488 } 1436 }
1489 1437
1490 } // namespace blink 1438 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutTableCell.h ('k') | third_party/WebKit/Source/core/layout/LayoutTableCol.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698