2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(CONTEXT_MENUS)
30 #include "WebContextMenuItemData.h"
32 #include "APIObject.h"
33 #include "ArgumentCoders.h"
34 #include "Arguments.h"
35 #include <wtf/text/CString.h>
36 #include <WebCore/ContextMenu.h>
38 using namespace WebCore;
42 WebContextMenuItemData::WebContextMenuItemData()
43 : m_type(WebCore::ActionType)
44 , m_action(WebCore::ContextMenuItemTagNoAction)
50 WebContextMenuItemData::WebContextMenuItemData(WebCore::ContextMenuItemType type, WebCore::ContextMenuAction action, const String& title, bool enabled, bool checked)
57 ASSERT(type == WebCore::ActionType || type == WebCore::CheckableActionType || type == WebCore::SeparatorType);
60 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_ICON_TYPE_SUPPORT)
61 WebContextMenuItemData::WebContextMenuItemData(WebCore::ContextMenuItemType type, WebCore::ContextMenuAction action, const String& title, const String& iconFile, bool enabled, bool checked)
65 , m_iconFile(iconFile)
69 ASSERT(type == WebCore::ActionType || type == WebCore::CheckableActionType || type == WebCore::SeparatorType);
73 WebContextMenuItemData::WebContextMenuItemData(WebCore::ContextMenuAction action, const String& title, bool enabled, const Vector<WebContextMenuItemData>& submenu)
74 : m_type(WebCore::SubmenuType)
83 WebContextMenuItemData::WebContextMenuItemData(const WebCore::ContextMenuItem& item, WebCore::ContextMenu* menu)
85 , m_action(item.action())
86 , m_title(item.title())
88 if (m_type == WebCore::SubmenuType) {
89 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
90 const Vector<WebCore::ContextMenuItem>& coreSubmenu = item.subMenuItems();
92 Vector<WebCore::ContextMenuItem> coreSubmenu = WebCore::contextMenuItemVector(item.platformSubMenu());
94 m_submenu = kitItems(coreSubmenu, menu);
97 m_enabled = item.enabled();
98 m_checked = item.checked();
101 ContextMenuItem WebContextMenuItemData::core() const
103 if (m_type != SubmenuType)
104 return ContextMenuItem(m_type, m_action, m_title, m_enabled, m_checked);
106 Vector<ContextMenuItem> subMenuItems = coreItems(m_submenu);
107 return ContextMenuItem(m_action, m_title, m_enabled, m_checked, subMenuItems);
110 APIObject* WebContextMenuItemData::userData() const
112 return m_userData.get();
115 void WebContextMenuItemData::setUserData(APIObject* userData)
117 m_userData = userData;
120 void WebContextMenuItemData::encode(CoreIPC::ArgumentEncoder* encoder) const
122 encoder->encode(CoreIPC::In(static_cast<uint32_t>(m_type), static_cast<uint32_t>(m_action), m_title, m_checked, m_enabled, m_submenu));
125 bool WebContextMenuItemData::decode(CoreIPC::ArgumentDecoder* decoder, WebContextMenuItemData& item)
132 Vector<WebContextMenuItemData> submenu;
134 if (!decoder->decode(CoreIPC::Out(type, action, title, checked, enabled, submenu)))
138 case WebCore::ActionType:
139 case WebCore::SeparatorType:
140 case WebCore::CheckableActionType:
141 item = WebContextMenuItemData(static_cast<WebCore::ContextMenuItemType>(type), static_cast<WebCore::ContextMenuAction>(action), title, enabled, checked);
143 case WebCore::SubmenuType:
144 item = WebContextMenuItemData(static_cast<WebCore::ContextMenuAction>(action), title, enabled, submenu);
147 ASSERT_NOT_REACHED();
154 Vector<WebContextMenuItemData> kitItems(const Vector<WebCore::ContextMenuItem>& coreItemVector, WebCore::ContextMenu* menu)
156 Vector<WebContextMenuItemData> result;
157 result.reserveCapacity(coreItemVector.size());
158 for (unsigned i = 0; i < coreItemVector.size(); ++i)
159 result.append(WebContextMenuItemData(coreItemVector[i], menu));
164 Vector<ContextMenuItem> coreItems(const Vector<WebContextMenuItemData>& kitItemVector)
166 Vector<ContextMenuItem> result;
167 result.reserveCapacity(kitItemVector.size());
168 for (unsigned i = 0; i < kitItemVector.size(); ++i)
169 result.append(kitItemVector[i].core());
174 } // namespace WebKit
175 #endif // ENABLE(CONTEXT_MENUS)