Changeset 68337 in webkit


Ignore:
Timestamp:
Sep 25, 2010 1:42:46 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

2010-09-25 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Tony Chang.

FormatBlockCommand's modifyRange and doApply should be merged
https://bugs.webkit.org/show_bug.cgi?id=46504

Isolated the code in doApply to insert and remove lists for single paragraph into doApplyForSingleParagraph.
Merged the code in modifyRange into doApply and cleaned up.

No new tests are added since this is a cleanup.

  • editing/FormatBlockCommand.cpp: (WebCore::FormatBlockCommand::doApply): Merged with modifyRange; calls doApplyForSingleParagraph. (WebCore::FormatBlockCommand::doApplyForSingleParagraph): Added.
  • editing/FormatBlockCommand.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r68335 r68337  
     12010-09-25  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        FormatBlockCommand's modifyRange and doApply should be merged
     6        https://bugs.webkit.org/show_bug.cgi?id=46504
     7
     8        Isolated the code in doApply to insert and remove lists for single paragraph into doApplyForSingleParagraph.
     9        Merged the code in modifyRange into doApply and cleaned up.
     10
     11        No new tests are added since this is a cleanup.
     12
     13        * editing/FormatBlockCommand.cpp:
     14        (WebCore::FormatBlockCommand::doApply): Merged with modifyRange; calls doApplyForSingleParagraph.
     15        (WebCore::FormatBlockCommand::doApplyForSingleParagraph): Added.
     16        * editing/FormatBlockCommand.h:
     17
    1182010-09-25  Dan Bernstein  <mitz@apple.com>
    219
  • trunk/WebCore/editing/FormatBlockCommand.cpp

    r66032 r68337  
    4242}
    4343
    44 bool FormatBlockCommand::modifyRange()
    45 {
    46     ASSERT(endingSelection().isRange());
    47     VisiblePosition visibleStart = endingSelection().visibleStart();
    48     VisiblePosition visibleEnd = endingSelection().visibleEnd();
    49     VisiblePosition startOfLastParagraph = startOfParagraph(visibleEnd);
    50    
    51     if (startOfParagraph(visibleStart) == startOfLastParagraph)
    52         return false;
    53 
    54     setEndingSelection(visibleStart);
    55     doApply();
    56     visibleStart = endingSelection().visibleStart();
    57     VisiblePosition nextParagraph = endOfParagraph(visibleStart).next();
    58     while (nextParagraph.isNotNull() && nextParagraph != startOfLastParagraph) {
    59         setEndingSelection(nextParagraph);
    60         doApply();
    61         nextParagraph = endOfParagraph(endingSelection().visibleStart()).next();
    62     }
    63     setEndingSelection(visibleEnd);
    64     doApply();
    65     visibleEnd = endingSelection().visibleEnd();
    66     setEndingSelection(VisibleSelection(visibleStart.deepEquivalent(), visibleEnd.deepEquivalent(), DOWNSTREAM));
    67 
    68     return true;
    69 }
    70 
    7144void FormatBlockCommand::doApply()
    7245{
     
    8760    // margin/padding, but not others.  We should make the gap painting more consistent and
    8861    // then use a left margin/padding rule here.
    89     if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd))
     62    if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd)) {
    9063        setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(true)));
     64        visibleEnd = endingSelection().visibleEnd();
     65    }
    9166
    92     if (endingSelection().isRange() && modifyRange())
     67    VisiblePosition startOfLastParagraph = startOfParagraph(visibleEnd);
     68    if (endingSelection().isCaret() || startOfParagraph(visibleStart) == startOfLastParagraph) {
     69        doApplyForSingleParagraph();
    9370        return;
     71    }
    9472
     73    setEndingSelection(visibleStart);
     74    doApplyForSingleParagraph();
     75    visibleStart = endingSelection().visibleStart();
     76    VisiblePosition nextParagraph = endOfParagraph(visibleStart).next();
     77    while (nextParagraph.isNotNull() && nextParagraph != startOfLastParagraph) {
     78        setEndingSelection(nextParagraph);
     79        doApplyForSingleParagraph();
     80        nextParagraph = endOfParagraph(endingSelection().visibleStart()).next();
     81    }
     82    setEndingSelection(visibleEnd);
     83    doApplyForSingleParagraph();
     84    visibleEnd = endingSelection().visibleEnd();
     85
     86    setEndingSelection(VisibleSelection(visibleStart.deepEquivalent(), visibleEnd.deepEquivalent(), DOWNSTREAM));
     87}
     88
     89void FormatBlockCommand::doApplyForSingleParagraph()
     90{
    9591    ExceptionCode ec;
    9692    String localName, prefix;
     
    10399        // We're already in a block with the format we want, so we don't have to do anything
    104100        return;
    105    
     101
    106102    VisiblePosition paragraphStart = startOfParagraph(endingSelection().visibleStart());
    107103    VisiblePosition paragraphEnd = endOfParagraph(endingSelection().visibleStart());
     
    110106    RefPtr<Element> blockNode = createHTMLElement(document(), m_tagName);
    111107    RefPtr<Element> placeholder = createBreakElement(document());
    112    
     108
    113109    Node* root = endingSelection().start().node()->rootEditableElement();
    114110    if (validBlockTag(refNode->nodeName().lower()) &&
     
    123119    }
    124120    appendNode(placeholder, blockNode);
    125    
     121
    126122    VisiblePosition destination(Position(placeholder.get(), 0));
    127123    if (paragraphStart == paragraphEnd && !lineBreakExistsAtVisiblePosition(paragraphStart)) {
  • trunk/WebCore/editing/FormatBlockCommand.h

    r39456 r68337  
    4242
    4343    virtual void doApply();
     44    void doApplyForSingleParagraph();
    4445    virtual EditAction editingAction() const { return EditActionFormatBlock; }
    4546
    46     bool modifyRange();
    4747    AtomicString m_tagName;
    4848};
Note: See TracChangeset for help on using the changeset viewer.