| 1 | /* |
| 2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 3 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | |
| 24 | #if ENABLE(CONTEXT_MENUS) |
| 25 | |
| 26 | #include "WebContextMenu.h" |
| 27 | |
| 28 | #include "ContextMenuContextData.h" |
| 29 | #include "UserData.h" |
| 30 | #include "WebCoreArgumentCoders.h" |
| 31 | #include "WebPage.h" |
| 32 | #include "WebPageProxyMessages.h" |
| 33 | #include "WebProcess.h" |
| 34 | #include <WebCore/ContextMenu.h> |
| 35 | #include <WebCore/ContextMenuController.h> |
| 36 | #include <WebCore/Frame.h> |
| 37 | #include <WebCore/FrameView.h> |
| 38 | #include <WebCore/Page.h> |
| 39 | |
| 40 | namespace WebKit { |
| 41 | using namespace WebCore; |
| 42 | |
| 43 | WebContextMenu::(WebPage* page) |
| 44 | : m_page(page) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | WebContextMenu::() |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | void WebContextMenu::() |
| 53 | { |
| 54 | ContextMenuController& controller = m_page->corePage()->contextMenuController(); |
| 55 | Frame* frame = controller.hitTestResult().innerNodeFrame(); |
| 56 | if (!frame) |
| 57 | return; |
| 58 | FrameView* view = frame->view(); |
| 59 | if (!view) |
| 60 | return; |
| 61 | |
| 62 | Vector<WebContextMenuItemData> ; |
| 63 | RefPtr<API::Object> userData; |
| 64 | menuItemsWithUserData(menuItems, userData); |
| 65 | |
| 66 | auto = view->contentsToRootView(controller.hitTestResult().roundedPointInInnerNodeFrame()); |
| 67 | |
| 68 | ContextMenuContextData (menuLocation, menuItems, controller.context()); |
| 69 | |
| 70 | // Mark the WebPage has having a shown context menu then notify the UIProcess. |
| 71 | m_page->contextMenuShowing(); |
| 72 | m_page->send(Messages::WebPageProxy::ShowContextMenu(contextMenuContextData, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get()))); |
| 73 | } |
| 74 | |
| 75 | void WebContextMenu::(const WebContextMenuItemData& item) |
| 76 | { |
| 77 | m_page->corePage()->contextMenuController().contextMenuItemSelected(static_cast<ContextMenuAction>(item.action()), item.title()); |
| 78 | } |
| 79 | |
| 80 | void WebContextMenu::(Vector<WebContextMenuItemData> &, RefPtr<API::Object>& userData) const |
| 81 | { |
| 82 | ContextMenuController& controller = m_page->corePage()->contextMenuController(); |
| 83 | |
| 84 | ContextMenu* = controller.contextMenu(); |
| 85 | if (!menu) |
| 86 | return; |
| 87 | |
| 88 | // Give the bundle client a chance to process the menu. |
| 89 | const Vector<ContextMenuItem>& coreItems = menu->items(); |
| 90 | |
| 91 | if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(*m_page, controller.hitTestResult(), coreItems, menuItems, userData)) |
| 92 | return; |
| 93 | menuItems = kitItems(coreItems); |
| 94 | } |
| 95 | |
| 96 | Vector<WebContextMenuItemData> WebContextMenu::() const |
| 97 | { |
| 98 | Vector<WebContextMenuItemData> ; |
| 99 | RefPtr<API::Object> userData; |
| 100 | menuItemsWithUserData(menuItems, userData); |
| 101 | return menuItems; |
| 102 | } |
| 103 | |
| 104 | } // namespace WebKit |
| 105 | |
| 106 | #endif // ENABLE(CONTEXT_MENUS) |
| 107 | |