OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv
ed. |
5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
6 * Copyright (C) 2010 Daniel Bates (dbates@intudata.com) | 6 * Copyright (C) 2010 Daniel Bates (dbates@intudata.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 break; | 1114 break; |
1115 case ListStyleCategory::Symbol: | 1115 case ListStyleCategory::Symbol: |
1116 m_text = listMarkerText(style()->listStyleType(), 0); // value is ignore
d for these types | 1116 m_text = listMarkerText(style()->listStyleType(), 0); // value is ignore
d for these types |
1117 break; | 1117 break; |
1118 case ListStyleCategory::Language: | 1118 case ListStyleCategory::Language: |
1119 m_text = listMarkerText(style()->listStyleType(), m_listItem->value()); | 1119 m_text = listMarkerText(style()->listStyleType(), m_listItem->value()); |
1120 break; | 1120 break; |
1121 } | 1121 } |
1122 } | 1122 } |
1123 | 1123 |
| 1124 LayoutUnit LayoutListMarker::getWidthOfTextWithSuffix() const |
| 1125 { |
| 1126 if (m_text.isEmpty()) |
| 1127 return 0; |
| 1128 const Font& font = style()->font(); |
| 1129 LayoutUnit itemWidth = font.width(m_text); |
| 1130 // TODO(wkorman): Look into constructing a text run for both text and suffix |
| 1131 // and painting them together. |
| 1132 UChar suffix[2] = { listMarkerSuffix(style()->listStyleType(), m_listItem->v
alue()), ' ' }; |
| 1133 TextRun run = constructTextRun(font, suffix, 2, styleRef(), style()->directi
on()); |
| 1134 LayoutUnit suffixSpaceWidth = font.width(run); |
| 1135 return itemWidth + suffixSpaceWidth; |
| 1136 } |
| 1137 |
1124 void LayoutListMarker::computePreferredLogicalWidths() | 1138 void LayoutListMarker::computePreferredLogicalWidths() |
1125 { | 1139 { |
1126 ASSERT(preferredLogicalWidthsDirty()); | 1140 ASSERT(preferredLogicalWidthsDirty()); |
1127 updateContent(); | 1141 updateContent(); |
1128 | 1142 |
1129 if (isImage()) { | 1143 if (isImage()) { |
1130 LayoutSize imageSize = m_image->imageSize(this, style()->effectiveZoom()
); | 1144 LayoutSize imageSize = m_image->imageSize(this, style()->effectiveZoom()
); |
1131 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); | 1145 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); |
1132 clearPreferredLogicalWidthsDirty(); | 1146 clearPreferredLogicalWidthsDirty(); |
1133 updateMargins(); | 1147 updateMargins(); |
1134 return; | 1148 return; |
1135 } | 1149 } |
1136 | 1150 |
1137 const Font& font = style()->font(); | 1151 const Font& font = style()->font(); |
1138 | 1152 |
1139 LayoutUnit logicalWidth = 0; | 1153 LayoutUnit logicalWidth = 0; |
1140 switch (listStyleCategory()) { | 1154 switch (listStyleCategory()) { |
1141 case ListStyleCategory::None: | 1155 case ListStyleCategory::None: |
1142 break; | 1156 break; |
1143 case ListStyleCategory::Symbol: | 1157 case ListStyleCategory::Symbol: |
1144 logicalWidth = (font.fontMetrics().ascent() * 2 / 3 + 1) / 2 + 2; | 1158 logicalWidth = (font.fontMetrics().ascent() * 2 / 3 + 1) / 2 + 2; |
1145 break; | 1159 break; |
1146 case ListStyleCategory::Language: | 1160 case ListStyleCategory::Language: |
1147 if (m_text.isEmpty()) { | 1161 logicalWidth = getWidthOfTextWithSuffix(); |
1148 logicalWidth = 0; | |
1149 } else { | |
1150 LayoutUnit itemWidth = font.width(m_text); | |
1151 UChar suffixSpace[2] = { listMarkerSuffix(style()->listStyleType(),
m_listItem->value()), ' ' }; | |
1152 LayoutUnit suffixSpaceWidth = font.width(constructTextRun(font, suff
ixSpace, 2, styleRef(), style()->direction())); | |
1153 logicalWidth = itemWidth + suffixSpaceWidth; | |
1154 } | |
1155 break; | 1162 break; |
1156 } | 1163 } |
1157 | 1164 |
1158 m_minPreferredLogicalWidth = logicalWidth; | 1165 m_minPreferredLogicalWidth = logicalWidth; |
1159 m_maxPreferredLogicalWidth = logicalWidth; | 1166 m_maxPreferredLogicalWidth = logicalWidth; |
1160 | 1167 |
1161 clearPreferredLogicalWidthsDirty(); | 1168 clearPreferredLogicalWidthsDirty(); |
1162 | 1169 |
1163 updateMargins(); | 1170 updateMargins(); |
1164 } | 1171 } |
(...skipping 18 matching lines...) Expand all Loading... |
1183 break; | 1190 break; |
1184 } | 1191 } |
1185 } | 1192 } |
1186 } else { | 1193 } else { |
1187 if (style()->isLeftToRightDirection()) { | 1194 if (style()->isLeftToRightDirection()) { |
1188 if (isImage()) { | 1195 if (isImage()) { |
1189 marginStart = -minPreferredLogicalWidth() - cMarkerPadding; | 1196 marginStart = -minPreferredLogicalWidth() - cMarkerPadding; |
1190 } else { | 1197 } else { |
1191 int offset = fontMetrics.ascent() * 2 / 3; | 1198 int offset = fontMetrics.ascent() * 2 / 3; |
1192 switch (listStyleCategory()) { | 1199 switch (listStyleCategory()) { |
| 1200 case ListStyleCategory::None: |
| 1201 break; |
1193 case ListStyleCategory::Symbol: | 1202 case ListStyleCategory::Symbol: |
1194 marginStart = -offset - cMarkerPadding - 1; | 1203 marginStart = -offset - cMarkerPadding - 1; |
1195 break; | 1204 break; |
1196 case ListStyleCategory::None: | |
1197 break; | |
1198 default: | 1205 default: |
1199 marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferre
dLogicalWidth() - offset / 2; | 1206 marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferre
dLogicalWidth(); |
1200 } | 1207 } |
1201 } | 1208 } |
1202 marginEnd = -marginStart - minPreferredLogicalWidth(); | 1209 marginEnd = -marginStart - minPreferredLogicalWidth(); |
1203 } else { | 1210 } else { |
1204 if (isImage()) { | 1211 if (isImage()) { |
1205 marginEnd = cMarkerPadding; | 1212 marginEnd = cMarkerPadding; |
1206 } else { | 1213 } else { |
1207 int offset = fontMetrics.ascent() * 2 / 3; | 1214 int offset = fontMetrics.ascent() * 2 / 3; |
1208 switch (listStyleCategory()) { | 1215 switch (listStyleCategory()) { |
| 1216 case ListStyleCategory::None: |
| 1217 break; |
1209 case ListStyleCategory::Symbol: | 1218 case ListStyleCategory::Symbol: |
1210 marginEnd = offset + cMarkerPadding + 1 - minPreferredLogica
lWidth(); | 1219 marginEnd = offset + cMarkerPadding + 1 - minPreferredLogica
lWidth(); |
1211 break; | 1220 break; |
1212 case ListStyleCategory::None: | |
1213 break; | |
1214 default: | 1221 default: |
1215 marginEnd = m_text.isEmpty() ? 0 : offset / 2; | 1222 marginEnd = 0; |
1216 } | 1223 } |
1217 } | 1224 } |
1218 marginStart = -marginEnd - minPreferredLogicalWidth(); | 1225 marginStart = -marginEnd - minPreferredLogicalWidth(); |
1219 } | 1226 } |
1220 | 1227 |
1221 } | 1228 } |
1222 | 1229 |
1223 mutableStyleRef().setMarginStart(Length(marginStart, Fixed)); | 1230 mutableStyleRef().setMarginStart(Length(marginStart, Fixed)); |
1224 mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed)); | 1231 mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed)); |
1225 } | 1232 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 switch (listStyleCategory()) { | 1328 switch (listStyleCategory()) { |
1322 case ListStyleCategory::None: | 1329 case ListStyleCategory::None: |
1323 return IntRect(); | 1330 return IntRect(); |
1324 case ListStyleCategory::Symbol: { | 1331 case ListStyleCategory::Symbol: { |
1325 // TODO(wkorman): Review and clean up/document the calculations below. | 1332 // TODO(wkorman): Review and clean up/document the calculations below. |
1326 // http://crbug.com/543193 | 1333 // http://crbug.com/543193 |
1327 const FontMetrics& fontMetrics = style()->fontMetrics(); | 1334 const FontMetrics& fontMetrics = style()->fontMetrics(); |
1328 int ascent = fontMetrics.ascent(); | 1335 int ascent = fontMetrics.ascent(); |
1329 int bulletWidth = (ascent * 2 / 3 + 1) / 2; | 1336 int bulletWidth = (ascent * 2 / 3 + 1) / 2; |
1330 relativeRect = IntRect(1, 3 * (ascent - ascent * 2 / 3) / 2, bulletWidth
, bulletWidth); | 1337 relativeRect = IntRect(1, 3 * (ascent - ascent * 2 / 3) / 2, bulletWidth
, bulletWidth); |
| 1338 } |
1331 break; | 1339 break; |
1332 } | |
1333 case ListStyleCategory::Language: | 1340 case ListStyleCategory::Language: |
1334 if (m_text.isEmpty()) | 1341 relativeRect = IntRect(0, 0, getWidthOfTextWithSuffix(), style()->font()
.fontMetrics().height()); |
1335 return IntRect(); | 1342 break; |
1336 const Font& font = style()->font(); | |
1337 int itemWidth = font.width(m_text); | |
1338 UChar suffixSpace[2] = { listMarkerSuffix(style()->listStyleType(), m_li
stItem->value()), ' ' }; | |
1339 int suffixSpaceWidth = font.width(constructTextRun(font, suffixSpace, 2,
styleRef(), style()->direction())); | |
1340 relativeRect = IntRect(0, 0, itemWidth + suffixSpaceWidth, font.fontMetr
ics().height()); | |
1341 } | 1343 } |
1342 | 1344 |
1343 if (!style()->isHorizontalWritingMode()) { | 1345 if (!style()->isHorizontalWritingMode()) { |
1344 relativeRect = relativeRect.transposedRect(); | 1346 relativeRect = relativeRect.transposedRect(); |
1345 relativeRect.setX(size().width() - relativeRect.x() - relativeRect.width
()); | 1347 relativeRect.setX(size().width() - relativeRect.x() - relativeRect.width
()); |
1346 } | 1348 } |
1347 | 1349 |
1348 return relativeRect; | 1350 return relativeRect; |
1349 } | 1351 } |
1350 | 1352 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 if (style()) { | 1384 if (style()) { |
1383 // Reuse the current margins. Otherwise resetting the margins to initial
values | 1385 // Reuse the current margins. Otherwise resetting the margins to initial
values |
1384 // would trigger unnecessary layout. | 1386 // would trigger unnecessary layout. |
1385 newStyle->setMarginStart(style()->marginStart()); | 1387 newStyle->setMarginStart(style()->marginStart()); |
1386 newStyle->setMarginEnd(style()->marginRight()); | 1388 newStyle->setMarginEnd(style()->marginRight()); |
1387 } | 1389 } |
1388 setStyle(newStyle.release()); | 1390 setStyle(newStyle.release()); |
1389 } | 1391 } |
1390 | 1392 |
1391 } // namespace blink | 1393 } // namespace blink |
OLD | NEW |