Add missing format for date/time picker
[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_format_set(m_pickerLayout->datePicker, "%Y/%m/%d");
659     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
660
661     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
662     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
663     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
664     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
665
666 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
667     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
668     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
669 #endif
670
671     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
672     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
673     elm_object_text_set(m_pickerLayout->okButton, "OK");
674     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
675     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
676     evas_object_focus_set(m_pickerLayout->okButton, true);
677
678     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
679     evas_object_show(m_pickerLayout->popup);
680 }
681
682 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
683 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
684 {
685     // Jan.
686     if (totalDays - 31 < 0) {
687         *remains = totalDays;
688         return 0;
689     }
690
691     totalDays = totalDays - 31;
692
693     // Feb.
694     if (isLeapYear(year)) {
695         if (totalDays - 29 < 0) {
696             *remains = totalDays;
697             return 1;
698         }
699         totalDays = totalDays - 29;
700     } else {
701         if (totalDays - 28 < 0) {
702             *remains = totalDays;
703             return 1;
704         }
705         totalDays = totalDays - 28;
706     }
707
708     // Mar.
709     if (totalDays - 31 < 0) {
710         *remains = totalDays;
711         return 2;
712     }
713     totalDays = totalDays - 31;
714
715     // Apr.
716     if (totalDays - 30 < 0) {
717         *remains = totalDays;
718         return 3;
719     }
720     totalDays = totalDays - 30;
721
722     // May
723     if (totalDays - 31 < 0) {
724         *remains = totalDays;
725         return 4;
726     }
727     totalDays = totalDays - 31;
728
729     // Jun.
730     if (totalDays - 30 < 0) {
731         *remains = totalDays;
732         return 5;
733     }
734     totalDays = totalDays - 30;
735
736     // Jul.
737     if (totalDays - 31 < 0) {
738         *remains = totalDays;
739         return 6;
740     }
741     totalDays = totalDays - 31;
742
743     // Aug.
744     if (totalDays - 31 < 0) {
745         *remains = totalDays;
746         return 7;
747     }
748     totalDays = totalDays - 31;
749
750     // Sept.
751     if (totalDays - 30 < 0) {
752         *remains = totalDays;
753         return 8;
754     }
755     totalDays = totalDays - 30;
756
757     // Oct.
758     if (totalDays - 31 < 0) {
759         *remains = totalDays;
760         return 9;
761     }
762     totalDays = totalDays - 31;
763
764     // Nov.
765     if (totalDays - 30 < 0) {
766         *remains = totalDays;
767         return 10;
768     }
769     totalDays = totalDays - 30;
770
771     *remains = totalDays;
772     return 11;
773 }
774
775 void InputPicker::ewk_week_popup(const char* inputValue)
776 {
777     struct tm* currentTime;
778     time_t cur_time;
779     time(&cur_time);
780     currentTime = localtime(&cur_time);
781
782     Input_Date_Str dateStr;
783     memset(&dateStr, 0, sizeof(Input_Date_Str));
784
785     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
786     Evas_Object* win = parent;
787
788     if (inputValue && strlen(inputValue)) {
789         char tmpinputValue[30] = {0,};
790
791         sprintf(tmpinputValue, "%s", inputValue);
792         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
793         const char* week = strstr(inputValue, "W");
794         int weekNum = 1;
795         if (week)
796             weekNum = atoi(week + 1);
797
798         currentTime->tm_year = atoi(dateStr.year);
799         currentTime->tm_year = currentTime->tm_year - 1900;
800
801         struct tm firtTimeOfyear;
802         memset(&firtTimeOfyear, 0, sizeof(struct tm));
803         firtTimeOfyear.tm_year = currentTime->tm_year;
804         firtTimeOfyear.tm_mon = 0;
805         firtTimeOfyear.tm_mday = 1;
806         mktime(&firtTimeOfyear);
807
808         char firstWeek[10] = {0, };
809         strftime(firstWeek, 10, "%w", &firtTimeOfyear);
810         int firstWeekCount = atoi(firstWeek);
811
812         int totalDays = 1;
813
814         totalDays = weekNum * 7 - firstWeekCount;
815
816         int days = 0;
817         int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
818
819         currentTime->tm_mon = month;
820         currentTime->tm_mday = days;
821     }
822
823     if (m_pickerLayout) {
824         // Just update the value.
825         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
826         evas_object_focus_set(m_pickerLayout->okButton, true);
827         return;
828     }
829
830     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
831
832     while (parent) {
833         const char* type = elm_object_widget_type_get(parent);
834         if (type) {
835             if (!strcmp(type, "elm_win")) {
836                 win =  parent;
837                 break;
838             }
839         }
840         parent = elm_object_parent_widget_get(parent);
841     }
842
843     if (!win)
844         win = m_ewkView;
845
846     m_pickerLayout->popup = elm_popup_add(win);
847     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
848
849 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
850     if (EflAssistHandle) {
851         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
852         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
853         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
854     }
855 #endif
856
857     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
858     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
859     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
860
861     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
862
863     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
864     elm_datetime_format_set(m_pickerLayout->datePicker, "%Y/%m/%d");
865     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
866
867     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
868     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
869     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
870     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
871
872 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
873     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
874     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
875 #endif
876
877     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
878     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
879     elm_object_text_set(m_pickerLayout->okButton, "OK");
880     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
881     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
882     evas_object_focus_set(m_pickerLayout->okButton, true);
883
884     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
885     evas_object_show(m_pickerLayout->popup);
886 }
887
888 void InputPicker::ewk_time_popup(const char* inputValue)
889 {
890     struct tm* currentTime;
891     time_t  cur_time;
892     time(&cur_time);
893     currentTime = localtime(&cur_time);
894
895     Input_Date_Str dateStr;
896     memset(&dateStr, 0, sizeof(Input_Date_Str));
897
898     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
899     Evas_Object* win = parent;
900
901     if (inputValue && strlen(inputValue)) {
902         char tmpinputValue[30] = {0,};
903
904         sprintf(tmpinputValue, "%s", inputValue);
905         strcpy(dateStr.hour, strtok(tmpinputValue,":"));
906         strcpy(dateStr.min, strtok(0, ":"));
907
908         currentTime->tm_hour = atoi(dateStr.hour);
909         currentTime->tm_min = atoi(dateStr.min);
910     }
911
912     if (m_pickerLayout) {
913         // Just update the value.
914         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
915         evas_object_focus_set(m_pickerLayout->okButton, true);
916         return;
917     }
918
919     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
920
921     while (parent) {
922         const char* type = elm_object_widget_type_get(parent);
923         if (type) {
924             if (!strcmp(type, "elm_win")) {
925                 win =  parent;
926                 break;
927             }
928         }
929         parent = elm_object_parent_widget_get(parent);
930     }
931
932     if (!win)
933         win = m_ewkView;
934
935     m_pickerLayout->popup = elm_popup_add(win);
936     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
937
938 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
939     if (EflAssistHandle) {
940         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
941         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
942         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
943     }
944 #endif
945
946     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
947     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
948     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
949
950     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
951
952     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
953     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
954     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
955     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
956
957 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
958     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,start", _edit_start_cb, 0);
959     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,end", _edit_end_cb, 0);
960 #endif
961
962     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
963     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
964     elm_object_text_set(m_pickerLayout->okButton, "OK");
965     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
966     evas_object_focus_set(m_pickerLayout->okButton, true);
967
968     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
969     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
970     evas_object_show(m_pickerLayout->popup);
971 }
972
973 void InputPicker::ewk_month_popup(const char* inputValue)
974 {
975     struct tm* currentTime;
976     time_t  cur_time;
977     time(&cur_time);
978     currentTime = localtime(&cur_time);
979
980     Input_Date_Str dateStr;
981     memset(&dateStr, 0, sizeof(Input_Date_Str));
982
983     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
984     Evas_Object* win = parent;
985
986     if (inputValue && strlen(inputValue)) {
987         char tmpInputValue[30] = {0,};
988
989         sprintf(tmpInputValue, "%s", inputValue);
990         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
991         strcpy(dateStr.mon, strtok(0, "-"));
992
993         currentTime->tm_year = atoi(dateStr.year);
994         currentTime->tm_mon = atoi(dateStr.mon);
995
996         currentTime->tm_year = currentTime->tm_year - 1900;
997         currentTime->tm_mon = currentTime->tm_mon - 1;
998     }
999
1000     if (m_pickerLayout) {
1001         // Just update the value.
1002         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1003         evas_object_focus_set(m_pickerLayout->okButton, true);
1004         return;
1005     }
1006
1007     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
1008
1009     while (parent) {
1010         const char* type = elm_object_widget_type_get(parent);
1011         if (type) {
1012             if (!strcmp(type, "elm_win")) {
1013                 win =  parent;
1014                 break;
1015             }
1016         }
1017         parent = elm_object_parent_widget_get(parent);
1018     }
1019
1020     if (!win)
1021         win = m_ewkView;
1022
1023     m_pickerLayout->popup = elm_popup_add(win);
1024     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
1025
1026 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1027     if (EflAssistHandle) {
1028         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
1029         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
1030         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
1031     }
1032 #endif
1033
1034     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1035     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
1036
1037     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1038
1039     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1040     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1041     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text",  "Month (Default format) :");
1042     elm_datetime_format_set(m_pickerLayout->datePicker, "%Y/%m");
1043     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date",  m_pickerLayout->datePicker);
1044
1045 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1046     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
1047     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
1048 #endif
1049
1050     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1051     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1052     elm_object_text_set(m_pickerLayout->okButton, "OK");
1053     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1054     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
1055     evas_object_focus_set(m_pickerLayout->okButton, true);
1056
1057     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1058     evas_object_show(m_pickerLayout->popup);
1059 }
1060
1061 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
1062 {
1063     struct tm* currentTime;
1064     time_t  cur_time;
1065     time(&cur_time);
1066     currentTime = localtime(&cur_time);
1067
1068     Input_Date_Str dateStr;
1069     memset(&dateStr, 0, sizeof(Input_Date_Str));
1070
1071     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
1072     Evas_Object* win = parent;
1073
1074     if (inputValue && strlen(inputValue)) {
1075         char tmpInputValue[30] = {0, };
1076
1077         sprintf(tmpInputValue, "%s", inputValue);
1078         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
1079         strcpy(dateStr.mon, strtok(0, "-"));
1080         strcpy(dateStr.day, strtok(0, "T"));
1081         strcpy(dateStr.hour, strtok(0, ":"));
1082
1083         if (local)
1084             strcpy(dateStr.min, strtok(0, "Z"));
1085         else
1086             strcpy(dateStr.min, strtok(0, ":"));
1087
1088         currentTime->tm_year = atoi(dateStr.year);
1089         currentTime->tm_mon = atoi(dateStr.mon);
1090         currentTime->tm_mday = atoi(dateStr.day);
1091         currentTime->tm_hour = atoi(dateStr.hour);
1092         currentTime->tm_min = atoi(dateStr.min);
1093
1094         currentTime->tm_year = currentTime->tm_year - 1900;
1095         currentTime->tm_mon = currentTime->tm_mon - 1;
1096     }
1097
1098     if (m_pickerLayout) {
1099         // Just update the value.
1100         m_pickerLayout->datetimeLocal = local;
1101
1102         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1103         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
1104         evas_object_focus_set(m_pickerLayout->okButton, true);
1105         return;
1106     }
1107
1108     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
1109
1110     m_pickerLayout->datetimeLocal = local;
1111
1112     while (parent) {
1113         const char* type = elm_object_widget_type_get(parent);
1114         if (type) {
1115             if (!strcmp(type, "elm_win")) {
1116                 win =  parent;
1117                 break;
1118             }
1119         }
1120         parent = elm_object_parent_widget_get(parent);
1121     }
1122
1123     if (!win)
1124         win = m_ewkView;
1125
1126     m_pickerLayout->popup = elm_popup_add(win);
1127     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
1128
1129 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1130     if (EflAssistHandle) {
1131         void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
1132         webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
1133         (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
1134     }
1135 #endif
1136
1137     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1138     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
1139     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1140
1141     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1142     elm_datetime_format_set(m_pickerLayout->datePicker, "%Y/%m/%d");
1143     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1144     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
1145     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
1146     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
1147     elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
1148
1149 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1150     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
1151     evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, 0);
1152 #endif
1153
1154     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
1155     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
1156     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
1157     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
1158
1159 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1160     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,start", _edit_start_cb, 0);
1161     evas_object_smart_callback_add(m_pickerLayout->timePicker, "edit,end", _edit_end_cb, 0);
1162 #endif
1163
1164     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1165     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1166     elm_object_text_set(m_pickerLayout->okButton, "OK");
1167     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1168     evas_object_focus_set(m_pickerLayout->okButton, true);
1169
1170     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1171     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1172     evas_object_show(m_pickerLayout->popup);
1173
1174 }
1175
1176 void InputPicker::_date_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1177 {
1178     struct tm currentTime;
1179     memset(&currentTime, 0, sizeof(struct tm));
1180     Input_Date date;
1181     char dateStr[20] = {0, };
1182
1183     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1184
1185     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1186
1187     date.day =  currentTime.tm_mday;
1188     date.mon = currentTime.tm_mon;
1189     date.year = currentTime.tm_year;
1190
1191     if(inputPicker->m_pickerLayout->popup){
1192         evas_object_del(inputPicker->m_pickerLayout->popup);
1193         inputPicker->m_pickerLayout->popup = 0;
1194     }
1195
1196     date.year = 1900 + date.year;
1197     sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1198
1199     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1200     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1201
1202     delete inputPicker->m_pickerLayout;
1203     inputPicker->m_pickerLayout = 0;
1204 }
1205
1206 void InputPicker::_week_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1207 {
1208     struct tm currentTime;
1209     memset(&currentTime, 0, sizeof(struct tm));
1210     Input_Date date;
1211     char dateStr[20] = {0, };
1212
1213     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1214
1215     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1216
1217     date.day =  currentTime.tm_mday;
1218     date.mon = currentTime.tm_mon;
1219     date.year = currentTime.tm_year;
1220     mktime(&currentTime);
1221
1222     if(inputPicker->m_pickerLayout->popup){
1223         evas_object_del(inputPicker->m_pickerLayout->popup);
1224         inputPicker->m_pickerLayout->popup = 0;
1225     }
1226
1227     struct tm firtTimeOfyear;
1228     memset(&firtTimeOfyear, 0, sizeof(struct tm));
1229     firtTimeOfyear.tm_year = date.year;
1230     firtTimeOfyear.tm_mon = 0;
1231     firtTimeOfyear.tm_mday = 1;
1232     mktime(&firtTimeOfyear);
1233
1234     char firstWeek[10] = {0, };
1235     strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1236     int firstWeekCount = atoi(firstWeek);
1237
1238     char totalDay[10] = {0, };
1239     strftime(totalDay, 10, "%j", &currentTime);
1240     int totalDayCount = atoi(totalDay);
1241
1242     int weekNum = (totalDayCount + firstWeekCount) / 7;
1243     if (totalDayCount + firstWeekCount > weekNum * 7)
1244         weekNum++;
1245
1246     date.year = 1900 + date.year;
1247     sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1248
1249     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1250     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1251
1252     delete inputPicker->m_pickerLayout;
1253     inputPicker->m_pickerLayout = 0;
1254 }
1255
1256 void InputPicker::_time_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1257 {
1258     struct tm currentTime;
1259     memset(&currentTime, 0, sizeof(struct tm));
1260     Input_Date date;
1261     char dateStr[20] = {0, };
1262
1263     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1264
1265     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1266
1267     date.hour =  currentTime.tm_hour;
1268     date.min = currentTime.tm_min;
1269
1270     if(inputPicker->m_pickerLayout->popup){
1271         evas_object_del(inputPicker->m_pickerLayout->popup);
1272         inputPicker->m_pickerLayout->popup = 0;
1273     }
1274
1275     sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1276     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1277     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1278
1279     delete inputPicker->m_pickerLayout;
1280     inputPicker->m_pickerLayout = 0;
1281 }
1282
1283 void InputPicker::_month_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1284 {
1285     struct tm currentTime;
1286     memset(&currentTime, 0, sizeof(struct tm));
1287     Input_Date date;
1288     char dateStr[20] = {0, };
1289
1290     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1291
1292     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1293
1294     date.mon = currentTime.tm_mon;
1295     date.year = currentTime.tm_year;
1296
1297     if(inputPicker->m_pickerLayout->popup){
1298         evas_object_del(inputPicker->m_pickerLayout->popup);
1299         inputPicker->m_pickerLayout->popup = 0;
1300     }
1301
1302     date.year = 1900 + date.year;
1303     sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1304
1305     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1306     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1307
1308     delete inputPicker->m_pickerLayout;
1309     inputPicker->m_pickerLayout = 0;
1310 }
1311
1312 void InputPicker::_datetime_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1313 {
1314     struct tm currentTime;
1315     memset(&currentTime, 0, sizeof(struct tm));
1316     Input_Date date;
1317     char dateStr[50] = {0, };
1318
1319     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1320
1321     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1322     date.year = currentTime.tm_year;
1323     date.day =  currentTime.tm_mday;
1324     date.mon = currentTime.tm_mon;
1325
1326     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1327     date.hour =  currentTime.tm_hour;
1328     date.min = currentTime.tm_min;
1329
1330     if (inputPicker->m_pickerLayout->popup) {
1331         evas_object_del(inputPicker->m_pickerLayout->popup);
1332         inputPicker->m_pickerLayout->popup = 0;
1333     }
1334
1335     date.year = 1900 + date.year;
1336
1337     if (inputPicker->m_pickerLayout->datetimeLocal)
1338         sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1339     else
1340         sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1341
1342     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1343     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1344
1345     delete inputPicker->m_pickerLayout;
1346     inputPicker->m_pickerLayout = 0;
1347 }
1348
1349 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1350 void InputPicker::_popup_back_cb(void* data,  Evas_Object* obj, void* event_info)
1351 {
1352     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1353
1354     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1355
1356     if (!inputPicker->m_pickerLayout)
1357         return;
1358
1359     if (inputPicker->m_pickerLayout->popup) {
1360         evas_object_del(inputPicker->m_pickerLayout->popup);
1361         inputPicker->m_pickerLayout->popup = 0;
1362     }
1363
1364     delete inputPicker->m_pickerLayout;
1365     inputPicker->m_pickerLayout = 0;
1366 }
1367 #endif
1368
1369 } // namespace WebKit
1370
1371 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)