Ignore contiguous composition event.
[framework/web/webkit-efl.git] / Source / WebKit2 / Shared / WebContextMenuItemData.cpp
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
28 #if ENABLE(CONTEXT_MENUS)
29
30 #include "WebContextMenuItemData.h"
31
32 #include "APIObject.h"
33 #include "ArgumentCoders.h"
34 #include "Arguments.h"
35 #include <wtf/text/CString.h>
36 #include <WebCore/ContextMenu.h>
37
38 using namespace WebCore;
39
40 namespace WebKit {
41
42 WebContextMenuItemData::WebContextMenuItemData()
43     : m_type(WebCore::ActionType)
44     , m_action(WebCore::ContextMenuItemTagNoAction)
45     , m_enabled(true)
46     , m_checked(false)
47 {
48 }
49
50 WebContextMenuItemData::WebContextMenuItemData(WebCore::ContextMenuItemType type, WebCore::ContextMenuAction action, const String& title, bool enabled, bool checked)
51     : m_type(type)
52     , m_action(action)
53     , m_title(title)
54     , m_enabled(enabled)
55     , m_checked(checked)
56 {
57     ASSERT(type == WebCore::ActionType || type == WebCore::CheckableActionType || type == WebCore::SeparatorType);
58 }
59
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)
62     : m_type(type)
63     , m_action(action)
64     , m_title(title)
65     , m_iconFile(iconFile)
66     , m_enabled(enabled)
67     , m_checked(checked)
68 {
69     ASSERT(type == WebCore::ActionType || type == WebCore::CheckableActionType || type == WebCore::SeparatorType);
70 }
71 #endif
72
73 WebContextMenuItemData::WebContextMenuItemData(WebCore::ContextMenuAction action, const String& title, bool enabled, const Vector<WebContextMenuItemData>& submenu)
74     : m_type(WebCore::SubmenuType)
75     , m_action(action)
76     , m_title(title)
77     , m_enabled(enabled)
78     , m_checked(false)
79     , m_submenu(submenu)
80 {
81 }
82
83 WebContextMenuItemData::WebContextMenuItemData(const WebCore::ContextMenuItem& item, WebCore::ContextMenu* menu)
84     : m_type(item.type())
85     , m_action(item.action())
86     , m_title(item.title())
87 {
88     if (m_type == WebCore::SubmenuType) {
89 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
90         const Vector<WebCore::ContextMenuItem>& coreSubmenu = item.subMenuItems();
91 #else
92         Vector<WebCore::ContextMenuItem> coreSubmenu = WebCore::contextMenuItemVector(item.platformSubMenu());
93 #endif
94         m_submenu = kitItems(coreSubmenu, menu);
95     }
96     
97     m_enabled = item.enabled();
98     m_checked = item.checked();
99 }
100
101 ContextMenuItem WebContextMenuItemData::core() const
102 {
103     if (m_type != SubmenuType)
104         return ContextMenuItem(m_type, m_action, m_title, m_enabled, m_checked);
105     
106     Vector<ContextMenuItem> subMenuItems = coreItems(m_submenu);
107     return ContextMenuItem(m_action, m_title, m_enabled, m_checked, subMenuItems);
108 }
109
110 APIObject* WebContextMenuItemData::userData() const
111 {
112     return m_userData.get();
113 }
114
115 void WebContextMenuItemData::setUserData(APIObject* userData)
116 {
117     m_userData = userData;
118 }
119     
120 void WebContextMenuItemData::encode(CoreIPC::ArgumentEncoder* encoder) const
121 {
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));
123 }
124
125 bool WebContextMenuItemData::decode(CoreIPC::ArgumentDecoder* decoder, WebContextMenuItemData& item)
126 {
127     uint32_t type;
128     uint32_t action;
129     String title;
130     bool checked;
131     bool enabled;
132     Vector<WebContextMenuItemData> submenu;
133
134     if (!decoder->decode(CoreIPC::Out(type, action, title, checked, enabled, submenu)))
135         return false;
136
137     switch (type) {
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);
142         break;
143     case WebCore::SubmenuType:
144         item = WebContextMenuItemData(static_cast<WebCore::ContextMenuAction>(action), title, enabled, submenu);
145         break;
146     default:
147         ASSERT_NOT_REACHED();
148         return false;
149     }
150
151     return true;
152 }
153
154 Vector<WebContextMenuItemData> kitItems(const Vector<WebCore::ContextMenuItem>& coreItemVector, WebCore::ContextMenu* menu)
155 {
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));
160     
161     return result;
162 }
163
164 Vector<ContextMenuItem> coreItems(const Vector<WebContextMenuItemData>& kitItemVector)
165 {
166     Vector<ContextMenuItem> result;
167     result.reserveCapacity(kitItemVector.size());
168     for (unsigned i = 0; i < kitItemVector.size(); ++i)
169         result.append(kitItemVector[i].core());
170     
171     return result;
172 }
173
174 } // namespace WebKit
175 #endif // ENABLE(CONTEXT_MENUS)