Skip to content

Commit 370c2a7

Browse files
[WK2] Keyboard menu key should show context menu
https://bugs.webkit.org/show_bug.cgi?id=72099 Source/WebCore: Reviewed by Carlos Garcia Campos. Show the context menu when the GtkWidget::popup-menu signal is emitted. This signal is triggered by pressing a key (usually the Menu key or the Shift + F10 shortcut) or it could be emitted on WebKitWebView. Test: fast/events/context-activated-by-key-event.html Also could be tested by: ManualTests/keyboard-menukey-event.html ManualTests/win/contextmenu-key.html ManualTests/win/contextmenu-key2.html * page/EventHandler.cpp: (WebCore::EventHandler::sendContextMenuEventForKey): Correctly send the mouse event that used for showing the context menu. Previously the event was immediately dispatched as it is, but this was only the right way if some element was focused on the page. If there was no focused element or non-empty text range then the event lacked the right node, where it was supposed to be shown. The correct node is determined and added to the event in the sendContextMenuEvent() so we have to use this function to send the event. Also use absoluteBoundingBoxRect() instead of pixelSnappedAbsoluteClippedOverflowRect() when determining a coordinate where to show the context menu for the currently focus element. The latter is not returning a right box (it is bigger) which could lead to the situation that no menu will be displayed at all, because the HitTest won't contain the right element as the determined coordinates could be outside of the element. * page/EventHandler.h: Source/WebKit2: Reviewed by Carlos Garcia Campos. Show the context menu when the GtkWidget::popup-menu signal is emitted. This signal is triggered by pressing a key (usually the Menu key or the Shift + F10 shortcut) or it could be emitted on WebKitWebView. * UIProcess/API/gtk/WebKitWebView.cpp: (webkit_web_view_class_init): (webkit_web_view_class_init): Update the documentation for the context-menu signal * UIProcess/API/gtk/WebKitWebViewBase.cpp: (webkitWebViewBasePopupMenu): Connect to the popup-menu signal and save the event that was used to trigger the signal. If there is no such event create a new GdkEvent with GDK_NOTHING type. (webkitWebViewBasePopupMenu): (webkit_web_view_base_class_init): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::handleContextMenuKeyEvent): * UIProcess/WebPageProxy.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::contextMenuForKeyEvent): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Tools: Show the context menu when the GtkWidget::popup-menu signal is emitted. This signal is triggered by pressing a key (usually the Menu key or the Shift + F10 shortcut) or it could be emitted on WebKitWebView. Reviewed by Carlos Garcia Campos. * TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp: (testContextMenuDefaultMenu): * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp: (WebViewTest::emitPopupMenuSignal): * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h: LayoutTests: Reviewed by Carlos Garcia Campos. Skip the fast/events/context-activated-by-key-event.html on Mac as it does not have a key to activate the context menu and on iOS as well. * platform/ios-simulator-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: * platform/mac/TestExpectations: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@213278 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9bcaceb commit 370c2a7

File tree

21 files changed

+315
-11
lines changed

21 files changed

+315
-11
lines changed

LayoutTests/ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2017-03-02 Tomas Popela <[email protected]>
2+
3+
[WK2] Keyboard menu key should show context menu
4+
https://bugs.webkit.org/show_bug.cgi?id=72099
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Skip the fast/events/context-activated-by-key-event.html on Mac as it
9+
does not have a key to activate the context menu and on iOS as well.
10+
11+
* platform/ios-simulator-wk2/TestExpectations:
12+
* platform/mac-wk2/TestExpectations:
13+
* platform/mac/TestExpectations:
14+
115
2017-03-02 Javier Fernandez <[email protected]>
216

