summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webmenurunner_mac.h
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 19:39:00 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 19:39:00 +0000
commit5dee2add09d2e6f3a397f567a82791c37a747509 (patch)
treeb0a6a05c3ec4cf275375235576a2d8ebfd46900c /webkit/glue/webmenurunner_mac.h
parentef921826834b693e83ebe3a4ae6984b9b39b723b (diff)
downloadchromium_src-5dee2add09d2e6f3a397f567a82791c37a747509.zip
chromium_src-5dee2add09d2e6f3a397f567a82791c37a747509.tar.gz
chromium_src-5dee2add09d2e6f3a397f567a82791c37a747509.tar.bz2
Clean up cocoa popup menu handling in test_shell.
The cocoa menu delegate, previously local to test_shell on Mac, now has the added responsibility of running the popup menu and processing the menu's actions. It is moved into its own files in order to use this class as-is in Chrome. BUG=8389 (http://crbug.com/8389) Review URL: http://codereview.chromium.org/92062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webmenurunner_mac.h')
-rw-r--r--webkit/glue/webmenurunner_mac.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/webkit/glue/webmenurunner_mac.h b/webkit/glue/webmenurunner_mac.h
new file mode 100644
index 0000000..eceaa3f
--- /dev/null
+++ b/webkit/glue/webmenurunner_mac.h
@@ -0,0 +1,71 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_WEBMENURUNNER_MAC_H_
+#define WEBKIT_GLUE_WEBMENURUNNER_MAC_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include <vector>
+
+#include "webkit/glue/webwidget_delegate.h"
+
+
+// WebMenuRunner ---------------------------------------------------------------
+// A class for determining whether an item was selected from an HTML select
+// control, or if the menu was dismissed without making a selection. If a menu
+// item is selected, MenuDelegate is informed and sets a flag which can be
+// queried after the menu has finished running.
+
+@interface WebMenuRunner : NSObject {
+ @private
+ // The actual menu object, which we own.
+ NSMenu* menu_;
+
+ // A flag set to YES if a menu item was chosen, or NO if the menu was
+ // dismissed without selecting an item.
+ BOOL menuItemWasChosen_;
+
+ // The index of the selected menu item.
+ int index_;
+}
+
+// Initializes the MenuDelegate with a list of items sent from WebKit.
+- (id)initWithItems:(const std::vector<WebMenuItem>&)items;
+- (void)dealloc;
+
+// Worker function used during initialization.
+- (void)addItem:(const WebMenuItem&)item;
+
+// Returns YES if an item was selected from the menu, NO if the menu was
+// dismissed.
+- (BOOL)menuItemWasChosen;
+
+// A callback for the menu controller object to call when an item is selected
+// from the menu. This is not called if the menu is dismissed without a
+// selection.
+- (void)menuItemSelected:(id)sender;
+
+// Displays and runs a native popup menu.
+- (void)runMenuInView:(NSView*)view
+ withBounds:(NSRect)bounds
+ initialIndex:(int)index;
+
+// Returns the index of selected menu item, or its initial value (-1) if no item
+// was selected.
+- (int)indexOfSelectedItem;
+
+@end // @interface WebMenuRunner
+
+// Helper function for manufacturing input events to send to WebKit. If
+// |item_chosen| is YES, we manufacture a mouse click event that corresponds to
+// the menu item that was selected, |selected_index|, based on the position of
+// the mouse click. Of |item_chosen| is NO, we create a keyboard event that
+// simulates an ESC (menu dismissal) action. The event is designed to be sent to
+// WebKit for processing by the PopupMenu class.
+NSEvent* CreateEventForMenuAction(BOOL item_chosen, int window_num,
+ int item_height, int selected_index,
+ NSRect menu_bounds, NSRect view_bounds);
+
+#endif // WEBKIT_GLUE_WEBMENURUNNER_MAC_H_