Пример #1
0
void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;

    if (baseOffset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(baseOffset) + " is not a valid base offset.");
        return;
    }

    if (extentOffset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(extentOffset) + " is not a valid extent offset.");
        return;
    }

    if (!baseNode || !extentNode)
        UseCounter::count(m_frame, UseCounter::SelectionSetBaseAndExtentNull);

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    VisiblePosition visibleBase = createVisiblePosition(createPosition(baseNode, baseOffset));
    VisiblePosition visibleExtent = createVisiblePosition(createPosition(extentNode, extentOffset));

    m_frame->selection().moveTo(visibleBase, visibleExtent);
}
Пример #2
0
void DOMSelection::setBaseAndExtent(Node* baseNode, unsigned baseOffset, Node* extentNode, unsigned extentOffset)
{
    if (!m_frame)
        return;

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection().moveTo(createLegacyEditingPosition(baseNode, baseOffset), createLegacyEditingPosition(extentNode, extentOffset), DOWNSTREAM);
}
Пример #3
0
void DOMSelection::extend(Node* node, int offset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;

    if (!node) {
        exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
        return;
    }

    if (offset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }
    if (offset > (node->offsetInCharacters() ? caretMaxOffset(node) : (int)node->countChildren())) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
        return;
    }

    if (!isValidForPosition(node))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection().setExtent(VisiblePosition(createLegacyEditingPosition(node, offset), DOWNSTREAM));
}
Пример #4
0
void DOMSelection::collapse(Node* node,
                            int offset,
                            ExceptionState& exceptionState) {
    if (!isAvailable())
        return;

    if (!node) {
        UseCounter::count(frame(), UseCounter::SelectionCollapseNull);
        frame()->selection().clear();
        return;
    }

    if (offset < 0) {
        exceptionState.throwDOMException(
            IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }

    if (!isValidForPosition(node))
        return;
    Range::checkNodeWOffset(node, offset, exceptionState);
    if (exceptionState.hadException())
        return;

    frame()->selection().setSelection(
        SelectionInDOMTree::Builder()
        .collapse(Position(node, offset))
        .setIsDirectional(frame()->selection().isDirectional())
        .build());
}
void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;

    if (!node) {
        m_frame->selection().clear();
        return;
    }

    if (offset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }

    if (!isValidForPosition(node))
        return;
    RefPtrWillBeRawPtr<Range> range = Range::create(node->document());
    range->setStart(node, offset, exceptionState);
    if (exceptionState.hadException())
        return;
    range->setEnd(node, offset, exceptionState);
    if (exceptionState.hadException())
        return;
    m_frame->selection().setSelectedRange(range.get(), DOWNSTREAM, m_frame->selection().isDirectional() ? FrameSelection::Directional : FrameSelection::NonDirectional);
}
Пример #6
0
void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;

    if (!node) {
        UseCounter::count(m_frame, UseCounter::SelectionCollapseNull);
        m_frame->selection().clear();
        return;
    }

    if (offset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }

    if (!isValidForPosition(node))
        return;
    RefPtrWillBeRawPtr<Range> range = Range::create(node->document());
    range->setStart(node, offset, exceptionState);
    if (exceptionState.hadException())
        return;
    range->setEnd(node, offset, exceptionState);
    if (exceptionState.hadException())
        return;
    m_frame->selection().setSelectedRange(range.get(), TextAffinity::Downstream, m_frame->selection().isDirectional() ? SelectionDirectionalMode::Directional : SelectionDirectionalMode::NonDirectional);
}
Пример #7
0
void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode& ec)
{
    if (!m_frame)
        return;

    if (baseOffset < 0 || extentOffset < 0) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    VisiblePosition visibleBase = VisiblePosition(baseNode, baseOffset, DOWNSTREAM);
    VisiblePosition visibleExtent = VisiblePosition(extentNode, extentOffset, DOWNSTREAM);

    m_frame->selection()->moveTo(visibleBase, visibleExtent);
}
Пример #8
0
void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode& ec)
{
    if (!m_frame)
        return;

    if (baseOffset < 0 || extentOffset < 0) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    // FIXME: Eliminate legacy editing positions
    VisiblePosition visibleBase = VisiblePosition(createLegacyEditingPosition(baseNode, baseOffset), DOWNSTREAM);
    VisiblePosition visibleExtent = VisiblePosition(createLegacyEditingPosition(extentNode, extentOffset), DOWNSTREAM);

    m_frame->selection().moveTo(visibleBase, visibleExtent);
}
Пример #9
0
void DOMSelection::setBaseAndExtent(Node* baseNode,
                                    int baseOffset,
                                    Node* extentNode,
                                    int extentOffset,
                                    ExceptionState& exceptionState) {
    if (!isAvailable())
        return;

    if (baseOffset < 0) {
        exceptionState.throwDOMException(
            IndexSizeError,
            String::number(baseOffset) + " is not a valid base offset.");
        return;
    }

    if (extentOffset < 0) {
        exceptionState.throwDOMException(
            IndexSizeError,
            String::number(extentOffset) + " is not a valid extent offset.");
        return;
    }

    if (!baseNode || !extentNode)
        UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    Position base = createPosition(baseNode, baseOffset);
    Position extent = createPosition(extentNode, extentOffset);
    const bool selectionHasDirection = true;

    // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
    // needs to be audited.  See http://crbug.com/590369 for more details.
    // In the long term, we should change FrameSelection::setSelection to take a
    // parameter that does not require clean layout, so that modifying selection
    // no longer performs synchronous layout by itself.
    frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();

    frame()->selection().setSelection(createVisibleSelection(
                                          base, extent, SelDefaultAffinity, selectionHasDirection));
}
Пример #10
0
void DOMSelection::setPosition(Node* node, unsigned offset)
{
    if (!m_frame)
        return;

    if (!isValidForPosition(node))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection().moveTo(createLegacyEditingPosition(node, offset), DOWNSTREAM);
}
Пример #11
0
void DOMSelection::setPosition(Node* node, int offset, ExceptionCode& ec)
{
    if (!m_frame)
        return;
    if (offset < 0) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(node))
        return;

    m_frame->selection()->moveTo(VisiblePosition(node, offset, DOWNSTREAM));
}
Пример #12
0
void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;

    if (baseOffset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(baseOffset) + " is not a valid base offset.");
        return;
    }

    if (extentOffset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(extentOffset) + " is not a valid extent offset.");
        return;
    }

    if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
        return;

    // FIXME: Eliminate legacy editing positions
    VisiblePosition visibleBase = VisiblePosition(createLegacyEditingPosition(baseNode, baseOffset), DOWNSTREAM);
    VisiblePosition visibleExtent = VisiblePosition(createLegacyEditingPosition(extentNode, extentOffset), DOWNSTREAM);

    m_frame->selection().moveTo(visibleBase, visibleExtent);
}
Пример #13
0
void DOMSelection::setPosition(Node* node, int offset, ExceptionState& exceptionState)
{
    if (!m_frame)
        return;
    if (offset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }

    if (!isValidForPosition(node))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection().moveTo(VisiblePosition(createLegacyEditingPosition(node, offset), DOWNSTREAM));
}
Пример #14
0
void DOMSelection::setPosition(Node* node, int offset, ExceptionCode& ec)
{
    if (!m_frame)
        return;
    if (offset < 0) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(node))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection()->moveTo(VisiblePosition(createLegacyEditingPosition(node, offset), DOWNSTREAM));
}
Пример #15
0
void DOMSelection::extend(Node& node, unsigned offset, ExceptionCode& ec)
{
    if (!m_frame)
        return;

    if (offset > (node.offsetInCharacters() ? caretMaxOffset(node) : node.countChildNodes())) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(&node))
        return;

    // FIXME: Eliminate legacy editing positions
    m_frame->selection().setExtent(createLegacyEditingPosition(&node, offset), DOWNSTREAM);
}
Пример #16
0
void DOMSelection::extend(Node* node, int offset, ExceptionCode& ec)
{
    if (!m_frame)
        return;

    if (!node) {
        ec = TYPE_MISMATCH_ERR;
        return;
    }

    if (offset < 0 || offset > (node->offsetInCharacters() ? caretMaxOffset(node) : (int)node->childNodeCount())) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (!isValidForPosition(node))
        return;

    m_frame->selection()->setExtent(VisiblePosition(node, offset, DOWNSTREAM));
}
Пример #17
0
void DOMSelection::extend(Node* node, int offset, ExceptionState& exceptionState)
{
    ASSERT(node);

    if (!m_frame)
        return;

    if (offset < 0) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }
    if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
        exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
        return;
    }

    if (!isValidForPosition(node))
        return;

    m_frame->selection().setExtent(createVisiblePosition(createPosition(node, offset)));
}
Пример #18
0
void DOMSelection::extend(Node* node,
                          int offset,
                          ExceptionState& exceptionState) {
    DCHECK(node);

    if (!isAvailable())
        return;

    if (offset < 0) {
        exceptionState.throwDOMException(
            IndexSizeError, String::number(offset) + " is not a valid offset.");
        return;
    }
    if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
        exceptionState.throwDOMException(
            IndexSizeError,
            String::number(offset) + " is larger than the given node's length.");
        return;
    }

    if (!isValidForPosition(node))
        return;

    const Position& base = frame()->selection().base();
    const Position& extent = createPosition(node, offset);
    const bool selectionHasDirection = true;

    // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
    // needs to be audited.  See http://crbug.com/590369 for more details.
    // In the long term, we should change FrameSelection::setSelection to take a
    // parameter that does not require clean layout, so that modifying selection
    // no longer performs synchronous layout by itself.
    frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();

    const VisibleSelection newSelection = createVisibleSelection(
            base, extent, TextAffinity::Downstream, selectionHasDirection);
    frame()->selection().setSelection(newSelection);
}