OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ | 5 #ifndef WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ |
6 #define WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ | 6 #define WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/scoped_nsobject.h" |
12 #include "webkit/glue/webwidget_delegate.h" | 13 #include "webkit/glue/webwidget_delegate.h" |
13 | 14 |
14 | 15 |
15 // WebMenuRunner --------------------------------------------------------------- | 16 // WebMenuRunner --------------------------------------------------------------- |
16 // A class for determining whether an item was selected from an HTML select | 17 // A class for determining whether an item was selected from an HTML select |
17 // control, or if the menu was dismissed without making a selection. If a menu | 18 // control, or if the menu was dismissed without making a selection. If a menu |
18 // item is selected, MenuDelegate is informed and sets a flag which can be | 19 // item is selected, MenuDelegate is informed and sets a flag which can be |
19 // queried after the menu has finished running. | 20 // queried after the menu has finished running. |
20 | 21 |
21 @interface WebMenuRunner : NSObject { | 22 @interface WebMenuRunner : NSObject { |
22 @private | 23 @private |
23 // The actual menu object, which we own. | 24 // The native menu control. |
24 NSMenu* menu_; | 25 scoped_nsobject<NSMenu> menu_; |
25 | 26 |
26 // A flag set to YES if a menu item was chosen, or NO if the menu was | 27 // A flag set to YES if a menu item was chosen, or NO if the menu was |
27 // dismissed without selecting an item. | 28 // dismissed without selecting an item. |
28 BOOL menuItemWasChosen_; | 29 BOOL menuItemWasChosen_; |
29 | 30 |
30 // The index of the selected menu item. | 31 // The index of the selected menu item. |
31 int index_; | 32 int index_; |
32 } | 33 } |
33 | 34 |
34 // Initializes the MenuDelegate with a list of items sent from WebKit. | 35 // Initializes the MenuDelegate with a list of items sent from WebKit. |
35 - (id)initWithItems:(const std::vector<WebMenuItem>&)items; | 36 - (id)initWithItems:(const std::vector<WebMenuItem>&)items; |
36 - (void)dealloc; | |
37 | |
38 // Worker function used during initialization. | |
39 - (void)addItem:(const WebMenuItem&)item; | |
40 | 37 |
41 // Returns YES if an item was selected from the menu, NO if the menu was | 38 // Returns YES if an item was selected from the menu, NO if the menu was |
42 // dismissed. | 39 // dismissed. |
43 - (BOOL)menuItemWasChosen; | 40 - (BOOL)menuItemWasChosen; |
44 | 41 |
45 // A callback for the menu controller object to call when an item is selected | |
46 // from the menu. This is not called if the menu is dismissed without a | |
47 // selection. | |
48 - (void)menuItemSelected:(id)sender; | |
49 | |
50 // Displays and runs a native popup menu. | 42 // Displays and runs a native popup menu. |
51 - (void)runMenuInView:(NSView*)view | 43 - (void)runMenuInView:(NSView*)view |
52 withBounds:(NSRect)bounds | 44 withBounds:(NSRect)bounds |
53 initialIndex:(int)index; | 45 initialIndex:(int)index; |
54 | 46 |
55 // Returns the index of selected menu item, or its initial value (-1) if no item | 47 // Returns the index of selected menu item, or its initial value (-1) if no item |
56 // was selected. | 48 // was selected. |
57 - (int)indexOfSelectedItem; | 49 - (int)indexOfSelectedItem; |
58 | 50 |
59 @end // @interface WebMenuRunner | 51 @end // @interface WebMenuRunner |
60 | 52 |
61 // Helper function for manufacturing input events to send to WebKit. If | 53 namespace webkit_glue { |
62 // |item_chosen| is YES, we manufacture a mouse click event that corresponds to | 54 // Helper function for users of WebMenuRunner, for manufacturing input events to |
63 // the menu item that was selected, |selected_index|, based on the position of | 55 // send to WebKit. If |item_chosen| is YES, we manufacture a mouse click event |
64 // the mouse click. Of |item_chosen| is NO, we create a keyboard event that | 56 // that corresponds to the menu item that was selected, |selected_index|, based |
65 // simulates an ESC (menu dismissal) action. The event is designed to be sent to | 57 // on the position of the mouse click. Of |item_chosen| is NO, we create a |
66 // WebKit for processing by the PopupMenu class. | 58 // keyboard event that simulates an ESC (menu dismissal) action. The event is |
67 NSEvent* CreateEventForMenuAction(BOOL item_chosen, int window_num, | 59 // designed to be sent to WebKit for processing by the PopupMenu class. |
68 int item_height, int selected_index, | 60 NSEvent* EventWithMenuAction(BOOL item_chosen, int window_num, |
69 NSRect menu_bounds, NSRect view_bounds); | 61 int item_height, int selected_index, |
| 62 NSRect menu_bounds, NSRect view_bounds); |
| 63 } // namespace webkit_glue |
70 | 64 |
71 #endif // WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ | 65 #endif // WEBKIT_GLUE_WEBMENURUNNER_MAC_H_ |
OLD | NEW |