Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> | 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
| 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. | 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. |
| 7 * Copyright (C) 2015 Google Inc. All rights reserved. | 7 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 class OrderedNamedLinesCollector { | 736 class OrderedNamedLinesCollector { |
| 737 STACK_ALLOCATED(); | 737 STACK_ALLOCATED(); |
| 738 WTF_MAKE_NONCOPYABLE(OrderedNamedLinesCollector); | 738 WTF_MAKE_NONCOPYABLE(OrderedNamedLinesCollector); |
| 739 public: | 739 public: |
| 740 OrderedNamedLinesCollector(const ComputedStyle& style, bool isRowAxis, size_ t repetitions) | 740 OrderedNamedLinesCollector(const ComputedStyle& style, bool isRowAxis, size_ t repetitions) |
| 741 : m_orderedNamedGridLines(isRowAxis ? style.orderedNamedGridColumnLines( ) : style.orderedNamedGridRowLines()) | 741 : m_orderedNamedGridLines(isRowAxis ? style.orderedNamedGridColumnLines( ) : style.orderedNamedGridRowLines()) |
| 742 , m_orderedNamedAutoRepeatGridLines(isRowAxis ? style.autoRepeatOrderedN amedGridColumnLines() : style.autoRepeatOrderedNamedGridRowLines()) | 742 , m_orderedNamedAutoRepeatGridLines(isRowAxis ? style.autoRepeatOrderedN amedGridColumnLines() : style.autoRepeatOrderedNamedGridRowLines()) |
| 743 , m_insertionPoint(isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint () : style.gridAutoRepeatRowsInsertionPoint()) | 743 , m_insertionPoint(isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint () : style.gridAutoRepeatRowsInsertionPoint()) |
| 744 , m_repetitions(repetitions) | 744 , m_repetitions(repetitions) |
| 745 { | 745 { |
| 746 auto autoRepeatTrackSizes = isRowAxis ? style.gridAutoRepeatColumns() : style.gridAutoRepeatRows(); | |
| 747 auto autoRepeatType = isRowAxis ? style.gridAutoRepeatColumnsType() : st yle.gridAutoRepeatRowsType(); | |
| 748 m_hasRepeatAutoFit = autoRepeatTrackSizes.size() && autoRepeatType == Au toFit; | |
| 746 } | 749 } |
| 747 | 750 |
| 748 bool isEmpty() const { return m_orderedNamedGridLines.isEmpty() && m_ordered NamedAutoRepeatGridLines.isEmpty(); } | 751 bool isEmpty() const { return m_orderedNamedGridLines.isEmpty() && m_ordered NamedAutoRepeatGridLines.isEmpty(); } |
| 749 void collectLineNamesForIndex(CSSGridLineNamesValue&, size_t index) const; | 752 void collectLineNamesForIndex(CSSGridLineNamesValue&, size_t index) const; |
| 750 | 753 |
| 751 private: | 754 private: |
| 752 | 755 |
| 753 enum NamedLinesType { NamedLines, AutoRepeatNamedLines }; | 756 enum NamedLinesType { NamedLines, AutoRepeatNamedLines }; |
| 754 void appendLines(CSSGridLineNamesValue&, size_t index, NamedLinesType) const ; | 757 void appendLines(CSSGridLineNamesValue&, size_t index, NamedLinesType) const ; |
| 755 | 758 |
| 756 const OrderedNamedGridLines& m_orderedNamedGridLines; | 759 const OrderedNamedGridLines& m_orderedNamedGridLines; |
| 757 const OrderedNamedGridLines& m_orderedNamedAutoRepeatGridLines; | 760 const OrderedNamedGridLines& m_orderedNamedAutoRepeatGridLines; |
| 758 size_t m_insertionPoint; | 761 size_t m_insertionPoint; |
| 759 size_t m_repetitions; | 762 size_t m_repetitions; |
| 763 bool m_hasRepeatAutoFit; | |
| 760 }; | 764 }; |
| 761 | 765 |
| 762 void OrderedNamedLinesCollector::appendLines(CSSGridLineNamesValue& lineNamesVal ue, size_t index, NamedLinesType type) const | 766 void OrderedNamedLinesCollector::appendLines(CSSGridLineNamesValue& lineNamesVal ue, size_t index, NamedLinesType type) const |
| 763 { | 767 { |
| 764 auto iter = type == NamedLines ? m_orderedNamedGridLines.find(index) : m_ord eredNamedAutoRepeatGridLines.find(index); | 768 auto iter = type == NamedLines ? m_orderedNamedGridLines.find(index) : m_ord eredNamedAutoRepeatGridLines.find(index); |
| 765 auto endIter = type == NamedLines ? m_orderedNamedGridLines.end() : m_ordere dNamedAutoRepeatGridLines.end(); | 769 auto endIter = type == NamedLines ? m_orderedNamedGridLines.end() : m_ordere dNamedAutoRepeatGridLines.end(); |
| 766 if (iter == endIter) | 770 if (iter == endIter) |
| 767 return; | 771 return; |
| 768 | 772 |
| 769 for (auto lineName : iter->value) | 773 for (auto lineName : iter->value) |
| 770 lineNamesValue.append(*CSSCustomIdentValue::create(lineName)); | 774 lineNamesValue.append(*CSSCustomIdentValue::create(lineName)); |
| 771 } | 775 } |
| 772 | 776 |
| 773 void OrderedNamedLinesCollector::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, size_t i) const | 777 void OrderedNamedLinesCollector::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, size_t i) const |
| 774 { | 778 { |
| 775 DCHECK(!isEmpty()); | 779 DCHECK(!isEmpty()); |
| 776 if (m_orderedNamedAutoRepeatGridLines.isEmpty() || i < m_insertionPoint) { | 780 if (m_orderedNamedAutoRepeatGridLines.isEmpty() || i < m_insertionPoint || ! m_repetitions) { |
| 777 appendLines(lineNamesValue, i, NamedLines); | 781 if (!m_hasRepeatAutoFit || m_repetitions || i < m_insertionPoint) { |
|
Manuel Rego
2016/06/21 21:57:37
Do we really need to check if m_hasRepeatAutoFit?
svillar
2016/06/23 08:09:42
Yes we do.
If m_repetitions is 0 then there are 2
| |
| 782 appendLines(lineNamesValue, i, NamedLines); | |
| 783 return; | |
| 784 } | |
| 785 | |
| 786 // If all the repetitions were dropped we should merge the line names su rrounding the repeat() | |
| 787 // function. We should also take the removed tracks into account for the following lines. | |
|
Manuel Rego
2016/06/21 21:57:37
I guess we could add an assert here to check that
svillar
2016/06/23 08:09:42
Do we? There is an if (m_repetitions) with an earl
| |
| 788 if (i == m_insertionPoint) { | |
| 789 appendLines(lineNamesValue, i, NamedLines); | |
| 790 appendLines(lineNamesValue, i + 1, NamedLines); | |
| 791 } else { | |
| 792 appendLines(lineNamesValue, i + 1, NamedLines); | |
|
Manuel Rego
2016/06/21 21:57:37
I don't understand this else part.
I guess that h
svillar
2016/06/23 08:09:42
So we're in the case of having dropped all the rep
| |
| 793 } | |
| 778 return; | 794 return; |
| 779 } | 795 } |
| 780 | 796 |
| 781 DCHECK(m_repetitions); | 797 DCHECK(m_repetitions); |
| 782 if (i > m_insertionPoint + m_repetitions) { | 798 if (i > m_insertionPoint + m_repetitions) { |
| 783 appendLines(lineNamesValue, i - (m_repetitions - 1), NamedLines); | 799 appendLines(lineNamesValue, i - (m_repetitions - 1), NamedLines); |
| 784 return; | 800 return; |
| 785 } | 801 } |
| 786 | 802 |
| 787 if (i == m_insertionPoint) { | 803 if (i == m_insertionPoint) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 811 list.append(*lineNames); | 827 list.append(*lineNames); |
| 812 } | 828 } |
| 813 | 829 |
| 814 static CSSValue* valueForGridTrackList(GridTrackSizingDirection direction, const LayoutObject* layoutObject, const ComputedStyle& style) | 830 static CSSValue* valueForGridTrackList(GridTrackSizingDirection direction, const LayoutObject* layoutObject, const ComputedStyle& style) |
| 815 { | 831 { |
| 816 bool isRowAxis = direction == ForColumns; | 832 bool isRowAxis = direction == ForColumns; |
| 817 const Vector<GridTrackSize>& trackSizes = isRowAxis ? style.gridTemplateColu mns() : style.gridTemplateRows(); | 833 const Vector<GridTrackSize>& trackSizes = isRowAxis ? style.gridTemplateColu mns() : style.gridTemplateRows(); |
| 818 const Vector<GridTrackSize>& autoRepeatTrackSizes = isRowAxis ? style.gridAu toRepeatColumns() : style.gridAutoRepeatRows(); | 834 const Vector<GridTrackSize>& autoRepeatTrackSizes = isRowAxis ? style.gridAu toRepeatColumns() : style.gridAutoRepeatRows(); |
| 819 bool isLayoutGrid = layoutObject && layoutObject->isLayoutGrid(); | 835 bool isLayoutGrid = layoutObject && layoutObject->isLayoutGrid(); |
| 820 | 836 |
| 821 // Handle the 'none' case. | 837 // auto-fit might eventually remove all the tracks, we should consider the g rid empty in that case too. |
| 822 bool trackListIsEmpty = trackSizes.isEmpty() && autoRepeatTrackSizes.isEmpty (); | 838 size_t repetitions = isLayoutGrid ? toLayoutGrid(layoutObject)->autoRepeatCo untForDirection(direction) : 0; |
| 839 bool trackListIsEmpty = trackSizes.isEmpty() && (autoRepeatTrackSizes.isEmpt y() || !repetitions); | |
|
Manuel Rego
2016/06/21 21:57:37
I guess checking !repetitions is enough:
bool t
svillar
2016/06/23 08:09:42
Yes we can do that in this case.
| |
| 823 if (isLayoutGrid && trackListIsEmpty) { | 840 if (isLayoutGrid && trackListIsEmpty) { |
| 824 // For grids we should consider every listed track, whether implicitly o r explicitly | 841 // For grids we should consider every listed track, whether implicitly o r explicitly |
| 825 // created. Empty grids have a sole grid line per axis. | 842 // created. Empty grids have a sole grid line per axis. |
| 826 auto& positions = isRowAxis ? toLayoutGrid(layoutObject)->columnPosition s() : toLayoutGrid(layoutObject)->rowPositions(); | 843 auto& positions = isRowAxis ? toLayoutGrid(layoutObject)->columnPosition s() : toLayoutGrid(layoutObject)->rowPositions(); |
| 827 trackListIsEmpty = positions.size() == 1; | 844 trackListIsEmpty = positions.size() == 1; |
| 828 } | 845 } |
| 829 | 846 |
| 830 if (trackListIsEmpty) | 847 if (trackListIsEmpty) |
| 831 return CSSPrimitiveValue::createIdentifier(CSSValueNone); | 848 return CSSPrimitiveValue::createIdentifier(CSSValueNone); |
| 832 | 849 |
| 833 size_t repetitions = isLayoutGrid ? toLayoutGrid(layoutObject)->autoRepeatCo untForDirection(direction) : 0; | |
| 834 OrderedNamedLinesCollector collector(style, isRowAxis, repetitions); | 850 OrderedNamedLinesCollector collector(style, isRowAxis, repetitions); |
| 835 CSSValueList* list = CSSValueList::createSpaceSeparated(); | 851 CSSValueList* list = CSSValueList::createSpaceSeparated(); |
| 836 size_t insertionIndex; | 852 size_t insertionIndex; |
| 837 if (isLayoutGrid) { | 853 if (isLayoutGrid) { |
| 838 const auto* grid = toLayoutGrid(layoutObject); | 854 const auto* grid = toLayoutGrid(layoutObject); |
| 839 const Vector<LayoutUnit>& trackPositions = direction == ForColumns ? gri d->columnPositions() : grid->rowPositions(); | 855 const Vector<LayoutUnit>& trackPositions = direction == ForColumns ? gri d->columnPositions() : grid->rowPositions(); |
| 840 // There are at least #tracks + 1 grid lines (trackPositions). Apart fro m that, the grid container can generate implicit grid tracks, | 856 // There are at least #tracks + 1 grid lines (trackPositions). Apart fro m that, the grid container can generate implicit grid tracks, |
| 841 // so we'll have more trackPositions than trackSizes as the latter only contain the explicit grid. | 857 // so we'll have more trackPositions than trackSizes as the latter only contain the explicit grid. |
| 842 ASSERT(trackPositions.size() - 1 >= trackSizes.size()); | 858 ASSERT(trackPositions.size() - 1 >= trackSizes.size()); |
| 843 | 859 |
| (...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3003 case CSSPropertyAll: | 3019 case CSSPropertyAll: |
| 3004 return nullptr; | 3020 return nullptr; |
| 3005 default: | 3021 default: |
| 3006 break; | 3022 break; |
| 3007 } | 3023 } |
| 3008 ASSERT_NOT_REACHED(); | 3024 ASSERT_NOT_REACHED(); |
| 3009 return nullptr; | 3025 return nullptr; |
| 3010 } | 3026 } |
| 3011 | 3027 |
| 3012 } // namespace blink | 3028 } // namespace blink |
| OLD | NEW |