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