Bug 23060

Summary: REGRESSION (r38629): Cannot scroll a WebHTMLView using Home/End/Page up/Page down
Product: WebKit Reporter: Cameron Zwarich (cpst) <zwarich>
Component: HTML EditingAssignee: Cameron Zwarich (cpst) <zwarich>
Status: RESOLVED FIXED    
Severity: Normal CC: darin
Priority: P2 Keywords: InRadar, Regression
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.5   
Attachments:
Description Flags
Proposed patch
none
Proposed patch darin: review+

Description Cameron Zwarich (cpst) 2008-12-31 14:41:07 PST
After r38629, all keyboard events get sent by Editor to the EditorClient, even if the selection is not editable. If the event's command is unsupported by WebHTMLView, WebHTMLView mistakingly thinks that the event was handled when it was not. When using the page up / page down keys, the events generated are of the form scrollPageUp rather than movePageUp, so they are unsupported by WebHTMLView and cause this bug to occur.
Comment 1 Cameron Zwarich (cpst) 2008-12-31 14:41:31 PST
<rdar://problem/6467830>
Comment 2 Cameron Zwarich (cpst) 2008-12-31 14:45:08 PST
Created attachment 26339 [details]
Proposed patch

Here's a patch that fixes the problem. This is probably testable in DRT, but I'd rather get the fix out of the way before deciding how to test it.
Comment 3 Darin Adler 2008-12-31 14:57:55 PST
Comment on attachment 26339 [details]
Proposed patch

Typo "mistakenly" rather than "mistakingly".

> -        bool eventWasHandled = true;
> +        bool eventWasHandled = false;

This changes the value when the delegate returns YES and when coreFrame is 0. Did you really mean to change it in those cases? Why?

> -            else {
> +            else if ([self _canEdit]) {
>                  _private->selectorForDoCommandBySelector = selector;
>                  [super doCommandBySelector:selector];
>                  _private->selectorForDoCommandBySelector = 0;
> +                eventWasHandled = true;
>              }

What this really amounts to is:

   if _canEdit returns false, then set eventWasHandled to false and don't call super's doCommandBySelector

So for one thing, you can write it that way:

    else if (![self_canEdit])
        eventWasHandled = false;
    else
        ...

Without changing the surrounding code, if you like.

But for another, I don't understand the rationale here. Maybe we should never treat calling [super doCommandBySelector:] as "eventWasHandled true" -- I don't see what _canEdit has to do with it.
Comment 4 Cameron Zwarich (cpst) 2008-12-31 15:02:00 PST
(In reply to comment #3)
> (From update of attachment 26339 [details] [review])
> Typo "mistakenly" rather than "mistakingly".
> 
> > -        bool eventWasHandled = true;
> > +        bool eventWasHandled = false;
> 
> This changes the value when the delegate returns YES and when coreFrame is 0.
> Did you really mean to change it in those cases? Why?
> 
> > -            else {
> > +            else if ([self _canEdit]) {
> >                  _private->selectorForDoCommandBySelector = selector;
> >                  [super doCommandBySelector:selector];
> >                  _private->selectorForDoCommandBySelector = 0;
> > +                eventWasHandled = true;
> >              }
> 
> What this really amounts to is:
> 
>    if _canEdit returns false, then set eventWasHandled to false and don't call
> super's doCommandBySelector
> 
> So for one thing, you can write it that way:
> 
>     else if (![self_canEdit])
>         eventWasHandled = false;
>     else
>         ...
> 
> Without changing the surrounding code, if you like.

Yeah, I accidentally changed the delegate case. I originally had it like you said, but thought it would be better to make the default false rather than true. I should never doubt my instincts. ;-)

> But for another, I don't understand the rationale here. Maybe we should never
> treat calling [super doCommandBySelector:] as "eventWasHandled true" -- I don't
> see what _canEdit has to do with it.

I would have thought about doing that, but I couldn't answer this question: when does [super doCommandBySelector:] ever handle an event? Presumedly there is some case if the code was added long ago.
Comment 5 Cameron Zwarich (cpst) 2008-12-31 15:02:23 PST
Comment on attachment 26339 [details]
Proposed patch

Clearing review flag pending a new patch.
Comment 6 Darin Adler 2008-12-31 15:06:01 PST
(In reply to comment #4)
> I would have thought about doing that, but I couldn't answer this question:
> when does [super doCommandBySelector:] ever handle an event? Presumedly there
> is some case if the code was added long ago.

I think the case has something to do with input methods, but I really don't know.
Comment 7 Cameron Zwarich (cpst) 2008-12-31 15:16:59 PST
Created attachment 26340 [details]
Proposed patch

Here is the revised patch. I don't want to change the default in the editable case if you don't know exactly why the message is passed to super. Also, 'mistakingly' is valid English, just a bit out of use. I changed it though. ;-)

The same comment stands about the test.
Comment 8 Darin Adler 2009-01-01 17:39:58 PST
Comment on attachment 26340 [details]
Proposed patch

r=me

I think this would be slightly better if it had a comment explaining what's going on.
Comment 9 Cameron Zwarich (cpst) 2009-01-02 07:18:50 PST
Fixed in r39549, with a comment added like Darin suggested.