Bug 129867 - Cut and copy functions should be refactored as suggested in FIXME line
Summary: Cut and copy functions should be refactored as suggested in FIXME line
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Enhancement
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-07 00:40 PST by Lukasz Bialek
Modified: 2014-03-28 19:27 PDT (History)
2 users (show)

See Also:


Attachments
Patch (7.14 KB, patch)
2014-03-07 00:47 PST, Lukasz Bialek
no flags Details | Formatted Diff | Diff
There was small error in first version. Fixed. (7.13 KB, patch)
2014-03-07 02:11 PST, Lukasz Bialek
no flags Details | Formatted Diff | Diff
Patch (5.49 KB, patch)
2014-03-07 03:28 PST, Lukasz Bialek
darin: review-
Details | Formatted Diff | Diff
Patch (4.96 KB, patch)
2014-03-28 02:57 PDT, Lukasz Bialek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lukasz Bialek 2014-03-07 00:40:29 PST
Most of code in Cut and Copy functions in Editor.cpp is identical (or analogical). There is a FIXME line suggesting to refactor this part of the code to start sharing code.
Comment 1 Lukasz Bialek 2014-03-07 00:47:20 PST
Created attachment 226093 [details]
Patch
Comment 2 Lukasz Bialek 2014-03-07 02:11:18 PST
Created attachment 226100 [details]
There was small error in first version. Fixed.
Comment 3 Lukasz Bialek 2014-03-07 03:28:56 PST
Created attachment 226109 [details]
Patch

copy() and cut() functions have to be kept (calling newly refactored function) to avoid changing function names in all ports (which is not a good idea...)
Comment 4 Darin Adler 2014-03-15 17:38:14 PDT
Comment on attachment 226109 [details]
Patch

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

This patch looks OK, but I don’t want to say review+ because I don’t want to add a new enum and a new public function to Editor just to restructure the code internals. I’m going to say review-, but please don’t let that discourage you!

> Source/WebCore/editing/Editor.cpp:1298
> +    bool isDoneByDHTML = (action == CutAction) ? tryDHTMLCut() : tryDHTMLCopy();
> +    if (isDoneByDHTML)
>          return; // DHTML did the whole operation
> -    if (!canCut()) {
> +
> +    bool canPerformAction = (action == CutAction) ? canCut() : canCopy();
> +    if (!canPerformAction) {
>          systemBeep();
>          return;
>      }

Not sure that putting this part of the function into shared code is worthwhile. I think cut and copy should just do these and then they could share a helper that does the rest.

> Source/WebCore/editing/Editor.h:90
> +enum EditorActionSpecifier { CutAction, CopyAction };

This enum should be private to the Editor class rather than at the top level. The other enums are at the namespace level for convenient use outside the class, but this one does not need to be used outside the class.

> Source/WebCore/editing/Editor.h:130
> +    void performCutOrCopy(EditorActionSpecifier);

This function should be private.
Comment 5 Lukasz Bialek 2014-03-28 02:57:48 PDT
Created attachment 228033 [details]
Patch

All comments were very accurate and has been addressed.
Comment 6 Lukasz Bialek 2014-03-28 03:15:14 PDT
> I’m going to say review-, but please don’t let that discourage you!

It's not so easy to discourage me :) Especially when comments are good and accurate. Fixed and ready for next review.
Comment 7 WebKit Commit Bot 2014-03-28 19:27:19 PDT
Comment on attachment 228033 [details]
Patch

Clearing flags on attachment: 228033

Committed r166445: <http://trac.webkit.org/changeset/166445>
Comment 8 WebKit Commit Bot 2014-03-28 19:27:21 PDT
All reviewed patches have been landed.  Closing bug.