Bug 74249

Summary: Push more member functions from EditCommand to CompositeEditCommand
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: HTML EditingAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: cshu, darin, enrica, morrita, ojan, tkent, tonikitoo, tony
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 64414, 74337    
Bug Blocks: 74490    
Attachments:
Description Flags
work in progress
none
Cleanup + regression fix
none
Fixed per Enrica's comments
none
cleanup
none
Fixed per Enrica's comment enrica: review+

Description Ryosuke Niwa 2011-12-10 17:10:10 PST
Right now EditCommand has many member functions that are overridden by CompositeEditCommand. However, some of them only make sense on CompositeEditCommand. We should move them to CompositeEditCommand since CompositeEditCommand now exists only at the time of initial application of the command.

Also, it doesn't make much sense for EditCommandComposition to share the same super class (EditCommand) with SimpleEditCommand and CompositeEditCommand.
Comment 1 Ryosuke Niwa 2011-12-10 17:39:07 PST
Created attachment 118700 [details]
work in progress
Comment 2 Ryosuke Niwa 2011-12-12 00:41:03 PST
Created attachment 118747 [details]
Cleanup + regression fix
Comment 3 Enrica Casucci 2011-12-12 10:33:02 PST
Comment on attachment 118747 [details]
Cleanup + regression fix

View in context: https://bugs.webkit.org/attachment.cgi?id=118747&action=review

> Source/WebCore/ChangeLog:15
> +        respondToUnappliedEditing exits early even when the unapplied command was a CreteLinkCommand.

Typo CreateLinkCommand.

> Source/WebCore/editing/CompositeEditCommand.cpp:74
> +    const VisibleSelection& startingSelection, const VisibleSelection endingSelection, bool wasCreateLink)

I suggest using was CreateLinkCommand as parameter name.

> Source/WebCore/editing/CompositeEditCommand.h:42
> +    static PassRefPtr<EditCommandComposition> create(Document*, const VisibleSelection&, const VisibleSelection, bool wasCreateLink);

Ditto.

> Source/WebCore/editing/CompositeEditCommand.h:48
> +    bool wasCreateLinkCommand() { return m_wasCreateLink; }

Again I would prefer m_wasCreateLinkCommand. It just feels more understandable.

> Source/WebCore/editing/CompositeEditCommand.h:55
> +    EditCommandComposition(Document* document, const VisibleSelection& startingSelection, const VisibleSelection& endingSelection, bool wasCreateLink)

Ditto.

> Source/WebCore/editing/CompositeEditCommand.h:62
> +    bool m_wasCreateLink;

Ditto.

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:2246
> +    frame->editor()->replaceSelectionWithText(text, selectReplacement, smartReplace);

I'm not sure this code is equivalent. The PreventNesting option seems to be lost.

> Source/WebKit/chromium/src/WebFrameImpl.cpp:1129
> +    frame()->editor()->replaceSelectionWithText(text, selectReplace, smartReplace);

Ditto.

> Source/WebKit/gtk/webkit/webkitwebframe.cpp:1001
> +    coreFrame->editor()->replaceSelectionWithText(text, selectReplacement, smartReplace);

Ditto.

> Source/WebKit/mac/WebView/WebFrame.mm:1049
> +    _private->coreFrame->editor()->replaceSelectionWithFragment(core(fragment), selectReplacement, smartReplace, matchStyle);

Ditto.
Comment 4 Enrica Casucci 2011-12-12 10:35:48 PST
The patch shows build errors on mac.
It would be better to add layout tests for the fix relative to the spellchecker regression. If you want to write the test I could run it and validate it for you, if you want.
Comment 5 Ryosuke Niwa 2011-12-12 10:40:08 PST
(In reply to comment #3)
> (From update of attachment 118747 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=118747&action=review
> 
> > Source/WebCore/ChangeLog:15
> > +        respondToUnappliedEditing exits early even when the unapplied command was a CreteLinkCommand.
> 
> Typo CreateLinkCommand.

Will fix.

> > Source/WebCore/editing/CompositeEditCommand.cpp:74
> > +    const VisibleSelection& startingSelection, const VisibleSelection endingSelection, bool wasCreateLink)
> 
> I suggest using was CreateLinkCommand as parameter name.

Sure, will change.

> > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:2246
> > +    frame->editor()->replaceSelectionWithText(text, selectReplacement, smartReplace);
> 
> I'm not sure this code is equivalent. The PreventNesting option seems to be lost.

PreventNesting is always set in Editor::replaceSelectionWithFragment.
Comment 6 Ryosuke Niwa 2011-12-12 10:52:48 PST
Created attachment 118817 [details]
Fixed per Enrica's comments
Comment 7 Ryosuke Niwa 2011-12-12 13:14:05 PST
Comment on attachment 118817 [details]
Fixed per Enrica's comments

Let me split this patch into 3 pieces:
1a - Remove dependency on ApplyCommand in WebKit
1b - Fix a regression in SpellingCorrectionController
2 - Push member functions from EditCommand to CompositeEditCommand.
Comment 8 Enrica Casucci 2011-12-12 13:17:37 PST
(In reply to comment #7)
> (From update of attachment 118817 [details])
> Let me split this patch into 3 pieces:
> 1a - Remove dependency on ApplyCommand in WebKit
> 1b - Fix a regression in SpellingCorrectionController
> 2 - Push member functions from EditCommand to CompositeEditCommand.

Sounds like a good plan to me.
Comment 9 Ryosuke Niwa 2011-12-14 00:41:28 PST
Created attachment 119173 [details]
cleanup
Comment 10 Enrica Casucci 2011-12-14 09:40:38 PST
Comment on attachment 119173 [details]
cleanup

View in context: https://bugs.webkit.org/attachment.cgi?id=119173&action=review

The changes look good, but there is a build failure. Please fix that.

> Source/WebCore/editing/Editor.cpp:871
> +    EditCommandComposition* composition = cmd->composition();

Nit. I would ASSERT composition directly.
Comment 11 Ryosuke Niwa 2011-12-14 13:12:39 PST
Created attachment 119282 [details]
Fixed per Enrica's comment
Comment 12 Enrica Casucci 2011-12-14 13:30:22 PST
Comment on attachment 119282 [details]
Fixed per Enrica's comment

Thanks!
Comment 13 Ryosuke Niwa 2011-12-14 13:31:10 PST
Great. Thanks for the review.
Comment 14 Ryosuke Niwa 2011-12-14 15:16:13 PST
Committed r102833: <http://trac.webkit.org/changeset/102833>