OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/rendering/RenderGrid.h" | 27 #include "core/rendering/RenderGrid.h" |
28 | 28 |
| 29 #include "core/paint/GridPainter.h" |
29 #include "core/rendering/RenderLayer.h" | 30 #include "core/rendering/RenderLayer.h" |
30 #include "core/rendering/RenderView.h" | 31 #include "core/rendering/RenderView.h" |
31 #include "core/rendering/TextAutosizer.h" | 32 #include "core/rendering/TextAutosizer.h" |
32 #include "core/rendering/style/GridCoordinate.h" | 33 #include "core/rendering/style/GridCoordinate.h" |
33 #include "platform/LengthFunctions.h" | 34 #include "platform/LengthFunctions.h" |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 static const int infinity = -1; | 38 static const int infinity = -1; |
38 | 39 |
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 | 1373 |
1373 ASSERT_NOT_REACHED(); | 1374 ASSERT_NOT_REACHED(); |
1374 return 0; | 1375 return 0; |
1375 } | 1376 } |
1376 | 1377 |
1377 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const | 1378 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const |
1378 { | 1379 { |
1379 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); | 1380 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); |
1380 } | 1381 } |
1381 | 1382 |
1382 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn
it start, LayoutUnit end) | |
1383 { | |
1384 // This function does a binary search over the coordinates. | |
1385 // This doesn't work with grid items overflowing their grid areas, but that
is managed with m_gridItemsOverflowingGridArea. | |
1386 | |
1387 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate
s.end() - 1, start) - coordinates.begin(); | |
1388 if (startGridAreaIndex > 0) | |
1389 --startGridAreaIndex; | |
1390 | |
1391 size_t endGridAreaIndex = std::upper_bound(coordinates.begin() + startGridAr
eaIndex, coordinates.end() - 1, end) - coordinates.begin(); | |
1392 if (endGridAreaIndex > 0) | |
1393 --endGridAreaIndex; | |
1394 | |
1395 return GridSpan(startGridAreaIndex, endGridAreaIndex); | |
1396 } | |
1397 | |
1398 class GridItemsSorter { | |
1399 public: | |
1400 bool operator()(const std::pair<RenderBox*, size_t>& firstChild, const std::
pair<RenderBox*, size_t>& secondChild) const | |
1401 { | |
1402 if (firstChild.first->style()->order() != secondChild.first->style()->or
der()) | |
1403 return firstChild.first->style()->order() < secondChild.first->style
()->order(); | |
1404 | |
1405 return firstChild.second < secondChild.second; | |
1406 } | |
1407 }; | |
1408 | |
1409 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 1383 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
1410 { | 1384 { |
1411 ASSERT_WITH_SECURITY_IMPLICATION(!gridIsDirty()); | 1385 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
1412 | |
1413 LayoutRect localPaintInvalidationRect = paintInfo.rect; | |
1414 localPaintInvalidationRect.moveBy(-paintOffset); | |
1415 | |
1416 GridSpan dirtiedColumns = dirtiedGridAreas(m_columnPositions, localPaintInva
lidationRect.x(), localPaintInvalidationRect.maxX()); | |
1417 GridSpan dirtiedRows = dirtiedGridAreas(m_rowPositions, localPaintInvalidati
onRect.y(), localPaintInvalidationRect.maxY()); | |
1418 | |
1419 Vector<std::pair<RenderBox*, size_t> > gridItemsToBePainted; | |
1420 | |
1421 for (GridSpan::iterator row = dirtiedRows.begin(); row != dirtiedRows.end();
++row) { | |
1422 for (GridSpan::iterator column = dirtiedColumns.begin(); column != dirti
edColumns.end(); ++column) { | |
1423 const Vector<RenderBox*, 1>& children = m_grid[row.toInt()][column.t
oInt()]; | |
1424 for (size_t j = 0; j < children.size(); ++j) | |
1425 gridItemsToBePainted.append(std::make_pair(children[j], m_gridIt
emsIndexesMap.get(children[j]))); | |
1426 } | |
1427 } | |
1428 | |
1429 for (Vector<RenderBox*>::const_iterator it = m_gridItemsOverflowingGridArea.
begin(); it != m_gridItemsOverflowingGridArea.end(); ++it) { | |
1430 if ((*it)->frameRect().intersects(localPaintInvalidationRect)) | |
1431 gridItemsToBePainted.append(std::make_pair(*it, m_gridItemsIndexesMa
p.get(*it))); | |
1432 } | |
1433 | |
1434 // Sort grid items following order-modified document order. | |
1435 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order | |
1436 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), G
ridItemsSorter()); | |
1437 | |
1438 RenderBox* previous = 0; | |
1439 for (Vector<std::pair<RenderBox*, size_t> >::const_iterator it = gridItemsTo
BePainted.begin(); it != gridItemsToBePainted.end(); ++it) { | |
1440 // We might have duplicates because of spanning children are included in
all cells they span. | |
1441 // Skip them here to avoid painting items several times. | |
1442 RenderBox* current = (*it).first; | |
1443 if (current == previous) | |
1444 continue; | |
1445 | |
1446 paintChild(current, paintInfo, paintOffset); | |
1447 previous = current; | |
1448 } | |
1449 } | |
1450 | |
1451 void RenderGrid::paintChild(RenderBox* child, PaintInfo& paintInfo, const Layout
Point& paintOffset) | |
1452 { | |
1453 LayoutPoint childPoint = flipForWritingModeForChild(child, paintOffset); | |
1454 if (!child->hasSelfPaintingLayer() && !child->isFloating()) | |
1455 child->paint(paintInfo, childPoint); | |
1456 } | 1386 } |
1457 | 1387 |
1458 const char* RenderGrid::renderName() const | 1388 const char* RenderGrid::renderName() const |
1459 { | 1389 { |
1460 if (isFloating()) | 1390 if (isFloating()) |
1461 return "RenderGrid (floating)"; | 1391 return "RenderGrid (floating)"; |
1462 if (isOutOfFlowPositioned()) | 1392 if (isOutOfFlowPositioned()) |
1463 return "RenderGrid (positioned)"; | 1393 return "RenderGrid (positioned)"; |
1464 if (isAnonymous()) | 1394 if (isAnonymous()) |
1465 return "RenderGrid (generated)"; | 1395 return "RenderGrid (generated)"; |
1466 if (isRelPositioned()) | 1396 if (isRelPositioned()) |
1467 return "RenderGrid (relative positioned)"; | 1397 return "RenderGrid (relative positioned)"; |
1468 return "RenderGrid"; | 1398 return "RenderGrid"; |
1469 } | 1399 } |
1470 | 1400 |
1471 } // namespace blink | 1401 } // namespace blink |
OLD | NEW |