WebKit can erroneously strip font-size CSS property from font element with size attribute
authorRyosuke Niwa <rniwa@webkit.org>
Sat, 23 Feb 2013 01:54:30 +0000 (01:54 +0000)
committerRyosuke Niwa <rniwa@webkit.org>
Sat, 23 Feb 2013 01:54:30 +0000 (01:54 +0000)
commit04d0c9f93e60603bb33b27049976d616868de743
treeebe6467d375e54580c3a3537a3c3ff1bcfde27b5
parent86a5d8f019f30635b3c7c1510fb88137e032245a
WebKit can erroneously strip font-size CSS property from font element with size attribute
https://bugs.webkit.org/show_bug.cgi?id=110657

Reviewed by Justin Garcia.

Source/WebCore:

The bug was caused by ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline
erroneously removing style attributes even on an element such as font that implicitly adds
editing style.

Fixed the bug by removing these elements or attributes when they conflict with the inline
style of the element. This is always safe because implicit style of an element is always
overridden by that of inline style.

Note that when the font element becomes "empty" (i.e. doesn't have any attributes), then
we also want to delete this font element as it doesn't contribute anything to the style.

Test: editing/pasteboard/insert-u-with-text-decoration-none.html
      editing/pasteboard/insert-font-with-size-and-css.html

* editing/ApplyStyleCommand.cpp:
(WebCore::isEmptyFontTag): Added ShouldStyleAttributeBeEmpty as an argument. This will
allow removeRedundantStylesAndKeepStyleSpanInline to ignore style attribute when we know
the attribute can be removed.

* editing/ApplyStyleCommand.h: Expose isEmptyFontTag and ShouldStyleAttributeBeEmpty.

* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::InsertedNodes::didReplaceNode): Added.
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline): See above.
* editing/ReplaceSelectionCommand.h:
(InsertedNodes): Added a declaration of didReplaceNode.

LayoutTests:

Added two regression tests to ensure WebKit doesn't erroneously remove inline styles of an element
when its implicit styles differ from the inline styles. Also rebaselined some tests as their results
have progressed.

* editing/pasteboard/insert-u-with-text-decoration-none-expected.txt: Added.
* editing/pasteboard/insert-u-with-text-decoration-none.html: Added.
* editing/pasteboard/insert-font-with-size-and-css-expected.txt: Added.
* editing/pasteboard/insert-font-with-size-and-css.html: Added.
* editing/pasteboard/4744008-expected.txt:
* editing/pasteboard/paste-text-with-style-5-expected.txt:
* editing/pasteboard/paste-text-with-style-5.html:
* editing/pasteboard/style-from-rules-expected.txt:
* editing/pasteboard/style-from-rules.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@143821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/4744008-expected.txt
LayoutTests/editing/pasteboard/insert-font-with-size-and-css-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/insert-font-with-size-and-css.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/insert-u-with-text-decoration-none-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/insert-u-with-text-decoration-none.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-text-with-style-5-expected.txt
LayoutTests/editing/pasteboard/paste-text-with-style-5.html
LayoutTests/editing/pasteboard/style-from-rules-expected.txt
LayoutTests/editing/pasteboard/style-from-rules.html
Source/WebCore/ChangeLog
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/ApplyStyleCommand.h
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.h