From 196de70fcf647c674e1ef5e2123745286a69f4f2 Mon Sep 17 00:00:00 2001 From: "ayush.k123" Date: Tue, 17 Jan 2023 09:29:53 +0530 Subject: [PATCH] [M108 Migration][NativeControl] InputPicker Migration This patch includes below changes: - Rename InputPicker.[h|cc] to input_picker.[h|cc]. - And rename inputpicker directory to input_picker too. - Layout struct was changed to class and it take charge of creating layout and handling callbacks. - Add static |CreateAndShow*| functions to create and show pickers instead of |show*Popup|. - Integrate |*popupCallback| for date picker to reduce duplication. - Use Android's ColorChooserUIController for color chooser implementation. Reference: https://review.tizen.org/gerrit/274457/ Change-Id: Iaac7ace5541067b799fc8f6fb804d6de3dd86cf6 Signed-off-by: Ayush Kumar --- content/browser/web_contents/web_contents_impl.cc | 10 +- content/browser/web_contents/web_contents_impl.h | 6 +- content/public/browser/web_contents.h | 2 +- third_party/blink/public/mojom/BUILD.gn | 2 +- .../core/html/forms/color_chooser_ui_controller.cc | 4 +- .../core/html/forms/color_chooser_ui_controller.h | 2 +- .../blink/renderer/core/page/chrome_client_impl.cc | 7 + tizen_src/ewk/efl_integration/BUILD.gn | 8 +- .../color_chooser_efl.cc | 8 +- .../color_chooser_efl.h | 11 +- .../browser/input_picker/input_picker.cc | 726 ++++++++++++++++ .../browser/input_picker/input_picker.h | 111 +++ .../browser/inputpicker/InputPicker.cc | 957 --------------------- .../browser/inputpicker/InputPicker.h | 83 -- tizen_src/ewk/efl_integration/eweb_view.cc | 14 +- tizen_src/ewk/efl_integration/eweb_view.h | 6 +- tizen_src/ewk/efl_integration/resource/BUILD.gn | 4 +- .../efl_integration/web_contents_delegate_efl.cc | 2 +- 18 files changed, 881 insertions(+), 1082 deletions(-) mode change 100644 => 100755 content/browser/web_contents/web_contents_impl.h mode change 100644 => 100755 content/public/browser/web_contents.h mode change 100644 => 100755 tizen_src/ewk/efl_integration/BUILD.gn rename tizen_src/ewk/efl_integration/browser/{inputpicker => input_picker}/color_chooser_efl.cc (86%) rename tizen_src/ewk/efl_integration/browser/{inputpicker => input_picker}/color_chooser_efl.h (63%) create mode 100644 tizen_src/ewk/efl_integration/browser/input_picker/input_picker.cc create mode 100644 tizen_src/ewk/efl_integration/browser/input_picker/input_picker.h delete mode 100755 tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.cc delete mode 100755 tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.h mode change 100644 => 100755 tizen_src/ewk/efl_integration/eweb_view.h diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 0d4eb02..2fc5272 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -712,7 +712,7 @@ class WebContentsImpl::WebContentsDestructionObserver raw_ptr owner_; }; -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) // TODO(sreejakshetty): Make |WebContentsImpl::ColorChooserHolder| per-frame // instead of WebContents-owned. // WebContentsImpl::ColorChooserHolder ----------------------------------------- @@ -1045,7 +1045,7 @@ WebContentsImpl::~WebContentsImpl() { dialog_manager_->CancelDialogs(this, /*reset_state=*/true); } -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) color_chooser_holder_.reset(); #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) find_request_manager_.reset(); @@ -5390,7 +5390,7 @@ WebContents* WebContentsImpl::GetFirstWebContentsInLiveOriginalOpenerChain() { : nullptr; } -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DidChooseColorInColorChooser", @@ -6447,7 +6447,7 @@ void WebContentsImpl::OnColorChooserFactoryReceiver( color_chooser_factory_receivers_.Add(this, std::move(receiver)); } -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void WebContentsImpl::OpenColorChooser( mojo::PendingReceiver chooser_receiver, mojo::PendingRemote client, @@ -9413,7 +9413,7 @@ void WebContentsImpl::RenderFrameHostStateChanged( dict.Add("new", new_state); }); -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) if (old_state == LifecycleState::kActive && !render_frame_host->GetParent()) { // TODO(sreejakshetty): Remove this reset when ColorChooserHolder becomes // per-frame. diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h old mode 100644 new mode 100755 index bd28298..b8ab515 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -529,7 +529,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, RenderFrameHostImpl* GetOpener() override; bool HasLiveOriginalOpenerChain() override; WebContents* GetFirstWebContentsInLiveOriginalOpenerChain() override; -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void DidChooseColorInColorChooser(SkColor color) override; void DidEndColorChooser() override; #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) @@ -1046,7 +1046,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, // blink::mojom::ColorChooserFactory --------------------------------------- void OnColorChooserFactoryReceiver( mojo::PendingReceiver receiver); -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void OpenColorChooser( mojo::PendingReceiver chooser, mojo::PendingRemote client, @@ -2127,7 +2127,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, gfx::Size device_emulation_size_; gfx::Size view_size_before_emulation_; -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) // Holds information about a current color chooser dialog, if one is visible. class ColorChooserHolder; std::unique_ptr color_chooser_holder_; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h old mode 100644 new mode 100755 index aea5078..273d548 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -1045,7 +1045,7 @@ class WebContents : public PageNavigator, // Returns false if the request is no longer valid, otherwise true. virtual bool GotResponseToKeyboardLockRequest(bool allowed) = 0; -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) // Called when the user has selected a color in the color chooser. virtual void DidChooseColorInColorChooser(SkColor color) = 0; diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn index ea681fe..40822a7 100644 --- a/third_party/blink/public/mojom/BUILD.gn +++ b/third_party/blink/public/mojom/BUILD.gn @@ -326,7 +326,7 @@ mojom("mojom_platform") { if (use_ozone) { enabled_features += [ "is_selection_clipboard_buffer_possible" ] } - if (is_android || is_mac) { + if (is_android || is_mac || use_efl) { enabled_features += [ "is_using_open_color_chooser" ] } if (tizen_product_tv) { diff --git a/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.cc b/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.cc index 97b2064..140bc65 100644 --- a/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.cc +++ b/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.cc @@ -53,7 +53,7 @@ void ColorChooserUIController::Trace(Visitor* visitor) const { } void ColorChooserUIController::OpenUI() { -#if BUILDFLAG(IS_ANDROID) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_EFL) OpenColorChooser(); #else NOTREACHED() << "ColorChooserUIController should only be used on Android"; @@ -79,7 +79,7 @@ void ColorChooserUIController::DidChooseColor(uint32_t color) { client_->DidChooseColor(Color::FromRGBA32(color)); } -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void ColorChooserUIController::OpenColorChooser() { DCHECK(!chooser_); frame_->GetBrowserInterfaceBroker().GetInterface( diff --git a/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.h b/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.h index 41e6097..0c3e11e 100644 --- a/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.h +++ b/third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.h @@ -63,7 +63,7 @@ class CORE_EXPORT ColorChooserUIController void DidChooseColor(uint32_t color) final; protected: -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL) void OpenColorChooser(); #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) mojo::Remote chooser_; diff --git a/third_party/blink/renderer/core/page/chrome_client_impl.cc b/third_party/blink/renderer/core/page/chrome_client_impl.cc index 5a1b86b..ec0e285 100644 --- a/third_party/blink/renderer/core/page/chrome_client_impl.cc +++ b/third_party/blink/renderer/core/page/chrome_client_impl.cc @@ -711,6 +711,12 @@ ColorChooser* ChromeClientImpl::OpenColorChooser( if (frame->GetDocument()->GetSettings()->GetImmersiveModeEnabled()) return nullptr; +#if defined(USE_EFL) + // EFL port's color picker implementation is based on + // ColorChooserUIController, similar to Android's impl. + controller = + MakeGarbageCollected(frame, chooser_client); +#else if (RuntimeEnabledFeatures::PagePopupEnabled()) { controller = MakeGarbageCollected( frame, this, chooser_client); @@ -721,6 +727,7 @@ ColorChooser* ChromeClientImpl::OpenColorChooser( controller = MakeGarbageCollected(frame, chooser_client); } +#endif controller->OpenUI(); return controller; } diff --git a/tizen_src/ewk/efl_integration/BUILD.gn b/tizen_src/ewk/efl_integration/BUILD.gn old mode 100644 new mode 100755 index da0da3390..8965db0 --- a/tizen_src/ewk/efl_integration/BUILD.gn +++ b/tizen_src/ewk/efl_integration/BUILD.gn @@ -309,10 +309,10 @@ shared_library("chromium-ewk") { "browser/geolocation/geolocation_permission_context_efl.h", "browser/geolocation/location_provider_efl.cc", "browser/geolocation/location_provider_efl.h", - "browser/inputpicker/InputPicker.cc", - "browser/inputpicker/InputPicker.h", - "browser/inputpicker/color_chooser_efl.cc", - "browser/inputpicker/color_chooser_efl.h", + "browser/input_picker/color_chooser_efl.cc", + "browser/input_picker/color_chooser_efl.h", + "browser/input_picker/input_picker.cc", + "browser/input_picker/input_picker.h", "browser/network_service/browser_url_loader_throttle_efl.cc", "browser/network_service/browser_url_loader_throttle_efl.h", "browser/notification/notification_controller_efl.cc", diff --git a/tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.cc b/tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.cc similarity index 86% rename from tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.cc rename to tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.cc index 102e50b..4a91cc5 100644 --- a/tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.cc +++ b/tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.cc @@ -9,11 +9,9 @@ namespace content { ColorChooserEfl::ColorChooserEfl(WebContents& web_contents) - : web_contents_(web_contents) { -} + : web_contents_(web_contents) {} -ColorChooserEfl::~ColorChooserEfl() { -} +ColorChooserEfl::~ColorChooserEfl() {} void ColorChooserEfl::SetSelectedColor(SkColor color) { #if !defined(EWK_BRINGUP) // FIXME: m94 bringup @@ -26,4 +24,4 @@ void ColorChooserEfl::End() { web_contents_.DidEndColorChooser(); #endif } -} +} // namespace content diff --git a/tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.h b/tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.h similarity index 63% rename from tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.h rename to tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.h index 59d6fdb..9091a33 100644 --- a/tizen_src/ewk/efl_integration/browser/inputpicker/color_chooser_efl.h +++ b/tizen_src/ewk/efl_integration/browser/input_picker/color_chooser_efl.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ColorChooserEfl_h -#define ColorChooserEfl_h +#ifndef EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_COLOR_CHOOSER_EFL_H_ +#define EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_COLOR_CHOOSER_EFL_H_ #include "content/public/browser/color_chooser.h" #include "third_party/skia/include/core/SkColor.h" @@ -20,6 +20,9 @@ class ColorChooserEfl : public ColorChooser { ColorChooserEfl(WebContents& web_contents); ~ColorChooserEfl(); + ColorChooserEfl(const ColorChooserEfl&) = delete; + ColorChooserEfl& operator=(const ColorChooserEfl&) = delete; + // ColorChooser implementation. void SetSelectedColor(SkColor color) override; void End() override; @@ -28,6 +31,6 @@ class ColorChooserEfl : public ColorChooser { WebContents& web_contents_; }; -} +} // namespace content -#endif // ColorChooserEfl_h +#endif // EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_COLOR_CHOOSER_EFL_H_ diff --git a/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.cc b/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.cc new file mode 100644 index 0000000..af7b8ff --- /dev/null +++ b/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.cc @@ -0,0 +1,726 @@ +// Copyright 2014 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "input_picker.h" + +#include +#include +#include +#include + +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/time/time.h" +#include "common/web_contents_utils.h" +#include "content/common/paths_efl.h" +#include "content/public/browser/web_contents.h" +#include "eweb_view.h" +#include "tizen/system_info.h" + +#if BUILDFLAG(IS_TIZEN) +#include +#include +#endif + +namespace content { + +static const char* kDefaultDatetimeFormat = "%Y/%m/%d %H:%M"; + +InputPicker::Layout::Layout(InputPicker* parent) : parent_(parent) { + CHECK(parent_); + evas_object_focus_set(parent_->web_view_->evas_object(), false); + // FIXME: Workaround. OSP requirement. OSP want to block own touch event + // while webkit internal picker is running. + evas_object_smart_callback_call(parent_->web_view_->evas_object(), + "input,picker,show", 0); +} + +InputPicker::Layout::~Layout() { + // FIXME: Workaround. OSP requirement. OSP want to block own touch event + // while webkit internal picker is running. + evas_object_smart_callback_call(parent_->web_view_->evas_object(), + "input,picker,hide", 0); + evas_object_focus_set(parent_->web_view_->evas_object(), true); + + if (!conformant_) + return; + + if (is_color_picker_) + DeleteColorPickerCallbacks(); + else + DeleteDatePickerCallbacks(); + + evas_object_del(conformant_); + conformant_ = nullptr; +} + +// static +std::unique_ptr +InputPicker::Layout::CreateAndShowColorPickerLayout(InputPicker* parent, + int r, + int g, + int b) { + std::unique_ptr picker_layout(new Layout(parent)); + picker_layout->is_color_picker_ = true; + + if (!picker_layout->AddBaseLayout("Select color", + "colorselector_popup_layout")) + return nullptr; + + picker_layout->color_rect_ = + evas_object_rectangle_add(evas_object_evas_get(picker_layout->layout_)); + if (!picker_layout->color_rect_) + return nullptr; + + evas_object_size_hint_weight_set(picker_layout->color_rect_, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + evas_object_show(picker_layout->color_rect_); + evas_object_color_set(picker_layout->color_rect_, r, g, b, 255); + elm_object_part_content_set(picker_layout->layout_, "rect", + picker_layout->color_rect_); + + if (!picker_layout->AddColorSelector(r, g, b)) + return nullptr; + + if (!picker_layout->AddOKButton()) + return nullptr; + + evas_object_show(picker_layout->layout_); + elm_object_content_set(picker_layout->popup_, picker_layout->layout_); + evas_object_show(picker_layout->popup_); + + picker_layout->red_ = r; + picker_layout->green_ = g; + picker_layout->blue_ = b; + + picker_layout->AddColorPickerCallbacks(); + + return picker_layout; +} + +static char* GetDateTimeFormat() { +#if BUILDFLAG(IS_TIZEN) + char* language = getenv("LANGUAGE"); + setenv("LANGUAGE", "en_US", 1); + + char* region_format = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (!region_format) + return nullptr; + + int time_value = 0; + char buf[256] = {0}; + vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &time_value); + if (time_value == VCONFKEY_TIME_FORMAT_24) + snprintf(buf, sizeof(buf), "%s_DTFMT_24HR", region_format); + else + snprintf(buf, sizeof(buf), "%s_DTFMT_12HR", region_format); + + free(region_format); + + // FIXME: Workaround fix for region format. + int buf_length = strlen(buf); + for (int i = 0; i < buf_length - 4; i++) { + if (buf[i] == 'u' && buf[i + 1] == 't' && buf[i + 2] == 'f') { + if (buf[i + 3] == '8') { + // utf8 -> UTF-8 + for (int j = buf_length; j > i + 3; j--) + buf[j] = buf[j - 1]; + buf[i + 3] = '-'; + buf[buf_length + 1] = '\0'; + } else if (buf[i + 3] == '-' && buf[i + 4] == '8') { + // utf-8 -> UTF-8 + } else { + break; + } + + buf[i] = 'U'; + buf[i + 1] = 'T'; + buf[i + 2] = 'F'; + break; + } + } + + if (!language || !strcmp(language, "")) + unsetenv("LANGUAGE"); + else + setenv("LANGUAGE", language, 1); + + char* date_time_format = dgettext("dt_fmt", buf); + // FIXME: Workaround fix for not supported dt_fmt. + // Use default format if dt_fmt string is not exist. + if (strlen(date_time_format) == strlen(buf) && + !strncmp(date_time_format, buf, strlen(buf))) + return nullptr; + + return strdup(date_time_format); +#else + return nullptr; +#endif +} + +// static +std::unique_ptr +InputPicker::Layout::CreateAndShowDateLayout(InputPicker* parent, + struct tm* current_time, + ui::TextInputType type) { + std::unique_ptr picker_layout(new Layout(parent)); + + picker_layout->input_type_ = type; + + std::string title; + switch (type) { + case ui::TEXT_INPUT_TYPE_DATE: { + title = "IDS_WEBVIEW_HEADER_SET_DATE"; + break; + } + case ui::TEXT_INPUT_TYPE_WEEK: { + title = "IDS_WEBVIEW_HEADER_SET_WEEK"; + break; + } + case ui::TEXT_INPUT_TYPE_MONTH: { + title = "IDS_WEBVIEW_HEADER_SET_MONTH"; + break; + } + default: + NOTREACHED(); + break; + } + + if (!picker_layout->AddBaseLayout(dgettext("WebKit", title.c_str()), + "date_popup")) + return nullptr; + + picker_layout->date_picker_ = elm_datetime_add(picker_layout->layout_); + if (!picker_layout->date_picker_) + return nullptr; + + elm_object_part_content_set(picker_layout->layout_, "elm.swallow.datetime", + picker_layout->date_picker_); + + char* format = GetDateTimeFormat(); + if (format) { + elm_datetime_format_set(picker_layout->date_picker_, format); + free(format); + } else { + elm_datetime_format_set(picker_layout->date_picker_, + kDefaultDatetimeFormat); + } + + elm_datetime_value_set(picker_layout->date_picker_, current_time); + + if (!picker_layout->AddOKButton()) + return nullptr; + + if (type == ui::TEXT_INPUT_TYPE_MONTH) { + elm_datetime_field_visible_set(picker_layout->date_picker_, + ELM_DATETIME_DATE, EINA_FALSE); + } + elm_datetime_field_visible_set(picker_layout->date_picker_, ELM_DATETIME_HOUR, + EINA_FALSE); + elm_datetime_field_visible_set(picker_layout->date_picker_, + ELM_DATETIME_MINUTE, EINA_FALSE); + + picker_layout->AddDatePickerCallbacks(); + + elm_object_content_set(picker_layout->popup_, picker_layout->layout_); + evas_object_show(picker_layout->popup_); + + return picker_layout; +} + +// static +std::unique_ptr +InputPicker::Layout::CreateAndShowDateTimeLayout(InputPicker* parent, + struct tm* current_time, + ui::TextInputType type) { + std::unique_ptr picker_layout(new Layout(parent)); + + picker_layout->input_type_ = type; + + elm_object_scale_set(picker_layout->popup_, 0.7); + if (!picker_layout->AddBaseLayout( + dgettext("WebKit", "IDS_WEBVIEW_HEADER_SET_DATE_AND_TIME"), + "datetime_popup")) + return nullptr; + + picker_layout->time_picker_ = elm_datetime_add(picker_layout->layout_); + picker_layout->date_picker_ = elm_datetime_add(picker_layout->layout_); + if (!picker_layout->time_picker_ || !picker_layout->date_picker_) + return nullptr; + + elm_object_part_content_set(picker_layout->layout_, "elm.swallow.datetime", + picker_layout->time_picker_); + elm_object_part_content_set(picker_layout->layout_, "elm.swallow.datetime2", + picker_layout->date_picker_); + elm_object_style_set(picker_layout->time_picker_, "time_layout"); + + char* format = GetDateTimeFormat(); + if (format) { + elm_datetime_format_set(picker_layout->date_picker_, format); + elm_datetime_format_set(picker_layout->time_picker_, format); + free(format); + } else { + elm_datetime_format_set(picker_layout->date_picker_, + kDefaultDatetimeFormat); + elm_datetime_format_set(picker_layout->time_picker_, + kDefaultDatetimeFormat); + } + + elm_datetime_value_set(picker_layout->date_picker_, current_time); + elm_datetime_value_set(picker_layout->time_picker_, current_time); + + if (!picker_layout->AddOKButton()) + return nullptr; + + picker_layout->AddDatePickerCallbacks(); + + elm_object_content_set(picker_layout->popup_, picker_layout->layout_); + evas_object_show(picker_layout->popup_); + + return picker_layout; +} + +// static +std::unique_ptr +InputPicker::Layout::CreateAndShowTimeLayout(InputPicker* parent, + struct tm* current_time) { + std::unique_ptr picker_layout(new Layout(parent)); + + picker_layout->input_type_ = ui::TEXT_INPUT_TYPE_TIME; + + if (!picker_layout->AddBaseLayout( + dgettext("WebKit", "IDS_WEBVIEW_HEADER_SET_TIME"), "date_popup")) + return nullptr; + + picker_layout->time_picker_ = elm_datetime_add(picker_layout->layout_); + if (!picker_layout->time_picker_) + return nullptr; + + 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"); + + elm_object_part_content_set(picker_layout->layout_, "elm.swallow.datetime", + picker_layout->time_picker_); + + char* format = GetDateTimeFormat(); + if (format) { + elm_datetime_format_set(picker_layout->time_picker_, format); + free(format); + } else { + elm_datetime_format_set(picker_layout->time_picker_, + kDefaultDatetimeFormat); + } + + elm_datetime_value_set(picker_layout->time_picker_, current_time); + + if (!picker_layout->AddOKButton()) + return nullptr; + + elm_datetime_field_visible_set(picker_layout->time_picker_, ELM_DATETIME_YEAR, + EINA_FALSE); + elm_datetime_field_visible_set(picker_layout->time_picker_, + ELM_DATETIME_MONTH, EINA_FALSE); + elm_datetime_field_visible_set(picker_layout->time_picker_, ELM_DATETIME_DATE, + EINA_FALSE); + + picker_layout->AddDatePickerCallbacks(); + + elm_object_content_set(picker_layout->popup_, picker_layout->layout_); + evas_object_show(picker_layout->popup_); + + return picker_layout; +} + +bool InputPicker::Layout::AddBaseLayout(const char* title, + const char* layout_group) { + Evas_Object* top_widget = elm_object_top_widget_get( + elm_object_parent_widget_get(parent_->web_view_->evas_object())); + if (!top_widget) + return false; + + conformant_ = elm_conformant_add(top_widget); + if (!conformant_) + return false; + + evas_object_size_hint_weight_set(conformant_, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_win_resize_object_add(top_widget, conformant_); + evas_object_show(conformant_); + + Evas_Object* layout = elm_layout_add(conformant_); + if (!layout) + return false; + + elm_layout_theme_set(layout, "layout", "application", "default"); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(layout); + elm_object_content_set(conformant_, layout); + + popup_ = elm_popup_add(layout); + if (!popup_) + return false; + + elm_popup_align_set(popup_, ELM_NOTIFY_ALIGN_FILL, 1.0); + elm_object_part_text_set(popup_, "title,text", title); + evas_object_size_hint_weight_set(popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + + layout_ = elm_layout_add(popup_); + if (!layout_) + return false; + + base::FilePath edj_dir; + base::PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edj_dir); + base::FilePath control_path; + control_path = edj_dir.Append(FILE_PATH_LITERAL("control.edj")); + elm_layout_file_set(layout_, control_path.AsUTF8Unsafe().c_str(), + layout_group); + + 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); + + return true; +} + +bool InputPicker::Layout::AddOKButton() { + ok_button_ = elm_button_add(popup_); + if (!ok_button_) + return false; + + 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_focus_set(ok_button_, true); + + return true; +} + +bool InputPicker::Layout::AddColorSelector(int r, int g, int b) { + color_picker_ = elm_colorselector_add(layout_); + if (!color_picker_) + return false; + + 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); + + if (IsTvProfile()) { + elm_colorselector_color_set(color_picker_, r, g, b, 255); + } else { + Eina_List* color_list = const_cast( + elm_colorselector_palette_items_get(color_picker_)); + Eina_List* list = nullptr; + Elm_Object_Item* it = nullptr; + void* item = nullptr; + int red = 0, green = 0, blue = 0, alpha = 0; + + EINA_LIST_FOREACH(color_list, list, item) { + if (item) { + Elm_Object_Item* elm_item = static_cast(item); + elm_colorselector_palette_item_color_get(elm_item, &red, &green, &blue, + &alpha); + if (red == r && green == g && blue == b) { + it = elm_item; + break; + } + } + } + + if (!it) + it = static_cast(eina_list_nth(color_list, 0)); + + elm_object_item_signal_emit(it, "elm,state,selected", "elm"); + } + + elm_object_part_content_set(layout_, "colorpalette", color_picker_); + + return true; +} + +void InputPicker::Layout::AddColorPickerCallbacks() { + evas_object_smart_callback_add(color_picker_, "color,item,selected", + ColorPickerItemSelectedCallback, color_rect_); + + evas_object_smart_callback_add(ok_button_, "clicked", + ColorPickerSelectFinishedCallback, this); +#if BUILDFLAG(IS_TIZEN) + eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, + ColorPickerBackKeyCallback, this); +#endif +} + +void InputPicker::Layout::DeleteColorPickerCallbacks() { + if (color_picker_) { + evas_object_smart_callback_del(color_picker_, "color,item,selected", + ColorPickerItemSelectedCallback); + } + + if (ok_button_) { + evas_object_smart_callback_del(ok_button_, "clicked", + ColorPickerSelectFinishedCallback); + } + +#if BUILDFLAG(IS_TIZEN) + if (popup_) { + eext_object_event_callback_del(popup_, EEXT_CALLBACK_BACK, + ColorPickerBackKeyCallback); + } +#endif +} + +void InputPicker::Layout::AddDatePickerCallbacks() { + evas_object_smart_callback_add(ok_button_, "clicked", + DatePickerSelectFinishedCallback, this); + + if (input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD || + input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME || + input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL) { + evas_object_smart_callback_add(date_picker_, "changed", + DatePickerItemChangedCallback, this); + evas_object_smart_callback_add(time_picker_, "changed", + DatePickerItemChangedCallback, this); + } + + if (IsTvProfile()) { + elm_object_signal_emit(layout_, "TV", "align,swallow.datetime"); + } + +#if BUILDFLAG(IS_TIZEN) + eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, + DatePickerBackKeyCallback, this); +#endif +} + +void InputPicker::Layout::DeleteDatePickerCallbacks() { + if (ok_button_) { + evas_object_smart_callback_del(ok_button_, "clicked", + DatePickerSelectFinishedCallback); + } + + if (input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD || + input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME || + input_type_ == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL) { + if (date_picker_) { + evas_object_smart_callback_del(date_picker_, "changed", + DatePickerItemChangedCallback); + } + if (time_picker_) { + evas_object_smart_callback_del(time_picker_, "changed", + DatePickerItemChangedCallback); + } + } + +#if BUILDFLAG(IS_TIZEN) + if (popup_) { + eext_object_event_callback_del(popup_, EEXT_CALLBACK_BACK, + DatePickerBackKeyCallback); + } +#endif +} + +// static +void InputPicker::Layout::ColorPickerItemSelectedCallback(void* data, + Evas_Object* obj, + void* event_info) { + int r = 0, g = 0, b = 0, a = 0; + Elm_Object_Item* color_it = static_cast(event_info); + elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a); + evas_object_color_set(static_cast(data), r, g, b, a); +} + +// static +void InputPicker::Layout::ColorPickerSelectFinishedCallback(void* data, + Evas_Object* obj, + void* event_info) { + Layout* picker_layout = static_cast(data); + + int r = 0, g = 0, b = 0, a = 0; + evas_object_color_get(picker_layout->color_rect_, &r, &g, &b, &a); + + picker_layout->parent_->web_view_->web_contents() + .DidChooseColorInColorChooser(SkColorSetARGB(a, r, g, b)); + picker_layout->parent_->RemoveColorPicker(); +} + +// static +void InputPicker::Layout::DatePickerSelectFinishedCallback(void* data, + Evas_Object* obj, + void* event_info) { + struct tm current_time; + memset(¤t_time, 0, sizeof(struct tm)); + + Layout* picker_layout = static_cast(data); + + if (picker_layout->input_type_ == ui::TEXT_INPUT_TYPE_TIME) + elm_datetime_value_get(picker_layout->time_picker_, ¤t_time); + else + elm_datetime_value_get(picker_layout->date_picker_, ¤t_time); + + char dateStr[20] = { + 0, + }; + + switch (picker_layout->input_type_) { + case ui::TEXT_INPUT_TYPE_DATE: { + strftime(dateStr, 20, "%F", ¤t_time); + break; + } + case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: + case ui::TEXT_INPUT_TYPE_DATE_TIME: { + strftime(dateStr, 20, "%FT%RZ", ¤t_time); + break; + } + case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: { + strftime(dateStr, 20, "%FT%R", ¤t_time); + break; + } + case ui::TEXT_INPUT_TYPE_TIME: { + strftime(dateStr, 20, "%R", ¤t_time); + break; + } + case ui::TEXT_INPUT_TYPE_WEEK: { + // Call mktime: current_time.tm_wday will be set + mktime(¤t_time); + strftime(dateStr, 20, "%G-W%V", ¤t_time); + break; + } + case ui::TEXT_INPUT_TYPE_MONTH: { + strftime(dateStr, 20, "%Y-%m", ¤t_time); + break; + } + default: + NOTREACHED(); + break; + } + + picker_layout->parent_->RemoveDatePicker(); +} + +// static +void InputPicker::Layout::DatePickerItemChangedCallback(void* data, + Evas_Object* obj, + void* event_info) { + struct tm current_time; + memset(¤t_time, 0, sizeof(struct tm)); + + Layout* picker_layout = static_cast(data); + if (obj == picker_layout->date_picker_) { + elm_datetime_value_get(picker_layout->date_picker_, ¤t_time); + elm_datetime_value_set(picker_layout->time_picker_, ¤t_time); + } else if (obj == picker_layout->time_picker_) { + elm_datetime_value_get(picker_layout->time_picker_, ¤t_time); + elm_datetime_value_set(picker_layout->date_picker_, ¤t_time); + } +} + +#if BUILDFLAG(IS_TIZEN) +// static +void InputPicker::Layout::ColorPickerBackKeyCallback(void* data, + Evas_Object* obj, + void* event_info) { + Layout* picker_layout = static_cast(data); + + picker_layout->parent_->web_view_->web_contents() + .DidChooseColorInColorChooser(SkColorSetARGB(255, picker_layout->red_, + picker_layout->green_, + picker_layout->blue_)); + picker_layout->parent_->RemoveColorPicker(); +} + +// static +void InputPicker::Layout::DatePickerBackKeyCallback(void* data, + Evas_Object* obj, + void* event_info) { + Layout* picker_layout = static_cast(data); + if (picker_layout) + picker_layout->parent_->RemoveDatePicker(); +} +#endif + +InputPicker::InputPicker(EWebView* view) : web_view_(view) {} + +void InputPicker::ShowColorPicker(int r, int g, int b, int a) { + picker_layout_ = Layout::CreateAndShowColorPickerLayout(this, r, g, b); + if (!picker_layout_) { + LOG(ERROR) << "Failed to create color picker."; + // We need to notify engine that default color is chosen + // otherwise selecting will never be finished. + web_view_->web_contents().DidChooseColorInColorChooser( + SkColorSetARGB(a, r, g, b)); + } +} + +void InputPicker::ShowDatePicker(ui::TextInputType input_type, + double input_date) { + web_view_->ExecuteEditCommand("Unselect", 0); + + time_t timep; + struct tm tm; + if (!std::isfinite(input_date)) { + time(&timep); + localtime_r(&timep, &tm); + } else if (input_type == ui::TEXT_INPUT_TYPE_MONTH) { + // When type is month, input_date is number of month since epoch. + unsigned int year = floor(input_date / 12.0) + 1970.0; + unsigned int month = input_date - (year - 1970) * 12 + 1; + CHECK_LE(month, 12u); + + char date[12]; + snprintf(date, sizeof(date), "%d-%d", year, month); + char* last_char = strptime(date, "%Y-%m", &tm); + DCHECK(last_char); + } else { + // In all other cases, input_date is number of milliseconds since epoch. + timep = base::Time::FromDoubleT(input_date / 1000).ToTimeT(); + gmtime_r(&timep, &tm); + } + struct tm* current_time = &tm; + + switch (input_type) { + case ui::TEXT_INPUT_TYPE_DATE: + case ui::TEXT_INPUT_TYPE_WEEK: + case ui::TEXT_INPUT_TYPE_MONTH: { + picker_layout_ = + Layout::CreateAndShowDateLayout(this, current_time, input_type); + break; + } + case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: + case ui::TEXT_INPUT_TYPE_DATE_TIME: + case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: { + picker_layout_ = + Layout::CreateAndShowDateTimeLayout(this, current_time, input_type); + break; + } + case ui::TEXT_INPUT_TYPE_TIME: { + picker_layout_ = Layout::CreateAndShowTimeLayout(this, current_time); + break; + } + default: + LOG(ERROR) << "Invalid date picker type."; + break; + } + + if (!picker_layout_) { + LOG(ERROR) << "Failed to create date picker."; + } +} + +void InputPicker::RemoveColorPicker() { + if (!picker_layout_) + return; + + picker_layout_.reset(); + web_view_->web_contents().DidEndColorChooser(); +} + +void InputPicker::RemoveDatePicker() { + if (!picker_layout_) + return; + + picker_layout_.reset(); +} + +} // namespace content diff --git a/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.h b/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.h new file mode 100644 index 0000000..ab2737ef --- /dev/null +++ b/tizen_src/ewk/efl_integration/browser/input_picker/input_picker.h @@ -0,0 +1,111 @@ +// Copyright 2014 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_INPUT_PICKER_H_ +#define EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_INPUT_PICKER_H_ + +#include +#include +#include + +#include "ewk/efl_integration/eweb_view.h" +#include "ui/base/ime/text_input_type.h" + +class EWebView; + +namespace content { + +class InputPicker { + public: + explicit InputPicker(EWebView* web_view); + + InputPicker(const InputPicker&) = delete; + InputPicker& operator=(const InputPicker&) = delete; + + void ShowColorPicker(int r, int g, int b, int a); + void ShowDatePicker(ui::TextInputType input_type, double input_date); + + private: + class Layout { + public: + static std::unique_ptr + CreateAndShowColorPickerLayout(InputPicker* parent, int r, int g, int b); + static std::unique_ptr CreateAndShowDateLayout( + InputPicker* parent, + struct tm* currentTime, + ui::TextInputType type); + static std::unique_ptr CreateAndShowDateTimeLayout( + InputPicker* parent, + struct tm* currentTime, + ui::TextInputType type); + static std::unique_ptr CreateAndShowTimeLayout( + InputPicker* parent, + struct tm* currentTime); + + ~Layout(); + + private: + explicit Layout(InputPicker* parent); + + Layout(const Layout&) = delete; + Layout& operator=(const Layout&) = delete; + + bool AddBaseLayout(const char* title, const char* layout_group); + bool AddOKButton(); + bool AddColorSelector(int r, int g, int b); + void AddColorPickerCallbacks(); + void DeleteColorPickerCallbacks(); + void AddDatePickerCallbacks(); + void DeleteDatePickerCallbacks(); + + static void ColorPickerSelectFinishedCallback(void* data, + Evas_Object* obj, + void* event_info); + static void ColorPickerItemSelectedCallback(void* data, + Evas_Object* obj, + void* event_info); + static void DatePickerSelectFinishedCallback(void* data, + Evas_Object* obj, + void* event_info); + static void DatePickerItemChangedCallback(void* data, + Evas_Object* obj, + void* event_info); + +#if BUILDFLAG(IS_TIZEN) + static void ColorPickerBackKeyCallback(void* data, + Evas_Object* obj, + void* event_info); + static void DatePickerBackKeyCallback(void* data, + Evas_Object* obj, + void* event_info); +#endif + + InputPicker* parent_ = nullptr; + + Evas_Object* conformant_ = nullptr; + Evas_Object* popup_ = nullptr; + Evas_Object* layout_ = nullptr; + Evas_Object* ok_button_ = nullptr; + Evas_Object* color_picker_ = nullptr; + Evas_Object* color_rect_ = nullptr; + Evas_Object* date_picker_ = nullptr; + Evas_Object* time_picker_ = nullptr; + + ui::TextInputType input_type_; + bool is_color_picker_ = false; + int red_ = 0; + int green_ = 0; + int blue_ = 0; + }; + + void RemoveColorPicker(); + void RemoveDatePicker(); + + EWebView* web_view_; + std::unique_ptr picker_layout_; +}; + +} // namespace content + +#endif // EWK_EFL_INTEGRATION_BROWSER_INPUT_PICKER_INPUT_PICKER_H_ diff --git a/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.cc b/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.cc deleted file mode 100755 index 8346d52..0000000 --- a/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.cc +++ /dev/null @@ -1,957 +0,0 @@ -// Copyright 2014 Samsung Electronics. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "InputPicker.h" - -#include "base/path_service.h" -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/time/time.h" -#include "common/web_contents_utils.h" -#include "content/common/paths_efl.h" -#include "content/public/browser/web_contents.h" -#include "eweb_view.h" -#include "tizen/system_info.h" - -#include -#include -#include - -#include -#if BUILDFLAG(IS_TIZEN) -#include -#include -#include -extern void* EflExtensionHandle; -#endif - -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) - , parent(elm_object_top_widget_get(elm_object_parent_widget_get(ewk_view_))) - , popup(0) - , layout(0) - , datePicker(0) - , time_picker(0) - , color_picker(0) - , color_rect(0) - , dataListEditField(0) - , initial_r(0) - , initial_g(0) - , initial_b(0) - , datetime_local(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); - } - - bool BuildColorSelector(); - bool CreateColorSelector(); - bool CreateOKButton(); - void SetPopupSize(int width, int height); - - base::FilePath GetLayoutFilePath() { - base::FilePath edj_dir; - base::FilePath control_edj; - base::PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edj_dir); - control_edj = edj_dir.Append(FILE_PATH_LITERAL("control.edj")); - return control_edj; - } - - ~Layout() { - /* 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_focus_set(ewk_view_, true); - } - - Evas_Object* ewk_view_; - Evas_Object* parent; - Evas_Object* popup; - Evas_Object* layout; - Evas_Object* datePicker; - Evas_Object* time_picker; - Evas_Object* color_picker; - Evas_Object* color_rect; - Evas_Object* okButton; - Evas_Object* dataListEditField; - int initial_r; - int initial_g; - int initial_b; - bool datetime_local; -}; - -bool InputPicker::Layout::BuildColorSelector() { - /* add color palette widget */ - color_picker = elm_colorselector_add(layout); - if (!color_picker) - return false; - - 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); - - if (IsTvProfile()) { - elm_colorselector_color_set(color_picker, initial_r, initial_g, initial_b, 255); - } else { - Eina_List* color_list = const_cast - (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(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); - return true; -} - -bool InputPicker::Layout::CreateOKButton() { - okButton = elm_button_add(popup); - if (!okButton) - return false; - - elm_object_style_set(okButton, "popup"); - elm_object_text_set(okButton, "OK"); - elm_object_part_content_set(popup, "button1", okButton); - evas_object_focus_set(okButton, true); - return true; -} - -void InputPicker::Layout::SetPopupSize(int width, int height) { - if(popup) { - evas_object_resize(popup, width, height); - evas_object_move(popup, 0, 0); - } -} - -bool InputPicker::Layout::CreateColorSelector() { - popup = elm_popup_add(parent); - if (!popup) - return false; - - 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 = GetLayoutFilePath(); - - layout = elm_layout_add(popup); - if (!layout) - return false; - - 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); - return CreateOKButton(); -} - -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() { -#if BUILDFLAG(IS_TIZEN) - char* datetimeFormat = NULL; - char* regionFormat = NULL; - char* language = NULL; - char buf[256] = { 0, }; - int timeValue = 0; - int isHour24 = 0; - int returnValue = 0; - - language = getenv("LANGUAGE"); - setenv("LANGUAGE", "en_US", 1); - - regionFormat = vconf_get_str(VCONFKEY_REGIONFORMAT); - if (!regionFormat) - return 0; - - returnValue = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &timeValue); - if (returnValue < 0) - isHour24 = 0; - else if (timeValue == VCONFKEY_TIME_FORMAT_12 || - timeValue == VCONFKEY_TIME_FORMAT_24) - isHour24 = timeValue - 1; - - if (isHour24) - snprintf(buf, sizeof(buf), "%s_DTFMT_24HR", regionFormat); - else - snprintf(buf, sizeof(buf), "%s_DTFMT_12HR", regionFormat); - - free(regionFormat); - - // FIXME: Workaround fix for region format. - int bufLength = strlen(buf); - for (int i = 0; i < bufLength - 4; i++) { - if (buf[i] == 'u' && buf[i + 1] == 't' && buf[i + 2] == 'f') { - if (buf[i + 3] == '8') { - // utf8 -> UTF-8 - for (int j = bufLength; j > i + 3; j--) - buf[j] = buf[j - 1]; - buf[i + 3] = '-'; - buf[bufLength + 1] = '\0'; - } else if (buf[i + 3] == '-' && buf[i + 4] == '8') { - // utf-8 -> UTF-8 - } else { - break; - } - - buf[i] = 'U'; - buf[i + 1] = 'T'; - buf[i + 2] = 'F'; - break; - } - } - - datetimeFormat = dgettext("dt_fmt", buf); - - if(!language || !strcmp(language, "")) - unsetenv("LANGUAGE"); - else - setenv("LANGUAGE", language, 1); - - // 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))) { - return 0; - } - - return strdup(datetimeFormat); -#else - return NULL; -#endif -} - -InputPicker::InputPicker(EWebView& web_view_) - : web_view_(web_view_) - , ewk_view_(web_view_.evas_object()) - , picker_layout_(0) - , data_list_(0) { -} - -InputPicker::~InputPicker() { - if (picker_layout_) { - if (picker_layout_->popup) - evas_object_del(picker_layout_->popup); - delete picker_layout_; - } -} - -void InputPicker::SetPopupSize(int width, int height) { - if (picker_layout_) - picker_layout_->SetPopupSize(width, height); -} - -#if BUILDFLAG(IS_TIZEN) -void InputPicker::endEditingCallback( - void* data, Evas_Object* obj, void* event_info) -{ - if (IsMobileProfile() || IsWearableProfile()) { - InputPicker* inputPicker = static_cast(data); - if (inputPicker) - inputPicker->removeDatetimePickerDelayed(); - } -} -#endif - -void InputPicker::showDatePicker(ui::TextInputType input_type, double input_date) -{ - web_view_.ExecuteEditCommand("Unselect", 0); - - time_t timep; - struct tm tm; - struct tm* currentTime; - - if (!std::isfinite(input_date)) { - time(&timep); - currentTime = localtime(&timep); - } else if (input_type == ui::TEXT_INPUT_TYPE_MONTH) { - // when type is month, input_date is number of month since epoch - unsigned int year = floor(input_date / 12.0) + 1970.0; - unsigned int month = input_date - (year - 1970) * 12 + 1; - CHECK(month <= 12); - - char date[12]; - snprintf(date, 12, "%d-%d", year, month); - - char* last_char = strptime(date, "%Y-%m", &tm); - DCHECK(last_char); - - currentTime = &tm; - } else { - // in all other cases, input_date is number of milliseconds since epoch - base::Time doubleT = base::Time::FromDoubleT(input_date/1000); - timep = doubleT.ToTimeT(); - currentTime = gmtime(&timep); - } - - switch (input_type) { - case ui::TEXT_INPUT_TYPE_DATE: - showDatePopup(currentTime); - break; - case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: - case ui::TEXT_INPUT_TYPE_DATE_TIME: - showDatetimePopup(currentTime, false /*datetime*/); - break; - case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: - showDatetimePopup(currentTime, true /* datetime_local */); - break; - case ui::TEXT_INPUT_TYPE_TIME: - showTimePopup(currentTime); - break; - case ui::TEXT_INPUT_TYPE_WEEK: - showWeekPopup(currentTime); - break; - case ui::TEXT_INPUT_TYPE_MONTH: - showMonthPopup(currentTime); - break; - default: - break; - } -} - -void InputPicker::ColorPickerKeyUpCallback(void* data, Evas*, Evas_Object* obj, void* event_info) { - Evas_Event_Key_Up* key_struct = static_cast(event_info); - if (!web_contents_utils::MapsToHWBackKey(key_struct->keyname)) - return; - - HandleBackKeyColorPicker(data, obj, event_info); -} - -void InputPicker::ShowColorPicker(int r, int g, int b, int alpha) { - if (picker_layout_) { - elm_colorselector_color_set(picker_layout_->color_picker, r, g, b, alpha); - evas_object_focus_set(picker_layout_->okButton, true); - evas_object_show(picker_layout_->layout); - return; - } - - picker_layout_ = new InputPicker::Layout(ewk_view_); - - picker_layout_->initial_r = r; - picker_layout_->initial_g = g; - picker_layout_->initial_b = b; - - picker_layout_->CreateColorSelector(); - - evas_object_smart_callback_add(picker_layout_->color_picker, - "color,item,selected", - SelectedColorCallback, - picker_layout_->color_rect); -#if BUILDFLAG(IS_TIZEN) - eext_object_event_callback_add(picker_layout_->popup, EEXT_CALLBACK_BACK, - HandleBackKeyColorPicker, this); -#endif - evas_object_event_callback_add(picker_layout_->popup, EVAS_CALLBACK_KEY_UP, - ColorPickerKeyUpCallback, this); - - evas_object_smart_callback_add( - picker_layout_->okButton, - "clicked", - ColorPickerCallback, - this); - - evas_object_show(picker_layout_->popup); -} - -void InputPicker::HideColorPicker() { - if (!picker_layout_) - return; -#if !defined(EWK_BRINGUP) // FIXME: m94 bringup - web_view_.web_contents().DidEndColorChooser(); -#endif - if (picker_layout_->popup) { - evas_object_del(picker_layout_->popup); - picker_layout_->popup = 0; - } - - delete picker_layout_; - picker_layout_ = 0; -} - -void InputPicker::SelectedColorCallback( - void* data, Evas_Object* obj, void* event_info) { - int r = 0; - int g = 0; - int b = 0; - int a = 0; - - Elm_Object_Item *color_it = static_cast(event_info); - elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a); - evas_object_color_set(static_cast(data), r, g, b, a); -} - -void InputPicker::ColorPickerCallback( - void* data, Evas_Object* obj, void* event_info) { - InputPicker* inputPicker = static_cast(data); - - int r(0), g(0), b(0), a(0); - evas_object_color_get(inputPicker->picker_layout_->color_rect, &r, &g, &b, &a); -#if !defined(EWK_BRINGUP) // FIXME: m94 bringup - inputPicker->web_view_.web_contents().DidChooseColorInColorChooser( - SkColorSetARGB(a, r, g, b)); -#endif - inputPicker->HideColorPicker(); -} - -void InputPicker::HandleBackKeyColorPicker( - void* data, Evas_Object* obj, void* event_info) { - InputPicker* inputPicker = static_cast(data); - - int r = inputPicker->picker_layout_->initial_r; - int g = inputPicker->picker_layout_->initial_g; - int b = inputPicker->picker_layout_->initial_b; - int a = 255; -#if !defined(EWK_BRINGUP) // FIXME: m94 bringup - inputPicker->web_view_.web_contents().DidChooseColorInColorChooser( - SkColorSetARGB(a, r, g, b)); -#endif - inputPicker->HideColorPicker(); -} - -void InputPicker::showDatePopup(struct tm* currentTime) { - if (picker_layout_) { - // Just update the value. - elm_datetime_value_set(picker_layout_->datePicker, currentTime); - evas_object_focus_set(picker_layout_->okButton, true); - return; - } - - picker_layout_ = new InputPicker::Layout(ewk_view_); - CreatePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_DATE"), - currentTime); - - picker_layout_->CreateOKButton(); - - evas_object_smart_callback_add( - picker_layout_->okButton, "clicked", datePopupCallback, this); - elm_object_content_set(picker_layout_->popup, picker_layout_->layout); - evas_object_show(picker_layout_->popup); -} - -void InputPicker::showWeekPopup(struct tm* currentTime) { - if (picker_layout_) { - // Just update the value. - elm_datetime_value_set(picker_layout_->datePicker, currentTime); - evas_object_focus_set(picker_layout_->okButton, true); - return; - } - - picker_layout_ = new InputPicker::Layout(ewk_view_); - CreatePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_WEEK"), - currentTime); - - picker_layout_->CreateOKButton(); - - evas_object_smart_callback_add( - picker_layout_->okButton, "clicked", weekPopupCallback, this); - elm_object_content_set(picker_layout_->popup, picker_layout_->layout); - evas_object_show(picker_layout_->popup); -} - -void InputPicker::showTimePopup(struct tm* currentTime) { - if (picker_layout_) { - // Just update the value. - 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_); - CreateTimePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_TIME"), - currentTime); - - picker_layout_->CreateOKButton(); - - evas_object_smart_callback_add( - picker_layout_->okButton, "clicked", timePopupCallback, this); - elm_object_content_set(picker_layout_->popup, picker_layout_->layout); - evas_object_show(picker_layout_->popup); -} - -void InputPicker::showMonthPopup(struct tm* currentTime) { - if (picker_layout_) { - // Just update the value. - elm_datetime_value_set(picker_layout_->datePicker, currentTime); - evas_object_focus_set(picker_layout_->okButton, true); - return; - } - - picker_layout_ = new InputPicker::Layout(ewk_view_); - CreatePopupLayout(dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_MONTH"), - currentTime); - - picker_layout_->CreateOKButton(); - - evas_object_smart_callback_add( - picker_layout_->okButton, "clicked", monthPopupCallback, this); - elm_object_content_set(picker_layout_->popup, picker_layout_->layout); - evas_object_show(picker_layout_->popup); -} - -void InputPicker::showDatetimePopup(struct tm* currentTime, bool datetime_local) { - 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); - return; - } - - picker_layout_ = new InputPicker::Layout(ewk_view_); - picker_layout_->datetime_local = datetime_local; - - CreateDateTimePopupLayout( - dgettext("WebKit","IDS_WEBVIEW_HEADER_SET_DATE_AND_TIME"), currentTime); - - picker_layout_->CreateOKButton(); - - evas_object_smart_callback_add( - picker_layout_->okButton, "clicked", datetimePopupCallback, this); - evas_object_smart_callback_add( - picker_layout_->datePicker, "changed", datetimeChangedCallback, this); - evas_object_smart_callback_add( - picker_layout_->time_picker, "changed", datetimeChangedCallback, this); - - elm_object_content_set(picker_layout_->popup, picker_layout_->layout); - evas_object_show(picker_layout_->popup); - -} - -Eina_Bool InputPicker::removeDatetimePicker(void* data) { - InputPicker* inputPicker = static_cast(data); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidCancelDialog(); -#endif - - if (!inputPicker->picker_layout_) - return ECORE_CALLBACK_CANCEL; - - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; - - return ECORE_CALLBACK_CANCEL; -} - -void InputPicker::removeDatetimePickerDelayed() { - ecore_timer_add(0.1, removeDatetimePicker, this); -} - -void InputPicker::DatePickerKeyUpCallback(void* data, Evas*, Evas_Object* obj, void* event_info) { - Evas_Event_Key_Up* key_struct = static_cast(event_info); - if (!web_contents_utils::MapsToHWBackKey(key_struct->keyname)) - return; - - HandleBackKeyDatePicker(data, obj, event_info); -} - -void InputPicker::CreatePopupLayout(const char* title, struct tm* currentTime) { - picker_layout_->popup = elm_popup_add(picker_layout_->parent); - 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 BUILDFLAG(IS_TIZEN) - if (EflExtensionHandle) { - void (*webkit_eext_object_event_callback_add)( - Evas_Object *, Eext_Callback_Type , Eext_Event_Cb func, void *); - webkit_eext_object_event_callback_add = (void (*)( - Evas_Object *, - Eext_Callback_Type , - Eext_Event_Cb func, - void *)) dlsym(EflExtensionHandle, "eext_object_event_callback_add"); - (*webkit_eext_object_event_callback_add)( - picker_layout_->popup, EEXT_CALLBACK_BACK, HandleBackKeyDatePicker, this); - } -#endif - evas_object_event_callback_add(picker_layout_->popup, EVAS_CALLBACK_KEY_UP, - DatePickerKeyUpCallback, this); - - base::FilePath edj_dir; - base::FilePath control_edj; - base::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_->datePicker = elm_datetime_add(picker_layout_->layout); - elm_object_part_content_set( - picker_layout_->layout, - "elm.swallow.datetime", - picker_layout_->datePicker); - - char* format = datetimeFormat(); - if (format) { - elm_datetime_format_set(picker_layout_->datePicker, format); - free(format); - } else { - elm_datetime_format_set(picker_layout_->datePicker, defaultDatetimeFormat); - } - - elm_datetime_value_set(picker_layout_->datePicker, currentTime); - -#if BUILDFLAG(IS_TIZEN) - if (IsTvProfile()) { - elm_object_signal_emit(picker_layout_->layout,"TV","align,swallow.datetime"); - } else if (IsMobileProfile() || IsWearableProfile()) { - evas_object_smart_callback_add( - picker_layout_->datePicker, "edit,end", endEditingCallback, 0); - } -#endif -} - -void InputPicker::CreateDateTimePopupLayout(const char* title, struct tm* currentTime) { - picker_layout_->popup = elm_popup_add(picker_layout_->parent); - elm_object_scale_set(picker_layout_->popup, 0.7); - 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 BUILDFLAG(IS_TIZEN) - if (EflExtensionHandle) { - void (*webkit_eext_object_event_callback_add)( - Evas_Object *, Eext_Callback_Type , Eext_Event_Cb func, void *); - webkit_eext_object_event_callback_add = (void (*)( - Evas_Object *, - Eext_Callback_Type , - Eext_Event_Cb func, - void *)) dlsym(EflExtensionHandle, "eext_object_event_callback_add"); - (*webkit_eext_object_event_callback_add)( - picker_layout_->popup, EEXT_CALLBACK_BACK, HandleBackKeyDatePicker, this); - } -#endif - evas_object_event_callback_add(picker_layout_->popup, EVAS_CALLBACK_KEY_UP, - DatePickerKeyUpCallback, this); - - base::FilePath edj_dir; - base::FilePath control_edj; - base::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_->time_picker = elm_datetime_add(picker_layout_->layout); - elm_object_part_content_set( - picker_layout_->layout, - "elm.swallow.datetime", - picker_layout_->time_picker); - - picker_layout_->datePicker = elm_datetime_add(picker_layout_->layout); - elm_object_part_content_set( - picker_layout_->layout, - "elm.swallow.datetime2", - picker_layout_->datePicker); - - elm_object_style_set(picker_layout_->time_picker, "time_layout"); - - char* format = datetimeFormat(); - if (format) { - elm_datetime_format_set(picker_layout_->datePicker, format); - elm_datetime_format_set(picker_layout_->time_picker, format); - free(format); - } else { - elm_datetime_format_set(picker_layout_->datePicker, defaultDatetimeFormat); - elm_datetime_format_set(picker_layout_->time_picker, defaultDatetimeFormat); - } - - elm_datetime_value_set(picker_layout_->datePicker, currentTime); - elm_datetime_value_set(picker_layout_->time_picker, currentTime); - -#if BUILDFLAG(IS_TIZEN) - if (IsMobileProfile() || IsWearableProfile()) { - evas_object_smart_callback_add( - picker_layout_->datePicker, "edit,end", endEditingCallback, 0); - } -#endif -} - -void InputPicker::CreateTimePopupLayout(const char* title, struct tm* currentTime) { - picker_layout_->popup = elm_popup_add(picker_layout_->parent); - 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 BUILDFLAG(IS_TIZEN) - if (EflExtensionHandle) { - void (*webkit_eext_object_event_callback_add)( - Evas_Object *, Eext_Callback_Type , Eext_Event_Cb func, void *); - webkit_eext_object_event_callback_add = (void (*)( - Evas_Object *, - Eext_Callback_Type , - Eext_Event_Cb func, - void *)) dlsym(EflExtensionHandle, "eext_object_event_callback_add"); - (*webkit_eext_object_event_callback_add)( - picker_layout_->popup, EEXT_CALLBACK_BACK, HandleBackKeyDatePicker, this); - } -#endif - evas_object_event_callback_add(picker_layout_->popup, EVAS_CALLBACK_KEY_UP, - DatePickerKeyUpCallback, this); - - base::FilePath edj_dir; - base::FilePath control_edj; - base::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 BUILDFLAG(IS_TIZEN) - if (IsTvProfile()) { - elm_object_signal_emit(picker_layout_->layout,"TV","align,swallow.datetime"); - } else if (IsMobileProfile() || IsWearableProfile()) { - 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); - picker_layout_->popup = 0; - } -} - -void InputPicker::datePopupCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - - elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime); - mktime(¤tTime); - - char dateStr[20] = { 0, }; - strftime(dateStr, 20, "%F" , ¤tTime); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr)); -#endif - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; -} - -void InputPicker::weekPopupCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - - elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime); - mktime(¤tTime); - - char dateStr[20] = { 0, }; - strftime(dateStr, 20, "%G-W%V", ¤tTime); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr)); -#endif - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; -} - -void InputPicker::timePopupCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - - elm_datetime_value_get(inputPicker->picker_layout_->time_picker, ¤tTime); - mktime(¤tTime); - - char dateStr[20] = { 0, }; - strftime(dateStr, 20, "%R", ¤tTime); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr)); -#endif - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; -} - -void InputPicker::monthPopupCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - mktime(¤tTime); - - elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime); - - char dateStr[20] = { 0, }; - strftime(dateStr, 20, "%Y-%m", ¤tTime); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr)); -#endif - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; -} - -void InputPicker::datetimePopupCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - - elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime); - mktime(¤tTime); - - char dateStr[50] = { 0, }; - if (inputPicker->picker_layout_->datetime_local) - strftime(dateStr, 50, "%FT%R", ¤tTime); - else - strftime(dateStr, 50, "%FT%RZ", ¤tTime); -#if !defined(EWK_BRINGUP) // FIXME: m67 bringup - inputPicker->web_view_.web_contents().DidReplaceDateTime(std::string(dateStr)); -#endif - inputPicker->web_view_.ExecuteEditCommand("Unselect", 0); - - inputPicker->deletePopupLayout(); - delete inputPicker->picker_layout_; - inputPicker->picker_layout_ = 0; -} - -void InputPicker::datetimeChangedCallback( - void* data, Evas_Object* obj, void* event_info) { - struct tm currentTime; - memset(¤tTime, 0, sizeof(struct tm)); - - InputPicker* inputPicker = static_cast(data); - if (obj == inputPicker->picker_layout_->datePicker) { - elm_datetime_value_get(inputPicker->picker_layout_->datePicker, ¤tTime); - elm_datetime_value_set(inputPicker->picker_layout_->time_picker, ¤tTime); - } else if (obj == inputPicker->picker_layout_->time_picker) { - elm_datetime_value_get(inputPicker->picker_layout_->time_picker, ¤tTime); - elm_datetime_value_set(inputPicker->picker_layout_->datePicker, ¤tTime); - } -} - -void InputPicker::HandleBackKeyDatePicker( - void* data, Evas_Object* obj, void* event_info) { - removeDatetimePicker(data); -} - -} // namespace content diff --git a/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.h b/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.h deleted file mode 100755 index e5b05a1..0000000 --- a/tizen_src/ewk/efl_integration/browser/inputpicker/InputPicker.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 Samsung Electronics. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef InputPicker_h -#define InputPicker_h - -#include -#include -#include -#include "ui/base/ime/text_input_type.h" - -class EWebView; - -namespace content { - -class WebContents; -struct ColorPopupUserData; -class WebContentsDelegateEfl; - -class InputPicker { - public: - explicit InputPicker(EWebView& web_view_); - ~InputPicker(); - - void showDatePicker(ui::TextInputType input_type, double input_date); - void ShowColorPicker(int r, int g, int b, int alpha); - void HideColorPicker(); - void SetPopupSize(int width, int height); - - private: - struct Layout; - - 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); - - static void ColorPickerKeyUpCallback( - void* data, Evas* e, Evas_Object* obj, void* event_info); - static void DatePickerKeyUpCallback( - void* data, Evas* e, Evas_Object* obj, void* event_info); - static void datePopupCallback( - void* data, Evas_Object* obj, void* event_info); - static void timePopupCallback( - void* data, Evas_Object* obj, void* event_info); - static void monthPopupCallback( - void* data, Evas_Object* obj, void* event_info); - static void weekPopupCallback( - void* data, Evas_Object* obj, void* event_info); - static void datetimePopupCallback( - void* data, Evas_Object* obj, void* event_info); - static void datetimeChangedCallback( - void* data, Evas_Object* obj, void* event_info); - static void endEditingCallback( - void* data, Evas_Object* obj, void* event_info); - static Eina_Bool removeDatetimePicker(void* data); - static void ColorPickerCallback( - void* data, Evas_Object* obj, void* event_info); - static void SelectedColorCallback( - void* data, Evas_Object* obj, void* event_info); - static void HandleBackKeyColorPicker( - void* data, Evas_Object* obj, void* event_info); - static void HandleBackKeyDatePicker( - void* data, Evas_Object* obj, void* event_info); - - EWebView& web_view_; - Evas_Object* ewk_view_; - Layout* picker_layout_; - Eina_List* data_list_; -}; - -} // namespace content - -#endif // InputPicker_h diff --git a/tizen_src/ewk/efl_integration/eweb_view.cc b/tizen_src/ewk/efl_integration/eweb_view.cc index 7da077e..ec146b6 100644 --- a/tizen_src/ewk/efl_integration/eweb_view.cc +++ b/tizen_src/ewk/efl_integration/eweb_view.cc @@ -532,8 +532,6 @@ void EWebView::SetOrientation(int orientation) { if (context_menu_) context_menu_->SetPopupSize(width, height); - if (inputPicker_) - inputPicker_->SetPopupSize(width, height); if (popup_controller_) popup_controller_->SetPopupSize(width, height); if (JavaScriptDialogManagerEfl* dialogMG = GetJavaScriptDialogManagerEfl()) @@ -2164,12 +2162,8 @@ void EWebView::ShowContentsDetectedPopup(const char* message) { } void EWebView::RequestColorPicker(int r, int g, int b, int a) { - inputPicker_.reset(new InputPicker(*this)); - inputPicker_->ShowColorPicker(r, g, b, a); -} - -void EWebView::DismissColorPicker() { - inputPicker_->HideColorPicker(); + input_picker_.reset(new InputPicker(this)); + input_picker_->ShowColorPicker(r, g, b, a); } bool EWebView::SetColorPickerColor(int r, int g, int b, int a) { @@ -2181,8 +2175,8 @@ bool EWebView::SetColorPickerColor(int r, int g, int b, int a) { void EWebView::InputPickerShow(ui::TextInputType input_type, double input_value) { - inputPicker_.reset(new InputPicker(*this)); - inputPicker_->showDatePicker(input_type, input_value); + input_picker_.reset(new InputPicker(this)); + input_picker_->ShowDatePicker(input_type, input_value); } void EWebView::LoadNotFoundErrorPage(const std::string& invalidUrl) { diff --git a/tizen_src/ewk/efl_integration/eweb_view.h b/tizen_src/ewk/efl_integration/eweb_view.h old mode 100644 new mode 100755 index 6b09cf1..b2d0037 --- a/tizen_src/ewk/efl_integration/eweb_view.h +++ b/tizen_src/ewk/efl_integration/eweb_view.h @@ -20,7 +20,7 @@ #include "base/callback.h" #include "base/containers/id_map.h" #include "base/synchronization/waitable_event.h" -#include "browser/inputpicker/InputPicker.h" +#include "browser/input_picker/input_picker.h" #include "browser/selectpicker/popup_picker.h" #include "content/browser/renderer_host/event_with_latency_info.h" #include "content/browser/selection/selection_controller_efl.h" @@ -69,6 +69,7 @@ class WebContentsDelegateEfl; class WebContentsViewAura; class ContextMenuControllerEfl; class PopupControllerEfl; +class InputPicker; } class ErrorParams; @@ -436,7 +437,6 @@ class EWebView { bool IsDragging() const; void RequestColorPicker(int r, int g, int b, int a); - void DismissColorPicker(); bool SetColorPickerColor(int r, int g, int b, int a); void InputPickerShow(ui::TextInputType input_type, double input_value); @@ -604,7 +604,7 @@ class EWebView { WebViewCallback authentication_cb_; - std::unique_ptr inputPicker_; + std::unique_ptr input_picker_; base::IDMap web_app_icon_url_get_callback_map_; base::IDMap diff --git a/tizen_src/ewk/efl_integration/resource/BUILD.gn b/tizen_src/ewk/efl_integration/resource/BUILD.gn index 274481b..33f8000 100644 --- a/tizen_src/ewk/efl_integration/resource/BUILD.gn +++ b/tizen_src/ewk/efl_integration/resource/BUILD.gn @@ -15,14 +15,14 @@ template("edje_res_ewk") { args = [ "$edje_compiler", "-id", - rebase_path("../images/"), + rebase_path("./images/"), rebase_path("{{source_file_part}}"), rebase_path("$root_out_dir/resources/{{source_name_part}}.edj"), ] } source_set(target_name) { - data = [ + deps = [ ":$edje_target_name", ] } diff --git a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc index ac72d7c..097edfe 100644 --- a/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc +++ b/tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc @@ -6,7 +6,7 @@ #include "base/strings/utf_string_conversions.h" #include "browser/favicon/favicon_database.h" -#include "browser/inputpicker/color_chooser_efl.h" +#include "browser/input_picker/color_chooser_efl.h" #include "browser/javascript_dialog_manager_efl.h" #include "browser/policy_response_delegate_efl.h" #include "common/render_messages_ewk.h" -- 2.7.4