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