Wrong values are shown in inputpicker
authorDongjun Kim <djmix.kim@samsung.com>
Wed, 4 Mar 2015 17:24:39 +0000 (02:24 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
It has some problem with conversion from string to double.
Even, some values are omitted while conversion.

We need to change for solving this problem.
1. Change mechanism of date conversion.
2. Change to "String" which type of date parameter from renderer.

Together with: If769a0500f0a58f6b4457bf4bc62c107ead4486f

BUG: http://168.219.209.56/jira/browse/TNEF-531
Reviewed by: Hyunhak Kim, Jaesik Chang, Piotr Grad

Change-Id: I12ea9fdee6dad8e505e6c4df852f5609f30e7659
Signed-off-by: Dongjun Kim <djmix.kim@samsung.com>
tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.cc [changed mode: 0644->0755]
tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.h [changed mode: 0644->0755]
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h

old mode 100644 (file)
new mode 100755 (executable)
index 0ab7784..5f60727
@@ -34,6 +34,15 @@ static const unsigned maxDatetimeLength = 32;
 static const unsigned maxDateStringLength = 10;
 static const char defaultDatetimeFormat[] = "%Y/%m/%d %H:%M";
 
+struct dateTimeValue {
+    char year[maxDatetimeLength];
+    char mon[maxDatetimeLength];
+    char day[maxDatetimeLength];
+    char hour[maxDatetimeLength];
+    char min[maxDatetimeLength];
+    char sec[maxDatetimeLength];
+};
+
 struct InputPicker::Layout {
   Layout(Evas_Object *ewkView)
     : ewk_view_(ewkView)
@@ -319,35 +328,153 @@ void InputPicker::endEditingCallback(
 }
 #endif
 
+#if defined(OS_TIZEN)
 void InputPicker::showDatePicker(
-    ui::TextInputType input_type, double input_date) {
-
+    ui::TextInputType input_type, std::string input_date)
+#else
+void InputPicker::showDatePicker(
+    ui::TextInputType input_type, double input_date)
+#endif
+{
   web_view_.ExecuteEditCommand("Unselect", 0);
 
+  time_t curTime;
+  time(&curTime);
+  struct tm* currentTime = localtime(&curTime);
+
+#if defined(OS_TIZEN)
+  dateTimeValue dateString;
+  memset(&dateString, 0, sizeof(dateTimeValue));
+
+  if (input_date.c_str() && strlen(input_date.c_str())) {
+    if(input_type == ui::TEXT_INPUT_TYPE_WEEK) {
+
+      char tempDateValue[maxDatetimeLength] = {0};
+      snprintf(tempDateValue, maxDatetimeLength, "%s", input_date.c_str());
+
+      char* token = strtok(tempDateValue, "-");
+      int year = atoi(token);
+      token = strtok(0, "W");
+      int weekOfYear = atoi(token);
+
+      snprintf(tempDateValue, maxDatetimeLength, "01/01/%d 0:00", year);
+
+      base::Time reference_time;
+      base::Time::FromString(tempDateValue, &reference_time);
+      reference_time += base::TimeDelta::FromDays((weekOfYear-1)*7);
+
+      time_t cur_time = reference_time.ToTimeT();
+      struct tm *convertTime = localtime(&cur_time);
+
+      if(convertTime->tm_wday)
+      {
+        int dayDelta = 7-convertTime->tm_wday;
+        reference_time += base::TimeDelta::FromDays(dayDelta);
+        cur_time = reference_time.ToTimeT();
+        convertTime = localtime(&cur_time);
+      }
+
+      currentTime->tm_year = convertTime->tm_year;
+      currentTime->tm_mon = convertTime->tm_mon;
+      currentTime->tm_mday = convertTime->tm_mday;
+    }
+    else {
+      char tempValue[maxDatetimeLength] = {0};
+      snprintf(tempValue, maxDatetimeLength, "%s", input_date.c_str());
+      char* token = strtok(tempValue,"-");
+
+      if (token)
+        strncpy(dateString.year, token, maxDatetimeLength);
+      token = strtok(0, "-");
+      if (token)
+        strncpy(dateString.mon, token, maxDatetimeLength);
+      token = strtok(0, "-");
+      if (token)
+        strncpy(dateString.day, token, maxDatetimeLength);
+
+      if (dateString.year)
+        currentTime->tm_year = atoi(dateString.year);
+      if (dateString.mon)
+        currentTime->tm_mon = atoi(dateString.mon);
+      if (dateString.day)
+        currentTime->tm_mday = atoi(dateString.day);
+
+      currentTime->tm_year = currentTime->tm_year - 1900;
+      currentTime->tm_mon = currentTime->tm_mon - 1;
+
+      if (input_type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
+          input_type == ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD ||
+          input_type == ui::TEXT_INPUT_TYPE_DATE_TIME) {
+        char tempDateValue[maxDatetimeLength] = {0};
+        snprintf(tempDateValue, maxDatetimeLength, "%s", input_date.c_str());
+
+        token = strtok(tempDateValue, "T");
+        token = strtok(0, ":");
+        if (token)
+          strncpy(dateString.hour, token, maxDatetimeLength);
+        token = strtok(0, ":");
+        if (token)
+          strncpy(dateString.min, token, maxDatetimeLength);
+        if (dateString.hour)
+          currentTime->tm_hour = atoi(dateString.hour);
+        if (dateString.min)
+          currentTime->tm_min = atoi(dateString.min);
+      }
+
+      if (input_type == ui::TEXT_INPUT_TYPE_TIME) {
+        currentTime = localtime(&curTime);
+        char tempDateValue[maxDatetimeLength] = {0};
+        snprintf(tempDateValue, maxDatetimeLength, "%s", input_date.c_str());
+
+        token = strtok(tempDateValue, ":");
+        if (token)
+          strncpy(dateString.hour, token, maxDatetimeLength);
+        token = strtok(0, ":");
+        if (token)
+          strncpy(dateString.min, token, maxDatetimeLength);
+        if (dateString.hour)
+          currentTime->tm_hour = atoi(dateString.hour);
+        if (dateString.min)
+          currentTime->tm_min = atoi(dateString.min);
+      }
+    }
+  }
+#else
+  if (isnan(input_date)) {
+    time(&curTime);
+    currentTime = localtime(&curTime);
+  }
+  else {
+    base::Time doubleT = base::Time::FromDoubleT(input_date/1000);
+    curTime = doubleT.ToTimeT();
+    currentTime = localtime(&curTime);
+    currentTime->tm_hour = currentTime->tm_hour - 1;
+  }
+#endif
+
   switch (input_type) {
     case ui::TEXT_INPUT_TYPE_DATE:
-      showDatePopup(input_date);
+      showDatePopup(currentTime);
       break;
     case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
     case ui::TEXT_INPUT_TYPE_DATE_TIME:
-      showDatetimePopup(input_date, false);
+      showDatetimePopup(currentTime, false /*datetime*/);
       break;
     case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
-      showDatetimePopup(input_date, true);
+      showDatetimePopup(currentTime, true /* datetime_local */);
       break;
     case ui::TEXT_INPUT_TYPE_TIME:
-      showTimePopup(input_date);
+      showTimePopup(currentTime);
       break;
     case ui::TEXT_INPUT_TYPE_WEEK:
-      showWeekPopup(input_date);
+      showWeekPopup(currentTime);
       break;
     case ui::TEXT_INPUT_TYPE_MONTH:
-      showMonthPopup(input_date);
+      showMonthPopup(currentTime);
       break;
     default:
       break;
   }
-
 }
 
 void InputPicker::ShowColorPicker(int r, int g, int b, int alpha) {
@@ -440,19 +567,7 @@ void InputPicker::HandleBackKeyColorPicker(
 }
 #endif
 
-void InputPicker::showDatePopup(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);
-  }
-
+void InputPicker::showDatePopup(struct tm* currentTime) {
   if (picker_layout_) {
     // Just update the value.
     elm_datetime_value_set(picker_layout_->datePicker, currentTime);
@@ -477,19 +592,7 @@ void InputPicker::showDatePopup(double input_date) {
   evas_object_show(picker_layout_->popup);
 }
 
-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);
-  }
-
+void InputPicker::showWeekPopup(struct tm* currentTime) {
   if (picker_layout_) {
     // Just update the value.
     elm_datetime_value_set(picker_layout_->datePicker, currentTime);
@@ -514,31 +617,17 @@ void InputPicker::showWeekPopup(double input_date) {
   evas_object_show(picker_layout_->popup);
 }
 
-void InputPicker::showTimePopup(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);
-    currentTime->tm_hour = currentTime->tm_hour - 1;
-  }
-
+void InputPicker::showTimePopup(struct tm* currentTime) {
   if (picker_layout_) {
     // Just update the value.
-    elm_datetime_value_set(picker_layout_->datePicker, currentTime);
+    elm_datetime_value_set(picker_layout_->time_picker, currentTime);
     evas_object_focus_set(picker_layout_->okButton, true);
     return;
   }
 
   picker_layout_ = new InputPicker::Layout(ewk_view_);
-  CreatePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_TIME"),
+  CreateTimePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_TIME"),
       currentTime);
-  elm_object_style_set(picker_layout_->datePicker, "time_layout");
 
   picker_layout_->okButton = elm_button_add(picker_layout_->popup);
   elm_object_style_set(picker_layout_->okButton, "popup");
@@ -553,19 +642,7 @@ void InputPicker::showTimePopup(double input_date) {
   evas_object_show(picker_layout_->popup);
 }
 
-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);
-  }
-
+void InputPicker::showMonthPopup(struct tm* currentTime) {
   if (picker_layout_) {
     // Just update the value.
     elm_datetime_value_set(picker_layout_->datePicker, currentTime);
@@ -590,20 +667,7 @@ void InputPicker::showMonthPopup(double input_date) {
   evas_object_show(picker_layout_->popup);
 }
 
-void InputPicker::showDatetimePopup(double input_date, bool datetime_local) {
-  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);
-    currentTime->tm_hour = currentTime->tm_hour - 2;
-  }
-
+void InputPicker::showDatetimePopup(struct tm* currentTime, bool datetime_local) {
   if (picker_layout_) {
     // Just update the value.
     picker_layout_->datetime_local = datetime_local;
@@ -707,6 +771,7 @@ void InputPicker::CreatePopupLayout(const char* title, struct tm* currentTime) {
   }
 
   elm_datetime_value_set(picker_layout_->datePicker, currentTime);
+
 #if defined(OS_TIZEN_MOBILE)
   evas_object_smart_callback_add(
       picker_layout_->datePicker, "edit,end", endEditingCallback, 0);
@@ -781,6 +846,64 @@ void InputPicker::CreateDateTimePopupLayout(const char* title, struct tm* curren
 #endif
 }
 
+void InputPicker::CreateTimePopupLayout(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);
+
+#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);
+  }
+#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(),
+      "date_popup");
+  evas_object_size_hint_weight_set(
+      picker_layout_->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+  picker_layout_->time_picker = elm_datetime_add(picker_layout_->layout);
+  elm_object_part_content_set(
+      picker_layout_->layout,
+      "elm.swallow.datetime",
+      picker_layout_->time_picker);
+
+  elm_object_style_set(picker_layout_->time_picker, "time_layout");
+
+  char* format = datetimeFormat();
+  if (format) {
+    elm_datetime_format_set(picker_layout_->time_picker, format);
+    free(format);
+  } else {
+    elm_datetime_format_set(picker_layout_->time_picker, defaultDatetimeFormat);
+  }
+
+  elm_datetime_value_set(picker_layout_->time_picker, currentTime);
+
+#if defined(OS_TIZEN_MOBILE)
+  evas_object_smart_callback_add(
+      picker_layout_->time_picker, "edit,end", endEditingCallback, 0);
+#endif
+}
+
 void InputPicker::deletePopupLayout() {
   if(picker_layout_->popup){
     evas_object_del(picker_layout_->popup);
@@ -837,7 +960,7 @@ void InputPicker::timePopupCallback(
 
   InputPicker* inputPicker = static_cast<InputPicker*>(data);
 
-  elm_datetime_value_get(inputPicker->picker_layout_->datePicker, &currentTime);
+  elm_datetime_value_get(inputPicker->picker_layout_->time_picker, &currentTime);
   mktime(&currentTime);
 
   char dateStr[20] = { 0, };
old mode 100644 (file)
new mode 100755 (executable)
index 0c3afdf..38361bd
@@ -7,6 +7,7 @@
 
 #include <ctime>
 #include <Evas.h>
+#include <string>
 #include "ui/base/ime/text_input_type.h"
 
 class EWebView;
@@ -22,8 +23,12 @@ class InputPicker {
     explicit InputPicker(EWebView& web_view_);
     ~InputPicker();
 
+#if defined(OS_TIZEN)
     void showDatePicker(
-        ui::TextInputType input_type, double input_date);
+        ui::TextInputType input_type, std::string input_date);
+#else
+    void showDatePicker(ui::TextInputType input_type, double input_date);
+#endif
     void ShowColorPicker(int r, int g, int b, int alpha);
     void HideColorPicker();
     void SetPopupSize(int width, int height);
@@ -31,14 +36,15 @@ class InputPicker {
   private:
     struct Layout;
 
-    void showDatePopup(double input_date);
-    void showTimePopup(double input_date);
-    void showMonthPopup(double input_date);
-    void showWeekPopup(double input_date);
-    void showDatetimePopup(double input_date, bool datetimeLocal);
+    void showDatePopup(struct tm* currentTime);
+    void showTimePopup(struct tm* currentTime);
+    void showMonthPopup(struct tm* currentTime);
+    void showWeekPopup(struct tm* currentTime);
+    void showDatetimePopup(struct tm* currentTime, bool datetime_local);
     void removeDatetimePickerDelayed();
     void CreatePopupLayout(const char* title, struct tm* currentTime);
     void CreateDateTimePopupLayout(const char* title, struct tm* currentTime);
+    void CreateTimePopupLayout(const char* title, struct tm* currentTime);
     void deletePopupLayout();
     void addColorRect(
         const char* part, int r, int g, int b, ColorPopupUserData* color_data);
index 3495a36..0948c24 100644 (file)
@@ -2159,8 +2159,12 @@ bool EWebView::SetColorPickerColor(int r, int g, int b, int a) {
 }
 
 void EWebView::InputPickerShow(
-    ui::TextInputType input_type, double input_value) {
-
+#if defined(OS_TIZEN)
+    ui::TextInputType input_type, std::string input_value)
+#else
+    ui::TextInputType input_type, double input_value)
+#endif
+{
   inputPicker_.reset(new InputPicker(*this));
   inputPicker_->showDatePicker(input_type, input_value);
 }
index 2fae943..e993a29 100644 (file)
@@ -434,8 +434,12 @@ class EWebView {
   void RequestColorPicker(int r, int g, int b, int a);
   void DismissColorPicker();
   bool SetColorPickerColor(int r, int g, int b, int a);
+#if defined(OS_TIZEN)
   void InputPickerShow(
-      ui::TextInputType input_type, double input_value);
+      ui::TextInputType input_type, std::string input_value);
+#else
+  void InputPickerShow(ui::TextInputType input_type, double input_value);
+#endif
   void FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId);
 
 #ifdef TIZEN_EDGE_EFFECT
index 3258ee5..5ad2e77 100644 (file)
@@ -587,7 +587,11 @@ content::ColorChooser* WebContentsDelegateEfl::OpenColorChooser(
 
 void WebContentsDelegateEfl::OpenDateTimeDialog(
     ui::TextInputType dialog_type,
+#if defined(OS_TIZEN)
+    std::string dialog_value,
+#else
     double dialog_value,
+#endif
     double min,
     double max,
     double step,
index 7cb8238..a134745 100644 (file)
@@ -152,7 +152,11 @@ class WebContentsDelegateEfl
   ColorChooser* OpenColorChooser(WebContents* web_contents, SkColor color,
       const std::vector<ColorSuggestion>& suggestions) override;
   void OpenDateTimeDialog(ui::TextInputType dialog_type,
+#if defined(OS_TIZEN)
+      std::string dialog_value,
+#else
       double dialog_value,
+#endif
       double min,
       double max,
       double step,