1/*
2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#include "config.h"
27#include "WKContextMenuItem.h"
28
29#include "APIArray.h"
30#include "WebContextMenuItem.h"
31#include "WebContextMenuItemData.h"
32#include "WKAPICast.h"
33#include "WKContextMenuItemTypes.h"
34
35WKTypeID WKContextMenuItemGetTypeID()
36{
37#if ENABLE(CONTEXT_MENUS)
38 return WebKit::toAPI(WebKit::WebContextMenuItem::APIType);
39#else
40 return WebKit::toAPI(API::Object::Type::Null);
41#endif
42}
43
44WKContextMenuItemRef WKContextMenuItemCreateAsAction(WKContextMenuItemTag tag, WKStringRef title, bool enabled)
45{
46#if ENABLE(CONTEXT_MENUS)
47 return WebKit::toAPI(&WebKit::WebContextMenuItem::create(WebKit::WebContextMenuItemData(WebCore::ActionType, WebKit::toImpl(tag), WebKit::toImpl(title)->string(), enabled, false)).leakRef());
48#else
49 UNUSED_PARAM(tag);
50 UNUSED_PARAM(title);
51 UNUSED_PARAM(enabled);
52 return nullptr;
53#endif
54}
55
56WKContextMenuItemRef WKContextMenuItemCreateAsCheckableAction(WKContextMenuItemTag tag, WKStringRef title, bool enabled, bool checked)
57{
58#if ENABLE(CONTEXT_MENUS)
59 return WebKit::toAPI(&WebKit::WebContextMenuItem::create(WebKit::WebContextMenuItemData(WebCore::CheckableActionType, WebKit::toImpl(tag), WebKit::toImpl(title)->string(), enabled, checked)).leakRef());
60#else
61 UNUSED_PARAM(tag);
62 UNUSED_PARAM(title);
63 UNUSED_PARAM(enabled);
64 UNUSED_PARAM(checked);
65 return nullptr;
66#endif
67}
68
69WKContextMenuItemRef WKContextMenuItemCreateAsSubmenu(WKStringRef title, bool enabled, WKArrayRef submenuItems)
70{
71#if ENABLE(CONTEXT_MENUS)
72 return WebKit::toAPI(&WebKit::WebContextMenuItem::create(WebKit::toImpl(title)->string(), enabled, WebKit::toImpl(submenuItems)).leakRef());
73#else
74 UNUSED_PARAM(title);
75 UNUSED_PARAM(enabled);
76 UNUSED_PARAM(submenuItems);
77 return nullptr;
78#endif
79}
80
81WKContextMenuItemRef WKContextMenuItemSeparatorItem()
82{
83#if ENABLE(CONTEXT_MENUS)
84 return WebKit::toAPI(WebKit::WebContextMenuItem::separatorItem());
85#else
86 return nullptr;
87#endif
88}
89
90WKContextMenuItemTag WKContextMenuItemGetTag(WKContextMenuItemRef itemRef)
91{
92#if ENABLE(CONTEXT_MENUS)
93 return WebKit::toAPI(WebKit::toImpl(itemRef)->data().action());
94#else
95 UNUSED_PARAM(itemRef);
96 return WebKit::toAPI(WebCore::ContextMenuItemTagNoAction);
97#endif
98}
99
100WKContextMenuItemType WKContextMenuItemGetType(WKContextMenuItemRef itemRef)
101{
102#if ENABLE(CONTEXT_MENUS)
103 return WebKit::toAPI(WebKit::toImpl(itemRef)->data().type());
104#else
105 UNUSED_PARAM(itemRef);
106 return WebKit::toAPI(WebCore::ActionType);
107#endif
108}
109
110WKStringRef WKContextMenuItemCopyTitle(WKContextMenuItemRef itemRef)
111{
112#if ENABLE(CONTEXT_MENUS)
113 return WebKit::toCopiedAPI(WebKit::toImpl(itemRef)->data().title().impl());
114#else
115 UNUSED_PARAM(itemRef);
116 return 0;
117#endif
118}
119
120bool WKContextMenuItemGetEnabled(WKContextMenuItemRef itemRef)
121{
122#if ENABLE(CONTEXT_MENUS)
123 return WebKit::toImpl(itemRef)->data().enabled();
124#else
125 UNUSED_PARAM(itemRef);
126 return false;
127#endif
128}
129
130bool WKContextMenuItemGetChecked(WKContextMenuItemRef itemRef)
131{
132#if ENABLE(CONTEXT_MENUS)
133 return WebKit::toImpl(itemRef)->data().checked();
134#else
135 UNUSED_PARAM(itemRef);
136 return false;
137#endif
138}
139
140WKArrayRef WKContextMenuCopySubmenuItems(WKContextMenuItemRef itemRef)
141{
142#if ENABLE(CONTEXT_MENUS)
143 return WebKit::toAPI(&WebKit::toImpl(itemRef)->submenuItemsAsAPIArray().leakRef());
144#else
145 UNUSED_PARAM(itemRef);
146 return 0;
147#endif
148}
149
150WKTypeRef WKContextMenuItemGetUserData(WKContextMenuItemRef itemRef)
151{
152#if ENABLE(CONTEXT_MENUS)
153 return WebKit::toAPI(WebKit::toImpl(itemRef)->userData());
154#else
155 UNUSED_PARAM(itemRef);
156 return 0;
157#endif
158}
159
160void WKContextMenuItemSetUserData(WKContextMenuItemRef itemRef, WKTypeRef userDataRef)
161{
162#if ENABLE(CONTEXT_MENUS)
163 WebKit::toImpl(itemRef)->setUserData(WebKit::toImpl(userDataRef));
164#else
165 UNUSED_PARAM(itemRef);
166 UNUSED_PARAM(userDataRef);
167#endif
168}
169