OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. |
5 * All rights reserved. | 5 * All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return LayoutUnit( | 118 return LayoutUnit( |
119 LineLayoutBR(GetLineLayoutItem()).LineHeight(IsFirstLineStyle())); | 119 LineLayoutBR(GetLineLayoutItem()).LineHeight(IsFirstLineStyle())); |
120 if (Parent()->GetLineLayoutItem() == GetLineLayoutItem().Parent()) | 120 if (Parent()->GetLineLayoutItem() == GetLineLayoutItem().Parent()) |
121 return Parent()->LineHeight(); | 121 return Parent()->LineHeight(); |
122 return LineLayoutBoxModel(GetLineLayoutItem().Parent()) | 122 return LineLayoutBoxModel(GetLineLayoutItem().Parent()) |
123 .LineHeight(IsFirstLineStyle(), | 123 .LineHeight(IsFirstLineStyle(), |
124 IsHorizontal() ? kHorizontalLine : kVerticalLine, | 124 IsHorizontal() ? kHorizontalLine : kVerticalLine, |
125 kPositionOnContainingLine); | 125 kPositionOnContainingLine); |
126 } | 126 } |
127 | 127 |
| 128 LayoutUnit InlineTextBox::OffsetTo(LineVerticalPositionType position_type, |
| 129 FontBaseline baseline_type) const { |
| 130 if (IsText() && |
| 131 (position_type == LineVerticalPositionType::TopOfEmHeight || |
| 132 position_type == LineVerticalPositionType::BottomOfEmHeight)) { |
| 133 const Font& font = GetLineLayoutItem().Style(IsFirstLineStyle())->GetFont(); |
| 134 if (const SimpleFontData* font_data = font.PrimaryFont()) { |
| 135 const FontMetrics& metrics = font_data->GetFontMetrics(); |
| 136 if (position_type == LineVerticalPositionType::TopOfEmHeight) { |
| 137 // Use Ascent, not FixedAscent, to match to how InlineTextBoxPainter |
| 138 // computes the baseline position. |
| 139 return metrics.Ascent(baseline_type) - |
| 140 font_data->EmHeightAscent(baseline_type); |
| 141 } |
| 142 if (position_type == LineVerticalPositionType::BottomOfEmHeight) { |
| 143 return metrics.Ascent(baseline_type) + |
| 144 font_data->EmHeightDescent(baseline_type); |
| 145 } |
| 146 } |
| 147 } |
| 148 switch (position_type) { |
| 149 case LineVerticalPositionType::TextTop: |
| 150 case LineVerticalPositionType::TopOfEmHeight: |
| 151 return LayoutUnit(); |
| 152 case LineVerticalPositionType::TextBottom: |
| 153 case LineVerticalPositionType::BottomOfEmHeight: |
| 154 return LogicalHeight(); |
| 155 } |
| 156 NOTREACHED(); |
| 157 return LayoutUnit(); |
| 158 } |
| 159 |
| 160 LayoutUnit InlineTextBox::VerticalPosition( |
| 161 LineVerticalPositionType position_type, |
| 162 FontBaseline baseline_type) const { |
| 163 return LogicalTop() + OffsetTo(position_type, baseline_type); |
| 164 } |
| 165 |
128 bool InlineTextBox::IsSelected(int start_pos, int end_pos) const { | 166 bool InlineTextBox::IsSelected(int start_pos, int end_pos) const { |
129 int s_pos = std::max(start_pos - start_, 0); | 167 int s_pos = std::max(start_pos - start_, 0); |
130 // The position after a hard line break is considered to be past its end. | 168 // The position after a hard line break is considered to be past its end. |
131 // See the corresponding code in InlineTextBox::getSelectionState. | 169 // See the corresponding code in InlineTextBox::getSelectionState. |
132 int e_pos = std::min(end_pos - start_, int(len_) + (IsLineBreak() ? 0 : 1)); | 170 int e_pos = std::min(end_pos - start_, int(len_) + (IsLineBreak() ? 0 : 1)); |
133 return (s_pos < e_pos); | 171 return (s_pos < e_pos); |
134 } | 172 } |
135 | 173 |
136 SelectionState InlineTextBox::GetSelectionState() const { | 174 SelectionState InlineTextBox::GetSelectionState() const { |
137 SelectionState state = GetLineLayoutItem().GetSelectionState(); | 175 SelectionState state = GetLineLayoutItem().GetSelectionState(); |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 for (; printed_characters < kLayoutObjectCharacterOffset; | 760 for (; printed_characters < kLayoutObjectCharacterOffset; |
723 printed_characters++) | 761 printed_characters++) |
724 fputc(' ', stderr); | 762 fputc(' ', stderr); |
725 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), | 763 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), |
726 value.Utf8().data()); | 764 value.Utf8().data()); |
727 } | 765 } |
728 | 766 |
729 #endif | 767 #endif |
730 | 768 |
731 } // namespace blink | 769 } // namespace blink |
OLD | NEW |