#include "InputPicker.h"
-#include "base/path_service.h"
+#include <Ecore_X.h>
+#include <Elementary.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "base/files/file_path.h"
-#include "paths_efl.h"
#include "base/logging.h"
+#include "base/path_service.h"
#include "base/time/time.h"
#include "content/public/browser/web_contents.h"
#include "eweb_view.h"
+#include "paths_efl.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <Elementary.h>
#if defined(OS_TIZEN)
#include <vconf/vconf.h>
#endif
#if defined(OS_TIZEN_MOBILE)
-#include <dlfcn.h>
#include <efl_assist.h>
-extern void* EflAssistHandle;
#endif
using namespace tizen_webview;
namespace content {
-static const unsigned maxDatetimeLength = 32;
-static const unsigned maxDateStringLength = 10;
static const char defaultDatetimeFormat[] = "%Y/%m/%d %H:%M";
struct InputPicker::Layout {
Layout(Evas_Object *ewkView)
- : ewk_view_(ewkView)
+ : ewk_view(ewkView)
+ , widget_win(0)
+ , layout_conformant(0)
, popup(0)
, layout(0)
- , datePicker(0)
- , colorRect(0)
- , dataListEditField(0)
+ , date_picker(0)
+ , color_picker(0)
+ , color_rect(0)
+ , ok_button(0)
, initial_r(0)
, initial_g(0)
, initial_b(0)
, datetime_local(false) {
- evas_object_focus_set(ewk_view_, false);
+ evas_object_focus_set(ewk_view, false);
/* FIXME : Workaround. OSP requirement.
OSP want to block own touch event while webkit internal picker is running. */
- evas_object_smart_callback_call(ewk_view_, "input,picker,show", 0);
+ evas_object_smart_callback_call(ewk_view, "input,picker,show", 0);
}
~Layout() {
+ DeleteWin();
+
/* FIXME : Workaround. OSP requirement.
OSP want to block own touch event while webkit internal picker is running. */
- evas_object_smart_callback_call(ewk_view_, "input,picker,hide", 0);
+ evas_object_smart_callback_call(ewk_view, "input,picker,hide", 0);
+
+ evas_object_focus_set(ewk_view, true);
+ }
+
+ bool CreateWin() {
+ Evas_Object* top_widget = ewk_view;
+
+ if (Evas_Object *o = elm_object_parent_widget_get(ewk_view))
+ top_widget = o;
+ if (Evas_Object *o = elm_object_top_widget_get(top_widget))
+ top_widget = o;
+
+ if (!top_widget)
+ return false;
+
+ widget_win = elm_win_add(top_widget,
+ "WebKit InputPicker Popup",
+ ELM_WIN_BASIC);
+ if (!widget_win)
+ return false;
+
+ elm_win_alpha_set(widget_win, EINA_TRUE);
+ ecore_x_icccm_name_class_set(elm_win_xwindow_get(widget_win),
+ "APP_POPUP", "APP_POPUP");
+
+ if (elm_win_wm_rotation_supported_get(top_widget)) {
+ int preferredRotation = elm_win_wm_rotation_preferred_rotation_get(top_widget);
+ if (preferredRotation == -1) {
+ int rots[4] = {0, 90, 180, 270};
+ elm_win_wm_rotation_available_rotations_set(widget_win, rots, 4);
+ } else {
+ elm_win_wm_rotation_available_rotations_set(widget_win,
+ &preferredRotation, 1);
+ }
+ }
+
+ Evas_Object* conformant = elm_conformant_add(widget_win);
+ if (!conformant)
+ return false;
+
+ evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(widget_win, conformant);
+ evas_object_show(conformant);
+
+ layout_conformant = elm_layout_add(conformant);
+ if (!layout_conformant)
+ return false;
+
+ elm_layout_theme_set(layout_conformant, "layout", "application", "default");
+ evas_object_size_hint_weight_set(layout_conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(layout_conformant);
+
+ elm_object_content_set(conformant, layout_conformant);
+ elm_win_conformant_set(widget_win, EINA_TRUE);
+
+ int width = 0;
+ int height = 0;
+ ecore_x_screen_size_get(ecore_x_default_screen_get(), &width, &height);
+
+ evas_object_resize(widget_win, width, height);
+ elm_win_focus_highlight_enabled_set(widget_win, EINA_TRUE);
+ elm_win_focus_highlight_style_set(widget_win, NULL);
+ evas_object_show(widget_win);
+
+ return true;
+ }
+
+ void DeleteWin() {
+ if (!widget_win)
+ return;
+
+ evas_object_del(widget_win);
+ widget_win = 0;
+ }
+
+ base::FilePath GetLayoutFile() {
+ base::FilePath edj_dir;
+ base::FilePath control_edj;
+ PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edj_dir);
+ control_edj = edj_dir.Append(FILE_PATH_LITERAL("control.edj"));
+ return control_edj;
+ }
+
+ void CreateDateTimeSelector(const char* title) {
+ popup = elm_popup_add(layout_conformant);
+ if (!popup)
+ return;
+
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(popup, "title,text", title);
+
+ date_picker = elm_datetime_add(layout_conformant);
+ if (!date_picker)
+ return;
+
+#if defined(OS_TIZEN)
+ layout = elm_datetime_picker_get(date_picker, ELM_DATETIME_DATE_PICKER);
+#else
+ layout = date_picker;
+#endif
+
+ elm_object_content_set(popup, layout);
+ elm_object_signal_emit(popup, "datepicker,show", "");
+ }
+
+ void CreateColorSelector() {
+ popup = elm_popup_add(widget_win);
+ if (!popup)
+ return;
+
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ elm_object_part_text_set(popup, "title,text", "Select color");
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ base::FilePath control_edj = GetLayoutFile();
+
+ layout = elm_layout_add(popup);
+ if (!layout)
+ return;
+
+ elm_layout_file_set(layout, control_edj.AsUTF8Unsafe().c_str(),
+ "colorselector_popup_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ color_rect = evas_object_rectangle_add(evas_object_evas_get(layout));
+
+ if (color_rect) {
+ evas_object_size_hint_weight_set(color_rect,
+ EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(color_rect);
+ evas_object_color_set(color_rect, initial_r, initial_g, initial_b, 255);
+ elm_object_part_content_set(layout, "rect", color_rect);
+ }
+
+ BuildColorSelector();
+
+ evas_object_show(layout);
+ elm_object_content_set(popup, layout);
}
- Evas_Object* ewk_view_;
+ void BuildColorSelector() {
+ /* add color palette widget */
+ color_picker = elm_colorselector_add(layout);
+ if (!color_picker)
+ return;
+
+ elm_colorselector_mode_set(color_picker, ELM_COLORSELECTOR_PALETTE);
+ evas_object_size_hint_fill_set(color_picker, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(color_picker, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ Eina_List* color_list = elm_colorselector_palette_items_get(color_picker);
+ Eina_List* list = 0;
+ void* item = 0;
+ int r = 0;
+ int g = 0;
+ int b = 0;
+ int a = 0;
+ Elm_Object_Item* it = NULL;
+
+ EINA_LIST_FOREACH(color_list, list, item) {
+ if (item) {
+ elm_colorselector_palette_item_color_get((Elm_Object_Item*)item, &r, &g, &b, &a);
+ if (r == initial_r && g == initial_g && b == initial_b) {
+ it = (Elm_Object_Item*)item;
+ break;
+ }
+ }
+ }
+
+ if (!it)
+ it = (Elm_Object_Item*)eina_list_nth((Eina_List*)color_list, 0);
+
+ elm_object_item_signal_emit((Elm_Object_Item*)it, "elm,state,selected", "elm");
+
+ elm_object_part_content_set(layout, "colorpalette", color_picker);
+ }
+
+ void CreateOKButton() {
+ ok_button = elm_button_add(popup);
+ if (!ok_button)
+ return;
+
+ elm_object_style_set(ok_button, "popup");
+ elm_object_text_set(ok_button, "OK");
+ elm_object_part_content_set(popup, "button1", ok_button);
+ }
+
+ Evas_Object* ewk_view;
+ Evas_Object* widget_win;
+ Evas_Object* layout_conformant;
Evas_Object* popup;
Evas_Object* layout;
- Evas_Object* datePicker;
- Evas_Object* colorRect;
- Evas_Object* okButton;
- Evas_Object* dataListEditField;
+ Evas_Object* date_picker;
+ Evas_Object* color_picker;
+ Evas_Object* color_rect;
+ Evas_Object* ok_button;
int initial_r;
int initial_g;
int initial_b;
bool datetime_local;
};
-struct ColorPopupUserData {
- InputPicker* inputPicker;
- Evas_Object* colorRect;
- Evas_Object* color;
- Evas_Object* colorAccessObject;
-};
-
-struct Input_Date {
- int year;
- int mon;
- int day;
- int hour;
- int min;
- int sec;
-};
-
-struct Input_Date_Str {
- char year[maxDateStringLength];
- char mon[maxDateStringLength];
- char day[maxDateStringLength];
- char hour[maxDateStringLength];
- char min[maxDateStringLength];
- char sec[maxDateStringLength];
-};
-
-static char* datetimeFormat() {
+static char* DateTimeFormat() {
#if defined(OS_TIZEN)
- char* datetimeFormat = NULL;
+ char* dateTimeFormat = NULL;
char* regionFormat = NULL;
char* language = NULL;
char buf[256] = { 0, };
}
}
- datetimeFormat = dgettext("dt_fmt", buf);
+ dateTimeFormat = dgettext("dt_fmt", buf);
if(!language || !strcmp(language, ""))
unsetenv("LANGUAGE");
// FIXME: Workaround fix for not supported dt_fmt.
// Use default format if dt_fmt string is not exist.
- if (strlen(datetimeFormat) == strlen(buf) &&
- !strncmp(datetimeFormat, buf, strlen(buf))) {
+ if (strlen(dateTimeFormat) == strlen(buf) &&
+ !strncmp(dateTimeFormat, buf, strlen(buf))) {
return 0;
}
- return strdup(datetimeFormat);
+ return strdup(dateTimeFormat);
#else
return NULL;
#endif
}
InputPicker::InputPicker(EWebView& web_view_)
- : ewk_view_(web_view_.evas_object())
- , picker_layout_(0)
- , data_list_(0)
- , web_view_(web_view_) {
+ : web_view_(web_view_)
+ , ewk_view_(web_view_.evas_object())
+ , picker_layout_(0) {
}
InputPicker::~InputPicker() {
- if (picker_layout_) {
- if (picker_layout_->popup)
- evas_object_del(picker_layout_->popup);
- delete picker_layout_;
- }
+ DeletePicker();
+}
+
+void InputPicker::DeletePicker() {
+ if (!picker_layout_)
+ return;
+
+ delete picker_layout_;
+ picker_layout_ = 0;
}
#if defined(OS_TIZEN_MOBILE)
-void InputPicker::endEditingCallback(
+void InputPicker::EndEditingCallback(
void* data, Evas_Object* obj, void* event_info)
{
InputPicker* inputPicker = static_cast<InputPicker*>(data);
if (inputPicker)
- inputPicker->removeDatetimePickerDelayed();
+ inputPicker->RemoveDatetimePickerDelayed();
}
#endif
-void InputPicker::showDatePicker(
+void InputPicker::ShowDatePicker(
tizen_webview::Input_Type input_type, double input_date) {
web_view_.ExecuteEditCommand("Unselect", 0);
if (input_type == TW_INPUT_TYPE_DATE)
- showDatePopup(input_date);
+ ShowDatePopup(input_date);
else if (input_type == TW_INPUT_TYPE_TIME)
- showTimePopup(input_date);
+ ShowTimePopup(input_date);
else if (input_type == TW_INPUT_TYPE_DATETIME)
- showDatetimePopup(input_date, false);
+ ShowDatetimePopup(input_date, false);
else if (input_type == TW_INPUT_TYPE_DATETIMELOCAL)
- showDatetimePopup(input_date, true);
+ ShowDatetimePopup(input_date, true);
else if (input_type == TW_INPUT_TYPE_MONTH)
- showMonthPopup(input_date);
+ ShowMonthPopup(input_date);
else if (input_type == TW_INPUT_TYPE_WEEK)
- showWeekPopup(input_date);
+ ShowWeekPopup(input_date);
}
-void InputPicker::showColorPicker(int r, int g, int b, int alpha) {
- if (!picker_layout_)
+void InputPicker::ShowColorPicker(int r, int g, int b, int alpha) {
+ if (picker_layout_) {
+ // Just update the value.
+ if (picker_layout_->color_picker)
+ elm_colorselector_color_set(picker_layout_->color_picker, r, g, b, alpha);
+ evas_object_focus_set(picker_layout_->ok_button, true);
+ return;
+ }
+
picker_layout_ = new InputPicker::Layout(ewk_view_);
- picker_layout_->popup = elm_popup_add(ewk_view_);
- elm_object_part_text_set(picker_layout_->popup, "title,text", "Select color");
+
+ if (!picker_layout_->CreateWin())
+ return;
picker_layout_->initial_r = r;
picker_layout_->initial_g = g;
picker_layout_->initial_b = b;
-#if defined(OS_TIZEN_MOBILE)
- if (EflAssistHandle) {
- void (*webkit_ea_object_event_callback_add)(
- Evas_Object *,
- Ea_Callback_Type,
- Ea_Event_Cb func,
- void *);
- webkit_ea_object_event_callback_add = (void (*)(
- Evas_Object *,
- Ea_Callback_Type,
- Ea_Event_Cb func,
- void *)) dlsym(EflAssistHandle, "ea_object_event_callback_add");
- (*webkit_ea_object_event_callback_add)(
- picker_layout_->popup, EA_CALLBACK_BACK, handleBackKeyColorPicker, this);
- }
-#endif
-
- picker_layout_->layout = elm_layout_add(picker_layout_->popup);
-
- base::FilePath edj_dir;
- base::FilePath control_edj;
- PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edj_dir);
- control_edj = edj_dir.Append(FILE_PATH_LITERAL("control.edj"));
-
- elm_layout_file_set(
- picker_layout_->layout,
- control_edj.AsUTF8Unsafe().c_str(),
- "color_picker");
- evas_object_size_hint_weight_set(
- picker_layout_->layout,
- EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- evas_object_show(picker_layout_->layout);
- elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
-
- picker_layout_->colorRect = evas_object_rectangle_add(
- evas_object_evas_get(picker_layout_->layout));
- evas_object_size_hint_weight_set(
- picker_layout_->colorRect,
- EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- evas_object_show(picker_layout_->colorRect);
-
- evas_object_color_set(picker_layout_->colorRect, r, g, b, 255);
- elm_object_part_content_set(
- picker_layout_->layout,
- "elm.swallow.color_rect",
- picker_layout_->colorRect);
-
- static ColorPopupUserData color1Data;
- addColorRect("elm.swallow.color1", 128, 0, 0, &color1Data);
-
- static ColorPopupUserData color2Data;
- addColorRect("elm.swallow.color2", 255, 0, 128, &color2Data);
-
- static ColorPopupUserData color3Data;
- addColorRect("elm.swallow.color3", 255, 0, 0, &color3Data);
-
- static ColorPopupUserData color4Data;
- addColorRect("elm.swallow.color4", 255, 127, 39, &color4Data);
-
- static ColorPopupUserData color5Data;
- addColorRect("elm.swallow.color5", 255, 255, 0, &color5Data);
-
- static ColorPopupUserData color6Data;
- addColorRect("elm.swallow.color6", 0, 255, 0, &color6Data);
-
- static ColorPopupUserData color7Data;
- addColorRect("elm.swallow.color7", 0, 255, 255, &color7Data);
-
- static ColorPopupUserData color8Data;
- addColorRect("elm.swallow.color8", 0, 0, 255, &color8Data);
-
- static ColorPopupUserData color9Data;
- addColorRect("elm.swallow.color9", 0, 0, 128, &color9Data);
-
- static ColorPopupUserData color10Data;
- addColorRect("elm.swallow.color10", 64, 0, 64, &color10Data);
- static ColorPopupUserData color11Data;
- addColorRect("elm.swallow.color11", 153, 217, 234, &color11Data);
+ picker_layout_->CreateColorSelector();
- static ColorPopupUserData color12Data;
- addColorRect("elm.swallow.color12", 128, 128, 128, &color12Data);
-
- static ColorPopupUserData color13Data;
- addColorRect("elm.swallow.color13", 0, 0, 0, &color13Data);
-
- static ColorPopupUserData color14Data;
- addColorRect("elm.swallow.color14", 255, 255, 255, &color14Data);
-
- // Set focus on first color rect.
- if (color1Data.colorAccessObject)
- elm_object_focus_set(color1Data.colorAccessObject, true);
+ evas_object_smart_callback_add(picker_layout_->color_picker, "color,item,selected",
+ SelectedColorCallback, picker_layout_->color_rect);
+#if defined(OS_TIZEN_MOBILE)
+ ea_object_event_callback_add(picker_layout_->popup, EA_CALLBACK_BACK,
+ HandleBackKeyColorPicker, this);
+#endif
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup,
- "button1",
- picker_layout_->okButton);
+ picker_layout_->CreateOKButton();
evas_object_smart_callback_add(
- picker_layout_->okButton,
+ picker_layout_->ok_button,
"clicked",
- colorPickerCallback,
+ ColorPickerCallback,
this);
evas_object_show(picker_layout_->popup);
}
-void InputPicker::hideColorPicker() {
+void InputPicker::HideColorPicker() {
if (!picker_layout_)
return;
web_view_.web_contents().DidEndColorChooser();
- if (picker_layout_->popup) {
- evas_object_del(picker_layout_->popup);
- picker_layout_->popup = 0;
- }
-
delete picker_layout_;
picker_layout_ = 0;
}
-void InputPicker::keyDownColorPickerCallback(
- void* data, Evas* evas, Evas_Object* obj, void* event_info) {
- Evas_Event_Key_Down *event = (Evas_Event_Key_Down *)event_info;
- if (!strncmp("Return", event->keyname, 6) ||
- !strncmp("space", event->keyname, 5)) {
- ColorPopupUserData* color_data = static_cast<ColorPopupUserData*>(data);
- color_data->inputPicker->selectedColorCallback(data, 0, 0, 0);
- }
-}
-
-void InputPicker::selectedColorCallback(
- void* data, Evas* evas, Evas_Object* obj, void* event_info) {
+void InputPicker::SelectedColorCallback(
+ void* data, Evas_Object* obj, void* event_info) {
int r = 0;
int g = 0;
int b = 0;
int a = 0;
- ColorPopupUserData* color_data = static_cast<ColorPopupUserData*>(data);
- evas_object_color_get(color_data->color, &r, &g, &b, &a);
- evas_object_color_set(color_data->colorRect, r, g, b, a);
- elm_object_focus_set(color_data->colorAccessObject, true);
+ Elm_Object_Item *color_it = static_cast<Elm_Object_Item *>(event_info);
+ elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
+ evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
}
-void InputPicker::addColorRect(
- const char* part, int r, int g, int b, ColorPopupUserData* color_data) {
-#if defined(OS_TIZEN)
- Evas_Object* color = evas_object_rectangle_add(evas_object_evas_get(
- picker_layout_->layout));
- evas_object_size_hint_weight_set(color, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_color_set(color, r, g, b, 255);
- elm_object_part_content_set(picker_layout_->layout, part, color);
- evas_object_show(color);
-
- Evas_Object* accessObject = elm_access_object_register(
- color, picker_layout_->layout);
- elm_object_focus_custom_chain_append(
- picker_layout_->layout, accessObject, NULL);
-
- color_data->inputPicker = this;
- color_data->colorRect = picker_layout_->colorRect;
- color_data->color = color;
- color_data->colorAccessObject = accessObject;
-
- evas_object_event_callback_add(
- accessObject, EVAS_CALLBACK_KEY_DOWN, keyDownColorPickerCallback,
- color_data);
- evas_object_event_callback_add(
- color, EVAS_CALLBACK_MOUSE_DOWN, selectedColorCallback, color_data);
-#endif
-}
-
-void InputPicker::colorPickerCallback(
+void InputPicker::ColorPickerCallback(
void* data, Evas_Object* obj, void* event_info) {
InputPicker* inputPicker = static_cast<InputPicker*>(data);
int r(0), g(0), b(0), a(0);
- evas_object_color_get(inputPicker->picker_layout_->colorRect, &r, &g, &b, &a);
+ evas_object_color_get(inputPicker->picker_layout_->color_rect, &r, &g, &b, &a);
inputPicker->web_view_.web_contents().DidChooseColorInColorChooser(
SkColorSetARGB(a, r, g, b));
- inputPicker->hideColorPicker();
+ inputPicker->HideColorPicker();
}
#if defined(OS_TIZEN_MOBILE)
-void InputPicker::handleBackKeyColorPicker(
+void InputPicker::HandleBackKeyColorPicker(
void* data, Evas_Object* obj, void* event_info) {
InputPicker* inputPicker = static_cast<InputPicker*>(data);
inputPicker->web_view_.web_contents().DidChooseColorInColorChooser(
SkColorSetARGB(a, r, g, b));
- inputPicker->hideColorPicker();
+ inputPicker->HideColorPicker();
}
#endif
-void InputPicker::showDatePopup(double input_date) {
- time_t cur_time;
+namespace {
+
+struct tm* GetTime(time_t &cur_time, double input_date) {
struct tm* currentTime;
if (isnan(input_date)) {
time(&cur_time);
- currentTime = localtime(&cur_time);
} else {
base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
cur_time = doubleT.ToTimeT();
- currentTime = localtime(&cur_time);
}
+ currentTime = localtime(&cur_time);
+ return currentTime;
+}
+
+} // namespace
+
+void InputPicker::ShowDatePopup(double input_date) {
+ time_t cur_time;
+ struct tm* currentTime = GetTime(cur_time, input_date);
if (picker_layout_) {
// Just update the value.
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
- evas_object_focus_set(picker_layout_->okButton, true);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
+ evas_object_focus_set(picker_layout_->ok_button, true);
return;
}
picker_layout_ = new InputPicker::Layout(ewk_view_);
- createPopupLayout("Set Date", currentTime);
+ CreatePopupLayout("Set Date", currentTime);
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup, "button1", picker_layout_->okButton);
- evas_object_focus_set(picker_layout_->okButton, true);
+ evas_object_focus_set(picker_layout_->ok_button, true);
evas_object_smart_callback_add(
- picker_layout_->okButton, "clicked", datePopupCallback, this);
+ picker_layout_->ok_button, "clicked", DatePopupCallback, this);
+
elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
evas_object_show(picker_layout_->popup);
}
-void InputPicker::showWeekPopup(double input_date) {
+void InputPicker::ShowWeekPopup(double input_date) {
time_t cur_time;
- struct tm* currentTime;
-
- if (isnan(input_date)) {
- time(&cur_time);
- currentTime = localtime(&cur_time);
- } else {
- base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
- cur_time = doubleT.ToTimeT();
- currentTime = localtime(&cur_time);
- }
+ struct tm* currentTime = GetTime(cur_time, input_date);
if (picker_layout_) {
// Just update the value.
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
- evas_object_focus_set(picker_layout_->okButton, true);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
+ evas_object_focus_set(picker_layout_->ok_button, true);
return;
}
picker_layout_ = new InputPicker::Layout(ewk_view_);
- createPopupLayout("Set Week", currentTime);
+ CreatePopupLayout("Set Week", currentTime);
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup, "button1", picker_layout_->okButton);
- evas_object_focus_set(picker_layout_->okButton, true);
+ evas_object_focus_set(picker_layout_->ok_button, true);
evas_object_smart_callback_add(
- picker_layout_->okButton, "clicked", weekPopupCallback, this);
+ picker_layout_->ok_button, "clicked", WeekPopupCallback, this);
elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
evas_object_show(picker_layout_->popup);
}
-void InputPicker::showTimePopup(double input_date) {
+void InputPicker::ShowTimePopup(double input_date) {
time_t cur_time;
- struct tm* currentTime;
+ struct tm* currentTime = GetTime(cur_time, input_date);
- if (isnan(input_date)) {
- time(&cur_time);
- currentTime = localtime(&cur_time);
- } else {
- base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
- cur_time = doubleT.ToTimeT();
- currentTime = localtime(&cur_time);
- currentTime->tm_hour = currentTime->tm_hour - 1;
- }
+ if (!isnan(input_date))
+ currentTime->tm_hour -= 1;
if (picker_layout_) {
// Just update the value.
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
- evas_object_focus_set(picker_layout_->okButton, true);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
+ evas_object_focus_set(picker_layout_->ok_button, true);
return;
}
picker_layout_ = new InputPicker::Layout(ewk_view_);
- createPopupLayout("Set Time", currentTime);
- elm_object_style_set(picker_layout_->datePicker, "time_layout");
+ CreatePopupLayout("Set Time", currentTime);
+ elm_object_style_set(picker_layout_->date_picker, "time_layout");
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup, "button1", picker_layout_->okButton);
- evas_object_focus_set(picker_layout_->okButton, true);
+ evas_object_focus_set(picker_layout_->ok_button, true);
evas_object_smart_callback_add(
- picker_layout_->okButton, "clicked", timePopupCallback, this);
+ picker_layout_->ok_button, "clicked", TimePopupCallback, this);
elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
evas_object_show(picker_layout_->popup);
}
-void InputPicker::showMonthPopup(double input_date) {
+void InputPicker::ShowMonthPopup(double input_date) {
time_t cur_time;
- struct tm* currentTime;
-
- if (isnan(input_date)) {
- time(&cur_time);
- currentTime = localtime(&cur_time);
- } else {
- base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
- cur_time = doubleT.ToTimeT();
- currentTime = localtime(&cur_time);
- }
+ struct tm* currentTime = GetTime(cur_time, input_date);
if (picker_layout_) {
// Just update the value.
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
- evas_object_focus_set(picker_layout_->okButton, true);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
+ evas_object_focus_set(picker_layout_->ok_button, true);
return;
}
picker_layout_ = new InputPicker::Layout(ewk_view_);
- createPopupLayout("Set Month", currentTime);
+ CreatePopupLayout("Set Month", currentTime);
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup, "button1", picker_layout_->okButton);
- evas_object_focus_set(picker_layout_->okButton, true);
+ evas_object_focus_set(picker_layout_->ok_button, true);
evas_object_smart_callback_add(
- picker_layout_->okButton, "clicked", monthPopupCallback, this);
+ picker_layout_->ok_button, "clicked", MonthPopupCallback, this);
elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
evas_object_show(picker_layout_->popup);
}
-void InputPicker::showDatetimePopup(double input_date, bool datetime_local) {
+void InputPicker::ShowDatetimePopup(double input_date, bool datetime_local) {
time_t cur_time;
- struct tm* currentTime;
+ struct tm* currentTime = GetTime(cur_time, input_date);
- if (isnan(input_date)) {
- time(&cur_time);
- currentTime = localtime(&cur_time);
- } else {
- base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
- cur_time = doubleT.ToTimeT();
- currentTime = localtime(&cur_time);
- currentTime->tm_hour = currentTime->tm_hour - 2;
- }
+ if (!isnan(input_date))
+ currentTime->tm_hour -= 2;
if (picker_layout_) {
// Just update the value.
picker_layout_->datetime_local = datetime_local;
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
- evas_object_focus_set(picker_layout_->okButton, true);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
+ evas_object_focus_set(picker_layout_->ok_button, true);
return;
}
picker_layout_ = new InputPicker::Layout(ewk_view_);
picker_layout_->datetime_local = datetime_local;
- createPopupLayout("Set date and time", currentTime);
+ CreatePopupLayout("Set date and time", currentTime);
- picker_layout_->okButton = elm_button_add(picker_layout_->popup);
- elm_object_style_set(picker_layout_->okButton, "popup");
- elm_object_text_set(picker_layout_->okButton, "OK");
- elm_object_part_content_set(
- picker_layout_->popup, "button1", picker_layout_->okButton);
- evas_object_focus_set(picker_layout_->okButton, true);
+ evas_object_focus_set(picker_layout_->ok_button, true);
evas_object_smart_callback_add(
- picker_layout_->okButton, "clicked", datetimePopupCallback, this);
+ picker_layout_->ok_button, "clicked", DateTimePopupCallback, this);
elm_object_content_set(picker_layout_->popup, picker_layout_->layout);
evas_object_show(picker_layout_->popup);
}
-Eina_Bool InputPicker::removeDatetimePicker(void* data) {
+Eina_Bool InputPicker::RemoveDatetimePicker(void* data) {
InputPicker* inputPicker = static_cast<InputPicker*>(data);
inputPicker->web_view_.web_contents().DidCancelDialog();
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
return ECORE_CALLBACK_CANCEL;
}
-void InputPicker::removeDatetimePickerDelayed() {
- ecore_timer_add(0.1, removeDatetimePicker, this);
+void InputPicker::RemoveDatetimePickerDelayed() {
+ ecore_timer_add(0.1, RemoveDatetimePicker, this);
}
-void InputPicker::createPopupLayout(const char* title, struct tm* currentTime) {
- picker_layout_->popup = elm_popup_add(ewk_view_);
- evas_object_size_hint_weight_set(
- picker_layout_->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_part_text_set(picker_layout_->popup, "title,text", title);
+void InputPicker::CreatePopupLayout(const char* title, struct tm* currentTime) {
+ if (!picker_layout_->CreateWin())
+ return;
+
+ picker_layout_->CreateDateTimeSelector(title);
#if defined(OS_TIZEN_MOBILE)
- if (EflAssistHandle) {
- void (*webkit_ea_object_event_callback_add)(
- Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
- webkit_ea_object_event_callback_add = (void (*)(
- Evas_Object *,
- Ea_Callback_Type ,
- Ea_Event_Cb func,
- void *)) dlsym(EflAssistHandle, "ea_object_event_callback_add");
- (*webkit_ea_object_event_callback_add)(
- picker_layout_->popup, EA_CALLBACK_BACK, handleBackKeyDatePicker, this);
- }
+ ea_object_event_callback_add(picker_layout_->popup, EA_CALLBACK_BACK,
+ HandleBackKeyDatePicker, this);
#endif
- base::FilePath edj_dir;
- base::FilePath control_edj;
- PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edj_dir);
- control_edj = edj_dir.Append(FILE_PATH_LITERAL("control.edj"));
-
-
- picker_layout_->layout = elm_layout_add(picker_layout_->popup);
- elm_layout_file_set(
- picker_layout_->layout,
- control_edj.AsUTF8Unsafe().c_str(),
- "datetime_popup");
- evas_object_size_hint_weight_set(
- picker_layout_->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-
- picker_layout_->datePicker = elm_datetime_add(picker_layout_->layout);
- elm_object_part_content_set(
- picker_layout_->layout,
- "elm.swallow.datetime",
- picker_layout_->datePicker);
-
- char* format = datetimeFormat();
+ char* format = DateTimeFormat();
if (format) {
- elm_datetime_format_set(picker_layout_->datePicker, format);
+ elm_datetime_format_set(picker_layout_->date_picker, format);
free(format);
} else
- elm_datetime_format_set(picker_layout_->datePicker, defaultDatetimeFormat);
+ elm_datetime_format_set(picker_layout_->date_picker, defaultDatetimeFormat);
- elm_datetime_value_set(picker_layout_->datePicker, currentTime);
+ elm_datetime_value_set(picker_layout_->date_picker, currentTime);
#if defined(OS_TIZEN_MOBILE)
evas_object_smart_callback_add(
- picker_layout_->datePicker, "edit,end", endEditingCallback, 0);
+ picker_layout_->date_picker, "edit,end", EndEditingCallback, 0);
#endif
-}
-void InputPicker::deletePopupLayout() {
- if(picker_layout_->popup){
- evas_object_del(picker_layout_->popup);
- picker_layout_->popup = 0;
- }
+ picker_layout_->CreateOKButton();
+
+ evas_object_show(picker_layout_->popup);
}
-void InputPicker::datePopupCallback(
+void InputPicker::DatePopupCallback(
void* data, Evas_Object* obj, void* event_info) {
struct tm currentTime;
memset(¤tTime, 0, sizeof(struct tm));
InputPicker* inputPicker = static_cast<InputPicker*>(data);
- elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime);
+ elm_datetime_value_get(inputPicker->picker_layout_->date_picker, ¤tTime);
mktime(¤tTime);
char dateStr[20] = { 0, };
inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr));
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
}
-void InputPicker::weekPopupCallback(
+void InputPicker::WeekPopupCallback(
void* data, Evas_Object* obj, void* event_info) {
struct tm currentTime;
memset(¤tTime, 0, sizeof(struct tm));
InputPicker* inputPicker = static_cast<InputPicker*>(data);
- elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime);
+ elm_datetime_value_get(inputPicker->picker_layout_->date_picker, ¤tTime);
mktime(¤tTime);
char dateStr[20] = { 0, };
inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr));
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
}
-void InputPicker::timePopupCallback(
+void InputPicker::TimePopupCallback(
void* data, Evas_Object* obj, void* event_info) {
struct tm currentTime;
memset(¤tTime, 0, sizeof(struct tm));
InputPicker* inputPicker = static_cast<InputPicker*>(data);
- elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime);
+ elm_datetime_value_get(inputPicker->picker_layout_->date_picker, ¤tTime);
mktime(¤tTime);
char dateStr[20] = { 0, };
inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr));
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
}
-void InputPicker::monthPopupCallback(
+void InputPicker::MonthPopupCallback(
void* data, Evas_Object* obj, void* event_info) {
struct tm currentTime;
memset(¤tTime, 0, sizeof(struct tm));
InputPicker* inputPicker = static_cast<InputPicker*>(data);
mktime(¤tTime);
- elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime);
+ elm_datetime_value_get(inputPicker->picker_layout_->date_picker, ¤tTime);
char dateStr[20] = { 0, };
strftime(dateStr, 20, "%Y-%m", ¤tTime);
inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr));
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
}
-void InputPicker::datetimePopupCallback(
+void InputPicker::DateTimePopupCallback(
void* data, Evas_Object* obj, void* event_info) {
struct tm currentTime;
memset(¤tTime, 0, sizeof(struct tm));
InputPicker* inputPicker = static_cast<InputPicker*>(data);
- elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime);
+ elm_datetime_value_get(inputPicker->picker_layout_->date_picker, ¤tTime);
mktime(¤tTime);
char dateStr[50] = { 0, };
inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr));
inputPicker->web_view_.ExecuteEditCommand("Unselect", 0);
- inputPicker->deletePopupLayout();
- delete inputPicker->picker_layout_;
- inputPicker->picker_layout_ = 0;
+ inputPicker->DeletePicker();
}
#if defined(OS_TIZEN_MOBILE)
-void InputPicker::handleBackKeyDatePicker(
+void InputPicker::HandleBackKeyDatePicker(
void* data, Evas_Object* obj, void* event_info) {
- removeDatetimePicker(data);
+ RemoveDatetimePicker(data);
}
#endif