c2c8acc1650b123dae391aa520901508f39134f8
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / InputPicker.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "InputPicker.h"
22
23 #include "ewk_view.h"
24
25 #include <Elementary.h>
26
27 #include <ctime>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
32 #include <dlfcn.h>
33 #include <efl_assist.h>
34 extern void* EflAssistHandle;
35 #endif
36
37 #if OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
38
39 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
40 static inline void _picker_back_cb(void* data, Evas_Object* obj, void* event_info)
41 {
42     elm_object_signal_emit(obj, "picker,hide", "");
43 }
44
45 static void _edit_start_cb(void* data, Evas_Object* obj, void* event_info)
46 {
47     if (!EflAssistHandle)
48         return;
49
50     void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
51     webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
52     (*webkit_ea_object_event_callback_add)(obj, EA_CALLBACK_BACK, _picker_back_cb, 0);
53 }
54
55 static void _edit_end_cb(void* data, Evas_Object* obj, void* event_info)
56 {
57     if (!EflAssistHandle)
58         return;
59
60     void (*webkit_ea_object_event_callback_del)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func);
61     webkit_ea_object_event_callback_del = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func))dlsym(EflAssistHandle, "ea_object_event_callback_del");
62     (*webkit_ea_object_event_callback_del)(obj, EA_CALLBACK_BACK, _picker_back_cb);
63 }
64 #endif // ENABLE(TIZEN_HW_MORE_BACK_KEY)
65
66 Input_Picker_Layout::Input_Picker_Layout(Evas_Object* ewkView)
67     : m_ewkView(ewkView)
68     , popup(0)
69     , layout(0)
70     , timePicker(0)
71     , datePicker(0)
72     , colorRect(0)
73     , okButton(0)
74     , dataListEditField(0)
75 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
76     , initial_r(0)
77     , initial_g(0)
78     , initial_b(0)
79 #endif
80     , datetimeLocal(false)
81 {
82     evas_object_focus_set(m_ewkView, false);
83
84     /* FIXME : Workaround. OSP requirement.
85        OSP want to block own touch event while webkit internal picker is running. */
86     evas_object_smart_callback_call(m_ewkView, "input,picker,show", 0);
87 }
88
89 Input_Picker_Layout::~Input_Picker_Layout()
90 {
91     /* FIXME : Workaround. OSP requirement.
92        OSP want to block own touch event while webkit internal picker is running. */
93     evas_object_smart_callback_call(m_ewkView, "input,picker,hide", 0);
94 }
95
96 namespace WebKit {
97
98 InputPicker::InputPicker(Evas_Object* ewkView)
99     : m_ewkView(ewkView)
100     , m_pickerLayout(0)
101     , m_dataList(0)
102 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
103     , m_isColorPickerShown(false)
104 #endif
105 {
106 }
107
108 InputPicker::~InputPicker()
109 {
110     if (m_pickerLayout) {
111         if (m_pickerLayout->popup)
112             evas_object_del(m_pickerLayout->popup);
113         delete m_pickerLayout;
114     }
115 }
116
117 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
118 {
119     if(inputType == EWK_INPUT_TYPE_DATE)
120         ewk_date_popup(inputValue);
121     else if(inputType == EWK_INPUT_TYPE_TIME)
122         ewk_time_popup(inputValue);
123     else if(inputType == EWK_INPUT_TYPE_DATETIME)
124         ewk_datetime_popup(inputValue, false);
125     else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
126         ewk_datetime_popup(inputValue, true);
127     else if(inputType == EWK_INPUT_TYPE_MONTH)
128         ewk_month_popup(inputValue);
129     else if(inputType == EWK_INPUT_TYPE_WEEK)
130         ewk_week_popup(inputValue);
131 }
132
133 #if ENABLE(TIZEN_DATALIST_ELEMENT)
134 void InputPicker::_data_list_popup_response_cb(void* data,  Evas_Object* obj, void* eventInfo)
135 {
136     InputPicker* inputPicker = static_cast<InputPicker*>(data);
137     const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
138     ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
139
140     if (inputPicker->m_pickerLayout->popup) {
141         evas_object_del(inputPicker->m_pickerLayout->popup);
142         inputPicker->m_pickerLayout->popup = 0;
143     }
144
145     delete inputPicker->m_pickerLayout;
146     inputPicker->m_pickerLayout = 0;
147
148     inputPicker->m_dataList = 0;
149 }
150
151 void InputPicker::_data_list_popup_response_cancel_cb(void* data,  Evas_Object* obj, void* eventInfo)
152 {
153     InputPicker* inputPicker = static_cast<InputPicker*>(data);
154
155     if (inputPicker->m_pickerLayout->popup) {
156         evas_object_del(inputPicker->m_pickerLayout->popup);
157         inputPicker->m_pickerLayout->popup = 0;
158     }
159
160     delete inputPicker->m_pickerLayout;
161     inputPicker->m_pickerLayout = 0;
162
163     inputPicker->m_dataList = 0;
164 }
165
166 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
167 {
168     InputPicker* inputPicker = static_cast<InputPicker*>(data);
169     Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
170     Elm_Object_Item* item = elm_list_first_item_get(obj);
171
172     int index = 0;
173     while (item) {
174         if (item == selectedItem)
175             break;
176         index++;
177         item = elm_list_item_next(item);
178     }
179
180     Eina_List* list = 0;
181     void* listItem = 0;
182     int listIndex = 0;
183     EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
184         if (listItem && index == listIndex)
185             elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
186
187         listIndex++;
188     }
189 }
190
191 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
192 {
193     Evas_Object* entry = static_cast<Evas_Object*>(data);
194     elm_entry_entry_set(entry, "");
195 }
196
197 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
198 {
199     Evas_Object* layout = static_cast<Evas_Object*>(data);
200
201     if (elm_object_focus_get(layout)) {
202         if (elm_entry_is_empty(obj))
203             elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
204         else
205             elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
206     }
207 }
208
209 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
210 {
211     Evas_Object* layout = static_cast<Evas_Object*>(data);
212
213     if (!elm_entry_is_empty(obj))
214         elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
215 }
216
217 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
218 {
219     Evas_Object* layout = static_cast<Evas_Object*>(data);
220     elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
221 }
222
223 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
224 {
225     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
226     Evas_Object* win = parent;
227
228     m_dataList = optionList;
229
230     if (m_pickerLayout)
231         return;
232
233     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
234
235     /* FIXME: If the entry is in the popup, the parent should be naviframe for uifw limitation. */
236     Evas_Object* naviframe = elm_naviframe_add(m_ewkView);
237     while (parent) {
238         const char* type = elm_object_widget_type_get(parent);
239         if (type) {
240             if (!strcmp(type, elm_object_widget_type_get(naviframe))) {
241                 win =  parent;
242                 break;
243             }
244         }
245         parent = elm_object_parent_widget_get(parent);
246     }
247
248     evas_object_del(naviframe);
249
250     if (!win)
251         win = m_ewkView;
252
253     m_pickerLayout->popup = elm_popup_add(win);
254     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
255
256 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
257     if (EflAssistHandle) {
258         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
259         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
260         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _data_list_popup_response_cancel_cb, this);
261     }
262 #endif
263
264     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
265     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
266     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
267     evas_object_show(m_pickerLayout->layout);
268     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
269
270     Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
271     Eina_List* list = 0;
272     void* listItem = 0;
273     EINA_LIST_FOREACH(optionList, list, listItem) {
274         if (listItem)
275             elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
276     }
277     evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
278     evas_object_show(elmList);
279     elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
280
281     Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
282     elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
283
284     m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
285     elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
286
287     elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
288     elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
289     evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
290     evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
291     evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
292
293     elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
294     evas_object_show(editFieldLayout);
295
296     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
297     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
298     elm_object_text_set(m_pickerLayout->okButton, "OK");
299     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
300     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
301     evas_object_show(m_pickerLayout->popup);
302     evas_object_focus_set(m_pickerLayout->okButton, true);
303
304     Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
305     elm_object_style_set(cancelButton, "popup_button/default");
306     elm_object_text_set(cancelButton, "Cancel");
307     elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
308     evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
309     evas_object_show(cancelButton);
310 }
311
312 void InputPicker::hideDataList(Ewk_Input_Type inputType)
313 {
314     if (!m_dataList)
315         return;
316
317     if(m_pickerLayout->popup){
318         evas_object_del(m_pickerLayout->popup);
319         m_pickerLayout->popup = 0;
320     }
321
322     delete m_pickerLayout;
323     m_pickerLayout = 0;
324
325     m_dataList = 0;
326 }
327 #endif
328
329 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
330 void InputPicker::showColorPicker(int r, int g, int b, int)
331 {
332     m_isColorPickerShown = true;
333     ewk_color_popup(r, g, b);
334 }
335
336 void InputPicker::hideColorPicker()
337 {
338     m_isColorPickerShown = false;
339     if (!m_pickerLayout)
340         return;
341
342     if (m_pickerLayout->popup) {
343         evas_object_del(m_pickerLayout->popup);
344         m_pickerLayout->popup = 0;
345     }
346
347     delete m_pickerLayout;
348     m_pickerLayout = 0;
349 }
350 #endif
351
352 #if ENABLE(ELM_COLORPALLETE)
353 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
354 {
355     int r = 0;
356     int g = 0;
357     int b = 0;
358     int a = 0;
359     Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
360     elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
361     evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
362 }
363 #endif
364
365 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
366 {
367     int r = 0;
368     int g = 0;
369     int b = 0;
370     int a = 0;
371     evas_object_color_get(obj, &r, &g, &b, &a);
372
373     evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
374 }
375
376 void InputPicker::ewk_color_popup(int r, int g, int b)
377 {
378     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
379     Evas_Object* win = parent;
380
381     if (m_pickerLayout)
382         return;
383
384     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
385
386     while (parent) {
387         const char* type = elm_object_widget_type_get(parent);
388         if (type) {
389             if (!strcmp(type, "elm_win")) {
390                 win =  parent;
391                 break;
392             }
393         }
394         parent = elm_object_parent_widget_get(parent);
395     }
396
397     if (!win)
398     win = m_ewkView;
399
400     m_pickerLayout->popup = elm_popup_add(win);
401     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
402
403 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
404     m_pickerLayout->initial_r = r;
405     m_pickerLayout->initial_g = g;
406     m_pickerLayout->initial_b = b;
407     if (EflAssistHandle) {
408         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
409         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
410         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _color_back_cb, this);
411     }
412 #endif
413
414     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
415     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
416     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
417     evas_object_show(m_pickerLayout->layout);
418     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
419
420     m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
421     evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
422     evas_object_show(m_pickerLayout->colorRect);
423
424     evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
425     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
426 #if ENABLE(ELM_COLORPALLETE)
427     Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
428     elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
429
430     elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
431     elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
432     elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
433     elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
434     elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
435     elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
436     elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
437     elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
438     elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
439     elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
440     elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
441     elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
442
443     evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
444     evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
445     evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
446     evas_object_show(colorPalette);
447
448     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
449 #else
450     Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
451     evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
452     evas_object_color_set(color1, 128, 0, 0, 255);
453     evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
454     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
455     evas_object_show(color1);
456
457     Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
458     evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
459     evas_object_color_set(color2, 255, 0, 128, 255);
460     evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
461     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
462     evas_object_show(color2);
463
464     Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
465     evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
466     evas_object_color_set(color3, 255, 0, 0, 255);
467     evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
468     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
469     evas_object_show(color3);
470
471     Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
472     evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
473     evas_object_color_set(color4, 255, 127, 39, 255);
474     evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
475     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
476     evas_object_show(color4);
477
478     Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
479     evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
480     evas_object_color_set(color5, 255, 255, 0, 255);
481     evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
482     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
483     evas_object_show(color5);
484
485     Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
486     evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
487     evas_object_color_set(color6, 0, 255, 0, 255);
488     evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
489     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
490     evas_object_show(color6);
491
492     Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
493     evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
494     evas_object_color_set(color7, 0, 255, 255, 255);
495     evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
496     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
497     evas_object_show(color7);
498
499     Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
500     evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
501     evas_object_color_set(color8, 0, 0, 255, 255);
502     evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
503     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
504     evas_object_show(color8);
505
506     Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
507     evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
508     evas_object_color_set(color9, 0, 0, 128, 255);
509     evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
510     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
511     evas_object_show(color9);
512
513     Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
514     evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
515     evas_object_color_set(color10, 64, 0, 64, 255);
516     evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
517     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
518     evas_object_show(color10);
519
520     Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
521     evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
522     evas_object_color_set(color11, 153, 217, 234, 255);
523     evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
524     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
525     evas_object_show(color11);
526
527     Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
528     evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
529     evas_object_color_set(color12, 128, 128, 128, 255);
530     evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
531     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
532     evas_object_show(color12);
533
534     Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
535     evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
536     evas_object_color_set(color13, 0, 0, 0, 255);
537     evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
538     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
539     evas_object_show(color13);
540
541     Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
542     evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
543     evas_object_color_set(color14, 255, 255, 255, 255);
544     evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
545     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
546     evas_object_show(color14);
547 #endif
548     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
549     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
550     elm_object_text_set(m_pickerLayout->okButton, "OK");
551     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
552     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
553     evas_object_focus_set(m_pickerLayout->okButton, true);
554
555     evas_object_show(m_pickerLayout->popup);
556 }
557
558 void InputPicker::_color_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
559 {
560     InputPicker* inputPicker = static_cast<InputPicker*>(data);
561
562     int r = 0;
563     int g = 0;
564     int b = 0;
565     int a = 0;
566     evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
567
568     ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
569
570     inputPicker->hideColorPicker();
571 }
572
573 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
574 void InputPicker::_color_back_cb(void* data,  Evas_Object* obj, void* event_info)
575 {
576     InputPicker* inputPicker = static_cast<InputPicker*>(data);
577
578     int r = inputPicker->m_pickerLayout->initial_r;
579     int g = inputPicker->m_pickerLayout->initial_g;
580     int b = inputPicker->m_pickerLayout->initial_b;
581     int a = 255;
582     ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
583
584     inputPicker->hideColorPicker();
585 }
586 #endif
587
588 void InputPicker::ewk_date_popup(const char* inputValue)
589 {
590     struct tm* currentTime;
591     time_t cur_time;
592     time(&cur_time);
593     currentTime = localtime(&cur_time);
594
595     Input_Date_Str dateStr;
596     memset(&dateStr, 0, sizeof(Input_Date_Str));
597
598     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
599     Evas_Object* win = parent;
600
601     if (inputValue && strlen(inputValue)) {
602         char tmpinputValue[30] = {0,};
603
604         sprintf(tmpinputValue, "%s", inputValue);
605         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
606         strcpy(dateStr.mon, strtok(0, "-"));
607         strcpy(dateStr.day, strtok(0, "-"));
608
609         currentTime->tm_year = atoi(dateStr.year);
610         currentTime->tm_mon = atoi(dateStr.mon);
611         currentTime->tm_mday = atoi(dateStr.day);
612
613         currentTime->tm_year = currentTime->tm_year - 1900;
614         currentTime->tm_mon = currentTime->tm_mon - 1;
615     }
616
617     if (m_pickerLayout) {
618         // Just update the value.
619         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
620         evas_object_focus_set(m_pickerLayout->okButton, true);
621         return;
622     }
623
624     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
625
626     while (parent) {
627         const char* type = elm_object_widget_type_get(parent);
628         if (type) {
629             if (!strcmp(type, "elm_win")) {
630                 win =  parent;
631                 break;
632             }
633         }
634         parent = elm_object_parent_widget_get(parent);
635     }
636
637     if (!win)
638         win = m_ewkView;
639
640     m_pickerLayout->popup = elm_popup_add(win);
641     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
642
643 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
644     if (EflAssistHandle) {
645         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
646         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
647         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
648     }
649 #endif
650
651     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
652     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
653     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
654
655     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
656
657     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
658     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
659
660     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
661     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
662     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
663     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
664
665 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
666     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
667     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
668 #endif
669
670     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
671     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
672     elm_object_text_set(m_pickerLayout->okButton, "OK");
673     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
674     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
675     evas_object_focus_set(m_pickerLayout->okButton, true);
676
677     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
678     evas_object_show(m_pickerLayout->popup);
679 }
680
681 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
682 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
683 {
684     // Jan.
685     if (totalDays - 31 < 0) {
686         *remains = totalDays;
687         return 0;
688     }
689
690     totalDays = totalDays - 31;
691
692     // Feb.
693     if (isLeapYear(year)) {
694         if (totalDays - 29 < 0) {
695             *remains = totalDays;
696             return 1;
697         }
698         totalDays = totalDays - 29;
699     } else {
700         if (totalDays - 28 < 0) {
701             *remains = totalDays;
702             return 1;
703         }
704         totalDays = totalDays - 28;
705     }
706
707     // Mar.
708     if (totalDays - 31 < 0) {
709         *remains = totalDays;
710         return 2;
711     }
712     totalDays = totalDays - 31;
713
714     // Apr.
715     if (totalDays - 30 < 0) {
716         *remains = totalDays;
717         return 3;
718     }
719     totalDays = totalDays - 30;
720
721     // May
722     if (totalDays - 31 < 0) {
723         *remains = totalDays;
724         return 4;
725     }
726     totalDays = totalDays - 31;
727
728     // Jun.
729     if (totalDays - 30 < 0) {
730         *remains = totalDays;
731         return 5;
732     }
733     totalDays = totalDays - 30;
734
735     // Jul.
736     if (totalDays - 31 < 0) {
737         *remains = totalDays;
738         return 6;
739     }
740     totalDays = totalDays - 31;
741
742     // Aug.
743     if (totalDays - 31 < 0) {
744         *remains = totalDays;
745         return 7;
746     }
747     totalDays = totalDays - 31;
748
749     // Sept.
750     if (totalDays - 30 < 0) {
751         *remains = totalDays;
752         return 8;
753     }
754     totalDays = totalDays - 30;
755
756     // Oct.
757     if (totalDays - 31 < 0) {
758         *remains = totalDays;
759         return 9;
760     }
761     totalDays = totalDays - 31;
762
763     // Nov.
764     if (totalDays - 30 < 0) {
765         *remains = totalDays;
766         return 10;
767     }
768     totalDays = totalDays - 30;
769
770     *remains = totalDays;
771     return 11;
772 }
773
774 void InputPicker::ewk_week_popup(const char* inputValue)
775 {
776     struct tm* currentTime;
777     time_t cur_time;
778     time(&cur_time);
779     currentTime = localtime(&cur_time);
780
781     Input_Date_Str dateStr;
782     memset(&dateStr, 0, sizeof(Input_Date_Str));
783
784     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
785     Evas_Object* win = parent;
786
787     if (inputValue && strlen(inputValue)) {
788         char tmpinputValue[30] = {0,};
789
790         sprintf(tmpinputValue, "%s", inputValue);
791         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
792         const char* week = strstr(inputValue, "W");
793         int weekNum = 1;
794         if (week)
795             weekNum = atoi(week + 1);
796
797         currentTime->tm_year = atoi(dateStr.year);
798         currentTime->tm_year = currentTime->tm_year - 1900;
799
800         struct tm firtTimeOfyear;
801         memset(&firtTimeOfyear, 0, sizeof(struct tm));
802         firtTimeOfyear.tm_year = currentTime->tm_year;
803         firtTimeOfyear.tm_mon = 0;
804         firtTimeOfyear.tm_mday = 1;
805         mktime(&firtTimeOfyear);
806
807         char firstWeek[10] = {0, };
808         strftime(firstWeek, 10, "%w", &firtTimeOfyear);
809         int firstWeekCount = atoi(firstWeek);
810
811         int totalDays = 1;
812
813         totalDays = weekNum * 7 - firstWeekCount;
814
815         int days = 0;
816         int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
817
818         currentTime->tm_mon = month;
819         currentTime->tm_mday = days;
820     }
821
822     if (m_pickerLayout) {
823         // Just update the value.
824         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
825         evas_object_focus_set(m_pickerLayout->okButton, true);
826         return;
827     }
828
829     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
830
831     while (parent) {
832         const char* type = elm_object_widget_type_get(parent);
833         if (type) {
834             if (!strcmp(type, "elm_win")) {
835                 win =  parent;
836                 break;
837             }
838         }
839         parent = elm_object_parent_widget_get(parent);
840     }
841
842     if (!win)
843         win = m_ewkView;
844
845     m_pickerLayout->popup = elm_popup_add(win);
846     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
847
848 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
849     if (EflAssistHandle) {
850         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
851         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
852         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
853     }
854 #endif
855
856     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
857     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
858     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
859
860     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
861
862     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
863     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
864
865     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
866     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
867     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
868     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
869
870 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
871     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
872     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
873 #endif
874
875     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
876     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
877     elm_object_text_set(m_pickerLayout->okButton, "OK");
878     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
879     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
880     evas_object_focus_set(m_pickerLayout->okButton, true);
881
882     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
883     evas_object_show(m_pickerLayout->popup);
884 }
885
886 void InputPicker::ewk_time_popup(const char* inputValue)
887 {
888     struct tm* currentTime;
889     time_t  cur_time;
890     time(&cur_time);
891     currentTime = localtime(&cur_time);
892
893     Input_Date_Str dateStr;
894     memset(&dateStr, 0, sizeof(Input_Date_Str));
895
896     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
897     Evas_Object* win = parent;
898
899     if (inputValue && strlen(inputValue)) {
900         char tmpinputValue[30] = {0,};
901
902         sprintf(tmpinputValue, "%s", inputValue);
903         strcpy(dateStr.hour, strtok(tmpinputValue,":"));
904         strcpy(dateStr.min, strtok(0, ":"));
905
906         currentTime->tm_hour = atoi(dateStr.hour);
907         currentTime->tm_min = atoi(dateStr.min);
908     }
909
910     if (m_pickerLayout) {
911         // Just update the value.
912         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
913         evas_object_focus_set(m_pickerLayout->okButton, true);
914         return;
915     }
916
917     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
918
919     while (parent) {
920         const char* type = elm_object_widget_type_get(parent);
921         if (type) {
922             if (!strcmp(type, "elm_win")) {
923                 win =  parent;
924                 break;
925             }
926         }
927         parent = elm_object_parent_widget_get(parent);
928     }
929
930     if (!win)
931         win = m_ewkView;
932
933     m_pickerLayout->popup = elm_popup_add(win);
934     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
935
936 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
937     if (EflAssistHandle) {
938         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
939         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
940         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
941     }
942 #endif
943
944     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
945     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
946     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
947
948     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
949
950     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
951     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
952     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
953     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
954
955 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
956     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,start", _edit_start_cb, 0);
957     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,end", _edit_end_cb, 0);
958 #endif
959
960     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
961     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
962     elm_object_text_set(m_pickerLayout->okButton, "OK");
963     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
964     evas_object_focus_set(m_pickerLayout->okButton, true);
965
966     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
967     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
968     evas_object_show(m_pickerLayout->popup);
969 }
970
971 void InputPicker::ewk_month_popup(const char* inputValue)
972 {
973     struct tm* currentTime;
974     time_t  cur_time;
975     time(&cur_time);
976     currentTime = localtime(&cur_time);
977
978     Input_Date_Str dateStr;
979     memset(&dateStr, 0, sizeof(Input_Date_Str));
980
981     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
982     Evas_Object* win = parent;
983
984     if (inputValue && strlen(inputValue)) {
985         char tmpInputValue[30] = {0,};
986
987         sprintf(tmpInputValue, "%s", inputValue);
988         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
989         strcpy(dateStr.mon, strtok(0, "-"));
990
991         currentTime->tm_year = atoi(dateStr.year);
992         currentTime->tm_mon = atoi(dateStr.mon);
993
994         currentTime->tm_year = currentTime->tm_year - 1900;
995         currentTime->tm_mon = currentTime->tm_mon - 1;
996     }
997
998     if (m_pickerLayout) {
999         // Just update the value.
1000         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1001         evas_object_focus_set(m_pickerLayout->okButton, true);
1002         return;
1003     }
1004
1005     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
1006
1007     while (parent) {
1008         const char* type = elm_object_widget_type_get(parent);
1009         if (type) {
1010             if (!strcmp(type, "elm_win")) {
1011                 win =  parent;
1012                 break;
1013             }
1014         }
1015         parent = elm_object_parent_widget_get(parent);
1016     }
1017
1018     if (!win)
1019         win = m_ewkView;
1020
1021     m_pickerLayout->popup = elm_popup_add(win);
1022     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
1023
1024 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1025     if (EflAssistHandle) {
1026         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
1027         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
1028         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
1029     }
1030 #endif
1031
1032     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1033     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
1034
1035     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1036
1037     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1038     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1039     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text",  "Month (Default format) :");
1040     elm_datetime_format_set(m_pickerLayout->datePicker, "%Y %m");
1041     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date",  m_pickerLayout->datePicker);
1042
1043 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1044     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
1045     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
1046 #endif
1047
1048     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1049     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1050     elm_object_text_set(m_pickerLayout->okButton, "OK");
1051     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1052     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
1053     evas_object_focus_set(m_pickerLayout->okButton, true);
1054
1055     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1056     evas_object_show(m_pickerLayout->popup);
1057 }
1058
1059 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
1060 {
1061     struct tm* currentTime;
1062     time_t  cur_time;
1063     time(&cur_time);
1064     currentTime = localtime(&cur_time);
1065
1066     Input_Date_Str dateStr;
1067     memset(&dateStr, 0, sizeof(Input_Date_Str));
1068
1069     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
1070     Evas_Object* win = parent;
1071
1072     if (inputValue && strlen(inputValue)) {
1073         char tmpInputValue[30] = {0, };
1074
1075         sprintf(tmpInputValue, "%s", inputValue);
1076         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
1077         strcpy(dateStr.mon, strtok(0, "-"));
1078         strcpy(dateStr.day, strtok(0, "T"));
1079         strcpy(dateStr.hour, strtok(0, ":"));
1080
1081         if (local)
1082             strcpy(dateStr.min, strtok(0, "Z"));
1083         else
1084             strcpy(dateStr.min, strtok(0, ":"));
1085
1086         currentTime->tm_year = atoi(dateStr.year);
1087         currentTime->tm_mon = atoi(dateStr.mon);
1088         currentTime->tm_mday = atoi(dateStr.day);
1089         currentTime->tm_hour = atoi(dateStr.hour);
1090         currentTime->tm_min = atoi(dateStr.min);
1091
1092         currentTime->tm_year = currentTime->tm_year - 1900;
1093         currentTime->tm_mon = currentTime->tm_mon - 1;
1094     }
1095
1096     if (m_pickerLayout) {
1097         // Just update the value.
1098         m_pickerLayout->datetimeLocal = local;
1099
1100         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1101         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
1102         evas_object_focus_set(m_pickerLayout->okButton, true);
1103         return;
1104     }
1105
1106     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
1107
1108     m_pickerLayout->datetimeLocal = local;
1109
1110     while (parent) {
1111         const char* type = elm_object_widget_type_get(parent);
1112         if (type) {
1113             if (!strcmp(type, "elm_win")) {
1114                 win =  parent;
1115                 break;
1116             }
1117         }
1118         parent = elm_object_parent_widget_get(parent);
1119     }
1120
1121     if (!win)
1122         win = m_ewkView;
1123
1124     m_pickerLayout->popup = elm_popup_add(win);
1125     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
1126
1127 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1128     if (EflAssistHandle) {
1129         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
1130         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
1131         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
1132     }
1133 #endif
1134
1135     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1136     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
1137     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1138
1139     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1140     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1141     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
1142     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
1143     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
1144     elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
1145
1146 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1147     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
1148     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
1149 #endif
1150
1151     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
1152     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
1153     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
1154     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
1155
1156 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1157     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,start", _edit_start_cb, 0);
1158     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,end", _edit_end_cb, 0);
1159 #endif
1160
1161     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1162     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1163     elm_object_text_set(m_pickerLayout->okButton, "OK");
1164     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1165     evas_object_focus_set(m_pickerLayout->okButton, true);
1166
1167     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1168     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1169     evas_object_show(m_pickerLayout->popup);
1170
1171 }
1172
1173 void InputPicker::_date_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1174 {
1175     struct tm currentTime;
1176     memset(&currentTime, 0, sizeof(struct tm));
1177     Input_Date date;
1178     char dateStr[20] = {0, };
1179
1180     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1181
1182     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1183
1184     date.day =  currentTime.tm_mday;
1185     date.mon = currentTime.tm_mon;
1186     date.year = currentTime.tm_year;
1187
1188     if(inputPicker->m_pickerLayout->popup){
1189         evas_object_del(inputPicker->m_pickerLayout->popup);
1190         inputPicker->m_pickerLayout->popup = 0;
1191     }
1192
1193     date.year = 1900 + date.year;
1194     sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1195
1196     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1197     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1198
1199     delete inputPicker->m_pickerLayout;
1200     inputPicker->m_pickerLayout = 0;
1201 }
1202
1203 void InputPicker::_week_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1204 {
1205     struct tm currentTime;
1206     memset(&currentTime, 0, sizeof(struct tm));
1207     Input_Date date;
1208     char dateStr[20] = {0, };
1209
1210     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1211
1212     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1213
1214     date.day =  currentTime.tm_mday;
1215     date.mon = currentTime.tm_mon;
1216     date.year = currentTime.tm_year;
1217     mktime(&currentTime);
1218
1219     if(inputPicker->m_pickerLayout->popup){
1220         evas_object_del(inputPicker->m_pickerLayout->popup);
1221         inputPicker->m_pickerLayout->popup = 0;
1222     }
1223
1224     struct tm firtTimeOfyear;
1225     memset(&firtTimeOfyear, 0, sizeof(struct tm));
1226     firtTimeOfyear.tm_year = date.year;
1227     firtTimeOfyear.tm_mon = 0;
1228     firtTimeOfyear.tm_mday = 1;
1229     mktime(&firtTimeOfyear);
1230
1231     char firstWeek[10] = {0, };
1232     strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1233     int firstWeekCount = atoi(firstWeek);
1234
1235     char totalDay[10] = {0, };
1236     strftime(totalDay, 10, "%j", &currentTime);
1237     int totalDayCount = atoi(totalDay);
1238
1239     int weekNum = (totalDayCount + firstWeekCount) / 7;
1240     if (totalDayCount + firstWeekCount > weekNum * 7)
1241         weekNum++;
1242
1243     date.year = 1900 + date.year;
1244     sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1245
1246     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1247     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1248
1249     delete inputPicker->m_pickerLayout;
1250     inputPicker->m_pickerLayout = 0;
1251 }
1252
1253 void InputPicker::_time_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1254 {
1255     struct tm currentTime;
1256     memset(&currentTime, 0, sizeof(struct tm));
1257     Input_Date date;
1258     char dateStr[20] = {0, };
1259
1260     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1261
1262     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1263
1264     date.hour =  currentTime.tm_hour;
1265     date.min = currentTime.tm_min;
1266
1267     if(inputPicker->m_pickerLayout->popup){
1268         evas_object_del(inputPicker->m_pickerLayout->popup);
1269         inputPicker->m_pickerLayout->popup = 0;
1270     }
1271
1272     sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1273     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1274     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1275
1276     delete inputPicker->m_pickerLayout;
1277     inputPicker->m_pickerLayout = 0;
1278 }
1279
1280 void InputPicker::_month_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1281 {
1282     struct tm currentTime;
1283     memset(&currentTime, 0, sizeof(struct tm));
1284     Input_Date date;
1285     char dateStr[20] = {0, };
1286
1287     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1288
1289     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1290
1291     date.mon = currentTime.tm_mon;
1292     date.year = currentTime.tm_year;
1293
1294     if(inputPicker->m_pickerLayout->popup){
1295         evas_object_del(inputPicker->m_pickerLayout->popup);
1296         inputPicker->m_pickerLayout->popup = 0;
1297     }
1298
1299     date.year = 1900 + date.year;
1300     sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1301
1302     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1303     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1304
1305     delete inputPicker->m_pickerLayout;
1306     inputPicker->m_pickerLayout = 0;
1307 }
1308
1309 void InputPicker::_datetime_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1310 {
1311     struct tm currentTime;
1312     memset(&currentTime, 0, sizeof(struct tm));
1313     Input_Date date;
1314     char dateStr[50] = {0, };
1315
1316     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1317
1318     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1319     date.year = currentTime.tm_year;
1320     date.day =  currentTime.tm_mday;
1321     date.mon = currentTime.tm_mon;
1322
1323     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1324     date.hour =  currentTime.tm_hour;
1325     date.min = currentTime.tm_min;
1326
1327     if (inputPicker->m_pickerLayout->popup) {
1328         evas_object_del(inputPicker->m_pickerLayout->popup);
1329         inputPicker->m_pickerLayout->popup = 0;
1330     }
1331
1332     date.year = 1900 + date.year;
1333
1334     if (inputPicker->m_pickerLayout->datetimeLocal)
1335         sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1336     else
1337         sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1338
1339     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1340     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1341
1342     delete inputPicker->m_pickerLayout;
1343     inputPicker->m_pickerLayout = 0;
1344 }
1345
1346 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1347 void InputPicker::_popup_back_cb(void* data,  Evas_Object* obj, void* event_info)
1348 {
1349     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1350
1351     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1352
1353     if (!inputPicker->m_pickerLayout)
1354         return;
1355
1356     if (inputPicker->m_pickerLayout->popup) {
1357         evas_object_del(inputPicker->m_pickerLayout->popup);
1358         inputPicker->m_pickerLayout->popup = 0;
1359     }
1360
1361     delete inputPicker->m_pickerLayout;
1362     inputPicker->m_pickerLayout = 0;
1363 }
1364 #endif
1365
1366 } // namespace WebKit
1367
1368 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)