1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// 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 "base/scoped_nsobject.h"
#include "webkit/glue/webmenuitem.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 native menu control.
scoped_nsobject<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_;
// The font size being used for the menu.
CGFloat fontSize_;
}
// Initializes the MenuDelegate with a list of items sent from WebKit.
- (id)initWithItems:(const std::vector<WebMenuItem>&)items
fontSize:(CGFloat)fontSize
rightAligned:(BOOL)rightAligned;
// Returns YES if an item was selected from the menu, NO if the menu was
// dismissed.
- (BOOL)menuItemWasChosen;
// 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
namespace webkit_glue {
// Helper function for users of WebMenuRunner, 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* EventWithMenuAction(BOOL item_chosen, int window_num,
int item_height, int selected_index,
NSRect menu_bounds, NSRect view_bounds);
} // namespace webkit_glue
#endif // WEBKIT_GLUE_WEBMENURUNNER_MAC_H_
|