2 Copyright (C) 2011 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "ewk_hit_test.h"
23 #include "ewk_hit_test_private.h"
24 #include <wtf/text/CString.h>
27 using namespace WebKit;
28 using namespace WebCore;
30 /** Structure used to report hit test result */
31 struct _Ewk_Hit_Test {
32 Ewk_Hit_Test_Result_Context context;
35 CString linkTitle; /**< the title of link */
36 CString linkLabel; /**< the text of the link */
41 CString tagName; /**<tag name for hit element */
42 CString nodeValue; /**<node value for hit element */
43 Eina_Hash* attributeHash; /**<attribute data for hit element */
47 void* buffer; /**<image buffer for hit element */
48 unsigned int length; /**<image buffer length for hit element */
49 CString fileNameExtension; /**<image filename extension for hit element */
53 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
54 static void freeHitTestAttributeHashData(void* data)
56 EINA_SAFETY_ON_NULL_RETURN(data);
57 eina_stringshare_del(static_cast<Eina_Stringshare*>(data));
60 Ewk_Hit_Test* ewkHitTestCreate(WebHitTestResult::Data& hitTestResultData)
62 Ewk_Hit_Test* hitTest = new Ewk_Hit_Test;
64 hitTest->linkURI = hitTestResultData.absoluteLinkURL.utf8();
65 hitTest->linkTitle = hitTestResultData.linkTitle.utf8();
66 hitTest->linkLabel = hitTestResultData.linkLabel.utf8();
67 hitTest->imageURI = hitTestResultData.absoluteImageURL.utf8();
68 hitTest->mediaURI = hitTestResultData.absoluteMediaURL.utf8();
70 int context = hitTestResultData.context;
71 hitTest->context = static_cast<Ewk_Hit_Test_Result_Context>(context);
74 hitTest->nodeData.attributeHash = 0;
75 if (hitTestResultData.hitTestMode & EWK_HIT_TEST_MODE_NODE_DATA) {
76 hitTest->nodeData.tagName = hitTestResultData.nodeData.tagName.utf8();
77 hitTest->nodeData.nodeValue = hitTestResultData.nodeData.nodeValue.utf8();
79 if (!hitTestResultData.nodeData.attributeMap.isEmpty()) {
80 hitTest->nodeData.attributeHash = eina_hash_string_superfast_new(freeHitTestAttributeHashData);
82 WebHitTestResult::Data::NodeData::AttributeMap::iterator attributeMapEnd = hitTestResultData.nodeData.attributeMap.end();
83 for (WebHitTestResult::Data::NodeData::AttributeMap::iterator it = hitTestResultData.nodeData.attributeMap.begin(); it != attributeMapEnd; ++it) {
84 eina_hash_add(hitTest->nodeData.attributeHash, it->first.utf8().data(), eina_stringshare_add(it->second.utf8().data()));
89 hitTest->imageData.buffer = 0;
90 hitTest->imageData.length = 0;
91 if ((hitTestResultData.hitTestMode & EWK_HIT_TEST_MODE_IMAGE_DATA) && (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)) {
92 if (!hitTestResultData.imageData.data.isEmpty()) {
93 hitTest->imageData.length = hitTestResultData.imageData.data.size();
94 hitTest->imageData.fileNameExtension = hitTestResultData.imageData.fileNameExtension.utf8();
96 if (hitTest->imageData.length > 0) {
97 hitTest->imageData.buffer = calloc(1, hitTest->imageData.length);
98 if (hitTest->imageData.buffer)
99 memcpy(hitTest->imageData.buffer, hitTestResultData.imageData.data.data(), hitTest->imageData.length);
108 void ewk_hit_test_free(Ewk_Hit_Test* hitTest)
110 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
111 EINA_SAFETY_ON_NULL_RETURN(hitTest);
113 if (hitTest->nodeData.attributeHash)
114 eina_hash_free(hitTest->nodeData.attributeHash);
116 if (hitTest->imageData.buffer) {
117 free(hitTest->imageData.buffer);
118 hitTest->imageData.buffer = 0;
119 hitTest->imageData.length = 0;
126 Ewk_Hit_Test_Result_Context ewk_hit_test_result_context_get(Ewk_Hit_Test* hitTest)
128 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
129 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT);
131 return hitTest->context;
133 return EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
137 const char* ewk_hit_test_link_uri_get(Ewk_Hit_Test* hitTest)
139 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
140 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
142 return hitTest->linkURI.data();
148 const char* ewk_hit_test_link_title_get(Ewk_Hit_Test* hitTest)
150 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
151 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
153 return hitTest->linkTitle.data();
159 const char* ewk_hit_test_link_label_get(Ewk_Hit_Test* hitTest)
161 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
162 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
164 return hitTest->linkLabel.data();
170 const char* ewk_hit_test_image_uri_get(Ewk_Hit_Test* hitTest)
172 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
173 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
175 return hitTest->imageURI.data();
181 const char* ewk_hit_test_media_uri_get(Ewk_Hit_Test* hitTest)
183 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
184 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
186 return hitTest->mediaURI.data();
192 const char* ewk_hit_test_tag_name_get(Ewk_Hit_Test* hitTest)
194 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
195 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
197 return hitTest->nodeData.tagName.data();
203 const char* ewk_hit_test_node_value_get(Ewk_Hit_Test* hitTest)
205 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
206 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
208 return hitTest->nodeData.nodeValue.data();
214 Eina_Hash* ewk_hit_test_attribute_hash_get(Ewk_Hit_Test* hitTest)
216 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
217 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
219 return hitTest->nodeData.attributeHash;
225 void* ewk_hit_test_image_buffer_get(Ewk_Hit_Test* hitTest)
227 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
228 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
230 return hitTest->imageData.buffer;
236 unsigned int ewk_hit_test_image_buffer_length_get(Ewk_Hit_Test* hitTest)
238 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
239 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
241 return hitTest->imageData.length;
247 const char* ewk_hit_test_image_file_name_extension_get(Ewk_Hit_Test* hitTest)
249 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
250 EINA_SAFETY_ON_NULL_RETURN_VAL(hitTest, 0);
252 return hitTest->imageData.fileNameExtension.data();