Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: webkit/tools/test_shell/mac/test_webview_delegate.mm

Issue 9703067: mac: Move EventWithMenuAction() to the only file where it's called. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/webmenurunner_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/mac/test_webview_delegate.mm
diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm
index e0d3f38c8d55da0fc231c587b86b4cecaed388b4..59a07ff36384f10c18ae8f85f7078d8880840081 100644
--- a/webkit/tools/test_shell/mac/test_webview_delegate.mm
+++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm
@@ -24,6 +24,64 @@ using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
using WebKit::WebWidget;
+namespace {
+
+// Helper function for manufacturing input events to send to WebKit.
+NSEvent* EventWithMenuAction(BOOL item_chosen, int window_num,
+ int item_height, int selected_index,
+ NSRect menu_bounds, NSRect view_bounds) {
+ NSEvent* event = nil;
+ double event_time = (double)(AbsoluteToDuration(UpTime())) / 1000.0;
+
+ if (item_chosen) {
+ // Construct a mouse up event to simulate the selection of an appropriate
+ // menu item.
+ NSPoint click_pos;
+ click_pos.x = menu_bounds.size.width / 2;
+
+ // This is going to be hard to calculate since the button is painted by
+ // WebKit, the menu by Cocoa, and we have to translate the selected_item
+ // index to a coordinate that WebKit's PopupMenu expects which uses a
+ // different font *and* expects to draw the menu below the button like we do
+ // on Windows.
+ // The WebKit popup menu thinks it will draw just below the button, so
+ // create the click at the offset based on the selected item's index and
+ // account for the different coordinate system used by NSView.
+ int item_offset = selected_index * item_height + item_height / 2;
+ click_pos.y = view_bounds.size.height - item_offset;
+ event = [NSEvent mouseEventWithType:NSLeftMouseUp
+ location:click_pos
+ modifierFlags:0
+ timestamp:event_time
+ windowNumber:window_num
+ context:nil
+ eventNumber:0
+ clickCount:1
+ pressure:1.0];
+ } else {
+ // Fake an ESC key event (keyCode = 0x1B, from webinputevent_mac.mm) and
+ // forward that to WebKit.
+ NSPoint key_pos;
+ key_pos.x = 0;
+ key_pos.y = 0;
+ NSString* escape_str = [NSString stringWithFormat:@"%c", 0x1B];
+ event = [NSEvent keyEventWithType:NSKeyDown
+ location:key_pos
+ modifierFlags:0
+ timestamp:event_time
+ windowNumber:window_num
+ context:nil
+ characters:@""
+ charactersIgnoringModifiers:escape_str
+ isARepeat:NO
+ keyCode:0x1B];
+ }
+
+ return event;
+}
+
+} // namespace
+
// WebViewClient --------------------------------------------------------------
WebWidget* TestWebViewDelegate::createPopupMenu(
@@ -76,8 +134,7 @@ void TestWebViewDelegate::show(WebNavigationPolicy policy) {
// position based on the selected index and provided bounds.
WebWidgetHost* popup = shell_->popupHost();
int window_num = [shell_->mainWnd() windowNumber];
- NSEvent* event =
- webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen],
+ NSEvent* event = EventWithMenuAction([menu_runner menuItemWasChosen],
window_num, item_height,
[menu_runner indexOfSelectedItem],
position, view_rect);
« no previous file with comments | « webkit/glue/webmenurunner_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698