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