Set focus on popup when picker popup is displayed
[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     evas_object_focus_set(m_pickerLayout->okButton, true);
261
262     Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
263     elm_object_style_set(cancelButton, "popup_button/default");
264     elm_object_text_set(cancelButton, "Cancel");
265     elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
266     evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
267     evas_object_show(cancelButton);
268 }
269
270 void InputPicker::hideDataList(Ewk_Input_Type inputType)
271 {
272     if (!m_dataList)
273         return;
274
275     if(m_pickerLayout->popup){
276         evas_object_del(m_pickerLayout->popup);
277         m_pickerLayout->popup = 0;
278     }
279
280     delete m_pickerLayout;
281     m_pickerLayout = 0;
282
283     m_dataList = 0;
284 }
285 #endif
286
287 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
288 void InputPicker::showColorPicker(int r, int g, int b, int)
289 {
290     m_isColorPickerShown = true;
291     ewk_color_popup(r, g, b);
292 }
293
294 void InputPicker::hideColorPicker()
295 {
296     m_isColorPickerShown = false;
297     if (!m_pickerLayout)
298         return;
299
300     if (m_pickerLayout->popup) {
301         evas_object_del(m_pickerLayout->popup);
302         m_pickerLayout->popup = 0;
303     }
304
305     delete m_pickerLayout;
306     m_pickerLayout = 0;
307 }
308 #endif
309
310 #if ENABLE(ELM_COLORPALLETE)
311 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
312 {
313     int r = 0;
314     int g = 0;
315     int b = 0;
316     int a = 0;
317     Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
318     elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
319     evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
320 }
321 #endif
322
323 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
324 {
325     int r = 0;
326     int g = 0;
327     int b = 0;
328     int a = 0;
329     evas_object_color_get(obj, &r, &g, &b, &a);
330
331     evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
332 }
333
334 void InputPicker::ewk_color_popup(int r, int g, int b)
335 {
336     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
337     Evas_Object* win = parent;
338
339     if (m_pickerLayout)
340         return;
341
342     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
343
344     while (parent) {
345         const char* type = elm_object_widget_type_get(parent);
346         if (type) {
347             if (!strcmp(type, "elm_win")) {
348                 win =  parent;
349                 break;
350             }
351         }
352         parent = elm_object_parent_widget_get(parent);
353     }
354
355     if (!win)
356     win = m_ewkView;
357
358     m_pickerLayout->popup = elm_popup_add(win);
359     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
360
361     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
362     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
363     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
364     evas_object_show(m_pickerLayout->layout);
365     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
366
367     m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
368     evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
369     evas_object_show(m_pickerLayout->colorRect);
370
371     printf("\n<<<<<<<< r = [%d], g = [%d], b = [%d] >>>>>>>>>>\n", r, g, b);
372
373     evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
374     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
375 #if ENABLE(ELM_COLORPALLETE)
376     Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
377     elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
378
379     elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
380     elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
381     elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
382     elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
383     elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
384     elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
385     elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
386     elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
387     elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
388     elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
389     elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
390     elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
391
392     evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
393     evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
394     evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
395     evas_object_show(colorPalette);
396
397     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
398 #else
399     Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
400     evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
401     evas_object_color_set(color1, 128, 0, 0, 255);
402     evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
403     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
404     evas_object_show(color1);
405
406     Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
407     evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
408     evas_object_color_set(color2, 255, 0, 128, 255);
409     evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
410     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
411     evas_object_show(color2);
412
413     Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
414     evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
415     evas_object_color_set(color3, 255, 0, 0, 255);
416     evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
417     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
418     evas_object_show(color3);
419
420     Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
421     evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
422     evas_object_color_set(color4, 255, 127, 39, 255);
423     evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
424     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
425     evas_object_show(color4);
426
427     Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
428     evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
429     evas_object_color_set(color5, 255, 255, 0, 255);
430     evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
431     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
432     evas_object_show(color5);
433
434     Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
435     evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
436     evas_object_color_set(color6, 0, 255, 0, 255);
437     evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
438     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
439     evas_object_show(color6);
440
441     Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
442     evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
443     evas_object_color_set(color7, 0, 255, 255, 255);
444     evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
445     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
446     evas_object_show(color7);
447
448     Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
449     evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
450     evas_object_color_set(color8, 0, 0, 255, 255);
451     evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
452     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
453     evas_object_show(color8);
454
455     Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
456     evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
457     evas_object_color_set(color9, 0, 0, 128, 255);
458     evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
459     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
460     evas_object_show(color9);
461
462     Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
463     evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
464     evas_object_color_set(color10, 64, 0, 64, 255);
465     evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
466     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
467     evas_object_show(color10);
468
469     Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
470     evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
471     evas_object_color_set(color11, 153, 217, 234, 255);
472     evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
473     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
474     evas_object_show(color11);
475
476     Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
477     evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
478     evas_object_color_set(color12, 128, 128, 128, 255);
479     evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
480     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
481     evas_object_show(color12);
482
483     Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
484     evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
485     evas_object_color_set(color13, 0, 0, 0, 255);
486     evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
487     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
488     evas_object_show(color13);
489
490     Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
491     evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
492     evas_object_color_set(color14, 255, 255, 255, 255);
493     evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
494     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
495     evas_object_show(color14);
496 #endif
497     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
498     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
499     elm_object_text_set(m_pickerLayout->okButton, "OK");
500     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
501     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
502     evas_object_focus_set(m_pickerLayout->okButton, true);
503
504     evas_object_show(m_pickerLayout->popup);
505 }
506
507 void InputPicker::_color_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
508 {
509     InputPicker* inputPicker = static_cast<InputPicker*>(data);
510
511     int r = 0;
512     int g = 0;
513     int b = 0;
514     int a = 0;
515     evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
516
517     ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
518
519     inputPicker->hideColorPicker();
520 }
521
522 void InputPicker::ewk_date_popup(const char* inputValue)
523 {
524     struct tm* currentTime;
525     time_t cur_time;
526     time(&cur_time);
527     currentTime = localtime(&cur_time);
528
529     Input_Date_Str dateStr;
530     memset(&dateStr, 0, sizeof(Input_Date_Str));
531
532     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
533     Evas_Object* win = parent;
534
535     if (inputValue && strlen(inputValue)) {
536         char tmpinputValue[30] = {0,};
537
538         sprintf(tmpinputValue, "%s", inputValue);
539         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
540         strcpy(dateStr.mon, strtok(0, "-"));
541         strcpy(dateStr.day, strtok(0, "-"));
542
543         currentTime->tm_year = atoi(dateStr.year);
544         currentTime->tm_mon = atoi(dateStr.mon);
545         currentTime->tm_mday = atoi(dateStr.day);
546
547         currentTime->tm_year = currentTime->tm_year - 1900;
548         currentTime->tm_mon = currentTime->tm_mon - 1;
549     }
550
551     if (m_pickerLayout) {
552         // Just update the value.
553         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
554         return;
555     }
556
557     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
558
559     while (parent) {
560         const char* type = elm_object_widget_type_get(parent);
561         if (type) {
562             if (!strcmp(type, "elm_win")) {
563                 win =  parent;
564                 break;
565             }
566         }
567         parent = elm_object_parent_widget_get(parent);
568     }
569
570     if (!win)
571         win = m_ewkView;
572
573     m_pickerLayout->popup = elm_popup_add(win);
574     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
575
576     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
577     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
578     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
579
580     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
581
582     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
583     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
584
585     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
586     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
587     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
588     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
589
590     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
591     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
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", _date_popup_response_cb, this);
595     evas_object_focus_set(m_pickerLayout->okButton, true);
596
597     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
598     evas_object_show(m_pickerLayout->popup);
599 }
600
601 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
602 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
603 {
604     // Jan.
605     if (totalDays - 31 < 0) {
606         *remains = totalDays;
607         return 0;
608     }
609
610     totalDays = totalDays - 31;
611
612     // Feb.
613     if (isLeapYear(year)) {
614         if (totalDays - 29 < 0) {
615             *remains = totalDays;
616             return 1;
617         }
618         totalDays = totalDays - 29;
619     } else {
620         if (totalDays - 28 < 0) {
621             *remains = totalDays;
622             return 1;
623         }
624         totalDays = totalDays - 28;
625     }
626
627     // Mar.
628     if (totalDays - 31 < 0) {
629         *remains = totalDays;
630         return 2;
631     }
632     totalDays = totalDays - 31;
633
634     // Apr.
635     if (totalDays - 30 < 0) {
636         *remains = totalDays;
637         return 3;
638     }
639     totalDays = totalDays - 30;
640
641     // May
642     if (totalDays - 31 < 0) {
643         *remains = totalDays;
644         return 4;
645     }
646     totalDays = totalDays - 31;
647
648     // Jun.
649     if (totalDays - 30 < 0) {
650         *remains = totalDays;
651         return 5;
652     }
653     totalDays = totalDays - 30;
654
655     // Jul.
656     if (totalDays - 31 < 0) {
657         *remains = totalDays;
658         return 6;
659     }
660     totalDays = totalDays - 31;
661
662     // Aug.
663     if (totalDays - 31 < 0) {
664         *remains = totalDays;
665         return 7;
666     }
667     totalDays = totalDays - 31;
668
669     // Sept.
670     if (totalDays - 30 < 0) {
671         *remains = totalDays;
672         return 8;
673     }
674     totalDays = totalDays - 30;
675
676     // Oct.
677     if (totalDays - 31 < 0) {
678         *remains = totalDays;
679         return 9;
680     }
681     totalDays = totalDays - 31;
682
683     // Nov.
684     if (totalDays - 30 < 0) {
685         *remains = totalDays;
686         return 10;
687     }
688     totalDays = totalDays - 30;
689
690     *remains = totalDays;
691     return 11;
692 }
693
694 void InputPicker::ewk_week_popup(const char* inputValue)
695 {
696     struct tm* currentTime;
697     time_t cur_time;
698     time(&cur_time);
699     currentTime = localtime(&cur_time);
700
701     Input_Date_Str dateStr;
702     memset(&dateStr, 0, sizeof(Input_Date_Str));
703
704     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
705     Evas_Object* win = parent;
706
707     if (inputValue && strlen(inputValue)) {
708         char tmpinputValue[30] = {0,};
709
710         sprintf(tmpinputValue, "%s", inputValue);
711         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
712         const char* week = strstr(inputValue, "W");
713         int weekNum = 1;
714         if (week)
715             weekNum = atoi(week + 1);
716
717         currentTime->tm_year = atoi(dateStr.year);
718         currentTime->tm_year = currentTime->tm_year - 1900;
719
720         struct tm firtTimeOfyear;
721         memset(&firtTimeOfyear, 0, sizeof(struct tm));
722         firtTimeOfyear.tm_year = currentTime->tm_year;
723         firtTimeOfyear.tm_mon = 0;
724         firtTimeOfyear.tm_mday = 1;
725         mktime(&firtTimeOfyear);
726
727         char firstWeek[10] = {0, };
728         strftime(firstWeek, 10, "%w", &firtTimeOfyear);
729         int firstWeekCount = atoi(firstWeek);
730
731         int totalDays = 1;
732
733         totalDays = weekNum * 7 - firstWeekCount;
734
735         int days = 0;
736         int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
737
738         currentTime->tm_mon = month;
739         currentTime->tm_mday = days;
740     }
741
742     if (m_pickerLayout) {
743         // Just update the value.
744         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
745         return;
746     }
747
748     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
749
750     while (parent) {
751         const char* type = elm_object_widget_type_get(parent);
752         if (type) {
753             if (!strcmp(type, "elm_win")) {
754                 win =  parent;
755                 break;
756             }
757         }
758         parent = elm_object_parent_widget_get(parent);
759     }
760
761     if (!win)
762         win = m_ewkView;
763
764     m_pickerLayout->popup = elm_popup_add(win);
765     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
766
767     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
768     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
769     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
770
771     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
772
773     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
774     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
775
776     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
777     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
778     elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
779     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
780
781     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
782     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
783     elm_object_text_set(m_pickerLayout->okButton, "OK");
784     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
785     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
786     evas_object_focus_set(m_pickerLayout->okButton, true);
787
788     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
789     evas_object_show(m_pickerLayout->popup);
790 }
791
792 void InputPicker::ewk_time_popup(const char* inputValue)
793 {
794     struct tm* currentTime;
795     time_t  cur_time;
796     time(&cur_time);
797     currentTime = localtime(&cur_time);
798
799     Input_Date_Str dateStr;
800     memset(&dateStr, 0, sizeof(Input_Date_Str));
801
802     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
803     Evas_Object* win = parent;
804
805     if (inputValue && strlen(inputValue)) {
806         char tmpinputValue[30] = {0,};
807
808         sprintf(tmpinputValue, "%s", inputValue);
809         strcpy(dateStr.hour, strtok(tmpinputValue,":"));
810         strcpy(dateStr.min, strtok(0, ":"));
811
812         currentTime->tm_hour = atoi(dateStr.hour);
813         currentTime->tm_min = atoi(dateStr.min);
814     }
815
816     if (m_pickerLayout) {
817         // Just update the value.
818         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
819         return;
820     }
821
822     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
823
824     while (parent) {
825         const char* type = elm_object_widget_type_get(parent);
826         if (type) {
827             if (!strcmp(type, "elm_win")) {
828                 win =  parent;
829                 break;
830             }
831         }
832         parent = elm_object_parent_widget_get(parent);
833     }
834
835     if (!win)
836         win = m_ewkView;
837
838     m_pickerLayout->popup = elm_popup_add(win);
839     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
840
841     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
842     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
843     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
844
845     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
846
847     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
848     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
849     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
850
851     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
852
853     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
854     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
855     elm_object_text_set(m_pickerLayout->okButton, "OK");
856     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
857     evas_object_focus_set(m_pickerLayout->okButton, true);
858
859     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
860     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
861     evas_object_show(m_pickerLayout->popup);
862 }
863
864 void InputPicker::ewk_month_popup(const char* inputValue)
865 {
866     struct tm* currentTime;
867     time_t  cur_time;
868     time(&cur_time);
869     currentTime = localtime(&cur_time);
870
871     Input_Date_Str dateStr;
872     memset(&dateStr, 0, sizeof(Input_Date_Str));
873
874     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
875     Evas_Object* win = parent;
876
877     if (inputValue && strlen(inputValue)) {
878         char tmpInputValue[30] = {0,};
879
880         sprintf(tmpInputValue, "%s", inputValue);
881         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
882         strcpy(dateStr.mon, strtok(0, "-"));
883
884         currentTime->tm_year = atoi(dateStr.year);
885         currentTime->tm_mon = atoi(dateStr.mon);
886
887         currentTime->tm_year = currentTime->tm_year - 1900;
888         currentTime->tm_mon = currentTime->tm_mon - 1;
889     }
890
891     if (m_pickerLayout) {
892         // Just update the value.
893         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
894         return;
895     }
896
897     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
898
899     while (parent) {
900         const char* type = elm_object_widget_type_get(parent);
901         if (type) {
902             if (!strcmp(type, "elm_win")) {
903                 win =  parent;
904                 break;
905             }
906         }
907         parent = elm_object_parent_widget_get(parent);
908     }
909
910     if (!win)
911         win = m_ewkView;
912
913     m_pickerLayout->popup = elm_popup_add(win);
914
915     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
916
917     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
918     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
919
920     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
921     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
922
923     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
924
925     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text",  "Month (Default format) :");
926
927     elm_datetime_format_set(m_pickerLayout->datePicker, "%Y %m");
928     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date",  m_pickerLayout->datePicker);
929
930     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
931     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
932     elm_object_text_set(m_pickerLayout->okButton, "OK");
933     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
934     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
935     evas_object_focus_set(m_pickerLayout->okButton, true);
936
937     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
938     evas_object_show(m_pickerLayout->popup);
939 }
940
941 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
942 {
943     struct tm* currentTime;
944     time_t  cur_time;
945     time(&cur_time);
946     currentTime = localtime(&cur_time);
947
948     Input_Date_Str dateStr;
949     memset(&dateStr, 0, sizeof(Input_Date_Str));
950
951     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
952     Evas_Object* win = parent;
953
954     if (inputValue && strlen(inputValue)) {
955         char tmpInputValue[30] = {0, };
956
957         sprintf(tmpInputValue, "%s", inputValue);
958         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
959         strcpy(dateStr.mon, strtok(0, "-"));
960         strcpy(dateStr.day, strtok(0, "T"));
961         strcpy(dateStr.hour, strtok(0, ":"));
962
963         if (local)
964             strcpy(dateStr.min, strtok(0, "Z"));
965         else
966             strcpy(dateStr.min, strtok(0, ":"));
967
968         currentTime->tm_year = atoi(dateStr.year);
969         currentTime->tm_mon = atoi(dateStr.mon);
970         currentTime->tm_mday = atoi(dateStr.day);
971         currentTime->tm_hour = atoi(dateStr.hour);
972         currentTime->tm_min = atoi(dateStr.min);
973
974         currentTime->tm_year = currentTime->tm_year - 1900;
975         currentTime->tm_mon = currentTime->tm_mon - 1;
976     }
977
978     if (m_pickerLayout) {
979         // Just update the value.
980         m_pickerLayout->datetimeLocal = local;
981
982         elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
983         elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
984         return;
985     }
986
987     m_pickerLayout = new Input_Picker_Layout(m_ewkView);
988
989     m_pickerLayout->datetimeLocal = local;
990
991     while (parent) {
992         const char* type = elm_object_widget_type_get(parent);
993         if (type) {
994             if (!strcmp(type, "elm_win")) {
995                 win =  parent;
996                 break;
997             }
998         }
999         parent = elm_object_parent_widget_get(parent);
1000     }
1001
1002     if (!win)
1003         win = m_ewkView;
1004
1005     m_pickerLayout->popup = elm_popup_add(win);
1006     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
1007
1008     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1009     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
1010     evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1011
1012     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1013     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1014
1015     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
1016     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
1017     elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
1018     elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
1019
1020     m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
1021     elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
1022     elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
1023     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
1024
1025     m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1026     elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1027     elm_object_text_set(m_pickerLayout->okButton, "OK");
1028     elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1029     evas_object_focus_set(m_pickerLayout->okButton, true);
1030
1031     evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1032     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1033     evas_object_show(m_pickerLayout->popup);
1034
1035 }
1036
1037 void InputPicker::_date_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1038 {
1039     struct tm currentTime;
1040     memset(&currentTime, 0, sizeof(struct tm));
1041     Input_Date date;
1042     char dateStr[20] = {0, };
1043
1044     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1045
1046     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1047
1048     date.day =  currentTime.tm_mday;
1049     date.mon = currentTime.tm_mon;
1050     date.year = currentTime.tm_year;
1051
1052     if(inputPicker->m_pickerLayout->popup){
1053         evas_object_del(inputPicker->m_pickerLayout->popup);
1054         inputPicker->m_pickerLayout->popup = 0;
1055     }
1056
1057     date.year = 1900 + date.year;
1058     sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1059
1060     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1061     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1062
1063     delete inputPicker->m_pickerLayout;
1064     inputPicker->m_pickerLayout = 0;
1065 }
1066
1067 void InputPicker::_week_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1068 {
1069     struct tm currentTime;
1070     memset(&currentTime, 0, sizeof(struct tm));
1071     Input_Date date;
1072     char dateStr[20] = {0, };
1073
1074     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1075
1076     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1077
1078     date.day =  currentTime.tm_mday;
1079     date.mon = currentTime.tm_mon;
1080     date.year = currentTime.tm_year;
1081     mktime(&currentTime);
1082
1083     if(inputPicker->m_pickerLayout->popup){
1084         evas_object_del(inputPicker->m_pickerLayout->popup);
1085         inputPicker->m_pickerLayout->popup = 0;
1086     }
1087
1088     struct tm firtTimeOfyear;
1089     memset(&firtTimeOfyear, 0, sizeof(struct tm));
1090     firtTimeOfyear.tm_year = date.year;
1091     firtTimeOfyear.tm_mon = 0;
1092     firtTimeOfyear.tm_mday = 1;
1093     mktime(&firtTimeOfyear);
1094
1095     char firstWeek[10] = {0, };
1096     strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1097     int firstWeekCount = atoi(firstWeek);
1098
1099     char totalDay[10] = {0, };
1100     strftime(totalDay, 10, "%j", &currentTime);
1101     int totalDayCount = atoi(totalDay);
1102
1103     int weekNum = (totalDayCount + firstWeekCount) / 7;
1104     if (totalDayCount + firstWeekCount > weekNum * 7)
1105         weekNum++;
1106
1107     date.year = 1900 + date.year;
1108     sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1109
1110     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1111     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1112
1113     delete inputPicker->m_pickerLayout;
1114     inputPicker->m_pickerLayout = 0;
1115 }
1116
1117 void InputPicker::_time_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1118 {
1119     struct tm currentTime;
1120     memset(&currentTime, 0, sizeof(struct tm));
1121     Input_Date date;
1122     char dateStr[20] = {0, };
1123
1124     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1125
1126     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1127
1128     date.hour =  currentTime.tm_hour;
1129     date.min = currentTime.tm_min;
1130
1131     if(inputPicker->m_pickerLayout->popup){
1132         evas_object_del(inputPicker->m_pickerLayout->popup);
1133         inputPicker->m_pickerLayout->popup = 0;
1134     }
1135
1136     sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1137     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1138     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1139
1140     delete inputPicker->m_pickerLayout;
1141     inputPicker->m_pickerLayout = 0;
1142 }
1143
1144 void InputPicker::_month_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1145 {
1146     struct tm currentTime;
1147     memset(&currentTime, 0, sizeof(struct tm));
1148     Input_Date date;
1149     char dateStr[20] = {0, };
1150
1151     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1152
1153     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1154
1155     date.mon = currentTime.tm_mon;
1156     date.year = currentTime.tm_year;
1157
1158     if(inputPicker->m_pickerLayout->popup){
1159         evas_object_del(inputPicker->m_pickerLayout->popup);
1160         inputPicker->m_pickerLayout->popup = 0;
1161     }
1162
1163     date.year = 1900 + date.year;
1164     sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1165
1166     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1167     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1168
1169     delete inputPicker->m_pickerLayout;
1170     inputPicker->m_pickerLayout = 0;
1171 }
1172
1173 void InputPicker::_datetime_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1174 {
1175     struct tm currentTime;
1176     memset(&currentTime, 0, sizeof(struct tm));
1177     Input_Date date;
1178     char dateStr[50] = {0, };
1179
1180     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1181
1182     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1183     date.year = currentTime.tm_year;
1184     date.day =  currentTime.tm_mday;
1185     date.mon = currentTime.tm_mon;
1186
1187     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1188     date.hour =  currentTime.tm_hour;
1189     date.min = currentTime.tm_min;
1190
1191     if (inputPicker->m_pickerLayout->popup) {
1192         evas_object_del(inputPicker->m_pickerLayout->popup);
1193         inputPicker->m_pickerLayout->popup = 0;
1194     }
1195
1196     date.year = 1900 + date.year;
1197
1198     if (inputPicker->m_pickerLayout->datetimeLocal)
1199         sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1200     else
1201         sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1202
1203     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1204     ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1205
1206     delete inputPicker->m_pickerLayout;
1207     inputPicker->m_pickerLayout = 0;
1208 }
1209
1210 } // namespace WebKit
1211
1212 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)