LayoutRect LayoutSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit*) { if (!box || !box->isInlineTextBox()) return LayoutRect(); InlineTextBox* textBox = toInlineTextBox(box); if (static_cast<unsigned>(caretOffset) < textBox->start() || static_cast<unsigned>(caretOffset) > textBox->start() + textBox->len()) return LayoutRect(); // Use the edge of the selection rect to determine the caret rect. if (static_cast<unsigned>(caretOffset) < textBox->start() + textBox->len()) { LayoutRect rect = textBox->localSelectionRect(caretOffset, caretOffset + 1); LayoutUnit x = box->isLeftToRightDirection() ? rect.x() : rect.maxX(); return LayoutRect(x, rect.y(), caretWidth, rect.height()); } LayoutRect rect = textBox->localSelectionRect(caretOffset - 1, caretOffset); LayoutUnit x = box->isLeftToRightDirection() ? rect.maxX() : rect.x(); return LayoutRect(x, rect.y(), caretWidth, rect.height()); }
static FloatRect localQuadForTextBox(const InlineTextBox& box, unsigned start, unsigned end, bool useSelectionHeight) { unsigned realEnd = std::min(box.end() + 1, end); LayoutRect boxSelectionRect = box.localSelectionRect(start, realEnd); if (!boxSelectionRect.height()) return FloatRect(); if (useSelectionHeight) return boxSelectionRect; // Change the height and y position (or width and x for vertical text) // because selectionRect uses selection-specific values. if (box.isHorizontal()) { boxSelectionRect.setHeight(box.height()); boxSelectionRect.setY(box.y()); } else { boxSelectionRect.setWidth(box.width()); boxSelectionRect.setX(box.x()); } return boxSelectionRect; }