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