Example #1
0
void TypingCommand::doApply()
{
    if (endingSelection().isNone())
        return;
        
    if (m_commandType == DeleteKey)
        if (m_commands.isEmpty())
            m_openedByBackwardDelete = true;

    switch (m_commandType) {
        case DeleteSelection:
            deleteSelection(m_smartDelete);
            return;
        case DeleteKey:
            deleteKeyPressed(m_granularity);
            return;
        case ForwardDeleteKey:
            forwardDeleteKeyPressed(m_granularity);
            return;
        case InsertLineBreak:
            insertLineBreak();
            return;
        case InsertParagraphSeparator:
            insertParagraphSeparator();
            return;
        case InsertParagraphSeparatorInQuotedContent:
            insertParagraphSeparatorInQuotedContent();
            return;
        case InsertText:
            insertText(m_textToInsert, m_selectInsertedText);
            return;
    }

    ASSERT_NOT_REACHED();
}
Example #2
0
bool Editor::insertParagraphSeparator()
{
    if (!canEdit())
        return false;

    if (!canEditRichly())
        return insertLineBreak();

    VisiblePosition caret = m_frame.selection().selection().visibleStart();
    bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
    ASSERT(m_frame.document());
    TypingCommand::insertParagraphSeparator(*m_frame.document(), 0);
    revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);

    return true;
}
Example #3
0
bool Editor::handleTextEvent(TextEvent* event)
{
    // Default event handling for Drag and Drop will be handled by DragController
    // so we leave the event for it.
    if (event->isDrop())
        return false;

    if (event->isPaste()) {
        if (event->pastingFragment())
            replaceSelectionWithFragment(event->pastingFragment(), false, event->shouldSmartReplace(), event->shouldMatchStyle());
        else
            replaceSelectionWithText(event->data(), false, event->shouldSmartReplace());
        return true;
    }

    String data = event->data();
    if (data == "\n") {
        if (event->isLineBreak())
            return insertLineBreak();
        return insertParagraphSeparator();
    }

    return insertTextWithoutSendingTextEvent(data, false, event);
}
Example #4
0
void PaintArea::paintCurrentNode(PaintNode *currentPaintNode,
                                 QPainter *qPainter,
                                 std::vector<PaintNode*> *paintNodes,
                                 std::vector<PaintNode*>::iterator
                                 currentLocation)
{
    if (currentPaintNode->getTypeOfPaintNode() == "char")
    {
        //Draw the text contained within each paragraph node. New lines are
        //only added after each paragraph node--not any other element.
        if (positionSet)
        {
            updateCurrentPosition();
        }

        char *character = currentPaintNode->getCharacter();
        *currentCharacter = QString(*character);

        currentFont = qPainter->font();

        if (currentPaintNode->getWeight() == QFont::Bold)
        {
            currentFont.setBold(true);
        }
        else
        {
            currentFont.setBold(false);
        }

        if (currentPaintNode->getStyle() == QFont::StyleItalic)
        {
            currentFont.setItalic(true);
        }
        else
        {
            currentFont.setItalic(false);
        }

        QFontMetrics fm(currentFont);

        //Wrap text by entire words, not character-by-character.
        if (!nextWordChecked)
        {
            int currentLineWidth = totalWidth;
            currentLineWidth += getNextWordWidth(paintNodes, qPainter,
                                                 currentLocation);

            if (currentLineWidth + RIGHT_SIDE_PADDING + STARTING_X
                    >= this->width())
            {
                totalWidth = 0;
                currentY += fm.height();
                currentX = STARTING_X;
            }

            nextWordChecked = true;
        }

        QRect box(QPoint(currentX, currentY), QSize(fm.width(*character),
                                                    fm.height()));

        qPainter->setFont(currentFont);
        qPainter->drawText(box, Qt::AlignCenter, QString(*character));

        if (isspace(*character))
        {
            nextWordChecked = false;
        }

        updateCurrentPosition();
    }

    else if (currentPaintNode->getTypeOfPaintNode() == "image")
    {
        //Draw the image.
        QImage image(QString::fromStdString(currentPaintNode->getSourcePath()));
        if (image.width() + totalWidth >= this->width() + RIGHT_SIDE_PADDING)
        {
            totalWidth = 0;
            currentX = 0;

            QFontMetrics fm(currentFont);
            currentY += fm.height();
        }
        qPainter->drawImage(currentX, currentY, image);

        currentX += image.width() + 10;
        totalWidth += image.width() + 10;
        if (currentX >= this->width() - RIGHT_SIDE_PADDING)
        {
            currentX = STARTING_X;
        }
        currentY += image.height() + 10;
        nextWordChecked = false;

        currentLocation++;
        if ((*currentLocation)->getTypeOfPaintNode() == "node")
        {
            currentX = STARTING_X;
            totalWidth = 0;
        }
    }

    else if (currentPaintNode->getTypeOfPaintNode() == "hr")
    {
        QFontMetrics fm(currentFont);
        if (currentX != STARTING_X)
        {
            currentX = STARTING_X;
            currentY += fm.height();
        }

        qPainter->drawLine(QPoint(currentX, currentY),
                           QPoint(this->width() - RIGHT_SIDE_PADDING,
                                  currentY));

        currentY += fm.height();
        totalWidth = 0;
    }

    else if (currentPaintNode->getTypeOfPaintNode() == "ul")
    {
        //This is an ugly, hard-coded solution that will be removed as part of the
        //0.2.0 beta code rewrite and clean up.
        insertLineBreak();
        currentY -= 20;
        drawDocument(qPainter, currentPaintNode->returnNode()->
                     getPaintNodes());
    }

    else if (currentPaintNode->getTypeOfPaintNode() == "li")
    {
        indentOn = true;
        insertLineBreak();
        QPen bulletPoint(Qt::black);
        bulletPoint.setCapStyle(Qt::RoundCap);
        bulletPoint.setWidth(5);
        qPainter->setPen(bulletPoint);
        qPainter->drawPoint(currentX - 7, currentY + 10);
        drawDocument(qPainter, currentPaintNode->returnNode()->
                     getPaintNodes());
        indentOn = false;
        insertLineBreak();
    }

    else if (currentPaintNode->getTypeOfPaintNode() == "node")
    {

        //Call the function again on each of the PaintNode's child paint nodes.
        //This ensures that all of the child nodes of the overall parent node
        //are drawn.
        std::vector<PaintNode*> *childPaintNodes = currentPaintNode->
                returnNode()->getPaintNodes();
        drawDocument(qPainter, childPaintNodes);
        if (currentPaintNode->returnNode()->getTypeOfRenderNode() == "p")
        {
            insertLineBreak();
        }
    }
}