| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == bo
x->lineLayoutItem(); prev = prev->prevRootBox()) { | 187 for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == bo
x->lineLayoutItem(); prev = prev->prevRootBox()) { |
| 188 prev->setLineBreakInfo(0, 0, BidiStatus()); | 188 prev->setLineBreakInfo(0, 0, BidiStatus()); |
| 189 prev->markDirty(); | 189 prev->markDirty(); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, G
lyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& vertical
PositionCache) | 193 LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, G
lyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& vertical
PositionCache) |
| 194 { | 194 { |
| 195 // SVG will handle vertical alignment on its own. | 195 // SVG will handle vertical alignment on its own. |
| 196 if (isSVGRootInlineBox()) | 196 if (isSVGRootInlineBox()) |
| 197 return 0; | 197 return LayoutUnit(); |
| 198 | 198 |
| 199 LayoutUnit maxPositionTop; | 199 LayoutUnit maxPositionTop; |
| 200 LayoutUnit maxPositionBottom; | 200 LayoutUnit maxPositionBottom; |
| 201 int maxAscent = 0; | 201 int maxAscent = 0; |
| 202 int maxDescent = 0; | 202 int maxDescent = 0; |
| 203 bool setMaxAscent = false; | 203 bool setMaxAscent = false; |
| 204 bool setMaxDescent = false; | 204 bool setMaxDescent = false; |
| 205 | 205 |
| 206 // Figure out if we're in no-quirks mode. | 206 // Figure out if we're in no-quirks mode. |
| 207 bool noQuirksMode = lineLayoutItem().document().inNoQuirksMode(); | 207 bool noQuirksMode = lineLayoutItem().document().inNoQuirksMode(); |
| 208 | 208 |
| 209 m_baselineType = dominantBaseline(); | 209 m_baselineType = dominantBaseline(); |
| 210 | 210 |
| 211 computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent,
maxDescent, setMaxAscent, setMaxDescent, noQuirksMode, textBoxDataMap, baseline
Type(), verticalPositionCache); | 211 computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent,
maxDescent, setMaxAscent, setMaxDescent, noQuirksMode, textBoxDataMap, baseline
Type(), verticalPositionCache); |
| 212 | 212 |
| 213 if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom)) | 213 if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom)) |
| 214 adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPosi
tionBottom); | 214 adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPosi
tionBottom); |
| 215 | 215 |
| 216 LayoutUnit maxHeight = maxAscent + maxDescent; | 216 LayoutUnit maxHeight = LayoutUnit(maxAscent + maxDescent); |
| 217 LayoutUnit lineTop = heightOfBlock; | 217 LayoutUnit lineTop = heightOfBlock; |
| 218 LayoutUnit lineBottom = heightOfBlock; | 218 LayoutUnit lineBottom = heightOfBlock; |
| 219 LayoutUnit lineTopIncludingMargins = heightOfBlock; | 219 LayoutUnit lineTopIncludingMargins = heightOfBlock; |
| 220 LayoutUnit lineBottomIncludingMargins = heightOfBlock; | 220 LayoutUnit lineBottomIncludingMargins = heightOfBlock; |
| 221 LayoutUnit selectionBottom = heightOfBlock; | 221 LayoutUnit selectionBottom = heightOfBlock; |
| 222 bool setLineTop = false; | 222 bool setLineTop = false; |
| 223 bool hasAnnotationsBefore = false; | 223 bool hasAnnotationsBefore = false; |
| 224 bool hasAnnotationsAfter = false; | 224 bool hasAnnotationsAfter = false; |
| 225 placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode
, lineTop, lineBottom, selectionBottom, setLineTop, lineTopIncludingMargins, lin
eBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType
()); | 225 placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode
, lineTop, lineBottom, selectionBottom, setLineTop, lineTopIncludingMargins, lin
eBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType
()); |
| 226 m_hasAnnotationsBefore = hasAnnotationsBefore; | 226 m_hasAnnotationsBefore = hasAnnotationsBefore; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 597 } |
| 598 | 598 |
| 599 LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositio
nCache& verticalPositionCache) | 599 LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositio
nCache& verticalPositionCache) |
| 600 { | 600 { |
| 601 if (box->lineLayoutItem().isText()) | 601 if (box->lineLayoutItem().isText()) |
| 602 return box->parent()->logicalTop(); | 602 return box->parent()->logicalTop(); |
| 603 | 603 |
| 604 LineLayoutBoxModel boxModel = box->boxModelObject(); | 604 LineLayoutBoxModel boxModel = box->boxModelObject(); |
| 605 ASSERT(boxModel.isInline()); | 605 ASSERT(boxModel.isInline()); |
| 606 if (!boxModel.isInline()) | 606 if (!boxModel.isInline()) |
| 607 return 0; | 607 return LayoutUnit(); |
| 608 | 608 |
| 609 // This method determines the vertical position for inline elements. | 609 // This method determines the vertical position for inline elements. |
| 610 bool firstLine = isFirstLineStyle(); | 610 bool firstLine = isFirstLineStyle(); |
| 611 if (firstLine && !boxModel.document().styleEngine().usesFirstLineRules()) | 611 if (firstLine && !boxModel.document().styleEngine().usesFirstLineRules()) |
| 612 firstLine = false; | 612 firstLine = false; |
| 613 | 613 |
| 614 // Check the cache. | 614 // Check the cache. |
| 615 bool isLayoutInline = boxModel.isLayoutInline(); | 615 bool isLayoutInline = boxModel.isLayoutInline(); |
| 616 if (isLayoutInline && !firstLine) { | 616 if (isLayoutInline && !firstLine) { |
| 617 LayoutUnit verticalPosition = verticalPositionCache.get(boxModel, baseli
neType()); | 617 LayoutUnit verticalPosition = LayoutUnit(verticalPositionCache.get(boxMo
del, baselineType())); |
| 618 if (verticalPosition != PositionUndefined) | 618 if (verticalPosition != PositionUndefined) |
| 619 return verticalPosition; | 619 return verticalPosition; |
| 620 } | 620 } |
| 621 | 621 |
| 622 LayoutUnit verticalPosition; | 622 LayoutUnit verticalPosition; |
| 623 EVerticalAlign verticalAlign = boxModel.style()->verticalAlign(); | 623 EVerticalAlign verticalAlign = boxModel.style()->verticalAlign(); |
| 624 if (verticalAlign == TOP || verticalAlign == BOTTOM) | 624 if (verticalAlign == TOP || verticalAlign == BOTTOM) |
| 625 return 0; | 625 return LayoutUnit(); |
| 626 | 626 |
| 627 LineLayoutItem parent = boxModel.parent(); | 627 LineLayoutItem parent = boxModel.parent(); |
| 628 if (parent.isLayoutInline() && parent.style()->verticalAlign() != TOP && par
ent.style()->verticalAlign() != BOTTOM) | 628 if (parent.isLayoutInline() && parent.style()->verticalAlign() != TOP && par
ent.style()->verticalAlign() != BOTTOM) |
| 629 verticalPosition = box->parent()->logicalTop(); | 629 verticalPosition = box->parent()->logicalTop(); |
| 630 | 630 |
| 631 if (verticalAlign != BASELINE) { | 631 if (verticalAlign != BASELINE) { |
| 632 const Font& font = parent.style(firstLine)->font(); | 632 const Font& font = parent.style(firstLine)->font(); |
| 633 const FontMetrics& fontMetrics = font.fontMetrics(); | 633 const FontMetrics& fontMetrics = font.fontMetrics(); |
| 634 int fontSize = font.fontDescription().computedPixelSize(); | 634 int fontSize = font.fontDescription().computedPixelSize(); |
| 635 | 635 |
| 636 LineDirectionMode lineDirection = parent.isHorizontalWritingMode() ? Hor
izontalLine : VerticalLine; | 636 LineDirectionMode lineDirection = parent.isHorizontalWritingMode() ? Hor
izontalLine : VerticalLine; |
| 637 | 637 |
| 638 if (verticalAlign == SUB) { | 638 if (verticalAlign == SUB) { |
| 639 verticalPosition += fontSize / 5 + 1; | 639 verticalPosition += fontSize / 5 + 1; |
| 640 } else if (verticalAlign == SUPER) { | 640 } else if (verticalAlign == SUPER) { |
| 641 verticalPosition -= fontSize / 3 + 1; | 641 verticalPosition -= fontSize / 3 + 1; |
| 642 } else if (verticalAlign == TEXT_TOP) { | 642 } else if (verticalAlign == TEXT_TOP) { |
| 643 verticalPosition += boxModel.baselinePosition(baselineType(), firstL
ine, lineDirection) - fontMetrics.ascent(baselineType()); | 643 verticalPosition += boxModel.baselinePosition(baselineType(), firstL
ine, lineDirection) - fontMetrics.ascent(baselineType()); |
| 644 } else if (verticalAlign == MIDDLE) { | 644 } else if (verticalAlign == MIDDLE) { |
| 645 verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontM
etrics.xHeight() / 2) - boxModel.lineHeight(firstLine, lineDirection) / 2 + boxM
odel.baselinePosition(baselineType(), firstLine, lineDirection)).round(); | 645 verticalPosition = LayoutUnit((verticalPosition - LayoutUnit(fontMet
rics.xHeight() / 2) |
| 646 - boxModel.lineHeight(firstLine, lineDirection) / 2 |
| 647 + boxModel.baselinePosition(baselineType(), firstLine, lineDirec
tion)).round()); |
| 646 } else if (verticalAlign == TEXT_BOTTOM) { | 648 } else if (verticalAlign == TEXT_BOTTOM) { |
| 647 verticalPosition += fontMetrics.descent(baselineType()); | 649 verticalPosition += fontMetrics.descent(baselineType()); |
| 648 // lineHeight - baselinePosition is always 0 for replaced elements (
except inline blocks), so don't bother wasting time in that case. | 650 // lineHeight - baselinePosition is always 0 for replaced elements (
except inline blocks), so don't bother wasting time in that case. |
| 649 if (!boxModel.isAtomicInlineLevel() || boxModel.isInlineBlockOrInlin
eTable()) | 651 if (!boxModel.isAtomicInlineLevel() || boxModel.isInlineBlockOrInlin
eTable()) |
| 650 verticalPosition -= (boxModel.lineHeight(firstLine, lineDirectio
n) - boxModel.baselinePosition(baselineType(), firstLine, lineDirection)); | 652 verticalPosition -= (boxModel.lineHeight(firstLine, lineDirectio
n) - boxModel.baselinePosition(baselineType(), firstLine, lineDirection)); |
| 651 } else if (verticalAlign == BASELINE_MIDDLE) { | 653 } else if (verticalAlign == BASELINE_MIDDLE) { |
| 652 verticalPosition += -boxModel.lineHeight(firstLine, lineDirection) /
2 + boxModel.baselinePosition(baselineType(), firstLine, lineDirection); | 654 verticalPosition += -boxModel.lineHeight(firstLine, lineDirection) /
2 + boxModel.baselinePosition(baselineType(), firstLine, lineDirection); |
| 653 } else if (verticalAlign == LENGTH) { | 655 } else if (verticalAlign == LENGTH) { |
| 654 LayoutUnit lineHeight; | 656 LayoutUnit lineHeight; |
| 655 // Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-alig
n: 'Percentages: refer to the 'line-height' of the element itself'. | 657 // Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-alig
n: 'Percentages: refer to the 'line-height' of the element itself'. |
| 656 if (boxModel.style()->verticalAlignLength().hasPercent()) | 658 if (boxModel.style()->verticalAlignLength().hasPercent()) |
| 657 lineHeight = boxModel.style()->computedLineHeight(); | 659 lineHeight = LayoutUnit(boxModel.style()->computedLineHeight()); |
| 658 else | 660 else |
| 659 lineHeight = boxModel.lineHeight(firstLine, lineDirection); | 661 lineHeight = boxModel.lineHeight(firstLine, lineDirection); |
| 660 verticalPosition -= valueForLength(boxModel.style()->verticalAlignLe
ngth(), lineHeight); | 662 verticalPosition -= valueForLength(boxModel.style()->verticalAlignLe
ngth(), lineHeight); |
| 661 } | 663 } |
| 662 } | 664 } |
| 663 | 665 |
| 664 // Store the cached value. | 666 // Store the cached value. |
| 665 if (isLayoutInline && !firstLine) | 667 if (isLayoutInline && !firstLine) |
| 666 verticalPositionCache.set(boxModel, baselineType(), verticalPosition); | 668 verticalPositionCache.set(boxModel, baselineType(), verticalPosition); |
| 667 | 669 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 endBox = nullptr; | 702 endBox = nullptr; |
| 701 return nullptr; | 703 return nullptr; |
| 702 } | 704 } |
| 703 | 705 |
| 704 const char* RootInlineBox::boxName() const | 706 const char* RootInlineBox::boxName() const |
| 705 { | 707 { |
| 706 return "RootInlineBox"; | 708 return "RootInlineBox"; |
| 707 } | 709 } |
| 708 | 710 |
| 709 } // namespace blink | 711 } // namespace blink |
| OLD | NEW |