2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
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.
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.
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.
24 #if ENABLE(CONTEXT_MENUS)
26 #include "WebContextMenu.h"
28 #include "InjectedBundleHitTestResult.h"
29 #include "InjectedBundleUserMessageCoders.h"
30 #include "WebCoreArgumentCoders.h"
31 #include "WebHitTestResult.h"
33 #include "WebPageProxyMessages.h"
34 #include "WebProcess.h"
35 #include <WebCore/ContextMenu.h>
36 #include <WebCore/ContextMenuController.h>
37 #include <WebCore/Frame.h>
38 #include <WebCore/FrameView.h>
39 #include <WebCore/Page.h>
41 using namespace WebCore;
45 WebContextMenu::WebContextMenu(WebPage* page)
50 WebContextMenu::~WebContextMenu()
54 void WebContextMenu::show()
56 #if ENABLE(CONTEXT_MENUS)
57 ContextMenuController* controller = m_page->corePage()->contextMenuController();
60 ContextMenu* menu = controller->contextMenu();
63 Node* node = controller->hitTestResult().innerNonSharedNode();
66 Frame* frame = node->document()->frame();
69 FrameView* view = frame->view();
73 // Give the bundle client a chance to process the menu.
74 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
75 const Vector<ContextMenuItem>& coreItems = menu->items();
77 Vector<ContextMenuItem> coreItems = contextMenuItemVector(menu->platformDescription());
79 Vector<WebContextMenuItemData> proposedMenu = kitItems(coreItems, menu);
80 Vector<WebContextMenuItemData> newMenu;
81 RefPtr<APIObject> userData;
82 RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(controller->hitTestResult());
83 if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, hitTestResult.get(), proposedMenu, newMenu, userData))
84 proposedMenu = newMenu;
86 WebHitTestResult::Data webHitTestResultData(controller->hitTestResult());
88 // Mark the WebPage has having a shown context menu then notify the UIProcess.
89 m_page->contextMenuShowing();
90 m_page->send(Messages::WebPageProxy::ShowContextMenu(view->contentsToWindow(controller->hitTestResult().roundedPoint()), webHitTestResultData, proposedMenu, InjectedBundleUserMessageEncoder(userData.get())));
94 void WebContextMenu::itemSelected(const WebContextMenuItemData& item)
96 #if !PLATFORM(EFL) || ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
97 ContextMenuItem coreItem(ActionType, static_cast<ContextMenuAction>(item.action()), item.title());
98 m_page->corePage()->contextMenuController()->contextMenuItemSelected(&coreItem);
102 #if ENABLE(TIZEN_CONTEXT_CLICK)
103 Vector<WebContextMenuItemData> WebContextMenu::items() const
105 Vector<WebContextMenuItemData> proposedMenu;
106 #if ENABLE(CONTEXT_MENUS)
107 ContextMenuController* controller = m_page->corePage()->contextMenuController();
110 ContextMenu* menu = controller->contextMenu();
114 // Give the bundle client a chance to process the menu.
115 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
116 const Vector<ContextMenuItem>& coreItems = menu->items();
118 Vector<ContextMenuItem> coreItems = contextMenuItemVector(menu->platformDescription());
120 proposedMenu = kitItems(coreItems, menu);
121 Vector<WebContextMenuItemData> newMenu;
122 RefPtr<APIObject> userData;
123 RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(controller->hitTestResult());
124 if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, hitTestResult.get(), proposedMenu, newMenu, userData))
125 proposedMenu = newMenu;
131 } // namespace WebKit
133 #endif // ENABLE(CONTEXT_MENUS)