Changeset 14169 in webkit


Ignore:
Timestamp:
May 2, 2006 8:17:55 PM (18 years ago)
Author:
justing
Message:

LayoutTests:

Reviewed by harrison


<http://bugzilla.opendarwin.org/show_bug.cgi?id=8704>
Fix a few end merge bugs
<rdar://problem/4424044>
REGRESSION: Extra line appears when typing

Added a function so that selection changes can participate in slow-motion-mode:

  • editing/editing.js: Extra newlines were added:
  • editing/inserting/paragraph-separator-01-expected.checksum: Added.
  • editing/inserting/paragraph-separator-01-expected.png: Added.
  • editing/inserting/paragraph-separator-01-expected.txt: Added.
  • editing/inserting/paragraph-separator-01.html: Added.
  • editing/inserting/paragraph-separator-02-expected.checksum: Added.
  • editing/inserting/paragraph-separator-02-expected.png: Added.
  • editing/inserting/paragraph-separator-02-expected.txt: Added.
  • editing/inserting/paragraph-separator-02.html: Added. A preserved newline was turned into a nbsp:
  • editing/inserting/paragraph-separator-03-expected.checksum: Added.
  • editing/inserting/paragraph-separator-03-expected.png: Added.
  • editing/inserting/paragraph-separator-03-expected.txt: Added.
  • editing/inserting/paragraph-separator-03.html: Added. End merge didn't happen:
  • editing/pasteboard/merge-end-4-expected.checksum: Added.
  • editing/pasteboard/merge-end-4-expected.png: Added.
  • editing/pasteboard/merge-end-4-expected.txt: Added.
  • editing/pasteboard/merge-end-4.html: Added. Content was pulled out of these special elements:
  • editing/pasteboard/merge-end-blockquote-expected.checksum: Added.
  • editing/pasteboard/merge-end-blockquote-expected.png: Added.
  • editing/pasteboard/merge-end-blockquote-expected.txt: Added.
  • editing/pasteboard/merge-end-blockquote.html: Added.
  • editing/pasteboard/merge-end-list-expected.checksum: Added.
  • editing/pasteboard/merge-end-list-expected.png: Added.
  • editing/pasteboard/merge-end-list-expected.txt: Added.
  • editing/pasteboard/merge-end-list.html: Added.
  • editing/pasteboard/merge-end-table-expected.checksum: Added.
  • editing/pasteboard/merge-end-table-expected.png: Added.
  • editing/pasteboard/merge-end-table-expected.txt: Added.
  • editing/pasteboard/merge-end-table.html: Added.

WebCore:

Reviewed by harrison


