Bug 144663

Summary: New force-related DOM events should fire in WK1 views
Product: WebKit Reporter: Beth Dakin <bdakin>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, commit-queue, dbates, sabouhallawa, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch sam: review+

Description Beth Dakin 2015-05-05 22:25:01 PDT
NeNew force-related DOM events should fire in WK1 views

rdar://problem/20281886
Comment 1 Beth Dakin 2015-05-05 22:38:00 PDT
Created attachment 252448 [details]
Patch
Comment 2 WebKit Commit Bot 2015-05-05 22:40:03 PDT
Attachment 252448 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebImmediateActionController.mm:151:  The parameter name "element" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:53:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:78:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:109:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
Total errors found: 4 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Beth Dakin 2015-05-06 15:27:34 PDT
Created attachment 252527 [details]
Patch
Comment 4 WebKit Commit Bot 2015-05-06 15:29:30 PDT
Attachment 252527 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebImmediateActionController.mm:151:  The parameter name "element" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:53:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:78:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:109:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
Total errors found: 4 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Tim Horton 2015-05-06 15:41:47 PDT
Comment on attachment 252527 [details]
Patch

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

> Source/WebCore/page/mac/EventHandlerMac.mm:86
> +    static NeverDestroyed<RetainPtr<NSEvent>> event;

Is it really right for this to be stored between views? That seems weird.

> Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:428
> +        if ([event type] == NSEventTypePressure) {

You check this three times in this function. Maybe put it in a local?

> Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:439
> +    UNUSED_PARAM(lastPressureEvent);

Indentation is wrong I think.

> Source/WebKit/mac/WebView/WebHTMLView.mm:-3844
> -    [[[self _webView] _immediateActionController] webView:[self _webView] willHandleMouseDown:event];

Whaaaaaa?

> Source/WebKit/mac/WebView/WebViewData.h:178
> +    NSEvent *pressureEvent;

Maybe lastPressureEvent?

Could you not keep this in EventHandler instead and avoid keeping it here?
Comment 6 Beth Dakin 2015-05-06 15:55:08 PDT
(In reply to comment #5)
> Comment on attachment 252527 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=252527&action=review
> 
> > Source/WebCore/page/mac/EventHandlerMac.mm:86
> > +    static NeverDestroyed<RetainPtr<NSEvent>> event;
> 
> Is it really right for this to be stored between views? That seems weird.
> 

Hmm, maybe not. I was copying what's done for currentNSEventSlot(). I think it makes as much sense in this new case as it did in the old, but I'm a little unsure here.

> > Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:428
> > +        if ([event type] == NSEventTypePressure) {
> 
> You check this three times in this function. Maybe put it in a local?
> 

Sure, I can fix this up.

> > Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:439
> > +    UNUSED_PARAM(lastPressureEvent);
> 
> Indentation is wrong I think.
> 

Will look.

> > Source/WebKit/mac/WebView/WebHTMLView.mm:-3844
> > -    [[[self _webView] _immediateActionController] webView:[self _webView] willHandleMouseDown:event];
> 
> Whaaaaaa?
> 

This is because mouseDown used to come after the immediate action! Remember? We used to have shenanigans like this in WK2 as well, and we were able to remove them when we switched to delaysPrimaryMouseEvents:NO. This code was there purely because we were getting mouse down at a weird time.

> > Source/WebKit/mac/WebView/WebViewData.h:178
> > +    NSEvent *pressureEvent;
> 
> Maybe lastPressureEvent?
> 

Sure.

> Could you not keep this in EventHandler instead and avoid keeping it here?

Hmmmmmmm. I'll have to think this over. This is a closer mirror to what we do in WK2. If we moved it to EventHandler, we would have WK1 only member variables there, which we actually manage to avoid at this point.
Comment 7 Tim Horton 2015-05-06 15:58:25 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > Comment on attachment 252527 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=252527&action=review
> > 
> > > Source/WebCore/page/mac/EventHandlerMac.mm:86
> > > +    static NeverDestroyed<RetainPtr<NSEvent>> event;
> > 
> > Is it really right for this to be stored between views? That seems weird.
> > 
> 
> Hmm, maybe not. I was copying what's done for currentNSEventSlot(). I think
> it makes as much sense in this new case as it did in the old, but I'm a
> little unsure here.

It's OK to keep a "current" event globally, because the relevant parts of WebKit are single-threaded, and a "current" event will get cleared when it's done (I assume). But keeping a "last" event, that lives beyond its own handling, seems wrong in the multi-view case.
Comment 8 Tim Horton 2015-05-06 15:59:23 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > > Source/WebKit/mac/WebView/WebHTMLView.mm:-3844
> > > -    [[[self _webView] _immediateActionController] webView:[self _webView] willHandleMouseDown:event];
> > 
> > Whaaaaaa?
> > 
> 
> This is because mouseDown used to come after the immediate action! Remember?
> We used to have shenanigans like this in WK2 as well, and we were able to
> remove them when we switched to delaysPrimaryMouseEvents:NO. This code was
> there purely because we were getting mouse down at a weird time.

Righto.

> > Could you not keep this in EventHandler instead and avoid keeping it here?
> 
> Hmmmmmmm. I'll have to think this over. This is a closer mirror to what we
> do in WK2. If we moved it to EventHandler, we would have WK1 only member
> variables there, which we actually manage to avoid at this point.

Could you not then perhaps use them for WK2 as well, and share some code that you currently have duplicated between WebView and WKView?
Comment 9 Beth Dakin 2015-05-06 16:03:46 PDT
(In reply to comment #8)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > > Source/WebKit/mac/WebView/WebHTMLView.mm:-3844
> > > > -    [[[self _webView] _immediateActionController] webView:[self _webView] willHandleMouseDown:event];
> > > 
> > > Whaaaaaa?
> > > 
> > 
> > This is because mouseDown used to come after the immediate action! Remember?
> > We used to have shenanigans like this in WK2 as well, and we were able to
> > remove them when we switched to delaysPrimaryMouseEvents:NO. This code was
> > there purely because we were getting mouse down at a weird time.
> 
> Righto.
> 
> > > Could you not keep this in EventHandler instead and avoid keeping it here?
> > 
> > Hmmmmmmm. I'll have to think this over. This is a closer mirror to what we
> > do in WK2. If we moved it to EventHandler, we would have WK1 only member
> > variables there, which we actually manage to avoid at this point.
> 
> Could you not then perhaps use them for WK2 as well, and share some code
> that you currently have duplicated between WebView and WKView?

Ugh, maybe some day? But I  find the idea of that exhausting because I had originally implemented a version of the WK2 code that was more like this, but Simon and Sam very much wanted every layer of the WebKit events to have force in them, and to squish the square peg (pressure events in AppKit are not mouse events) into the round hole (we want pressure events to be mouse events) at the moment NSEvents are converted to anything else in WK2. That is done in the UIProcess, way far away from EventHandler. In WK1, that conversion happens at a surprisingly low level, hence all of these new parameters.
Comment 10 Tim Horton 2015-05-06 16:11:09 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Comment on attachment 252527 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=252527&action=review
> > > 
> > > > Source/WebCore/page/mac/EventHandlerMac.mm:86
> > > > +    static NeverDestroyed<RetainPtr<NSEvent>> event;
> > > 
> > > Is it really right for this to be stored between views? That seems weird.
> > > 
> > 
> > Hmm, maybe not. I was copying what's done for currentNSEventSlot(). I think
> > it makes as much sense in this new case as it did in the old, but I'm a
> > little unsure here.
> 
> It's OK to keep a "current" event globally, because the relevant parts of
> WebKit are single-threaded, and a "current" event will get cleared when it's
> done (I assume). But keeping a "last" event, that lives beyond its own
> handling, seems wrong in the multi-view case.

OK, Sam explained that this *is* actually the force event matching the currently processing event, not actually the last event, and it doesn't persist between handling events, so I think it just needs a different name, not a big change.
Comment 11 Beth Dakin 2015-05-06 16:32:22 PDT
Created attachment 252535 [details]
Patch

Okay, here's a new patch that uses a new name, assuming we do feel okay about this approach. I can try something else if there is another idea too!
Comment 12 WebKit Commit Bot 2015-05-06 16:33:29 PDT
Attachment 252535 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebImmediateActionController.mm:151:  The parameter name "element" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:53:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:78:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:109:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
Total errors found: 4 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Beth Dakin 2015-05-06 17:03:27 PDT
Created attachment 252540 [details]
Patch
Comment 14 WebKit Commit Bot 2015-05-06 17:05:13 PDT
Attachment 252540 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebView/WebImmediateActionController.mm:151:  The parameter name "element" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:53:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:78:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
ERROR: Source/WebCore/platform/mac/PlatformEventFactoryMac.mm:109:  A case label should not be indented, but line up with its switch statement.  [whitespace/indent] [4]
Total errors found: 4 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 15 Sam Weinig 2015-05-07 13:00:05 PDT
Comment on attachment 252540 [details]
Patch

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

> Source/WebCore/page/mac/EventHandlerMac.mm:124
>      currentNSEventSlot() = m_savedCurrentEvent;
> +    correspondingPressureEventSlot() = nil;

I would follow the pattern we have here and keep a stack of corresponding events.

> Source/WebKit/mac/WebView/WebHTMLView.mm:4093
> +    NSEvent *lastPressureEvent = [[self _webView] _pressureEvent];
> +    if (event == lastPressureEvent)
> +        return;

Is this necessary? It seems like it can't happen.

> Source/WebKit/mac/WebView/WebViewData.h:178
> +    NSEvent *pressureEvent;

This should be a RetainPtr. You can probably get rid of the helpers when you make this change.
Comment 16 Beth Dakin 2015-05-07 15:34:02 PDT
http://trac.webkit.org/changeset/183954

Thanks Sam and Tim!
Comment 17 Said Abou-Hallawa 2015-05-07 18:11:54 PDT
http://trac.webkit.org/changeset/183968

Fixing iPhone 6 iOS simulator Build.
Comment 18 Beth Dakin 2015-05-08 11:23:23 PDT
Another follow-up: https://bugs.webkit.org/show_bug.cgi?id=144805