| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 ASSERT(needsLayout()); | 133 ASSERT(needsLayout()); |
| 134 LayoutAnalyzer::Scope analyzer(*this); | 134 LayoutAnalyzer::Scope analyzer(*this); |
| 135 | 135 |
| 136 if (isImage()) { | 136 if (isImage()) { |
| 137 updateMarginsAndContent(); | 137 updateMarginsAndContent(); |
| 138 LayoutSize imageSize(imageBulletSize()); | 138 LayoutSize imageSize(imageBulletSize()); |
| 139 setWidth(imageSize.width()); | 139 setWidth(imageSize.width()); |
| 140 setHeight(imageSize.height()); | 140 setHeight(imageSize.height()); |
| 141 } else { | 141 } else { |
| 142 setLogicalWidth(minPreferredLogicalWidth()); | 142 setLogicalWidth(minPreferredLogicalWidth()); |
| 143 setLogicalHeight(style()->fontMetrics().height()); | 143 setLogicalHeight(LayoutUnit(style()->fontMetrics().height())); |
| 144 } | 144 } |
| 145 | 145 |
| 146 setMarginStart(0); | 146 setMarginStart(LayoutUnit()); |
| 147 setMarginEnd(0); | 147 setMarginEnd(LayoutUnit()); |
| 148 | 148 |
| 149 Length startMargin = style()->marginStart(); | 149 Length startMargin = style()->marginStart(); |
| 150 Length endMargin = style()->marginEnd(); | 150 Length endMargin = style()->marginEnd(); |
| 151 if (startMargin.isFixed()) | 151 if (startMargin.isFixed()) |
| 152 setMarginStart(startMargin.value()); | 152 setMarginStart(LayoutUnit(startMargin.value())); |
| 153 if (endMargin.isFixed()) | 153 if (endMargin.isFixed()) |
| 154 setMarginEnd(endMargin.value()); | 154 setMarginEnd(LayoutUnit(endMargin.value())); |
| 155 | 155 |
| 156 clearNeedsLayout(); | 156 clearNeedsLayout(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*) | 159 void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*) |
| 160 { | 160 { |
| 161 // A list marker can't have a background or border image, so no need to call
the base class method. | 161 // A list marker can't have a background or border image, so no need to call
the base class method. |
| 162 if (o != m_image->data()) | 162 if (o != m_image->data()) |
| 163 return; | 163 return; |
| 164 | 164 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 195 break; | 195 break; |
| 196 case ListStyleCategory::Language: | 196 case ListStyleCategory::Language: |
| 197 m_text = ListMarkerText::text(style()->listStyleType(), m_listItem->valu
e()); | 197 m_text = ListMarkerText::text(style()->listStyleType(), m_listItem->valu
e()); |
| 198 break; | 198 break; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 LayoutUnit LayoutListMarker::getWidthOfTextWithSuffix() const | 202 LayoutUnit LayoutListMarker::getWidthOfTextWithSuffix() const |
| 203 { | 203 { |
| 204 if (m_text.isEmpty()) | 204 if (m_text.isEmpty()) |
| 205 return 0; | 205 return LayoutUnit(); |
| 206 const Font& font = style()->font(); | 206 const Font& font = style()->font(); |
| 207 LayoutUnit itemWidth = font.width(m_text); | 207 LayoutUnit itemWidth = LayoutUnit(font.width(m_text)); |
| 208 // TODO(wkorman): Look into constructing a text run for both text and suffix | 208 // TODO(wkorman): Look into constructing a text run for both text and suffix |
| 209 // and painting them together. | 209 // and painting them together. |
| 210 UChar suffix[2] = { ListMarkerText::suffix(style()->listStyleType(), m_listI
tem->value()), ' ' }; | 210 UChar suffix[2] = { ListMarkerText::suffix(style()->listStyleType(), m_listI
tem->value()), ' ' }; |
| 211 TextRun run = constructTextRun(font, suffix, 2, styleRef(), style()->directi
on()); | 211 TextRun run = constructTextRun(font, suffix, 2, styleRef(), style()->directi
on()); |
| 212 LayoutUnit suffixSpaceWidth = font.width(run); | 212 LayoutUnit suffixSpaceWidth = LayoutUnit(font.width(run)); |
| 213 return itemWidth + suffixSpaceWidth; | 213 return itemWidth + suffixSpaceWidth; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void LayoutListMarker::computePreferredLogicalWidths() | 216 void LayoutListMarker::computePreferredLogicalWidths() |
| 217 { | 217 { |
| 218 ASSERT(preferredLogicalWidthsDirty()); | 218 ASSERT(preferredLogicalWidthsDirty()); |
| 219 updateContent(); | 219 updateContent(); |
| 220 | 220 |
| 221 if (isImage()) { | 221 if (isImage()) { |
| 222 LayoutSize imageSize(imageBulletSize()); | 222 LayoutSize imageSize(imageBulletSize()); |
| 223 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); | 223 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); |
| 224 clearPreferredLogicalWidthsDirty(); | 224 clearPreferredLogicalWidthsDirty(); |
| 225 updateMargins(); | 225 updateMargins(); |
| 226 return; | 226 return; |
| 227 } | 227 } |
| 228 | 228 |
| 229 const Font& font = style()->font(); | 229 const Font& font = style()->font(); |
| 230 | 230 |
| 231 LayoutUnit logicalWidth; | 231 LayoutUnit logicalWidth; |
| 232 switch (listStyleCategory()) { | 232 switch (listStyleCategory()) { |
| 233 case ListStyleCategory::None: | 233 case ListStyleCategory::None: |
| 234 break; | 234 break; |
| 235 case ListStyleCategory::Symbol: | 235 case ListStyleCategory::Symbol: |
| 236 logicalWidth = (font.fontMetrics().ascent() * 2 / 3 + 1) / 2 + 2; | 236 logicalWidth = LayoutUnit((font.fontMetrics().ascent() * 2 / 3 + 1) / 2
+ 2); |
| 237 break; | 237 break; |
| 238 case ListStyleCategory::Language: | 238 case ListStyleCategory::Language: |
| 239 logicalWidth = getWidthOfTextWithSuffix(); | 239 logicalWidth = getWidthOfTextWithSuffix(); |
| 240 break; | 240 break; |
| 241 } | 241 } |
| 242 | 242 |
| 243 m_minPreferredLogicalWidth = logicalWidth; | 243 m_minPreferredLogicalWidth = logicalWidth; |
| 244 m_maxPreferredLogicalWidth = logicalWidth; | 244 m_maxPreferredLogicalWidth = logicalWidth; |
| 245 | 245 |
| 246 clearPreferredLogicalWidthsDirty(); | 246 clearPreferredLogicalWidthsDirty(); |
| 247 | 247 |
| 248 updateMargins(); | 248 updateMargins(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void LayoutListMarker::updateMargins() | 251 void LayoutListMarker::updateMargins() |
| 252 { | 252 { |
| 253 const FontMetrics& fontMetrics = style()->fontMetrics(); | 253 const FontMetrics& fontMetrics = style()->fontMetrics(); |
| 254 | 254 |
| 255 LayoutUnit marginStart; | 255 LayoutUnit marginStart; |
| 256 LayoutUnit marginEnd; | 256 LayoutUnit marginEnd; |
| 257 | 257 |
| 258 if (isInside()) { | 258 if (isInside()) { |
| 259 if (isImage()) { | 259 if (isImage()) { |
| 260 marginEnd = cMarkerPaddingPx; | 260 marginEnd = LayoutUnit(cMarkerPaddingPx); |
| 261 } else { | 261 } else { |
| 262 switch (listStyleCategory()) { | 262 switch (listStyleCategory()) { |
| 263 case ListStyleCategory::Symbol: | 263 case ListStyleCategory::Symbol: |
| 264 marginStart = -1; | 264 marginStart = LayoutUnit(-1); |
| 265 marginEnd = fontMetrics.ascent() - minPreferredLogicalWidth() +
1; | 265 marginEnd = fontMetrics.ascent() - minPreferredLogicalWidth() +
1; |
| 266 break; | 266 break; |
| 267 default: | 267 default: |
| 268 break; | 268 break; |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 } else { | 271 } else { |
| 272 if (style()->isLeftToRightDirection()) { | 272 if (style()->isLeftToRightDirection()) { |
| 273 if (isImage()) { | 273 if (isImage()) { |
| 274 marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx; | 274 marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx; |
| 275 } else { | 275 } else { |
| 276 int offset = fontMetrics.ascent() * 2 / 3; | 276 int offset = fontMetrics.ascent() * 2 / 3; |
| 277 switch (listStyleCategory()) { | 277 switch (listStyleCategory()) { |
| 278 case ListStyleCategory::None: | 278 case ListStyleCategory::None: |
| 279 break; | 279 break; |
| 280 case ListStyleCategory::Symbol: | 280 case ListStyleCategory::Symbol: |
| 281 marginStart = -offset - cMarkerPaddingPx - 1; | 281 marginStart = LayoutUnit(-offset - cMarkerPaddingPx - 1); |
| 282 break; | 282 break; |
| 283 default: | 283 default: |
| 284 marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferre
dLogicalWidth(); | 284 marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferre
dLogicalWidth(); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 marginEnd = -marginStart - minPreferredLogicalWidth(); | 287 marginEnd = -marginStart - minPreferredLogicalWidth(); |
| 288 } else { | 288 } else { |
| 289 if (isImage()) { | 289 if (isImage()) { |
| 290 marginEnd = cMarkerPaddingPx; | 290 marginEnd = LayoutUnit(cMarkerPaddingPx); |
| 291 } else { | 291 } else { |
| 292 int offset = fontMetrics.ascent() * 2 / 3; | 292 int offset = fontMetrics.ascent() * 2 / 3; |
| 293 switch (listStyleCategory()) { | 293 switch (listStyleCategory()) { |
| 294 case ListStyleCategory::None: | 294 case ListStyleCategory::None: |
| 295 break; | 295 break; |
| 296 case ListStyleCategory::Symbol: | 296 case ListStyleCategory::Symbol: |
| 297 marginEnd = offset + cMarkerPaddingPx + 1 - minPreferredLogi
calWidth(); | 297 marginEnd = offset + cMarkerPaddingPx + 1 - minPreferredLogi
calWidth(); |
| 298 break; | 298 break; |
| 299 default: | 299 default: |
| 300 marginEnd = 0; | 300 marginEnd = LayoutUnit(); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 marginStart = -marginEnd - minPreferredLogicalWidth(); | 303 marginStart = -marginEnd - minPreferredLogicalWidth(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 } | 306 } |
| 307 | 307 |
| 308 mutableStyleRef().setMarginStart(Length(marginStart, Fixed)); | 308 mutableStyleRef().setMarginStart(Length(marginStart, Fixed)); |
| 309 mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed)); | 309 mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed)); |
| 310 } | 310 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (style()) { | 464 if (style()) { |
| 465 // Reuse the current margins. Otherwise resetting the margins to initial
values | 465 // Reuse the current margins. Otherwise resetting the margins to initial
values |
| 466 // would trigger unnecessary layout. | 466 // would trigger unnecessary layout. |
| 467 newStyle->setMarginStart(style()->marginStart()); | 467 newStyle->setMarginStart(style()->marginStart()); |
| 468 newStyle->setMarginEnd(style()->marginRight()); | 468 newStyle->setMarginEnd(style()->marginRight()); |
| 469 } | 469 } |
| 470 setStyle(newStyle.release()); | 470 setStyle(newStyle.release()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace blink | 473 } // namespace blink |
| OLD | NEW |