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

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

Issue 2469903002: Use appropriate background object visual rect for composited table cell backgrounds. (Closed)
Patch Set: Explicitly create special clients if needed in TablePaintInvalidator. Add initally-empty test varia… Created 4 years, 1 month 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 28 matching lines...) Expand all
39 #include "platform/geometry/TransformState.h" 39 #include "platform/geometry/TransformState.h"
40 #include "wtf/PtrUtil.h" 40 #include "wtf/PtrUtil.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 using namespace HTMLNames; 44 using namespace HTMLNames;
45 45
46 struct SameSizeAsLayoutTableCell : public LayoutBlockFlow { 46 struct SameSizeAsLayoutTableCell : public LayoutBlockFlow {
47 unsigned bitfields; 47 unsigned bitfields;
48 int paddings[2]; 48 int paddings[2];
49 void* pointer; 49 void* pointer1;
50 void* pointer2;
51 void* pointer3;
52 void* pointer4;
53 void* pointer5;
50 }; 54 };
51 55
52 static_assert(sizeof(LayoutTableCell) == sizeof(SameSizeAsLayoutTableCell), 56 static_assert(sizeof(LayoutTableCell) == sizeof(SameSizeAsLayoutTableCell),
53 "LayoutTableCell should stay small"); 57 "LayoutTableCell should stay small");
54 static_assert(sizeof(CollapsedBorderValue) == 8, 58 static_assert(sizeof(CollapsedBorderValue) == 8,
55 "CollapsedBorderValue should stay small"); 59 "CollapsedBorderValue should stay small");
56 60
57 LayoutTableCell::LayoutTableCell(Element* element) 61 LayoutTableCell::LayoutTableCell(Element* element)
58 : LayoutBlockFlow(element), 62 : LayoutBlockFlow(element),
59 m_absoluteColumnIndex(unsetColumnIndex), 63 m_absoluteColumnIndex(unsetColumnIndex),
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // The baseline of a cell is the baseline of the first in-flow line box in the 460 // The baseline of a cell is the baseline of the first in-flow line box in the
457 // cell, or the first in-flow table-row in the cell, whichever comes first. If 461 // cell, or the first in-flow table-row in the cell, whichever comes first. If
458 // there is no such line box or table-row, the baseline is the bottom of 462 // there is no such line box or table-row, the baseline is the bottom of
459 // content edge of the cell box. 463 // content edge of the cell box.
460 int firstLineBaseline = firstLineBoxBaseline(); 464 int firstLineBaseline = firstLineBoxBaseline();
461 if (firstLineBaseline != -1) 465 if (firstLineBaseline != -1)
462 return firstLineBaseline; 466 return firstLineBaseline;
463 return (borderBefore() + paddingBefore() + contentLogicalHeight()).toInt(); 467 return (borderBefore() + paddingBefore() + contentLogicalHeight()).toInt();
464 } 468 }
465 469
470 void LayoutTableCell::createCompositedCellDisplayItemClients() {
471 if (!usesCompositedCellDisplayItemClients())
472 return;
473
474 if (row()->styleRef().hasBackground() && !m_rowBackgroundDisplayItemClient) {
475 m_rowBackgroundDisplayItemClient =
476 wrapUnique(new LayoutTableCell::RowBackgroundDisplayItemClient(*row()));
477 }
478
479 LayoutTable::ColAndColGroup colAndColGroup =
480 table()->colElementAtAbsoluteColumn(absoluteColumnIndex());
481 LayoutTableCol* column = colAndColGroup.col;
482 LayoutTableCol* columnGroup = colAndColGroup.colgroup;
483 if (column && column->styleRef().hasBackground() &&
484 !m_colBackgroundDisplayItemClient) {
485 m_colBackgroundDisplayItemClient = wrapUnique(
486 new LayoutTableCell::ColBackgroundDisplayItemClient(*column));
487 }
488 if (columnGroup && columnGroup->styleRef().hasBackground() &&
489 !m_colGroupBackgroundDisplayItemClient) {
490 m_colGroupBackgroundDisplayItemClient = wrapUnique(
491 new LayoutTableCell::ColBackgroundDisplayItemClient(*columnGroup));
492 }
493 if (section()->styleRef().hasBackground() &&
494 !m_sectionBackgroundDisplayItemClient) {
495 m_sectionBackgroundDisplayItemClient = wrapUnique(
496 new LayoutTableCell::SectionBackgroundDisplayItemClient(*section()));
497 }
498 }
499
500 void LayoutTableCell::ensureIsReadyForPaintInvalidation() {
501 LayoutBlockFlow::ensureIsReadyForPaintInvalidation();
502 // Below handles the case where a page starts out in a state where the table
wkorman 2016/11/15 01:05:33 I ended up keeping this as it handles one case (de
503 // cell compositing state and its container styling is such that one or more
504 // special display item clients are needed.
505 createCompositedCellDisplayItemClients();
506 }
507
466 void LayoutTableCell::styleDidChange(StyleDifference diff, 508 void LayoutTableCell::styleDidChange(StyleDifference diff,
467 const ComputedStyle* oldStyle) { 509 const ComputedStyle* oldStyle) {
468 DCHECK_EQ(style()->display(), EDisplay::TableCell); 510 DCHECK_EQ(style()->display(), EDisplay::TableCell);
469 511
470 LayoutBlockFlow::styleDidChange(diff, oldStyle); 512 LayoutBlockFlow::styleDidChange(diff, oldStyle);
471 setHasBoxDecorationBackground(true); 513 setHasBoxDecorationBackground(true);
472 514
473 if (parent() && section() && oldStyle && 515 if (parent() && section() && oldStyle &&
474 style()->height() != oldStyle->height()) 516 style()->height() != oldStyle->height())
475 section()->rowLogicalHeightChanged(row()); 517 section()->rowLogicalHeightChanged(row());
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 bool LayoutTableCell::backgroundIsKnownToBeOpaqueInRect( 1451 bool LayoutTableCell::backgroundIsKnownToBeOpaqueInRect(
1410 const LayoutRect& localRect) const { 1452 const LayoutRect& localRect) const {
1411 // If this object has layer, the area of collapsed borders should be 1453 // If this object has layer, the area of collapsed borders should be
1412 // transparent to expose the collapsed borders painted on the underlying 1454 // transparent to expose the collapsed borders painted on the underlying
1413 // layer. 1455 // layer.
1414 if (hasLayer() && table()->collapseBorders()) 1456 if (hasLayer() && table()->collapseBorders())
1415 return false; 1457 return false;
1416 return LayoutBlockFlow::backgroundIsKnownToBeOpaqueInRect(localRect); 1458 return LayoutBlockFlow::backgroundIsKnownToBeOpaqueInRect(localRect);
1417 } 1459 }
1418 1460
1419 bool LayoutTableCell::usesTableAsAdditionalDisplayItemClient() const { 1461 LayoutTableCell::RowBackgroundDisplayItemClient::RowBackgroundDisplayItemClient(
1420 // In certain cases such as collapsed borders for composited table cells we 1462 const LayoutTableRow& layoutTableRow)
1421 // paint content for the cell into the table graphics layer backing and so 1463 : m_layoutTableRow(layoutTableRow) {}
1422 // must use the table's visual rect. 1464
1465 String LayoutTableCell::RowBackgroundDisplayItemClient::debugName() const {
1466 return "RowBackground";
1467 }
1468
1469 LayoutRect LayoutTableCell::RowBackgroundDisplayItemClient::visualRect() const {
1470 return m_layoutTableRow.visualRect();
1471 }
1472
1473 LayoutTableCell::ColBackgroundDisplayItemClient::ColBackgroundDisplayItemClient(
1474 const LayoutTableCol& layoutTableCol)
1475 : m_layoutTableCol(layoutTableCol) {}
1476
1477 String LayoutTableCell::ColBackgroundDisplayItemClient::debugName() const {
1478 return "ColBackground";
1479 }
1480
1481 LayoutRect LayoutTableCell::ColBackgroundDisplayItemClient::visualRect() const {
1482 return m_layoutTableCol.visualRect();
1483 }
1484
1485 LayoutTableCell::SectionBackgroundDisplayItemClient::
1486 SectionBackgroundDisplayItemClient(
1487 const LayoutTableSection& layoutTableSection)
1488 : m_layoutTableSection(layoutTableSection) {}
1489
1490 String LayoutTableCell::SectionBackgroundDisplayItemClient::debugName() const {
1491 return "SectionBackground";
1492 }
1493
1494 LayoutRect LayoutTableCell::SectionBackgroundDisplayItemClient::visualRect()
1495 const {
1496 return m_layoutTableSection.visualRect();
1497 }
1498
1499 bool LayoutTableCell::usesCompositedCellDisplayItemClients() const {
1500 // Composited table cells are painted in special ways that require the use of
1501 // custom display item clients:
1502 //
1503 // 1. When painting row background we paint content for the cell into the
1504 // table row graphics layer backing and so must use the row's visual rect.
1505 //
1506 // 2. When painting section, column or column group backgrounds we paint
1507 // content for the cell into the table section graphics layer backing and must
1508 // use the visual rect for the respective background object
1423 return (hasLayer() && layer()->compositingState() != NotComposited) || 1509 return (hasLayer() && layer()->compositingState() != NotComposited) ||
1424 RuntimeEnabledFeatures::slimmingPaintV2Enabled(); 1510 RuntimeEnabledFeatures::slimmingPaintV2Enabled();
Xianzhu 2016/11/15 02:58:23 This misses the case that the row is composited bu
wkorman 2016/11/15 19:46:02 Ah. I will look at adding tests for these cases (e
Xianzhu 2016/11/15 20:16:58 Sorry, "DisplayItemClients" should be "LayoutTable
1425 } 1511 }
1426 1512
1427 void LayoutTableCell::invalidateDisplayItemClients( 1513 void LayoutTableCell::invalidateDisplayItemClients(
1428 PaintInvalidationReason reason) const { 1514 PaintInvalidationReason reason) const {
1429 if (m_collapsedBorderValues && usesTableAsAdditionalDisplayItemClient()) { 1515 LayoutBlockFlow::invalidateDisplayItemClients(reason);
1430 ObjectPaintInvalidator(*this).invalidateDisplayItemClient( 1516
1431 *m_collapsedBorderValues, reason); 1517 if (!usesCompositedCellDisplayItemClients())
1518 return;
1519
1520 ObjectPaintInvalidator invalidator(*this);
1521 if (m_collapsedBorderValues)
1522 invalidator.invalidateDisplayItemClient(*m_collapsedBorderValues, reason);
1523 if (m_rowBackgroundDisplayItemClient) {
1524 invalidator.invalidateDisplayItemClient(*m_rowBackgroundDisplayItemClient,
1525 reason);
1432 } 1526 }
1433 LayoutBlockFlow::invalidateDisplayItemClients(reason); 1527 if (m_colBackgroundDisplayItemClient) {
1528 invalidator.invalidateDisplayItemClient(*m_colBackgroundDisplayItemClient,
1529 reason);
1530 }
1531 if (m_colGroupBackgroundDisplayItemClient) {
1532 invalidator.invalidateDisplayItemClient(
1533 *m_colGroupBackgroundDisplayItemClient, reason);
1534 }
1535 if (m_sectionBackgroundDisplayItemClient) {
1536 invalidator.invalidateDisplayItemClient(
1537 *m_sectionBackgroundDisplayItemClient, reason);
1538 }
1434 } 1539 }
1435 1540
1436 // TODO(lunalu): Deliberately dump the "inner" box of table cells, since that 1541 // TODO(lunalu): Deliberately dump the "inner" box of table cells, since that
1437 // is what current results reflect. We'd like to clean up the results to dump 1542 // is what current results reflect. We'd like to clean up the results to dump
1438 // both the outer box and the intrinsic padding so that both bits of information 1543 // both the outer box and the intrinsic padding so that both bits of information
1439 // are captured by the results. 1544 // are captured by the results.
1440 LayoutRect LayoutTableCell::debugRect() const { 1545 LayoutRect LayoutTableCell::debugRect() const {
1441 LayoutRect rect = LayoutRect( 1546 LayoutRect rect = LayoutRect(
1442 location().x(), location().y() + intrinsicPaddingBefore(), size().width(), 1547 location().x(), location().y() + intrinsicPaddingBefore(), size().width(),
1443 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter()); 1548 size().height() - intrinsicPaddingBefore() - intrinsicPaddingAfter());
1444 1549
1445 LayoutBlock* cb = containingBlock(); 1550 LayoutBlock* cb = containingBlock();
1446 if (cb) 1551 if (cb)
1447 cb->adjustChildDebugRect(rect); 1552 cb->adjustChildDebugRect(rect);
1448 1553
1449 return rect; 1554 return rect;
1450 } 1555 }
1451 1556
1452 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const { 1557 void LayoutTableCell::adjustChildDebugRect(LayoutRect& r) const {
1453 r.move(0, -intrinsicPaddingBefore()); 1558 r.move(0, -intrinsicPaddingBefore());
1454 } 1559 }
1455 1560
1456 } // namespace blink 1561 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698