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

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

Issue 2502353003: Paint collapsed borders of a table as one display item (Closed)
Patch Set: rebaseline-cl 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.startBorder.isVisible() && !newValues.endBorder.isVisible() &&
wkorman 2016/12/05 05:49:22 Just a thought: could improve readability if we mo
Xianzhu 2016/12/05 17:28:54 Done.
1326 !newValues.endBorder().isVisible() && 1298 !newValues.beforeBorder.isVisible() &&
1327 !newValues.beforeBorder().isVisible() && 1299 !newValues.afterBorder.isVisible()) {
1328 !newValues.afterBorder().isVisible()) {
1329 changed = !!m_collapsedBorderValues; 1300 changed = !!m_collapsedBorderValues;
1330 m_collapsedBorderValues = nullptr; 1301 m_collapsedBorderValues = nullptr;
1331 } else if (!m_collapsedBorderValues) { 1302 } else if (!m_collapsedBorderValues) {
1332 changed = true; 1303 changed = true;
1333 m_collapsedBorderValues = wrapUnique(new CollapsedBorderValues( 1304 m_collapsedBorderValues = wrapUnique(new CollapsedBorderValues(newValues));
1334 *table(), newValues.startBorder(), newValues.endBorder(),
1335 newValues.beforeBorder(), newValues.afterBorder()));
1336 } else { 1305 } else {
1337 // We check visuallyEquals so that the table cell is invalidated only if a 1306 // We check visuallyEquals so that the table cell is invalidated only if a
1338 // changed collapsed border is visible in the first place. 1307 // changed collapsed border is visible in the first place.
1339 changed = !m_collapsedBorderValues->startBorder().visuallyEquals( 1308 changed = !m_collapsedBorderValues->startBorder.visuallyEquals(
wkorman 2016/12/05 05:49:22 Similar just-a-thought: could add a CollapsedBorde
Xianzhu 2016/12/05 17:28:54 Done.
1340 newValues.startBorder()) || 1309 newValues.startBorder) ||
1341 !m_collapsedBorderValues->endBorder().visuallyEquals( 1310 !m_collapsedBorderValues->endBorder.visuallyEquals(
1342 newValues.endBorder()) || 1311 newValues.endBorder) ||
1343 !m_collapsedBorderValues->beforeBorder().visuallyEquals( 1312 !m_collapsedBorderValues->beforeBorder.visuallyEquals(
1344 newValues.beforeBorder()) || 1313 newValues.beforeBorder) ||
1345 !m_collapsedBorderValues->afterBorder().visuallyEquals( 1314 !m_collapsedBorderValues->afterBorder.visuallyEquals(
1346 newValues.afterBorder()); 1315 newValues.afterBorder);
1347 if (changed) 1316 if (changed)
1348 m_collapsedBorderValues->setCollapsedBorderValues(newValues); 1317 *m_collapsedBorderValues = newValues;
1349 } 1318 }
1350 1319
1351 // If collapsed borders changed, invalidate the cell's display item client on 1320 addBorderStyle(borderValues, newValues.startBorder);
1352 // the table's backing. 1321 addBorderStyle(borderValues, newValues.endBorder);
1353 // TODO(crbug.com/451090#c5): Need a way to invalidate/repaint the borders 1322 addBorderStyle(borderValues, newValues.beforeBorder);
1354 // only. 1323 addBorderStyle(borderValues, newValues.afterBorder);
1355 if (changed) 1324 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 } 1325 }
1365 1326
1366 void LayoutTableCell::sortBorderValues( 1327 void LayoutTableCell::sortBorderValues(
1367 LayoutTable::CollapsedBorderValues& borderValues) { 1328 Vector<CollapsedBorderValue>& borderValues) {
1368 std::sort(borderValues.begin(), borderValues.end(), compareBorders); 1329 std::sort(borderValues.begin(), borderValues.end(), compareBorders);
1369 } 1330 }
1370 1331
1371 void LayoutTableCell::paintBoxDecorationBackground( 1332 void LayoutTableCell::paintBoxDecorationBackground(
1372 const PaintInfo& paintInfo, 1333 const PaintInfo& paintInfo,
1373 const LayoutPoint& paintOffset) const { 1334 const LayoutPoint& paintOffset) const {
1374 TableCellPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset); 1335 TableCellPainter(*this).paintBoxDecorationBackground(paintInfo, paintOffset);
1375 } 1336 }
1376 1337
1377 void LayoutTableCell::paintMask(const PaintInfo& paintInfo, 1338 void LayoutTableCell::paintMask(const PaintInfo& paintInfo,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 } 1413 }
1453 1414
1454 void LayoutTableCell::invalidateDisplayItemClients( 1415 void LayoutTableCell::invalidateDisplayItemClients(
1455 PaintInvalidationReason reason) const { 1416 PaintInvalidationReason reason) const {
1456 LayoutBlockFlow::invalidateDisplayItemClients(reason); 1417 LayoutBlockFlow::invalidateDisplayItemClients(reason);
1457 1418
1458 if (!usesCompositedCellDisplayItemClients()) 1419 if (!usesCompositedCellDisplayItemClients())
1459 return; 1420 return;
1460 1421
1461 ObjectPaintInvalidator invalidator(*this); 1422 ObjectPaintInvalidator invalidator(*this);
1462 if (m_collapsedBorderValues)
1463 invalidator.invalidateDisplayItemClient(*m_collapsedBorderValues, reason);
1464 if (m_rowBackgroundDisplayItemClient) { 1423 if (m_rowBackgroundDisplayItemClient) {
1465 invalidator.invalidateDisplayItemClient(*m_rowBackgroundDisplayItemClient, 1424 invalidator.invalidateDisplayItemClient(*m_rowBackgroundDisplayItemClient,
1466 reason); 1425 reason);
1467 } 1426 }
1468 } 1427 }
1469 1428
1470 // TODO(lunalu): Deliberately dump the "inner" box of table cells, since that 1429 // 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 1430 // 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 1431 // both the outer box and the intrinsic padding so that both bits of information
1473 // are captured by the results. 1432 // are captured by the results.
1474 LayoutRect LayoutTableCell::debugRect() const { 1433 LayoutRect LayoutTableCell::debugRect() const {
1475 LayoutRect rect = LayoutRect( 1434 LayoutRect rect = LayoutRect(
1476 location().x(), location().y() + intrinsicPaddingBefore(), size().width(), 1435 location().x(), location().y() + intrinsicPaddingBefore(), size().width(),
1477 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter()); 1436 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter());
1478 1437
1479 LayoutBlock* cb = containingBlock(); 1438 LayoutBlock* cb = containingBlock();
1480 if (cb) 1439 if (cb)
1481 cb->adjustChildDebugRect(rect); 1440 cb->adjustChildDebugRect(rect);
1482 1441
1483 return rect; 1442 return rect;
1484 } 1443 }
1485 1444
1486 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const { 1445 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const {
1487 r.move(0, -intrinsicPaddingBefore()); 1446 r.move(0, -intrinsicPaddingBefore());
1488 } 1447 }
1489 1448
1490 } // namespace blink 1449 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698