[EFL][WK2] Implemented color picker API
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / efl / ewk_popup_menu_item.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" 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 THE COPYRIGHT HOLDER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ewk_popup_menu_item.h"
28
29 #include "WKEinaSharedString.h"
30 #include "ewk_popup_menu_item_private.h"
31 #include "ewk_private.h"
32 #include <wtf/text/CString.h>
33
34 using namespace WebKit;
35
36 /**
37  * \struct  _Ewk_Popup_Menu_Item
38  * @brief   Contains the popup menu data.
39  */
40 struct _Ewk_Popup_Menu_Item {
41     Ewk_Popup_Menu_Item_Type type;
42     Ewk_Text_Direction textDirection;
43
44     bool hasTextDirectionOverride;
45     bool isEnabled;
46     bool isLabel;
47     bool isSelected;
48
49     WKEinaSharedString text;
50     WKEinaSharedString toolTip;
51     WKEinaSharedString accessibilityText;
52
53     explicit _Ewk_Popup_Menu_Item(const WebKit::WebPopupItem& item)
54         : type(static_cast<Ewk_Popup_Menu_Item_Type>(item.m_type))
55         , textDirection(static_cast<Ewk_Text_Direction>(item.m_textDirection))
56         , hasTextDirectionOverride(item.m_hasTextDirectionOverride)
57         , isEnabled(item.m_isEnabled)
58         , isLabel(item.m_isLabel)
59         , isSelected(item.m_isSelected)
60         , text(item.m_text.utf8().data())
61         , toolTip(item.m_toolTip.utf8().data())
62         , accessibilityText(item.m_accessibilityText.utf8().data())
63     { }
64 };
65
66 COMPILE_ASSERT_MATCHING_ENUM(EWK_POPUP_MENU_SEPARATOR, WebPopupItem::Separator);
67 COMPILE_ASSERT_MATCHING_ENUM(EWK_POPUP_MENU_ITEM, WebPopupItem::Item);
68
69 /**
70  * @internal
71  * Constructs a Ewk_Popup_Menu_Item.
72  */
73 Ewk_Popup_Menu_Item* ewk_popup_menu_item_new(const WebKit::WebPopupItem& item)
74 {
75     return new Ewk_Popup_Menu_Item(item);
76 }
77
78 /**
79  * @internal
80  * Frees a Ewk_Popup_Menu_Item.
81  */
82 void ewk_popup_menu_item_free(Ewk_Popup_Menu_Item* item)
83 {
84     EINA_SAFETY_ON_NULL_RETURN(item);
85     delete item;
86 }
87
88 Ewk_Popup_Menu_Item_Type ewk_popup_menu_item_type_get(const Ewk_Popup_Menu_Item* item)
89 {
90     EINA_SAFETY_ON_NULL_RETURN_VAL(item, EWK_POPUP_MENU_UNKNOWN);
91
92     return item->type;
93 }
94
95 const char* ewk_popup_menu_item_text_get(const Ewk_Popup_Menu_Item* item)
96 {
97     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
98
99     return item->text;
100 }
101
102 Ewk_Text_Direction ewk_popup_menu_item_text_direction_get(const Ewk_Popup_Menu_Item* item)
103 {
104     EINA_SAFETY_ON_NULL_RETURN_VAL(item, EWK_TEXT_DIRECTION_LEFT_TO_RIGHT);
105
106     return item->textDirection;
107 }
108
109 Eina_Bool ewk_popup_menu_item_text_direction_override_get(const Ewk_Popup_Menu_Item* item)
110 {
111     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
112
113     return item->hasTextDirectionOverride;
114 }
115
116 const char* ewk_popup_menu_item_tooltip_get(const Ewk_Popup_Menu_Item* item)
117 {
118     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
119
120     return item->toolTip;
121 }
122
123 const char* ewk_popup_menu_item_accessibility_text_get(const Ewk_Popup_Menu_Item* item)
124 {
125     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
126
127     return item->accessibilityText;
128 }
129
130 Eina_Bool ewk_popup_menu_item_enabled_get(const Ewk_Popup_Menu_Item* item)
131 {
132     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
133
134     return item->isEnabled;
135 }
136
137 Eina_Bool ewk_popup_menu_item_is_label_get(const Ewk_Popup_Menu_Item* item)
138 {
139     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
140
141     return item->isLabel;
142 }
143
144 Eina_Bool ewk_popup_menu_item_selected_get(const Ewk_Popup_Menu_Item* item)
145 {
146     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
147
148     return item->isSelected;
149 }