Bug 191715

Summary: Caret stops blinking after context menu shown
Product: WebKit Reporter: Jonathan Hammer <jonathan>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Minor CC: commit-queue, dino, jonathan, megan_gardner, rniwa, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: All   
OS: All   
See Also: https://bugs.webkit.org/show_bug.cgi?id=40533
Attachments:
Description Flags
Patch
none
Patch none

Description Jonathan Hammer 2018-11-15 14:24:58 PST
Showing a context menu for a selection of text inside of a contenteditable element stops the caret from blinking even *after* the context menu is dismissed. The only way to restart the blinking after the menu is dismissed is to click somewhere else inside the contenteditable element. If you don’t click and instead use the keyboard to change the selection, the caret will remain unblinking.

FrameSelection::setCaretBlinkingSuspended(true) is called from EventHandler::handleMousePressEvent(). The balancing setCaretBlinkingSuspended(false) call is found in EventHandler::handleMouseReleaseEvent. The reason it is broken in the case of context menus is because handleMouseReleaseEvent is never called after the context menu is shown.

My proposed fix is to modify EventHandler::sendContextMenuEvent and have it call setCaretBlinkingSuspended(false) before showing the menu. I can create a patch, but wanted to ask first if it is feasible to create a layout regression test to cover this bug/fix? I can’t think of an obvious way to do it.
Comment 1 Ryosuke Niwa 2018-11-15 19:36:26 PST
Yes, you should be able to send eventSender.mouseDown(2) or eventSender.keyDown('menu') to trigger a context menu. It may only work in WebKitLegacy / WebKit1 though... so you might need to run the test with -1.
Comment 2 Jonathan Hammer 2018-11-15 19:42:20 PST
(In reply to Ryosuke Niwa from comment #1)
> Yes, you should be able to send eventSender.mouseDown(2) or
> eventSender.keyDown('menu') to trigger a context menu. It may only work in
> WebKitLegacy / WebKit1 though... so you might need to run the test with -1.

Sorry I should have clarified: my question is how would the test be able to determine if the caret was blinking or not (after the menu is dismissed)?
Comment 3 Ryosuke Niwa 2018-11-15 19:46:57 PST
Oh, you probably have to add some method to internals to expose whether FrameSelection::m_caretBlinkTimer is active or not.
Comment 4 Jonathan Hammer 2018-11-15 19:57:59 PST
(In reply to Ryosuke Niwa from comment #3)
> Oh, you probably have to add some method to internals to expose whether
> FrameSelection::m_caretBlinkTimer is active or not.

Ah, got it. Didn’t know about internals until just now. I’ll look into it. Thanks!
Comment 5 Jonathan Hammer 2018-11-16 11:22:29 PST
Created attachment 355081 [details]
Patch

Proposed patch.
Comment 6 Ryosuke Niwa 2018-11-16 11:51:47 PST
Comment on attachment 355081 [details]
Patch

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

Thanks for the fix! The code change looks good but there are a few nits to fix.

> Source/WebCore/page/EventHandler.cpp:2883
> +    

Nit: Whitespace.

> LayoutTests/fast/events/contextmenu-dismiss-blink-caret.html:3
> +    <div id="contenteditable" contenteditable>This tests whether the caret continues to blink after the context menu is dismissed.</div>

Please add an instruction to run this test manually in the browser.
This is important so that QA folks, etc... can run this test manually to verify the fix,
and also in the future this test ever gets broken, to be able to bisect using a browser.
Comment 7 Jonathan Hammer 2018-11-16 12:37:32 PST
Created attachment 355100 [details]
Patch

Revised patch attached
Comment 8 Ryosuke Niwa 2018-11-17 01:38:55 PST
Comment on attachment 355100 [details]
Patch

Let's land this. In the future, please also set cq? so that someone who is a committer can cq+ the patch to land it.
Comment 9 WebKit Commit Bot 2018-11-17 02:04:58 PST
Comment on attachment 355100 [details]
Patch

Clearing flags on attachment: 355100

Committed r238345: <https://trac.webkit.org/changeset/238345>
Comment 10 WebKit Commit Bot 2018-11-17 02:05:00 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2018-11-17 02:05:35 PST
<rdar://problem/46149260>