Bug 57515

Summary: [WK2] [Mac] Implement KeyDown function for WebKit2 EventSender
Product: WebKit Reporter: Chang Shu <cshu>
Component: Tools / TestsAssignee: Chang Shu <cshu>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, ap, buildbot, darin, kbalazs, laszlo.gombos, lforschler, mjs, sam, webkit-ews, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.6   
Bug Depends on: 57629    
Bug Blocks: 42194, 56485, 68108    
Attachments:
Description Flags
fix patch
none
fix patch 2
none
fix patch 2
eric: review-
fix patch 3
darin: review+
patch 4 none

Description Chang Shu 2011-03-30 17:43:48 PDT
Start building framework using KeyDown event.
Comment 1 Chang Shu 2011-03-31 09:07:29 PDT
Created attachment 87740 [details]
fix patch

This patch does the following things for KeyDown event:
1. passes function calls from WebKitTestRunner::InjectedBundle to WebKit2::WebProcess::InjectedBundle through WK interface 
2. encodes it as a binary buffer attached to a general InjectedBundle message.
3. sends out the message to UIProcess
4. UIProcess passes the general InjectedBundle message to WebKitTestRunner::EventSenderProxy.
5. EventSenderProxy calls the decoding mechanism through WK interface
5. EventSenderProxy further calls the platform-dependent code to trigger the event from the UIProcess side.

Note that the platform-dependent implementation on Mac has not been done yet for my lack of experience on objC development.
Comment 2 Chang Shu 2011-03-31 09:10:13 PDT
I changed the title of the bug since my patch is 100% common code except the project files.
Comment 3 Darin Adler 2011-03-31 09:18:58 PDT
Maciej told me an approach like this won’t work due to the behavior of CoreIPC.
Comment 4 Darin Adler 2011-03-31 09:20:17 PDT
We can make it work by enhancing CoreIPC. I don’t know the details. Maybe he can fill us in.

Adding him to the cc list. In the mean time I am making a version of eventSender work entirely within the web process. We can still move to the round trip UI process version later, but this will get many tests running and testing what they intend to even though they will not test as much code as the multi-process version we eventually want.
Comment 5 Early Warning System Bot 2011-03-31 09:37:08 PDT
Attachment 87740 [details] did not build on qt:
Build output: http://queues.webkit.org/results/8315188
Comment 6 Build Bot 2011-03-31 10:00:25 PDT
Attachment 87740 [details] did not build on win:
Build output: http://queues.webkit.org/results/8297951
Comment 7 Chang Shu 2011-03-31 10:04:59 PDT
(In reply to comment #3)
> Maciej told me an approach like this won’t work due to the behavior of CoreIPC.

Hi, Darin,
I am not sure which part of the code you are referring to. With the similar patch for bug 56485, I have made it work on Qt and fixed at least one test case. It will be good the enhance CoreIPC though and the WK interface will become neater.
Comment 8 Darin Adler 2011-03-31 10:07:58 PDT
I am going to put my patches that work entirely in the web process up for review. I hope that does not make your task more difficult. I think your direction is fine. It’s Maciej and Anders that can explain the concerns. Please also fee free to replace my code with yours if mine lands and yours will work even better.
Comment 9 Chang Shu 2011-03-31 11:00:53 PDT
Created attachment 87766 [details]
fix patch 2

fix build break
Comment 10 WebKit Review Bot 2011-03-31 11:03:50 PDT
Attachment 87766 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebKit2/ChangeLog', u'Source/WebKit..." exit_code: 1

Tools/WebKitTestRunner/EventSenderProxy.h:30:  Should have a space between // and comment  [whitespace/comments] [4]
Total errors found: 1 in 30 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 11 Chang Shu 2011-03-31 11:11:23 PDT
Created attachment 87770 [details]
fix patch 2
Comment 12 Eric Seidel (no email) 2011-04-26 16:56:33 PDT
Comment on attachment 87770 [details]
fix patch 2

I'm told Maciej believes this can't work this way.  I'm sorry I don't have more infromation for you than that.
Comment 13 Chang Shu 2011-04-26 17:07:15 PDT
(In reply to comment #12)
> (From update of attachment 87770 [details])
> I'm told Maciej believes this can't work this way.  I'm sorry I don't have more infromation for you than that.

Yes, I understand. Thanks
Comment 14 Chang Shu 2011-05-24 11:11:35 PDT
I am back to this bug now. I had a concern that the synchronous message cannot hop from WebProcess to UIProcess and to WebProcess again. But after I investigated the code, it actually works.
Comment 15 Chang Shu 2011-05-25 09:05:49 PDT
Created attachment 94789 [details]
fix patch 3

This patch allows key events being sent from WTR::InjectedBundle to WTR UIProcess and then to WebKit2::WebProcess again, all synchronously.
Comment 16 Adam Roben (:aroben) 2011-08-17 08:05:56 PDT
*** Bug 62576 has been marked as a duplicate of this bug. ***
Comment 17 Darin Adler 2011-09-12 17:05:25 PDT
Comment on attachment 94789 [details]
fix patch 3

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

> Source/WebKit2/UIProcess/API/C/WKPagePrivate.h:71
> +WK_EXPORT void WKPageSetSendEventSynchronously(WKPageRef page, bool sync);

The name here is not ideal. Given what this does, normally we’d name this WKPageSetShouldSendKeyboardEventsSynchronously.

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1091
> +    // FIXME: Platform default behaviors should be performed during normal DOM event dispatch (in most cases, in default keydown event handler).

Do we really need this FIXME?

> Source/WebKit2/WebProcess/WebPage/WebPage.messages.in:36
> +    KeyEventSync(WebKit::WebKeyboardEvent event) -> (bool handled)

I think it would be best if there was some way to indicate this was intended for testing only.

> Tools/WebKitTestRunner/EventSenderProxy.h:36
> +    EventSenderProxy(TestController* testController) : m_testController(testController) { };

This semicolon is unnecessary.

> Tools/WebKitTestRunner/EventSenderProxy.h:38
> +    void keyDown(WKStringRef key, WKEventModifiers, unsigned int location, double timestamp);

It should be "unsigned", not "unsigned int".

> Tools/WebKitTestRunner/TestController.cpp:31
> +#if PLATFORM(MAC)
> +#include "EventSenderProxy.h"
> +#endif

Conditional includes should normally be separate and under unconditional includes.

> Tools/WebKitTestRunner/TestController.cpp:502
> +#if PLATFORM(MAC)

What is Mac-specific here?

> Tools/WebKitTestRunner/TestController.cpp:518
> +            unsigned int location = static_cast<unsigned int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get()))));

