Skip to content
  • bweinstein@apple.com's avatar
    JavaScriptCore: Turn on USE(CROSS_PLATFORM_CONTEXT_MENUS) for Windows. · c4728817
    bweinstein@apple.com authored
    Reviewed by Adam Roben.
    
    * wtf/Platform.h:
    
    WebCore: Prep for WebKit2: Context menu support on Windows
    https://bugs.webkit.org/show_bug.cgi?id=50514
            
    Reviewed by Adam Roben.
    
    Before this patch ContextMenu on Windows were backed by HMENUs, and ContextMenuItems
    were backed by MENUITEMINFOs. This meant they couldn't be copied, and they needed to
    be to work in WebKit2.
            
    This patch adds a new USE flag - CROSS_PLATFORM_CONTEXT_MENUS that are for a cross-platform
    representation of context menus. This patch also has Windows adopt them.
            
    Cross-platform context menus change the API of context menus and the ContextMenuClient. There
    is no more idea of a PlatformMenuDescription or a PlatformMenuItemDescription. Menus are backed
    by a Vector of ContextMenuItems, and menu items are backed by the variables they need (enabled, checked
    title, action, type, and submenu).
            
    This patch also refactors the ContextMenuClient interface to use a variation on the getCustomMenuFromDefaultItems
    function to allow for customization of the context menu.
            
    For other ports to use CROSS_PLATFORM_CONTEXT_MENUS, all they need to do is write conversion functions from
    a ContextMenu <-> native menu type, and ContextMenuItem <-> native menu item type. For Windows, this is done
    in ContextMenuWin.cpp and ContextMenuItemWin.cpp.
    
    No new tests, no change in behavior.
    
    * WebCore.vcproj/WebCore.vcproj: Add new files (only needed on Windows for now).
    * loader/EmptyClients.h:
    (WebCore::EmptyContextMenuClient::customizeMenu): Define this function if CROSS_PLATFORM_CONTEXT_MENUS
        is on.
    * page/ContextMenuClient.h: Ditto. 
    * page/ContextMenuController.cpp:
    (WebCore::ContextMenuController::showContextMenu): Call customizeMenu instead of 
        getCustomMenuFromDefaultItems if CROSS_PLATFORM_CONTEXT_MENUS is on.
    * platform/ContextMenu.cpp: Added.
    (WebCore::ContextMenu::ContextMenu): Empty constructor.
    (WebCore::ContextMenu::setItems): Sets the items in the menu.
    (WebCore::ContextMenu::items): Returns the items in the menu.
    (WebCore::ContextMenu::itemAtIndex):
    (WebCore::itemWithActionInMenu): Returns the item with the correct action, recursively descending
        into submenus.
    (WebCore::ContextMenu::itemWithAction): Calls through to itemWithActionInMenu.
    * platform/ContextMenu.h: Added a new set of functions and member variables that are defined for
        CROSS_PLATFORM_CONTEXT_MENUS.
    (WebCore::ContextMenu::appendItem): Appends an item to the menu.
    * platform/ContextMenuItem.cpp: Added.
    (WebCore::ContextMenuItem::ContextMenuItem):
    (WebCore::ContextMenuItem::~ContextMenuItem):
    (WebCore::ContextMenuItem::setSubMenu):
    * platform/ContextMenuItem.h:
    (WebCore::ContextMenuItem::type): Returns the type.
    (WebCore::ContextMenuItem::setType): Sets the type.
    (WebCore::ContextMenuItem::action): Returns the action.
    (WebCore::ContextMenuItem::setAction): Sets the action.
    (WebCore::ContextMenuItem::title): Returns the title.
    (WebCore::ContextMenuItem::setTitle): Sets the title.
    (WebCore::ContextMenuItem::checked): Returns whether or not the menu item is checked.
    (WebCore::ContextMenuItem::setChecked): Sets whether ot not the menu item is checked.
    (WebCore::ContextMenuItem::enabled): Returns whether or not the menu item is enabled.
    (WebCore::ContextMenuItem::setEnabled): Sets whether or not the menu item is enabled.
    (WebCore::ContextMenuItem::submenu): Returns the submenu.
    * platform/PlatformMenuDescription.h: Remove the idea if a PlatformMenuDescription if 
        CROSS_PLATFORM_CONTEXT_MENUS is on.
    * platform/win/ContextMenuItemWin.cpp:
    (WebCore::ContextMenuItem::ContextMenuItem): Creates a ContextMenuItem from a MENUITEMINFO.
    (WebCore::ContextMenuItem::nativeMenuItem): Creates and returns a MENUITEMINFO.
    * platform/win/ContextMenuWin.cpp:
    (WebCore::ContextMenu::ContextMenu): Creates a ContextMenu from an HMENU.
    (WebCore::ContextMenu::nativeMenu): Creates and returns an HMENU.
    
    WebKit/win: Prep for WebKit2: Context menu support on Windows
    https://bugs.webkit.org/show_bug.cgi?id=50514
            
    Reviewed by Adam Roben.
    
    Update WebKit for the new CROSS_PLATFORM_CONTEXT_MENUS flag, and define customizeMenu
    instead of getCustomMenuFromDefaultItems.
    
    * WebCoreSupport/WebContextMenuClient.cpp:
    (WebContextMenuClient::customizeMenu): getCustomMenuFromDefaultItems was turned into
        this function, with refactoring using nativeMenu instead of platformDescription.
    (WebContextMenuClient::contextMenuItemSelected):  Use nativeMenu instead of platformDescription.
    * WebCoreSupport/WebContextMenuClient.h:
    * WebView.cpp:
    (WebView::handleContextMenuEvent): Call nativeMenu instead of platformDescription.
    (WebView::performContextMenuAction): Only call itemAtIndex with one argument, no need
        for the second.
    
    WebKit2: Prep for WebKit2: Context menu support on Windows
    https://bugs.webkit.org/show_bug.cgi?id=50514
            
    Reviewed by Adam Roben.
    
    Update WebKit2 to call the correct code when CROSS_PLATFORM_CONTEXT_MENUS is set.
    
    * Shared/WebContextMenuItemData.cpp:
    (WebKit::WebContextMenuItemData::WebContextMenuItemData): Add a branch based on whether or not 
        CROSS_PLATFORM_CONTEXT_MENUS is set.
    * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
    (WebKit::WebContextMenuClient::customizeMenu): Define different functions based on
        whether or not CROSS_PLATFORM_CONTEXT_MENUS. Both of these are stubs, so functionality
        doesn't need to be shared.
    * WebProcess/WebCoreSupport/WebContextMenuClient.h: Define different functions based on
        whether or not CROSS_PLATFORM_CONTEXT_MENUS. 
    * WebProcess/WebPage/WebContextMenu.cpp:
    (WebKit::WebContextMenu::show): Add a branch based on whether or not 
        CROSS_PLATFORM_CONTEXT_MENUS is set.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73802 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    c4728817