Bug 74921 - [EFL] Add new commands for Ewk_Editor_Command.
Summary: [EFL] Add new commands for Ewk_Editor_Command.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit EFL (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 85046
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-20 04:43 PST by Michal Pakula vel Rutka
Modified: 2012-05-16 02:16 PDT (History)
7 users (show)

See Also:


Attachments
proposed patch (8.83 KB, patch)
2011-12-20 04:45 PST, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff
move implementation to new files (14.87 KB, patch)
2012-01-12 04:47 PST, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff
changelog and style fixes (14.95 KB, patch)
2012-01-12 06:48 PST, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff
rebased patch (15.83 KB, patch)
2012-04-23 05:37 PDT, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff
move back implementation to ewk_view (13.28 KB, patch)
2012-04-26 08:16 PDT, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff
new patch using OwnPtr (12.67 KB, patch)
2012-04-27 03:58 PDT, Michal Pakula vel Rutka
gyuyoung.kim: commit-queue-
Details | Formatted Diff | Diff
rebased patch (12.60 KB, patch)
2012-05-10 07:34 PDT, Michal Pakula vel Rutka
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Pakula vel Rutka 2011-12-20 04:43:52 PST
This extends Ewk_Editor_Command with new commands. Also a table of editor command strings was introduced. Numerous calls of _ewk_view_editor_command for each case in ewk_view_execute_editor_command were replaced by one call of functions obtaining a command string from a table for given Ewk_Editor_Command value.
Comment 1 Michal Pakula vel Rutka 2011-12-20 04:45:23 PST
Created attachment 120009 [details]
proposed patch
Comment 2 Grzegorz Czajkowski 2012-01-03 06:02:45 PST
Mostly LGTM.

> Source/WebKit/efl/ewk/ewk_view.cpp:1480
> +            && (command < static_cast<int>(sizeof(_ewk_view_editor_commands) / sizeof(const char*))))

This line has wrong indent.
Comment 3 Gyuyoung Kim 2012-01-03 16:37:12 PST
Comment on attachment 120009 [details]
proposed patch

I think editor command can be implemented by new file. For example, ewk_editor.cpp or ewk_editor_command.cpp and so on. As you know, there are many features and functions in ewk_view.cpp. How do you think about my suggestion?
Comment 4 Michal Pakula vel Rutka 2012-01-04 03:57:36 PST
I am OK with this, but into this new file I can put only the ewk_view_editor_command* functions there for now. I will prepare a new patch soon.
Comment 5 Raphael Kubo da Costa (:rakuco) 2012-01-10 19:26:58 PST
Comment on attachment 120009 [details]
proposed patch

Clearing r? flag while the patch is being reworked.
Comment 6 Michal Pakula vel Rutka 2012-01-12 04:47:52 PST
Created attachment 122215 [details]
move implementation to new files
Comment 7 Michal Pakula vel Rutka 2012-01-12 06:48:33 PST
Created attachment 122231 [details]
changelog and style fixes
Comment 8 Michal Pakula vel Rutka 2012-04-23 05:37:03 PDT
Created attachment 138327 [details]
rebased patch

previous patch become obsolete as CMakelistEfl was removed and PlatformEfl.cmake was added
Comment 9 Grzegorz Czajkowski 2012-04-25 02:05:22 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=138327&action=review

> Source/WebKit/ChangeLog:8
> +        This extends Ewk_Editor_Command with new commands and moving it to new ewk_editor files.

Please mention what exactly is changed here. I think description: "Added ewk_editor.cpp and ewk_editor.h files" is sufficient.

> Source/WebKit/PlatformEfl.cmake:100
> +    efl/ewk/ewk_editor.cpp

