RESOLVED FIXED Bug 65833
Remove redundant inline styles from the pasted contents more aggressively
https://bugs.webkit.org/show_bug.cgi?id=65833
Summary Remove redundant inline styles from the pasted contents more aggressively
Ryosuke Niwa
Reported 2011-08-07 15:54:45 PDT
This is the first half of my patch for the bug 34564. This patch will improve the code in ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline to more aggressively remove redundant style spans and reduce their attributes.
Attachments
fixes the bug (17.21 KB, patch)
2011-08-07 16:09 PDT, Ryosuke Niwa
no flags
Rebaselined 2 more tests (18.79 KB, patch)
2011-08-07 19:17 PDT, Ryosuke Niwa
no flags
rebaselined 4 more tests (23.52 KB, patch)
2011-08-07 21:34 PDT, Ryosuke Niwa
no flags
Updated per review (23.51 KB, patch)
2011-08-08 12:02 PDT, Ryosuke Niwa
tony: review+
Ryosuke Niwa
Comment 1 2011-08-07 16:09:55 PDT
Created attachment 103188 [details] fixes the bug
Ryosuke Niwa
Comment 2 2011-08-07 17:20:35 PDT
Comment on attachment 103188 [details] fixes the bug Oops, it appears that I've messed up a boolean expression.
Ryosuke Niwa
Comment 3 2011-08-07 19:17:15 PDT
Created attachment 103197 [details] Rebaselined 2 more tests
Ryosuke Niwa
Comment 4 2011-08-07 19:21:22 PDT
(In reply to comment #3) > Created an attachment (id=103197) [details] > Rebaselined 2 more tests Unfortunately, we have to rebaseline 4 more tests after bugs 65836 and 65837 are fixed.
Ryosuke Niwa
Comment 5 2011-08-07 21:34:48 PDT
Created attachment 103198 [details] rebaselined 4 more tests
Tony Chang
Comment 6 2011-08-08 11:09:43 PDT
Comment on attachment 103198 [details] rebaselined 4 more tests View in context: https://bugs.webkit.org/attachment.cgi?id=103198&action=review Looks fine, just had some questions and style nits. > Source/WebCore/editing/ApplyStyleCommand.cpp:78 > + NamedNodeMap* map = element->attributes(true); // true for read-only Nit: I have a slight preference for |bool readOnly = true;| and passing that in as a param, but the comment is fine too. > Source/WebCore/editing/ApplyStyleCommand.cpp:88 > + return matchedAttributes >= map->length(); Would == be sufficient? > Source/WebCore/editing/EditingStyle.cpp:894 > + if (!m_mutableStyle || !m_mutableStyle->length()) Nit: The !m_mutableStyle check seems to duplicated with the calling code. Maybe just move the length() check to the caller and remove the checks in removePropertiesInElementDefaultStyle()? > Source/WebCore/editing/ReplaceSelectionCommand.cpp:-482 > - // FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance Is this no longer true? > Source/WebCore/editing/ReplaceSelectionCommand.cpp:483 > + for (RefPtr<Node> node = m_firstNodeInserted.get(); node && node != pastEndNode; node = next) { We now stop on pastEndNode. Why didn't we do that before? This seems more correct; does the new test test this change? > Source/WebCore/editing/ReplaceSelectionCommand.cpp:512 > + if (node && isStyleSpan(element)) { It looks like node is always non-NULL here. If so, it seems like you can get rid of |next| and put in as the third clause of the for loop.
Ryosuke Niwa
Comment 7 2011-08-08 11:23:29 PDT
Comment on attachment 103198 [details] rebaselined 4 more tests View in context: https://bugs.webkit.org/attachment.cgi?id=103198&action=review Thanks for the review. >> Source/WebCore/editing/ApplyStyleCommand.cpp:78 >> + NamedNodeMap* map = element->attributes(true); // true for read-only > > Nit: I have a slight preference for |bool readOnly = true;| and passing that in as a param, but the comment is fine too. Okay, will do that. >> Source/WebCore/editing/ApplyStyleCommand.cpp:88 >> + return matchedAttributes >= map->length(); > > Would == be sufficient? I'll assert that matchedAttributes <= map->length() so that I can use equality here. >> Source/WebCore/editing/EditingStyle.cpp:894 >> + if (!m_mutableStyle || !m_mutableStyle->length()) > > Nit: The !m_mutableStyle check seems to duplicated with the calling code. Maybe just move the length() check to the caller and remove the checks in removePropertiesInElementDefaultStyle()? This function is to become public and used in markup.cpp so I'd like to keep these checks or at least !m_mutableStyle->length() >> Source/WebCore/editing/ReplaceSelectionCommand.cpp:-482 >> - // FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance > > Is this no longer true? Huh, I guess I should keep that comment. >> Source/WebCore/editing/ReplaceSelectionCommand.cpp:483 >> + for (RefPtr<Node> node = m_firstNodeInserted.get(); node && node != pastEndNode; node = next) { > > We now stop on pastEndNode. Why didn't we do that before? This seems more correct; does the new test test this change? We always did. See lines 506-507 below that have been removed. I'm simply moving the ending condition here. >> Source/WebCore/editing/ReplaceSelectionCommand.cpp:512 > > It looks like node is always non-NULL here. If so, it seems like you can get rid of |next| and put in as the third clause of the for loop. No, node can be detached from the document (see removeNodePreservingChildren on line 506) in which case node-> traverseNextNode() will be 0. The only reason I check node is to make sure we don't dereference stale element pointer.
Tony Chang
Comment 8 2011-08-08 11:28:19 PDT
(In reply to comment #7) > (From update of attachment 103198 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=103198&action=review > >> Source/WebCore/editing/ReplaceSelectionCommand.cpp:512 > > > > > It looks like node is always non-NULL here. If so, it seems like you can get rid of |next| and put in as the third clause of the for loop. > > No, node can be detached from the document (see removeNodePreservingChildren on line 506) in which case node-> traverseNextNode() will be 0. The only reason I check node is to make sure we don't dereference stale element pointer. I see. That explains why we have |next|, but shouldn't the node always be non-NULL even when detached? It's a refptr.
Ryosuke Niwa
Comment 9 2011-08-08 11:33:49 PDT
Comment on attachment 103198 [details] rebaselined 4 more tests View in context: https://bugs.webkit.org/attachment.cgi?id=103198&action=review >>>> Source/WebCore/editing/ReplaceSelectionCommand.cpp:512 >>>> + if (node && isStyleSpan(element)) { >>> >>> It looks like node is always non-NULL here. If so, it seems like you can get rid of |next| and put in as the third clause of the for loop. >> >> > > I see. That explains why we have |next|, but shouldn't the node always be non-NULL even when detached? It's a refptr. That's a good point actually. Will remove the check.
Ryosuke Niwa
Comment 10 2011-08-08 12:02:54 PDT
Created attachment 103272 [details] Updated per review
Ryosuke Niwa
Comment 11 2011-08-08 12:15:24 PDT
Note You need to log in before you can comment on or make changes to this bug.