<http://bugzilla.opendarwin.org/show_bug.cgi?id=8704>
Fix a few end merge bugs
<rdar://problem/4424044>
REGRESSION: Extra line appears when typing

  • bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge smartInsertForString:replacingRange:beforeString:afterString:]): Use renamed characterAfter.
  • editing/InsertParagraphSeparatorCommand.cpp: (WebCore::InsertParagraphSeparatorCommand::doApply): Regenerate a VisiblePosition that became stale during a text node split. Don't rebalance whitespace after the operation, 1) it has a bug that turns preserved newlines into nbsps, 2) I think it should only be done during serialization, not after every command (since editable regions now always have -webkit-nbsp-mode:space on them). Use a regular br for the placeholder as I think we can move away from -webkit-block-placeholders.


  • editing/RebalanceWhitespaceCommand.cpp: Added FIXMEs.
  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::shouldMergeStart): Removed FIXME. (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Can now use rendering information. (WebCore::ReplaceSelectionCommand::doApply): Call shouldMergeEnd after the insertion so that it can use rendering information. Don't use positionAfterNode of the last node inserted to mark the position at the end of inserted content because canonicalization can send it into content that was already in the document.


  • editing/ReplaceSelectionCommand.h:
  • editing/VisiblePosition.cpp: (WebCore::VisiblePosition::characterAfter): Renamed. When two candidates are visually equivalent, the rightmost candidate will be the one inside the text node where the character will be.


  • editing/VisiblePosition.h:
  • editing/htmlediting.cpp: (WebCore::enclosingTableCell): Added. (WebCore::enclosingList):
  • editing/htmlediting.h:
Location:
trunk
Files:
28 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r14155 r14169  
     12006-05-02  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by harrison
     4       
     5        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8704>
     6        Fix a few end merge bugs
     7        <rdar://problem/4424044>
     8        REGRESSION: Extra line appears when typing
     9
     10        Added a function so that selection changes can participate in slow-motion-mode:
     11        * editing/editing.js:
     12        Extra newlines were added:
     13        * editing/inserting/paragraph-separator-01-expected.checksum: Added.
     14        * editing/inserting/paragraph-separator-01-expected.png: Added.
     15        * editing/inserting/paragraph-separator-01-expected.txt: Added.
     16        * editing/inserting/paragraph-separator-01.html: Added.
     17        * editing/inserting/paragraph-separator-02-expected.checksum: Added.
     18        * editing/inserting/paragraph-separator-02-expected.png: Added.
     19        * editing/inserting/paragraph-separator-02-expected.txt: Added.
     20        * editing/inserting/paragraph-separator-02.html: Added.
     21        A preserved newline was turned into a nbsp:
     22        * editing/inserting/paragraph-separator-03-expected.checksum: Added.
     23        * editing/inserting/paragraph-separator-03-expected.png: Added.
     24        * editing/inserting/paragraph-separator-03-expected.txt: Added.
     25        * editing/inserting/paragraph-separator-03.html: Added.
     26        End merge didn't happen:
     27        * editing/pasteboard/merge-end-4-expected.checksum: Added.
     28        * editing/pasteboard/merge-end-4-expected.png: Added.
     29        * editing/pasteboard/merge-end-4-expected.txt: Added.
     30        * editing/pasteboard/merge-end-4.html: Added.
     31        Content was pulled out of these special elements:
     32        * editing/pasteboard/merge-end-blockquote-expected.checksum: Added.
     33        * editing/pasteboard/merge-end-blockquote-expected.png: Added.
     34        * editing/pasteboard/merge-end-blockquote-expected.txt: Added.
     35        * editing/pasteboard/merge-end-blockquote.html: Added.
     36        * editing/pasteboard/merge-end-list-expected.checksum: Added.
     37        * editing/pasteboard/merge-end-list-expected.png: Added.
     38        * editing/pasteboard/merge-end-list-expected.txt: Added.
     39        * editing/pasteboard/merge-end-list.html: Added.
     40        * editing/pasteboard/merge-end-table-expected.checksum: Added.
     41        * editing/pasteboard/merge-end-table-expected.png: Added.
     42        * editing/pasteboard/merge-end-table-expected.txt: Added.
     43        * editing/pasteboard/merge-end-table.html: Added.
     44
    1452006-05-02  Anders Carlsson  <andersca@mac.com>
    246
  • trunk/LayoutTests/editing/editing.js

    r13851 r14169  
    1010//-------------------------------------------------------------------------------------------------------
    1111
     12function execSetSelectionCommand(sn, so, en, eo) {
     13    window.getSelection().setBaseAndExtent(sn, so, en, eo);
     14}
     15function setSelectionCommand(sn, so, en, eo) {
     16    if (commandDelay > 0) {
     17        window.setTimeout(execSetSelectionCommand, commandCount * commandDelay, sn, so, en, eo);
     18        commandCount++;
     19    } else
     20        execSetSelectionCommand(sn, so, en, eo);
     21}
     22
     23//-------------------------------------------------------------------------------------------------------
     24
    1225function execTransposeCharactersCommand() {
    1326    document.execCommand("Transpose");
  • trunk/WebCore/ChangeLog

    r14167 r14169  
     12006-05-02  Justin Garcia  <justin.garcia@apple.com>
     2
     3        Reviewed by harrison
     4       
     5        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8704>
     6        Fix a few end merge bugs
     7        <rdar://problem/4424044>
     8        REGRESSION: Extra line appears when typing
     9
     10        * bridge/mac/WebCoreFrameBridge.mm:
     11        (-[WebCoreFrameBridge smartInsertForString:replacingRange:beforeString:afterString:]):
     12        Use renamed characterAfter.
     13        * editing/InsertParagraphSeparatorCommand.cpp:
     14        (WebCore::InsertParagraphSeparatorCommand::doApply):
     15        Regenerate a VisiblePosition that became stale during a text node split.
     16        Don't rebalance whitespace after the operation, 1) it has a bug that turns preserved
     17        newlines into nbsps, 2) I think it should only be done during serialization, not after
     18        every command (since editable regions now always have -webkit-nbsp-mode:space on them).
     19        Use a regular br for the placeholder as I think we can move away from -webkit-block-placeholders.
     20       
     21        * editing/RebalanceWhitespaceCommand.cpp: Added FIXMEs.
     22        * editing/ReplaceSelectionCommand.cpp:
     23        (WebCore::ReplaceSelectionCommand::shouldMergeStart): Removed FIXME.
     24        (WebCore::ReplaceSelectionCommand::shouldMergeEnd): Can now use rendering information.
     25        (WebCore::ReplaceSelectionCommand::doApply):
     26        Call shouldMergeEnd after the insertion so that it can use rendering information.
     27        Don't use positionAfterNode of the last node inserted to mark the position at the end
     28        of inserted content because canonicalization can send it into content that was already
     29        in the document.
     30       
     31        * editing/ReplaceSelectionCommand.h:
     32        * editing/VisiblePosition.cpp:
     33        (WebCore::VisiblePosition::characterAfter):
     34        Renamed.  When two candidates are visually equivalent, the rightmost candidate will be
     35        the one inside the text node where the character will be.
     36       
     37        * editing/VisiblePosition.h:
     38        * editing/htmlediting.cpp:
     39        (WebCore::enclosingTableCell): Added.
     40        (WebCore::enclosingList):
     41        * editing/htmlediting.h:
     42
    1432006-05-02  David Hyatt  <hyatt@apple.com>
    244
  • trunk/WebCore/bridge/mac/WebCoreFrameBridge.mm

    r14110 r14169  
    18171817    bool addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(startVisiblePos);
    18181818    if (addLeadingSpace) {
    1819         QChar previousChar = startVisiblePos.previous().character();
     1819        QChar previousChar = startVisiblePos.previous().characterAfter();
    18201820        if (!previousChar.isNull()) {
    18211821            addLeadingSpace = !m_frame->isCharacterSmartReplaceExempt(previousChar, true);
     
    18251825    bool addTrailingSpace = endPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(endVisiblePos);
    18261826    if (addTrailingSpace) {
    1827         QChar thisChar = endVisiblePos.character();
     1827        QChar thisChar = endVisiblePos.characterAfter();
    18281828        if (!thisChar.isNull()) {
    18291829            addTrailingSpace = !m_frame->isCharacterSmartReplaceExempt(thisChar, false);
  • trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp

    r13821 r14169  
    266266    // FIXME: We need the affinity for pos, but pos.downstream() does not give it
    267267    Position leadingWhitespace = pos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY);
     268    // FIXME: leadingWhitespacePosition is returning the position before preserved newlines for positions
     269    // after the preserved newline, causing the newline to be turned into a nbsp.
    268270    if (leadingWhitespace.isNotNull()) {
    269271        Text *textNode = static_cast<Text *>(leadingWhitespace.node());
     
    278280            splitTextNode(textNode, pos.offset());
    279281            pos = Position(startNode, 0);
     282            visiblePos = VisiblePosition(pos);
    280283            splitText = true;
    281284        }
     
    296299    }
    297300
    298     // Insert a block placeholder if the next visible position is in a different paragraph,
    299     // because we know that there will be no content on the first line of the new block
    300     // before the first block child. So, we need the placeholder to "hold the first line open".
    301     VisiblePosition next = visiblePos.next();
    302     if (!next.isNull() && !inSameBlock(visiblePos, next))
    303         appendBlockPlaceholder(blockToInsert.get());
    304 
     301    // If the paragraph separator was inserted at the end of a paragraph, an empty line must be
     302    // created.  All of the nodes, starting at visiblePos, are about to be added to the new paragraph
     303    // element.  If the first node to be inserted won't be one that will hold an empty line open, add a br.
     304    if (isEndOfParagraph(visiblePos) && !startNode->hasTagName(brTag) &&
     305        !(startNode->renderer()->style()->preserveNewline() && visiblePos.characterAfter() == '\n'))
     306        appendNode(createBreakElement(document()).get(), blockToInsert.get());
     307       
    305308    // Move the start node and the siblings of the start node.
    306309    if (startNode != startBlock) {
     
    344347
    345348    setEndingSelection(Position(blockToInsert.get(), 0), DOWNSTREAM);
    346     rebalanceWhitespace();
    347349    applyStyleAfterInsertion();
    348350}
  • trunk/WebCore/editing/RebalanceWhitespaceCommand.cpp

    r13393 r14169  
    4444}
    4545
     46// FIXME: This doesn't go into adjacent text in siblings, cousins, etc.
     47// FIXME: This turns preserved newlines into nbsps.
    4648void RebalanceWhitespaceCommand::doApply()
    4749{
  • trunk/WebCore/editing/ReplaceSelectionCommand.cpp

    r14143 r14169  
    482482   
    483483    // Don't pull content out of a list item.
    484     // FIXMEs: Do this check in shouldMergeEnd too.  Don't pull content out of a table cell either.
     484    // FIXMEs: Don't pull content out of a table cell either.
    485485    if (enclosingList(incomingFragment.mergeStartNode()))
    486486        return false;
     
    497497}
    498498
    499 bool ReplaceSelectionCommand::shouldMergeEnd(const ReplacementFragment& incomingFragment, const Selection& destinationSelection)
    500 {
    501     return !incomingFragment.hasInterchangeNewlineAtEnd() && !isEndOfParagraph(destinationSelection.visibleEnd());
     499bool ReplaceSelectionCommand::shouldMergeEnd(const ReplacementFragment& incomingFragment, const VisiblePosition& endOfInsertedContent, const VisiblePosition& destination)
     500{
     501    Node* endNode = endOfInsertedContent.deepEquivalent().node();
     502    Node* destinationNode = destination.deepEquivalent().node();
     503    // FIXME: Unify the naming scheme for these enclosing element getters.
     504    return !incomingFragment.hasInterchangeNewlineAtEnd() &&
     505           isEndOfParagraph(endOfInsertedContent) &&
     506           nearestMailBlockquote(endNode) == nearestMailBlockquote(destinationNode) &&
     507           enclosingListChild(endNode) == enclosingListChild(destinationNode) &&
     508           enclosingTableCell(endNode) == enclosingTableCell(destinationNode) &&
     509           !endNode->hasTagName(hrTag);
    502510}
    503511
     
    531539    bool mergeStart = shouldMergeStart(fragment, selection);
    532540   
    533     // Whether the last paragraph of the incoming fragment should be merged with content from visibleEnd to endOfParagraph(visibleEnd).
    534     bool mergeEnd = shouldMergeEnd(fragment, selection);
     541    bool endWasEndOfParagraph = isEndOfParagraph(visibleEnd);
    535542
    536543    Position startPos = selection.start();
     
    612619        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(visiblePos);
    613620        if (addLeadingSpace) {
    614             QChar previousChar = visiblePos.previous().character();
     621            QChar previousChar = visiblePos.previous().characterAfter();
    615622            if (!previousChar.isNull()) {
    616623                addLeadingSpace = !frame->isCharacterSmartReplaceExempt(previousChar, true);
     
    619626        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(visiblePos);
    620627        if (addTrailingSpace) {
    621             QChar thisChar = visiblePos.character();
     628            QChar thisChar = visiblePos.characterAfter();
    622629            if (!thisChar.isNull()) {
    623630                addTrailingSpace = !frame->isCharacterSmartReplaceExempt(thisChar, false);
     
    793800    // Make sure that content after the end of the selection being pasted into is in the same paragraph as the
    794801    // last bit of content that was inserted.
    795     if (mergeEnd) {
    796         VisiblePosition afterInsertedContent(positionAfterNode(m_lastNodeInserted.get()));
    797         if (isEndOfParagraph(afterInsertedContent)) {
    798             VisiblePosition startOfParagraphToMove = startOfParagraph(afterInsertedContent);
    799             VisiblePosition destination = afterInsertedContent.next();
    800             moveParagraph(startOfParagraphToMove, afterInsertedContent, destination);
    801         }
     802    VisiblePosition endOfInsertedContent(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
     803    VisiblePosition destination = endOfInsertedContent.next();
     804    if (!endWasEndOfParagraph && shouldMergeEnd(fragment, endOfInsertedContent, destination)) {
     805        VisiblePosition startOfParagraphToMove = startOfParagraph(endOfInsertedContent);
     806        moveParagraph(startOfParagraphToMove, endOfInsertedContent, destination);
    802807    }
    803808   
  • trunk/WebCore/editing/ReplaceSelectionCommand.h

    r14086 r14169  
    132132   
    133133    bool shouldMergeStart(const ReplacementFragment&, const Selection&);
    134     bool shouldMergeEnd(const ReplacementFragment&, const Selection&);
     134    bool shouldMergeEnd(const ReplacementFragment&, const VisiblePosition&, const VisiblePosition&);
    135135
    136136    RefPtr<Node> m_firstNodeInserted;
  • trunk/WebCore/editing/VisiblePosition.cpp

    r14086 r14169  
    214214}
    215215
    216 QChar VisiblePosition::character() const
    217 {
    218     Position pos = m_deepPosition;
     216QChar VisiblePosition::characterAfter() const
     217{
     218    // We canonicalize to the first of two equivalent candidates, but the second of the two candidates
     219    // is the one that will be inside the text node containing the character after this visible position.
     220    Position pos = m_deepPosition.downstream();
    219221    Node *node = pos.node();
    220222    if (!node || !node->isTextNode()) {
  • trunk/WebCore/editing/VisiblePosition.h

    r13896 r14169  
    6767    bool isLastInBlock() const;
    6868
    69     QChar character() const;
     69    QChar characterAfter() const;
    7070   
    7171    void debugPosition(const char* msg = "") const;
  • trunk/WebCore/editing/htmlediting.cpp

    r14071 r14169  
    374374}
    375375
     376Node* enclosingTableCell(Node* node)
     377{
     378    if (!node)
     379        return 0;
     380       
     381    for (Node* n = node->parentNode(); n; n = n->parentNode())
     382        if (n->renderer() && n->renderer()->isTableCell())
     383            return n;
     384           
     385    return 0;
     386}
     387
    376388Node* enclosingList(Node* node)
    377389{
     
    382394        if (n->hasTagName(ulTag) || n->hasTagName(olTag))
    383395            return n;
     396           
    384397    return 0;
    385398}
  • trunk/WebCore/editing/htmlediting.h

    r14071 r14169  
    8282Position positionOutsideContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
    8383
    84 bool isListElement(Node* n);
    85 Node* enclosingList(Node* node);
    86 Node *enclosingListChild(Node *n);
    87 bool isTableElement(Node* n);
     84Node* enclosingTableCell(Node*);
     85bool isListElement(Node*);
     86Node* enclosingList(Node*);
     87Node* enclosingListChild(Node*);
     88bool isTableElement(Node*);
    8889bool isFirstVisiblePositionAfterTableElement(const Position&);
    8990Position positionBeforePrecedingTableElement(const Position&);
Note: See TracChangeset for help on using the changeset viewer.