2010-12-23 Ryosuke Niwa <rniwa@webkit.org>
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Dec 2010 00:22:00 +0000 (00:22 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Dec 2010 00:22:00 +0000 (00:22 +0000)
commit21911aa053d0e8b043fba358be9d78697194b545
tree9d4432e623a68d9b11c5c960dc3607f5e618ce41
parent6f3d59adcbb5da7c11199ba79423ec2288e0fd78
2010-12-23  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Darin Adler.

        Selection becomes stale when CharacterData is manipulated directly
        https://bugs.webkit.org/show_bug.cgi?id=51389

        The bug was caused by SelectionController's not adjusting selection when CharacterData's
        m_data is modified by its API.

        Fixed the bug by adding textWillBeReplaced to SelectionController and calling it in
        CharacterData::textWillBeReplaced. Added newLength to setDataAndUpdate, which is passed to
        textWillBeReplaced because inserting, replacing, or removing data may require moving
        the offset of the selection end points (done by shouldRemovePositionAfterAdoptingTextReplacement).

        Also fixed the condition for determining whether or not a node intersects the selection
        in respondToNodeModification, which is extracted from nodeWillBeRemoved. The old condition
        failed to recognize certain cases when selection started and ended with non-zero offsets.

        Tests: editing/selection/character-data-mutation-crash.html
               editing/selection/character-data-mutation.html

        * dom/CharacterData.cpp:
        (WebCore::CharacterData::setData): Passes newLegnth to setDataAndUpdate.
        (WebCore::CharacterData::appendData): Ditto.
        (WebCore::CharacterData::insertData): Ditto.
        (WebCore::CharacterData::deleteData): Ditto.
        (WebCore::CharacterData::replaceData): Ditto.
        (WebCore::CharacterData::setDataAndUpdate): Added newLegnth to the argument list,
        and renamed lengthOfReplacedData to oldLength; calls textWillBeReplaced.
        * dom/CharacterData.h:
        * editing/SelectionController.cpp:
        (WebCore::removingNodeRemovesPosition): Removed indentations from blank lines.
        (WebCore::SelectionController::nodeWillBeRemoved): Calls nodeWillBeRemoved.
        (WebCore::SelectionController::respondToNodeModification): Extracted from nodeWillBeRemoved;
        fixed the logic to figure out whether a node is inside the range or not.
        (WebCore::shouldRemovePositionAfterAdoptingTextReplacement): Added.
        (WebCore::SelectionController::textWillBeReplaced): Added.
        * editing/SelectionController.h:
2010-12-23  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Darin Adler.

        Selection becomes stale when CharacterData is manipulated directly
        https://bugs.webkit.org/show_bug.cgi?id=51389

        Added tests to ensure WebKit adjusts or clears selection when the start container
        or the end container of the selection's first range is modified by CharacterData's API.

        Many editing tests had to be rebaselined due to different editing delegate dumps
        caused by WebKit's properly adjusting selection's offsets as editing commands modify the DOM.

        * editing/deleting/delete-by-word-001-expected.txt:
        * editing/deleting/delete-by-word-002-expected.txt:
        * editing/deleting/delete-ligature-001-expected.txt:
        * editing/deleting/delete-ligature-002-expected.txt:
        * editing/deleting/delete-ligature-003-expected.txt:
        * editing/deleting/skip-virama-001-expected.txt:
        * editing/execCommand/createLink-expected.txt:
        * editing/execCommand/hilitecolor-expected.txt:
        * editing/execCommand/unlink-expected.txt:
        * editing/inserting/insert-thai-characters-001-expected.txt:
        * editing/pasteboard/copy-in-password-field-expected.txt:
        * editing/pasteboard/paste-into-anchor-text-expected.txt:
        * editing/selection/character-data-mutation-crash-expected.txt: Added.
        * editing/selection/character-data-mutation-crash.html: Added.
        * editing/selection/character-data-mutation-expected.txt: Added.
        * editing/selection/character-data-mutation.html: Added.
        * editing/style/remove-underline-from-stylesheet-expected.txt:
        * editing/style/typing-style-003-expected.txt:
        * editing/undo/redo-style-expected.txt:
        * platform/mac/editing/deleting/collapse-whitespace-3587601-fix-expected.txt:
        * platform/mac/editing/deleting/delete-3608430-fix-expected.txt:
        * platform/mac/editing/deleting/delete-3608445-fix-expected.txt:
        * platform/mac/editing/deleting/delete-3608462-fix-expected.txt:
        * platform/mac/editing/deleting/delete-after-span-ws-001-expected.txt:
        * platform/mac/editing/deleting/delete-after-span-ws-002-expected.txt:
        * platform/mac/editing/deleting/delete-after-span-ws-003-expected.txt:
        * platform/mac/editing/deleting/delete-and-undo-expected.txt:
        * platform/mac/editing/deleting/delete-block-merge-contents-010-expected.txt:
        * platform/mac/editing/deleting/delete-block-table-expected.txt:
        * platform/mac/editing/deleting/delete-br-007-expected.txt:
        * platform/mac/editing/deleting/delete-character-001-expected.txt:
        * platform/mac/editing/deleting/delete-contiguous-ws-001-expected.txt:
        * platform/mac/editing/deleting/delete-hr-expected.txt:
        * platform/mac/editing/deleting/delete-leading-ws-001-expected.txt:
        * platform/mac/editing/deleting/delete-line-end-ws-001-expected.txt:
        * platform/mac/editing/deleting/delete-line-end-ws-002-expected.txt:
        * platform/mac/editing/deleting/delete-listitem-001-expected.txt:
        * platform/mac/editing/deleting/delete-selection-001-expected.txt:
        * platform/mac/editing/deleting/delete-tab-001-expected.txt:
        * platform/mac/editing/deleting/delete-tab-002-expected.txt:
        * platform/mac/editing/deleting/delete-tab-003-expected.txt:
        * platform/mac/editing/deleting/delete-tab-004-expected.txt:
        * platform/mac/editing/deleting/delete-trailing-ws-001-expected.txt:
        * platform/mac/editing/deleting/delete-trailing-ws-002-expected.txt:
        * platform/mac/editing/deleting/delete-ws-fixup-001-expected.txt:
        * platform/mac/editing/deleting/delete-ws-fixup-002-expected.txt:
        * platform/mac/editing/deleting/forward-delete-expected.txt:
        * platform/mac/editing/deleting/non-smart-delete-expected.txt:
        * platform/mac/editing/deleting/smart-delete-001-expected.txt:
        * platform/mac/editing/deleting/smart-delete-002-expected.txt:
        * platform/mac/editing/deleting/smart-delete-003-expected.txt:
        * platform/mac/editing/deleting/smart-delete-004-expected.txt:
        * platform/mac/editing/execCommand/insertHorizontalRule-expected.txt:
        * platform/mac/editing/input/firstrectforcharacterrange-styled-expected.txt:
        * platform/mac/editing/input/text-input-controller-expected.txt:
        * platform/mac/editing/inserting/4278698-expected.txt:
        * platform/mac/editing/inserting/editing-empty-divs-expected.txt:
        * platform/mac/editing/inserting/insert-3654864-fix-expected.txt:
        * platform/mac/editing/inserting/insert-after-delete-001-expected.txt:
        * platform/mac/editing/inserting/insert-br-003-expected.txt:
        * platform/mac/editing/inserting/insert-br-006-expected.txt:
        * platform/mac/editing/inserting/insert-br-007-expected.txt:
        * platform/mac/editing/inserting/insert-br-008-expected.txt:
        * platform/mac/editing/inserting/insert-br-009-expected.txt:
        * platform/mac/editing/inserting/insert-br-at-tabspan-002-expected.txt:
        * platform/mac/editing/inserting/insert-br-at-tabspan-003-expected.txt:
        * platform/mac/editing/inserting/insert-div-003-expected.txt:
        * platform/mac/editing/inserting/insert-div-006-expected.txt:
        * platform/mac/editing/inserting/insert-div-008-expected.txt:
        * platform/mac/editing/inserting/insert-div-024-expected.txt:
        * platform/mac/editing/inserting/insert-space-in-empty-doc-expected.txt:
        * platform/mac/editing/inserting/insert-tab-003-expected.txt:
        * platform/mac/editing/inserting/insert-text-at-tabspan-001-expected.txt:
        * platform/mac/editing/inserting/insert-text-at-tabspan-002-expected.txt:
        * platform/mac/editing/inserting/insert-text-with-newlines-expected.txt:
        * platform/mac/editing/inserting/typing-001-expected.txt:
        * platform/mac/editing/inserting/typing-002-expected.txt:
        * platform/mac/editing/inserting/typing-003-expected.txt:
        * platform/mac/editing/inserting/typing-around-br-001-expected.txt:
        * platform/mac/editing/inserting/typing-around-image-001-expected.txt:
        * platform/mac/editing/pasteboard/4076267-2-expected.txt:
        * platform/mac/editing/pasteboard/4076267-3-expected.txt:
        * platform/mac/editing/pasteboard/bad-placeholder-expected.txt:
        * platform/mac/editing/pasteboard/cut-text-001-expected.txt:
        * platform/mac/editing/pasteboard/emacs-ctrl-a-k-y-expected.txt:
        * platform/mac/editing/pasteboard/emacs-ctrl-k-y-001-expected.txt:
        * platform/mac/editing/pasteboard/interchange-newline-1-expected.txt:
        * platform/mac/editing/pasteboard/merge-end-1-expected.txt:
        * platform/mac/editing/pasteboard/merge-end-2-expected.txt:
        * platform/mac/editing/pasteboard/merge-end-4-expected.txt:
        * platform/mac/editing/pasteboard/merge-end-list-expected.txt:
        * platform/mac/editing/pasteboard/merge-end-table-expected.txt:
        * platform/mac/editing/pasteboard/paste-match-style-001-expected.txt:
        * platform/mac/editing/pasteboard/paste-text-001-expected.txt:
        * platform/mac/editing/pasteboard/paste-text-019-expected.txt:
        * platform/mac/editing/pasteboard/paste-text-at-tabspan-001-expected.txt:
        * platform/mac/editing/pasteboard/paste-text-at-tabspan-002-expected.txt:
        * platform/mac/editing/pasteboard/paste-text-at-tabspan-003-expected.txt:
        * platform/mac/editing/pasteboard/paste-xml-expected.txt:
        * platform/mac/editing/pasteboard/pasting-object-expected.txt:
        * platform/mac/editing/pasteboard/smart-paste-002-expected.txt:
        * platform/mac/editing/pasteboard/smart-paste-006-expected.txt:
        * platform/mac/editing/pasteboard/smart-paste-007-expected.txt:
        * platform/mac/editing/pasteboard/subframe-dragndrop-1-expected.txt:
        * platform/mac/editing/spelling/spelling-expected.txt:
        * platform/mac/editing/style/style-3681552-fix-001-expected.txt:
        * platform/mac/editing/style/style-3681552-fix-002-expected.txt:
        * platform/mac/editing/style/style-boundary-002-expected.txt:
        * platform/mac/editing/style/style-boundary-005-expected.txt:
        * platform/mac/editing/style/typing-style-001-expected.txt:
        * platform/mac/editing/style/typing-style-002-expected.txt:
        * platform/mac/editing/style/unbold-in-bold-expected.txt:
        * platform/mac/editing/undo/4063751-expected.txt:
        * platform/mac/editing/undo/redo-typing-001-expected.txt:
        * platform/mac/editing/undo/undo-combined-delete-boundary-expected.txt:
        * platform/mac/editing/undo/undo-combined-delete-expected.txt:
        * platform/mac/editing/undo/undo-delete-boundary-expected.txt:
        * platform/mac/editing/undo/undo-delete-expected.txt:
        * platform/mac/editing/undo/undo-forward-delete-boundary-expected.txt:
        * platform/mac/editing/undo/undo-forward-delete-expected.txt:
        * platform/mac/editing/undo/undo-misspellings-expected.txt:
        * platform/mac/editing/undo/undo-typing-001-expected.txt:
        * platform/mac/editing/unsupported-content/list-type-after-expected.txt:
        * platform/mac/editing/unsupported-content/list-type-before-expected.txt:
        * platform/mac/editing/unsupported-content/table-type-after-expected.txt:
        * platform/mac/editing/unsupported-content/table-type-before-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74593 268f45cc-cd09-0410-ab3c-d52691b4dbfc
132 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/deleting/delete-by-word-001-expected.txt
LayoutTests/editing/deleting/delete-by-word-002-expected.txt
LayoutTests/editing/deleting/delete-ligature-001-expected.txt
LayoutTests/editing/deleting/delete-ligature-002-expected.txt
LayoutTests/editing/deleting/delete-ligature-003-expected.txt
LayoutTests/editing/deleting/skip-virama-001-expected.txt
LayoutTests/editing/execCommand/createLink-expected.txt
LayoutTests/editing/execCommand/hilitecolor-expected.txt
LayoutTests/editing/execCommand/unlink-expected.txt
LayoutTests/editing/inserting/insert-thai-characters-001-expected.txt
LayoutTests/editing/pasteboard/copy-in-password-field-expected.txt
LayoutTests/editing/pasteboard/paste-into-anchor-text-expected.txt
LayoutTests/editing/selection/character-data-mutation-crash-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/character-data-mutation-crash.html [new file with mode: 0644]
LayoutTests/editing/selection/character-data-mutation-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/character-data-mutation.html [new file with mode: 0644]
LayoutTests/editing/style/remove-underline-from-stylesheet-expected.txt
LayoutTests/editing/style/typing-style-003-expected.txt
LayoutTests/editing/undo/redo-style-expected.txt
LayoutTests/platform/mac/editing/deleting/collapse-whitespace-3587601-fix-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-3608430-fix-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-3608445-fix-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-3608462-fix-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-after-span-ws-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-after-span-ws-002-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-after-span-ws-003-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-and-undo-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-block-merge-contents-010-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-block-table-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-br-007-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-character-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-contiguous-ws-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-hr-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-leading-ws-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-line-end-ws-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-line-end-ws-002-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-listitem-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-selection-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-tab-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-tab-002-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-tab-003-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-tab-004-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-trailing-ws-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-trailing-ws-002-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-ws-fixup-001-expected.txt
LayoutTests/platform/mac/editing/deleting/delete-ws-fixup-002-expected.txt
LayoutTests/platform/mac/editing/deleting/forward-delete-expected.txt
LayoutTests/platform/mac/editing/deleting/non-smart-delete-expected.txt
LayoutTests/platform/mac/editing/deleting/smart-delete-001-expected.txt
LayoutTests/platform/mac/editing/deleting/smart-delete-002-expected.txt
LayoutTests/platform/mac/editing/deleting/smart-delete-003-expected.txt
LayoutTests/platform/mac/editing/deleting/smart-delete-004-expected.txt
LayoutTests/platform/mac/editing/execCommand/insertHorizontalRule-expected.txt
LayoutTests/platform/mac/editing/input/firstrectforcharacterrange-styled-expected.txt
LayoutTests/platform/mac/editing/input/text-input-controller-expected.txt
LayoutTests/platform/mac/editing/inserting/4278698-expected.txt
LayoutTests/platform/mac/editing/inserting/editing-empty-divs-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-3654864-fix-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-after-delete-001-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-003-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-006-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-007-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-008-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-009-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-at-tabspan-002-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-br-at-tabspan-003-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-div-003-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-div-006-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-div-008-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-div-024-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-space-in-empty-doc-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-tab-003-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-text-at-tabspan-001-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-text-at-tabspan-002-expected.txt
LayoutTests/platform/mac/editing/inserting/insert-text-with-newlines-expected.txt
LayoutTests/platform/mac/editing/inserting/typing-001-expected.txt
LayoutTests/platform/mac/editing/inserting/typing-002-expected.txt
LayoutTests/platform/mac/editing/inserting/typing-003-expected.txt
LayoutTests/platform/mac/editing/inserting/typing-around-br-001-expected.txt
LayoutTests/platform/mac/editing/inserting/typing-around-image-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/4076267-2-expected.txt
LayoutTests/platform/mac/editing/pasteboard/4076267-3-expected.txt
LayoutTests/platform/mac/editing/pasteboard/bad-placeholder-expected.txt
LayoutTests/platform/mac/editing/pasteboard/cut-text-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/emacs-ctrl-a-k-y-expected.txt
LayoutTests/platform/mac/editing/pasteboard/emacs-ctrl-k-y-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/interchange-newline-1-expected.txt
LayoutTests/platform/mac/editing/pasteboard/merge-end-1-expected.txt
LayoutTests/platform/mac/editing/pasteboard/merge-end-2-expected.txt
LayoutTests/platform/mac/editing/pasteboard/merge-end-4-expected.txt
LayoutTests/platform/mac/editing/pasteboard/merge-end-list-expected.txt
LayoutTests/platform/mac/editing/pasteboard/merge-end-table-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-match-style-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-019-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-at-tabspan-001-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-at-tabspan-002-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-text-at-tabspan-003-expected.txt
LayoutTests/platform/mac/editing/pasteboard/paste-xml-expected.txt
LayoutTests/platform/mac/editing/pasteboard/pasting-object-expected.txt
LayoutTests/platform/mac/editing/pasteboard/smart-paste-002-expected.txt
LayoutTests/platform/mac/editing/pasteboard/smart-paste-006-expected.txt
LayoutTests/platform/mac/editing/pasteboard/smart-paste-007-expected.txt
LayoutTests/platform/mac/editing/pasteboard/subframe-dragndrop-1-expected.txt
LayoutTests/platform/mac/editing/spelling/spelling-expected.txt
LayoutTests/platform/mac/editing/style/style-3681552-fix-001-expected.txt
LayoutTests/platform/mac/editing/style/style-3681552-fix-002-expected.txt
LayoutTests/platform/mac/editing/style/style-boundary-002-expected.txt
LayoutTests/platform/mac/editing/style/style-boundary-005-expected.txt
LayoutTests/platform/mac/editing/style/typing-style-001-expected.txt
LayoutTests/platform/mac/editing/style/typing-style-002-expected.txt
LayoutTests/platform/mac/editing/style/unbold-in-bold-expected.txt
LayoutTests/platform/mac/editing/undo/4063751-expected.txt
LayoutTests/platform/mac/editing/undo/redo-typing-001-expected.txt
LayoutTests/platform/mac/editing/undo/undo-combined-delete-boundary-expected.txt
LayoutTests/platform/mac/editing/undo/undo-combined-delete-expected.txt
LayoutTests/platform/mac/editing/undo/undo-delete-boundary-expected.txt
LayoutTests/platform/mac/editing/undo/undo-delete-expected.txt
LayoutTests/platform/mac/editing/undo/undo-forward-delete-boundary-expected.txt
LayoutTests/platform/mac/editing/undo/undo-forward-delete-expected.txt
LayoutTests/platform/mac/editing/undo/undo-misspellings-expected.txt
LayoutTests/platform/mac/editing/undo/undo-typing-001-expected.txt
LayoutTests/platform/mac/editing/unsupported-content/list-type-after-expected.txt
LayoutTests/platform/mac/editing/unsupported-content/list-type-before-expected.txt
LayoutTests/platform/mac/editing/unsupported-content/table-type-after-expected.txt
LayoutTests/platform/mac/editing/unsupported-content/table-type-before-expected.txt
WebCore/ChangeLog
WebCore/dom/CharacterData.cpp
WebCore/dom/CharacterData.h
WebCore/editing/SelectionController.cpp
WebCore/editing/SelectionController.h