<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>184231</bug_id>
          
          <creation_ts>2018-04-01 23:51:52 -0700</creation_ts>
          <short_desc>REGRESSION(r228260): WebHTMLView beeps at every keydown for Chinese/Japanese/Korean Input Method</short_desc>
          <delta_ts>2018-04-04 09:04:04 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>UI Events</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>184244</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>darin</cc>
    
    <cc>dbates</cc>
    
    <cc>jiewen_tan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1411013</commentid>
    <comment_count>0</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-01 23:51:52 -0700</bug_when>
    <thetext>WebHTMLView beep at every keydown for Chinese/Japanese/Korean Input Method after r228260.

&lt;rdar://problem/38092985&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411014</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-01 23:52:26 -0700</bug_when>
    <thetext>The problem here is that EventHandler::internalKeyEvent sets setDefaultHandled when the key event is handled by input method. Because we clear m_defaultHandled flag before dispatching the event after r228260, EventHandler::keyEvent ends up returning false and resulting in the beep.

Arguably, this is a misuse of m_defaultHandled flag.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411016</commentid>
    <comment_count>2</comment_count>
      <attachid>336972</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 00:41:00 -0700</bug_when>
    <thetext>Created attachment 336972
Fixes the bug</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411017</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 00:42:11 -0700</bug_when>
    <thetext>It&apos;s really upsetting that there isn&apos;t s a way to write a test for this. But the problem here is that there doesn&apos;t seem to be a way of detecting this case inside a layout test, and in API tests, triggering the right input method is virtually impossible (we can&apos;t require runners of API tests to always have Chinese Pinyin keyboard available for example).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411089</commentid>
    <comment_count>4</comment_count>
      <attachid>336972</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2018-04-02 09:21:58 -0700</bug_when>
    <thetext>Comment on attachment 336972
Fixes the bug

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

&gt; Source/WebCore/ChangeLog:13
&gt; +        Unfortunately, no new tests since there is no facility to detect this case in layout tests, and we can&apos;t
&gt; +        easily emulate or trigger a real input method in API tests.

What aspects of an input method need to be emulated here? We certainly can&apos;t detect a beep, but any input method functions can be triggered via textInputController.

The code change looks fine to me, however I don&apos;t understand the motivation for changing this behavior in r228260. The ChangeLog says &quot;Clears m_defaultHandled so
a value left over from a previous dispatch doesn&apos;t affect the next dispatch&quot;, but it doesn&apos;t explain why that&apos;s desirable, and doesn&apos;t add a regression test for the change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411201</commentid>
    <comment_count>5</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 12:52:26 -0700</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #4)
&gt; Comment on attachment 336972 [details]
&gt; Fixes the bug
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=336972&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/ChangeLog:13
&gt; &gt; +        Unfortunately, no new tests since there is no facility to detect this case in layout tests, and we can&apos;t
&gt; &gt; +        easily emulate or trigger a real input method in API tests.
&gt; 
&gt; What aspects of an input method need to be emulated here? We certainly can&apos;t
&gt; detect a beep, but any input method functions can be triggered via
&gt; textInputController.

That the event gets processed by input methods. Basically, we need handleInputMethodKeydown to set defaultHandled, and then we&apos;d need a way of detecting the return value of EventHandler::internalKeyEvent.
 
&gt; The code change looks fine to me, however I don&apos;t understand the motivation
&gt; for changing this behavior in r228260. The ChangeLog says &quot;Clears
&gt; m_defaultHandled so
&gt; a value left over from a previous dispatch doesn&apos;t affect the next
&gt; dispatch&quot;, but it doesn&apos;t explain why that&apos;s desirable, and doesn&apos;t add a
&gt; regression test for the change.