Please keep alphabetical order.
Comment 10 Grzegorz Czajkowski 2012-04-25 02:12:06 PDT
(In reply to comment #3)
> (From update of attachment 120009 [details])
> I think editor command can be implemented by new file. For example, ewk_editor.cpp or ewk_editor_command.cpp and so on. As you know, there are many features and functions in ewk_view.cpp. How do you think about my suggestion?

I think it's good idea to split out this feature to new files. What about name ewk_view_editor(h/cpp) ?
Comment 11 Raphael Kubo da Costa (:rakuco) 2012-04-25 08:05:41 PDT
Comment on attachment 138327 [details]
rebased patch

I think separating the enum definition from the _ewk_editor_commands array is error prone; one might inadvertently make the two data structures out of sync and cause havoc. How about doing the following in ewk_editor.cpp (this is similar to what exists in EditorClientQt.cpp):

  struct EditorCommand {
      Ewk_Editor_Command ewkCommand;
      const char editorCommand;
  };

  static const EditorCommand editorCommands[] = {
      { EWK_EDITOR_COMMAND_INSERT_IMAGE, "InsertImage" },
      { EWK_EDITOR_COMMAND_INSERT_TEXT, "InsertText" },
      // ...
  };

  static const char* _ewk_editor_command_get(Ewk_Editor_Command command)
  {
      static Eina_Hash* commandHash = 0;

      if (!commandHash) {
          // Initialize the hash map with Ewk_Editor_Command as key and
          // a const char* as value.
      }

      return static_cast<const char*>(eina_hash_find(...));
  }

  Eina_Bool ewk_editor_command_execute(...)
  {
      // ...
  }
Comment 12 Raphael Kubo da Costa (:rakuco) 2012-04-25 08:08:02 PDT
As for the splitting being proposed, I still find it weird to call an ewk_view function without the ewk_view prefix as is the case with ewk_editor_command_execute. You're expected to pass a sort of "self" or "this" as the first parameter and the function name should match it.
Comment 13 Michal Pakula vel Rutka 2012-04-25 08:23:35 PDT
(In reply to comment #12)
> As for the splitting being proposed, I still find it weird to call an ewk_view function without the ewk_view prefix as is the case with ewk_editor_command_execute. You're expected to pass a sort of "self" or "this" as the first parameter and the function name should match it.

In case of a file name proposed by Grzegorz: ewk_view_editor.h/cpp, the function name will be changed to ewk_view_editor. Will it be good for you to use ewkView then? Still it won't be 'self' or 'this', but at least names will match.
Comment 14 Raphael Kubo da Costa (:rakuco) 2012-04-25 08:36:21 PDT
(In reply to comment #13)
> In case of a file name proposed by Grzegorz: ewk_view_editor.h/cpp, the function name will be changed to ewk_view_editor. Will it be good for you to use ewkView then? Still it won't be 'self' or 'this', but at least names will match.

It sounds better; personally, I still don't see much reason not to just put these things into ewk_view.cpp itself, but if you guys prefer to split, ewk_view_editor is better than ewk_editor.
Comment 15 Michal Pakula vel Rutka 2012-04-25 08:49:57 PDT
(In reply to comment #11)
> (From update of attachment 138327 [details])
> I think separating the enum definition from the _ewk_editor_commands array is error prone; one might inadvertently make the two data structures out of sync and cause havoc. How about doing the following in ewk_editor.cpp (this is similar to what exists in EditorClientQt.cpp):
> 
>   struct EditorCommand {
>       Ewk_Editor_Command ewkCommand;
>       const char editorCommand;
>   };
> 
>   static const EditorCommand editorCommands[] = {
>       { EWK_EDITOR_COMMAND_INSERT_IMAGE, "InsertImage" },
>       { EWK_EDITOR_COMMAND_INSERT_TEXT, "InsertText" },
>       // ...
>   };
> 
>   static const char* _ewk_editor_command_get(Ewk_Editor_Command command)
>   {
>       static Eina_Hash* commandHash = 0;
> 
>       if (!commandHash) {
>           // Initialize the hash map with Ewk_Editor_Command as key and
>           // a const char* as value.
>       }
> 
>       return static_cast<const char*>(eina_hash_find(...));
>   }
> 
>   Eina_Bool ewk_editor_command_execute(...)
>   {
>       // ...
>   }

Good idea, I will apply it as soon as naming discussion will be over.
Comment 16 Tomasz Morawski 2012-04-26 00:20:10 PDT
(In reply to comment #14)
> (In reply to comment #13)
> > In case of a file name proposed by Grzegorz: ewk_view_editor.h/cpp, the function name will be changed to ewk_view_editor. Will it be good for you to use ewkView then? Still it won't be 'self' or 'this', but at least names will match.
> 
> It sounds better; personally, I still don't see much reason not to just put these things into ewk_view.cpp itself, but if you guys prefer to split, ewk_view_editor is better than ewk_editor.
I agree with you. I think it should be put into ewk_view.cpp.
Comment 17 Grzegorz Czajkowski 2012-04-26 00:28:18 PDT
(In reply to comment #16)
> (In reply to comment #14)
> > (In reply to comment #13)
> > > In case of a file name proposed by Grzegorz: ewk_view_editor.h/cpp, the function name will be changed to ewk_view_editor. Will it be good for you to use ewkView then? Still it won't be 'self' or 'this', but at least names will match.
> > 
> > It sounds better; personally, I still don't see much reason not to just put these things into ewk_view.cpp itself, but if you guys prefer to split, ewk_view_editor is better than ewk_editor.
> I agree with you. I think it should be put into ewk_view.cpp.

Ok, those arguments are convincing to keep thie feature into ewk_view files. Thanks for your opinions.
Comment 18 Michal Pakula vel Rutka 2012-04-26 08:16:05 PDT
Created attachment 139008 [details]
move back implementation to ewk_view

Implementation is moved back to ewk_view and a hash table proposed by Raphael was added.
Comment 19 Raphael Kubo da Costa (:rakuco) 2012-04-26 18:30:04 PDT
Comment on attachment 139008 [details]
move back implementation to ewk_view

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

> Source/WebKit/efl/ewk/ewk_view.cpp:321
> +    Eina_Hash* editorCommandHash;

I didn't understand why this was added to the private data instead of being a static variable inside _ewk_view_editor_command_string_get -- every time a new view is created a new hash will be created with the exact same data.

> Source/WebKit/efl/ewk/ewk_view.cpp:1219
> +            eina_hash_add(priv->editorCommandHash, &editorCommands[i].ewkEditorCommand,
> +                    editorCommands[i].editorCommandString);

We usually don't wrap at 80 characters, so these lines can be merged.
Comment 20 Raphael Kubo da Costa (:rakuco) 2012-04-26 18:37:20 PDT
One other thing I'd like to ask is whether other ports implement something similar, and if they don't, if they achieve the functionality implemented here in another way.

I started wondering about this after taking a look at bug 82286 -- it's rather unfortunate that we can't exercise the function being changed here in DumpRenderTree.
Comment 21 Michal Pakula vel Rutka 2012-04-27 03:29:25 PDT
Comment on attachment 139008 [details]
move back implementation to ewk_view

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

>> Source/WebKit/efl/ewk/ewk_view.cpp:321
>> +    Eina_Hash* editorCommandHash;
> 
> I didn't understand why this was added to the private data instead of being a static variable inside _ewk_view_editor_command_string_get -- every time a new view is created a new hash will be created with the exact same data.

I had difficulties with calling eina_hash_free on static Eina_Hash inside function. I will move the hash table back to function and replace it with OwnPtr<Eina_Hash>.

>> Source/WebKit/efl/ewk/ewk_view.cpp:1219
>> +                    editorCommands[i].editorCommandString);
> 
> We usually don't wrap at 80 characters, so these lines can be merged.

Done
Comment 22 Michal Pakula vel Rutka 2012-04-27 03:58:15 PDT
Created attachment 139166 [details]
new patch using OwnPtr

A new patch moving hash table back inside static function using OwnPtr approach for freeing Eina_Hash.
Comment 23 Michal Pakula vel Rutka 2012-04-27 07:14:07 PDT
(In reply to comment #20)
> One other thing I'd like to ask is whether other ports implement something similar, and if they don't, if they achieve the functionality implemented here in another way.
> 
> I started wondering about this after taking a look at bug 82286 -- it's rather unfortunate that we can't exercise the function being changed here in DumpRenderTree.

The most similar can be found in QT: QWebPage::triggerAction, where we can call some editing actions from API using enum. I am not 100% sure but I think there are some API function using commands as strings in Chromium (WebFrameImpl::executeCommand) and Windows (WebView::executeCoreCommandByName). All ports mentioned above are using the methods in DumpRendererTree.
Comment 24 Gyuyoung Kim 2012-05-01 01:18:41 PDT
Comment on attachment 139166 [details]
new patch using OwnPtr

Attachment 139166 [details] did not pass efl-ews (efl):
Output: http://queues.webkit.org/results/12592488
Comment 25 Raphael Kubo da Costa (:rakuco) 2012-05-02 20:16:19 PDT
(In reply to comment #21)
> (From update of attachment 139008 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=139008&action=review
> 
> >> Source/WebKit/efl/ewk/ewk_view.cpp:321
> >> +    Eina_Hash* editorCommandHash;
> > 
> > I didn't understand why this was added to the private data instead of being a static variable inside _ewk_view_editor_command_string_get -- every time a new view is created a new hash will be created with the exact same data.
> 
> I had difficulties with calling eina_hash_free on static Eina_Hash inside function. I will move the hash table back to function and replace it with OwnPtr<Eina_Hash>.

Note that this approach "leaks" as much as using a static raw pointer -- even if you do call the OwnPtr destructor, it will be done at the program shutdown anyway. I guess that's why this idiom is not found elsewhere in the code base, by the way.
Comment 26 Michal Pakula vel Rutka 2012-05-07 04:24:31 PDT
(In reply to comment #25)
> (In reply to comment #21)
> > (From update of attachment 139008 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=139008&action=review
> > 
> > >> Source/WebKit/efl/ewk/ewk_view.cpp:321
> > >> +    Eina_Hash* editorCommandHash;
> > > 
> > > I didn't understand why this was added to the private data instead of being a static variable inside _ewk_view_editor_command_string_get -- every time a new view is created a new hash will be created with the exact same data.
> > 
> > I had difficulties with calling eina_hash_free on static Eina_Hash inside function. I will move the hash table back to function and replace it with OwnPtr<Eina_Hash>.
> 
> Note that this approach "leaks" as much as using a static raw pointer -- even if you do call the OwnPtr destructor, it will be done at the program shutdown anyway. I guess that's why this idiom is not found elsewhere in the code base, by the way.

I just thought that it will be better to clean up after myself by calling eina_hash_free explicitly than leaving it unfreed as we destroy the application.
Comment 27 Raphael Kubo da Costa (:rakuco) 2012-05-07 08:14:41 PDT
(In reply to comment #26)
> > Note that this approach "leaks" as much as using a static raw pointer -- even if you do call the OwnPtr destructor, it will be done at the program shutdown anyway. I guess that's why this idiom is not found elsewhere in the code base, by the way.
> 
> I just thought that it will be better to clean up after myself by calling eina_hash_free explicitly than leaving it unfreed as we destroy the application.

In practice this will make no difference, and WebKit itself already does that in many other places, including WebCore. The patch size could be reduced a bit if you just leak the raw pointer, and you wouldn't need to depend on the Eina_Hash OwnPtr bug to land this.
Comment 28 Raphael Kubo da Costa (:rakuco) 2012-05-10 07:05:21 PDT
Please resend the patch now that bug 85046 has landed so we can check if it passes the EFL EWS.
Comment 29 Michal Pakula vel Rutka 2012-05-10 07:34:54 PDT
Created attachment 141167 [details]
rebased patch

rebase patch after https://bugs.webkit.org/attachment.cgi?bugid=85046 has landed
Comment 30 Raphael Kubo da Costa (:rakuco) 2012-05-15 08:47:50 PDT
LGTM now.
Comment 31 Hajime Morrita 2012-05-16 02:03:45 PDT
Comment on attachment 141167 [details]
rebased patch

rubberstamping.
Comment 32 WebKit Review Bot 2012-05-16 02:16:12 PDT
Comment on attachment 141167 [details]
rebased patch

Clearing flags on attachment: 141167

Committed r117239: <http://trac.webkit.org/changeset/117239>
Comment 33 WebKit Review Bot 2012-05-16 02:16:18 PDT
All reviewed patches have been landed.  Closing bug.