| 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. All r
ights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 bool InlineTextBox::isSelected(int startPos, int endPos) const | 132 bool InlineTextBox::isSelected(int startPos, int endPos) const |
| 133 { | 133 { |
| 134 int sPos = std::max(startPos - m_start, 0); | 134 int sPos = std::max(startPos - m_start, 0); |
| 135 // The position after a hard line break is considered to be past its end. | 135 // The position after a hard line break is considered to be past its end. |
| 136 // See the corresponding code in InlineTextBox::selectionState. | 136 // See the corresponding code in InlineTextBox::selectionState. |
| 137 int ePos = std::min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1)); | 137 int ePos = std::min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1)); |
| 138 return (sPos < ePos); | 138 return (sPos < ePos); |
| 139 } | 139 } |
| 140 | 140 |
| 141 LayoutObject::SelectionState InlineTextBox::selectionState() const | 141 SelectionState InlineTextBox::selectionState() const |
| 142 { | 142 { |
| 143 LayoutObject::SelectionState state = layoutObject().selectionState(); | 143 SelectionState state = layoutObject().selectionState(); |
| 144 if (state == LayoutObject::SelectionStart || state == LayoutObject::Selectio
nEnd || state == LayoutObject::SelectionBoth) { | 144 if (state == SelectionStart || state == SelectionEnd || state == SelectionBo
th) { |
| 145 int startPos, endPos; | 145 int startPos, endPos; |
| 146 layoutObject().selectionStartEnd(startPos, endPos); | 146 layoutObject().selectionStartEnd(startPos, endPos); |
| 147 // The position after a hard line break is considered to be past its end
. | 147 // The position after a hard line break is considered to be past its end
. |
| 148 // See the corresponding code in InlineTextBox::isSelected. | 148 // See the corresponding code in InlineTextBox::isSelected. |
| 149 int lastSelectable = start() + len() - (isLineBreak() ? 1 : 0); | 149 int lastSelectable = start() + len() - (isLineBreak() ? 1 : 0); |
| 150 | 150 |
| 151 // FIXME: Remove -webkit-line-break: LineBreakAfterWhiteSpace. | 151 // FIXME: Remove -webkit-line-break: LineBreakAfterWhiteSpace. |
| 152 int endOfLineAdjustmentForCSSLineBreak = layoutObject().style()->lineBre
ak() == LineBreakAfterWhiteSpace ? -1 : 0; | 152 int endOfLineAdjustmentForCSSLineBreak = layoutObject().style()->lineBre
ak() == LineBreakAfterWhiteSpace ? -1 : 0; |
| 153 bool start = (state != LayoutObject::SelectionEnd && startPos >= m_start
&& startPos <= m_start + m_len + endOfLineAdjustmentForCSSLineBreak); | 153 bool start = (state != SelectionEnd && startPos >= m_start && startPos <
= m_start + m_len + endOfLineAdjustmentForCSSLineBreak); |
| 154 bool end = (state != LayoutObject::SelectionStart && endPos > m_start &&
endPos <= lastSelectable); | 154 bool end = (state != SelectionStart && endPos > m_start && endPos <= las
tSelectable); |
| 155 if (start && end) | 155 if (start && end) |
| 156 state = LayoutObject::SelectionBoth; | 156 state = SelectionBoth; |
| 157 else if (start) | 157 else if (start) |
| 158 state = LayoutObject::SelectionStart; | 158 state = SelectionStart; |
| 159 else if (end) | 159 else if (end) |
| 160 state = LayoutObject::SelectionEnd; | 160 state = SelectionEnd; |
| 161 else if ((state == LayoutObject::SelectionEnd || startPos < m_start) | 161 else if ((state == SelectionEnd || startPos < m_start) |
| 162 && (state == LayoutObject::SelectionStart || endPos > lastSelectable
)) | 162 && (state == SelectionStart || endPos > lastSelectable)) |
| 163 state = LayoutObject::SelectionInside; | 163 state = SelectionInside; |
| 164 else if (state == LayoutObject::SelectionBoth) | 164 else if (state == SelectionBoth) |
| 165 state = LayoutObject::SelectionNone; | 165 state = SelectionNone; |
| 166 } | 166 } |
| 167 | 167 |
| 168 // If there are ellipsis following, make sure their selection is updated. | 168 // If there are ellipsis following, make sure their selection is updated. |
| 169 if (m_truncation != cNoTruncation && root().ellipsisBox()) { | 169 if (m_truncation != cNoTruncation && root().ellipsisBox()) { |
| 170 EllipsisBox* ellipsis = root().ellipsisBox(); | 170 EllipsisBox* ellipsis = root().ellipsisBox(); |
| 171 if (state != LayoutObject::SelectionNone) { | 171 if (state != SelectionNone) { |
| 172 int start, end; | 172 int start, end; |
| 173 selectionStartEnd(start, end); | 173 selectionStartEnd(start, end); |
| 174 // The ellipsis should be considered to be selected if the end of | 174 // The ellipsis should be considered to be selected if the end of |
| 175 // the selection is past the beginning of the truncation and the | 175 // the selection is past the beginning of the truncation and the |
| 176 // beginning of the selection is before or at the beginning of the | 176 // beginning of the selection is before or at the beginning of the |
| 177 // truncation. | 177 // truncation. |
| 178 ellipsis->setSelectionState(end >= m_truncation && start <= m_trunca
tion ? | 178 ellipsis->setSelectionState(end >= m_truncation && start <= m_trunca
tion ? |
| 179 LayoutObject::SelectionInside : LayoutObject::SelectionNone); | 179 SelectionInside : SelectionNone); |
| 180 } else { | 180 } else { |
| 181 ellipsis->setSelectionState(LayoutObject::SelectionNone); | 181 ellipsis->setSelectionState(SelectionNone); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 return state; | 185 return state; |
| 186 } | 186 } |
| 187 | 187 |
| 188 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) | 188 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) |
| 189 { | 189 { |
| 190 int sPos = std::max(startPos - m_start, 0); | 190 int sPos = std::max(startPos - m_start, 0); |
| 191 int ePos = std::min(endPos - m_start, (int)m_len); | 191 int ePos = std::min(endPos - m_start, (int)m_len); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 363 } |
| 364 | 364 |
| 365 void InlineTextBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf
fset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) | 365 void InlineTextBox::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf
fset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) |
| 366 { | 366 { |
| 367 InlineTextBoxPainter(*this).paint(paintInfo, paintOffset); | 367 InlineTextBoxPainter(*this).paint(paintInfo, paintOffset); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const | 370 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const |
| 371 { | 371 { |
| 372 int startPos, endPos; | 372 int startPos, endPos; |
| 373 if (layoutObject().selectionState() == LayoutObject::SelectionInside) { | 373 if (layoutObject().selectionState() == SelectionInside) { |
| 374 startPos = 0; | 374 startPos = 0; |
| 375 endPos = layoutObject().textLength(); | 375 endPos = layoutObject().textLength(); |
| 376 } else { | 376 } else { |
| 377 layoutObject().selectionStartEnd(startPos, endPos); | 377 layoutObject().selectionStartEnd(startPos, endPos); |
| 378 if (layoutObject().selectionState() == LayoutObject::SelectionStart) | 378 if (layoutObject().selectionState() == SelectionStart) |
| 379 endPos = layoutObject().textLength(); | 379 endPos = layoutObject().textLength(); |
| 380 else if (layoutObject().selectionState() == LayoutObject::SelectionEnd) | 380 else if (layoutObject().selectionState() == SelectionEnd) |
| 381 startPos = 0; | 381 startPos = 0; |
| 382 } | 382 } |
| 383 | 383 |
| 384 sPos = std::max(startPos - m_start, 0); | 384 sPos = std::max(startPos - m_start, 0); |
| 385 ePos = std::min(endPos - m_start, (int)m_len); | 385 ePos = std::min(endPos - m_start, (int)m_len); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const LayoutPoint&
boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Font& font,
bool grammar) | 388 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const LayoutPoint&
boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Font& font,
bool grammar) |
| 389 { | 389 { |
| 390 InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin, marker, style
, font, grammar); | 390 InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin, marker, style
, font, grammar); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), &obj); | 562 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), &obj); |
| 563 const int layoutObjectCharacterOffset = 75; | 563 const int layoutObjectCharacterOffset = 75; |
| 564 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) | 564 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) |
| 565 fputc(' ', stderr); | 565 fputc(' ', stderr); |
| 566 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); | 566 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); |
| 567 } | 567 } |
| 568 | 568 |
| 569 #endif | 569 #endif |
| 570 | 570 |
| 571 } // namespace blink | 571 } // namespace blink |
| OLD | NEW |