| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 LayoutListMarker* LayoutListMarker::createAnonymous(LayoutListItem* item) | 60 LayoutListMarker* LayoutListMarker::createAnonymous(LayoutListItem* item) |
| 61 { | 61 { |
| 62 Document& document = item->document(); | 62 Document& document = item->document(); |
| 63 LayoutListMarker* layoutObject = new LayoutListMarker(item); | 63 LayoutListMarker* layoutObject = new LayoutListMarker(item); |
| 64 layoutObject->setDocumentForAnonymous(&document); | 64 layoutObject->setDocumentForAnonymous(&document); |
| 65 return layoutObject; | 65 return layoutObject; |
| 66 } | 66 } |
| 67 | 67 |
| 68 IntSize LayoutListMarker::imageBulletSize() const |
| 69 { |
| 70 ASSERT(isImage()); |
| 71 |
| 72 // FIXME: This is a somewhat arbitrary default width. Generated images for m
arkers really won't |
| 73 // become particularly useful until we support the CSS3 marker pseudoclass t
o allow control over |
| 74 // the width and height of the marker box. |
| 75 int bulletWidth = style()->fontMetrics().ascent() / 2; |
| 76 IntSize defaultBulletSize(bulletWidth, bulletWidth); |
| 77 return calculateImageIntrinsicDimensions(m_image.get(), defaultBulletSize, D
oNotScaleByEffectiveZoom); |
| 78 } |
| 79 |
| 68 void LayoutListMarker::styleWillChange(StyleDifference diff, const ComputedStyle
& newStyle) | 80 void LayoutListMarker::styleWillChange(StyleDifference diff, const ComputedStyle
& newStyle) |
| 69 { | 81 { |
| 70 if (style() && (newStyle.listStylePosition() != style()->listStylePosition()
|| newStyle.listStyleType() != style()->listStyleType())) | 82 if (style() && (newStyle.listStylePosition() != style()->listStylePosition()
|| newStyle.listStyleType() != style()->listStyleType())) |
| 71 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::StyleChange); | 83 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::StyleChange); |
| 72 | 84 |
| 73 LayoutBox::styleWillChange(diff, newStyle); | 85 LayoutBox::styleWillChange(diff, newStyle); |
| 74 } | 86 } |
| 75 | 87 |
| 76 void LayoutListMarker::styleDidChange(StyleDifference diff, const ComputedStyle*
oldStyle) | 88 void LayoutListMarker::styleDidChange(StyleDifference diff, const ComputedStyle*
oldStyle) |
| 77 { | 89 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 ListMarkerPainter(*this).paint(paintInfo, paintOffset); | 130 ListMarkerPainter(*this).paint(paintInfo, paintOffset); |
| 119 } | 131 } |
| 120 | 132 |
| 121 void LayoutListMarker::layout() | 133 void LayoutListMarker::layout() |
| 122 { | 134 { |
| 123 ASSERT(needsLayout()); | 135 ASSERT(needsLayout()); |
| 124 LayoutAnalyzer::Scope analyzer(*this); | 136 LayoutAnalyzer::Scope analyzer(*this); |
| 125 | 137 |
| 126 if (isImage()) { | 138 if (isImage()) { |
| 127 updateMarginsAndContent(); | 139 updateMarginsAndContent(); |
| 128 setWidth(m_image->imageSize(this, style()->effectiveZoom()).width()); | 140 LayoutSize imageSize(imageBulletSize()); |
| 129 setHeight(m_image->imageSize(this, style()->effectiveZoom()).height()); | 141 setWidth(imageSize.width()); |
| 142 setHeight(imageSize.height()); |
| 130 } else { | 143 } else { |
| 131 setLogicalWidth(minPreferredLogicalWidth()); | 144 setLogicalWidth(minPreferredLogicalWidth()); |
| 132 setLogicalHeight(style()->fontMetrics().height()); | 145 setLogicalHeight(style()->fontMetrics().height()); |
| 133 } | 146 } |
| 134 | 147 |
| 135 setMarginStart(0); | 148 setMarginStart(0); |
| 136 setMarginEnd(0); | 149 setMarginEnd(0); |
| 137 | 150 |
| 138 Length startMargin = style()->marginStart(); | 151 Length startMargin = style()->marginStart(); |
| 139 Length endMargin = style()->marginEnd(); | 152 Length endMargin = style()->marginEnd(); |
| 140 if (startMargin.isFixed()) | 153 if (startMargin.isFixed()) |
| 141 setMarginStart(startMargin.value()); | 154 setMarginStart(startMargin.value()); |
| 142 if (endMargin.isFixed()) | 155 if (endMargin.isFixed()) |
| 143 setMarginEnd(endMargin.value()); | 156 setMarginEnd(endMargin.value()); |
| 144 | 157 |
| 145 clearNeedsLayout(); | 158 clearNeedsLayout(); |
| 146 } | 159 } |
| 147 | 160 |
| 148 void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*) | 161 void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*) |
| 149 { | 162 { |
| 150 // A list marker can't have a background or border image, so no need to call
the base class method. | 163 // A list marker can't have a background or border image, so no need to call
the base class method. |
| 151 if (o != m_image->data()) | 164 if (o != m_image->data()) |
| 152 return; | 165 return; |
| 153 | 166 |
| 154 if (size() != m_image->imageSize(this, style()->effectiveZoom()) || m_image-
>errorOccurred()) | 167 LayoutSize imageSize = isImage() ? LayoutSize(imageBulletSize()) : LayoutSiz
e(); |
| 168 if (size() != imageSize || m_image->errorOccurred()) |
| 155 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::ImageChanged); | 169 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::ImageChanged); |
| 156 else | 170 else |
| 157 setShouldDoFullPaintInvalidation(); | 171 setShouldDoFullPaintInvalidation(); |
| 158 } | 172 } |
| 159 | 173 |
| 160 void LayoutListMarker::updateMarginsAndContent() | 174 void LayoutListMarker::updateMarginsAndContent() |
| 161 { | 175 { |
| 162 updateContent(); | 176 updateContent(); |
| 163 updateMargins(); | 177 updateMargins(); |
| 164 } | 178 } |
| 165 | 179 |
| 166 void LayoutListMarker::updateContent() | 180 void LayoutListMarker::updateContent() |
| 167 { | 181 { |
| 168 // FIXME: This if-statement is just a performance optimization, but it's mes
sy to use the preferredLogicalWidths dirty bit for this. | 182 // FIXME: This if-statement is just a performance optimization, but it's mes
sy to use the preferredLogicalWidths dirty bit for this. |
| 169 // It's unclear if this is a premature optimization. | 183 // It's unclear if this is a premature optimization. |
| 170 if (!preferredLogicalWidthsDirty()) | 184 if (!preferredLogicalWidthsDirty()) |
| 171 return; | 185 return; |
| 172 | 186 |
| 173 m_text = ""; | 187 m_text = ""; |
| 174 | 188 |
| 175 if (isImage()) { | 189 if (isImage()) |
| 176 // FIXME: This is a somewhat arbitrary width. Generated images for mark
ers really won't become particularly useful | |
| 177 // until we support the CSS3 marker pseudoclass to allow control over th
e width and height of the marker box. | |
| 178 int bulletWidth = style()->fontMetrics().ascent() / 2; | |
| 179 IntSize defaultBulletSize(bulletWidth, bulletWidth); | |
| 180 IntSize imageSize = calculateImageIntrinsicDimensions(m_image.get(), def
aultBulletSize, DoNotScaleByEffectiveZoom); | |
| 181 m_image->setContainerSizeForLayoutObject(this, imageSize, style()->effec
tiveZoom()); | |
| 182 return; | 190 return; |
| 183 } | |
| 184 | 191 |
| 185 switch (listStyleCategory()) { | 192 switch (listStyleCategory()) { |
| 186 case ListStyleCategory::None: | 193 case ListStyleCategory::None: |
| 187 break; | 194 break; |
| 188 case ListStyleCategory::Symbol: | 195 case ListStyleCategory::Symbol: |
| 189 m_text = ListMarkerText::text(style()->listStyleType(), 0); // value is
ignored for these types | 196 m_text = ListMarkerText::text(style()->listStyleType(), 0); // value is
ignored for these types |
| 190 break; | 197 break; |
| 191 case ListStyleCategory::Language: | 198 case ListStyleCategory::Language: |
| 192 m_text = ListMarkerText::text(style()->listStyleType(), m_listItem->valu
e()); | 199 m_text = ListMarkerText::text(style()->listStyleType(), m_listItem->valu
e()); |
| 193 break; | 200 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 LayoutUnit suffixSpaceWidth = font.width(run); | 214 LayoutUnit suffixSpaceWidth = font.width(run); |
| 208 return itemWidth + suffixSpaceWidth; | 215 return itemWidth + suffixSpaceWidth; |
| 209 } | 216 } |
| 210 | 217 |
| 211 void LayoutListMarker::computePreferredLogicalWidths() | 218 void LayoutListMarker::computePreferredLogicalWidths() |
| 212 { | 219 { |
| 213 ASSERT(preferredLogicalWidthsDirty()); | 220 ASSERT(preferredLogicalWidthsDirty()); |
| 214 updateContent(); | 221 updateContent(); |
| 215 | 222 |
| 216 if (isImage()) { | 223 if (isImage()) { |
| 217 LayoutSize imageSize = m_image->imageSize(this, style()->effectiveZoom()
); | 224 LayoutSize imageSize(imageBulletSize()); |
| 218 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); | 225 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHor
izontalWritingMode() ? imageSize.width() : imageSize.height(); |
| 219 clearPreferredLogicalWidthsDirty(); | 226 clearPreferredLogicalWidthsDirty(); |
| 220 updateMargins(); | 227 updateMargins(); |
| 221 return; | 228 return; |
| 222 } | 229 } |
| 223 | 230 |
| 224 const Font& font = style()->font(); | 231 const Font& font = style()->font(); |
| 225 | 232 |
| 226 LayoutUnit logicalWidth = 0; | 233 LayoutUnit logicalWidth = 0; |
| 227 switch (listStyleCategory()) { | 234 switch (listStyleCategory()) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 394 } |
| 388 } | 395 } |
| 389 | 396 |
| 390 bool LayoutListMarker::isInside() const | 397 bool LayoutListMarker::isInside() const |
| 391 { | 398 { |
| 392 return m_listItem->notInList() || style()->listStylePosition() == INSIDE; | 399 return m_listItem->notInList() || style()->listStylePosition() == INSIDE; |
| 393 } | 400 } |
| 394 | 401 |
| 395 IntRect LayoutListMarker::getRelativeMarkerRect() const | 402 IntRect LayoutListMarker::getRelativeMarkerRect() const |
| 396 { | 403 { |
| 397 if (isImage()) | 404 if (isImage()) { |
| 398 return IntRect(0, 0, m_image->imageSize(this, style()->effectiveZoom()).
width(), m_image->imageSize(this, style()->effectiveZoom()).height()); | 405 IntSize imageSize = imageBulletSize(); |
| 406 return IntRect(0, 0, imageSize.width(), imageSize.height()); |
| 407 } |
| 399 | 408 |
| 400 IntRect relativeRect; | 409 IntRect relativeRect; |
| 401 switch (listStyleCategory()) { | 410 switch (listStyleCategory()) { |
| 402 case ListStyleCategory::None: | 411 case ListStyleCategory::None: |
| 403 return IntRect(); | 412 return IntRect(); |
| 404 case ListStyleCategory::Symbol: { | 413 case ListStyleCategory::Symbol: { |
| 405 // TODO(wkorman): Review and clean up/document the calculations below. | 414 // TODO(wkorman): Review and clean up/document the calculations below. |
| 406 // http://crbug.com/543193 | 415 // http://crbug.com/543193 |
| 407 const FontMetrics& fontMetrics = style()->fontMetrics(); | 416 const FontMetrics& fontMetrics = style()->fontMetrics(); |
| 408 int ascent = fontMetrics.ascent(); | 417 int ascent = fontMetrics.ascent(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 if (style()) { | 466 if (style()) { |
| 458 // Reuse the current margins. Otherwise resetting the margins to initial
values | 467 // Reuse the current margins. Otherwise resetting the margins to initial
values |
| 459 // would trigger unnecessary layout. | 468 // would trigger unnecessary layout. |
| 460 newStyle->setMarginStart(style()->marginStart()); | 469 newStyle->setMarginStart(style()->marginStart()); |
| 461 newStyle->setMarginEnd(style()->marginRight()); | 470 newStyle->setMarginEnd(style()->marginRight()); |
| 462 } | 471 } |
| 463 setStyle(newStyle.release()); | 472 setStyle(newStyle.release()); |
| 464 } | 473 } |
| 465 | 474 |
| 466 } // namespace blink | 475 } // namespace blink |
| OLD | NEW |