Inserting an image, selecting, underlining, and then deleting leaves the typing style...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2017 23:26:55 +0000 (23:26 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2017 23:26:55 +0000 (23:26 +0000)
commit746461ec7c7c4165ae9d3aec01b97903325346e1
tree07d8a625d6cb61b9f98c071252e3c765e64cde2c
parent2fc542d8b7a4f8bf55433a75a4b3208a0867ce45
Inserting an image, selecting, underlining, and then deleting leaves the typing style with both "-webkit-text-decorations-in-effect" and "text-decoration"
https://bugs.webkit.org/show_bug.cgi?id=179431

Reviewed by Ryosuke Niwa.

Source/WebCore:

When inserting an image element, selecting it, underlining the selection, deleting, and then inserting text, we
crash on a debug assert. This codepath was exercised by an API test added in <https://trac.webkit.org/r224512>.
This assertion happens due to the following sequence of events:
1. DeleteSelectionCommand::saveTypingStyleState computes a typing style.
2. In doing so, it calls into EditingStyle::init, which observes that "-webkit-text-decorations-in-effect" is
   present and appends "text-decoration" with an identical CSS value to the EditingStyle's mutable style
   properties.
3. DeleteSelectionCommand::calculateTypingStyleAfterDelete sets the current selection's typing style to the
   above typing style.
4. Later on, when we try to insert text, we compute the StyleChange using the above typing style, which calls
   into reconcileTextDecorationProperties.
5. reconcileTextDecorationProperties debug asserts that "-webkit-text-decorations-in-effect" and
   "text-decoration" don't coexist on the EditingStyle's (i.e. the typing style's) mutable properties; since (2)
   added both properties, this assertion fires.

It appears that step (2) shouldn't be adding "text-decoration" in addition to EditingStyle's mutable style
properties, since doing so would violate the requirements of reconcileTextDecorationProperties. As such, we can
tweak EditingStyle::init to *replace* the "-webkit-text-decorations-in-effect" property with "text-decoration"
instead; this matches the behavior of reconcileTextDecorationProperties, and ensures that we only have the
"text-decorations" property when we try to insert text in step (4).

Test: editing/execCommand/underline-selection-containing-image.html

* editing/EditingStyle.cpp:
(WebCore::EditingStyle::init):

LayoutTests:

Adds a new layout test to fix a debug assertion. See WebCore/ChangeLog for more details. Additionally
rebaselines a few existing tests that serialize markup strings to include `text-decoration: none;`.

* editing/execCommand/underline-selection-containing-image-expected.txt: Added.
* editing/execCommand/underline-selection-containing-image.html: Added.
* editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt:
* fast/events/before-input-events-prevent-drag-and-drop-expected.txt:
* fast/events/input-events-paste-rich-datatransfer-expected.txt:
* fast/events/ondrop-text-html-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224649 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/underline-selection-containing-image-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/underline-selection-containing-image.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt
LayoutTests/fast/events/before-input-events-prevent-drag-and-drop-expected.txt
LayoutTests/fast/events/input-events-paste-rich-datatransfer-expected.txt
LayoutTests/fast/events/ondrop-text-html-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/EditingStyle.cpp