Yeah, another option is to revert that aspect of the change. For now, I&apos;m making this very targeted fix for the very egregious issue of beeping every time anyone times in CJK.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411205</commentid>
    <comment_count>6</comment_count>
    <who name="Jiewen Tan">jiewen_tan</who>
    <bug_when>2018-04-02 12:55:13 -0700</bug_when>
    <thetext>(In reply to Ryosuke Niwa from comment #3)
&gt; It&apos;s really upsetting that there isn&apos;t s a way to write a test for this. But
&gt; the problem here is that there doesn&apos;t seem to be a way of detecting this
&gt; case inside a layout test, and in API tests, triggering the right input
&gt; method is virtually impossible (we can&apos;t require runners of API tests to
&gt; always have Chinese Pinyin keyboard available for example).

For testing, could we somehow fake a KeyDown Event in either JS code or native code that mimic the one that could be fired by Pinyin input in an API test, and then use a swizzler to capture [NSResponder keyDown:]?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411206</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2018-04-02 12:55:50 -0700</bug_when>
    <thetext>&gt; Basically, we need handleInputMethodKeydown to set defaultHandled, and then we&apos;d need a way of detecting the return value of EventHandler::internalKeyEvent.

I see. There is some limited support for posing JS code as an input method, but not a lot, and I don&apos;t remember much about it from the top of my head. So probably not very testable indeed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411207</commentid>
    <comment_count>8</comment_count>
      <attachid>336972</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2018-04-02 12:56:14 -0700</bug_when>
    <thetext>Comment on attachment 336972
Fixes the bug

Also, official r+, and you can consider the comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411208</commentid>
    <comment_count>9</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 12:57:53 -0700</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #7)
&gt; &gt; Basically, we need handleInputMethodKeydown to set defaultHandled, and then we&apos;d need a way of detecting the return value of EventHandler::internalKeyEvent.
&gt; 
&gt; I see. There is some limited support for posing JS code as an input method,
&gt; but not a lot, and I don&apos;t remember much about it from the top of my head.
&gt; So probably not very testable indeed.

Yeah, I feel really bad landing this patch without a test given the lack of testing is probably exactly why this regression got introduced. But I have to think about it more to figure out a way of testing, and we probably shouldn&apos;t block landing this patch on that.

Thanks for the review!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411209</commentid>
    <comment_count>10</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 12:59:44 -0700</bug_when>
    <thetext>Committed r230173: &lt;https://trac.webkit.org/changeset/230173&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1411212</commentid>
    <comment_count>11</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-04-02 13:02:11 -0700</bug_when>
    <thetext>Tracking the testing aspect of it in https://bugs.webkit.org/show_bug.cgi?id=184244.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>336972</attachid>
            <date>2018-04-02 00:41:00 -0700</date>
            <delta_ts>2018-04-02 12:56:14 -0700</delta_ts>
            <desc>Fixes the bug</desc>
            <filename>bug-184231-20180402004058.patch</filename>
            <type>text/plain</type>
            <size>2352</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDIzMDE0OSkKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDIwIEBACisyMDE4LTA0LTAyICBSeW9zdWtl
IE5pd2EgIDxybml3YUB3ZWJraXQub3JnPgorCisgICAgICAgIFJFR1JFU1NJT04ocjIyODI2MCk6
V2ViSFRNTFZpZXcgYmVlcHMgYXQgZXZlcnkga2V5ZG93biBmb3IgQ2hpbmVzZS9KYXBhbmVzZS9L
b3JlYW4gSW5wdXQgTWV0aG9kCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3df
YnVnLmNnaT9pZD0xODQyMzEKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4K
KworICAgICAgICBUaGUgYnVnIHdhcyBjYXVzZWQgYnkgRXZlbnRIYW5kbGVyOjppbnRlcm5hbEtl
eUV2ZW50IGNhbGxpbmcgc2V0RGVmYXVsdEhhbmRsZWQgYW5kIGV4cGVjdGluZyBpdCB0byBzdGF5
IHRydWUKKyAgICAgICAgYWZ0Z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ZiB3ZSBhcmUgZGlzcGF0Y2hpbmcgYSBmYWtl
IGJhY2t3YXJkIGNvbXBhdGliaWxpdHkga2V5cHJlc3MsIHRoZW4gd2UgcHJldGVuZCB0aGF0IHRo
ZSBrZXlwcmVzcyBoYXBwZW5lZCBvbiB0aGUgb3JpZ2luYWwgZWxlbWVudC4KICAgICBpZiAoIWtl
eWRvd25SZXN1bHQpIHsK
</data>
<flag name="review"
          id="355423"
          type_id="1"
          status="+"
          setter="ap"
    />
          </attachment>
      

    </bug>

</bugzilla>