Пример #1
0
VisibleSelection visibleSelectionForFocusedBlock(Element* element)
{
    int textLength = inputElementText(element).length();

    if (DOMSupport::toTextControlElement(element)) {
        RenderTextControl* textRender = toRenderTextControl(element->renderer());
        if (!textRender)
            return VisibleSelection();

        VisiblePosition startPosition = textRender->visiblePositionForIndex(0);
        VisiblePosition endPosition;

        if (textLength)
            endPosition = textRender->visiblePositionForIndex(textLength);
        else
            endPosition = startPosition;
        return VisibleSelection(startPosition, endPosition);
    }

    // Must be content editable, generate the range.
    RefPtr<Range> selectionRange = TextIterator::rangeFromLocationAndLength(element, 0, textLength);

    if (!selectionRange)
        return VisibleSelection();

    if (!textLength)
        return VisibleSelection(selectionRange->startPosition(), DOWNSTREAM);

    return VisibleSelection(selectionRange->startPosition(), selectionRange->endPosition());
}
Пример #2
0
VisibleSelection visibleSelectionForInputElement(Element* element)
{
    return visibleSelectionForRangeInputElement(element, 0, inputElementText(element).length());
}