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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 bool InlineTextBox::IsSelected(int start_pos, int end_pos) const { | 166 bool InlineTextBox::IsSelected(int start_pos, int end_pos) const { |
167 int s_pos = std::max(start_pos - start_, 0); | 167 int s_pos = std::max(start_pos - start_, 0); |
168 // 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. |
169 // See the corresponding code in InlineTextBox::getSelectionState. | 169 // See the corresponding code in InlineTextBox::getSelectionState. |
170 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)); |
171 return (s_pos < e_pos); | 171 return (s_pos < e_pos); |
172 } | 172 } |
173 | 173 |
174 SelectionState InlineTextBox::GetSelectionState() const { | 174 SelectionState InlineTextBox::GetSelectionState() const { |
175 SelectionState state = GetLineLayoutItem().GetSelectionState(); | 175 SelectionState state = GetLineLayoutItem().GetSelectionState(); |
176 if (state == SelectionStart || state == SelectionEnd || | 176 if (state == SelectionState::kStart || state == SelectionState::kEnd || |
177 state == SelectionBoth) { | 177 state == SelectionState::kStartAndEnd) { |
178 int start_pos, end_pos; | 178 int start_pos, end_pos; |
179 std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd(); | 179 std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd(); |
180 // The position after a hard line break is considered to be past its end. | 180 // The position after a hard line break is considered to be past its end. |
181 // See the corresponding code in InlineTextBox::isSelected. | 181 // See the corresponding code in InlineTextBox::isSelected. |
182 int last_selectable = Start() + Len() - (IsLineBreak() ? 1 : 0); | 182 int last_selectable = Start() + Len() - (IsLineBreak() ? 1 : 0); |
183 | 183 |
184 // FIXME: Remove -webkit-line-break: LineBreakAfterWhiteSpace. | 184 // FIXME: Remove -webkit-line-break: LineBreakAfterWhiteSpace. |
185 int end_of_line_adjustment_for_css_line_break = | 185 int end_of_line_adjustment_for_css_line_break = |
186 GetLineLayoutItem().Style()->GetLineBreak() == | 186 GetLineLayoutItem().Style()->GetLineBreak() == |
187 LineBreak::kAfterWhiteSpace | 187 LineBreak::kAfterWhiteSpace |
188 ? -1 | 188 ? -1 |
189 : 0; | 189 : 0; |
190 bool start = (state != SelectionEnd && start_pos >= start_ && | 190 bool start = (state != SelectionState::kEnd && start_pos >= start_ && |
191 start_pos <= start_ + len_ + | 191 start_pos <= start_ + len_ + |
192 end_of_line_adjustment_for_css_line_break); | 192 end_of_line_adjustment_for_css_line_break); |
193 bool end = (state != SelectionStart && end_pos > start_ && | 193 bool end = (state != SelectionState::kStart && end_pos > start_ && |
194 end_pos <= last_selectable); | 194 end_pos <= last_selectable); |
195 if (start && end) | 195 if (start && end) |
196 state = SelectionBoth; | 196 state = SelectionState::kStartAndEnd; |
197 else if (start) | 197 else if (start) |
198 state = SelectionStart; | 198 state = SelectionState::kStart; |
199 else if (end) | 199 else if (end) |
200 state = SelectionEnd; | 200 state = SelectionState::kEnd; |
201 else if ((state == SelectionEnd || start_pos < start_) && | 201 else if ((state == SelectionState::kEnd || start_pos < start_) && |
202 (state == SelectionStart || end_pos > last_selectable)) | 202 (state == SelectionState::kStart || end_pos > last_selectable)) |
203 state = SelectionInside; | 203 state = SelectionState::kInside; |
204 else if (state == SelectionBoth) | 204 else if (state == SelectionState::kStartAndEnd) |
205 state = SelectionNone; | 205 state = SelectionState::kNone; |
206 } | 206 } |
207 | 207 |
208 // If there are ellipsis following, make sure their selection is updated. | 208 // If there are ellipsis following, make sure their selection is updated. |
209 if (truncation_ != kCNoTruncation && Root().GetEllipsisBox()) { | 209 if (truncation_ != kCNoTruncation && Root().GetEllipsisBox()) { |
210 EllipsisBox* ellipsis = Root().GetEllipsisBox(); | 210 EllipsisBox* ellipsis = Root().GetEllipsisBox(); |
211 if (state != SelectionNone) { | 211 if (state != SelectionState::kNone) { |
212 int start, end; | 212 int start, end; |
213 SelectionStartEnd(start, end); | 213 SelectionStartEnd(start, end); |
214 // The ellipsis should be considered to be selected if the end of the | 214 // The ellipsis should be considered to be selected if the end of the |
215 // selection is past the beginning of the truncation and the beginning of | 215 // selection is past the beginning of the truncation and the beginning of |
216 // the selection is before or at the beginning of the truncation. | 216 // the selection is before or at the beginning of the truncation. |
217 ellipsis->SetSelectionState(end >= truncation_ && start <= truncation_ | 217 ellipsis->SetSelectionState(end >= truncation_ && start <= truncation_ |
218 ? SelectionInside | 218 ? SelectionState::kInside |
219 : SelectionNone); | 219 : SelectionState::kNone); |
220 } else { | 220 } else { |
221 ellipsis->SetSelectionState(SelectionNone); | 221 ellipsis->SetSelectionState(SelectionState::kNone); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 return state; | 225 return state; |
226 } | 226 } |
227 | 227 |
228 bool InlineTextBox::HasWrappedSelectionNewline() const { | 228 bool InlineTextBox::HasWrappedSelectionNewline() const { |
229 DCHECK(!GetLineLayoutItem().NeedsLayout()); | 229 DCHECK(!GetLineLayoutItem().NeedsLayout()); |
230 | 230 |
231 SelectionState state = GetSelectionState(); | 231 SelectionState state = GetSelectionState(); |
232 if (state != SelectionStart && state != SelectionInside) | 232 if (state != SelectionState::kStart && state != SelectionState::kInside) |
233 return false; | 233 return false; |
234 | 234 |
235 // Checking last leaf child can be slow, so we make sure to do this | 235 // Checking last leaf child can be slow, so we make sure to do this |
236 // only after checking selection state. | 236 // only after checking selection state. |
237 if (Root().LastLeafChild() != this) | 237 if (Root().LastLeafChild() != this) |
238 return false; | 238 return false; |
239 | 239 |
240 // It's possible to have mixed LTR/RTL on a single line, and we only | 240 // It's possible to have mixed LTR/RTL on a single line, and we only |
241 // want to paint a newline when we're the last leaf child and we make | 241 // want to paint a newline when we're the last leaf child and we make |
242 // sure there isn't a differently-directioned box following us. | 242 // sure there isn't a differently-directioned box following us. |
243 bool is_ltr = IsLeftToRightDirection(); | 243 bool is_ltr = IsLeftToRightDirection(); |
244 if ((!is_ltr && Root().FirstSelectedBox() != this) || | 244 if ((!is_ltr && Root().FirstSelectedBox() != this) || |
245 (is_ltr && Root().LastSelectedBox() != this)) | 245 (is_ltr && Root().LastSelectedBox() != this)) |
246 return false; | 246 return false; |
247 | 247 |
248 // If we're the last inline text box in containing block, our containing block | 248 // If we're the last inline text box in containing block, our containing block |
249 // is inline, and the selection continues into that block, then rely on the | 249 // is inline, and the selection continues into that block, then rely on the |
250 // next inline text box (if any) to paint a wrapped new line as needed. | 250 // next inline text box (if any) to paint a wrapped new line as needed. |
251 if (NextTextBox()) | 251 if (NextTextBox()) |
252 return true; | 252 return true; |
253 auto root_block = Root().Block(); | 253 auto root_block = Root().Block(); |
254 if (root_block.IsInline() && root_block.GetSelectionState() != SelectionEnd && | 254 if (root_block.IsInline() && |
255 root_block.GetSelectionState() != SelectionBoth && | 255 root_block.GetSelectionState() != SelectionState::kEnd && |
| 256 root_block.GetSelectionState() != SelectionState::kStartAndEnd && |
256 root_block.InlineBoxWrapper() && | 257 root_block.InlineBoxWrapper() && |
257 ((is_ltr && root_block.InlineBoxWrapper()->NextOnLine()) || | 258 ((is_ltr && root_block.InlineBoxWrapper()->NextOnLine()) || |
258 (!is_ltr && root_block.InlineBoxWrapper()->PrevOnLine()))) { | 259 (!is_ltr && root_block.InlineBoxWrapper()->PrevOnLine()))) { |
259 return false; | 260 return false; |
260 } | 261 } |
261 | 262 |
262 return true; | 263 return true; |
263 } | 264 } |
264 | 265 |
265 float InlineTextBox::NewlineSpaceWidth() const { | 266 float InlineTextBox::NewlineSpaceWidth() const { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 518 |
518 void InlineTextBox::Paint(const PaintInfo& paint_info, | 519 void InlineTextBox::Paint(const PaintInfo& paint_info, |
519 const LayoutPoint& paint_offset, | 520 const LayoutPoint& paint_offset, |
520 LayoutUnit /*lineTop*/, | 521 LayoutUnit /*lineTop*/, |
521 LayoutUnit /*lineBottom*/) const { | 522 LayoutUnit /*lineBottom*/) const { |
522 InlineTextBoxPainter(*this).Paint(paint_info, paint_offset); | 523 InlineTextBoxPainter(*this).Paint(paint_info, paint_offset); |
523 } | 524 } |
524 | 525 |
525 void InlineTextBox::SelectionStartEnd(int& s_pos, int& e_pos) const { | 526 void InlineTextBox::SelectionStartEnd(int& s_pos, int& e_pos) const { |
526 int start_pos, end_pos; | 527 int start_pos, end_pos; |
527 if (GetLineLayoutItem().GetSelectionState() == SelectionInside) { | 528 if (GetLineLayoutItem().GetSelectionState() == SelectionState::kInside) { |
528 start_pos = 0; | 529 start_pos = 0; |
529 end_pos = GetLineLayoutItem().TextLength(); | 530 end_pos = GetLineLayoutItem().TextLength(); |
530 } else { | 531 } else { |
531 std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd(); | 532 std::tie(start_pos, end_pos) = GetLineLayoutItem().SelectionStartEnd(); |
532 if (GetLineLayoutItem().GetSelectionState() == SelectionStart) | 533 if (GetLineLayoutItem().GetSelectionState() == SelectionState::kStart) |
533 end_pos = GetLineLayoutItem().TextLength(); | 534 end_pos = GetLineLayoutItem().TextLength(); |
534 else if (GetLineLayoutItem().GetSelectionState() == SelectionEnd) | 535 else if (GetLineLayoutItem().GetSelectionState() == SelectionState::kEnd) |
535 start_pos = 0; | 536 start_pos = 0; |
536 } | 537 } |
537 | 538 |
538 s_pos = std::max(start_pos - start_, 0); | 539 s_pos = std::max(start_pos - start_, 0); |
539 e_pos = std::min(end_pos - start_, (int)len_); | 540 e_pos = std::min(end_pos - start_, (int)len_); |
540 } | 541 } |
541 | 542 |
542 void InlineTextBox::PaintDocumentMarker(GraphicsContext& pt, | 543 void InlineTextBox::PaintDocumentMarker(GraphicsContext& pt, |
543 const LayoutPoint& box_origin, | 544 const LayoutPoint& box_origin, |
544 const DocumentMarker& marker, | 545 const DocumentMarker& marker, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 for (; printed_characters < kLayoutObjectCharacterOffset; | 749 for (; printed_characters < kLayoutObjectCharacterOffset; |
749 printed_characters++) | 750 printed_characters++) |
750 fputc(' ', stderr); | 751 fputc(' ', stderr); |
751 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), | 752 fprintf(stderr, "(%d,%d) \"%s\"\n", Start(), Start() + Len(), |
752 value.Utf8().data()); | 753 value.Utf8().data()); |
753 } | 754 } |
754 | 755 |
755 #endif | 756 #endif |
756 | 757 |
757 } // namespace blink | 758 } // namespace blink |
OLD | NEW |