Changeset 291956 in webkit for trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
- Timestamp:
- Mar 27, 2022, 9:18:05 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r291690 r291956 36 36 #include "CSSFunctionValue.h" 37 37 #include "CSSGridAutoRepeatValue.h" 38 #include "CSSGridIntegerRepeatValue.h" 38 39 #include "CSSLineBoxContainValue.h" 39 40 #include "CSSPrimitiveValue.h" … … 856 857 857 858 bool isEmpty() const { return m_orderedNamedGridLines.isEmpty() && m_orderedNamedAutoRepeatGridLines.isEmpty(); } 858 virtual void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const ;859 virtual void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const = 0; 859 860 860 861 virtual int namedGridLineCount() const { return m_orderedNamedGridLines.size(); } … … 867 868 const OrderedNamedGridLinesMap& m_orderedNamedGridLines; 868 869 const OrderedNamedGridLinesMap& m_orderedNamedAutoRepeatGridLines; 869 };870 871 class OrderedNamedLinesCollectorInsideRepeat : public OrderedNamedLinesCollector {872 public:873 OrderedNamedLinesCollectorInsideRepeat(const RenderStyle& style, bool isRowAxis)874 : OrderedNamedLinesCollector(style, isRowAxis)875 {876 }877 878 void collectLineNamesForIndex(CSSGridLineNamesValue&, unsigned index) const override;879 880 int namedGridLineCount() const override { return m_orderedNamedAutoRepeatGridLines.size(); }881 870 }; 882 871 … … 942 931 } 943 932 944 void OrderedNamedLinesCollector::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const945 {946 ASSERT(!isEmpty());947 appendLines(lineNamesValue, i, NamedLines);948 }949 950 void OrderedNamedLinesCollectorInsideRepeat::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const951 {952 ASSERT(!isEmpty());953 appendLines(lineNamesValue, i, AutoRepeatNamedLines);954 }955 956 933 void OrderedNamedLinesCollectorInGridLayout::collectLineNamesForIndex(CSSGridLineNamesValue& lineNamesValue, unsigned i) const 957 934 { … … 1025 1002 1026 1003 template <typename T, typename F> 1027 void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int start, int end, int offset = 0) 1028 { 1029 ASSERT(0 <= start); 1004 void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int offset = 0) 1005 { 1006 int start = 0; 1007 int end = tracks.size(); 1030 1008 ASSERT(start <= end); 1031 1009 ASSERT(static_cast<unsigned>(end) <= tracks.size()); … … 1039 1017 } 1040 1018 1041 template <typename T, typename F> 1042 void populateGridTrackList(CSSValueList& list, OrderedNamedLinesCollector& collector, const Vector<T>& tracks, F getTrackSize, int offset = 0) 1043 { 1044 populateGridTrackList<T>(list, collector, tracks, getTrackSize, 0, tracks.size(), offset); 1045 } 1046 1047 static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector, int start, int end) 1048 { 1049 for (int i = start; i < end; i++) 1019 static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector) 1020 { 1021 for (int i = 0; i < collector.namedGridLineCount(); i++) 1050 1022 addValuesForNamedGridLinesAtIndex(collector, i, list, true); 1051 }1052 1053 static void populateSubgridLineNameList(CSSValueList& list, OrderedNamedLinesCollector& collector)1054 {1055 populateSubgridLineNameList(list, collector, 0, collector.namedGridLineCount());1056 1023 } 1057 1024 … … 1078 1045 1079 1046 auto list = CSSValueList::createSpaceSeparated(); 1080 if (isSubgrid)1081 list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid));1082 1047 1083 1048 // If the element is a grid container, the resolved value is the used value, … … 1088 1053 auto* grid = downcast<RenderGrid>(renderer); 1089 1054 if (isSubgrid) { 1055 list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid)); 1056 1090 1057 OrderedNamedLinesCollectorInSubgridLayout collector(style, isRowAxis, grid->numTracks(direction)); 1091 1058 populateSubgridLineNameList(list.get(), collector); … … 1103 1070 1104 1071 // Otherwise, the resolved value is the computed value, preserving repeat(). 1105 OrderedNamedLinesCollector collector(style, isRowAxis); 1106 auto getTrackSize = [&](const GridTrackSize& v) { 1107 return specifiedValueForGridTrackSize(v, style); 1072 const GridTrackList& computedTracks = isRowAxis ? style.gridColumnList() : style.gridRowList(); 1073 1074 auto repeatVisitor = [&](CSSValueList& dest, const RepeatEntry& entry) { 1075 if (std::holds_alternative<Vector<String>>(entry)) { 1076 auto lineNamesValue = CSSGridLineNamesValue::create(); 1077 for (const auto& name : std::get<Vector<String>>(entry)) 1078 lineNamesValue->append(CSSValuePool::singleton().createCustomIdent(name)); 1079 dest.append(lineNamesValue); 1080 } else { 1081 dest.append(specifiedValueForGridTrackSize(std::get<GridTrackSize>(entry), style)); 1082 } 1108 1083 }; 1109 1084 1110 OrderedNamedLinesCollectorInsideRepeat repeatCollector(style, isRowAxis); 1111 if (isSubgrid) { 1112 if (!repeatCollector.namedGridLineCount()) { 1113 populateSubgridLineNameList(list.get(), collector); 1114 return list; 1115 } 1116 1117 // Add the line names that precede the auto repeat(). 1118 int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint(); 1119 autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, collector.namedGridLineCount()); 1120 populateSubgridLineNameList(list.get(), collector, 0, autoRepeatInsertionPoint); 1121 1122 // Add a CSSGridAutoRepeatValue with the contents of the auto repeat(). 1123 ASSERT((isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType()) == AutoRepeatType::Fill); 1124 auto repeatedValues = CSSGridAutoRepeatValue::create(CSSValueAutoFill); 1125 populateSubgridLineNameList(repeatedValues.get(), repeatCollector); 1126 list->append(repeatedValues.get()); 1127 1128 // Add the line names that follow the auto repeat(). 1129 populateSubgridLineNameList(list.get(), collector, autoRepeatInsertionPoint, collector.namedGridLineCount()); 1130 return list; 1131 } 1132 1133 if (autoRepeatTrackSizes.isEmpty()) { 1134 // If there's no auto repeat(), just add all the line names and track sizes. 1135 populateGridTrackList(list.get(), collector, trackSizes, getTrackSize); 1136 return list; 1137 } 1138 1139 // Add the line names and track sizes that precede the auto repeat(). 1140 int autoRepeatInsertionPoint = isRowAxis ? style.gridAutoRepeatColumnsInsertionPoint() : style.gridAutoRepeatRowsInsertionPoint(); 1141 autoRepeatInsertionPoint = std::clamp<int>(autoRepeatInsertionPoint, 0, trackSizes.size()); 1142 populateGridTrackList(list.get(), collector, trackSizes, getTrackSize, 0, autoRepeatInsertionPoint); 1143 1144 // Add a CSSGridAutoRepeatValue with the contents of the auto repeat(). 1145 AutoRepeatType autoRepeatType = isRowAxis ? style.gridAutoRepeatColumnsType() : style.gridAutoRepeatRowsType(); 1146 auto repeatedValues = CSSGridAutoRepeatValue::create(autoRepeatType == AutoRepeatType::Fill ? CSSValueAutoFill : CSSValueAutoFit); 1147 1148 populateGridTrackList(repeatedValues.get(), repeatCollector, autoRepeatTrackSizes, getTrackSize); 1149 list->append(repeatedValues.get()); 1150 1151 // Add the line names and track sizes that follow the auto repeat(). 1152 populateGridTrackList(list.get(), collector, trackSizes, getTrackSize, autoRepeatInsertionPoint, trackSizes.size(), 1); 1085 auto trackEntryVisitor = WTF::makeVisitor([&](const GridTrackSize& size) { 1086 list->append(specifiedValueForGridTrackSize(size, style)); 1087 }, [&](const Vector<String>& names) { 1088 auto lineNamesValue = CSSGridLineNamesValue::create(); 1089 for (const auto& name : names) 1090 lineNamesValue->append(CSSValuePool::singleton().createCustomIdent(name)); 1091 list->append(lineNamesValue); 1092 }, [&](const GridTrackEntryRepeat& repeat) { 1093 auto repeatedValues = CSSGridIntegerRepeatValue::create(repeat.repeats); 1094 for (const auto& entry : repeat.list) 1095 repeatVisitor(repeatedValues, entry); 1096 list->append(repeatedValues); 1097 }, [&](const GridTrackEntryAutoRepeat& repeat) { 1098 auto repeatedValues = CSSGridAutoRepeatValue::create(repeat.type == AutoRepeatType::Fill ? CSSValueAutoFill : CSSValueAutoFit); 1099 for (const auto& entry : repeat.list) 1100 repeatVisitor(repeatedValues, entry); 1101 list->append(repeatedValues); 1102 }, [&](const GridTrackEntrySubgrid&) { 1103 list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueSubgrid)); 1104 }); 1105 1106 for (const auto& entry : computedTracks) 1107 std::visit(trackEntryVisitor, entry); 1108 1153 1109 return list; 1154 1110 }
Note:
See TracChangeset
for help on using the changeset viewer.