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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 void RootInlineBox::clearTruncation() | 88 void RootInlineBox::clearTruncation() |
89 { | 89 { |
90 if (hasEllipsisBox()) { | 90 if (hasEllipsisBox()) { |
91 detachEllipsisBox(); | 91 detachEllipsisBox(); |
92 InlineFlowBox::clearTruncation(); | 92 InlineFlowBox::clearTruncation(); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 int RootInlineBox::baselinePosition(FontBaseline baselineType) const | 96 int RootInlineBox::baselinePosition(FontBaseline baselineType) const |
97 { | 97 { |
98 return boxModelObject()->baselinePosition(baselineType, isFirstLineStyle(),
isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); | 98 return boxModelObject().baselinePosition(baselineType, isFirstLineStyle(), i
sHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
99 } | 99 } |
100 | 100 |
101 LayoutUnit RootInlineBox::lineHeight() const | 101 LayoutUnit RootInlineBox::lineHeight() const |
102 { | 102 { |
103 return boxModelObject()->lineHeight(isFirstLineStyle(), isHorizontal() ? Hor
izontalLine : VerticalLine, PositionOfInteriorLineBoxes); | 103 return boxModelObject().lineHeight(isFirstLineStyle(), isHorizontal() ? Hori
zontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
104 } | 104 } |
105 | 105 |
106 bool RootInlineBox::lineCanAccommodateEllipsis(bool ltr, int blockEdge, int line
BoxEdge, int ellipsisWidth) | 106 bool RootInlineBox::lineCanAccommodateEllipsis(bool ltr, int blockEdge, int line
BoxEdge, int ellipsisWidth) |
107 { | 107 { |
108 // First sanity-check the unoverflowed width of the whole line to see if the
re is sufficient room. | 108 // First sanity-check the unoverflowed width of the whole line to see if the
re is sufficient room. |
109 int delta = ltr ? lineBoxEdge - blockEdge : blockEdge - lineBoxEdge; | 109 int delta = ltr ? lineBoxEdge - blockEdge : blockEdge - lineBoxEdge; |
110 if (logicalWidth() - delta < ellipsisWidth) | 110 if (logicalWidth() - delta < ellipsisWidth) |
111 return false; | 111 return false; |
112 | 112 |
113 // Next iterate over all the line boxes on the line. If we find a replaced
element that intersects | 113 // Next iterate over all the line boxes on the line. If we find a replaced
element that intersects |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 if (includeGlyphsForBox(box) && glyphOverflow && glyphOverflow->computeBound
s) { | 674 if (includeGlyphsForBox(box) && glyphOverflow && glyphOverflow->computeBound
s) { |
675 setAscentAndDescent(ascent, descent, glyphOverflow->top, glyphOverflow->
bottom, ascentDescentSet); | 675 setAscentAndDescent(ascent, descent, glyphOverflow->top, glyphOverflow->
bottom, ascentDescentSet); |
676 affectsAscent = glyphOverflow->top - box->logicalTop() > 0; | 676 affectsAscent = glyphOverflow->top - box->logicalTop() > 0; |
677 affectsDescent = glyphOverflow->bottom + box->logicalTop() > 0; | 677 affectsDescent = glyphOverflow->bottom + box->logicalTop() > 0; |
678 } | 678 } |
679 | 679 |
680 if (includeMarginForBox(box)) { | 680 if (includeMarginForBox(box)) { |
681 LayoutUnit ascentWithMargin = box->lineLayoutItem().style(isFirstLineSty
le())->fontMetrics().ascent(baselineType()); | 681 LayoutUnit ascentWithMargin = box->lineLayoutItem().style(isFirstLineSty
le())->fontMetrics().ascent(baselineType()); |
682 LayoutUnit descentWithMargin = box->lineLayoutItem().style(isFirstLineSt
yle())->fontMetrics().descent(baselineType()); | 682 LayoutUnit descentWithMargin = box->lineLayoutItem().style(isFirstLineSt
yle())->fontMetrics().descent(baselineType()); |
683 if (box->parent() && !box->lineLayoutItem().isText()) { | 683 if (box->parent() && !box->lineLayoutItem().isText()) { |
684 ascentWithMargin += box->boxModelObject()->borderBefore() + box->box
ModelObject()->paddingBefore() + box->boxModelObject()->marginBefore(); | 684 ascentWithMargin += box->boxModelObject().borderBefore() + box->boxM
odelObject().paddingBefore() + box->boxModelObject().marginBefore(); |
685 descentWithMargin += box->boxModelObject()->borderAfter() + box->box
ModelObject()->paddingAfter() + box->boxModelObject()->marginAfter(); | 685 descentWithMargin += box->boxModelObject().borderAfter() + box->boxM
odelObject().paddingAfter() + box->boxModelObject().marginAfter(); |
686 } | 686 } |
687 setAscentAndDescent(ascent, descent, ascentWithMargin, descentWithMargin
, ascentDescentSet); | 687 setAscentAndDescent(ascent, descent, ascentWithMargin, descentWithMargin
, ascentDescentSet); |
688 | 688 |
689 // Treat like a replaced element, since we're using the margin box. | 689 // Treat like a replaced element, since we're using the margin box. |
690 affectsAscent = true; | 690 affectsAscent = true; |
691 affectsDescent = true; | 691 affectsDescent = true; |
692 } | 692 } |
693 } | 693 } |
694 | 694 |
695 LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositio
nCache& verticalPositionCache) | 695 LayoutUnit RootInlineBox::verticalPositionForBox(InlineBox* box, VerticalPositio
nCache& verticalPositionCache) |
696 { | 696 { |
697 if (box->lineLayoutItem().isText()) | 697 if (box->lineLayoutItem().isText()) |
698 return box->parent()->logicalTop(); | 698 return box->parent()->logicalTop(); |
699 | 699 |
700 LayoutBoxModelObject* layoutObject = box->boxModelObject(); | 700 LineLayoutBoxModel boxModel = box->boxModelObject(); |
701 ASSERT(layoutObject->isInline()); | 701 ASSERT(boxModel.isInline()); |
702 if (!layoutObject->isInline()) | 702 if (!boxModel.isInline()) |
703 return 0; | 703 return 0; |
704 | 704 |
705 // This method determines the vertical position for inline elements. | 705 // This method determines the vertical position for inline elements. |
706 bool firstLine = isFirstLineStyle(); | 706 bool firstLine = isFirstLineStyle(); |
707 if (firstLine && !layoutObject->document().styleEngine().usesFirstLineRules(
)) | 707 if (firstLine && !boxModel.document().styleEngine().usesFirstLineRules()) |
708 firstLine = false; | 708 firstLine = false; |
709 | 709 |
710 // Check the cache. | 710 // Check the cache. |
711 bool isLayoutInline = layoutObject->isLayoutInline(); | 711 bool isLayoutInline = boxModel.isLayoutInline(); |
712 if (isLayoutInline && !firstLine) { | 712 if (isLayoutInline && !firstLine) { |
713 LayoutUnit verticalPosition = verticalPositionCache.get(layoutObject, ba
selineType()); | 713 LayoutUnit verticalPosition = verticalPositionCache.get(boxModel, baseli
neType()); |
714 if (verticalPosition != PositionUndefined) | 714 if (verticalPosition != PositionUndefined) |
715 return verticalPosition; | 715 return verticalPosition; |
716 } | 716 } |
717 | 717 |
718 LayoutUnit verticalPosition = 0; | 718 LayoutUnit verticalPosition = 0; |
719 EVerticalAlign verticalAlign = layoutObject->style()->verticalAlign(); | 719 EVerticalAlign verticalAlign = boxModel.style()->verticalAlign(); |
720 if (verticalAlign == TOP || verticalAlign == BOTTOM) | 720 if (verticalAlign == TOP || verticalAlign == BOTTOM) |
721 return 0; | 721 return 0; |
722 | 722 |
723 LayoutObject* parent = layoutObject->parent(); | 723 LineLayoutItem parent = boxModel.parent(); |
724 if (parent->isLayoutInline() && parent->style()->verticalAlign() != TOP && p
arent->style()->verticalAlign() != BOTTOM) | 724 if (parent.isLayoutInline() && parent.style()->verticalAlign() != TOP && par
ent.style()->verticalAlign() != BOTTOM) |
725 verticalPosition = box->parent()->logicalTop(); | 725 verticalPosition = box->parent()->logicalTop(); |
726 | 726 |
727 if (verticalAlign != BASELINE) { | 727 if (verticalAlign != BASELINE) { |
728 const Font& font = parent->style(firstLine)->font(); | 728 const Font& font = parent.style(firstLine)->font(); |
729 const FontMetrics& fontMetrics = font.fontMetrics(); | 729 const FontMetrics& fontMetrics = font.fontMetrics(); |
730 int fontSize = font.fontDescription().computedPixelSize(); | 730 int fontSize = font.fontDescription().computedPixelSize(); |
731 | 731 |
732 LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? Ho
rizontalLine : VerticalLine; | 732 LineDirectionMode lineDirection = parent.isHorizontalWritingMode() ? Hor
izontalLine : VerticalLine; |
733 | 733 |
734 if (verticalAlign == SUB) { | 734 if (verticalAlign == SUB) { |
735 verticalPosition += fontSize / 5 + 1; | 735 verticalPosition += fontSize / 5 + 1; |
736 } else if (verticalAlign == SUPER) { | 736 } else if (verticalAlign == SUPER) { |
737 verticalPosition -= fontSize / 3 + 1; | 737 verticalPosition -= fontSize / 3 + 1; |
738 } else if (verticalAlign == TEXT_TOP) { | 738 } else if (verticalAlign == TEXT_TOP) { |
739 verticalPosition += layoutObject->baselinePosition(baselineType(), f
irstLine, lineDirection) - fontMetrics.ascent(baselineType()); | 739 verticalPosition += boxModel.baselinePosition(baselineType(), firstL
ine, lineDirection) - fontMetrics.ascent(baselineType()); |
740 } else if (verticalAlign == MIDDLE) { | 740 } else if (verticalAlign == MIDDLE) { |
741 verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontM
etrics.xHeight() / 2) - layoutObject->lineHeight(firstLine, lineDirection) / 2 +
layoutObject->baselinePosition(baselineType(), firstLine, lineDirection)).round
(); | 741 verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontM
etrics.xHeight() / 2) - boxModel.lineHeight(firstLine, lineDirection) / 2 + boxM
odel.baselinePosition(baselineType(), firstLine, lineDirection)).round(); |
742 } else if (verticalAlign == TEXT_BOTTOM) { | 742 } else if (verticalAlign == TEXT_BOTTOM) { |
743 verticalPosition += fontMetrics.descent(baselineType()); | 743 verticalPosition += fontMetrics.descent(baselineType()); |
744 // lineHeight - baselinePosition is always 0 for replaced elements (
except inline blocks), so don't bother wasting time in that case. | 744 // lineHeight - baselinePosition is always 0 for replaced elements (
except inline blocks), so don't bother wasting time in that case. |
745 if (!layoutObject->isReplaced() || layoutObject->isInlineBlockOrInli
neTable()) | 745 if (!boxModel.isReplaced() || boxModel.isInlineBlockOrInlineTable()) |
746 verticalPosition -= (layoutObject->lineHeight(firstLine, lineDir
ection) - layoutObject->baselinePosition(baselineType(), firstLine, lineDirectio
n)); | 746 verticalPosition -= (boxModel.lineHeight(firstLine, lineDirectio
n) - boxModel.baselinePosition(baselineType(), firstLine, lineDirection)); |
747 } else if (verticalAlign == BASELINE_MIDDLE) { | 747 } else if (verticalAlign == BASELINE_MIDDLE) { |
748 verticalPosition += -layoutObject->lineHeight(firstLine, lineDirecti
on) / 2 + layoutObject->baselinePosition(baselineType(), firstLine, lineDirectio
n); | 748 verticalPosition += -boxModel.lineHeight(firstLine, lineDirection) /
2 + boxModel.baselinePosition(baselineType(), firstLine, lineDirection); |
749 } else if (verticalAlign == LENGTH) { | 749 } else if (verticalAlign == LENGTH) { |
750 LayoutUnit lineHeight; | 750 LayoutUnit lineHeight; |
751 // Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-alig
n: 'Percentages: refer to the 'line-height' of the element itself'. | 751 // Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-alig
n: 'Percentages: refer to the 'line-height' of the element itself'. |
752 if (layoutObject->style()->verticalAlignLength().hasPercent()) | 752 if (boxModel.style()->verticalAlignLength().hasPercent()) |
753 lineHeight = layoutObject->style()->computedLineHeight(); | 753 lineHeight = boxModel.style()->computedLineHeight(); |
754 else | 754 else |
755 lineHeight = layoutObject->lineHeight(firstLine, lineDirection); | 755 lineHeight = boxModel.lineHeight(firstLine, lineDirection); |
756 verticalPosition -= valueForLength(layoutObject->style()->verticalAl
ignLength(), lineHeight); | 756 verticalPosition -= valueForLength(boxModel.style()->verticalAlignLe
ngth(), lineHeight); |
757 } | 757 } |
758 } | 758 } |
759 | 759 |
760 // Store the cached value. | 760 // Store the cached value. |
761 if (isLayoutInline && !firstLine) | 761 if (isLayoutInline && !firstLine) |
762 verticalPositionCache.set(layoutObject, baselineType(), verticalPosition
); | 762 verticalPositionCache.set(boxModel, baselineType(), verticalPosition); |
763 | 763 |
764 return verticalPosition; | 764 return verticalPosition; |
765 } | 765 } |
766 | 766 |
767 bool RootInlineBox::includeLeadingForBox(InlineBox* box) const | 767 bool RootInlineBox::includeLeadingForBox(InlineBox* box) const |
768 { | 768 { |
769 if (box->lineLayoutItem().isReplaced() || (box->lineLayoutItem().isText() &&
!box->isText())) | 769 if (box->lineLayoutItem().isReplaced() || (box->lineLayoutItem().isText() &&
!box->isText())) |
770 return false; | 770 return false; |
771 | 771 |
772 LineBoxContain lineBoxContain = lineLayoutItem().style()->lineBoxContain(); | 772 LineBoxContain lineBoxContain = lineLayoutItem().style()->lineBoxContain(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 endBox = nullptr; | 849 endBox = nullptr; |
850 return nullptr; | 850 return nullptr; |
851 } | 851 } |
852 | 852 |
853 const char* RootInlineBox::boxName() const | 853 const char* RootInlineBox::boxName() const |
854 { | 854 { |
855 return "RootInlineBox"; | 855 return "RootInlineBox"; |
856 } | 856 } |
857 | 857 |
858 } // namespace blink | 858 } // namespace blink |
OLD | NEW |