Should just be "unsigned" not "unsigned int".
Comment 18 Chang Shu 2011-09-12 20:45:48 PDT
Thanks a lot for the review, Darin. I'll provide a new patch to accommodate your review and rebase the code.
(In reply to comment #17)
> (From update of attachment 94789 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=94789&action=review
> 
> > Source/WebKit2/UIProcess/API/C/WKPagePrivate.h:71
> > +WK_EXPORT void WKPageSetSendEventSynchronously(WKPageRef page, bool sync);
> 
> The name here is not ideal. Given what this does, normally we’d name this WKPageSetShouldSendKeyboardEventsSynchronously.
> 
> > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1091
> > +    // FIXME: Platform default behaviors should be performed during normal DOM event dispatch (in most cases, in default keydown event handler).
> 
> Do we really need this FIXME?
> 
> > Source/WebKit2/WebProcess/WebPage/WebPage.messages.in:36
> > +    KeyEventSync(WebKit::WebKeyboardEvent event) -> (bool handled)
> 
> I think it would be best if there was some way to indicate this was intended for testing only.
> 
> > Tools/WebKitTestRunner/EventSenderProxy.h:36
> > +    EventSenderProxy(TestController* testController) : m_testController(testController) { };
> 
> This semicolon is unnecessary.
> 
> > Tools/WebKitTestRunner/EventSenderProxy.h:38
> > +    void keyDown(WKStringRef key, WKEventModifiers, unsigned int location, double timestamp);
> 
> It should be "unsigned", not "unsigned int".
> 
> > Tools/WebKitTestRunner/TestController.cpp:31
> > +#if PLATFORM(MAC)
> > +#include "EventSenderProxy.h"
> > +#endif
> 
> Conditional includes should normally be separate and under unconditional includes.
> 
> > Tools/WebKitTestRunner/TestController.cpp:502
> > +#if PLATFORM(MAC)
> 
> What is Mac-specific here?
> 
> > Tools/WebKitTestRunner/TestController.cpp:518
> > +            unsigned int location = static_cast<unsigned int>(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, locationKey.get()))));
> 
> Should just be "unsigned" not "unsigned int".
Comment 19 Balazs Kelemen 2011-09-13 05:35:12 PDT
It's strange to me that this patch is a Mac-only fix. I guess the plan is to do the platform independent part and the Mac part in one and later fix it on other platforms, is that right?
Comment 20 Chang Shu 2011-09-13 06:57:31 PDT
Exactly. I will change the title. Thanks.
(In reply to comment #19)
> It's strange to me that this patch is a Mac-only fix. I guess the plan is to do the platform independent part and the Mac part in one and later fix it on other platforms, is that right?
Comment 21 Chang Shu 2011-09-13 11:42:00 PDT
Created attachment 107203 [details]
patch 4
Comment 22 WebKit Review Bot 2011-09-13 12:25:51 PDT
Comment on attachment 107203 [details]
patch 4

Clearing flags on attachment: 107203

Committed r95039: <http://trac.webkit.org/changeset/95039>
Comment 23 WebKit Review Bot 2011-09-13 12:25:57 PDT
All reviewed patches have been landed.  Closing bug.