#include "base/logging.h"
#include "tizen_src/chromium_impl/tizen/system_info.h"
#include "wrt/src/browser/popup_string.h"
-#include "wrt/src/browser/wrt_native_window.h"
#include "wrt/src/common/constants.h"
#if BUILDFLAG(IS_TIZEN_TV)
-#include <aul.h>
-#include <algorithm>
-#include <memory>
-
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-#include "tizen_src/chromium_impl/content/common/paths_efl.h"
-#include "wrt/src/common/locale_manager.h"
+#include "wrt/src/browser/tv/popup_tv.h"
#endif
namespace wrt {
const char* kStyleButton = "popup";
const char* kStyleButtonLeft = "popup";
const char* kStyleButtonRight = "popup";
+const char* kStyleCheck = "multiline";
const char* kStyleEditPw = "editfield/password/popup";
const char* kStyleLabel = "popup/default";
-
-#if BUILDFLAG(IS_TIZEN_TV)
-const char* kStateFocused = "focused";
-const char* kStyleCheck = "C_Checkbox_WhiteText";
-const char* kStylePopup = "C_PopupBasic_WhiteBottom";
-const char* kWRTEdjeFile = "wrtjs_tizen.edj";
-const unsigned int kTimeout = 60; // second
-#else
-const char* kStyleCheck = "default";
const char* kStylePopup = "default";
const char* kWRTEdjePath = "/usr/share/edje/wrtjs/wrtjs_tizen.edj";
-#endif
-
-std::vector<std::unique_ptr<Popup>> opened_popups;
-
-#if BUILDFLAG(IS_TIZEN_TV)
-int syspopup_pid_ = -1;
-
-static void EntryKeyDownCallback(void* data,
- Evas* e,
- Evas_Object* obj,
- void* event_info) {
- if (!data || !obj || !event_info) {
- LOG(ERROR) << "parameter is nullptr";
- return;
- }
- Evas_Event_Key_Down* ev = static_cast<Evas_Event_Key_Down*>(event_info);
- if (!ev->key) {
- LOG(ERROR) << "ev->key is nullptr";
- return;
- }
- Popup* popup = static_cast<Popup*>(data);
- popup->HandleEntryKeyDownEvent(ev->key);
-}
-#endif
-static Evas_Object* AddCheckBox(Evas_Object* parent) {
+static Evas_Object* AddCheckBox(Evas_Object* parent, const std::string& style) {
Evas_Object* check = elm_check_add(parent);
- elm_object_style_set(check, kStyleCheck);
+ elm_object_style_set(check, style.c_str());
evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
-#if !BUILDFLAG(IS_TIZEN_TV)
- elm_object_style_set(check, "multiline");
-#endif // IS_TIZEN_TV
elm_check_state_set(check, EINA_FALSE);
return check;
}
-Evas_Object* CreateNewWindow(Evas_Object* parent) {
- if (!parent)
- return nullptr;
-
- Evas_Object* window = elm_win_add(parent, "WRTPopupWindow", ELM_WIN_BASIC);
- if (!window)
- return nullptr;
-
- elm_win_title_set(window, "WRTPopupWindow");
- elm_win_alpha_set(window, EINA_TRUE);
- elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_HIDE);
-
- if (elm_win_wm_rotation_supported_get(parent)) {
- int rots[] = {0, 90, 180, 270};
- elm_win_wm_rotation_available_rotations_set(window, rots, 4);
- }
-
- int window_width, window_height;
- elm_win_screen_size_get(window, nullptr, nullptr, &window_width,
- &window_height);
- evas_object_resize(window, window_width, window_height);
-
- elm_win_conformant_set(window, EINA_TRUE);
- Evas_Object* conformant = elm_conformant_add(window);
- evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- elm_win_resize_object_add(window, conformant);
- evas_object_show(conformant);
-
- return window;
-}
-
} // namespace
// static
+std::vector<std::unique_ptr<Popup>> Popup::opened_popups_;
+
+// static
std::unique_ptr<Popup> Popup::CreatePopup(Evas_Object* window) {
#if BUILDFLAG(IS_TIZEN_TV)
- window = CreateNewWindow(window);
+ return PopupTV::CreatePopup(window);
#endif
Evas_Object* popup = elm_popup_add(window);
-#if !BUILDFLAG(IS_TIZEN_TV)
+
elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
-#endif
evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_style_set(popup, kStylePopup);
elm_box_padding_set(box, 0, 10);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
-#if BUILDFLAG(IS_TIZEN_TV)
- Evas_Object* table = elm_table_add(popup);
- if (!table) {
- LOG(ERROR) << "Failed to Create Table";
- return nullptr;
- }
-
- Evas_Object* rect = evas_object_rectangle_add(evas_object_evas_get(table));
- evas_object_color_set(rect, 0, 0, 0, 0);
- const double real_width = 800;
- const double real_height = 300;
- evas_object_size_hint_min_set(rect, real_width, real_height);
- evas_object_size_hint_max_set(rect, real_width, real_height);
- elm_table_pack(table, rect, 0, 0, 1, 1);
- elm_table_pack(table, box, 0, 0, 1, 1);
- elm_object_content_set(popup, table);
-#else
elm_object_part_content_set(popup, "default", box);
-#endif // IS_TIZEN_TV
evas_object_show(box);
evas_object_event_callback_add(
popup, EVAS_CALLBACK_RESIZE, nullptr, nullptr);
- auto* instance = new Popup(popup, box, IsTvProfile() ? window : nullptr);
+ auto* instance = new Popup(popup, box);
return std::unique_ptr<Popup>(instance);
}
// static
void Popup::Show(std::unique_ptr<Popup> popup) {
- if (popup->window_)
- evas_object_show(popup->window_);
- evas_object_show(popup->popup_);
-
-#if BUILDFLAG(IS_TIZEN_TV)
- (popup->timeout_timer_)
- .Start(FROM_HERE, base::Seconds(kTimeout), popup.get(), &Popup::Timeout);
-#endif
- opened_popups.push_back(std::move(popup));
+ if (popup)
+ popup->ShowInternal(std::move(popup));
}
// static
void Popup::ForceCloseAllPopup() {
- for (auto& popup : opened_popups) {
- // will cause modification of opened_popups
+ for (auto& popup : opened_popups_) {
+ // will cause modification of opened_popups_
popup->Hide();
}
- opened_popups.clear();
+ opened_popups_.clear();
}
-Popup::Popup(Evas_Object* popup, Evas_Object* box, Evas_Object* window)
- : popup_(popup), box_(box), window_(window) {
- if (window_) {
- auto main_native_window = WRTNativeWindow::GetMainNativeWindow();
- if (main_native_window)
- main_native_window->AddObserver(this);
- }
-}
+Popup::Popup(Evas_Object* popup, Evas_Object* box) : popup_(popup), box_(box) {}
Popup::~Popup() {
- if (window_) {
- auto main_native_window = WRTNativeWindow::GetMainNativeWindow();
- if (main_native_window)
- main_native_window->RemoveObserver(this);
- evas_object_del(window_);
- window_ = popup_ = nullptr;
- } else if (popup_) {
+ if (popup_) {
evas_object_del(popup_);
popup_ = nullptr;
}
}
-void Popup::OnWindowShow() {
- if (window_) {
- evas_object_show(window_);
- elm_win_raise(window_);
- }
-}
-
-void Popup::OnWindowHide() {
- if (window_) {
- evas_object_hide(window_);
- }
+void Popup::ShowInternal(std::unique_ptr<Popup> popup) {
+ evas_object_show(popup->popup_);
+ opened_popups_.push_back(std::move(popup));
}
void Popup::SetButtonType(ButtonType type) {
kContentButton2, kStyleButtonRight);
break;
}
-
-#if BUILDFLAG(IS_TIZEN_TV)
- if (button2_) {
- auto focused_callback = [](void* instance, Evas_Object* button,
- void* /*eventInfo*/) {
- for (auto iterator = opened_popups.begin();
- iterator != opened_popups.end(); ++iterator) {
- if (iterator->get() == instance) {
- if (((*iterator)->timeout_timer_).IsRunning())
- ((*iterator)->timeout_timer_).Reset();
- return;
- }
- }
- LOG(ERROR) << "Fail to get Popup instance";
- };
- evas_object_smart_callback_add(button1_, kStateFocused, focused_callback,
- this);
- evas_object_smart_callback_add(button2_, kStateFocused, focused_callback,
- this);
- }
-#endif
}
Evas_Object* Popup::AddButton(const char* id, const char* content,
elm_object_part_content_set(popup_, content, button);
auto callback = [](void* data, Evas_Object* button, void* /*eventInfo*/) {
- for (auto iterator = opened_popups.begin();
- iterator != opened_popups.end(); ++iterator) {
+ for (auto iterator = opened_popups_.begin();
+ iterator != opened_popups_.end(); ++iterator) {
if (iterator->get() == data) {
std::unique_ptr<Popup> popup(iterator->release());
- opened_popups.erase(iterator);
+ opened_popups_.erase(iterator);
popup->HandleButtonClickEvent(button);
return;
}
elm_object_signal_emit(entry, kSignalEdit, "");
elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
-#if BUILDFLAG(IS_TIZEN_TV)
- evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
- EntryKeyDownCallback, this);
-#endif
-
if (type == Popup::EntryType::Edit) {
evas_object_smart_callback_add(entry, kStateActivated,
[](void*, Evas_Object* obj, void*) {
evas_object_show(entry);
Evas_Object* layout = elm_layout_add(box_);
-#if BUILDFLAG(IS_TIZEN_TV)
- base::FilePath edje_dir;
- base::PathService::Get(PathsEfl::EDJE_RESOURCE_DIR, &edje_dir);
- elm_layout_file_set(layout, (edje_dir.value() + "/" + kWRTEdjeFile).c_str(),
- "PopupTextEntrySet");
-#else
- elm_layout_file_set(layout, kWRTEdjePath, "PopupTextEntrySet");
-#endif
+ if (edjeFilePath_.empty())
+ edjeFilePath_ = kWRTEdjePath;
+ elm_layout_file_set(layout, edjeFilePath_.c_str(), "PopupTextEntrySet");
Evas_Object* rectangle = evas_object_rectangle_add(
evas_object_evas_get(layout));
}
void Popup::SetCheckBox(const std::string& id) {
- check_box_ = AddCheckBox(box_);
+ if (checkStyle_.empty())
+ checkStyle_ = kStyleCheck;
+ check_box_ = AddCheckBox(box_, checkStyle_);
if (!id.empty()) {
elm_object_domain_translatable_part_text_set(
check_box_, kContentText,
std::move(handler_).Run(is_positive, is_checked, entry1, entry2);
}
-#if BUILDFLAG(IS_TIZEN_TV)
-void Popup::ShowVoiceRecognitionToast(const std::string& app_title) {
- bool font_except = false;
- std::string lang = LocaleManager::GetSystemLocale();
- lang = lang.substr(0, lang.find_first_of("-"));
-
- const std::vector<std::string> except_lang = {
- {"zh"}, {"sl"}, {"fa"}, {"kok"}, {"am"}, {"my"}, {"km"}, {"ckb"}, {"bh"},
- };
-
- if (std::find(except_lang.begin(), except_lang.end(), lang) !=
- except_lang.end()) {
- LOG(INFO) << "locale-font exception. no font re-setting";
- font_except = true;
- }
-
- const std::string mic_icon = popup_string::GetText(popup_string::kMicIcon);
- const std::string button_search = popup_string::GetTextAndReplace(
- popup_string::kPressButtonSearch, mic_icon);
- const std::string speech_Recog = popup_string::GetTextAndReplace(
- popup_string::kSpeechRecognition, app_title);
-
- const std::string font_size_start =
- font_except ? "" : "<font=SamsungOneUI_400 font_size=22>";
- const std::string font_size_end = font_except ? "" : "</font>";
- const std::string popup_text =
- "<font=SamsungOneUI_700 font_size=32>"
- "<align=center>" +
- button_search +
- "<br>"
- "</align>"
- "</font>" +
- font_size_start + "<align=center>" + speech_Recog + "</align>" +
- font_size_end;
-
- // combine the notification text
- LOG(INFO) << "toast popup text : " << popup_text;
-
- // launch toast
- auto bundle_for_popup = std::unique_ptr<bundle, decltype(bundle_free)*>(
- bundle_create(), bundle_free);
- if (!bundle_for_popup.get()) {
- LOG(ERROR) << "bundle_create failed";
- return;
- }
-
- int bundle_ret = bundle_add_str(bundle_for_popup.get(), "type", "toast");
- if (BUNDLE_ERROR_NONE != bundle_ret) {
- LOG(ERROR) << "bundle_add_str failed: " << bundle_ret;
- return;
- }
- bundle_ret =
- bundle_add_str(bundle_for_popup.get(), "text", popup_text.c_str());
- if (BUNDLE_ERROR_NONE != bundle_ret) {
- LOG(ERROR) << "bundle_add_str failed: " << bundle_ret;
- return;
- }
- bundle_ret = bundle_add_str(bundle_for_popup.get(), "timeout", "3");
- if (BUNDLE_ERROR_NONE != bundle_ret) {
- LOG(ERROR) << "bundle_add_str failed: " << bundle_ret;
- return;
- }
-
- syspopup_pid_ =
- aul_launch_app("org.tizen.alert-syspopup", bundle_for_popup.get());
- if (syspopup_pid_ < 0)
- LOG(ERROR) << "launch toast fail, return code is " << syspopup_pid_;
-}
-
-void Popup::HideVoiceRecognitionToast() {
- LOG(INFO) << "hide toast, pid is " << syspopup_pid_;
- if (syspopup_pid_ > 0) {
- int kill_ret = aul_pause_app("org.tizen.alert-syspopup");
- if (kill_ret != AUL_R_OK)
- LOG(ERROR) << "hide toast fail, return code is " << kill_ret;
- syspopup_pid_ = -1;
- }
-}
-
-void Popup::HandleEntryKeyDownEvent(const std::string& key) {
- if (key == "Cancel") {
- elm_object_focus_set(button1_, EINA_TRUE);
- } else if (key == "Select") {
- elm_object_focus_set(button2_, EINA_TRUE);
- }
-}
-
-void Popup::Timeout() {
- LOG(INFO) << "popup is timeout";
- // button1 is negative, button2 is positive
- elm_object_signal_emit(button1_, "elm,action,click", "elm");
-}
-#endif
-
} // namespace wrt