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 "MutableArray.h"
30 #include "WebContextMenuItem.h"
31 #include "WebContextMenuItemData.h"
32 #include "WKAPICast.h"
33 #include "WKContextMenuItemTypes.h"
34
35 using namespace WebCore;
36 using namespace WebKit;
37
WKContextMenuItemGetTypeID()38 WKTypeID WKContextMenuItemGetTypeID()
39 {
40 return toAPI(WebContextMenuItem::APIType);
41 }
42
WKContextMenuItemCreateAsAction(WKContextMenuItemTag tag,WKStringRef title,bool enabled)43 WKContextMenuItemRef WKContextMenuItemCreateAsAction(WKContextMenuItemTag tag, WKStringRef title, bool enabled)
44 {
45 return toAPI(WebContextMenuItem::create(WebContextMenuItemData(ActionType, toImpl(tag), toImpl(title)->string(), enabled, false)).leakRef());
46 }
47
WKContextMenuItemCreateAsCheckableAction(WKContextMenuItemTag tag,WKStringRef title,bool enabled,bool checked)48 WKContextMenuItemRef WKContextMenuItemCreateAsCheckableAction(WKContextMenuItemTag tag, WKStringRef title, bool enabled, bool checked)
49 {
50 return toAPI(WebContextMenuItem::create(WebContextMenuItemData(CheckableActionType, toImpl(tag), toImpl(title)->string(), enabled, checked)).leakRef());
51 }
52
WKContextMenuItemCreateAsSubmenu(WKStringRef title,bool enabled,WKArrayRef submenuItems)53 WKContextMenuItemRef WKContextMenuItemCreateAsSubmenu(WKStringRef title, bool enabled, WKArrayRef submenuItems)
54 {
55 return toAPI(WebContextMenuItem::create(toImpl(title)->string(), enabled, toImpl(submenuItems)).leakRef());
56 }
57
WKContextMenuItemSeparatorItem()58 WKContextMenuItemRef WKContextMenuItemSeparatorItem()
59 {
60 return toAPI(WebContextMenuItem::separatorItem());
61 }
62
WKContextMenuItemGetTag(WKContextMenuItemRef itemRef)63 WKContextMenuItemTag WKContextMenuItemGetTag(WKContextMenuItemRef itemRef)
64 {
65 return toAPI(toImpl(itemRef)->data()->action());
66 }
67
WKContextMenuItemGetType(WKContextMenuItemRef itemRef)68 WKContextMenuItemType WKContextMenuItemGetType(WKContextMenuItemRef itemRef)
69 {
70 return toAPI(toImpl(itemRef)->data()->type());
71 }
72
WKContextMenuItemCopyTitle(WKContextMenuItemRef itemRef)73 WKStringRef WKContextMenuItemCopyTitle(WKContextMenuItemRef itemRef)
74 {
75 return toCopiedAPI(toImpl(itemRef)->data()->title().impl());
76 }
77
WKContextMenuItemGetEnabled(WKContextMenuItemRef itemRef)78 bool WKContextMenuItemGetEnabled(WKContextMenuItemRef itemRef)
79 {
80 return toImpl(itemRef)->data()->enabled();
81 }
82
WKContextMenuItemGetChecked(WKContextMenuItemRef itemRef)83 bool WKContextMenuItemGetChecked(WKContextMenuItemRef itemRef)
84 {
85 return toImpl(itemRef)->data()->checked();
86 }
87
WKContextMenuCopySubmenuItems(WKContextMenuItemRef itemRef)88 WKArrayRef WKContextMenuCopySubmenuItems(WKContextMenuItemRef itemRef)
89 {
90 return toAPI(toImpl(itemRef)->submenuItemsAsImmutableArray().leakRef());
91 }
92
WKContextMenuItemGetUserData(WKContextMenuItemRef itemRef)93 WKTypeRef WKContextMenuItemGetUserData(WKContextMenuItemRef itemRef)
94 {
95 return toAPI(toImpl(itemRef)->userData());
96 }
97
WKContextMenuItemSetUserData(WKContextMenuItemRef itemRef,WKTypeRef userDataRef)98 void WKContextMenuItemSetUserData(WKContextMenuItemRef itemRef, WKTypeRef userDataRef)
99 {
100 toImpl(itemRef)->setUserData(toImpl(userDataRef));
101 }
102