317
[GTK] Unreviewed test gardening
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This tests whether the context menu is displayed on the menu key press.
2+
example.com
3+
PASS WINDOW
4+
PASS CONTENTEDITABLE
5+
PASS ELEMENT
6+
PASS CONTENTEDITABLE SELECTION
7+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<html>
2+
<body>
3+
<div id="contenteditable" contenteditable>This tests whether the context menu is displayed on the menu key press.</div>
4+
<a id="link" href="example.com">example.com</a>
5+
<p id='result'></p>
6+
</body>
7+
</html>
8+
9+
10+
<script>
11+
function log(text) {
12+
document.getElementById('result').appendChild(document.createTextNode(text));
13+
document.getElementById('result').appendChild(document.createElement("br"));
14+
}
15+
16+
function onWindowContextMenu(event) {
17+
log('PASS WINDOW');
18+
event.stopPropagation();
19+
}
20+
function onContentEditableContextMenu(event) {
21+
if (window.getSelection().toString())
22+
log('PASS CONTENTEDITABLE SELECTION');
23+
else
24+
log('PASS CONTENTEDITABLE');
25+
event.stopPropagation();
26+
}
27+
function onFocusedElementContextMenu(event) {
28+
log('PASS ELEMENT');
29+
event.stopPropagation();
30+
}
31+
32+
window.addEventListener('contextmenu', onWindowContextMenu);
33+
document.getElementById('contenteditable').addEventListener('contextmenu', onContentEditableContextMenu);
34+
document.getElementById('link').addEventListener('contextmenu', onFocusedElementContextMenu);
35+
36+
if (window.testRunner) {
37+
eventSender.keyDown('menu');
38+
39+
var rect = document.getElementById('contenteditable').getBoundingClientRect();
40+
var x = rect.left + rect.width / 2;
41+
var y = rect.top + rect.height / 2;
42+
eventSender.mouseMoveTo(x, y);
43+
eventSender.mouseDown();
44+
eventSender.mouseUp();
45+
eventSender.keyDown('menu');
46+
47+
document.getElementById('link').focus();
48+
eventSender.keyDown('menu');
49+
50+
window.getSelection().selectAllChildren(document.getElementById('contenteditable'));
51+
eventSender.keyDown('menu');
52+
53+
testRunner.dumpAsText();
54+
}
55+
56+
</script>

LayoutTests/platform/ios-simulator-wk2/TestExpectations

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,3 +1916,6 @@ fast/css/deferred-parsing/hover-test.html [ Skip ]
19161916
webkit.org/b/166025 http/tests/fetch/fetching-same-resource-with-diffferent-options.html [ Pass Failure ]
19171917

19181918
imported/w3c/web-platform-tests/webrtc [ Skip ]
1919+
1920+
# Skipped because there is no key to show the context menu
1921+
fast/events/context-activated-by-key-event.html [ Skip ]

