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