LayoutTests/platform/mac-wk2/TestExpectations

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,8 @@ webkit.org/b/168089 [ Release ] animations/trigger-container-scroll-empty.html [
638638

639639
webkit.org/b/168391 [ ElCapitan Debug ] storage/indexeddb/modern/idbcursor-continue-primary-key-1.html [ Pass Timeout ]
640640

641+
641642
webkit.org/b/168380 [ ElCapitan Debug ] imported/w3c/web-platform-tests/IndexedDB/idb-binary-key-roundtrip.htm [ Pass Failure ]
643+
644+
# Skipped because Mac doesn't have a key to show the context menu
645+
fast/events/context-activated-by-key-event.html [ Skip ]

LayoutTests/platform/mac/TestExpectations

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,3 +1550,6 @@ webkit.org/b/168503 editing/pasteboard/drag-drop-copy-content.html [ Failure ]
15501550
webkit.org/b/168936 imported/w3c/web-platform-tests/IndexedDB/idbdatabase-deleteObjectStore-exception-order.htm [ Pass Failure ]
15511551

15521552
webkit.org/b/168927 fast/dom/timer-throttling-hidden-page.html [ Pass Failure ]
1553+
1554+
# Skipped because Mac doesn't have a key to show the context menu
1555+
fast/events/context-activated-by-key-event.html [ Skip ]

Source/WebCore/ChangeLog

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
2017-03-02 Tomas Popela <[email protected]>
2+
3+
[WK2] Keyboard menu key should show context menu
4+
https://bugs.webkit.org/show_bug.cgi?id=72099
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Show the context menu when the GtkWidget::popup-menu signal is
9+
emitted. This signal is triggered by pressing a key (usually
10+
the Menu key or the Shift + F10 shortcut) or it could be emitted on
11+
WebKitWebView.
12+
13+
Test: fast/events/context-activated-by-key-event.html
14+
15+
Also could be tested by:
16+
17+
ManualTests/keyboard-menukey-event.html
18+
ManualTests/win/contextmenu-key.html
19+
ManualTests/win/contextmenu-key2.html
20+
21+
* page/EventHandler.cpp:
22+
(WebCore::EventHandler::sendContextMenuEventForKey):
23+
Correctly send the mouse event that used for showing the context menu.
24+
Previously the event was immediately dispatched as it is, but this was
25+
only the right way if some element was focused on the page. If there
26+
was no focused element or non-empty text range then the event lacked
27+
the right node, where it was supposed to be shown. The correct node
28+
is determined and added to the event in the sendContextMenuEvent() so
29+
we have to use this function to send the event.
30+
31+
Also use absoluteBoundingBoxRect() instead of
32+
pixelSnappedAbsoluteClippedOverflowRect() when determining
33+
a coordinate where to show the context menu for the currently focus
34+
element. The latter is not returning a right box (it is bigger) which
35+
could lead to the situation that no menu will be displayed at all,
36+
because the HitTest won't contain the right element as the
37+
determined coordinates could be outside of the element.
38+
* page/EventHandler.h:
39+
140
2017-03-02 Carlos Garcia Campos <[email protected]>
241

342
[GTK] Crash in WebCore::CoordinatedGraphicsLayer::notifyFlushRequired

Source/WebCore/page/EventHandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,8 +2899,9 @@ bool EventHandler::sendContextMenuEventForKey()
28992899
RenderBoxModelObject* box = focusedElement->renderBoxModelObject();
29002900
if (!box)
29012901
return false;
2902-
IntRect clippedRect = box->pixelSnappedAbsoluteClippedOverflowRect();
2903-
location = IntPoint(clippedRect.x(), clippedRect.maxY() - 1);
2902+
2903+
IntRect boundingBoxRect = box->absoluteBoundingBoxRect(true);
2904+
location = IntPoint(boundingBoxRect.x(), boundingBoxRect.maxY() - 1);
29042905
} else {
29052906
location = IntPoint(
29062907
rightAligned ? view->contentsWidth() - kContextMenuMargin : kContextMenuMargin,
@@ -2932,7 +2933,7 @@ bool EventHandler::sendContextMenuEventForKey()
29322933

29332934
PlatformMouseEvent platformMouseEvent(position, globalPosition, RightButton, eventType, 1, false, false, false, false, WTF::currentTime(), ForceAtClick, NoTap);
29342935

2935-
return !dispatchMouseEvent(eventNames().contextmenuEvent, targetNode, true, 0, platformMouseEvent, false);
2936+
return sendContextMenuEvent(platformMouseEvent);
29362937
}
29372938
#endif // ENABLE(CONTEXT_MENUS)
29382939

Source/WebCore/page/EventHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class EventHandler {
234234

235235
#if ENABLE(CONTEXT_MENUS)
236236
WEBCORE_EXPORT bool sendContextMenuEvent(const PlatformMouseEvent&);
237-
bool sendContextMenuEventForKey();
237+
WEBCORE_EXPORT bool sendContextMenuEventForKey();
238238
#endif
239239

240240
void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }

Source/WebKit2/ChangeLog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2017-03-02 Tomas Popela <[email protected]>
2+
3+
[WK2] Keyboard menu key should show context menu
4+
https://bugs.webkit.org/show_bug.cgi?id=72099
5+
6+
Reviewed by Carlos Garcia Campos.
7+
8+
Show the context menu when the GtkWidget::popup-menu signal is
9+
emitted. This signal is triggered by pressing a key (usually
10+
the Menu key or the Shift + F10 shortcut) or it could be emitted on
11+
WebKitWebView.
12+
13+
* UIProcess/API/gtk/WebKitWebView.cpp:
14+
(webkit_web_view_class_init):
15+
(webkit_web_view_class_init): Update the documentation for the
16+
context-menu signal
17+
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
18+
(webkitWebViewBasePopupMenu): Connect to the popup-menu signal and
19+
save the event that was used to trigger the signal. If there is no
20+
such event create a new GdkEvent with GDK_NOTHING type.
21+
(webkitWebViewBasePopupMenu):
22+
(webkit_web_view_base_class_init):
23+
* UIProcess/WebPageProxy.cpp:
24+
(WebKit::WebPageProxy::handleContextMenuKeyEvent):
25+
* UIProcess/WebPageProxy.h:
26+
* WebProcess/WebPage/WebPage.cpp:
27+
(WebKit::WebPage::contextMenuForKeyEvent):
28+
* WebProcess/WebPage/WebPage.h:
29+
* WebProcess/WebPage/WebPage.messages.in:
30+
131
2017-03-01 Wenson Hsieh <[email protected]>
232

333
Replace -[WKWebView adjustedDataInteractionItemProviders:] with a UI delegate method

0 commit comments

Comments
 (0)